コード例 #1
0
ファイル: chthreads.c プロジェクト: sdalu/ChibiOS
/**
 * @brief   Creates a new thread into a static memory area.
 * @details The new thread is initialized but not inserted in the ready list,
 *          the initial state is @p CH_STATE_WTSTART.
 * @post    The initialized thread can be subsequently started by invoking
 *          @p chThdStart(), @p chThdStartI() or @p chSchWakeupS()
 *          depending on the execution context.
 * @note    A thread can terminate by calling @p chThdExit() or by simply
 *          returning from its main function.
 * @note    Threads created using this function do not obey to the
 *          @p CH_DBG_FILL_THREADS debug option because it would keep
 *          the kernel locked for too much time.
 *
 * @param[out] tdp      pointer to the thread descriptor
 * @return              The pointer to the @p thread_t structure allocated for
 *                      the thread into the working space area.
 *
 * @iclass
 */
thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) {
  thread_t *tp;

  chDbgCheckClassI();
  chDbgCheck(tdp != NULL);
  chDbgCheck(MEM_IS_ALIGNED(tdp->wbase, PORT_WORKING_AREA_ALIGN) &&
             MEM_IS_ALIGNED(tdp->wend, PORT_STACK_ALIGN) &&
             (tdp->wend > tdp->wbase) &&
             ((size_t)((tdp->wend - tdp->wbase) *
                       sizeof (stkalign_t)) >= THD_WORKING_AREA_SIZE(0)));
  chDbgCheck((tdp->prio <= HIGHPRIO) && (tdp->funcp != NULL));

  /* The thread structure is laid out in the upper part of the thread
     workspace. The thread position structure is aligned to the required
     stack alignment because it represents the stack top.*/
  tp = (thread_t *)((uint8_t *)tdp->wend -
                    MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN));

  /* Initial state.*/
  tp->state = CH_STATE_WTSTART;

  /* Stack boundary.*/
  tp->stklimit = tdp->wbase;

  /* Setting up the port-dependent part of the working area.*/
  PORT_SETUP_CONTEXT(tp, tdp->wbase, tp, tdp->funcp, tdp->arg);

  /* The driver object is initialized but not started.*/
  return _thread_init(tp, tdp->name, tdp->prio);
}
コード例 #2
0
ファイル: sys_arch.c プロジェクト: TexZK/ChibiOS
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;
}
コード例 #3
0
ファイル: sys_arch.c プロジェクト: oh3eqn/ChibiOS
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread,
                            void *arg, int stacksize, int prio) {
  thread_t *tp;

  tp = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(stacksize),
                           name, prio, (tfunc_t)thread, arg);
  return (sys_thread_t)tp;
}
コード例 #4
0
ファイル: cmsis_os.c プロジェクト: 0110/stm32f103playground
/**
 * @brief   Creates a thread.
 */
osThreadId osThreadCreate(const osThreadDef_t *thread_def, void *argument) {
  size_t size;

  size = thread_def->stacksize == 0 ? CMSIS_CFG_DEFAULT_STACK :
                                      thread_def->stacksize;
  return (osThreadId)chThdCreateFromHeap(0,
                                         THD_WORKING_AREA_SIZE(size),
                                         NORMALPRIO+thread_def->tpriority,
                                         (tfunc_t)thread_def->pthread,
                                         argument);
}
コード例 #5
0
ファイル: chthreads.c プロジェクト: ChibiOS/ChibiOS-gitmain
/**
 * @brief   Creates a new thread into a static memory area.
 * @details The new thread is initialized but not inserted in the ready list,
 *          the initial state is @p CH_STATE_WTSTART.
 * @post    The initialized thread can be subsequently started by invoking
 *          @p chThdStart(), @p chThdStartI() or @p chSchWakeupS()
 *          depending on the execution context.
 * @note    A thread can terminate by calling @p chThdExit() or by simply
 *          returning from its main function.
 * @note    Threads created using this function do not obey to the
 *          @p CH_DBG_FILL_THREADS debug option because it would keep
 *          the kernel locked for too much time.
 *
 * @param[out] wsp      pointer to a working area dedicated to the thread stack
 * @param[in] size      size of the working area
 * @param[in] prio      the priority level for the new thread
 * @param[in] pf        the thread function
 * @param[in] arg       an argument passed to the thread function. It can be
 *                      @p NULL.
 * @return              The pointer to the @p thread_t structure allocated for
 *                      the thread into the working space area.
 *
 * @iclass
 */
