m2mb API docs  25.30.003
m2mb API sets documentation
m2mb_os.h File Reference

Basic functionality of Operating systems. More...

Go to the source code of this file.

Macros

#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_taskSetAttrItem_(h, args...)   m2mb_os_taskSetAttrItem( h, CMDS_ARGS( args ) )
 

Typedefs

typedef struct M2MB_OS_TASK_ATTR_HANDLE_TAG * M2MB_OS_TASK_ATTR_HANDLE
 
typedef struct M2MB_OS_TASK_HANDLE_TAG * M2MB_OS_TASK_HANDLE
 
typedef void(* ENTRY_FN) (void *)
 

Enumerations

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_BYTES_MAX_OCCUPATION = 6,
  M2MB_OS_MEMINFO_END
}
 

Functions

UINT32 M2MB_OS_MS2TICKS (UINT32 ms)
 Convert ms to ticks. More...
 
void * m2mb_os_malloc (UINT32 size)
 Allocates bytes of memory. More...
 
void * m2mb_os_calloc (UINT32 size)
 Allocates bytes of memory and init space with 0. More...
 
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_RESULT_E m2mb_os_taskSleep (UINT32 ticks)
 Suspend current task for specified time in ticks. 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 coperate by releasing scheduler control. More...
 
M2MB_OS_RESULT_E m2mb_os_taskWaitAbort (M2MB_OS_TASK_HANDLE taskHandle)
 Abort suspension of specified task. More...
 
MEM_W 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 duration of system tick in ms. More...
 
M2MB_OS_RESULT_E m2mb_os_get_errno (UINT32 *pCategory, INT32 *pErrno)
 Allow to get Errno saved in relative task environment. More...
 
M2MB_OS_RESULT_E m2mb_os_memInfo (M2MB_OS_MEMINFO_E memInfoSelect, MEM_W *pOut)
 Returns dynamic memory (HEAP) information. More...
 
void * m2mb_os_realloc (void *ptr, UINT32 size)
 Dynamic memory reallocation. More...
 
M2MB_OS_RESULT_E m2mb_os_RAMAvail (MEM_W *p_total, MEM_W *p_available)
 

Detailed Description

Basic functionality of Operating systems.

m2m/m2m_generic/common/m2mb_inc/m2mb_os.h

Majors task related functionalities are defined, plus some systems info and settings e.g. system timer tick

@notes Dependencies: m2mb_types.h m2mb_os_types.h m2mb_platform_conf.h

Author
Alessandro Papagno
Date
01/03/2017

Function Documentation

◆ m2mb_os_calloc()

void* m2mb_os_calloc ( 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]sizesize in byte of memory to be allocated and initialize
Returns
valid pointer in case of success
NULL in case of error
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

M2MB_OS_RESULT_E osRes;
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 relative task environment.

This service allow 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;
UINT32 pCategory;
M2MB_OS_RESULT_E res;
//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 duration of system tick in ms.

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

Parameters
[out]pTickDurationpointer to address of variable to be updated
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()

MEM_W 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_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
valid pointer in case of success
NULL in case of error
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_memInfo()

M2MB_OS_RESULT_E m2mb_os_memInfo ( M2MB_OS_MEMINFO_E  memInfoSelect,
MEM_W *  pOut 
)

Returns dynamic memory (HEAP) information.

This function returns dynamic memory (HEAP) information: -the total number of memory fragments -the total number of available bytes -the total memory size

Parameters
[in]*memInfoSelectpointer of information required type: M2MB_OS_MEMINFO_E
[out]*pOutpointer of information required value
Returns
M2MB_OS_SUCCESS for success
others in case of error : see m2mb_os_types.h
Note

Example

