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

📄 rtx_config.c

📁 对STR710的I/O操作的典型例子程序,使用KEIL编译.采用MDK3.05操作系统.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
 *      R T L  -  K e r n e l
 *----------------------------------------------------------------------------
 *      Name:    RTX_CONFIG.C
 *      Purpose: Configuration of RTX Kernel for ST STR71x
 *      Rev.:    V3.05 / 22-mar-2007
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2007 KEIL - An ARM Company. All rights reserved. 
 *---------------------------------------------------------------------------*/

#include <71x_lib.H>
#include <RTX_Config.h>                  /* RTX user configuration header    */

/*----------------------------------------------------------------------------
 *      RTX User configuration part BEGIN
 *---------------------------------------------------------------------------*/

//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
//
// <h>Task Definitions
// ===================
//
//   <o>Number of concurrent running tasks <0-250>
//   <i> Define max. number of tasks that will run at the same time.
//   <i> Default: 6
#ifndef OS_TASKCNT
 #define OS_TASKCNT     6
#endif

//   <o>Number of tasks with user-provided stack <0-250>
//   <i> Define the number of tasks that will use a bigger stack.
//   <i> The memory space for the stack is provided by the user.
//   <i> Default: 0
#ifndef OS_PRIVCNT
 #define OS_PRIVCNT     0
#endif

//   <o>Task stack size [bytes] <20-4096:8><#/4>
//   <i> Set the stack size for tasks which is assigned by the system.
//   <i> Default: 200
#ifndef OS_STKSIZE
 #define OS_STKSIZE     50
#endif

// <q>Check for the stack overflow
// ===============================
// <i> Include the stack checking code for a stack overflow.
// <i> Note that additional code reduces the Kernel performance.
#ifndef OS_STKCHECK
 #define OS_STKCHECK    1
#endif

//   <o>Number of user timers <0-250>
//   <i> Define max. number of user timers that will run at the same time.
//   <i> Default: 0  (User timers disabled)
#ifndef OS_TIMERCNT
 #define OS_TIMERCNT    0
#endif

// </h>
// <h>System Timer Configuration
// =============================
//   <o>RTX Kernel timer number
//     <0=> Timer 0 <1=> Timer 1 <2=> Timer 2 <3=> Timer 3
//   <i> Define the ARM timer used as a system tick timer.
//   <i> Default: Timer 0
#ifndef OS_TIMER
 #define OS_TIMER       0
#endif

//   <o>Timer clock value [Hz] <1-1000000000>
//   <i> Set the timer clock value for selected timer.
//   <i> Default: 12000000  (12MHz at 48MHz RCLK and prescaler by 4)
#ifndef OS_CLOCK
 #define OS_CLOCK       12000000
#endif

//   <o>Timer tick value [us] <1-1000000>
//   <i> Set the timer tick value for selected timer.
//   <i> Default: 10000  (10ms)
#ifndef OS_TICK
 #define OS_TICK        10000
#endif

// </h>
// <e>Round-Robin Task switching
// =============================
// <i> Enable Round-Robin Task switching.
#ifndef OS_ROBIN
 #define OS_ROBIN       1
#endif

//   <o>Round-Robin Timeout [ticks] <1-1000>
//   <i> Define how long a task will execute before a task switch.
//   <i> Default: 5
#ifndef OS_ROBINTOUT
 #define OS_ROBINTOUT   5
#endif

// </e>

//------------- <<< end of configuration section >>> -----------------------

/*----------------------------------------------------------------------------
 *      RTX User configuration part END
 *---------------------------------------------------------------------------*/

#if   (OS_TIMER == 0)                                   /* Timer 0          */
  #define OS_TID_       0                               /*  Timer ID        */
  #define TIMx          TIM0
#elif (OS_TIMER == 1)                                   /* Timer 1          */
  #define OS_TID_       19                              /*  Timer ID        */
  #define TIMx          TIM1
#elif (OS_TIMER == 2)                                   /* Timer 2          */
  #define OS_TID_       20                              /*  Timer ID        */
  #define TIMx          TIM2
#elif (OS_TIMER == 3)                                   /* Timer 3          */
  #define OS_TID_       21                              /*  Timer ID        */
  #define TIMx          TIM3
#else
  #error OS_TIMER invalid
#endif

#define OS_TIM_         (1 << OS_TID_)                  /*  Interrupt Mask  */
#define OS_TRV          ((U16)(((double)OS_CLOCK*(double)OS_TICK)/1E8)-5)
#define OS_TVAL         ((TIMx->CNTR + 4) & 0xFFFF)     /*  Timer Value     */
#define OS_TOVF          (TIMx->SR & TIM_OCFB)          /*  Overflow Flag   */
#define OS_TREL()       ;                               /*  Timer Reload    */
#define OS_TFIRQ()      TIMx->CR2 |=  TIM_TOE_Mask;     /*  Force Interrupt */
#define OS_TIACK()      TIMx->CR2 &= ~TIM_TOE_Mask;     /*  Interrupt Ack   */ \
                        TIMx->SR   = ~TIM_OCFB;                                \
                        EIC->IPR   =  OS_TIM_;
