Ubiquitous Computing Technology Corporation

UCT — μT-Kernel 3.0 Migration Guide

μT-Kernel 3.0 and FreeRTOS

For developers considering migration from FreeRTOS to μT-Kernel 3.0: feature comparisons and practical porting notes

About This Page Overview

This tutorial draws on our experience porting μT-Kernel 3.0, which UCT publishes on GitHub for Infineon MCUs.

In this example, we installed μT-Kernel 3.0 on an Infineon PSoC 6 evaluation board (CY8CKIT-062S2-43012) and ported an Infineon ModusToolbox Wi-Fi sample application from FreeRTOS to μT-Kernel 3.0. Because the sample included FreeRTOS, its FreeRTOS-specific code had to be rewritten for μT-Kernel 3.0.

This tutorial explains functional and conceptual differences between the two RTOSs, providing practical guidance for porting FreeRTOS-based modules to μT-Kernel 3.0.

1. Comparison: Differences Between μT-Kernel 3.0 and FreeRTOS Feature Comparison

1. Comparison: Differences Between μT-Kernel 3.0 and FreeRTOS Feature Comparison

The goal here is to replace FreeRTOS APIs with μT-Kernel 3.0 APIs. Functions available in FreeRTOS but absent from μT-Kernel 3.0 therefore require attention. The following comparison starts with FreeRTOS functions to identify those that must be implemented using alternative μT-Kernel 3.0 facilities.

◯: Supported △: Partially supported or specified only ×: Not supported; separate implementation required

Function FreeRTOS μT-Kernel 3.0 Notes
Task Creation◯◯Task creation and deletion
Task Control◯◯Waiting, suspension, resumption and related operations
Task Utilities◯△The basic functions are equivalent.
RTOS Kernel Control◯△
Direct To Task Notifications◯◯Similar to tk_slp_tsk / tk_wup_tsk
Queues◯×Similar functionality can be implemented with message buffers
Queue Sets◯×An extension of queues
Stream Buffers◯×
Message Buffers◯◯FreeRTOS message buffers are based on stream buffers and inherit their restrictions
Semaphore / Mutexes◯△μT-Kernel 3.0 does not provide recursive mutexes.
Software Timers◯◯Cyclic handlers and alarm handlers
Event Groups (or 'flags')◯◯Event flags
FreeRTOS-MPU Specific◯×
Co-routines◯×Non-preemptive multitasking

The following table continues the comparison with μT-Kernel 3.0 functions not included above.

Function FreeRTOS μT-Kernel 3.0 Notes
Task exception handling×△Specified in μT-Kernel 3.0 but not implemented.
Mailboxes×◯
Rendezvous×Outside the specificationOutside the μT-Kernel 3.0 specification, but included in the implementation.
Fixed-size memory pools×◯
Interrupt management×◯
System state management×◯
Subsystem management×△Specified in μT-Kernel 3.0 but not implemented.
Debugging support×◯(Note)
Note: FreeRTOS provides APIs such as vTaskList() to retrieve a task list, but does not offer equivalent APIs for queues, semaphores or message buffers. Because this is not a uniform facility across objects, the table treats vTaskList() as a task utility rather than a debugging-support facility and marks this entry ×.
How to use these tables: Treat these comparison tables as a reference. If an application requires a particular function, compare both OS specifications in detail with that requirement in mind.
Some application requirements involve functions absent from one OS or the other. Those requirements may be implemented with different facilities, so a one-to-one comparison of individual APIs or functions is not always possible.
2. Porting Files and Functions Compared Porting Files

2. Porting Files and Functions Compared Porting Files

In ModusToolbox, functions required by applications, drivers and libraries are collected in COMPONENT_FREERTOS/. Use that directory as a reference to create COMPONENT_MTKERNEL3/ and implement the required functions with μT-Kernel 3.0.
The following files were created:

  • mtb_shared/abstraction-rtos/release-v1.5.0/source/COMPONENT_MTKERNEL3/cyabs_rtos_mtkernel3.c
  • mtb_shared/abstraction-rtos/include/COMPONENT_MTKERNEL3/cyabs_rtos_impl.h
  • mtb_shared/wifi-mw-core/release-v3.4.0/lwip-whd-port/COMPONENT_MTKERNEL3/arch/sys_arch.c
  • mtb_shared/wifi-mw-core/release-v3.4.0/lwip-whd-port/COMPONENT_MTKERNEL3/arch/cc.h
  • mtb_shared/wifi-mw-core/release-v3.4.0/lwip-whd-port/COMPONENT_MTKERNEL3/arch/sys_arch.h
  • mtb_shared/clib-support/release-v1.2.0/COMPONENT_MTKERNEL3/cy_mutex_pool.c

Several revisions of each implementation existed. For this port, COMPONENT_MTKERNEL3/ was placed alongside COMPONENT_FREERTOS/ in the Wi-Fi TCP Client sample.

The purpose of each file is outlined below.

(1) cyabs_rtos_mtkernel3.c

This file appears to provide a wrapper that abstracts RTOS functions for ModusToolbox sample applications. It uses the following functions in μT-Kernel 3.0 and FreeRTOS; their differences are explained below.

  • Task Control
  • Mutexes
  • Semaphores
  • Event Flags and Event Groups
  • Timers

Queues are also provided, but μT-Kernel 3.0 has no queue facility, so message buffers were used instead. Because these implementations use different mechanisms, they do not support a direct comparison of queue functions and are omitted here.

(2) sys_arch.c

This file supplies mutual-exclusion mechanisms and related facilities to lwIP. It uses the following functions:

  • Mutexes
  • Semaphores
  • Mailboxes

Mailboxes are an additional function not used in cyabs_rtos_mtkernel3.c. However, FreeRTOS has no mailbox facility and uses queues instead, so a direct functional or API comparison is not possible and is omitted.

(3) cy_mutex_pool.c

This file supplies RTOS facilities to clib and uses mutexes. Mutex differences are explained elsewhere, so they are not repeated here.

(4) Header Files

The port also requires additional header files. Their details are omitted because they do not directly explain the differences between μT-Kernel 3.0 and FreeRTOS that are the focus of this article.

3. Function-by-Function Comparison API Comparison

3. Function-by-Function Comparison API Comparison

cyabs_rtos_mtkernel3.c collects wrapper functions that abstract RTOS services for ModusToolbox sample applications. The following sections describe the APIs used to implement each function and the differences between the two operating systems.

Queues are excluded from this comparison
The FreeRTOS implementation uses its queue facility. Since μT-Kernel 3.0 has no queue facility, its implementation uses message buffers. There is no directly corresponding facility for an API-by-API comparison, so queues are not discussed here.

3-1. Task Control

Creating and Starting Tasks

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_create_thread()xTaskCreateStatic()tk_cre_tsk(), tk_sta_tsk()

Creates a task and starts execution. Replacing xTaskCreateStatic() with tk_cre_tsk() followed by tk_sta_tsk() provides the equivalent function.

In FreeRTOS, xTaskCreateStatic() both creates a task and makes it eligible to execute. Despite the name, it does more than creation alone. The FreeRTOS state diagram has no DORMANT state equivalent to that in μT-Kernel 3.0: a newly created task enters READY or RUNNING. To reproduce this behavior in μT-Kernel 3.0, create the task with tk_cre_tsk() and then start it with tk_sta_tsk().

FreeRTOS task state-transition diagram
Figure 1. FreeRTOS task state transitions
μT-Kernel task state-transition diagram
Figure 2. μT-Kernel task state transitions

In the FreeRTOS version, cy_rtos_create_thread() allocates task memory and passes it to the API as the stack. Coordinating when that memory is released adds complexity and involves the following APIs:

  • pvPortMalloc(): allocate memory
  • xSemaphoreCreateBinary(): create a binary semaphore

μT-Kernel does not require this handling; simply call tk_cre_tsk() followed by tk_sta_tsk().

Exiting Tasks

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_exit_thread()vTaskDelete()tk_exd_tsk()

Task exit and deletion use vTaskDelete() in FreeRTOS and tk_exd_tsk() in μT-Kernel 3.0. As explained under task creation, the FreeRTOS wrapper also allocates memory in cy_rtos_create_thread(), so that memory must be released. Additional logic is needed to coordinate the release timing.

In μT-Kernel 3.0, tk_exd_tsk() alone exits and deletes the task. A task can also be retained instead of deleted, as shown in the state diagram. Calling tk_ext_tsk() exits the task into DORMANT state, allowing tk_sta_tsk() to restart it from its entry point.

  • tk_ext_tsk(): exit the task
  • tk_exd_tsk(): exit and delete the task

Terminating Tasks

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_terminate_thread()vTaskDelete()tk_ter_tsk(), tk_del_tsk()

FreeRTOS has no separate task-termination function, so vTaskDelete() deletes the task. As noted earlier, memory allocated within the library must also be released when the task ends.

μT-Kernel 3.0 requires no equivalent memory handling: call tk_ter_tsk() and then tk_del_tsk(). A terminated task could be restarted if retained, but this wrapper deletes it to match the FreeRTOS version's behavior.

Use of tk_ter_tsk() is generally discouraged in μT-Kernel 3.0. Forcibly terminating a task can destabilize a system, for example by leaving allocated memory or kernel objects unreleased. This risk is not unique to μT-Kernel 3.0. The API remains available because some situations require forced termination.

Checking Task Execution State

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_is_thread_running()eTaskGetState()tk_ref_tsk()

This function determines whether the specified task is running. FreeRTOS uses eTaskGetState(). μT-Kernel 3.0 does not provide a dedicated single-purpose API, so the implementation uses tk_ref_tsk(), which retrieves a set of task information.

Retrieving a Task Identifier

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_get_thread_handle()xTaskGetCurrentTaskHandle()tk_get_tid()

Both operating systems provide corresponding APIs, so this function can be mapped directly.

Task Sleep and Wake-up

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_wait_thread_notification()ulTaskNotifyTake()tk_slp_tsk(), tk_can_wup()
cy_rtos_set_thread_notification()xTaskNotifyGive(),
vTaskNotifyGiveFromISR(),
portEND_SWITCHING_ISR()
tk_wup_tsk()

These functions put a task to sleep and wake it up. FreeRTOS offers several related APIs and macros; this wrapper uses relatively simple ones. The basic API mapping is as follows.

FunctionFreeRTOSμT-Kernel 3.0
SleepulTaskNotifyTake()tk_slp_tsk()
Wake-upxTaskNotifyGive()tk_wup_tsk()

A major difference is whether wake-up requests are queued. In μT-Kernel 3.0, calling tk_wup_tsk() while a task is not sleeping increments its pending wake-up count. If that count is at least one, tk_slp_tsk() decrements it and continues without sleeping, until the count reaches zero. In FreeRTOS, requests do not accumulate beyond one. A direct mapping would therefore behave differently. The μT-Kernel 3.0 implementation clears the queued wake-up count after tk_slp_tsk() returns.

FreeRTOS separates APIs called from tasks from those called from interrupt service routines (ISRs). ISRs must use the corresponding FromISR() API. Consequently, cy_rtos_wait_thread_notification() has a parameter identifying whether its caller is a task or an ISR. In μT-Kernel 3.0, tasks and ISRs, termed task-independent portions, can use the same API. The RTOS checks whether the call is permitted and returns an error if it is not. As a general rule, nonblocking APIs may be called from task-independent portions, so a wake-up API does not need a separate caller-context variant.

Delaying Tasks

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_delay_milliseconds()vTaskDelay()tk_dly_tsk()

Both operating systems put the task into a waiting state for the specified duration.

FreeRTOS APIs require the delay to be converted to ticks. A macro is available, but this adds a step. Page 62 of Mastering the FreeRTOS Real Time Kernel gives the following guidance:

Note: It is not recommended to specify times in ticks directly within the application, but instead to use the pdMS_TO_TICKS() macro to specify times in milliseconds, and in so doing, ensuring times specified within the application do not change if the tick frequency is changed.
The note recommends specifying application times in milliseconds with pdMS_TO_TICKS(), rather than directly in ticks, so changes to the tick frequency do not change the requested duration.

If tick-based timeout values require this precaution, the API specification could instead define timeouts in milliseconds. ITRON and μT-Kernel take that approach, making the conversion part of the operating-system contract.

3-2. Mutexes

Creating Mutexes

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_init_mutex2()xSemaphoreCreateMutex(),
xSemaphoreCreateRecursiveMutex()
tk_cre_mtx()

This function creates a mutex. FreeRTOS provides ordinary and recursive mutexes. μT-Kernel 3.0 provides ordinary mutexes but no recursive mutex facility. If required, recursive behavior can be implemented using an ordinary mutex, tk_get_tid() to identify the task, and a counter.