M2MB_OS_RESULT_E res;
MEM_W fragments, bytes_available, size;
res = m2mb_os_memInfo( M2MB_OS_MEMINFO_FRAGMENTS, &fragments );
if ( res != M2MB_OS_SUCCESS )
{
PrintToUart("\n Memory Information fragments error %d", res);
return;
}
res = m2mb_os_memInfo( M2MB_OS_MEMINFO_BYTES_AVAILABLE, &bytes_available );
if ( res != M2MB_OS_SUCCESS )
{
PrintToUart("\n Memory Information bytes available error %d", res);
return;
}
res = m2mb_os_memInfo( M2MB_OS_MEMINFO_SIZE, &size );
if ( res != M2MB_OS_SUCCESS )
{
PrintToUart("\n Memory Information size error %d", res);
return;
}
PrintToUart("\n Memory Informations: \n MEMINFO_FRAGMENTS: %d \n BYTES_AVAILABLE: %d \n MEMORY_SIZE: %d \n", fragments, bytes_available, size);

◆ M2MB_OS_MS2TICKS()

UINT32 M2MB_OS_MS2TICKS ( UINT32  ms)

Convert ms to ticks.

This functions converts input expressed as millisecond in number of ticks Can be used in functions which require number of ticks as arguments, providing ticks got from ms

Parameters
[in]msInput value expressed in ms
Returns
Number of Ticks to cover requested ms
Note
Usually maximum number of ticks which can be used in a function ( e.g see m2mb_os_taskSleep ) is defined by the function itself: e.g. for UINT32 it is 0xFFFF FFFF M2MB_OS_MS2TICKS is instead limited in ms input to UINT32, so in principle cannot cover all range of ticks. If needed calculate the ticks and place directly the value in dedicated function. E.g. if tick is 16 ms wide, 0xFFFF FFFF ms will provide maximum 0xFFF FFFF ticks instead of 0xFFFF FFFF available in functions requiring ticks as argument. By the way 0xFFFF FFFF ms is something like 1193 hours

// make the task wait for 10 s

◆ m2mb_os_realloc()

void* m2mb_os_realloc ( void *  ptr,
UINT32  size 
)

Dynamic memory reallocation.

Changes the size of the memory block pointed to by ptr.

The function may move the memory block to a new location (whose address is returned by the function).

The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. If the new size is larger, the value of the newly allocated portion is indeterminate.

In case that ptr is a null pointer, the function behaves like malloc, assigning a new block of size bytes and returning a pointer to its beginning.

Parameters
[in]

◆ 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 coperate 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 cicle, 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. In case stack is provided, some space will be lost due to internal management structures, so the area available will be a bit less than the area provided If stack size is not provided, minimum stack size M2MB_OS_MIN_STACK_SIZE will be allocated.

