OpenClovis Logo

API Usage Examples
Operating System Abstraction Layer (OSAL)

Code Examples. More...

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();

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