Esempio n. 1
0
/// Timer Tick (called each SysTick).
static void osRtxTimerTick (void) {
  os_timer_t *timer;
  osStatus_t  status;

  timer = osRtxInfo.timer.list;
  if (timer == NULL) {
    //lint -e{904} "Return statement before end of function" [MISRA Note 1]
    return;
  }

  timer->tick--;
  while ((timer != NULL) && (timer->tick == 0U)) {
    TimerUnlink(timer);
    status = osMessageQueuePut(osRtxInfo.timer.mq, &timer->finfo, 0U, 0U);
    if (status != osOK) {
      (void)osRtxErrorNotify(osRtxErrorTimerQueueOverflow, timer);
    }
    if (timer->type == osRtxTimerPeriodic) {
      TimerInsert(timer, timer->load);
    } else {
      timer->state = osRtxTimerStopped;
    }
    timer = osRtxInfo.timer.list;
  }
}
Esempio n. 2
0
// Provide libspace for current thread
void *__user_perthread_libspace(void)
{
    osThreadId_t id;
    uint32_t     n;

    if (os_kernel_is_active() != 0U) {
        id = osThreadGetId();
        for (n = 0U; n < (uint32_t)OS_THREAD_LIBSPACE_NUM; n++) {
            if (os_libspace_id[n] == NULL) {
                os_libspace_id[n] = id;
            }
            if (os_libspace_id[n] == id) {
                break;
            }
        }
        if (n == (uint32_t)OS_THREAD_LIBSPACE_NUM) {
            (void)osRtxErrorNotify(osRtxErrorClibSpace, id);
        }
    } else {
        n = OS_THREAD_LIBSPACE_NUM;
    }

    //lint -e{9087} "cast between pointers to different object types"
    return (void *)&os_libspace[n][0];
}
Esempio n. 3
0
void *__user_perthread_libspace (void) {
  osThreadId_t id;
  uint32_t     n;

  if (!os_kernel_is_active()) {
    return (void *)&os_libspace[OS_THREAD_LIBSPACE_NUM][0];
  }

  id = osThreadGetId();
  for (n = 0U; n < OS_THREAD_LIBSPACE_NUM; n++) {
    if (os_libspace_id[n] == NULL) {
      os_libspace_id[n] = id;
      return (void *)&os_libspace[n][0];
    }
    if (os_libspace_id[n] == id) {
      return (void *)&os_libspace[n][0];
    }
  }

  if (n == OS_THREAD_LIBSPACE_NUM) {
    osRtxErrorNotify(osRtxErrorClibSpace, id);
  }

  return (void *)&os_libspace[n][0];
}
Esempio n. 4
0
int _mutex_initialize(mutex *m) {
  *m = osMutexNew(NULL);
  if (*m == NULL) {
    osRtxErrorNotify(osRtxErrorClibMutex, m);
    return 0;
  }
  return 1;
}
Esempio n. 5
0
/* Initialize mutex */
__USED int _mutex_initialize(mutex *m)
{
    osMutexAttr_t attr;
    memset(&attr, 0, sizeof(attr));
    attr.name = "ARM toolchain mutex";
    attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;

    mutex *slot = NULL;
    core_util_critical_section_enter();
    for (int i = 0; i < OS_MUTEX_STATIC_NUM; i++) {
        if (_static_mutexes[i] == NULL) {
            _static_mutexes[i] = (mutex) - 1; // dummy value to reserve slot
            slot = &_static_mutexes[i];
            //Use the static attrs
            attr.cb_size = sizeof(mbed_rtos_storage_mutex_t);
            attr.cb_mem = &_static_mutexes_mem[i];
            break;
        }
    }
    core_util_critical_section_exit();

    if (slot != NULL) {
        *m = osMutexNew(&attr);
        *slot = *m;
        if (*m != NULL) {
            return 1;
        }
    }

    /* Mutex pool exhausted, try using HEAP */
    attr.cb_size = sizeof(mbed_rtos_storage_mutex_t);
    attr.cb_mem = (void *)malloc(attr.cb_size);
    if (attr.cb_mem == NULL) {
        osRtxErrorNotify(osRtxErrorClibSpace, m);
        return 0;
    }

    *m = osMutexNew(&attr);
    if (*m == NULL) {
        osRtxErrorNotify(osRtxErrorClibMutex, m);
        return 0;
    }

    return 1;
}
Esempio n. 6
0
/// Register post ISR processing.
/// \param[in]  object          generic object.
void osRtxPostProcess (os_object_t *object) {

  if (isr_queue_put(object) != 0U) {
    if (osRtxInfo.kernel.blocked == 0U) {
      SetPendSV();
    } else {
      osRtxInfo.kernel.pendSV = 1U;
    }
  } else {
    osRtxErrorNotify(osRtxErrorISRQueueOverflow, object);
  }
}