WE310F5  39.00.000
M2MB OS

This section describes the M2MB APIs to perform various Operating systems operations. More...

#define vspfunc(...)   (0)
 
#define uart_print(...)
 
#define M2MB_OS_TASK_INVALID   0
 
#define M2MB_OS_TASK_INVALID_ATTR   0
 
#define M2MB_OS_TASK_AUTOSTART   1
 
#define M2MB_OS_TASK_NOT_START   0
 
#define M2MB_OS_ISR_ON   1
 
#define M2MB_OS_ISR_OFF   0
 
#define M2MB_OS_MIN_STACK_SIZE   1024
 
#define M2MB_FS_CAT   ( (UINT32)0 )
 
#define M2MB_SMS_CAT   ( (UINT32)1 )
 
#define M2MB_GNSS_CAT   ( (UINT32)2 )
 
#define M2MB_OS_CAT   ( (UINT32)3 )
 
#define M2MB_OS_ENTER_CRITICAL()   do { __asm("cpsid i"); } while(0)
 
#define M2MB_OS_EXIT_CRITICAL()   do { __asm("cpsie i"); } while(0)
 
enum  M2MB_OS_TASK_SEL_CMD_E {
  M2MB_OS_TASK_SEL_CMD_CREATE_ATTR,
  M2MB_OS_TASK_SEL_CMD_DEL_ATTR,
  M2MB_OS_TASK_SEL_CMD_NAME,
  M2MB_OS_TASK_SEL_CMD_USRNAME,
  M2MB_OS_TASK_SEL_CMD_STACK_START,
  M2MB_OS_TASK_SEL_CMD_STACK_SIZE,
  M2MB_OS_TASK_SEL_CMD_PRIORITY,
  M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH,
  M2MB_OS_TASK_SEL_CMD_TSLICE,
  M2MB_OS_TASK_SEL_CMD_AUTOSTART,
  M2MB_OS_TASK_SEL_CMD_STATE,
  M2MB_OS_TASK_SEL_CMD_RUN_CNT,
  M2MB_OS_TASK_SEL_CMD_END
}
 
enum  M2MB_OS_TASK_STATE_E {
  M2MB_OS_TASK_STATE_READY,
  M2MB_OS_TASK_STATE_COMPLETED,
  M2MB_OS_TASK_STATE_TERMINATED,
  M2MB_OS_TASK_STATE_SUSP,
  M2MB_OS_TASK_STATE_SLEEP,
  M2MB_OS_TASK_STATE_QUEUE_SUSP,
  M2MB_OS_TASK_STATE_SEMAPHORE_SUSP,
  M2MB_OS_TASK_STATE_SIG_SUSP,
  M2MB_OS_TASK_STATE_BLOCK_MEM_SUSP,
  M2MB_OS_TASK_STATE_BYTE_MEM_SUSP,
  M2MB_OS_TASK_STATE_MUTEX_SUSP = 0x0D,
  M2MB_OS_TASK_STATE_END
}
 
enum  M2MB_OS_MEMINFO_E {
  M2MB_OS_MEMINFO_FRAGMENTS,
  M2MB_OS_MEMINFO_BYTES_AVAILABLE,
  M2MB_OS_MEMINFO_SIZE,
  M2MB_OS_MEMINFO_END
}
 
typedef HANDLE M2MB_OS_TASK_HANDLE
 
typedef HANDLE M2MB_OS_TASK_ATTR_HANDLE
 
typedef void(* ENTRY_FN) (void *)
 
UINT32 M2MB_OS_MS2TICKS (UINT32 ms)
 
void * m2mb_os_malloc (UINT32 size)
 Allocates bytes of memory. More...
 
void * m2mb_os_calloc (UINT32 count, UINT32 size)
 Allocates bytes of memory and init space with 0. More...
 
void * m2mb_os_realloc (void *ptr, UINT32 size)
 
M2MB_OS_RESULT_E m2mb_os_free (void *pMem)
 Free allocated memory. More...
 
M2MB_OS_RESULT_E m2mb_os_init (void)
 Initialization of OS. More...
 
M2MB_OS_RESULT_E m2mb_os_taskCreate (M2MB_OS_TASK_HANDLE *pTaskHandle, M2MB_OS_TASK_ATTR_HANDLE *pTaskAttr, ENTRY_FN entryFn, void *pArg)
 Create application task. More...
 