thread_t *chThdCreateI(void *wsp, size_t size,
                       tprio_t prio, tfunc_t pf, void *arg) {
  /* The thread structure is laid out in the lower part of the thread
     workspace.*/
  thread_t *tp = wsp;

  chDbgCheckClassI();
  chDbgCheck((wsp != NULL) && (size >= THD_WORKING_AREA_SIZE(0)) &&
             (prio <= HIGHPRIO) && (pf != NULL));

  PORT_SETUP_CONTEXT(tp, wsp, size, pf, arg);
  return _thread_init(tp, prio);
}
コード例 #6
0
ファイル: sys_arch.c プロジェクト: ChibiOS/ChibiOS-gitmain
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread,
                            void *arg, int stacksize, int prio) {

  size_t wsz;
  void *wsp;

  (void)name;
  wsz = THD_WORKING_AREA_SIZE(stacksize);
  wsp = chCoreAlloc(wsz);
  if (wsp == NULL)
    return NULL;
  return (sys_thread_t)chThdCreateStatic(wsp, wsz, prio, (tfunc_t)thread, arg);
}
コード例 #7
0
/**
 * @brief   Initialize the Data Link Layer object.
 * @details The function starts the DataLinkLayer serial driver
 *          - Check the actual state of the driver
 *          - Configure and start the sdSerial driver
 *          - Init the mutex variable used by the 'DLLSendSingleFrameSerial' function
 *          - Init the mailboxes which are work like a buffer
 *          - Creates a SyncFrame
 *          - Starts the 'SDReceiving' and 'SDSending' threads which are provide
 *            the whole DLL functionality
 *          - Set the DLL state to ACTIVE
 *
 * @param[in] dllp    DataLinkLayer driver structure
 * @param[in] config  The config contains the speed and the ID of the serial driver
 */
