예제 #1
0
/**
 * @brief   Allocate an object clearing it.
 */
void *osPoolCAlloc(osPoolId pool_id) {
  void *object;

  object = chPoolAllocI((memory_pool_t *)pool_id);
  memset(object, 0, pool_id->mp_object_size);
  return object;
}
예제 #2
0
/**
 *
 * @brief   Appends an item to a queue from ISR context.
 *
 * @param[in] queuep       pointer to instance of @p struct pios_queue
 * @param[in] itemp        pointer to item which will be appended to the queue
 * @param[in] timeout_ms   timeout for appending item to queue in milliseconds
 *
 * @returns true on success or false on timeout or failure
 *
 */
bool PIOS_Queue_Send_FromISR(struct pios_queue *queuep, const void *itemp, bool *wokenp)
{
	chSysLockFromIsr();
	void *buf = chPoolAllocI(&queuep->mp);
	if (buf == NULL)
	{
		chSysUnlockFromIsr();
		return false;
	}

	memcpy(buf, itemp, queuep->mp.mp_object_size);

	msg_t result = chMBPostI(&queuep->mb, (msg_t)buf);

	if (result != RDY_OK)
	{
		chPoolFreeI(&queuep->mp, buf);
		chSysUnlockFromIsr();
		return false;
	}

	chSysUnlockFromIsr();

	return true;
}
/**
 * @brief   Allocates an object from a memory pool.
 *
 * @param[in] mp        pointer to a @p MemoryPool structure
 * @return              The pointer to the allocated object.
 * @retval NULL         if pool is empty.
 *
 * @api
 */
void *chPoolAlloc(MemoryPool *mp) {
  void *objp;

  chSysLock();
  objp = chPoolAllocI(mp);
  chSysUnlock();
  return objp;
}
예제 #4
0
/**
 * @brief   Allocates an object from a memory pool.
 * @pre     The memory pool must be already been initialized.
 *
 * @param[in] mp        pointer to a @p memory_pool_t structure
 * @return              The pointer to the allocated object.
 * @retval NULL         if pool is empty.
 *
 * @api
 */
void *chPoolAlloc(memory_pool_t *mp) {
  void *objp;

  chSysLock();
  objp = chPoolAllocI(mp);
  chSysUnlock();
  return objp;
}
예제 #5
0
/**
 * @brief   Allocate an object.
 */
void *osPoolAlloc(osPoolId pool_id) {
  void *object;

  syssts_t sts = chSysGetStatusAndLockX();
  object = chPoolAllocI((memory_pool_t *)pool_id);
  chSysRestoreStatusX(sts);

  return object;
}
예제 #6
0
파일: chmempools.c 프로젝트: rusefi/ChibiOS
/**
 * @brief   Allocates an object from a guarded memory pool.
 * @pre     The guarded memory pool must already be initialized.
 *
 * @param[in] gmp       pointer to a @p guarded_memory_pool_t structure
 * @param[in] timeout   the number of ticks before the operation timeouts,
 *                      the following special values are allowed:
 *                      - @a TIME_IMMEDIATE immediate timeout.
 *                      - @a TIME_INFINITE no timeout.
 *                      .
 * @return              The pointer to the allocated object.
 * @retval NULL         if the operation timed out.
 *
 * @sclass
 */
void *chGuardedPoolAllocTimeoutS(guarded_memory_pool_t *gmp,
                                 sysinterval_t timeout) {
  msg_t msg;

  msg = chSemWaitTimeoutS(&gmp->sem, timeout);
  if (msg != MSG_OK) {
    return NULL;
  }

  return chPoolAllocI(&gmp->pool);
}
예제 #7
0
파일: ch.cpp 프로젝트: viktorradnai/ChibiOS
void *MemoryPool::allocI(void) {

    return chPoolAllocI(&pool);
}