Esempio n. 1
0
OS_ID rt_tmr_create (U16 tcnt, U16 info)  {
  /* Create an user timer and put it into the chained timer list using      */
  /* a timeout count value of "tcnt". User parameter "info" is used as a    */
  /* parameter for the user provided callback function "os_tmr_call ()".    */
  P_TMR p_tmr, p;
  U32 delta,itcnt = tcnt;

  if ((tcnt == 0U) || (m_tmr == NULL)) {
    return (NULL);
  }
  p_tmr = rt_alloc_box ((U32 *)m_tmr);
  if (!p_tmr)  {
    return (NULL);
  }
  p_tmr->info = info;
  p = (P_TMR)&os_tmr;
  delta = p->tcnt;
  while ((delta < itcnt) && (p->next != NULL)) {
    p = p->next;
    delta += p->tcnt;
  }
  /* Right place found, insert timer into the list */
  p_tmr->next = p->next;
  p_tmr->tcnt = (U16)(delta - itcnt);
  p->next = p_tmr;
  p->tcnt -= p_tmr->tcnt;
  return (p_tmr);
}
Esempio n. 2
0
OS_TID rt_tsk_create (FUNCP task, U32 prio_stksz, void *stk, void *argv) {
    /* Start a new task declared with "task". */
    P_TCB task_context;
    U32 i;

    /* Priority 0 is reserved for idle task! */
    if ((prio_stksz & 0xFFU) == 0U) {
        prio_stksz += 1U;
    }
    task_context = rt_alloc_box (mp_tcb);
    if (task_context == NULL) {
        return (0U);
    }
    /* If "size != 0" use a private user provided stack. */
    task_context->stack      = stk;
    task_context->priv_stack = (U16)(prio_stksz >> 8);

    /* Find a free entry in 'os_active_TCB' table. */
    i = rt_get_TID ();
    if (i == 0U) {
        return (0U);
    }
    task_context->task_id = (U8)i;
    /* Pass parameter 'argv' to 'rt_init_context' */
    task_context->msg = argv;
    task_context->argv = argv;
    /* For 'size == 0' system allocates the user stack from the memory pool. */
    rt_init_context (task_context, (U8)(prio_stksz & 0xFFU), task);

    os_active_TCB[i-1U] = task_context;
    DBG_TASK_NOTIFY(task_context, __TRUE);
    rt_dispatch (task_context);
    return ((OS_TID)i);
}
Esempio n. 3
0
void *rt_mem_alloc (void *box_mem)
{
	void *ptr;
	//printf("Entered malloc\n");
	ptr = rt_alloc_box(box_mem);
	if(ptr != NULL)	
		return ptr;
	else	{
		// add task to waiting list.
		rt_put_prio(&wait_list, os_tsk.run);
		rt_block (0xffff, (U8)os_tsk.run);
		return NULL;
	}
	
	/*
	void *ptr;
	ptr = rt_alloc_box(box_mem);
	
	printf("wait_count: %d\n", wait_count);
	
	if (ptr != NULL)
	{
		if (wait_count > 0)
		{
			if (os_tsk.run->prio <= highest_prio)
			{
				highest_prio = os_tsk.run->prio;
				printf("highest_prio: %d\n", highest_prio);  
				return ptr;
			}
		}
		else if (wait_count == 0)	//Empty list, with mem available, just add task
		{
			return ptr;
		}
	}
	else
	{
		rt_put_prio(&wait_list, os_tsk.run);
		//increment counter when a task is added to wait list
		wait_count++;
		printf("wait_count, if mem no available: %d\n", wait_count);
		rt_block (0xffff, (U8)os_tsk.run);
	}	
*/
}
Esempio n. 4
0
static void rt_init_context (P_TCB p_TCB, U8 priority, FUNCP task_body) {
  /* Initialize general part of the Task Control Block. */
  p_TCB->cb_type = TCB;
  p_TCB->state   = READY;
  p_TCB->prio    = priority;
  p_TCB->p_lnk   = NULL;
  p_TCB->p_rlnk  = NULL;
  p_TCB->p_dlnk  = NULL;
  p_TCB->p_blnk  = NULL;
  p_TCB->delta_time    = 0;
  p_TCB->interval_time = 0;
  p_TCB->events  = 0;
  p_TCB->waits   = 0;
  p_TCB->stack_frame = 0;

  if (p_TCB->priv_stack == 0) {
    /* Allocate the memory space for the stack. */
    p_TCB->stack = rt_alloc_box (mp_stk);
  }
  rt_init_stack (p_TCB, task_body);
}
Esempio n. 5
0
void rt_mbx_psh (P_MCB p_CB, void *p_msg) {
  /* Store the message to the mailbox queue or pass it to task directly. */
  P_TCB p_TCB;
  void *mem;

  if (p_CB->p_lnk != NULL) switch (p_CB->state) {
#ifdef __CMSIS_RTOS
    case 3:
      /* Task is waiting to allocate memory, remove it from the waiting list */
      mem = rt_alloc_box(p_msg);
      if (mem == NULL) break;
      p_TCB = rt_get_first ((P_XCB)p_CB);
      rt_ret_val(p_TCB, (U32)mem);
      p_TCB->state = READY;
      rt_rmv_dly (p_TCB);
      rt_put_prio (&os_rdy, p_TCB);
      break;
#endif
    case 2:
      /* Task is waiting to send a message, remove it from the waiting list */
      p_TCB = rt_get_first ((P_XCB)p_CB);
#ifdef __CMSIS_RTOS
      rt_ret_val(p_TCB, 0/*osOK*/);
#else
      rt_ret_val(p_TCB, OS_R_OK);
#endif
      p_CB->msg[p_CB->first] = p_TCB->msg;
      rt_inc (&p_CB->count);
      if (++p_CB->first == p_CB->size) {
        p_CB->first = 0;
      }
      p_TCB->state = READY;
      rt_rmv_dly (p_TCB);
      rt_put_prio (&os_rdy, p_TCB);
      break;
    case 1:
      /* Task is waiting for a message, pass the message to the task directly */
      p_TCB = rt_get_first ((P_XCB)p_CB);
#ifdef __CMSIS_RTOS
      rt_ret_val2(p_TCB, 0x10/*osEventMessage*/, (U32)p_msg);
#else
      *p_TCB->msg = p_msg;
      rt_ret_val (p_TCB, OS_R_MBX);
#endif
      p_TCB->state = READY;
      rt_rmv_dly (p_TCB);
      rt_put_prio (&os_rdy, p_TCB);
      break;
  } else {
      /* No task is waiting for a message, store it to the mailbox queue */
      if (p_CB->count < p_CB->size) {
        p_CB->msg[p_CB->first] = p_msg;
        rt_inc (&p_CB->count);
        if (++p_CB->first == p_CB->size) {
          p_CB->first = 0;
        }
      }
      else {
        os_error (OS_ERR_MBX_OVF);
      }
  }
}