Choco OS  V.0.16.9.0
Join to the chocolate world
(SYS-LLD) System Low Level Driver

Manage system operations. More...

Typedefs

typedef void oC_SYS_LLD_Context_t
 type for storing context of the machine More...
 
typedef void(* oC_SYS_LLD_Interrupt_t) (void)
 type for storing interrupt pointers More...
 
typedef void(* oC_SYS_LLD_SysTickIncrementHandler_t) (void)
 stores SysTick interrupt handler More...
 
typedef void(* oC_SYS_LLD_EventInterrupt_t) (oC_SYS_LLD_EventFlags_t EventFlags, oC_SYS_LLD_Context_t *Context, void *BusAddress)
 stores event handler function More...
 
typedef void(* oC_SYS_LLD_ContextHandler_t) (void *Parameter)
 stores pointer to context handler function More...
 
typedef void(* oC_SYS_LLD_ContextExitHandler_t) (void)
 pointer to the context exit handler More...
 

Enumerations

Functions

oC_ErrorCode_t oC_SYS_LLD_TurnOnDriver (void)
 initializes the driver to work More...
 
oC_ErrorCode_t oC_SYS_LLD_TurnOffDriver (void)
 release the driver More...
 
oC_ErrorCode_t oC_SYS_LLD_SetEventInterruptHandler (oC_SYS_LLD_EventInterrupt_t EventHandler, oC_SYS_LLD_EventFlags_t EventsFlags)
 sets event interrupt handler More...
 
bool oC_SYS_LLD_IsMachineSupportMultithreadMode (void)
 checks if the machine supports multi-thread mode More...
 
void oC_SYS_LLD_TurnOnInterrupts (void)
 turns on interrupt More...
 
void oC_SYS_LLD_TurnOffInterrupts (void)
 turns off interrupt More...
 
void oC_SYS_LLD_EnterCriticalSection (void)
 enters to critical section More...
 
void oC_SYS_LLD_ExitCriticalSection (void)
 exits from critical section More...
 
bool oC_SYS_LLD_AreInterruptsEnabled (void)
 checks if interrupts are turned on More...
 
oC_ErrorCode_t oC_SYS_LLD_ConfigureSystemTimer (oC_Frequency_t Frequency, oC_SYS_LLD_SysTickIncrementHandler_t Interrupt)
 configures system timer More...
 
oC_ErrorCode_t oC_SYS_LLD_ReadSystemTimerFrequency (oC_Frequency_t *outFrequency)
 reads configured system frequency More...
 
oC_ErrorCode_t oC_SYS_LLD_SetNextContext (oC_SYS_LLD_Context_t *Context)
 configures next machine context More...
 
oC_Int_t oC_SYS_LLD_GetContextStackSize (oC_SYS_LLD_Context_t *Context)
 returns size of the stack for context More...
 
oC_Int_t oC_SYS_LLD_GetContextFreeStackSize (oC_SYS_LLD_Context_t *Context)
 returns size of free stack in the context More...
 
oC_ErrorCode_t oC_SYS_LLD_ReturnToSystemContext (void)
 switches to the system context More...
 
oC_SYS_LLD_Context_toC_SYS_LLD_GetCurrentContext (void)
 returns pointer to the current context More...
 
oC_SYS_LLD_Context_toC_SYS_LLD_GetSystemContext (void)
 returns pointer to the system context More...
 
oC_ErrorCode_t oC_SYS_LLD_InitializeContext (oC_SYS_LLD_Context_t **Context, oC_Int_t StackSize, oC_SYS_LLD_ContextHandler_t ContextHandler, void *Parameters, oC_SYS_LLD_ContextExitHandler_t ExitHandler)
 initializes stack of process More...
 
oC_Int_t oC_SYS_LLD_GetMinimumContextSize (oC_Int_t StackSize)
 returns minimum size to allocate for context More...
 
const char * oC_SYS_LLD_GetMachineName (void)
 returns printable name of the machine More...
 
