Making embedded software portable

Thread Starter

robertin75

Joined Oct 18, 2012
5
Hello:

How do you guys start developing embedded code that can be used in a different set of microcontrollers of the same vendor?

I want to develop some device drivers for different Renesas microcontrollers, specifically the 78K0R/FB3 and 78K0R/FC3.

As a note one has more timers than the other and to generate PWM outputs you need to timer channels, one for the period and the other for the duty cycle.

For example I want to create a function for PWM that can be used on either micro.

Let's say something like void PWM_SetPWMOutput(ChannelRef Channel, U32 Period, U8 DutyCycle).

Should I use something like HAL (Hardware Abstraction Layers)?

Any website you know for further reading?

Most of the google results are specific for certain RTO's includying Linux.

Thanks
 

ErnieM

Joined Apr 24, 2011
8,377
I am unfamiliar with the Renesas products but am quite familiar with Microchip and how they handle this situation.

1. A device specific header file that defines any and all hardware such as memory, timers, PWM modules, and such.

2. A Hardware_Profile header file specific to the application that defines what resources are used where (ie, what SPI module is controlling the SD card). Note this file may be included by name by other library code modules.

3. Function libraries that drive the actual hardware. Function names are of the type:

void PWM_SetPWMOutput##(Channel, U32 Period, U8 DutyCycle)

Where ## would be the channel number (or omitted when there is only one module). Each module gets it's own (mostly identical) code, but as the code is quite short it's probably the same size and certainly faster as passing a channel number to the handler.
 

ErnieM

Joined Apr 24, 2011
8,377
Oh, and I forgot the most important part: the libraries are chock full of conditional compilation macros or alternate routines based on exactly which device the code is used on.
 

takao21203

Joined Apr 28, 2012
3,702
You create a different .h file for each controller.

You create ONE hardwareprofile.h

In this file, you use conditional include, and link the appreciate .h file for that controller.

The I/O bits are handled in a similar way. You have to specify them in one .h file
 
I suggest you use the Renesas Cubesuit+ IDE. This IDE have a code generator that you can easily select the number of PWM and the type of duty cycles you want for all their controllers. This way you maintain portability without changing your application code.

To make your application functions portable. I suggest you create a function that passes the desired duty cycle into generated code. Cubesuite+ will provide a user define handler to interface with its generated code.
 

Thread Starter

robertin75

Joined Oct 18, 2012
5
I suggest you use the Renesas Cubesuit+ IDE. This IDE have a code generator that you can easily select the number of PWM and the type of duty cycles you want for all their controllers. This way you maintain portability without changing your application code.

To make your application functions portable. I suggest you create a function that passes the desired duty cycle into generated code. Cubesuite+ will provide a user define handler to interface with its generated code.
Thanks for your suggestions.

In fact I did something similar.
 
Top