/** * @brief Initializes the objects factory. * * @init */ void _factory_init(void) { #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) chMtxObjectInit(&ch_factory.mtx); #else chSemObjectInit(&ch_factory.sem, (cnt_t)1); #endif #if CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE dyn_list_init(&ch_factory.obj_list); chPoolObjectInit(&ch_factory.obj_pool, sizeof (registered_object_t), chCoreAllocAlignedI); #endif #if CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE dyn_list_init(&ch_factory.buf_list); #endif #if CH_CFG_FACTORY_SEMAPHORES == TRUE dyn_list_init(&ch_factory.sem_list); chPoolObjectInit(&ch_factory.sem_pool, sizeof (dyn_semaphore_t), chCoreAllocAlignedI); #endif #if CH_CFG_FACTORY_MAILBOXES == TRUE dyn_list_init(&ch_factory.mbx_list); #endif #if CH_CFG_FACTORY_OBJ_FIFOS == TRUE dyn_list_init(&ch_factory.fifo_list); #endif }
/** * @brief Kernel initialization. */ osStatus osKernelInitialize(void) { cmsis_os_started = 0; chSysInit(); chThdSetPriority(HIGHPRIO); chPoolObjectInit(&sempool, sizeof(semaphore_t), chCoreAlloc); chPoolLoadArray(&sempool, semaphores, CMSIS_CFG_NUM_SEMAPHORES); chPoolObjectInit(&timpool, sizeof(virtual_timer_t), chCoreAlloc); chPoolLoadArray(&timpool, timers, CMSIS_CFG_NUM_TIMERS); return osOK; }
/** * @brief Create a memory pool. * @note The pool is not really created because it is allocated statically, * this function just re-initializes it. */ osPoolId osPoolCreate(const osPoolDef_t *pool_def) { chPoolObjectInit(pool_def->pool, (size_t)pool_def->item_sz, NULL); chPoolLoadArray(pool_def->pool, pool_def->items, (size_t)pool_def->pool_sz); return (osPoolId)pool_def->pool; }
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.*/ chPoolObjectInit(&mp1, 16, null_provider); test_assert(5, chPoolAlloc(&mp1) == NULL, "provider returned memory"); }
static void test_005_001_execute(void) { unsigned i; /* [5.1.1] Adding the objects to the pool using chPoolLoadArray().*/ test_set_step(1); { chPoolLoadArray(&mp1, objects, MEMORY_POOL_SIZE); } /* [5.1.2] Emptying the pool using chPoolAlloc().*/ test_set_step(2); { for (i = 0; i < MEMORY_POOL_SIZE; i++) test_assert(chPoolAlloc(&mp1) != NULL, "list empty"); } /* [5.1.3] Now must be empty.*/ test_set_step(3); { test_assert(chPoolAlloc(&mp1) == NULL, "list not empty"); } /* [5.1.4] Adding the objects to the pool using chPoolFree().*/ test_set_step(4); { for (i = 0; i < MEMORY_POOL_SIZE; i++) chPoolFree(&mp1, &objects[i]); } /* [5.1.5] Emptying the pool using chPoolAlloc() again.*/ test_set_step(5); { for (i = 0; i < MEMORY_POOL_SIZE; i++) test_assert(chPoolAlloc(&mp1) != NULL, "list empty"); } /* [5.1.6] Now must be empty again.*/ test_set_step(6); { test_assert(chPoolAlloc(&mp1) == NULL, "list not empty"); } /* [5.1.7] Covering the case where a provider is unable to return more memory.*/ test_set_step(7); { chPoolObjectInit(&mp1, sizeof (uint32_t), null_provider); test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory"); } }
MemoryPool::MemoryPool(size_t size, memgetfunc_t provider, void* p, size_t n) { chPoolObjectInit(&pool, size, provider); chPoolLoadArray(&pool, p, n); }
/*------------------------------------------------------------------------* * chibios_rt::MemoryPool * *------------------------------------------------------------------------*/ MemoryPool::MemoryPool(size_t size, memgetfunc_t provider) { chPoolObjectInit(&pool, size, provider); }
static void test_005_001_setup(void) { chPoolObjectInit(&mp1, sizeof (uint32_t), NULL); }
static void pools1_setup(void) { chPoolObjectInit(&mp1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), NULL); }
/** * @brief Initializes an empty guarded memory pool. * * @param[out] gmp pointer to a @p guarded_memory_pool_t structure * @param[in] size the size of the objects contained in this guarded * memory pool, the minimum accepted size is the size * of a pointer to void. * * @init */ void chGuardedPoolObjectInit(guarded_memory_pool_t *gmp, size_t size) { chPoolObjectInit(&gmp->pool, size, NULL); chSemObjectInit(&gmp->sem, (cnt_t)0); }