const char * oC_SYS_LLD_GetMachineFamilyName (void)
 returns printable name of the machine family More...
 
const char * oC_SYS_LLD_GetMachineProducentName (void)
 returns printable name of the machine producent More...
 
void oC_SYS_LLD_Reset (void)
 software reset of the machine More...
 
bool oC_SYS_LLD_IsStackPushDecrementPointer (void)
 flag if stack push is decrement pointer More...
 
oC_ErrorCode_t oC_SYS_LLD_ReadPowerState (float *outVcc)
 reads power state More...
 
void * oC_SYS_LLD_GetLastProcessStackPointer (void)
 returns stack pointer of last executed process More...
 

Detailed Description

The driver is for supporting operations that are specific for the system handling, such as switching context, turning on and off interrupts, configuring system tick and so on.
The module must be turned on before usage by the function oC_SYS_LLD_TurnOnDriver. When it is not needed anymore, the oC_SYS_LLD_TurnOffDriver allow to turn it off. It will restore the system task.
It support also an event system, that can be configured by oC_SYS_LLD_SetEventInterruptHandler once after enabling the module. The SYS allow for switching context. The context is the stack that was allocated for the thread for example. The size of required allocation can be read by function oC_SYS_LLD_GetMinimumContextSize. When memory for a process stack is allocated with correct size it must be initialized. For initialization you will need to set pointer to the function, that will be executed during context handling. There is not any kill thread function. If thread want to destroy by itself, it should just change current context and wait. On the other hand, when some other thread want to kill a thread, there is no need to inform this module - if other thread want to kill, so other thread is currently active.
The module does not support any queue for tasks. It just help by simple way for task switching. The real task manager is implemented in the kernel, not portable space, and it is common for all machines.
The first thing to use the SYS-LLD as a context switcher, is configuration of the system timer. It can be done by oC_SYS_LLD_ConfigureSystemTimer. It allow to set frequency of calling the SysTick handler function. Note, that this function should be called every time, when the system clock is reconfigured - otherwise this frequency will be not updated. The SysTick handler function is the special function that allow to select next task to execute. If it will return true, the context will be switched immediately. To select the next context, use the function oC_SYS_LLD_SetNextContext.

Some example pseudo-code (do not use it - it is only for explanation):

//
// This is the context handler, that will blink the led
//
void BlinkLed(void * Parameter)
{
while(1)
{
TurnOnLed();
oC_CLOCK_DelayForMicroseconds(500);
TurnOffLed();
oC_CLOCK_DelayForMicroseconds(500);
}
}
//
// Handler for context exit event
//
void BlinkLedStopped()
{
// Some error occurs, and the BlinkLed function has been stopped!
while(1);
}
//
// Handler for the SysTick event. When it will return true, the context will be switched.
//
bool IncrementSystemTimer(void)
{
return true;
}
void main()
{
// This will enable the SYS driver
// This will configure the timer to call the IncrementSystemTimer function periodically with frequency 10 kHz
oC_SYS_LLD_ConfigureSystemTimer( oC_kHz(10) , IncrementSystemTimer );
// Allocation the stack for this context. We will reserve 128 bytes for execution of the BlinkLed function.
// Allocation of context by setting function to execute, size of the stack and exit handler function.
if(oC_SYS_LLD_InitializeContext( context , 128 , BlinkLed , NULL , BlinkLedStopped))
{
// Setting the context as the next context to switched, when it will be possible (with the next call of the SysTick handler, that will return true).
}
}
The SYS-LLD module supports controlling of stack overflow. It is controlled with frequency of system timer. So, when the system timer is configured to work with 1 kHz frequency, the stack is checked each 1 ms. Size of the context stack free memory can be checked by the function oC_SYS_LLD_GetContextFreeStackSize.

Typedef Documentation

typedef void oC_SYS_LLD_Context_t

