|
楼主 |
发表于 2016-6-21 00:18:37
|
显示全部楼层
首先,我好久没用 uC/OS-II了,我现在现在在用uC/OS-III (发现并使用uC/Probe这个软件之前,我就开始用uC/OS-III),所以现在我也没有uC/OS-II的工程和硬件可以测试。
然后在说下你说的这2个地方, 自从uC/OS-III开始,它的代码把跟CPU操作有关的一些定义和函数单独提取出来形成了一个“uC-CPU”的库了,记得之前看 uC/OS-III 书籍中作者说是为了更容易通过某些软件认证,具体的不详。
我刚刚也看了,我的代码中,确实有调用过这些函数(也是以前用官方的移植代码中Copy过来的),如下是我现在工程的Main函数:
- int main(void)
- {
- OS_ERR err;
-
- NVIC_SetVectorTable(NVIC_VectTab_FLASH,SystemAddress - 0x08000000);
-
- CPU_Init(); /* Initialize the uC/CPU services */
- Mem_Init(); /* Initialize Memory Mmanagment Module */
-
- CPU_IntDis();
- OSInit(&err); //OS初始化
- Task_Monitor_Create(); //建立任务监视器任务(其他任务在此任务中创建)
- OSStart(&err); //启动OS,打开总中断
- return(0);
- }
复制代码
我刚刚也试了,把这些函数屏蔽掉,在编译运行的话,虽然硬件也可以工作,但是uC/Probe却无法显示任务信息了。 至于uC/OS-II该如何解决,我就不清楚了。你可以试试在 Micrium 官网找个 uC/OS-II 移植的工程,看看里面有没有相应的代码。
此外,在第一个任务中,系统时钟打开、硬件初始化完毕后,建立其他任务之前,还运行了如下代码:
- cpu_clk_freq = BSP_CPU_ClkFreq(); /* Determine SysTick reference freq. */
- cnts = cpu_clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz; /* Determine nbr SysTick increments */
- OS_CPU_SysTickInit(cnts); /* Init uC/OS periodic time src (SysTick). */ /* Initialize Memory Management Module */
- #if OS_CFG_STAT_TASK_EN > 0u
- OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
- #endif
复制代码
以下是另外一些函数,也是从官方的工程中Copy过来的:(BSP_Init()函数除外,这个是我自己写的)
- #include "bsp.h"
- /*
- *********************************************************************************************************
- * REGISTERS
- *********************************************************************************************************
- */
- #define DWT_CR *(CPU_REG32 *)0xE0001000
- #define DWT_CYCCNT *(CPU_REG32 *)0xE0001004
- #define DEM_CR *(CPU_REG32 *)0xE000EDFC
- #define DBGMCU_CR *(CPU_REG32 *)0xE0042004
- /*
- *********************************************************************************************************
- * REGISTER BITS
- *********************************************************************************************************
- */
- #define DBGMCU_CR_TRACE_IOEN_MASK 0x10
- #define DBGMCU_CR_TRACE_MODE_ASYNC 0x00
- #define DBGMCU_CR_TRACE_MODE_SYNC_01 0x40
- #define DBGMCU_CR_TRACE_MODE_SYNC_02 0x80
- #define DBGMCU_CR_TRACE_MODE_SYNC_04 0xC0
- #define DBGMCU_CR_TRACE_MODE_MASK 0xC0
- #define DEM_CR_TRCENA (1 << 24)
- #define DWT_CR_CYCCNTENA (1 << 0)
- /*
- *********************************************************************************************************
- * BSP_Init()
- *
- * Description : Initialize the Board Support Package (BSP).
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : Application.
- *
- * Note(s) : (1) This function SHOULD be called before any other BSP function is called.
- *********************************************************************************************************
- */
- void BSP_Init (void)
- {
- GPIO_DeInit(GPIOA);
- GPIO_DeInit(GPIOB);
- GPIO_DeInit(GPIOC);
- GPIO_DeInit(GPIOD);
- GPIO_DeInit(GPIOE);
- GPIO_DeInit(GPIOF);
- GPIO_DeInit(GPIOG);
-
- IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); /* 写入0x5555,使能看门狗寄存器的写入*/
- IWDG_SetPrescaler(IWDG_Prescaler_256); /* 时钟分频,40K/256=156HZ(6.4ms)*/
- IWDG_SetReload(3125); /* 喂狗时间 20s/6.4ms=3125 .注意不能大于0xfff*/
- IWDG_ReloadCounter();
- IWDG_Enable();
-
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
- PWR_BackupAccessCmd(ENABLE);
-
- Delay_Init();
- RTC_Init();
- SRAM_Init();
- LCD_X_TFT_Init();
- Relay_Init();
- LED_Init();
- Buzzer_Init();
- EEP_Init();
- DACx_Init();
- ADCx_Init();
- RS232_Init();
- CH376_PORT_INIT( ); /* 接口硬件初始化 */
-
- }
- /*
- *********************************************************************************************************
- * BSP_CPU_ClkFreq()
- *
- * Description : Read CPU registers to determine the CPU clock frequency of the chip.
- *
- * Argument(s) : none.
- *
- * Return(s) : The CPU clock frequency, in Hz.
- *
- * Caller(s) : Application.
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- CPU_INT32U BSP_CPU_ClkFreq (void)
- {
- RCC_ClocksTypeDef rcc_clocks;
- RCC_GetClocksFreq(&rcc_clocks);
- return ((CPU_INT32U)rcc_clocks.HCLK_Frequency);
- }
- /*
- *********************************************************************************************************
- * CPU_TS_TmrInit()
- *
- * Description : Initialize & start CPU timestamp timer.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : CPU_TS_Init().
- *
- * This function is an INTERNAL CPU module function & MUST be implemented by application/
- * BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
- *
- * Note(s) : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
- * if either of the following CPU features is enabled :
- *
- * (a) CPU timestamps
- * (b) CPU interrupts disabled time measurements
- *
- * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
- * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
- *
- * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
- * data type.
- *
- * (1) If timer has more bits, truncate timer values' higher-order bits greater
- * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
- *
- * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
- * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
- * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
- *
- * In other words, if timer size is not a binary-multiple of 8-bit octets
- * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
- * octet word size SHOULD be configured (e.g. to 16-bits). However, the
- * minimum supported word size for CPU timestamp timers is 8-bits.
- *
- * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
- * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
- *
- * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
- *
- * (c) When applicable, timer period SHOULD be less than the typical measured time
- * but MUST be less than the maximum measured time; otherwise, timer resolution
- * inadequate to measure desired times.
- *
- * See also 'CPU_TS_TmrRd() Note #2'.
- *********************************************************************************************************
- */
- #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
- void CPU_TS_TmrInit (void)
- {
- CPU_INT32U cpu_clk_freq_hz;
- DEM_CR |= (CPU_INT32U)DEM_CR_TRCENA; /* Enable Cortex-M3's DWT CYCCNT reg. */
- DWT_CYCCNT = (CPU_INT32U)0u;
- DWT_CR |= (CPU_INT32U)DWT_CR_CYCCNTENA;
- cpu_clk_freq_hz = BSP_CPU_ClkFreq();
- CPU_TS_TmrFreqSet(cpu_clk_freq_hz);
- }
- #endif
- /*$PAGE*/
- /*
- *********************************************************************************************************
- * CPU_TS_TmrRd()
- *
- * Description : Get current CPU timestamp timer count value.
- *
- * Argument(s) : none.
- *
- * Return(s) : Timestamp timer count (see Notes #2a & #2b).
- *
- * Caller(s) : CPU_TS_Init(),
- * CPU_TS_Get32(),
- * CPU_TS_Get64(),
- * CPU_IntDisMeasStart(),
- * CPU_IntDisMeasStop().
- *
- * This function is an INTERNAL CPU module function & MUST be implemented by application/
- * BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
- *
- * Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
- * if either of the following CPU features is enabled :
- *
- * (a) CPU timestamps
- * (b) CPU interrupts disabled time measurements
- *
- * See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
- * & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
- *
- * (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
- * data type.
- *
- * (1) If timer has more bits, truncate timer values' higher-order bits greater
- * than the configured 'CPU_TS_TMR' timestamp timer data type word size.
- *
- * (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
- * timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
- * configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
- *
- * In other words, if timer size is not a binary-multiple of 8-bit octets
- * (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
- * octet word size SHOULD be configured (e.g. to 16-bits). However, the
- * minimum supported word size for CPU timestamp timers is 8-bits.
- *
- * See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
- * & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
- *
- * (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
- *
- * (1) If timer is a 'down' counter whose values decrease with each time count,
- * then the returned timer value MUST be ones-complemented.
- *
- * (c) (1) When applicable, the amount of time measured by CPU timestamps is
- * calculated by either of the following equations :
- *
- * (A) Time measured = Number timer counts * Timer period
- *
- * where
- *
- * Number timer counts Number of timer counts measured
- * Timer period Timer's period in some units of
- * (fractional) seconds
- * Time measured Amount of time measured, in same
- * units of (fractional) seconds
- * as the Timer period
- *
- * Number timer counts
- * (B) Time measured = ---------------------
- * Timer frequency
- *
- * where
- *
- * Number timer counts Number of timer counts measured
- * Timer frequency Timer's frequency in some units
- * of counts per second
- * Time measured Amount of time measured, in seconds
- *
- * (2) Timer period SHOULD be less than the typical measured time but MUST be less
- * than the maximum measured time; otherwise, timer resolution inadequate to
- * measure desired times.
- *********************************************************************************************************
- */
- #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
- CPU_TS_TMR CPU_TS_TmrRd (void)
- {
- return ((CPU_TS_TMR)DWT_CYCCNT);
- }
- #endif
复制代码
以上代码供参考。 |
|