Parameters
[out]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)
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 successfull creation of task, M2MB_OS_TASK_ATTR_HANDLE will be deleted and relative pointer set to M2MB_OS_TASK_INVALID_ATTR Up to the user to remove the resources of attribute in case of failure during task creation Allowed From Initialization and tasks Preemption Possible Yes Example
M2MB_OS_RESULT_E osRes;
M2MB_OS_TASK_ATTR_HANDLE taskAttrHandle;
M2MB_OS_TASK_HANDLE taskHandle = M2MB_OS_TASK_INVALID;
UINT16 OFFSET = 1;
//3 methods are shown:
// ###### single attribute set n times
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_CREATE_ATTR, NULL);
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_NAME, "myTask" );
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_PRIORITY, 201 );
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH, 201 );
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_AUTOSTART, M2MB_OS_TASK_AUTOSTART );
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_USRNAME, "myUserTask" );
// ###### CMD macro usage: multi commands, followed by their relative associated parameter
m2mb_os_taskSetAttrItem( &taskAttrHandle,
CMDS(
M2MB_OS_TASK_SEL_CMD_CREATE_ATTR,
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, "myTask", 201, 201, M2MB_OS_TASK_AUTOSTART, "myUserTask"
);
// ###### CMDS_ARGS macro usage: multi commands, each followed by its own parameter
// arithmetic operation MUST BE INCLUDED in brackets: e.g M2MB_OS_TASK_SEL_CMD_PRIORITY, ( 200 + OFFSET ),
m2mb_os_taskSetAttrItem( &taskAttrHandle,
CMDS_ARGS(
M2MB_OS_TASK_SEL_CMD_CREATE_ATTR, NULL,
M2MB_OS_TASK_SEL_CMD_NAME, "myTask",
M2MB_OS_TASK_SEL_CMD_PRIORITY, ( 200 + OFFSET ),
M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH, ( 200 + OFFSET ),
M2MB_OS_TASK_SEL_CMD_AUTOSTART, M2MB_OS_TASK_AUTOSTART,
M2MB_OS_TASK_SEL_CMD_USRNAME, "myUserTask"
)
);
osRes = m2mb_os_taskCreate( &taskHandle, &taskAttrHandle, entry, (void*)1 );
if ( osRes != M2MB_OS_SUCCESS )
{
m2mb_os_taskSetAttrItem( &taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_DEL_ATTR, NULL );
}

◆ 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

◆ 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

M2MB_OS_TASK_HANDLE taskHandle;
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 retrieve special information of the specified task Selecting cmd, a parameter to be retrieved can be set To be used when task is already created: its right usage is under application responsibility

Parameters
[in]taskHandleTask handle identify 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 depend on selCmd used See examples
[in]pInpointer to Parameter to be specified, if any, to get right output See examples If 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
Not all M2MB_OS_TASK_SEL_CMD_E are allowed. Of course not Allowed: M2MB_OS_TASK_SEL_CMD_CREATE_ATTR M2MB_OS_TASK_SEL_CMD_DEL_ATTR

Example

M2MB_OS_TASK_HANDLE myTask;
CHAR MyTaskName[10];
CHAR *getName;
M2MB_OS_TASK_STATE_E taskState;
MEM_W stackStart;
memset(MyTaskName,0,10);
m2mb_os_taskGetItem(myTask, M2MB_OS_TASK_SEL_CMD_NAME, (MEM_W*)&getName, NULL);
memcpy(MyTaskName, getName, strlen(getName)>10 ? 10: strlen(getName));
or
m2mb_os_taskGetItem(myTask, M2MB_OS_TASK_SEL_CMD_NAME, (MEM_W*)&MyTaskName, 10);
m2mb_os_taskGetItem(myTask, M2MB_OS_TASK_SEL_CMD_STACK_START, (MEM_W*)&stackStart, NULL);
//copy only the first 10 chars to MyTaskName array of chars
m2mb_os_taskGetItem(myTask, M2MB_OS_TASK_SEL_CMD_USRNAME, (MEM_W*)&MyTaskName, 10);
// or simply get the pointer of name, with NULL
m2mb_os_taskGetItem(myTask, M2MB_OS_TASK_SEL_CMD_USRNAME, (MEM_W*)&getName, NULL);
//get the currrent state of the task
m2mb_os_taskGetItem(myTask, M2MB_OS_TASK_SEL_CMD_STATE, (MEM_W*)&taskState, NULL);
// and so on
M2MB_OS_TASK_ATTR_HANDLE taskAttrHandle;
M2MB_OS_TASK_HANDLE taskHandle = M2MB_OS_TASK_INVALID;
// option to set single attribute: see below to set all at once
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_CREATE_ATTR, NULL);
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_STACK_SIZE, 2048);
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_NAME, "MyTask" );
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_PRIORITY, 201 );
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH, 201 );
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_AUTOSTART, M2MB_OS_TASK_AUTOSTART );
m2mb_os_taskSetAttrItem(&taskAttrHandle, 1, M2MB_OS_TASK_SEL_CMD_USRNAME, "myUserTask" );
//or simply all at once
// m2mb_os_taskSetAttrItem( &taskAttrHandle,
// 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...
// NB: // arithmetic operation MUST BE INCLUDED in brackets: e.g M2MB_OS_TASK_SEL_CMD_PRIORITY, ( 200 + OFFSET ),
//
// m2mb_os_taskSetAttrItem( &taskAttrHandle,
// 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, &taskAttrHandle, entry, (void*)1,);
// ....
void entry (void *arg)
{
MEM_W out = 0;
UINT32 id = (UINT32)arg;
M2MB_OS_TASK_HANDLE handle = m2mb_os_taskGetId();
printf("\r\n Hello from Task argv [%d] ", id);
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_NAME, &out, NULL );
printf ( "\r\n name %s ", (char*)out );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_STACK_START, &out, NULL );
printf ( "\r\n stack start 0x%x ", out );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_STACK_SIZE, &out, NULL );
printf ( "\r\n stack size %xd ", out );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_PRIORITY, &out, NULL );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH, &out, NULL );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_TSLICE, &out, NULL );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_USRNAME, &out, NULL );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_STATE, &out, NULL );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_RUN_CNT, &out, NULL );
m2mb_os_taskGetItem( handle, M2MB_OS_TASK_SEL_CMD_AUTOSTART, &out, NULL );

