最近入门ucosiii。自己移植的这个同时开2个进程好像延时不了,流水灯不行,一直是亮,在延时卡死,但是如果去掉task2进程就可以的,求解
static void task1(void *p_arg);
static void task2(void *p_arg);
static void startup_task(void *p_arg);
static CPU_STK startup_task_stk[APP_TASK_START_STK_SIZE];
static CPU_STK task1_stk[TASK1_STK_SIZE];
static CPU_STK task2_stk[TASK2_STK_SIZE];
static OS_TCB AppTaskStartTCB;
static OS_TCB Task1_TCB;
static OS_TCB Task2_TCB;
static volatile OS_SEM taskSem;
#define DWT_CR *(CPU_REG32 *)0xE0001000
#define DWT_CYCCNT *(CPU_REG32 *)0xE0001004
#define DEM_CR *(CPU_REG32 *)0xE000EDFC
#define DBGMCU_CR *(CPU_REG32 *)0xE0042004
#define DEM_CR_TRCENA (1 << 24)
#define DWT_CR_CYCCNTENA (1 << 0)
/*CPU_INT32U BSP_CPU_ClkFreq (void)
{
RCC_ClocksTypeDef rcc_clocks;
RCC_GetClocksFreq(&rcc_clocks);
return ((CPU_INT32U)rcc_clocks.HCLK_Frequency);
} */
static void systick_init(void)
{
RCC_ClocksTypeDef rcc_clocks;
RCC_GetClocksFreq(&rcc_clocks);
SysTick_Config(rcc_clocks.HCLK_Frequency / OS_TICKS_PER_SEC);
LED0 = 0;
LED1 = 0;
LED2 = 0;
LED3 = 0;
}
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
void CPU_TS_TmrInit (void)
{
}
#endif
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
CPU_TS_TMR CPU_TS_TmrRd (void)
{
return (SysTick->VAL);
}
#endif
static void task1(void *p_arg)
{
OS_ERR err;
while(1)
{
LED0 = 1;
LED1 = 1;
LED2 = 1;
LED3 = 1;
OSTimeDly(100,OS_OPT_TIME_DLY, &err) ;
LED0 = 0;
LED1 = 0;
LED2 = 0;
LED3 = 0;
OSTimeDly(100,OS_OPT_TIME_DLY, &err) ;
}
}
static void task2(void *p_arg)
{ OS_ERR err;
for (;;)
{
if(KEY0 == 0)
{
LED0 = 1;
}
if(KEY1 == 0)
{
LED0 = 0;
}
if(KEY2 ==0)
{
LED2 = 1;
}
}
}
static void startup_task(void *p_arg)
{
OS_ERR err;
CPU_INT32U cpu_clk_freq;
CPU_INT32U cnts;
// while(SysTick_Config(SystemFrequency / OS_TICKS_PER_SEC)); /* Initialize the SysTick. */
key_init();
led_init();
OSTaskCreate((OS_TCB *)&Task1_TCB,
(CPU_CHAR *)"task1",
(OS_TASK_PTR ) task1,
(void *) 0,
(OS_PRIO ) TASK1_PRIO,
(CPU_STK *)&task1_stk[0],
(CPU_STK_SIZE) TASK1_STK_SIZE / 10,
(CPU_STK_SIZE) TASK1_STK_SIZE,
(OS_MSG_QTY ) 0,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskCreate((OS_TCB *)&Task2_TCB,
(CPU_CHAR *)"task2",
(OS_TASK_PTR ) task2,
(void *) 0,
(OS_PRIO ) TASK2_PRIO,
(CPU_STK *)&task2_stk[0],
(CPU_STK_SIZE) TASK2_STK_SIZE / 10,
(CPU_STK_SIZE) TASK2_STK_SIZE,
(OS_MSG_QTY ) 0,
(OS_TICK ) 0,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSSemCreate( (OS_SEM *)&taskSem,
(CPU_CHAR *)"taskSem",
(OS_SEM_CTR )0,
(OS_ERR *)err);
OSTaskDel( (OS_TCB *)&AppTaskStartTCB,
(OS_ERR *)&err);
// OSTaskDel(OS_PRIO_SELF);
}
int main(void)
{
OS_ERR err;
SystemInit();
systick_init();
CPU_Init();
OSInit(&err);
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"startup tast",
(OS_TASK_PTR ) startup_task,
(void *) 0,
(OS_PRIO ) APP_TASK_START_PRIO,
(CPU_STK *)&startup_task_stk[0],
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE / 10,
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err);
return 0;
}
|
|