M2MB_OS_RESULT_E m2mb_os_taskGetItem (M2MB_OS_TASK_HANDLE taskHandle, M2MB_OS_TASK_SEL_CMD_E selCmd, MEM_W *pOut, void *pIn)
 Get specific task properties. More...
 
M2MB_OS_RESULT_E m2mb_os_taskSetItem (M2MB_OS_TASK_HANDLE taskHandle, M2MB_OS_TASK_SEL_CMD_E selCmd, void *pIn)
 Set specific task properties. More...
 
M2MB_OS_RESULT_E m2mb_os_taskSetAttrItem (M2MB_OS_TASK_ATTR_HANDLE *pTaskAttrHandle, UINT8 nCmds,...)
 Set specific attribute for task creation. More...
 
M2MB_OS_TASK_HANDLE m2mb_os_taskGetId (void)
 Retrieves handle to the currently executing task. More...
 
M2MB_OS_RESULT_E m2mb_os_taskSuspend (M2MB_OS_TASK_HANDLE taskHandle)
 Suspend application task. More...
 
M2MB_OS_RESULT_E m2mb_os_taskResume (M2MB_OS_TASK_HANDLE taskHandle)
 Resume suspended application task. More...
 
M2MB_OS_RESULT_E m2mb_os_taskTerminate (M2MB_OS_TASK_HANDLE taskHandle)
 Terminates application task. More...
 
M2MB_OS_RESULT_E m2mb_os_taskRestart (M2MB_OS_TASK_HANDLE taskHandle)
 Task restart. More...
 
M2MB_OS_RESULT_E m2mb_os_taskDelete (M2MB_OS_TASK_HANDLE taskHandle)
 Task delete. More...
 
M2MB_OS_RESULT_E m2mb_os_taskCooperate (void)
 Make task to cooperate by releasing scheduler control. More...
 
M2MB_OS_RESULT_E m2mb_os_taskWaitAbort (M2MB_OS_TASK_HANDLE taskHandle)
 Abort suspension of a specified task. More...
 
UINT32 m2mb_os_getSysTicks (void)
 Get system time in ticks. More...
 
M2MB_OS_RESULT_E m2mb_os_setSysTicks (UINT32 newTick)
 Set start system time in ticks. More...
 
FLOAT32 m2mb_os_getSysTickDuration_ms (void)
 Get the duration of system tick in ms. More...
 
UINT8 m2mb_os_isrCtrl (UINT8 newIsrState)
 Enable and disable interrupts (ISRs) More...
 
M2MB_OS_RESULT_E m2mb_os_get_errno (UINT32 *pCategory, INT32 *pErrno)
 Allow to get Errno saved in a relative task environment. More...
 
int m2mb_thread_fp_enable (void)
 Sets the thread floating point unit flag. More...
 

Detailed Description

This section describes the M2MB APIs to perform various Operating systems operations.

Macro Definition Documentation

◆ M2MB_FS_CAT

#define M2MB_FS_CAT   ( (UINT32)0 )

Definition at line 88 of file m2mb_os.h.

◆ M2MB_GNSS_CAT

#define M2MB_GNSS_CAT   ( (UINT32)2 )

Definition at line 90 of file m2mb_os.h.

◆ M2MB_OS_CAT

#define M2MB_OS_CAT   ( (UINT32)3 )

Definition at line 91 of file m2mb_os.h.

◆ M2MB_OS_ENTER_CRITICAL

#define M2MB_OS_ENTER_CRITICAL ( )    do { __asm("cpsid i"); } while(0)

Definition at line 154 of file m2mb_os.h.

◆ M2MB_OS_EXIT_CRITICAL

#define M2MB_OS_EXIT_CRITICAL ( )    do { __asm("cpsie i"); } while(0)

Definition at line 155 of file m2mb_os.h.

◆ M2MB_OS_ISR_OFF

#define M2MB_OS_ISR_OFF   0

Definition at line 80 of file m2mb_os.h.

◆ M2MB_OS_ISR_ON

#define M2MB_OS_ISR_ON   1

Definition at line 79 of file m2mb_os.h.

◆ M2MB_OS_MIN_STACK_SIZE

#define M2MB_OS_MIN_STACK_SIZE   1024

Definition at line 83 of file m2mb_os.h.

◆ M2MB_OS_TASK_AUTOSTART

#define M2MB_OS_TASK_AUTOSTART   1

Definition at line 76 of file m2mb_os.h.

◆ M2MB_OS_TASK_INVALID