◆ 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 restarded It is in: M2MB_OS_TASK_STATE_COMPLETED when return of its entry function has been reached M2MB_OS_TASK_STATE_TERMINATED when it has been 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 In case stack is provided, ( M2MB_OS_TASK_SEL_CMD_STACK_START) some space will be lost due to internal management structures, so the area available will be a bit less than the area provided ( M2MB_OS_TASK_SEL_CMD_STACK_SIZE )

Parameters
[in]selCmdSelect parameter to be set (see M2MB_OS_TASK_SEL_CMD_E)
[in

◆ 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 set value for specified parameter of the specified task Selecting cmd, a parameter to be set can be selected To be used when task is already created: it is under application responsibility

Parameters
[in]taskHandleTask handle identify 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 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
Not all M2MB_OS_TASK_SEL_CMD_E are allowed. Allowed: M2MB_OS_TASK_SEL_CMD_USRNAME M2MB_OS_TASK_SEL_CMD_TSLICE M2MB_OS_TASK_SEL_CMD_PRIORITY M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH

Example

M2MB_OS_TASK_HANDLE myTask;
//used myTask; already created
CHAR MyTaskName[] = "myModule";
MEM_W stackStart = 0x52000100;
MEM_W stackSize = 0x1000;
m2mb_os_taskSetItem(myTask, M2MB_OS_TASK_SEL_CMD_USRNAME, (void*)&MyTaskName);
// and so on

◆ m2mb_os_taskSleep()

M2MB_OS_RESULT_E m2mb_os_taskSleep ( UINT32  ticks)

Suspend current task for specified time in ticks.

This functions allows current task to be suspended for the amount of "ticks" timer ticks Suspend calling task for the specified ticks

Parameters
[in]ticksNumber of timer ticks the task will be suspended. Duration of timer ticks depend on HW implementation and platform
Returns
M2MB_OS_SUCCESS in case of success
others in case of error : see m2mb_os_types.h .
Note
Allowed From tasks Preemption Possible Yes

Example

// Suppose duration of system tick is 100ms
//will suspend current task for 1 s (1000 ms)
//Could be easier to use the macro
//which automatically convert 1000 ms to Ticks

◆ 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 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:

void entry2( void *arg );
void entry3( void *arg );
M2MB_OS_TASK_HANDLE taskHandle2 = M2MB_OS_TASK_INVALID;
M2MB_OS_TASK_HANDLE taskHandle3 = M2MB_OS_TASK_INVALID;
M2MB_OS_SEM_HANDLE sem;
M2MB_OS_TASK_ATTR_HANDLE taskAttrHandle;
M2MB_OS_SEM_ATTR_HANDLE semAttr;
{
//create a semaphore
CMDS_ARGS(
M2MB_OS_SEM_SEL_CMD_CREATE_ATTR,NULL,
M2MB_OS_SEM_SEL_CMD_NAME,"MySem",
M2MB_OS_SEM_SEL_CMD_TYPE,0,
M2MB_OS_SEM_SEL_CMD_COUNT, 0
)
);
m2mb_os_sem_init( &sem, &semAttr );
m2mb_os_taskSetAttrItem( &taskAttrHandle,
CMDS_ARGS(
M2MB_OS_TASK_SEL_CMD_CREATE_ATTR, NULL,
M2MB_OS_TASK_SEL_CMD_STACK_SIZE, 2048,
M2MB_OS_TASK_SEL_CMD_NAME, "myTask2",
M2MB_OS_TASK_SEL_CMD_PRIORITY, 204,
M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH, 204,
M2MB_OS_TASK_SEL_CMD_AUTOSTART, M2MB_OS_TASK_AUTOSTART,
M2MB_OS_TASK_SEL_CMD_USRNAME, "myUserTask2"
)
);
m2mb_os_taskCreate( &taskHandle2, &taskAttrHandle, entry2, ( void * )2 );
// arithmetic operation MUST BE INCLUDED in brackets: e.g M2MB_OS_TASK_SEL_CMD_PRIORITY, ( 200 + OFFSET ),
m2mb_os_taskSetAttrItem( &taskAttrHandle,
CMDS_ARGS(
M2MB_OS_TASK_SEL_CMD_CREATE_ATTR, NULL,
M2MB_OS_TASK_SEL_CMD_STACK_SIZE, 2048,
M2MB_OS_TASK_SEL_CMD_NAME, "myTask3",
M2MB_OS_TASK_SEL_CMD_PRIORITY, 205,
M2MB_OS_TASK_SEL_CMD_PREEMPTIONTH, 205,
M2MB_OS_TASK_SEL_CMD_AUTOSTART, M2MB_OS_TASK_AUTOSTART,
M2MB_OS_TASK_SEL_CMD_USRNAME, "myUserTask3"
)
);
m2mb_os_taskCreate( &taskHandle3, &taskAttrHandle, entry3, ( void * )3 );
...
}
void entry2( void *arg )
{
UINT32 id = ( UINT32 )arg;
M2MB_OS_RESULT_E osRes;
osRes = m2mb_os_sem_get( sem, M2MB_OS_WAIT_FOREVER );
... printf( "\r\n Task [%d], Result: %d ", id, osRes);
}
void entry3( void *arg )
{
UINT32 id = ( UINT32 )arg;
M2MB_OS_RESULT_E osRes;
osRes = m2mb_os_taskWaitAbort( taskHandle2 );
... printf( "\r\n Task [%d], Result: %d ", id, osRes);
}
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.
m2mb_os_free
M2MB_OS_RESULT_E m2mb_os_free(void *pMem)
Free allocated memory.
m2mb_os_sem_get
M2MB_OS_RESULT_E m2mb_os_sem_get(M2MB_OS_SEM_HANDLE semHandle, UINT32 timeoutTicks)
Get an instance of semaphore.
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.
m2mb_os_taskCooperate
M2MB_OS_RESULT_E m2mb_os_taskCooperate(void)
Make task to coperate by releasing scheduler control.
m2mb_os_taskGetId
M2MB_OS_TASK_HANDLE m2mb_os_taskGetId(void)
Retrieves handle to the currently executing task.
m2mb_os_sem_init
M2MB_OS_RESULT_E m2mb_os_sem_init(M2MB_OS_SEM_HANDLE *pSemHandle, M2MB_OS_SEM_ATTR_HANDLE *pSemAttr)
Semaphore creation.
m2mb_os_calloc
void * m2mb_os_calloc(UINT32 size)
Allocates bytes of memory and init space with 0.
M2MB_OS_MS2TICKS
UINT32 M2MB_OS_MS2TICKS(UINT32 ms)
Convert ms to ticks.
m2mb_os_get_errno
M2MB_OS_RESULT_E m2mb_os_get_errno(UINT32 *pCategory, INT32 *pErrno)
Allow to get Errno saved in relative task environment.
m2mb_os_sem_setAttrItem
M2MB_OS_RESULT_E m2mb_os_sem_setAttrItem(M2MB_OS_SEM_ATTR_HANDLE *pSemAttrHandle, UINT8 nCmds,...)
Set semaphore attribute for creation.
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.
m2mb_os_taskWaitAbort
M2MB_OS_RESULT_E m2mb_os_taskWaitAbort(M2MB_OS_TASK_HANDLE taskHandle)
Abort suspension of specified task.
m2mb_os_taskSetAttrItem
M2MB_OS_RESULT_E m2mb_os_taskSetAttrItem(M2MB_OS_TASK_ATTR_HANDLE *pTaskAttrHandle, UINT8 nCmds,...)
Set specific attribute for task creation.
m2mb_os_taskSleep
M2MB_OS_RESULT_E m2mb_os_taskSleep(UINT32 ticks)
Suspend current task for specified time in ticks.
m2mb_os_memInfo
M2MB_OS_RESULT_E m2mb_os_memInfo(M2MB_OS_MEMINFO_E memInfoSelect, MEM_W *pOut)
Returns dynamic memory (HEAP) information.