void DLLStart(DLLDriver *dllp, DLLSerialConfig *config){
  osalDbgCheck((dllp != NULL) && (config != NULL));

  osalDbgAssert((dllp->state == DLL_UNINIT) || (dllp->state == DLL_ACTIVE),
              "DLLInit(), invalid state");

  dllp->config = config;
  SerialDCfg.speed = dllp->config->baudrate;       //Set the data rate to the given rate
  sdStart(dllp->config->SDriver, &SerialDCfg);     //Start the serial driver for the ESP8266


  chMtxObjectInit(&dllp->DLLSerialSendMutex);


  chMBObjectInit(&dllp->DLLBuffers.DLLFilledOutputBuffer,
                 dllp->DLLBuffers.DLLFilledOutputBufferQueue, OUTPUT_FRAME_BUFFER);

  chMBObjectInit(&dllp->DLLBuffers.DLLFreeOutputBuffer,
                 dllp->DLLBuffers.DLLFreeOutputBufferQueue, OUTPUT_FRAME_BUFFER);

  int i;
  for (i = 0; i < OUTPUT_FRAME_BUFFER; i++)
    (void)chMBPost(&dllp->DLLBuffers.DLLFreeOutputBuffer,
                   (msg_t)&dllp->DLLBuffers.DLLOutputBuffer[i], TIME_INFINITE);

  DLLCreateSyncFrame(dllp);

  dllp->SendingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(128), NORMALPRIO+1, SDSending, (void *)dllp);
  if (dllp->SendingThread == NULL)
    chSysHalt("DualFramework: Starting 'SendingThread' failed - out of memory");

  dllp->ReceivingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(128), NORMALPRIO+1, SDReceiving, (void *)dllp);
  if (dllp->ReceivingThread == NULL)
    chSysHalt("DualFramework: Starting 'ReceivingThread' failed - out of memory");

  dllp->state = DLL_ACTIVE;
}
コード例 #8
0
static void dyn1_execute(void) {
  size_t n, sz;
  void *p1;
  tprio_t prio = chThdGetPriorityX();

  (void)chHeapStatus(&heap1, &sz);
  /* Starting threads from the heap. */
  threads[0] = chThdCreateFromHeap(&heap1,
                                   THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE),
                                   prio-1, thread, "A");
  threads[1] = chThdCreateFromHeap(&heap1,
                                   THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE),
                                   prio-2, thread, "B");
  /* Allocating the whole heap in order to make the thread creation fail.*/
  (void)chHeapStatus(&heap1, &n);
  p1 = chHeapAlloc(&heap1, n);
  threads[2] = chThdCreateFromHeap(&heap1,
                                   THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE),
                                   prio-3, thread, "C");
  chHeapFree(p1);

  test_assert(1, (threads[0] != NULL) &&
                 (threads[1] != NULL) &&
                 (threads[2] == NULL) &&
                 (threads[3] == NULL) &&
                 (threads[4] == NULL),
                 "thread creation failed");

  /* Claiming the memory from terminated threads. */
  test_wait_threads();
  test_assert_sequence(2, "AB");

  /* Heap status checked again.*/
  test_assert(3, chHeapStatus(&heap1, &n) == 1, "heap fragmented");
  test_assert(4, n == sz, "heap size changed");
}
コード例 #9
0
ファイル: pac1720.c プロジェクト: CInsights/pecan-stm32f429
void pac1720_init(void)
{
	TRACE_INFO("PAC  > Init PAC1720");

	/* Write for both channels
	 * Current sensor sampling time	80ms (Denominator 2047)
	 * Current sensing average disabled
	 * Current sensing range +-80mV (FSR)
	 */
	I2C_write8(PAC1720_ADDRESS, PAC1720_CH1_VSENSE_SAMP_CONFIG, 0x53);
	I2C_write8(PAC1720_ADDRESS, PAC1720_CH2_VSENSE_SAMP_CONFIG, 0x53);
	I2C_write8(PAC1720_ADDRESS, PAC1720_V_SOURCE_SAMP_CONFIG,   0xFF);

	TRACE_INFO("PAC  > Init PAC1720 continuous measurement");
	chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(256), "PAC1720", NORMALPRIO, pac1720_thd, NULL);
}
コード例 #10
0
ファイル: chthreads.c プロジェクト: sdalu/ChibiOS
/**
 * @brief   Creates a new thread into a static memory area.
 * @note    A thread can terminate by calling @p chThdExit() or by simply
 *          returning from its main function.
 *
 * @param[out] wsp      pointer to a working area dedicated to the thread stack
 * @param[in] size      size of the working area
 * @param[in] prio      the priority level for the new thread
 * @param[in] pf        the thread function
 * @param[in] arg       an argument passed to the thread function. It can be
 *                      @p NULL.
 * @return              The pointer to the @p thread_t structure allocated for
 *                      the thread into the working space area.
 *
 * @api
 */
thread_t *chThdCreateStatic(void *wsp, size_t size,
                            tprio_t prio, tfunc_t pf, void *arg) {
  thread_t *tp;

  chDbgCheck((wsp != NULL) &&
             MEM_IS_ALIGNED(wsp, PORT_WORKING_AREA_ALIGN) &&
             (size >= THD_WORKING_AREA_SIZE(0)) &&
             MEM_IS_ALIGNED(size, PORT_STACK_ALIGN) &&
             (prio <= HIGHPRIO) && (pf != NULL));

#if CH_DBG_FILL_THREADS == TRUE
  _thread_memfill((uint8_t *)wsp,
                  (uint8_t *)wsp + size,
                  CH_DBG_STACK_FILL_VALUE);
#endif

  chSysLock();

  /* The thread structure is laid out in the upper part of the thread
     workspace. The thread position structure is aligned to the required
     stack alignment because it represents the stack top.*/
  tp = (thread_t *)((uint8_t *)wsp + size -
                    MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN));

  /* Stack boundary.*/
  tp->stklimit = (stkalign_t *)wsp;

  /* Setting up the port-dependent part of the working area.*/
  PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg);

  tp = _thread_init(tp, "noname", prio);

  /* Starting the thread immediately.*/
  chSchWakeupS(tp, MSG_OK);
  chSysUnlock();

  return tp;
}
コード例 #11
0
ファイル: testpools.c プロジェクト: ChibiOS/ChibiOS-gitmain
static void pools1_setup(void) {

  chPoolObjectInit(&mp1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), NULL);
}