This is the type for storing context of the machine. It should be dynamically allocated with size from the function oC_SYS_LLD_GetContextStackSize. The start of this structure pointer is at the start of the stack. It must be initialized by oC_SYS_LLD_InitializeContext function before usage. When it is done, you can change the context of the machine (call other task) by using the function oC_SYS_LLD_SetNextContext.

Definition at line 143 of file oc_sys_lld.h.

typedef void(* oC_SYS_LLD_ContextExitHandler_t) (void)

The type stores pointer to the function, that is called, when the context handler finish work.

Definition at line 216 of file oc_sys_lld.h.

typedef void(* oC_SYS_LLD_ContextHandler_t) (void *Parameter)

The type stores pointer to the function, that handle context

Parameters
ParameterUser parameter for the function

Definition at line 207 of file oc_sys_lld.h.

typedef void(* oC_SYS_LLD_EventInterrupt_t) (oC_SYS_LLD_EventFlags_t EventFlags, oC_SYS_LLD_Context_t *Context, void *BusAddress)

The type is for storing handler of events. It is a function that will be called, when one of enabled events by oC_SYS_LLD_SetEventInterruptHandler function will occur.

Parameters
EventFlagsFlags of active events (can be more than one)
ContextContext of the event

Definition at line 196 of file oc_sys_lld.h.

typedef void(* oC_SYS_LLD_Interrupt_t) (void)

The type is for storing interrupt handler function pointer. The function that is set to this pointer should be as short as possible, and it should be included, that this is executed in an interrupt.

Definition at line 172 of file oc_sys_lld.h.

typedef void(* oC_SYS_LLD_SysTickIncrementHandler_t) (void)

The type is for storing special function - SysTick handler. It is the function, that is called periodically as interrupt for inform the system about need the increment of the system tick counter. The handler should also change the current system task if it is needed.

Definition at line 182 of file oc_sys_lld.h.

Enumeration Type Documentation

The type stores flags for module events. Event handler, and interrupts selection can be done by oC_SYS_LLD_SetEventInterruptHandler function.

Enumerator
oC_SYS_LLD_EventFlags_HardFault 

Hard fault, reason is unknown.

oC_SYS_LLD_EventFlags_DivideBy0 

Hard fault, divide by 0 detected.

oC_SYS_LLD_EventFlags_UnalignedLoadOrStore 

Loading or storing data to memory occurs with not aligned address.

oC_SYS_LLD_EventFlags_UndefinedInstruction 

Undefined instruction detected.

oC_SYS_LLD_EventFlags_UsageFault 

Usage fault.

oC_SYS_LLD_EventFlags_ProcessStackOverflow 

The process is not correct, or the process stack was overflowed.

Definition at line 153 of file oc_sys_lld.h.

Function Documentation

bool oC_SYS_LLD_AreInterruptsEnabled ( void  )
Note
stm32f7 notes:
lm4f notes:

Definition at line 250 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_ConfigureSystemTimer ( oC_Frequency_t  Frequency,
oC_SYS_LLD_SysTickIncrementHandler_t  Interrupt 
)

The function is for configuration of the system timer that should call the Interrupt with the given Frequency.

Parameters
FrequencyFrequency of switching context event
InterruptSysTick increment interrupt handler
Returns
code of error or #oC_ErrorCode_None if success
Note
stm32f7 notes:
lm4f notes:

Definition at line 261 of file oc_sys_lld.c.

void oC_SYS_LLD_EnterCriticalSection ( void  )

The function enters to critical section.

Note
stm32f7 notes:
lm4f notes:

Definition at line 228 of file oc_sys_lld.c.

void oC_SYS_LLD_ExitCriticalSection ( void  )

The function enters to critical section.

Note
stm32f7 notes:
lm4f notes:

Definition at line 239 of file oc_sys_lld.c.

oC_Int_t oC_SYS_LLD_GetContextFreeStackSize ( oC_SYS_LLD_Context_t Context)

The function returns size of the free memory on the context stack.

