⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtx_config.c

📁 对STR710的I/O操作的典型例子程序,使用KEIL编译.采用MDK3.05操作系统.
💻 C
📖 第 1 页 / 共 2 页
字号:

/*--------------------------- os_def_interrupt ------------------------------*/

void os_def_interrupt (void) __irq  {
   /* Default Interrupt Function: may be called when timer ISR is disabled */
   OS_IACK();
}

/*--------------------------- os_tmr_init -----------------------------------*/

void os_tmr_init (void) {
   /* Initialize hardware timer as system tick timer. This function is     */
   /* called at the system startup.                                        */
   OS_TINIT();
#if (OS_ROBIN == 1)
   os_robin_time = OS_ROBINTOUT;
#endif
} /* end of os_tmr_init */

/*--------------------------- os_tmr_reload ---------------------------------*/

void os_tmr_reload (void) {
   /* Reload system timer for next period if a timer requires reload.        */
   OS_TREL();
} /* end of os_tmr_reload */

/*--------------------------- os_tmr_force_irq ------------------------------*/

void os_tmr_force_irq (void) {
   /* Force a timer interrupt.                                               */
   OS_TFIRQ();
} /* end of os_tmr_force_irq */

/*--------------------------- os_tmr_inspect_cnt ----------------------------*/

U32 os_tmr_inspect_cnt (void) {
   /* Inspect current value of rtx timer.                                    */
   return (OS_TVAL);
} /* end of os_tmr_inspect_cnt */

/*--------------------------- os_tmr_inspect_ovf ----------------------------*/

BOOL os_tmr_inspect_ovf (void) {
   /* Inspect current state of timer overflow flag.                          */
   return (OS_TOVF);
} /* end of os_tmr_inspect_ovf */

/*--------------------------- os_lock ---------------------------------------*/

void __swi(7) os_lock (void);
void __SWI_7          (void) {
   /* This function must be executed from supervisor mode protected from   */
   /* interrupts. STR71x interrupts are disabled with a delay because EIC  */
   /* pheripheral may run with a slower clock than CPU.                    */
   OS_LOCK();
   /* Wait for 'OS_LOCK' to become active. */
   __nop();
   __nop();
   __nop();
}

/*--------------------------- tsk_lock --------------------------------------*/

void tsk_lock (void) {
   /* Lock out tasks: prevents task switching by locking out scheduler       */
   /* activation on interrupt.                                            .  */
   os_lock ();
} /* end of tsk_lock */

/*--------------------------- tsk_unlock ------------------------------------*/

void tsk_unlock (void) {
   /* Enable AR System Tick Timer Interrupts.                                */
   OS_UNLOCK();
} /* end of tsk_unlock */

/*--------------------------- os_init_mem -----------------------------------*/

void os_init_mem (void) {
   U32 i;

   for (i = 0; i < OS_TASKCNT; i++) {
      os_active_TCB[i] = NULL;
   }
   _init_box (&m_tcb, sizeof(m_tcb), sizeof(struct OS_TCB));
   _init_box8 (&m_stk, sizeof(m_stk), OS_STKSIZE*4);
#if (OS_TIMERCNT != 0)
   _init_box (&m_tmr, sizeof(m_tmr), sizeof(struct OS_TMR));
#endif
} /* end of os_init_mem */

/*--------------------------- os_alloc_TCB ----------------------------------*/

P_TCB os_alloc_TCB () {
   return (_alloc_box (m_tcb));
} /* end of os_alloc_TCB */

/*--------------------------- os_free_TCB -----------------------------------*/

void os_free_TCB (P_TCB p_TCB) {
   /* Free allocated memory resources for the task "p_TCB" */
   _free_box (m_stk, p_TCB->stack);
   _free_box (m_tcb, p_TCB);
#if (OS_STKCHECK == 1)
   if (os_runtask == p_TCB) {
      /* os_tsk_delete_self() called. */
      os_del_flag = __TRUE;
   }
#endif
} /* end of os_free_TCB */

/*--------------------------- os_alloc_TMR ----------------------------------*/

P_TMR os_alloc_TMR () {
#if (OS_TIMERCNT != 0)
   return (_alloc_box (m_tmr));
#else
   return (NULL);
#endif
} /* end of os_alloc_TMR */

