[sdiy] Digital VCA

Matthew Smith matt at smiffytech.com
Sun Aug 28 02:56:58 CEST 2011


Quoth Dan Snazelle at 28/08/11 09:58...
> Can the freescale part run similar code?

If the code is written in a modular fashion, in a portable language (ie: 
not assembly,) yes.

I am writing the firmware in C. Anything device specific - mostly 
peripherals - is written in its own file, which is compiled into the 
main application.  This not only allows for portability, but also makes 
peripheral code easier to re-use.

For instance, The ADSR/LFO makes use of the following peripherals:

* ADC
* Serial communications controller (SPI)
* Serial communications controller (UART for MIDI)
* Timers
* General IO (LCD)
* General IO (Rotary encoder)

So, you write your main code (call it main.c) and then write code to 
handle all the hardware, a hardware abstraction layer (HAL,) if you like.

Each EXTERNAL piece of hardware has its own .c, .h files. This means I 
can re-use them between applications. These, in turn, rely on .c and .h 
files for each peripheral (the HAL.) It is by having separate files to 
"read from ADC," "set up UART," "send over SPI," each tailored to the 
specific architecture/toolchain, that we can obtain portability.

If I change my application from Atmel to Freescale parts, the main code 
and EXTERNAL hardware code is either unchanged or little changed. It's 
the parts of the code that form the HAL that are changed to suit the new 
architecture (or toolchain.)

The one aspect of the main code that DOES need to be modified between 
architectures and toolchains is interrupt handlers. For some reason, 
it's always seemed to complicated to bundle these off into the HAL code.

Pretty much the same applies with programmable logic. If you are going 
to make use of device-specific features such as hardware multipliers, 
shunt these off into a device-specific file. Then, when you move from a 
Xilinx part to an Altera part, for instance, you only need to change a 
single, known, part of the code. (Or so you hope.)

Moral: Writing your code in one homogenous lump will bring you to grief.

Hope this helps!

Cheers

M

-- 
Matthew Smith

Business: http://www.smiffytech.com
Blog:     http://www.smiffysplace.com
Linkedin: http://www.linkedin.com/in/smiffy
Flickr:   http://www.flickr.com/photos/msmiffy
Twitter:  http://twitter.com/smiffy



More information about the Synth-diy mailing list