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

RK0 Wiki

General application structure

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: declare manually or using the convenience macro, 
- task handle object (RK_TASK_HANDLE type)
- task function name (which signature is VOID-(VOID*)) 
- stack buffer (RK_STACK) 
- size (words) (UINT)
 */

RK_DECLARE(t1Handle, Task1, task1StackBuf, TASK1_STACKSIZ) 
/* RK_ prefixed macros don’t require a trailing ‘;’ */

/* Other objects (mem allocator, msg queues, semaphores, etc.) 
and any 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 */
   /* see kapi.h */

}

/* all task objects must be visible for the unit which 
 task functions are defined */

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

   while(1)

   {
      /* task will run until preempted by a higher priority task, 
         blocking or yielding 
         (there is no built-in time-slice in the scheduler) 
      */
   }
}

In main.c

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


/* initialise hardware-dependent code (plls, 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 value (the highest number) is defined in RK_CONF_MIN_PRIO (maximum 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.

  • Besides the QEMU build (on this repository), there are builds for Nucleo boards (on a wiki page). One of these builds doesn’t assume any IDE, and there’s a project for STM32CubeIDE. These can guide you on how to structure your design.

  • Currently the kernel only compiles with ARM-GCC and needs the CMSIS-GCC interface (found in core\inc\cmsis_gcc.h).

  • www.kernel0.org/blog


Clone this wiki locally