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

📄 rtx_config.c

📁 Keil UV3中自带操作系统ARTX的应用例程
💻 C
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
 *      R T L  -  K e r n e l
 *----------------------------------------------------------------------------
 *      Name:    RTX_CONFIG.C
 *      Purpose: Configuration of RTX Kernel for Philips LPC21xx
 *      Rev.:    V3.00 / 17-mar-2006
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2006 KEIL - An ARM Company. All rights reserved. 
 *---------------------------------------------------------------------------*/

#include <RTX_Config.h>                  /* RTX user configuration header    */
#pragma O0

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

//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
// <e>Task Mode Select
//   <o>Task Mode Select <0-1>
//   <i> Define max. number of tasks that will run at the same time.
//   <i> Default: 0
#ifndef OS_MODESEL
 #define OS_MODESEL     1//OS选择非典的中断向量编号模式
#endif

#if (OS_MODESEL == 0) //OS中断向量地址/编号模式选择
  #include <LPC213x.H>                     /* LPC21xx definitions              */
#else
  #include <LPC213xDEF.H>	//ARM菜鸟HotPower创建定义文件(愚人节预演版)
#endif
// </e>
//
// <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     7
#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//指定每一个任务的栈尺寸(32位字,此数乘4为栈字节数)
 #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//使能(1) 或禁止(0) 堆栈检查
 #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//指定用户定时器的数量(在回调函数os_tmr_call()里编写程序)
 #define OS_TIMERCNT    1
#endif

// </h>
// <h>System Timer Configuration
// =============================
//   <o>ARTX Kernel timer number <0=> Timer 0 <1=> Timer 1
//   <i> Define the ARM timer used as a system tick timer.
//   <i> Default: Timer 0
#ifndef OS_TIMER//指定一个片上定时器, 用作实时系统的时基, 可以是0 或1
 #define OS_TIMER       1
#endif

//   <o>Timer clock value [Hz] <1-1000000000>
//   <i> Set the timer clock value for selected timer.
//   <i> Default: 15000000  (15MHz at 60MHz CCLK and VPBDIV = 4)
#ifndef OS_CLOCK//指定所选择定时器的输入信号频率
 #define OS_CLOCK       15000000
#endif

//   <o>Timer tick value [us] <1-1000000>
//   <i> Set the timer tick value for selected timer.
//   <i> Default: 10000  (10ms)
#ifndef OS_TICK//指定系统定时的时间间隔, 单位为uS
 #define OS_TICK        10000
#endif

// </h>
// <e>Round-Robin Task switching
// =============================
// <i> Enable Round-Robin Task switching.
#ifndef OS_ROBIN//使能(1) 或禁止(0) 时间片轮转任务调度
 #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 >>> -----------------------

/*----------------------------------------------------------------------------
 *      ARTX User configuration part END
 *---------------------------------------------------------------------------*/

#if   (OS_TIMER == 0)                                   /* Timer 0          */
  #define OS_TID_       4                               /*  Timer ID        */
  #define OS_TIM_       (1 << OS_TID_)                  /*  Interrupt Mask  */
//OS_TRV指定定时器的重载值
  #define OS_TRV        ((U32)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
//OS_TVAL用于读取定时器的当前值
  #if (OS_MODESEL == 0)
    #define OS_TVAL       T0TC                            /*  Timer Value     */
  #else
    #define OS_TVAL       T0->TIMER_TC                            /*  Timer Value     */
  #endif
//OS_TOVF指定定时器溢出标志
  #if (OS_MODESEL == 0)
    #define OS_TOVF       (T0IR & 1)                      /*  Overflow Flag   */
  #else
    #define OS_TOVF       (T0->TIMER_IR & 1)                      /*  Overflow Flag   */
  #endif
//OS_TREL()定义定时器重载的指令序列
  #define OS_TREL()     ;                               /*  Timer Reload    */
//OS_TFIRQ()定义强制定时器中断的指令序列
  #if (OS_MODESEL == 0)
    #define OS_TFIRQ()    VICSoftInt   |= OS_TIM_;        /*  Force Interrupt */
  #else
    #define OS_TFIRQ()    VIC->SoftInt   |= OS_TIM_;        /*  Force Interrupt */
  #endif
//OS_TIACK()用于清除定时器中断的逻辑
  #if (OS_MODESEL == 0)
  #define OS_TIACK()    T0IR = 1;                       /*  Interrupt Ack   */ \
                        VICSoftIntClr = OS_TIM_;                               \
                        VICVectAddr   = 0;
  #else
  #define OS_TIACK()    T0->TIMER_IR = 1;                       /*  Interrupt Ack   */ \
                        VIC->SoftIntClr = OS_TIM_;                               \
                        VIC->VectAddr   = 0;
  #endif
//OS_TINIT()用于定义定时器的初始化代码
  #if (OS_MODESEL == 0)
  #define OS_TINIT()    T0MR0 = OS_TRV;                 /*  Initialization  */ \
                        T0MCR = 3;                                             \
                        T0TCR = 1;                                             \
                        VICDefVectAddr = (U32)os_def_interrupt;                 \
                        VICVectAddr15  = (U32)os_clock_interrupt;               \
                        VICVectCntl15  = 0x20 | OS_TID_;
  #else
  #define OS_TINIT()    T0->TIMER_MR0 = OS_TRV;                 /*  Initialization  */ \
                        T0->TIMER_MCR = 3;                                             \
                        T0->TIMER_TCR = 1;                                             \
                        VIC->DefVectAddr = 31;/*(U32)os_def_interrupt*/          \
                        VIC->VectAddrs[15]  = 15;/*(U32)os_clock_interrupt*/        \
                        VIC->VectCntls[15]  = 0x20 | OS_TID_;
  #endif
#elif (OS_TIMER == 1)                                   /* Timer 1          */
  #define OS_TID_       5                               /*  Timer ID        */
  #define OS_TIM_       (1 << OS_TID_)                  /*  Interrupt Mask  */
  #define OS_TRV        ((U32)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
  #if (OS_MODESEL == 0)
    #define OS_TVAL       T1TC                            /*  Timer Value     */
  #else
    #define OS_TVAL       T1->TIMER_TC                            /*  Timer Value     */
  #endif
  #if (OS_MODESEL == 0)
    #define OS_TOVF       (T1IR & 1)                      /*  Overflow Flag   */
  #else
    #define OS_TOVF       (T1->TIMER_IR & 1)                      /*  Overflow Flag   */
  #endif
  #define OS_TREL()     ;                               /*  Timer Reload    */
  #if (OS_MODESEL == 0)
    #define OS_TFIRQ()    VICSoftInt   |= OS_TIM_;        /*  Force Interrupt */
  #else
    #define OS_TFIRQ()    VIC->SoftInt   |= OS_TIM_;        /*  Force Interrupt */
  #endif
  #if (OS_MODESEL == 0)
  #define OS_TIACK()    T1IR = 1;                       /*  Interrupt Ack   */ \
                        VICSoftIntClr = OS_TIM_;                               \
                        VICVectAddr   = 0;
  #else
  #define OS_TIACK()    T1->TIMER_IR = 1;                       /*  Interrupt Ack   */ \
                        VIC->SoftIntClr = OS_TIM_;                               \
                        VIC->VectAddr   = 0;
  #endif
  #if (OS_MODESEL == 0)
  #define OS_TINIT()    T1MR0 = OS_TRV;                 /*  Initialization  */ \
                        T1MCR = 3;                                             \
                        T1TCR = 1;                                             \
                        VICDefVectAddr = (U32)os_def_interrupt;          \
                        VICVectAddr15  = (U32)os_clock_interrupt;        \
                        VICVectCntl15  = 0x20 | OS_TID_;
  #else
  #define OS_TINIT()    T1->TIMER_MR0 = OS_TRV;                 /*  Initialization  */ \
                        T1->TIMER_MCR = 3;                                             \
                        T1->TIMER_TCR = 1;                                             \
                        VIC->DefVectAddr = 31;/*(U32)os_def_interrupt*/          \
                        VIC->VectAddrs[15]  = 15;/*(U32)os_clock_interrupt*/        \
                        VIC->VectCntls[15]  = 0x20 | OS_TID_;
  #endif
#else
  #error OS_TIMER invalid
#endif

#if (OS_MODESEL == 0)
  #define OS_IACK()       VICVectAddr   = 0;              /* Interrupt Ack    */
#else
  #define OS_IACK()       VIC->VectAddr   = 0;              /* Interrupt Ack    */
#endif
//OS_LOCK()禁止系统定时器中断
#if (OS_MODESEL == 0)
  #define OS_LOCK()       VICIntEnClr   = OS_TIM_;        /* Task Lock        */
#else
  #define OS_LOCK()       VIC->IntEnClr   = OS_TIM_;        /* Task Lock        */
#endif
//OS_UNLOCK()使能系统定时器中断
#if (OS_MODESEL == 0)
  #define OS_UNLOCK()     VICIntEnable |= OS_TIM_;        /* Task Unlock      */
#else
  #define OS_UNLOCK()     VIC->IntEnable |= OS_TIM_;        /* Task Unlock      */
#endif

/* WARNING ! Do not use IDLE mode if you are using a JTAG interface  */
/*           for debugging your application.                         */
#if (OS_MODESEL == 0)
  #define _idle_()        PCON = 1;
#else
  #define _idle_()        POWER->P_CON = 1;
#endif
#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;
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;

/*----------------------------------------------------------------------------
 *      Local Variables
 *---------------------------------------------------------------------------*/
/* Memory pool for TCB allocation    */
static U32 m_tcb[(sizeof(struct OS_TCB) * OS_TASKCNT)/4 + 4];

/* Memory pool for System stack allocation. Need to allocate 2 additional  */
/* entries for 'os_clock_demon()' and 'os_idle_demon()'.                   */
static U64 m_stk[OS_STKSIZE * (OS_TASKCNT-OS_PRIVCNT+2)/2 + 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                                 */
  static U32 m_tmr[(sizeof(struct OS_TMR) * OS_TIMERCNT)/4 + 4];
#endif

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

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

extern void os_clock_interrupt (void);

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

⌨️ 快捷键说明

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