#define M2MB_OS_TASK_INVALID   0

Definition at line 73 of file m2mb_os.h.

◆ M2MB_OS_TASK_INVALID_ATTR

#define M2MB_OS_TASK_INVALID_ATTR   0

Definition at line 74 of file m2mb_os.h.

◆ M2MB_OS_TASK_NOT_START

#define M2MB_OS_TASK_NOT_START   0

Definition at line 77 of file m2mb_os.h.

◆ M2MB_SMS_CAT

#define M2MB_SMS_CAT   ( (UINT32)1 )

Definition at line 89 of file m2mb_os.h.

◆ uart_print

#define uart_print (   ...)

Definition at line 68 of file m2mb_os.h.

◆ vspfunc

#define vspfunc (   ...)    (0)

Definition at line 67 of file m2mb_os.h.

Typedef Documentation

◆ ENTRY_FN

typedef void( * ENTRY_FN) (void *)

Definition at line 100 of file m2mb_os.h.

◆ M2MB_OS_TASK_ATTR_HANDLE

Definition at line 97 of file m2mb_os.h.

◆ M2MB_OS_TASK_HANDLE

Definition at line 96 of file m2mb_os.h.

Enumeration Type Documentation

◆ M2MB_OS_MEMINFO_E

Enumerator
M2MB_OS_MEMINFO_FRAGMENTS 
M2MB_OS_MEMINFO_BYTES_AVAILABLE 
M2MB_OS_MEMINFO_SIZE 
M2MB_OS_MEMINFO_END 

Definition at line 142 of file m2mb_os.h.

◆ M2MB_OS_TASK_SEL_CMD_E

Enumerator
M2MB_OS_TASK_SEL_CMD_CREATE_ATTR 
M2MB_OS_TASK_SEL_CMD_DEL_ATTR 
M2MB_OS_TASK_SEL_CMD_NAME 

use as Os name

M2MB_OS_TASK_SEL_CMD_USRNAME 

if set, user name could be different from Os

M2MB_OS_TASK_SEL_CMD_STACK_START 
M2MB_OS_TASK_SEL_CMD_STACK_SIZE 
M2MB_OS_TASK_SEL_CMD_PRIORITY 
M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH 
M2MB_OS_TASK_SEL_CMD_TSLICE 

time slice: use max ticks for task to run when other tasks with same priority are ready

M2MB_OS_TASK_SEL_CMD_AUTOSTART 

start task soon after m2mb_os_taskCreate is called: no need to call m2mb_os_taskResume

M2MB_OS_TASK_SEL_CMD_STATE 
M2MB_OS_TASK_SEL_CMD_RUN_CNT 

task running count

M2MB_OS_TASK_SEL_CMD_END 

Definition at line 102 of file m2mb_os.h.

◆ M2MB_OS_TASK_STATE_E

Enumerator
M2MB_OS_TASK_STATE_READY 
M2MB_OS_TASK_STATE_COMPLETED 
M2MB_OS_TASK_STATE_TERMINATED 
M2MB_OS_TASK_STATE_SUSP 
M2MB_OS_TASK_STATE_SLEEP 
M2MB_OS_TASK_STATE_QUEUE_SUSP 
M2MB_OS_TASK_STATE_SEMAPHORE_SUSP 
M2MB_OS_TASK_STATE_SIG_SUSP 
M2MB_OS_TASK_STATE_BLOCK_MEM_SUSP 
M2MB_OS_TASK_STATE_BYTE_MEM_SUSP 
M2MB_OS_TASK_STATE_MUTEX_SUSP 
M2MB_OS_TASK_STATE_END 

Definition at line 123 of file m2mb_os.h.

Function Documentation

◆ m2mb_os_calloc()

void* m2mb_os_calloc ( UINT32  count,
UINT32  size 
)

Allocates bytes of memory and init space with 0.

This function provides service to reserve memory space to the caller and initialize it to 0

Parameters
[in]countNumber of blocks of memory to be allocated
[in]sizesize in byte of memory to be allocated and initialize
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_NO_MEMORY Service was unable to allocate the memory M2MB_OS_SIZE_ERROR Requested size is zero or larger than the heap size M2MB_OS_CALLER_ERROR Invalid caller of this service
Note
The performance of this service is a function of the requested block size and the amount of fragmentation in the heap. Hence, this service should not be used during time-critical task of execution. Allowed From Initialization and tasks Preemption Possible Yes

Example

//pointer to 10 UINT32
typedf struct
{
INT32 a;
INT8 b;
void *ptr;
}GEN_T;
GEN_T *pStruct;
pStruct = ( GEN_T * )m2mb_os_calloc( sizeof(GEN_T) );
if ( pStruct == NULL )
exit(...)
//all pStruct initialized to 0: pStruct->a = 0; pStruct->b = 0; pStruct->ptr = 0;

◆ m2mb_os_free()

M2MB_OS_RESULT_E m2mb_os_free ( void *  pMem)

Free allocated memory.

This function provides service to free already allocated memory space

Parameters
[in]pMempointer to memory where to release previous allocation
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_PTR_ERROR Invalid memory area pointer M2MB_OS_CALLER_ERROR Invalid caller of this service
Note
The application must prevent using the memory area after it is released. Allowed From Initialization and tasks Preemption Possible Yes

Example

osRes = m2mb_os_free( pStruct );
if ( osRes != M2MB_OS_SUCCESS )
//...

◆ m2mb_os_get_errno()

M2MB_OS_RESULT_E m2mb_os_get_errno ( UINT32 pCategory,
INT32 pErrno 
)

Allow to get Errno saved in a relative task environment.

This service allows to get last error number task safe, with the specified type of category for the error. It checks the error in the environment task in which the function is called, so to check the error, call it with this in mind

Parameters
[out]pCategorypointer for environment category the error is relative
[out]pErrnopointer to the variable where to set the error
Returns
M2MB_OS_INVALID_ARG if a not valid or recognized task calls the service
M2MB_OS_SUCCESS for success
Note

Example

INT32 pErrno;
INT32 pCategory;
//get last error if any
res = m2mb_os_get_errno( &pCategory, &pErrno );
// the error will be in the form: category - error
// e.g M2MB_OS_CAT - M2MB_OS_QUEUE_ERROR if res = M2MB_OS_SUCCESS

◆ m2mb_os_getSysTickDuration_ms()

FLOAT32 m2mb_os_getSysTickDuration_ms ( void  )

Get the duration of system tick in ms.

This service returns the value of the duration in ms of tick used inside the system

Returns
Duration of a system tick in case of success
0 in case of errors or service not available
Note
Please check your system to verify if this feature is even supported

Example

◆ m2mb_os_getSysTicks()

UINT32 m2mb_os_getSysTicks ( void  )

Get system time in ticks.

This service returns the contents of the internal system clock. Each timer- tick increases the internal system clock by one. The system clock is set to zero during initialization and can be changed to a specific value by the service m2mb_os_setSysTicks.

Returns
system clock ticks. Value of the internal, free running, system clock.
Note
The actual time each timer-tick represents is application specific. Please check your system Allowed From Initialization, tasks, timers, and ISRs Preemption Possible No

Example

◆ m2mb_os_init()

M2MB_OS_RESULT_E m2mb_os_init ( void  )

Initialization of OS.

Init of operating systems. Should be called as initialization process, before calling any other function of OS Simple init function which will setup the OS environment for next usage

Returns
M2MB_OS_SUCCESS in case of success
others in case of error : see m2mb_os_types.h
Note
<Notes>

Example

◆ m2mb_os_isrCtrl()

UINT8 m2mb_os_isrCtrl ( UINT8  newIsrState)

Enable and disable interrupts (ISRs)

This service enables or disables interrupts as specified by the input parameter newIsrState. If this service is called from an application task, the interrupt isrState remains part of that thread’s context. For example, if the thread calls this routine to disable interrupts and then suspends, when it is resumed, interrupts are disabled again.

Parameters
[in]newIsrStatevalue to be set for ISR
Returns
State of the current ISR Set to NULL if not needed. It could be M2MB_OS_ISR_ON or M2MB_OS_ISR_OFF. This allows users of the service to restore the previous state after interrupts are disabled.
Note
Allowed From tasks, timers, and ISRs Preemption Possible No

Example

UINT8 oldIsrState;
//Lockout interrupts
oldIsrState = m2mb_os_interruptCtrl( M2MB_OS_ISR_OFF );
//perform critical operation
//here current state is not needed
m2mb_os_interruptCtrl( oldIsrState );

◆ m2mb_os_malloc()

void* m2mb_os_malloc ( UINT32  size)

Allocates bytes of memory.

This function provides service to reserve memory space to the caller