Parameters
ContextPointer to the context initialized before by oC_SYS_LLD_InitializeContext
Returns
size or 0 if error
Note
stm32f7 notes:
lm4f notes:

Definition at line 368 of file oc_sys_lld.c.

oC_Int_t oC_SYS_LLD_GetContextStackSize ( oC_SYS_LLD_Context_t Context)

It returns size of the stack, that is allocated for the context. Note, that this size does not contain an extra size that is additionally required and used for handling the context. All of this size is used only for handling the process stack.

Parameters
ContextInitialized context pointer
Returns
size of the context, or 0 if error
Note
stm32f7 notes:
lm4f notes:

Definition at line 350 of file oc_sys_lld.c.

oC_SYS_LLD_Context_t * oC_SYS_LLD_GetCurrentContext ( void  )
Note
stm32f7 notes:
lm4f notes:

Definition at line 397 of file oc_sys_lld.c.

void * oC_SYS_LLD_GetLastProcessStackPointer ( void  )
Note
stm32f4 notes:
stm32f7 notes:

Definition at line 537 of file oc_sys_lld.c.

const char * oC_SYS_LLD_GetMachineFamilyName ( void  )

The function is for reading name of the target machine family.

Returns
constant string with machine family name.
Note
stm32f7 notes:
lm4f notes:

Definition at line 474 of file oc_sys_lld.c.

const char * oC_SYS_LLD_GetMachineName ( void  )

The function is for reading name of the target machine.

Returns
constant string with machine name
Note
stm32f7 notes:
lm4f notes:

Definition at line 463 of file oc_sys_lld.c.

const char * oC_SYS_LLD_GetMachineProducentName ( void  )

The function is for reading name of the target machine company.

Returns
constant string with machine company name.
Note
stm32f7 notes:
lm4f notes:

Definition at line 485 of file oc_sys_lld.c.

oC_Int_t oC_SYS_LLD_GetMinimumContextSize ( oC_Int_t  StackSize)

The function returns the minimum size of allocation that is needed to handle the context switching.

Parameters
StackSizeThe minimum stack size, that you will need for the task
Returns
size of the context structure
Note
stm32f7 notes:
lm4f notes:

Definition at line 452 of file oc_sys_lld.c.

oC_SYS_LLD_Context_t * oC_SYS_LLD_GetSystemContext ( void  )
Note
stm32f7 notes:
lm4f notes:

Definition at line 408 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_InitializeContext ( oC_SYS_LLD_Context_t **  Context,
oC_Int_t  StackSize,
oC_SYS_LLD_ContextHandler_t  ContextHandler,
void *  Parameters,
oC_SYS_LLD_ContextExitHandler_t  ExitHandler 
)

The function is for initialization of a context stack. Note, that the context must be allocated and initialized before. The minimum size of the stack for a context can be read by the function oC_SYS_LLD_GetMinimumContextSize.

Here some example of usage:

void ContextHandler( void * )
{
while(1);
}
void ExitHandler(void)
{
while(1);
}
oC_UInt_t stackSize = 512;
oC_SYS_LLD_Context_t * context = malloc( oC_SYS_LLD_GetMinimumContextSize(stackSize) );
oC_SYS_LLD_InitializeContext(context , stackSize, ContextHandler , NULL , ContextHandler , ExitHandler);
while(1);
Parameters
ContextAllocated memory to initialize. It will be used as a context stack.
StackSizeSize of the stack. It is not equal to the allocation size (this size should be smaller)
ContextHandlerThe function that should be called, while this context is active
ParametersOptional parameter for the ContextHandler function
ExitHandlerThe function that should be called, when the context handler will finish.
Returns
code of error, or oC_ErrorCode_None if success
Note
stm32f7 notes:
lm4f notes:

Definition at line 419 of file oc_sys_lld.c.

bool oC_SYS_LLD_IsMachineSupportMultithreadMode ( void  )

The function checks if the machine supports multi-thread mode. It returns false if it is not supported or not implemented already.

