Пример #1
0
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
{
   //Create a semaphore
   OS_CreateCSema(semaphore, count);

   //The event object was successfully created
   return TRUE;
}
/*--------------------------------------------
| Name:        kernel_sem_init
| Description:
| Parameters:  none
| Return Type: none
| Comments:
| See:
----------------------------------------------*/
int kernel_sem_init(kernel_sem_t* kernel_sem, int pshared, unsigned int value){
   if(!kernel_sem)
      return -1;
#ifdef __KERNEL_UCORE_EMBOS
   OS_CreateCSema(&kernel_sem->sem,(char)value);
#endif
   return 0;
}
/*
 * Create a new semaphore and initialize it.
 * If no memory is available return NULL
 */
sys_sem_t sys_sem_new(u8_t count)
{
   OS_CSEMA* p_sem = (OS_CSEMA*)malloc(sizeof(OS_CSEMA));
   /* out of memory? */
   if(!p_sem)
      return SYS_SEM_NULL;

   OS_CreateCSema(p_sem,count);
   return p_sem;
}
Пример #4
0
/*-----------------------------------------------------------------------------------
 * Creates and returns a new semaphore. The "count" argument specifies
 * the initial state of the semaphore. TBD finish and test
 */
err_t sys_sem_new( /*@special@*/ /*@out@*/ sys_sem_t *sem, u8_t count) /*@allocates *sem@*/
{
    if ( sem == NULL )
    {
        /*@-mustdefine@*/ /*@-compdef@*/ /* do not need to allocate or set *sem */
        return ERR_VAL;
        /*@+mustdefine@*/ /*@+compdef@*/
    }
    *sem = malloc_named("sys_sem_new", sizeof(OS_CSEMA));
// I am not sure but was protected in the orignal freertos code
    OS_EnterRegion();
    if ( count == (u8_t) 0 ) /* Means it can't be taken */
    {
        OS_CREATECSEMA(*sem);
    }
    else
    {
        OS_CreateCSema(*sem, count);
    }
    OS_LeaveRegion();
    /*@-compdef@*/ /* Lint doesnt realise allocation has occurred */
    return ERR_OK;
    /*@+compdef@*/
}