Parameters
[in]sizesize in byte of memory to be allocated
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_NO_MEMORY Service was unable to allocate the memory M2MB_OS_SIZE_ERROR Requested size is zero or larger than the heap size M2MB_OS_CALLER_ERROR Invalid caller of this service
Note
The performance of this service is a function of the requested block size and the amount of fragmentation in the heap. Hence, this service should not be used during time-critical task of execution. Allowed From Initialization and tasks Preemption Possible Yes

pointer to 10 UINT32 UINT32 *pUint; pUint = ( UINT32 * )m2mb_os_malloc( 10 * sizeof(UINT32) ); if ( pUint == NULL ) exit(...)

◆ M2MB_OS_MS2TICKS()

UINT32 M2MB_OS_MS2TICKS ( UINT32  ms)

◆ m2mb_os_realloc()

void* m2mb_os_realloc ( void *  ptr,
UINT32  size 
)

◆ m2mb_os_setSysTicks()

M2MB_OS_RESULT_E m2mb_os_setSysTicks ( UINT32  newTick)

Set start system time in ticks.

This service sets the internal system clock to the specified value. Each timer-tick increases the internal system clock by one.

Parameters
[in]newTickNew value to be set in system clock
Returns
M2MB_OS_SUCCESS only
Note
The actual time each timer-tick represents is application specific. Please check your system to verify if this feature is even supported Allowed From Threads, timers, and ISRs Preemption Possible No

Example

◆ m2mb_os_taskCooperate()

M2MB_OS_RESULT_E m2mb_os_taskCooperate ( void  )

Make task to cooperate by releasing scheduler control.

This service give control to scheduler if other tasks are ready-to-run at the same or higher priority. This is a method to allow other tasks at the same priority to be executed. Think about while1 tasks...

Returns
M2MB_OS_SUCCESS always
Note
Allowed From Tasks Preemption Possible Yes

Example

//suppose to have 2 tasks at the same priority
void entryTask1 (void *arg)
{
while(1)
{
// operation of task1
// only task1 can run: processor dedicated to it
m2mb_os_taskCooperate(); //let task2 to be executed
}
}
void entryTask2 (void *arg)
{
while(1)
{
// operation of task2
// only task2 can run: processor dedicated to it
m2mb_os_taskCooperate(); //let task1 to be executed
}
}
//so after every cycle, tasks will give room to others to be executed

◆ m2mb_os_taskCreate()

M2MB_OS_RESULT_E m2mb_os_taskCreate ( M2MB_OS_TASK_HANDLE pTaskHandle,
M2MB_OS_TASK_ATTR_HANDLE pTaskAttr,
ENTRY_FN  entryFn,
void *  pArg 
)

Create application task.

This service creates an application task that starts execution at the specified task entry function. The stack, priority, preemption-threshold, time-slice, and initial execution state of the task are among the attributes specified by the input parameters in pTaskAttr. If stack is not provided, it will be allocated by the system and removed after task deletion. If stack size is not provided, the minimum stack size M2MB_OS_MIN_STACK_SIZE will be allocated.

Parameters
[in]pTaskHandlepointer to Handle of the task to be used for future calling the specific task
[in]pTaskAttrhandle Attribute and options of the task to be created
[in]entryFnFunction which will be the start for the task
[in]pArgpointer - argument of the entry function of the task
Returns
M2MB_OS_SUCCESS in case of success (others in case of error : see m2mb_os_types.h)
A lot of errors can be revealed using m2mb_os_setTaskAttr (set attribute), since they are related to the attribute setting mechanism M2MB_OS_TASK_ERROR Invalid task handler, or the task is already created M2MB_OS_PTR_ERROR Invalid starting address of the entry point or the stack area in Attr is invalid, usually NULL M2MB_OS_SIZE_ERROR Size of stack area in Attr is invalid. M2MB_OS_PRIORITY_ERROR Priority set in Attr is out of range or invalid M2MB_OS_THRESH_ERROR Invalid preemption- threshold specified in Attr. The value should be less or equal to priority M2MB_OS_START_ERROR Invalid auto-start selection in Attr M2MB_OS_CALLER_ERROR Invalid caller of this service
Note
After successful creation of task, M2MB_OS_TASK_ATTR_HANDLE will be deleted and relative pointer set to NULL Allowed From Initialization and tasks Preemption Possible Yes Example

◆ m2mb_os_taskDelete()

M2MB_OS_RESULT_E m2mb_os_taskDelete ( M2MB_OS_TASK_HANDLE  taskHandle)

