KAL_Init

Description

Initialize Kernel Abstraction Layer (KAL).

Files

kal.h / kal.c

Prototype

void  KAL_Init (KAL_CFG   *p_cfg,
                RTOS_ERR  *p_err)


Arguments

p_cfg

Pointer to KAL configuration structure. DEF_NULL can be used.

p_err

Pointer to variable that will receive the return error code from this function.

RTOS_ERR_NONE

RTOS_ERR_OS

RTOS_ERR_ALREADY_INIT

RTOS_ERR_ALLOC

RTOS_ERR_INIT

Returned Value

None.

Callers

Application, if using specific memory segment.

Products, otherwise.

Notes / Warnings

  1. Mem_Init() must be called before calling KAL_Init().

Usage Example

Listing - KAL_Init() with Memory Segment Example
#include  <KAL/kal.h>                                                         (1)
#include  <lib_mem.h>
 
#define  APP_KAL_MEM_SEG_LEN  (10u * 1024u)                                   (2)
 
static  MEM_SEG     App_KAL_MemSeg;                                           (3)
static  CPU_INT08U  App_KAL_MemSegData[APP_KAL_MEM_SEG_LEN];                  (4)
 
static  void  AppTaskStart (void  *p_arg)
{
    KAL_CFG   cfg_kal;
    RTOS_ERR  err_rtos;
    LIB_ERR   err_lib;
 
 
    [...]
    Mem_Init();                                                               (5)
 
    Mem_SegCreate("KAL - Memory segment",                                     (6)
                  &App_KAL_MemSeg,
           (void *)App_KAL_MemSegData,
                   sizeof(App_KAL_MemSegData),
                  &err_lib);
    if (err_lib != LIB_MEM_ERR_NONE) {
        APP_TRACE_INFO(("Could not create KAL memory segment  w/err = %d\r\n", err_lib));
        /* !!!! Handle error. */
    }
 
    cfg_kal.MemSegPtr = &App_KAL_MemSeg;                                      (7)
 
    KAL_Init(&cfg_kal,                                                        (8)
             &err_rtos);
    if (err_rtos!= RTOS_ERR_NONE) {
        APP_TRACE_INFO(("Could not initialize KAL w/err = %d\r\n", err_rtos));
        /* !!!! Handle error. */
    }
    [...]
}

(1) The application file must include KAL/kal.h and lib_mem.h, to access KAL and µC/LIB types and functions.

(2) The size of the memory segment that KAL will use. The required size varies depending on the application. If more kernel objects (semaphores, tasks, etc.) are needed by the products (µC/FS, µC/USB-Host, etc.), the amount of memory used by KAL will be greater.

(3) Declare a MEM_SEG variable, that will contain information about the memory segment used by KAL.

(4) Declare memory that KAL will use (via the memory segment) to allocate everything needed. This memory could be allocated from elsewhere, depending on the application and type(s) of memory available.

(5) Mem_Init() must be called before calling either Mem_SegCreate() and KAL_Init().

(6) Create the memory segment that will be used by KAL to allocate everything it needs. This memory segment could also be used to allocate other items, related to the kernel or not.

(7) Set the MemSegPtr field of the KAL configuration to point to the created memory segment.

(8) Initialize Kernel Abstraction Layer (KAL), using the desired configuration.