Esempio n. 1
0
static void pools1_execute(void) {
  int i;

  /* Adding the WAs to the pool.*/
  chPoolLoadArray(&mp1, wa[0], MAX_THREADS);

  /* Emptying the pool.*/
  for (i = 0; i < MAX_THREADS; i++)
    test_assert(1, chPoolAlloc(&mp1) != NULL, "list empty");

  /* Now must be empty.*/
  test_assert(2, chPoolAlloc(&mp1) == NULL, "list not empty");

  /* Adding the WAs to the pool, one by one this time.*/
  for (i = 0; i < MAX_THREADS; i++)
    chPoolFree(&mp1, wa[i]);

  /* Emptying the pool again.*/
  for (i = 0; i < MAX_THREADS; i++)
    test_assert(3, chPoolAlloc(&mp1) != NULL, "list empty");

  /* Now must be empty again.*/
  test_assert(4, chPoolAlloc(&mp1) == NULL, "list not empty");

  /* Covering the case where a provider is unable to return more memory.*/
  chPoolInit(&mp1, 16, null_provider);
  test_assert(5, chPoolAlloc(&mp1) == NULL, "provider returned memory");
}
Esempio n. 2
0
/*
 * eventlogger_init
 *
 * This must be called before post_event can be used.
 * It sets up the logger thread and Event memory pool.
 * It assumes that ChibiOs's RTOS kernel has already been activated by calling
 * chSysInit().
 */
void eventlogger_init(void) {
	chPoolInit(&msg_pool, sizeof(GENERIC_message), NULL);
	chPoolLoadArray(&msg_pool, msg_data, EVENTBUFF_LENGTH);

	chThdCreateStatic( wa_thread_eventlogger
	                 , sizeof(wa_thread_eventlogger)
	                 , NORMALPRIO
	                 , eventlogger
	                 , NULL
	                 );
}
Esempio n. 3
0
/*
 * Start all usb related threads and initiate the USB subsytem.
 */
void startUsbControl(void) {
  chMBInit (&usbTXMailbox, (msg_t *)usbTXMailboxBuffer, USB_MAILBOX_SIZE);
  chMBInit (&usbRXMailbox, (msg_t *)usbRXMailboxBuffer, USB_MAILBOX_SIZE);

  chPoolInit (&usbMemPool, USB_PACKET_SIZE, NULL);
  chPoolLoadArray(&usbMemPool, &usbMemPoolBuffer, USB_MEM_POOL_SIZE);

  chThdCreateStatic(waUsbTx, sizeof(waUsbTx), NORMALPRIO, tUsbTx, NULL);
  chThdCreateStatic(waUsbRx, sizeof(waUsbRx), NORMALPRIO, tUsbRx, NULL);

  //Start and Connect USB
  usbStart(usbp, &config);
  usbConnectBus(usbp);
}
Esempio n. 4
0
/**
 *
 * @brief   Creates a queue.
 *
 * @returns instance of @p struct pios_queue or NULL on failure
 *
 */
struct pios_queue *PIOS_Queue_Create(size_t queue_length, size_t item_size)
{
	struct pios_queue *queuep = PIOS_malloc(sizeof(struct pios_queue));
	if (queuep == NULL)
		return NULL;

	/* Create the memory pool. */
	queuep->mpb = PIOS_malloc(item_size * (queue_length + PIOS_QUEUE_MAX_WAITERS));
	if (queuep->mpb == NULL) {
		PIOS_free(queuep);
		return NULL;
	}
	chPoolInit(&queuep->mp, item_size, NULL);
	chPoolLoadArray(&queuep->mp, queuep->mpb, queue_length + PIOS_QUEUE_MAX_WAITERS);

	/* Create the mailbox. */
	msg_t *mb_buf = PIOS_malloc(sizeof(msg_t) * queue_length);
	chMBInit(&queuep->mb, mb_buf, queue_length);

	return queuep;
}
Esempio n. 5
0
static void pools1_setup(void) {

  chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE), NULL);
}
Esempio n. 6
0
static void rfm69_mem_init()
{
	chPoolInit(&rfm69_mp, 16, NULL);
	chPoolLoadArray(&rfm69_mp, (void*)rfm69_mp_b, RFM69_MEMPOOL_ITEMS);
	chMBInit(&rfm69_mb, (msg_t*)rfm69_mb_q, RFM69_MEMPOOL_ITEMS);
}
Esempio n. 7
0
MemoryPool::MemoryPool(size_t size, memgetfunc_t provider, void* p, size_t n) {

    chPoolInit(&pool, size, provider);
    chPoolLoadArray(&pool, p, n);
}
Esempio n. 8
0
/*------------------------------------------------------------------------*
 * chibios_rt::MemoryPool                                                 *
 *------------------------------------------------------------------------*/
MemoryPool::MemoryPool(size_t size, memgetfunc_t provider) {

    chPoolInit(&pool, size, provider);
}
Esempio n. 9
0
/**
 * @brief   Initializes a Mail Pool.
 * @note    The number of the mail objects in the mail pool should be at
 *          least <b>2+size(mailbox)</b>, this considering one writer and
 *          one reader, add one element for each extra reader or writer in
 *          order to avoid waiting on the mail pool. A smaller number of
 *          elements can be specified if waiting on the pool is acceptable.
 *
 * @param[out] mlp      pointer to a @p MailPool structure
 * @param[in] size      the size of the mail objects to be placed in the pool
 * @param[in] p         pointer to the mail objects array first element
 * @param[in] n         number of elements in the mail objects array
 *
 * @init
 */
void mailInit(MailPool *mlp, size_t size, void *p, size_t n) {

  chPoolInit(&mlp->pool, size, NULL);
  chPoolLoadArray(&mlp->pool, p, n);
  chSemInit(&mlp->sem, (cnt_t)n);
}
Esempio n. 10
0
void forkOS_createThread_init() {
  chPoolInit(&pool_descriptor, THD_WA_SIZE(THREADS_STACK_SIZE), NULL);
  chPoolLoadArray(&pool_descriptor, (void *) pool_buf, NUM_THREADS);
}