Ejemplo n.º 1
0
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread,
                            void *arg, int stacksize, int prio) {
  size_t wsz;
  void *wsp;
  syssts_t sts;
  thread_t *tp;

  (void)name;
  wsz = THD_WORKING_AREA_SIZE(stacksize);
  wsp = chCoreAlloc(wsz);
  if (wsp == NULL)
    return NULL;

#if CH_DBG_FILL_THREADS == TRUE
  _thread_memfill((uint8_t *)wsp,
                  (uint8_t *)wsp + sizeof(thread_t),
                  CH_DBG_THREAD_FILL_VALUE);
  _thread_memfill((uint8_t *)wsp + sizeof(thread_t),
                  (uint8_t *)wsp + wsz,
                  CH_DBG_STACK_FILL_VALUE);
#endif

  sts = chSysGetStatusAndLockX();
  tp = chThdCreateI(wsp, wsz, prio, (tfunc_t)thread, arg);
  chRegSetThreadNameX(tp, name);
  chThdStartI(tp);
  chSysRestoreStatusX(sts);

  return (sys_thread_t)tp;
}
Ejemplo n.º 2
0
/**
 * @brief   Free an object.
 */
osStatus osPoolFree(osPoolId pool_id, void *block) {

  syssts_t sts = chSysGetStatusAndLockX();
  chPoolFreeI((memory_pool_t *)pool_id, block);
  chSysRestoreStatusX(sts);

  return osOK;
}
Ejemplo n.º 3
0
/**
 * @brief   Release a mutex.
 */
osStatus osMutexRelease(osMutexId mutex_id) {

  syssts_t sts = chSysGetStatusAndLockX();
  chBSemSignalI((binary_semaphore_t *)mutex_id);
  chSysRestoreStatusX(sts);

  return osOK;
}
Ejemplo n.º 4
0
/**
 * @brief   Release a semaphore.
 */
osStatus osSemaphoreRelease(osSemaphoreId semaphore_id) {

  syssts_t sts = chSysGetStatusAndLockX();
  chSemSignalI((semaphore_t *)semaphore_id);
  chSysRestoreStatusX(sts);

  return osOK;
}
Ejemplo n.º 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;
}
Ejemplo n.º 6
0
/**
 * @brief   Send signals.
 */
int32_t osSignalSet(osThreadId thread_id, int32_t signals) {
  int32_t oldsignals;

  syssts_t sts = chSysGetStatusAndLockX();
  oldsignals = (int32_t)thread_id->p_epending;
  chEvtSignalI((thread_t *)thread_id, (eventmask_t)signals);
  chSysRestoreStatusX(sts);

  return oldsignals;
}
Ejemplo n.º 7
0
uint64_t hrt_micros()
{
	static volatile uint64_t last_micros;

    /*
      use chSysGetStatusAndLockX() to prevent an interrupt while
      allowing this call from any context
     */
	syssts_t sts = chSysGetStatusAndLockX();
	uint64_t micros;
	micros = timer_base + (uint64_t)chVTGetSystemTimeX();
	// we are doing this to avoid an additional interupt routing
	// since we are definitely going to get called atleast once in
	// a full timer period
	if (last_micros > micros) {
        const uint64_t step = ST2US(1ULL<<CH_CFG_ST_RESOLUTION);
		timer_base += step;
		micros += step;
	}
	last_micros = micros;
	chSysRestoreStatusX(sts);
	return micros;
}
Ejemplo n.º 8
0
sys_prot_t sys_arch_protect(void) {

  return chSysGetStatusAndLockX();
}