OpenClovis Logo

Code Examples.

Code Examples.

The following code block shall create the above depicted sample state machine.

// Initialize OSAL.
// Allocate memory.
void* pMemory;
pMemory = clHeapAllocate(40);
ClUint32T taskId;
ClRcT myTaskFunction(void *);
// Create an attached task with MEDIUM priority, stack size=4024,
// myTaskFunction as the function to be invoked.
// The task Id should be stored in taskId.
CL_OSAL_THREAD_PRI_MEDIUM, 4024,myTaskFunction,NULL,&taskId);
// Create an detached task with MEDIUM priority, stack size=4024,
// myTaskFunction as the function to be invoked.
CL_OSAL_THREAD_PRI_MEDIUM, 4024,myTaskFunction,NULL);
// Get the task Id of the current executing task.
// Get the priority of a specific task.
clUint32 taskPriority;
clOsalTaskPriorityGet (taskId, &taskPriority);
// Set the priority of the specified task.
clOsalTaskPrioritySet (taskId, 20);
// Lock a task, so that it doesn't get preempted.
cosTaskLock();
// Unlock a task and allow it to be preempted.
cosTaskUnlock();
time.tsSec=2;
time.tsMicroSecond=10;
// Delay a task.
// Create a mutex.
clOsalMutexCreate (&mutexId);
// Lock a mutex.
clOsalMutexLock(mutexId);
// Unlock a mutex.
// Delete a mutex:
// Delete a task from execution.
// Get Number of blocks of memory allocated.
ClUint32T memAllocated;
clOsalNumMemoryAllocGet (&memAllocated);
// Get Number of blocks of memory freed.
ClUint32T memFreed;
clOsalNumMemoryDeallocedGet (&memFreed);
ClOsalCondIdT conditionId;
// Creates a condition variable.
clOsalCondCreate (&conditionId);
// Wait for a condition to be signalled.
clOsalCondWait (conditionId, mutexId, time);
// Signal a condition.
clOsalCondSignal (conditionId);
// Broadcast a condition.
clOsalCondBroadcast (conditionId);
// Delete a condition.
clOsalCondDelete (conditionId);
// Semaphores:
ClUint8T* pSemName = "SEM_NAME";
ClUint32T value = 1;
// Create a semaphore.
clOsalSemCreate(pSemName, value, &semId);
// Lock a semaphore.
// Try & lock a semaphore.
// Unlock a semaphore.
// Get value of the semaphore.
clOsalSemValueGet(semId, &value);
// Delete a semaphore.
// Process:
void processFunction(void* pStr);
// Create a process.
clOsalProcessCreate(processFunction, NULL,
// Suspend a process.
cosProcessSuspend(pid);
// Resume a process.
cosProcessResume(pid);
// Wait for a process to terminate.
// Delete a process.
// Get the process Id.
// Shared Memory:
ClUint8T* pShmName = "SHM_NAME";
void* pMem;
ClUint32T size = 1000;
clUint16_t mode = 0;
// Create a Shared memory region.
clOsalShmCreate(pShmName, size, &shmId, pMem);
// Attach a shared memory region.
clOsalShmAttach(shm, pMem);
// Detach a shared memory region.
clOsalShmDetach(shm, pMem);
// Set the permissions for shared memory.
// Get the permissions for shared memory.
// Get the size of shared memory allocated.
clOsalShmSizeGet(shm, &size);
// Delete a shared memory region created.
// Cleanup the OSAL during system shutdown.
cosCleanUp();
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
ClPtrT clHeapAllocate(CL_IN ClUint32T size)
Allocates memory of the requested size.
ClRcT clOsalProcessSelfIdGet(ClOsalPidT *pProcessId)
Retrieves the processId.
ClRcT clOsalCondCreate(ClOsalCondIdT *pConditionId)
Creates a condition variable.
ClRcT clOsalShmSizeGet(ClOsalShmIdT shmId, ClUint32T *pSize)
Retrieves the size of shared memory.
ClRcT clOsalSemUnlock(ClOsalSemIdT semId)
Unlocks a semaphore.
ClRcT clOsalShmAttach(ClOsalShmIdT shmId, void *pInMem, void **ppOutMem)
Attaches a shared memory.
ClRcT clOsalCondWait(ClOsalCondIdT conditionId, ClOsalMutexIdT mutexId, ClTimerTimeOutT time)
Waits for a condition.
ClRcT clOsalShmSecurityModeSet(ClOsalShmIdT shmId, ClUint32T mode)
Sets permissions to shared memory.
ClRcT clOsalMutexLock(ClOsalMutexIdT mutexId)
Locks a mutex.
ClRcT clOsalTaskDelete(ClOsalTaskIdT taskId)
Deletes a task.
ClRcT clOsalProcessCreate(ClOsalProcessFuncT fpFunction, void *functionArg, ClOsalProcessFlagT creationFlags, ClOsalPidT *pProcessId)
Creates a process.
ClRcT clOsalTaskCreateAttached(const ClCharT *taskName, ClOsalSchedulePolicyT schedulePolicy, ClUint32T priority, ClUint32T stackSize, void *(*fpTaskFunction)(void *), void *pTaskFuncArgument, ClOsalTaskIdT *pTaskId)
Creates a task.
ClRcT clOsalSemCreate(ClUint8T *pName, ClUint32T value, ClOsalSemIdT *pSemId)
Creates a semaphore.
ClRcT clOsalShmDetach(void *pMem)
Detaches a shared memory.
ClRcT clOsalSemLock(ClOsalSemIdT semId)
Locks a semaphore.
ClRcT clOsalTaskDelay(ClTimerTimeOutT timeOut)
Delays a task.
ClUint32T ClOsalShmIdT
The type of an identifier to the OSAL Shared Memory ID.
Definition: clOsalApi.h:243
ClRcT clOsalSelfTaskIdGet(ClOsalTaskIdT *pTaskId)
Retrieves task id.
ClRcT clOsalSemTryLock(ClOsalSemIdT semId)
Locks a semaphore if it is available.
ClRcT clOsalShmDelete(ClOsalShmIdT shmId)
Deletes a shared memory.
ClRcT clOsalMutexCreate(ClOsalMutexIdT *pMutexId)
Creates a mutex.
ClRcT clOsalSemValueGet(ClOsalSemIdT semId, ClUint32T *pSemValue)
Retrieves the value of a semaphore.
ClRcT clOsalProcessDelete(ClOsalPidT processId)
Deletes a process.
ClRcT clOsalMutexDelete(ClOsalMutexIdT mutexId)
Deletes a mutex.
ClRcT clOsalCondBroadcast(ClOsalCondIdT conditionId)
Broadcasts a condition.
ClRcT clOsalCondDelete(ClOsalCondIdT conditionId)
Deletes a condition variable.
ClOsalCondT * ClOsalCondIdT
The type of an identifier to the OSAL condition ID.
Definition: clOsalApi.h:227
ClUint32T ClOsalPidT
The type of an identifier to the OSAL Process ID.
Definition: clOsalApi.h:248
ClRcT clOsalTaskPriorityGet(ClOsalTaskIdT taskId, ClUint32T *pTaskPriority)
Retrieves the priority of the task.
ClRcT clOsalMutexUnlock(ClOsalMutexIdT mutexId)
Unlocks a mutex.
ClRcT clOsalProcessWait(ClOsalPidT processId)
Waits for a process to exit.
ClHandleT ClOsalSemIdT
The type of an identifier to the OSAL Semaphore ID.
Definition: clOsalApi.h:235
ClRcT clOsalTaskCreateDetached(const ClCharT *taskName, ClOsalSchedulePolicyT schedulePolicy, ClUint32T priority, ClUint32T stackSize, void *(*fpTaskFunction)(void *), void *pTaskFuncArgument)
Creates a task.
ClRcT clOsalInitialize(const ClPtrT pConfig)
Initializes the Operating System Abstraction Layer (OSAL).
ClRcT clOsalShmSecurityModeGet(ClOsalShmIdT shmId, ClUint32T *pMode)
Retrieves permissions of shared memory.
ClOsalMutexT * ClOsalMutexIdT
The type of an identifier to the OSAL Mutex ID.
Definition: clOsalApi.h:216
ClRcT clOsalCondSignal(ClOsalCondIdT conditionId)
Signals a condition.
ClRcT clOsalSemDelete(ClOsalSemIdT semId)
Deletes a semaphore.
ClRcT clOsalTaskPrioritySet(ClOsalTaskIdT taskId, ClUint32T taskPriority)
Sets the priority of the task.
ClRcT clOsalShmCreate(ClUint8T *pName, ClUint32T size, ClOsalShmIdT *pShmId)
Creates a shared memory.
@ CL_OSAL_THREAD_PRI_MEDIUM
Medium thread priority.
Definition: clOsalApi.h:309
@ CL_OSAL_SCHED_OTHER
Default scheduling mechanism.
Definition: clOsalApi.h:281
@ CL_OSAL_PROCESS_WITH_NEW_GROUP
This would create a new process group.
Definition: clOsalApi.h:326
The timeout value in seconds and milliseconds.
Definition: clTimerApi.h:87
ClUint32T tsSec
Number of seconds of the timeout.
Definition: clTimerApi.h:89

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen