Making embedded software portable

Discussion in 'Embedded Systems and Microcontrollers' started by robertin75, Nov 14, 2012.

  1. robertin75

    Thread Starter New Member

    Oct 18, 2012

    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.

  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    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.
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    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.
  4. takao21203

    Distinguished Member

    Apr 28, 2012
    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
  5. SolderFlux

    New Member

    Dec 6, 2012
    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.
  6. robertin75

    Thread Starter New Member

    Oct 18, 2012
    Thanks for your suggestions.

    In fact I did something similar.