Exemple #1
0
err_t sys_mbox_new(sys_mbox_t *mbox, int size) {
  
  *mbox = chHeapAlloc(NULL, sizeof(mailbox_t) + sizeof(msg_t) * size);
  if (*mbox == 0) {
    SYS_STATS_INC(mbox.err);
    return ERR_MEM;
  }
  else {
    chMBObjectInit(*mbox, (void *)(((uint8_t *)*mbox) + sizeof(mailbox_t)), size);
    SYS_STATS_INC(mbox.used);
    return ERR_OK;
  }
}
err_t sys_sem_new(sys_sem_t *sem, u8_t count) {

  *sem = chHeapAlloc(NULL, sizeof(Semaphore));
  if (*sem == 0) {
    SYS_STATS_INC(sem.err);
    return ERR_MEM;
  }
  else {
    chSemInit(*sem, (cnt_t)count);
    SYS_STATS_INC(sem.used);
    return ERR_OK;
  }
}
Exemple #3
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_trypost
 *---------------------------------------------------------------------------*
 * Description:
 *      Try to post the "msg" to the mailbox.  Returns immediately with
 *      error if cannot.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      void *msg               -- Pointer to data to post
 * Outputs:
 *      err_t                   -- ERR_OK if message posted, else ERR_MEM
 *                                  if not.
 *---------------------------------------------------------------------------*/
err_t sys_mbox_trypost( sys_mbox_t *pxMailBox, void *pxMessageToPost )
{
err_t xReturn;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

	if( xInsideISR != pdFALSE )
	{
		xReturn = xQueueSendFromISR( *pxMailBox, &pxMessageToPost, &xHigherPriorityTaskWoken );
	}
	else
	{
		xReturn = xQueueSend( *pxMailBox, &pxMessageToPost, ( portTickType ) 0 );
	}

	if( xReturn == pdPASS )
	{
		xReturn = ERR_OK;
	}
	else
	{
		/* The queue was already full. */
		xReturn = ERR_MEM;
		SYS_STATS_INC( mbox.err );
	}

	return xReturn;
}
Exemple #4
0
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) {

  if (chMBPost(*mbox, (msg_t)msg, TIME_IMMEDIATE) == MSG_TIMEOUT) {
    SYS_STATS_INC(mbox.err);
    return ERR_MEM;
  }
  return ERR_OK;
}
Exemple #5
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_trypost
 *---------------------------------------------------------------------------*
 * Description:
 *      Try to post the "msg" to the mailbox.  Returns immediately with
 *      error if cannot.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      void *msg               -- Pointer to data to post
 * Outputs:
 *      err_t                   -- ERR_OK if message posted, else ERR_MEM
 *                                  if not.
 *---------------------------------------------------------------------------*/
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
{
    if (xQueueSendToBack(*mbox, &msg, 0) == pdTRUE) {
        return ERR_OK;
    }

    /* The queue was already full. */
    SYS_STATS_INC(mbox.err);
    return ERR_MEM;
}
Exemple #6
0
/** Create a new mutex
 * @param mutex pointer to the mutex to create
 * @return a new mutex */
err_t sys_mutex_new(sys_mutex_t *pxMutex)
{
    *pxMutex = xSemaphoreCreateRecursiveMutex();

    if (*pxMutex == NULL) {
        SYS_STATS_INC(mutex.err);
        return ERR_MEM;
    }

    SYS_STATS_INC_USED(mutex);
    return ERR_OK;
}
Exemple #7
0
void sys_mbox_free(sys_mbox_t *mbox) {

  if (chMBGetUsedCountI(*mbox) != 0) {
    // If there are messages still present in the mailbox when the mailbox
    // is deallocated, it is an indication of a programming error in lwIP
    // and the developer should be notified.
    SYS_STATS_INC(mbox.err);
    chMBReset(*mbox);
  }
  chHeapFree(*mbox);
  *mbox = SYS_MBOX_NULL;
  SYS_STATS_DEC(mbox.used);
}
Exemple #8
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_new
 *---------------------------------------------------------------------------*
 * Description:
 *      Creates a new mailbox
 * Inputs:
 *      int size                -- Size of elements in the mailbox
 * Outputs:
 *      sys_mbox_t              -- Handle to new mailbox
 *---------------------------------------------------------------------------*/
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
{
    LWIP_ASSERT("size > 0", size > 0);

    *mbox = xQueueCreate(size, sizeof(void *));

    if (*mbox == NULL) {
        SYS_STATS_INC(mbox.err);
        return ERR_MEM;
    }

    SYS_STATS_INC_USED(mbox);
    return ERR_OK;
}
Exemple #9
0
/** Create a new mutex
 * @param mutex pointer to the mutex to create
 * @return a new mutex */