/*--------------------------- os_free_TMR -----------------------------------*/

void os_free_TMR (P_TMR timer) {
   /* Free allocated memory resources for user timer 'timer' */
#if (OS_TIMERCNT != 0)
   _free_box (m_tmr, timer);
#else
   timer = timer;
#endif
} /* end of os_free_TMR */

/*--------------------------- os_init_context -------------------------------*/

void os_init_context (P_TCB p_TCB, U8 priority,
                      FUNCP task_body, U8 full_context) {
   /* Prepare TCB and saved context for a first time start of a task         */
   /* "p_TCB" points to TCB to be initialised. "priority" indicates desired  */
   /* execution priority. "task_body" is the start address of the task.      */
   /* "full_context" identifies context type.                                */
   U32 *stk,i;

   /* Initialize general part of TCB */
   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;

   /* Initialize ARM specific part of TCB */
   p_TCB->full_ctx = full_context;

   /* Prepare a complete interrupt frame for first task start */
   if (p_TCB->priv_stack != 0) {
      /* User has provided a memory space for the stack. */
      stk = &p_TCB->stack[p_TCB->priv_stack>>2];
   }
   else {
      /* Allocate the memory space for the stack. */
      p_TCB->stack = _alloc_box (m_stk);
      /* Write to the top of stack. */
      stk = &p_TCB->stack[OS_STKSIZE];
   }

   /* Initial PC and default CPSR */
   *--stk = (U32)task_body;
   i      = INITIAL_CPSR;

   /* If a task in THUMB mode, set T-bit. */
   if ((U32)task_body & 1) {
      i |= 0x00000020;
   }
   *--stk = i;

   /* Write initial registers. */
   for (i = full_context ? 13 : 8; i; i--) {
      *--stk = 0;
   }

   /* For "full_context" assign a void pointer to R0. */
   if (full_context) {
      *--stk = (U32)p_TCB->p_msg;
   }

   /* Initial Task stack pointer. */
   p_TCB->tsk_stack = (U32)stk;

   /* Task entry point. */
   p_TCB->ptask = task_body;

#if (OS_STKCHECK == 1)
   /* Set a magic word for checking of stack overflow. */
   p_TCB->stack[0] = MAGIC_WORD;
#endif
} /* end of os_init_context */


/*--------------------------- os_switch_tasks -------------------------------*/

void __swi(0) os_switch_tasks (P_TCB p_new);
void __SWI_0                  (P_TCB p_new) {
   /* Switch to next task (identified by "p_new"). Saving old and restoring */
   /* new context is written in assembly (module: Swi_RTX.s)                */

#if (OS_STKCHECK == 1)
   if (tstclrb (&os_del_flag) == __FALSE) {
      /* Do not check if task has deleted itself. */
      if ((os_runtask->tsk_stack < (U32)os_runtask->stack) ||
          (os_runtask->stack[0] != MAGIC_WORD )) {
         os_stk_overflow ();
      }
   }
#endif
   os_runtask->full_ctx = __FALSE;
   os_runtask = p_new;
   p_new->state = RUNNING;
#if (OS_ROBIN == 1)
   if (p_new->full_ctx == __TRUE) {
      os_tsk_robin = p_new;
   }
#endif
   /* Tsk_Unlock */
   OS_UNLOCK();
} /* end of os_switch_tasks */


/*--------------------------- os_chk_robin ----------------------------------*/

void os_chk_robin (void) {
   /* Check if Round Robin timeout expired and switch to the next ready task.*/
   /* This function is called from the "os_clock_demon()" task scheduler.    */
#if (OS_ROBIN == 1)
   P_TCB p_new;

   if (os_rdy.p_lnk != os_tsk_robin) {
      os_robin_time = os_time + OS_ROBINTOUT;
      return;
      }
   if (os_robin_time == os_time) {
      /* Round Robin timeout has expired. */
      os_robin_time += OS_ROBINTOUT;
      p_new = os_get_first (&os_rdy);
      os_put_prio ((P_XCB)&os_rdy, p_new);
      }
#endif
} /* end of os_chk_robin */

/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -