Skip to content
Antonio Giacomelli edited this page Dec 5, 2025 · 378 revisions

RK0 Wiki

General application pattern

In app\application.h

#include <kapi.h>

/* custom includes, what is shared with main.c, for instance */

In app\application.c

#include <application.h>


/* Declare kernel objects */


/* Tasks: manually or using the macro _declare_ variables for task handle,
stack storage name and size in words  */

RK_DECLARE(t1Handle, Task1, task1StackBuf, TASK1_STACKSIZ)

/* Other objects (mem allocator, msg queues, semaphores, etc.) 
and backing storage they need
*/

RK_OBJ_TYPE objInstance;

myAppType_t typeMemPool[N_BLOCKS] __K_ALIGN(4);


/* Mandatory  */
VOID ApplicationInit(VOID)
{
   /* create/initialise tasks and other kernel objects */

}

/* tasks handles must be visible for the compilation unit task functions are defined */

VOID Task1(VOID* args)
{
   K_UNUSE(args);

   while(1)

   {
      /* code */
   }
}

In main.c

/* bsp, hal */
#include <board.h>
#include <application.h>


/* initialise hardware-dependent code (i/o, nvm, file system, etc) */

    kCoreInit(); /* minimal core config: systick settings and 
needed core interrupts */

    kInit(); /* initialise kernel and launch scheduler */

    while(1)
    {
       /* suggested */
       kErrHandler(RK_FAULT_APP_CRASH);
      
    }

}

Configuring the kernel

  • core/kconfig.h contains defines to enable or disable features and other critical configurations.

  • It is essential that the number of tasks in your application matches the number defined in RK_CONF_N_USRTASKS, and the lowest effective priority task number (the highest number) aligns with what is defined in RK_CONF_MIN_PRIO (maximum priority is 31).

  • If you’re using application timers, the stack size of the system task that runs the callouts might need to be adjusted on RK_CONF_TIMHANDLER_STACKSIZE. Remember, this value is in words (a word has 4 bytes). If you’re including any hooks on the IdleTask, also adjust RK_CONF_IDLE_STACKSIZE. These values must be a multiple of 8, which is a general rule for stack sizes.

  • To declare the objects needed for a task, you can use the convenience macro RK_DECLARE_TASK(). Check kapi.h for more information. Importantly, convenience macros that start with RK_ don’t need a trailing ; because they’re not meant to be seen as functions (some don’t even take arguments). Macros that start with a K_ are function-like macros.


  • Sections explaining the QEMU building system and its integration to VSCode on macOS, Windows, and Linux are available on the Wiki links.

  • A comprehensive Docbook explains kernel mechanisms (including the design rationale) and usage examples.

  • Complete application code for QEMU (on this repo) and Nucleo boards (on a wiki page) are useful for understanding how to structure your code.

Clone this wiki locally