err_t sys_mutex_new(sys_mutex_t *mutex)
{
	err_t ercd = ERR_MEM;

	*mutex = xSemaphoreCreateMutex();

	if (sys_mutex_valid(mutex)) {
		ercd = ERR_OK;
		SYS_STATS_INC_USED( mutex );
	} else {
		SYS_STATS_INC( mutex.err );
	}

	return ercd;
}
Exemple #10
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_free
 *---------------------------------------------------------------------------*
 * Description:
 *      Deallocates a mailbox. If there are messages still present in the
 *      mailbox when the mailbox is deallocated, it is an indication of a
 *      programming error in lwIP and the developer should be notified.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 * Outputs:
 *      sys_mbox_t              -- Handle to new mailbox
 *---------------------------------------------------------------------------*/
void sys_mbox_free(sys_mbox_t *mbox)
{
    UBaseType_t msgs_waiting;

    msgs_waiting = uxQueueMessagesWaiting(*mbox);
    configASSERT(msgs_waiting == 0);

#if SYS_STATS
    if (msgs_waiting != 0) {
        SYS_STATS_INC(mbox.err);
    }
    SYS_STATS_DEC(mbox.used);
#endif /* SYS_STATS */

    vQueueDelete(*mbox);
}
Exemple #11
0
err_t sys_mutex_new( sys_mutex_t *Mutex ) {
	err_t xReturn = ERR_MEM;
	BT_ERROR Error = BT_ERR_NONE;

	*Mutex = BT_CreateMutex(&Error);

	if( *Mutex != NULL ) {
		xReturn = ERR_OK;
		SYS_STATS_INC_USED( mutex );
	}
	else {
		SYS_STATS_INC( mutex.err );
	}

	return xReturn;
}
Exemple #12
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_trypost
 *---------------------------------------------------------------------------*
 * Description:
 *      Try to post the "msg" to the mailbox.  Returns immediately with
 *      error if cannot.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      void *msg               -- Pointer to data to post
 * Outputs:
 *      err_t                   -- ERR_OK if message posted, else ERR_MEM
 *                                  if not.
 *---------------------------------------------------------------------------*/
err_t sys_mbox_trypost( sys_mbox_t *pxMailBox, void *pxMessageToPost ) {
	BT_ERROR xReturn;

	xReturn = BT_QueueSend( *pxMailBox, &pxMessageToPost, 0 );

	if( xReturn == BT_TRUE ) {
		xReturn = ERR_OK;
	}
	else {
		/* The queue was already full. */
		xReturn = ERR_MEM;
		SYS_STATS_INC( mbox.err );
	}

	return xReturn;
}
Exemple #13
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_free
 *---------------------------------------------------------------------------*
 * Description:
 *      Deallocates a mailbox. If there are messages still present in the
 *      mailbox when the mailbox is deallocated, it is an indication of a
 *      programming error in lwIP and the developer should be notified.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 * Outputs:
 *      sys_mbox_t              -- Handle to new mailbox
 *---------------------------------------------------------------------------*/
void sys_mbox_free( sys_mbox_t *pxMailBox ) {
	BT_u32 ulMessagesWaiting;

	ulMessagesWaiting = BT_QueueMessagesWaiting( *pxMailBox );

	#if SYS_STATS
	{
		if( ulMessagesWaiting != 0UL ) {
			SYS_STATS_INC( mbox.err );
		}

		SYS_STATS_DEC( mbox.used );
	}
	#endif /* SYS_STATS */

	BT_CloseHandle( *pxMailBox );
}
Exemple #14
0
/** Delete an mbox
 * @param mbox mbox to delete */
void sys_mbox_free(sys_mbox_t *mbox)
{
	u32_t msg_wait_cnt = 0;

	if (!sys_mbox_valid(mbox)) {
		return;
	}
	msg_wait_cnt = uxQueueMessagesWaiting(*mbox);

	if (msg_wait_cnt) {
  		LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_free: mbox 0x%x, %d msgs waited\n", (uint32_t)(*mbox), msg_wait_cnt));
  		SYS_STATS_INC(mbox.err);
	}
	SYS_STATS_DEC(mbox.used);

	vQueueDelete( *mbox );
}
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_trypost
 *---------------------------------------------------------------------------*
 * Description:
 *      Try to post the "msg" to the mailbox.  Returns immediately with
 *      error if cannot.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      void *msg               -- Pointer to data to post
 * Outputs:
 *      err_t                   -- ERR_OK if message posted, else ERR_MEM
 *                                  if not.
 *---------------------------------------------------------------------------*/
err_t sys_mbox_trypost( sys_mbox_t *pxMailBox, void *pxMessageToPost )
{
err_t xReturn;

	if( xQueueSend( *pxMailBox, &pxMessageToPost, 0UL ) == pdPASS )
	{
		xReturn = ERR_OK;
	}
	else
	{
		/* The queue was already full. */
		xReturn = ERR_MEM;
		SYS_STATS_INC( mbox.err );
	}

	return xReturn;
}
Exemple #16
0
/** Create a new mutex
 * @param mutex pointer to the mutex to create
 * @return a new mutex */
err_t sys_mutex_new( sys_mutex_t *pxMutex )
{
err_t xReturn = ERR_MEM;

	*pxMutex = xSemaphoreCreateMutex();

	if( *pxMutex != NULL ) 
	{
		xReturn = ERR_OK;
		SYS_STATS_INC_USED( mutex );
	} 
	else 
	{
		SYS_STATS_INC( mutex.err );
	}
	
	return xReturn;
}
Exemple #17
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_sem_new
 *---------------------------------------------------------------------------*
 * Description:
 *      Creates and returns a new semaphore. The "ucCount" argument specifies
 *      the initial state of the semaphore.
 *      NOTE: Currently this routine only creates counts of 1 or 0
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      u8_t ucCount            -- Initial ucCount of semaphore (1 or 0)
 * Outputs:
 *      sys_sem_t               -- Created semaphore or 0 if could not create.
 *---------------------------------------------------------------------------*/
err_t sys_sem_new(sys_sem_t *pxSemaphore, u8_t initial_count)
{
    LWIP_ASSERT("initial_count invalid (not 0 or 1)",
                (initial_count == 0) || (initial_count == 1));

    *pxSemaphore = xSemaphoreCreateBinary();
    if (*pxSemaphore == NULL) {
        SYS_STATS_INC(sem.err);
        return ERR_MEM;
    }
    SYS_STATS_INC_USED(sem);

    if (initial_count == 1) {
        BaseType_t ret = xSemaphoreGive(*pxSemaphore);
        LWIP_ASSERT("sys_sem_new: initial give failed", ret == pdTRUE);
    }
    return ERR_OK;
}
Exemple #18
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_sem_new
 *---------------------------------------------------------------------------*
 * Description:
 *      Creates and returns a new semaphore. The "ucCount" argument specifies
 *      the initial state of the semaphore.
 *      NOTE: Currently this routine only creates counts of 1 or 0
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      u8_t ucCount              -- Initial ucCount of semaphore (1 or 0)
 * Outputs:
 *      sys_sem_t               -- Created semaphore or 0 if could not create.
 *---------------------------------------------------------------------------*/
err_t sys_sem_new( sys_sem_t *pxSemaphore, u8_t ucCount ) {
	err_t xReturn = ERR_MEM;
	BT_ERROR Error = BT_ERR_NONE;

	*pxSemaphore = BT_CreateMutex(&Error);

	if( *pxSemaphore != NULL ) {
		if( ucCount == 0U ) {
			BT_PendMutex( *pxSemaphore, 0 );
		}
		xReturn = ERR_OK;
		SYS_STATS_INC_USED( sem );
	}
	else {
		SYS_STATS_INC( sem.err );
	}

	return xReturn;
}
Exemple #19
0
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
{
  LWIP_ASSERT("mbox != NULL", mbox != NULL);
  LWIP_UNUSED_ARG(size);

  mbox->sem = CreateSemaphore(0, 0, MAX_QUEUE_ENTRIES, 0);
  LWIP_ASSERT("Error creating semaphore", mbox->sem != NULL);
  if(mbox->sem == NULL) {
    SYS_STATS_INC(mbox.err);
    return ERR_MEM;
  }
  memset(&mbox->q_mem, 0, sizeof(u32_t)*MAX_QUEUE_ENTRIES);
  mbox->head = 0;
  mbox->tail = 0;
  SYS_STATS_INC_USED(mbox);
#if LWIP_STATS && SYS_STATS
  LWIP_ASSERT("sys_mbox_new() counter overflow", lwip_stats.sys.mbox.used != 0 );
#endif /* LWIP_STATS && SYS_STATS */
  return ERR_OK;
}
Exemple #20
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_free
 *---------------------------------------------------------------------------*
 * Description:
 *      Deallocates a mailbox. If there are messages still present in the
 *      mailbox when the mailbox is deallocated, it is an indication of a
 *      programming error in lwIP and the developer should be notified.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 * Outputs:
 *      sys_mbox_t              -- Handle to new mailbox
 *---------------------------------------------------------------------------*/