#define OS_TINIT()      TIMx->OCBR =  OS_TRV;           /*  Initialization  */ \
                        TIMx->CR2  =  TIM_OCBIE_mask | (100 - 1);              \
                        TIMx->CR1  =  TIM_PWM_Mask | TIM_EN_Mask;              \
                        EIC->IVR   =  (U32)os_clock_interrupt;                 \
                        EIC->SIR[OS_TID_] = 1 |                                \
                                      ((U32)os_clock_interrupt << 16);         \
                        EIC->IER  |=  OS_TIM_;

#define OS_IACK()       ;                               /* Interrupt Ack    */

#define OS_LOCK()       EIC->ICR  &= ~0x0001;           /* Task Lock        */
#define OS_UNLOCK()     EIC->ICR  |=  0x0001;           /* Task Unlock      */

/* WARNING ! Do not use IDLE mode if you are using a JTAG interface  */
/*           for debugging your application.                         */
#define _idle_()        RCCU->SMR &= ~1;
#define INITIAL_CPSR    0x40000010
#define MAGIC_WORD      0xE25A2EA5

/*----------------------------------------------------------------------------
 *      Global Variables
 *---------------------------------------------------------------------------*/

extern P_TCB os_runtask;
extern struct OS_XCB os_rdy;
extern struct OS_TCB os_clock_TCB;
extern U16 os_time;
#pragma push
#pragma O0
U16 const os_maxtaskrun = OS_TASKCNT;
/* Export following defines to uVision debugger. */
U32 const os_stackinfo = (OS_STKCHECK<<24) | (OS_PRIVCNT<<16) | (OS_STKSIZE*4);
U32 const os_clockrate =  OS_TICK;
U32 const os_timernum  = (OS_TIMER << 16) | OS_TIMERCNT;
U32 const os_rrobin    = (OS_ROBIN << 16) | OS_ROBINTOUT;
#pragma pop

/*----------------------------------------------------------------------------
 *      Local Variables
 *---------------------------------------------------------------------------*/
/* Memory pool for TCB allocation    */
_declare_box (static m_tcb, sizeof(struct OS_TCB), OS_TASKCNT);

/* Memory pool for System stack allocation. Need to allocate 2 additional  */
/* entries for 'os_clock_demon()' and 'os_idle_demon()'.                   */
_declare_box8 (static m_stk, OS_STKSIZE*4, OS_TASKCNT-OS_PRIVCNT+2);

/* An array of Active task pointers.                                       */
P_TCB os_active_TCB[OS_TASKCNT];

#if (OS_ROBIN == 1)
  static U16  os_robin_time;
  static P_TCB os_tsk_robin;
#endif

#if (OS_TIMERCNT != 0)
  /* Memory pool for User Timer allocation                                 */
  _declare_box (static m_tmr, sizeof(struct OS_TMR), OS_TIMERCNT);
#endif

#if (OS_STKCHECK == 1)
  static BIT os_del_flag;
#endif

/*----------------------------------------------------------------------------
 *      Global Functions
 *---------------------------------------------------------------------------*/

extern void os_clock_interrupt (void);

/*--------------------------- os_idle_demon ---------------------------------*/

void os_idle_demon (void) __task {
   /* The idle demon is a system task. It is running when no other task is   */
   /* ready to run (idle situation). It must not terminate. Therefore it     */
   /* should contain at least an endless loop.                               */

   for (;;) {
   /* HERE: include here optional user code to be executed when no task runs.*/
   }
} /* end of os_idle_demon */


/*--------------------------- os_tmr_call -----------------------------------*/

void os_tmr_call (U16 info) {
   /* This function is called when the user timer has expired.               */
   /* Parameter "info" is the parameter defined when the timer was created.  */
   /* HERE: include here optional user code to be executed on timeout.       */
   info = info;
} /* end of os_tmr_call */

/*--------------------------- os_stk_overflow -------------------------------*/

#if (OS_STKCHECK == 1)
static void os_stk_overflow (void) {
   /* This function is called when a stack overflow is detected.             */
   /*  'os_runtask' points to a TCB of a task which has a stack overflow     */
   /*  'task_id'    holds a task id for this task                            */
   /* HERE: include here optional code to be executed on stack overflow.     */
   static volatile OS_TID task_id;

   /* Get a task identification for a task with stack problem to 'task_id'.*/
   task_id = os_get_TID (os_runtask);
   /* Use a uVision 'RTX Kernel' debug dialog page 'Active Tasks' to      */
   /* check which task has got a stack overflow and needs a bigger stack. */
   for (;;);
}
#endif

/*--------------------------- os_clock_interrupt0 ---------------------------*/

U32 os_clock_interrupt0 (U32 stack) {
   /* Do task switch to clock demon: entered upon a clock interrupt. Saving */
   /* and restoring context is written in assembly (module: Irq_RTX.s)      */
   OS_TIACK();
   OS_LOCK();
   os_runtask->tsk_stack = stack;
   os_runtask->full_ctx = __TRUE;
   os_runtask->state  = READY;
   os_put_rdy_first (os_runtask);
   os_runtask = &os_clock_TCB;
   os_clock_TCB.state = RUNNING;
   return (os_runtask->tsk_stack);
} /* end of os_clock_interrupt0 */

⌨️ 快捷键说明

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