Returns
true if the machine supports multi-thread mode and it is implemented.
Note
stm32f7 notes:
lm4f notes:

Definition at line 195 of file oc_sys_lld.c.

bool oC_SYS_LLD_IsStackPushDecrementPointer ( void  )

The function is for checking if stack push command is decrement or increment pointer on this machine.

Returns
true if after push, the address is decremented
Note
stm32f7 notes:
lm4f notes:

Definition at line 507 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_ReadPowerState ( float *  outVcc)

The function reads current power state (the VCC of the CPU)

Note
stm32f7 notes:
lm4f notes:

Definition at line 518 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_ReadSystemTimerFrequency ( oC_Frequency_t outFrequency)

The function is for reading frequency of the system timer.

Parameters
outFrequencya destination for the variable where the frequency should be saved.
Returns
code of error or #oC_ErrorCode_None if success
Note
stm32f7 notes:
lm4f notes:

Definition at line 299 of file oc_sys_lld.c.

void oC_SYS_LLD_Reset ( void  )

This function never returns.

Returns
code of error
Note
stm32f7 notes:
lm4f notes:

Definition at line 496 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_ReturnToSystemContext ( void  )

The function returns to the system context - the context, that was active, when the SYS LLD module was turned on.

Returns
code of error
Note
stm32f7 notes:
lm4f notes:

Definition at line 386 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_SetEventInterruptHandler ( oC_SYS_LLD_EventInterrupt_t  EventHandler,
oC_SYS_LLD_EventFlags_t  EventsFlags 
)

The function is for configuration of the event interrupts for the module. For information what events are handled, look at the oC_SYS_LLD_EventFlags_t type. The function configures and turns on each interrupt.

Parameters
EventHandlerPointer to the function that should be called, when event occurs
EventsFlagsEvents, that should be enabled
Note
Interrupt handler can be set only once. To set interrupt handler again, the SYS module must be restarted.
Returns
code of error, or #oC_ErrorCode_None if there is no error.
Note
stm32f7 notes:
lm4f notes:

Definition at line 164 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_SetNextContext ( oC_SYS_LLD_Context_t Context)

The function is for setting next context of the machine. It will save the pointer for later - the context will be switched with the first call of context switching interrupt. The context is the process stack. It should be allocated and initialized by oC_SYS_LLD_InitializeContext function before usage.

Warning
It is recommended to turn off interrupts before call of this function.
Note
stm32f7 notes:
lm4f notes:

Definition at line 321 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_TurnOffDriver ( void  )

The function is for releasing resources needed for the driver. The main driver should call it every time, when it is turned off. This function should restore default states in all resources, that are handled and was initialized by the driver. It must not protect by itself again turning off the driver when it is not turned on.

Note
When the module is turned off, this function restores the system context.
Returns
code of error, or #oC_ErrorCode_None if there is no error.
Note
stm32f7 notes:
lm4f notes: After this function it will return to the system context.

Definition at line 138 of file oc_sys_lld.c.

void oC_SYS_LLD_TurnOffInterrupts ( void  )

The function is for turning off interrupts. It not protect before recursive calling, each call of this function turns off interrupts.This function can be used also when module is turned off.

Note
stm32f7 notes:
lm4f notes:

Definition at line 217 of file oc_sys_lld.c.

oC_ErrorCode_t oC_SYS_LLD_TurnOnDriver ( void  )

The function is for initializing the low level driver. It will be called every time when the driver will turned on. There is no need to protect again returning because the main driver should protect it by itself.

Returns
code of error, or #oC_ErrorCode_None if there is no error.
Note
stm32f7 notes:
lm4f notes:

Definition at line 103 of file oc_sys_lld.c.

void oC_SYS_LLD_TurnOnInterrupts ( void  )

The function is for turning on interrupts. It not protect before recursive calling, each call of this function turns on interrupts. This function can be used also when module is turned off.

Note
stm32f7 notes:
lm4f notes:

Definition at line 206 of file oc_sys_lld.c.