Only the Wi-Fi sample using FreeRTOS was installed for this comparison. Its code calls cy_rtos_init_mutex2() with the recursive-mutex option. However, the application uses simple cy_rtos_get_mutex() / cy_rtos_set_mutex() pairs, and no part appeared to require recursion.

The mechanisms for preventing priority inversion also differ. FreeRTOS mutexes support priority inheritance only, whereas μT-Kernel 3.0 supports both priority inheritance and priority ceiling protocols.

Mutex FeatureFreeRTOSμT-Kernel 3.0
Ordinary mutexes◯◯
Recursive mutexes◯×
Priority inheritance protocol◯◯
Priority ceiling protocol×◯

Deleting, Locking and Unlocking Mutexes

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_deinit_mutex()vSemaphoreDelete()tk_del_mtx()
cy_rtos_get_mutex()xSemaphoreTake(),
xSemaphoreTakeRecursive()
tk_loc_mtx()
cy_rtos_set_mutex()xSemaphoreGive(),
xSemaphoreGiveRecursive()
tk_unl_mtx()

Corresponding APIs exist for these operations, so porting is straightforward. However, FreeRTOS requires the caller's context to be distinguished when selecting an API with or without FromISR(), adding complexity to wrappers of this kind.

3-3. Semaphores

The two operating systems provide corresponding semaphore APIs, making porting straightforward. In FreeRTOS, distinguishing caller context and expressing wait times in ticks still adds work, although this impression may partly reflect familiarity with μT-Kernel.

Creating and Deleting Semaphores

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_init_semaphore()xSemaphoreCreateCounting()tk_cre_sem()
cy_rtos_deinit_semaphore()vSemaphoreDelete()tk_del_sem()

Creation and deletion serve the same purpose in both operating systems, and both support binary and counting semaphores. μT-Kernel 3.0 additionally allows waiting tasks to be selected in FIFO or task-priority order, broadening semaphore applications. FreeRTOS uses FIFO order only.

Acquiring and Releasing Semaphore Resources

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_get_semaphore()xSemaphoreTake(),
xSemaphoreTakeFromISR()
tk_wai_sem()
cy_rtos_set_semaphore()xSemaphoreGive(),
xSemaphoreGiveFromISR(),
portYIELD_FROM_ISR()
tk_sig_sem()

Both systems acquire and release semaphore resources. FreeRTOS limits each operation to one resource, even for counting semaphores. μT-Kernel 3.0 permits an arbitrary count, allowing multiple resources to be acquired or released in one operation.

There is a more significant difference than either of these points.In FreeRTOS, if a semaphore operation in an interrupt handler requires a task switch, the developer must explicitly call portYIELD_FROM_ISR().Without that call, returning from the interrupt handler to task context does not immediately switch tasks; switching waits until it is next explicitly requested. This is FreeRTOS behavior and also applies to other communication objects. μT-Kernel 3.0 needs no such application code: dispatch occurs automatically when the interrupt handler exits. This is the principle of delayed dispatching.

The original FreeRTOS cy_rtos_setbits_event() implementation did not include a call to portYIELD_FROM_ISR().

3-4. Event Flags and Event Groups

Creating Event Flags

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_init_event()xEventGroupCreate()tk_cre_flg()

FreeRTOS event groups correspond to μT-Kernel 3.0 event flags. The term event flags is used below.

Although these facilities are similar, μT-Kernel 3.0 and FreeRTOS differ as follows.

Event-Flag FeatureFreeRTOSμT-Kernel 3.0
Number of flag bits8 or 24 bits, selected by configurationImplementation-dependent: unsigned int
Ordering of waiting tasksFIFO onlySelectable FIFO or priority order
Number of waiting tasksMultiple tasks may waitSelectable single-task or multiple-task waiting

In μT-Kernel 3.0, event flags use unsigned int, so their width follows the CPU and implementation for efficient processing. FreeRTOS provides 8 or 24 usable bits depending on configUSE_16_BIT_TICKS.

configUSE_16_BIT_TICKS defines TickType_t, but the usable event-flag width also depends on it. The code defines it as follows:

typedef TickType_t EventBits_t;

TickType_t is defined as 16 or 32 bits according to configUSE_16_BIT_TICKS:

