本帖最后由 chinesecom 于 2020-4-20 16:32 编辑
是一个初始默认任务,如下: 全速运行下面的程序不会死机;
int main(void)
{
hardware_init();
// log_info("Hardware Init Done!");
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityRealtime, 0,2048 );//1024
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
// if (defaultTaskHandle == NULL)log_info("defaultTask create fail");
// else log_info("defaultTask create OK");
// LCD_Clear(LCD_COLOR_WHITE);
// Create_Shtxx_thread(&sht20);
/* Create_pm2_5_thread(&pm2008ms);
Create_ch2o_thread(&ze08b);
//Create_rs485_thread(&RS485);
//Create_Gizwits_thread();
Create_ui_thread_thread();
Create_voc_thread_thread();*/
osKernelStart();
while(1){
led.toggle(&led);
sht20.ReadTemp(&sht20);
// log_info("sht20 temp is %0.3f",sht20.Temperature);
delay_1ms(200);
}
}
void StartDefaultTask(void const * argument)
{
uint8_t isbuzzeron = 0;
uint8_t key2sta = 0,key2oldsta = 0;
uint32_t batvol = 0;
uint16_t timedelaytosleep = 0;
while(1)
{
osDelay(100);
Freedog();
led.toggle(&led);
if(!KEY1.read(&KEY1))
{
// log_info("KEY1 Press!!");
BUZZER.set_bit(&BUZZER);
// osSignalSet(Gizwits_thread_Handle,KEY1SIG);
isbuzzeron = 1;
}
if(TOUCH_KEY.read(&TOUCH_KEY))
{
// log_info("TOUCH_KEY Press!!");
entrynormalmode();
// log_info("KEY2 switch to low..Entry normal run.");
BUZZER.set_bit(&BUZZER);
isbuzzeron = 1;
}
if(voc_type == BAD || (ze08b.value/1000.0 > 0.15)||pm2008ms.value>150)
{
BUZZER.set_bit(&BUZZER);
isbuzzeron = 1;
}
if(isbuzzeron) isbuzzeron++;
if(isbuzzeron > 3)
{
BUZZER.reset_bit(&BUZZER);
isbuzzeron = 0;
}
key2sta = KEY2.read(&KEY2);
if(key2sta != key2oldsta)
{
key2oldsta = key2sta;
if(key2sta)
{
// log_info("KEY2 switch to high..After 1 min ,Entry sleep.");
timedelaytosleep = 1;
// entrysleepmode();
}
else{
// log_info("KEY2 switch to low..Entry normal run.");
entrynormalmode();
}
}
if(timedelaytosleep) timedelaytosleep++;
if(timedelaytosleep > 10 * 60)
{
entrysleepmode();
timedelaytosleep = 0;
}
batvol = 0;
for(uint8_t i = 0;i<200;i++)
{
batvol += vbat_adc_value;
}
batvol = batvol/200;
batvol = batvol * 3300 *2/4095;
batlevel = ((batvol - SHUTDOWNPOW) * 100 /(FULLPOW - SHUTDOWNPOW));
if(batlevel > 100) batlevel = 100;
}
}
为什么我把任务里的entrynormalmode()函数里面的几句屏蔽了就死机呢?全速执行1分钟左右会出现执行到taskSELECT_HIGHEST_PRIORITY_TASK();就卡死机。或者将上面的if语句后面的都屏蔽掉也是这样。void entrynormalmode(void)
{
TFT_VCC_CTL = new_outport(GPIOA,GPIO_PIN_1);
TFT_VCC_CTL.reset_bit(&TFT_VCC_CTL);
SDRAM_VCC_CTL = new_outport(GPIOE,GPIO_PIN_6);
SDRAM_VCC_CTL.reset_bit(&SDRAM_VCC_CTL);
exmc_synchronous_dynamic_ram_init(EXMC_SDRAM_DEVICE0);
TLI_Init();
spi_flash = new_spi_flash(GPIOB,GPIO_PIN_3,GPIO_PIN_4,GPIO_PIN_5,SPI0,GPIOG,GPIO_PIN_14);
spi_flash.spi.Quadspi_init(&spi_flash.spi,GPIOB,GPIO_PIN_6,GPIO_PIN_7);
spi_flash.Init(&spi_flash);
spi_flash.Read(&spi_flash,(uint8_t*)0xc0000000,0x0,800*480*sizeof(uint16_t));
}保留前两句,后面几句屏蔽掉。
|
只是做了一个空任务。如图。是运行一段10几秒后进入死循环:F10后一直在taskSELECT_HIGHEST_PRIORITY_TASK()不会往下走。