Task delete.

This service deletes the specified application task. Since the specified task must be in a terminated or completed state, this service cannot be called from a task attempting to delete itself.

Parameters
[in,out]taskHandlehandle of the task to be deleted: after release it is set to M2MB_OS_TASK_INVALID
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_TASK_ERROR Invalid application task pointer M2MB_OS_DELETE_ERROR Specified thread is not in a terminated or completed state M2MB_OS_CALLER_ERROR Invalid caller of this service
Note
It is the application’s responsibility to manage the memory area associated with the tasks stack, which is available after this service completes. All the resources will be released and the taskHandle set to M2MB_OS_TASK_INVALID In addition, the application must prevent use of a deleted task.

Allowed From Tasks and timers Preemption Possible No

Example

◆ m2mb_os_taskGetId()

M2MB_OS_TASK_HANDLE m2mb_os_taskGetId ( void  )

Retrieves handle to the currently executing task.

The function return the handle of the currently executing task This Function is used to get task handle of the currently executing task

Returns
M2MB_OS_TASK_HANDLE of the current task
M2MB_OS_TASK_INVALID in case of error
Note
Allowed From Threads and ISRs Preemption Possible No

Example

taskHandle = m2mb_os_taskGetId();

◆ m2mb_os_taskGetItem()

M2MB_OS_RESULT_E m2mb_os_taskGetItem ( M2MB_OS_TASK_HANDLE  taskHandle,
M2MB_OS_TASK_SEL_CMD_E  selCmd,
MEM_W pOut,
void *  pIn 
)

Get specific task properties.

This function retrieves special information of the specified task Selecting cmd, a parameter to be retrieved can be set To be used when a task is already created: its right usage is under application responsibility

Parameters
[in]taskHandleTask handle identifies the task to get parameter from
[in]selCmdSelect parameter to be retrieved (see M2MB_OS_TASK_SEL_CMD_E)
[out]pOutpointer Output parameter got: its meaning depends on selCmd used See examples
[in]pInpointer to Parameter to be specified, if any, to get right output See examples If the parameter is not needed, use NULL
Returns
M2MB_OS_SUCCESS in case of success
others in case of error : see m2mb_os_types.h
Note
Allowed From Initialization, tasks, timers, and ISRs Preemption Possible No

Example