#if ( configUSE_16_BIT_TICKS == 1 ) typedef uint16_t TickType_t; #else typedef uint32_t TickType_t; #endif

Deleting Event Flags

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_deinit_event()vEventGroupDelete()tk_del_flg()

Both operating systems delete the event-flag object; there is no particular difference.

Setting Event Flags

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_setbits_event()xEventGroupSetBits(),
xEventGroupSetBitsFromISR()
tk_set_flg()

Both systems set the specified bits. FreeRTOS uses different APIs depending on the caller's context, which the application must therefore identify. μT-Kernel 3.0 does not require separate flag-setting APIs for different contexts.

As explained for semaphores, FreeRTOS requires an explicit portYIELD_FROM_ISR() call when a semaphore operation in an interrupt handler necessitates a task switch. This requirement also needs attention here.

Clearing Event Flags

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_clearbits_event()xEventGroupClearBits(),
xEventGroupClearBitsFromISR()
tk_clr_flg()

Both systems clear event bits, but FreeRTOS clears bits corresponding to ones in the mask, while μT-Kernel 3.0 clears those corresponding to zeros. Neither convention is inherently better; the difference matters during development and porting.

Reading Event Flags

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_getbits_event()xEventGroupGetBits()tk_ref_flg()

Both systems retrieve the current event-flag bit pattern.

Waiting for Event Flags

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_waitbits_event()xEventGroupWaitBits()tk_wai_flg()

Both systems wait for specified bits to become one. When multiple bits are specified, either all bits or any one bit can satisfy the condition. Both also let the caller select whether bits are cleared when the condition is met.
FreeRTOS only allows clearing of the bits specified in the wait condition. μT-Kernel 3.0 can alternatively clear all bits.

Bit-Clearing ModeFreeRTOSμT-Kernel 3.0
Do not clear bits◯◯
Clear the bits in the wait condition◯◯
Clear all bits×◯

Note also that FreeRTOS returns a bit pattern, as shown below.

The value of the event group at the time either the event bits being waited for became set, or the block time expired.

To detect a timeout, the caller must compare the returned bit pattern with the requested condition. μT-Kernel 3.0 instead indicates errors through the return value, simplifying the return handling. However, on error the flag bits are not read and are indeterminate, so code that uses the bit pattern must account for this.

3-5. Timers

Both systems provide the equivalent of alarm and cyclic handlers and therefore receive ◯ for timer functionality. For alarm handlers, however, μT-Kernel 3.0 and FreeRTOS specify the time parameter at different stages. The timing for specifying when the callback runs is shown below.

FunctionFreeRTOSμT-Kernel 3.0
Alarm handlersAt creationAt start
Cyclic handlersAt creationAt creation

This difference is manageable in new development, but can complicate porting between the operating systems.

Timer callbacks also run in different contexts. In μT-Kernel 3.0 they run in a task-independent portion, specifically an interrupt handler, and generally take precedence over tasks. FreeRTOS invokes callbacks from a dedicated timer task in task context. Its priority is set by configTIMER_TASK_PRIORITY, commonly defined as follows:

#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )

Many systems therefore assign the timer-service task the highest priority. Other tasks can nevertheless have that same priority, so timer callbacks do not necessarily take precedence over every task. Timer activation also sends commands to the timer task's queue, which can fail if the queue is full.

Creating Timers

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_init_timer()xTimerCreate()tk_cre_alm(), tk_cre_cyc()

μT-Kernel 3.0 provides separate alarm-handler and cyclic-handler facilities. FreeRTOS combines these as software timers, with an option selecting one-shot or repeated operation. One-shot timers correspond to alarm handlers and repeating timers to cyclic handlers. Their overall functions are similar, but the following differences require attention when implementing or porting them.

  • μT-Kernel 3.0 allows immediate activation at creation and specification of cyclic-handler startup timing:A μT-Kernel 3.0 cyclic handler can be started as soon as it is created, and its first activation time can also be specified. FreeRTOS does not provide these finer configuration options.
  • FreeRTOS allows timer timing to be changed:FreeRTOS provides xTimerChangePeriod() to change a timer's period. A μT-Kernel 3.0 cyclic handler's timing is specified at creation and cannot subsequently be changed. Alarm-handler timing is specified at start, so that facility does not need an equivalent API.
  • Callback arguments differ:μT-Kernel 3.0 passes the extended information supplied at creation, void *exinf, to the callback. FreeRTOS passes the timer handle, of type TimerHandle_t, determined when the timer is created.

