Porting code from ChibiOS 2.x to 3.x

ChibiOS 3.0 contains numerous improvements and changes. The API is very similar to the 2.6.x branch but there are some differences that should be considered.

API naming conventions

The API is mostly the same but a new function class has been introduced, the “X” class. X-class functions or macros are meant to be invoke-able from any context, ISR or Thread, within or without critical zones.

Some of the existing functions have been renamed in order to match the new semantic, if you see a compile error regarding a missing function or macro first check if the function has been renamed by adding an “X” at the end of the name.

Renamed Functions

Some functions have been renamed for consistency.

ChibiOS/RT 2.6.x ChibiOS/RT 3.0.x
chSysLockFromIsr() chSysLockFromISR()
chSysUnlockFromIsr() chSysUnlockFromISR()
chTimeNow() chVTGetSystemTime()
chTimeElapsedSince() chVTTimeElapsedSinceX()
chTimeIsWithin() chVTIsTimeWithinX()
chThdSelf() chThdGetSelfX()
chThdGetPriority() chThdGetPriorityX()
chThdGetTicks() chThdGetTicksX()
chThdLS() -
chThdTerminated() chThdTerminatedX()
chThdShouldTerminate() chThdShouldTerminateX()

Kernel types

All types have been renamed to not use camel-case and have an “_t” suffix, for example:

  • Thread become thread_t.
  • Semaphore become semaphore_t.
  • VirtualTimer become virtual_timer_t.
  • etc.

The bool_t type has been removed in order to converge to the standard “bool” type defined in stdbool.h.

Kernel Macros names changes

  • RDY_XXX macros have been renamed to MSG_XXX in order to better reveal the inner message-passing architecture.

Virtual Timers changes

Now Virtual Timers functions check if the timer is already armed before performing the operation. The functions affected are:

  • chVTSet() and chVTSetI(), the timer is first reset, if armed, then set again.
  • chVTReset() and chVTResetI(), the timer is reset only if it is already armed.

New functions have been added that have the same behaviour of the previous ones:

  • chVTDoSetI() behaves like the old chVTSetI().
  • chVTDoResetI() behaves like the old chVTResetI().

Now Virtual Timers also support a “tickless mode”, this means that there is no more a system tick, interrupts are triggered only when strictly required. There only a difference between the tickless mode and the normal mode, in tickless more the time counter continues to run even while in a critical zone because it is handled by an HW counter.

Kernel configuration options change

The configuration options prefix has been changed from “CH_” to “CH_CFG_”.

HAL architecture

In ChibiOS 3.0 the HAL is no more dependent on the RT kernel, it talks with the operating system using an abstraction layer called OSAL (Operating System Abstraction Layer). This makes possible to use the HAL with other RTOSes, like NIL, or even without an RTOS at all, an OSAL can also be implemented on a bare metal machine.

Changes to device drivers

Because the new architecture there are new rules about writing device drivers. The driver structure is almost the same but:

  • The header ch.h must not be included directly. Just include hal.h, which, by including osal.h, will also include the appropriate RTOS header.
  • RT API must not be invoked, call the equivalent OSAL API instead. The OSAL API is sufficient for drivers implementation, note, it is not meant to be a full RTOS abstraction. Often the OSAL API is equal to the RT/NIL API but the prefix is “osal” or “OSAL” instead of “ch” or “CH”.
  • Now the NVIC minidriver always takes the priority as parameter, the use of the CORTEX_PRIORITY_MASK() macro is no more required.

More articles and guides are available on the technical wiki.

learn more

Need Tutorials?

Try the video tutorials and guides on Play Embedded.

learn more

Need Support?

The forums is the best place, registration required.

learn more