CHAR MyTaskName[10];
CHAR *getName;
MEM_W stackStart;
memset(MyTaskName,0,10);
memcpy(MyTaskName, getName, strlen(getName)>10 ? 10: strlen(getName));
or
//copy only the first 10 chars to MyTaskName array of chars
// or simply get the pointer of name, with NULL
//get the current state of the task
// and so on
// option to set single attribute: see below to set all at once
//or simply all at once
// m2mb_os_taskSetAttrItem( &taskAttr,
// CMDS(
// M2MB_OS_TASK_SEL_CMD_CREATE_ATTR,
// M2MB_OS_TASK_SEL_CMD_STACK_SIZE,
// M2MB_OS_TASK_SEL_CMD_NAME,
// M2MB_OS_TASK_SEL_CMD_PRIORITY,
// M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH,
// M2MB_OS_TASK_SEL_CMD_AUTOSTART,
// M2MB_OS_TASK_SEL_CMD_USRNAME
// ),
// NULL, (void*)2048, "MyTask", (void*)201, (void*)201,
// (void*)M2MB_OS_TASK_AUTOSTART, "myUserTask"
// )
// or using CMDS_ARGS...
// m2mb_os_taskSetAttrItem( &taskAttr,
// CMDS_ARGS (
// M2MB_OS_TASK_SEL_CMD_CREATE_ATTR, NULL,
// M2MB_OS_TASK_SEL_CMD_STACK_SIZE, 2048,
// M2MB_OS_TASK_SEL_CMD_NAME, "MyTask",
// M2MB_OS_TASK_SEL_CMD_PRIORITY, 201,
// M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH, 201,
// M2MB_OS_TASK_SEL_CMD_AUTOSTART, M2MB_OS_TASK_AUTOSTART,
// M2MB_OS_TASK_SEL_CMD_USRNAME, "myUserTask"
// )
// );
m2mb_os_taskCreate( &taskHandle, &taskAttr, entry, (void*)1,);
// ....
void entry (void *arg)
{
MEM_W out = 0;
UINT32 id = (UINT32)arg;
printf("\r\n Hello from Task argv [%d] ", id);
printf ( "\r\n name %s ", (char*)out );
printf ( "\r\n stack start 0x%x ", out );
printf ( "\r\n stack size %xd ", out );

◆ m2mb_os_taskRestart()

M2MB_OS_RESULT_E m2mb_os_taskRestart ( M2MB_OS_TASK_HANDLE  taskHandle)

Task restart.

This service resets the specified task to execute at the entry point defined during task creation. The task must be in either a M2MB_OS_TASK_STATE_COMPLETED or M2MB_OS_TASK_STATE_TERMINATED state for it to be restarted It is in: M2MB_OS_TASK_STATE_COMPLETED when reached the

Returns
of entry function M2MB_OS_TASK_STATE_TERMINATED when terminated by m2mb_os_taskTerminate
Parameters
[in]taskHandlehandle of the task to be restarted
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_INVALID_ARG invalid taskHandle M2MB_OS_NOT_DONE specified task is not in compliant state to be restarted M2MB_OS_CALLER_ERROR invalid caller
Note
Allowed From Tasks

Example

◆ m2mb_os_taskResume()

M2MB_OS_RESULT_E m2mb_os_taskResume ( M2MB_OS_TASK_HANDLE  taskHandle)

Resume suspended application task.

This service resumes or prepares for execution a task that was previously suspended by a m2mb_os_taskSuspend call. In addition, this service resumes tasks that were created without an automatic start.

Parameters
[in]taskHandlehandle of the task to resume
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_INVALID_ARG in case of invalid taskHandle M2MB_OS_SUSPEND_LIFTED Previously set delayed suspension was lifted M2MB_OS_RESUME_ERROR task is not suspended or it is suspended for reasons other than m2mb_os_taskSuspend call M2MB_OS_CALLER_ERROR invalid caller
Note
Allowed From Initialization, tasks, timers, and ISRs

Example

◆ m2mb_os_taskSetAttrItem()

M2MB_OS_RESULT_E m2mb_os_taskSetAttrItem ( M2MB_OS_TASK_ATTR_HANDLE pTaskAttrHandle,
UINT8  nCmds,
  ... 
)

Set specific attribute for task creation.

Attribute defined can be used to create the task

Parameters
[in,out]pTaskAttrHandlePointer to M2MB_OS_TASK_ATTR_HANDLE handle to be set
[in]nCmds
Number of commands to be issued at once
[in]...variable inputs, N cmds (see M2MB_OS_TASK_SEL_CMD_E) followed by N arguments for their respective issued commands. CMDS(...) and CMDS_ARGS(...) macro can be used to better insert cmd and parameters and to better control right insertion
Returns
M2MB_OS_SUCCESS in case of success
Others in case of error : see m2mb_os_types.h
Note
The attribute set are useful for task creation. Once created, use instead m2mb_os_taskSetItem() to set only available task properties After m2mb_os_taskCreate call, M2MB_OS_TASK_ATTR_HANDLE handle will be automatically free and its value set to M2MB_OS_TASK_INVALID_ATTR To set multi parameters at once, make use of macro CMDS(...) or CMDS_ARGS: see m2mb_os_taskCreate section It is under application responsibility the right use of m2mb_os_taskSetAttrItem. For instance, multi creation of attrHandle without free of previous resources ( M2MB_OS_TASK_SEL_CMD_CREATE_ATTR without M2MB_OS_TASK_SEL_CMD_DEL_ATTR in case no m2mb_os_taskCreate is used in the between ) will waste memory.

Allowed From Initialization, tasks, timers, and ISRs Preemption Possible Yes

Example

exit(ERROR_CREATE_ATTR);
//...
// In case
//or using macro CMDS(...)
// m2mb_os_taskSetAttrItem( &taskAttr,
// CMDS(
// M2MB_OS_TASK_SEL_CMD_CREATE_ATTR,
// M2MB_OS_TASK_SEL_CMD_NAME,
// M2MB_OS_TASK_SEL_CMD_PRIORITY
// ),
// NULL, "myTask", 101
// );
// or using macro CMDS_ARGS(...)
// m2mb_os_taskSetAttrItem( &taskAttr,
// CMDS_ARGS(
// M2MB_OS_TASK_SEL_CMD_CREATE_ATTR, NULL,
// M2MB_OS_TASK_SEL_CMD_NAME, "myTask",
// M2MB_OS_TASK_SEL_CMD_PRIORITY, 101
// ),
// );

◆ m2mb_os_taskSetItem()

M2MB_OS_RESULT_E m2mb_os_taskSetItem ( M2MB_OS_TASK_HANDLE  taskHandle,
M2MB_OS_TASK_SEL_CMD_E  selCmd,
void *  pIn 
)

Set specific task properties.

This function sets value for a specified parameter of the specified task Selecting cmd, a parameter to be set can be selected To be used when a task is already created: it is under application responsibility

Parameters
[in]taskHandleTask handle identifies the task to set parameter to
[in]selCmdSelect parameter to be set (see M2MB_OS_TASK_SEL_CMD_E)
[in]pInPointer as value of parameter is to be set to the specified parameter
Returns
M2MB_OS_SUCCESS in case of success
Others in case of error : see m2mb_os_types.h
Note
Allowed From tasks and timers Preemption Possible Yes

Example

//used myTask; already created
char *MyTaskName[] = "myModule";
MEM_W stackStart = 0x52000100;
MEM_W stackSize = 0x1000;
// and so on

◆ m2mb_os_taskSuspend()

M2MB_OS_RESULT_E m2mb_os_taskSuspend ( M2MB_OS_TASK_HANDLE  taskHandle)

Suspend application task.

This service suspends the specified application task. A task may call this service to suspend itself. After being suspended, the task must be resumed by m2mb_os_taskResume to execute again.

Parameters
[in]taskHandlehandle of the task to suspend
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_INVALID_ARG in case of invalid taskHandle M2MB_OS_SUSPEND_ERROR task is already in suspended or terminated state M2MB_OS_CALLER_ERROR invalid caller
Note
Allowed From Initialization, tasks, timers, and ISRs

If the specified task is already suspended for another reason, this suspension is held internally until the prior suspension is lifted. When that happens, this unconditional suspension of the specified task is performed. Further unconditional suspension requests have no effect.

Example

◆ m2mb_os_taskTerminate()

M2MB_OS_RESULT_E m2mb_os_taskTerminate ( M2MB_OS_TASK_HANDLE  taskHandle)

Terminates application task.

This service terminates the specified application task regardless of whether the task is suspended or not. A task may call this service to terminate itself. After being terminated, the task must be restarted through m2mb_os_taskRestart for it to execute again.

Parameters
[in]taskHandlehandle of the task to terminate
Returns
M2MB_OS_SUCCESS in case of success
M2MB_OS_INVALID_ARG invalid taskHandle M2MB_OS_CALLER_ERROR invalid caller M2MB_OS_CALLER_ERROR invalid caller
Note
Allowed From tasks and timers Preemption Possible Yes

Example

◆ m2mb_os_taskWaitAbort()

M2MB_OS_RESULT_E m2mb_os_taskWaitAbort ( M2MB_OS_TASK_HANDLE  taskHandle)

Abort suspension of a specified task.

This service aborts sleep or any other object suspension of the specified task. If the wait is aborted, a M2MB_OS_WAIT_ABORTED value is returned from the service that the task was waiting on. This service does not release explicit suspension that is made by the m2mb_os_taskSuspend service.

Parameters
[in]taskHandleHandle of the task
Returns
M2MB_OS_SUCCESS in case of success
Others in case of error : see m2mb_os_types.h
Note
Allowed From Initialization, tasks, timers, and ISRs Preemption Possible Yes

Example of use:

...
m2mb_os_taskSetAttrItem( &taskAttr,
)
);
m2mb_os_taskCreate( &taskHandle2, &taskAttr, entry2, ( void * )2 );
)
);
m2mb_os_taskCreate( &taskHandle3, &taskAttr, entry3, ( void * )3 );
//create a semaphore
),
);
m2mb_os_sem_init( &sem, &semAttr );
...
void entry2( void *arg )
{
UINT32 id = ( UINT32 )arg;
... printf( "\r\n Task [%d], Result: %d ", id, osRes);
}
void entry3( void *arg )
{
UINT32 id = ( UINT32 )arg;
osRes = m2mb_os_taskWaitAbort( taskHandle2 );
... printf( "\r\n Task [%d], Result: %d ", id, osRes);
}

◆ m2mb_thread_fp_enable()

int m2mb_thread_fp_enable ( void  )

Sets the thread floating point unit flag.

By default, FPU support is disabled for each thread. If context of the FPU registers need to be saved, this API call must be made from the context of the application thread before the FPU usage.

Returns
0 on success
Note

Example