Starting Timers

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_start_timer()xTimerChangePeriod(), xTimerStart()tk_sta_alm(), tk_sta_cyc()

Both systems start timers. As described under timer creation, FreeRTOS sets the time when starting a timer. A μT-Kernel 3.0 alarm-handler start API can specify the activation time, providing equivalent functionality. A cyclic handler's timing cannot be changed at start because it is specified at creation.

As noted earlier, FreeRTOS timer functions are provided by a timer-service task. Timer-control APIs send requests to this task through a command queue, so an operation can fail when the queue is full.

Stopping Timers

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_stop_timer()xTimerStop()tk_stp_alm(), tk_stp_cyc()

Both systems stop the timer; their functions are equivalent.

Checking Timer Activation State

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_is_running_timer()xTimerIsTimerActive()tk_ref_alm(), tk_ref_cyc()

This retrieves whether a timer is active. FreeRTOS provides a dedicated API. μT-Kernel 3.0 retrieves timer information, including activation state, with tk_ref_alm() or tk_ref_cyc().

Deleting Timers

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_deinit_timer()xTimerDelete()tk_del_alm(), tk_del_cyc()

Both systems delete the timer; their functions are equivalent.

FreeRTOS also provides APIs for operations such as resetting timers and changing timer type. The following list omits FromISR() variants:

FreeRTOS Timer APIs
xTimerCreate()
xTimerCreateStatic()
xTimerIsTimerActive()
xTimerStart()
xTimerStop()
xTimerChangePeriod()
xTimerDelete()
xTimerReset()
pvTimerGetTimerID()
vTimerSetReloadMode()
vTimerSetTimerID()
xTimerGetTimerDaemonTaskHandle()
xTimerPendFunctionCall()
pcTimerGetName()
xTimerGetPeriod()
xTimerGetExpiryTime()
xTimerGetReloadMode()

The μT-Kernel 3.0 equivalents are shown below, illustrating the smaller API set. Variants ending in _u() are omitted.

Cyclic handlersAlarm handlersFunction
tk_cre_cyctk_cre_almCreate
tk_del_cyctk_del_almDelete
tk_sta_cyctk_sta_almStart
tk_stp_cyctk_stp_almStop
tk_ref_cyctk_ref_almReference

Retrieving System Uptime

Wrapper FunctionFreeRTOS APIμT-Kernel 3.0 API
cy_rtos_get_time()xTaskGetTickCount()tk_get_otm()

FreeRTOS represents time in ticks, so retrieved elapsed time is also a tick count. Applications must convert it to milliseconds when needed. μT-Kernel 3.0 specifies API time values in milliseconds, so that conversion is unnecessary.

4. Other Differences Additional Differences

4. Other Differences Additional Differences

The preceding sections describe differences encountered while replacing the RTOS component. Additional differences are summarized below.

4-1. FreeRTOS Includes Round-Robin Scheduling

FreeRTOS uses round-robin scheduling when several runnable tasks share a priority, dividing processing time among equal-priority tasks that are ready to execute.

μT-Kernel can implement similar behavior by calling tk_rot_rdq() from a cyclic handler or explicitly from a task. Explicit rotation allows a task to switch after completing a suitable amount of work, limiting disruption to the running task.

4-2. Documentation Is Primarily in English

The original μT-Kernel 3.0 documentation is in Japanese, whereas FreeRTOS documentation is primarily in English. AWS's Japanese pages also begin with a notice explaining that:

The translations are machine-generated, and the English version takes precedence if the translated text differs, is inconsistent or conflicts with it.

Machine translation is considerably more readable than it used to be. However, complex explanations can still be difficult to understand in Japanese, making it necessary to consult the English original.

4-3. No Fixed-Size Memory Pools

FreeRTOS has no fixed-size memory-pool facility. Fixed-size pools are useful in embedded devices for the following reasons:

  • Their simplicity keeps allocation and release operations lightweight.
  • They avoid memory fragmentation.

Reducing memory use matters in RAM-constrained systems, but variable-size pools can carry substantial overhead once management structures are included. This is a trade-off; with the larger RAM available in recent systems, allocating slightly larger fixed-size buffers may be acceptable.