void sys_mbox_free( sys_mbox_t *pxMailBox )
{
unsigned long ulMessagesWaiting;

	ulMessagesWaiting = uxQueueMessagesWaiting( *pxMailBox );
	configASSERT( ( ulMessagesWaiting == 0 ) );

	#if SYS_STATS
	{
		if( ulMessagesWaiting != 0UL )
		{
			SYS_STATS_INC( mbox.err );
		}

		SYS_STATS_DEC( mbox.used );
	}
	#endif /* SYS_STATS */

	vQueueDelete( *pxMailBox );
}
Exemple #21
0
/** Try to post a message to an mbox - may fail if full or ISR
 * @param mbox mbox to posts the message
 * @param msg message to post (ATTENTION: can be NULL) */
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
{
	err_t ercd = ERR_MEM;
	portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

	if (sys_mbox_valid(mbox)) {
		if( exc_sense() ) { /** in interrupt */
			ercd = xQueueSendToBackFromISR(*mbox, &msg, &xHigherPriorityTaskWoken);
		} else {
			ercd = xQueueSendToBack(*mbox, &msg, 0);
		}
	}
	if (ercd == pdPASS) {
		ercd = ERR_OK;
	} else {
		ercd = ERR_MEM;
		SYS_STATS_INC(mbox.err);
	}
	return ercd;
}
Exemple #22
0
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{
  HANDLE new_sem = NULL;

  LWIP_ASSERT("sem != NULL", sem != NULL);

  new_sem = CreateSemaphore(0, count, 100000, 0);
  LWIP_ASSERT("Error creating semaphore", new_sem != NULL);
  if(new_sem != NULL) {
    SYS_STATS_INC_USED(sem);
#if LWIP_STATS && SYS_STATS
    LWIP_ASSERT("sys_sem_new() counter overflow", lwip_stats.sys.sem.used != 0 );
#endif /* LWIP_STATS && SYS_STATS*/
    sem->sem = new_sem;
    return ERR_OK;
  }
   
  /* failed to allocate memory... */
  SYS_STATS_INC(sem.err);
  sem->sem = SYS_SEM_NULL;
  return ERR_MEM;
}
Exemple #23
0
/** Create a new semaphore
 * @param sem pointer to the semaphore to create
 * @param count initial count of the semaphore
 * @return ERR_OK if successful, another err_t otherwise */
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{
	err_t ercd = ERR_MEM;

	vSemaphoreCreateBinary((*sem));

	if (sys_sem_valid(sem)) {
		if (count == 0) {
			if (xSemaphoreTake(*sem, 1) == pdPASS) {
				ercd = ERR_OK;
				SYS_STATS_INC_USED(sem);
			}
		} else {
			ercd = ERR_OK;
			SYS_STATS_INC_USED(sem);
		}
	} else {
		SYS_STATS_INC(sem.err);
	}

	return ercd;
}
Exemple #24
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_sem_new
 *---------------------------------------------------------------------------*
 * Description:
 *      Creates and returns a new semaphore. The "ucCount" argument specifies
 *      the initial state of the semaphore.
 *      NOTE: Currently this routine only creates counts of 1 or 0
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      u8_t ucCount              -- Initial ucCount of semaphore (1 or 0)
 * Outputs:
 *      sys_sem_t               -- Created semaphore or 0 if could not create.
 *---------------------------------------------------------------------------*/
err_t sys_sem_new( sys_sem_t *pxSemaphore, u8_t ucCount )
{
err_t xReturn = ERR_MEM;

	vSemaphoreCreateBinary( ( *pxSemaphore ) );

	if( *pxSemaphore != NULL )
	{
		if( ucCount == 0U )
		{
			xSemaphoreTake( *pxSemaphore, 1UL );
		}

		xReturn = ERR_OK;
		SYS_STATS_INC_USED( sem );
	}
	else
	{
		SYS_STATS_INC( sem.err );
	}

	return xReturn;
}
/*---------------------------------------------------------------------------*
 * Routine:  sys_sem_new
 *---------------------------------------------------------------------------*
 * Description:
 *      Creates and returns a new semaphore. The "ucCount" argument specifies
 *      the initial state of the semaphore.
 *      NOTE: Currently this routine only creates counts of 1 or 0
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      u8_t ucCount              -- Initial ucCount of semaphore (1 or 0)
 * Outputs:
 *      sys_sem_t               -- Created semaphore or 0 if could not create.
 *---------------------------------------------------------------------------*/
err_t sys_sem_new( sys_sem_t *pxSemaphore, u8_t ucCount )
{
err_t xReturn = ERR_MEM;

	//vSemaphoreCreateBinary( ( *pxSemaphore ) );
	*pxSemaphore = xSemaphoreCreateCounting( 0xffff, ( unsigned long ) ucCount );

	if( *pxSemaphore != NULL )
	{
		if( ucCount == 0U )
		{
//			xSemaphoreTake( *pxSemaphore, 1UL );
		}

		xReturn = ERR_OK;
		SYS_STATS_INC_USED( sem );
	}
	else
	{
		SYS_STATS_INC( sem.err );
	}

	return xReturn;
}