4-4. OS Startup

In FreeRTOS, application code begins in main() and starts the RTOS by launching its scheduler. In μT-Kernel 3.0, application execution begins in an initial task. A main() function exists internally but is not exposed to application developers.

Exposing low-level startup details to RTOS application developers is not always desirable. Nevertheless, beginning at main() may be familiar to C programmers and helpful when moving from a bare-metal system to an OS. Once a developer is accustomed to an RTOS, this startup code may feel redundant.

4-5. Separate APIs for Tasks and ISRs

As explained earlier, FreeRTOS separates task APIs from ISR APIs. An interrupt service routine must call the corresponding FromISR() variant. The author finds this inconvenient: it gives developers flexibility but also requires them to handle more details and precautions.

4-6. Initial Semaphore Values

μT-Kernel 3.0 allows the initial semaphore count to be specified at creation. In the FreeRTOS case discussed here, the count starts at zero and is set by releasing resources after creation. FreeRTOS exposes separate fine-grained APIs, whereas μT-Kernel 3.0 groups related functions. The author considers the latter easier to understand.

4-7. Data Queues

μT-Kernel 3.0 has no data queues. Message buffers or mailboxes can serve as alternatives, although there is no equivalent operation for inserting an item at the front for immediate reception. Mailbox attributes can, however, arrange messages in message-priority order, allowing behavior that is similar, though not identical.

4-8. Task Priorities

In FreeRTOS, zero is the lowest task priority and configMAX_PRIORITIES − 1 is the highest. In μT-Kernel 3.0, one is the highest and CNF_MAX_TSKPRI is the lowest. This is partly a matter of familiarity, but the author finds a fixed value of one for the highest priority easier to understand.

4-9. Return Values

FreeRTOS object identifiers and return values are not uniform across facilities: the examples discussed include structures for queues, semaphores and mutexes, void* for message buffers, and integers for tasks. For example:

  • xTaskCreate() returns pdPASS or errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY.
  • xTaskCreateStatic() returns NULL on failure and a non-NULL value on success.

FreeRTOS API names include prefixes indicating the return type, as shown below. This may help readers, but the author finds it less convenient when writing an implementation.

PrefixType
pcchar*
pvvoid*
vvoid
uxUBaseType_t
xBaseType_t, TaskHandle_t, …

TRON-family operating systems, including μT-Kernel 3.0, follow these general rules:

  • Return value < 0: error
  • Return value ≥ 0: success

This consistency, reflecting lessons incorporated into the design, makes development easier in μT-Kernel 3.0 from the author's perspective.

4-10. Idle Tasks

FreeRTOS automatically supplies an idle task, which can host power-saving functionality and may be approachable for developers. In μT-Kernel 3.0, power-saving processing is implemented in low_pow(). The dispatcher calls it directly when no tasks are runnable, so no idle task needs to be created for that purpose.

4-11. Message Buffers

Both FreeRTOS and μT-Kernel 3.0 provide message buffers. FreeRTOS implements them on top of stream buffers, however, so the following restrictions apply.

IMPORTANT NOTE: Uniquely among FreeRTOS objects, the stream buffer implementation (so also the message buffer implementation, as message buffers are built on top of stream buffers) assumes there is only one task or interrupt that will write to the buffer (the writer), and only one task or interrupt that will read from the buffer (the reader). It is safe for the writer and reader to be different tasks or interrupts, but, unlike other FreeRTOS objects, it is not safe to have multiple different writers or multiple different readers.
  • Message buffers inherit the same usage restrictions as the stream buffers on which they are implemented.
  • Stream buffers assume that:
    • Only one task or interrupt writes to the buffer: the writer.
    • Only one task or interrupt reads from the buffer: the reader.
  • The writer and reader may be different tasks or interrupts.
  • Multiple writers or multiple readers are not safe without additional coordination.
  • If multiple writers are required, place the write API inside a critical section and set the send block time to zero.
  • If multiple readers are required, place the read API inside a critical section and set the receive block time to zero.

μT-Kernel 3.0 message buffers have no such restriction and can be accessed by multiple tasks.

Contact us to discuss migration or porting from FreeRTOS to μT-Kernel 3.0.

Contact Us →