初级会员
- 积分
- 145
- 金钱
- 145
- 注册时间
- 2015-4-18
- 在线时间
- 17 小时
|
1金钱
问题:去掉FATFS任务,CAN、LWIP可以正常运行,加上FATFS任务以后,程序运行到FATFS就会死机
请各位大神帮忙解决一下,谢谢
#include "can.h"
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "timer.h"
#include "sram.h"
#include "malloc.h"
#include "string.h"
#include "usmart.h"
#include "dm9000.h"
#include "lwip/netif.h"
#include "lwip_comm.h"
#include "lwipopts.h"
#include "includes.h"
#include "tcp_client_demo.h"
#include "rtc.h"
#include "sdio_sdcard.h"
#include "w25qxx.h"
#include "ff.h"
#include "exfuns.h"
#include "beep.h"
#include "fattester.h"
// ζè′«¸DÆ÷¡¢êa¶è′«¸DÆ÷μÄí·Îļt
#include "dht11.h"
#include "ds18b20.h"
/********************************
ALIENTEKÕ½½¢STM32¿a·¢°åLWIPêμÑé
»ùóúNETCONN APIμÄTCP¿í»§¶ËêμÑé
¼¼êõÖ§3Ö£owww.openedv.com
ìÔ±|μêÆì£ohttp://eboard.taobao.com
1Øע΢DÅ1«Öúƽì¨Î¢DÅoÅ£o"ÕyμãÔ-×ó"£¬Ãa·Ñ»ñè¡STM32×êáÏ¡£
1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾
×÷ÕߣoÕyμãÔ-×ó @ALIENTEK
********************************/
u8 can_flag=0; // 0,cann't sent data; 1,sent data
u8 FATFS_flag=0;
u8 CWUwarningflag=0; //CWUμ¥Ôa±¨¾ˉ±êÖ¾
u8 eliminate=0; // Ïûéù±ê־λ
//u8 bit[50]; // CAN½óêÕêy¾YéèÖûo3åÇø
__align(4) u8 StoM[10]; // ′óÕ¾μ½Ö÷Õ¾μÄêy¾Y»o3åÇø
__align(4) u8 MtoS[10]; // Ö÷Õ¾μ½′óÕ¾μÄêy¾Y»o3åÇø
u8 sendflag; // ·¢Ëí±ê־λ
u8 receflag; // ½óêÕ±ê־λ
//DIR ddp; //FATFSèÎÎñÖD
//FIL fil;
//FRESULT FATres;
//UINT bww;
//u16 year;
//u8 month;
//u8 day;
//u8 hour;
//u8 min;
//u8 sec;
//KEYèÎÎñ
#define KEY_TASK_PRIO 9
//èÎÎñ¶ÑÕ»′óD¡
#define KEY_STK_SIZE 64
//èÎÎñ¶ÑÕ»
OS_STK KEY_TASK_STK[KEY_STK_SIZE];
//èÎÎñoˉêy
void key_task(void *pdata);
//LEDèÎÎñ
//èÎÎñóÅÏ輶
#define LED_TASK_PRIO 29
//èÎÎñ¶ÑÕ»′óD¡
#define LED_STK_SIZE 64
//èÎÎñ¶ÑÕ»
OS_STK LED_TASK_STK[LED_STK_SIZE];
//èÎÎñoˉêy
void led_task(void *pdata);
//ÔúLCDéÏÏÔê¾μØÖ·DÅÏ¢èÎÎñ
//èÎÎñóÅÏ輶
#define DISPLAY_TASK_PRIO 11
//èÎÎñ¶ÑÕ»′óD¡
#define DISPLAY_STK_SIZE 128
//èÎÎñ¶ÑÕ»
OS_STK DISPLAY_TASK_STK[DISPLAY_STK_SIZE];
//èÎÎñoˉêy
void display_task(void *pdata);
//CANèÎÎñ
#define CAN_TASK_PRIO 12
#define CAN_STK_SIZE 128
OS_STK CAN_TASK_STK[CAN_STK_SIZE];
void can_task(void *pdata);
//RTC Task
#define RTC_TASK_PRIO 13
#define RTC_STK_SIZE 128
OS_STK RTC_TASK_STK[RTC_STK_SIZE];
void RTC_Task(void *pdata);
//FATFS TASK
#define FATFS_TASK_PRIO 14
#define FATFS_STK_SIZE 256
OS_STK FATFS_TASK_STK[FATFS_STK_SIZE];
void FATFS_Task(void *pdata);
//BEEP TASK
#define BEEP_TASK_PRIO 15
#define BEEP_STK_SIZE 32
OS_STK BEEP_TASK_STK[BEEP_STK_SIZE];
void BEEP_Task(void *pdata);
//WARNING TASK ±¨¾ˉèÎÎñ
#define WARNING_TASK_PRIO 16
#define WARNING_STK_SIZE 64
OS_STK WARNING_TASK_STK[WARNING_STK_SIZE];
void warning_task(void *pdata);
////DHT11 TASK
//#define DHT11_TASK_PRIO 17
//#define DHT11_STK_SIZE 128
//OS_STK DHT11_TASK_STK[DHT11_STK_SIZE];
//void DHT11_Task(void *pdata);
////DS18B20 TASK
//#define DS18B20_TASK_PRIO 18
//#define DS18B20_STK_SIZE 128
//OS_STK DS18B20_TASK_STK[DS18B20_STK_SIZE];
//void DS18B20_Task(void *pdata);
// Soundproof Task // ÏûéùèÎÎñ
#define SOUNDPROOF_TASK_PRIO 19
#define SOUNDPROOF_STK_SIZE 64
OS_STK SOUNDPROOF_TASK_STK[SOUNDPROOF_STK_SIZE];
void Soundproof_Task(void *pdata);
//STARTèÎÎñ
//èÎÎñóÅÏ輶
#define START_TASK_PRIO 30
//èÎÎñ¶ÑÕ»′óD¡
#define START_STK_SIZE 128
//èÎÎñ¶ÑÕ»
OS_STK START_TASK_STK[START_STK_SIZE];
//èÎÎñoˉêy
void start_task(void *pdata);
//ÔúLCDéÏÏÔê¾μØÖ·DÅÏ¢
//mode:1 ÏÔê¾DHCP»ñè¡μ½μÄμØÖ·
// ÆäËû ÏÔê¾¾2ì¬μØÖ·
void show_address(u8 mode)
{
u8 buf[30];
POINT_COLOR = RED;
if(mode==2)
{
sprintf((char*)buf,"DHCP IP :%d.%d.%d.%d",lwipdev.ip[0],lwipdev.ip[1],lwipdev.ip[2],lwipdev.ip[3]); //′òó¡¶ˉì¬IPμØÖ·
LCD_ShowString(30,150,210,16,16,buf);
sprintf((char*)buf,"DHCP GW :%d.%d.%d.%d",lwipdev.gateway[0],lwipdev.gateway[1],lwipdev.gateway[2],lwipdev.gateway[3]); //′òó¡íø1ØμØÖ·
LCD_ShowString(30,190,210,16,16,buf);
sprintf((char*)buf,"NET MASK:%d.%d.%d.%d",lwipdev.netmask[0],lwipdev.netmask[1],lwipdev.netmask[2],lwipdev.netmask[3]); //′òó¡×óíøÑúÂëμØÖ·
LCD_ShowString(30,210,210,16,16,buf);
LCD_ShowString(30,230,210,16,16,"Port:8087!");
}
else
{
sprintf((char*)buf,"Static IP:%d.%d.%d.%d",lwipdev.ip[0],lwipdev.ip[1],lwipdev.ip[2],lwipdev.ip[3]); //′òó¡¶ˉì¬IPμØÖ·
LCD_ShowString(30,50,210,16,16,buf);
sprintf((char*)buf,"Static GW:%d.%d.%d.%d",lwipdev.gateway[0],lwipdev.gateway[1],lwipdev.gateway[2],lwipdev.gateway[3]); //′òó¡íø1ØμØÖ·
LCD_ShowString(30,70,210,16,16,buf);
sprintf((char*)buf,"NET MASK:%d.%d.%d.%d",lwipdev.netmask[0],lwipdev.netmask[1],lwipdev.netmask[2],lwipdev.netmask[3]); //′òó¡×óíøÑúÂëμØÖ·
LCD_ShowString(30,90,210,16,16,buf);
LCD_ShowString(30,110,210,16,16,"Port:8087!");
}
}
int main(void)
{
CAN_Mode_Init(CAN_SJW_1tq,CAN_BS2_8tq,CAN_BS1_9tq,4,CAN_Mode_LoopBack);//CAN3õê¼»ˉ»·»ØÄ£ê½,2¨ìØÂê500Kbps
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
uart_init(115200); //′®¿ú3õê¼»ˉÎa115200
LED_Init(); //LED¶Ë¿ú3õê¼»ˉ
LCD_Init(); //3õê¼»ˉLCD
KEY_Init(); //3õê¼»ˉ°′¼ü
BEEP_Init();
usmart_dev.init(72); //3õê¼»ˉUSMART
W25QXX_Init(); //3õê¼»ˉW25Q128
RTC_Init(); //RTC3õê¼»ˉ
FSMC_SRAM_Init(); //3õê¼»ˉía2¿SRAM
my_mem_init(SRAMIN); //3õê¼»ˉÄú2¿Äú′æ3Ø
my_mem_init(SRAMEX); //3õê¼»ˉía2¿Äú′æ3Ø
POINT_COLOR = BRED;
//TCP TEST+CAN Test
LCD_ShowString(10,10,400,16,16,"TCP CLIENT NETCONN Test+ CAN Test");
// Show TCP Client data
LCD_ShowString(10,310,400,16,16,"TCP Client Send Data:000 times");//ÏÔê¾TCP Client·¢ËíμÄêy¾Y
LCD_ShowString(10,370,400,16,16,"TCP Client Receive Data:000 times");//ÏÔê¾TCP Client½óêÕμÄêy¾Y
// POINT_COLOR = BLACK;
// LCD_ShowString(10,150,200,16,16,"CAN Sent Meg 000 times");//ÏÔê¾ìáê¾DÅÏ¢
POINT_COLOR = BLUE; //à¶é«×Öìå
OSInit(); //UCOS3õê¼»ˉ
while(lwip_comm_init()) //lwip3õê¼»ˉ
{
LCD_ShowString(10,130,200,20,16,"Lwip Init failed!"); //lwip3õê¼»ˉ꧰ü
delay_ms(500);
LCD_Fill(30,130,230,150,WHITE);
delay_ms(500);
}
LCD_ShowString(10,130,200,20,16,"Lwip Init Success!"); //lwip3õê¼»ˉ3é1|
while(tcp_client_init()) //3õê¼»ˉtcp_client(′′½¨tcp_clientÏß3ì)
{
LCD_ShowString(10,150,200,20,16,"TCP Client failed!!"); //tcp¿í»§¶Ë′′½¨ê§°ü
delay_ms(500);
LCD_Fill(30,150,230,170,WHITE);
delay_ms(500);
}
LCD_ShowString(10,150,200,20,16,"TCP Client Success!"); //udp′′½¨3é1|
OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO);
OSStart(); //¿aÆôUCOS
}
//startèÎÎñ
void start_task(void *pdata)
{
OS_CPU_SR cpu_sr;
pdata = pdata ;
OSStatInit(); //3õê¼»ˉí3¼ÆèÎÎñ
OS_ENTER_CRITICAL(); //1ØÖD¶Ï
OSTaskCreate(led_task,(void*)0,(OS_STK*)&LED_TASK_STK[LED_STK_SIZE-1],LED_TASK_PRIO); //′′½¨LEDèÎÎñ
OSTaskCreate(key_task,(void*)0,(OS_STK*)&KEY_TASK_STK[KEY_STK_SIZE-1],KEY_TASK_PRIO); //′′½¨KEYèÎÎñ
OSTaskCreate(display_task,(void*)0,(OS_STK*)&DISPLAY_TASK_STK[DISPLAY_STK_SIZE-1],DISPLAY_TASK_PRIO); //ÏÔê¾èÎÎñ
OSTaskCreate(can_task,(void*)0,(OS_STK*)&CAN_TASK_STK[CAN_STK_SIZE-1],CAN_TASK_PRIO);//′′½¨CAN task
OSTaskCreate(RTC_Task,(void*)0,(OS_STK*)&RTC_TASK_STK[RTC_STK_SIZE-1],RTC_TASK_PRIO);//′′½¨RTC task
OSTaskCreate(FATFS_Task,(void*)0,(OS_STK*)&FATFS_TASK_STK[FATFS_STK_SIZE-1],FATFS_TASK_PRIO);//′′½¨FATFS task
OSTaskCreate(warning_task,(void*)0,(OS_STK*)&WARNING_TASK_STK[WARNING_STK_SIZE-1],WARNING_TASK_PRIO);//′′½¨±¨¾ˉèÎÎñ
OSTaskCreate(Soundproof_Task,(void*)0,(OS_STK*)&SOUNDPROOF_TASK_STK[SOUNDPROOF_STK_SIZE-1],SOUNDPROOF_TASK_PRIO); // ÏûéùèÎÎñ
// OSTaskCreate(DHT11_Task,(void*)0,(OS_STK*)&DHT11_TASK_STK[DHT11_STK_SIZE-1],DHT11_TASK_PRIO);//′′½¨DHT11 task
//
// OSTaskCreate(DS18B20_Task,(void*)0,(OS_STK*)&DS18B20_TASK_STK[DS18B20_STK_SIZE-1],DS18B20_TASK_PRIO);//′′½¨DS18B20 task
OSTaskSuspend(OS_PRIO_SELF); //1òÆestart_taskèÎÎñ
OS_EXIT_CRITICAL(); //¿aÖD¶Ï
}
//ÏÔê¾μØÖ·μèDÅÏ¢
void display_task(void *pdata)
{
while(1)
{
#if LWIP_DHCP //μ±¿aÆôDHCPμÄê±oò
if(lwipdev.dhcpstatus != 0) //¿aÆôDHCP
{
show_address(lwipdev.dhcpstatus ); //ÏÔê¾μØÖ·DÅÏ¢
OSTaskSuspend(OS_PRIO_SELF); //ÏÔê¾íêμØÖ·DÅÏ¢oó1òÆe×ÔéíèÎÎñ
}
#else
show_address(0); //ÏÔê¾¾2ì¬μØÖ·
OSTaskSuspend(OS_PRIO_SELF); //ÏÔê¾íêμØÖ·DÅÏ¢oó1òÆe×ÔéíèÎÎñ
#endif //LWIP_DHCP
OSTimeDlyHMSM(0,0,0,100);
}
}
//keyèÎÎñ
void key_task(void *pdata)
{
u8 keyvalue;
while(1)
{
keyvalue = KEY_Scan(0);
if(keyvalue==KEY0_PRES) //·¢Ëíêy¾Y
{
tcp_client_flag |= LWIP_SEND_DATA; //±ê¼ÇLWIPóDêy¾Yòa·¢Ëí;
}
else if(keyvalue==KEY1_PRES)
{
can_flag=1; // can_flagÎa1£¬CAN·¢Ëíêy¾Y
}
else if(keyvalue==WKUP_PRES)
{
eliminate+=1; // eliminate%2=0, »Ö¸′±¨¾ˉèÎÎñ£¬·ñÔò 1òÆe±¨¾ˉèÎÎñ
}
if (keyvalue==KEY2_PRES)
{
FATFS_flag=!FATFS_flag;
}
OSTimeDlyHMSM(0,0,0,50); //Ñóê±10ms
}
}
//ledèÎÎñ
void led_task(void *pdata)
{
while(1)
{
LED0 = !LED0;
OSTimeDlyHMSM(0,0,0,500); //Ñóê±500ms
}
}
// warning task ±¨¾ˉèÎÎñ
void warning_task(void *pdata)
{
while(1)
{
if(CWUwarningflag)
{
BEEP=1;
OSTimeDlyHMSM(0,0,0,500);
BEEP=0;
OSTimeDlyHMSM(0,0,0,500);
}
OSTimeDlyHMSM(0,0,0,10);
}
}
// soundproof task ÏûéùèÎÎñ
void Soundproof_Task(void *pdata)
{
while(1)
{
if(eliminate%2)
{
OSTaskSuspend(16); // 1òÆe ±¨¾ˉ èÎÎñ
BEEP=0;
}
else OSTaskResume(16); // »Ö¸′±¨¾ˉèÎÎñ
OSTimeDlyHMSM(0,0,0,20); // èÎÎñμ÷¶è
}
}
//CAN TASK
void can_task(void *pdata)
{
// óÃóú½óêÕ±¨ÎÄμÄéèÖÃλμÄDÅÏ¢′òó¡
u8 bit[50];
u8 reslen=0;//½óêÕêy¾Y3¤¶è
u16 CID[2]={0}; // ½óêÕμ½μÄêy¾YμÄCID
u8 i=0,t=0;
u8 scnt=0; //·¢Ëí¼Æêy
u8 rcnt=0; //½óêÕ¼Æêy
u8 sendcanbuf[8]={0}; // ·¢Ëíêy¾Y»o3åÇø
u8 resvcanbuf[8]={0}; // ½óêÕêy¾Y»o3åÇø
u8 sendres; //CAN ·¢Ëíêy¾YμÄ·μ»ØÖμ
u8 setbit[26]={0}; //½óêÕμÄ′óÕ¾μĸ÷λμÄéèÖÃ
short temp;
// LCD_ShowString(10+20*8,170,200,16,16,"Count:"); //ÏÔê¾μ±Ç°¼ÆêyÖμ
LCD_ShowString(18,190,400,16,16,"CAN Send Data:000times"); //ìáê¾·¢ËíμÄêy¾Y
LCD_ShowString(18,250,400,16,16,"CAN Receive Data:000times"); //ìáê¾½óêÕμ½μÄêy¾Y
while(1)
{
if(can_flag)//KEY1°′ÏÂ,·¢Ëíò»′Îêy¾Y
{
can_flag=0; // ½ûÖ1á¬Dø·¢Ëí£¬¼′£¬°′ÏÂò»′Îkey0,·¢Ëíò»′ÎCAN data
// CID=0X041; // Ö÷Õ¾μ½CWUᬽó±êê¾·û
sendcanbuf[0]=0X11; //ìî3ä·¢Ëí»o3åÇø
sendcanbuf[1]=0XE1;
sendcanbuf[2]=0X00; //highlevel
sendcanbuf[3]=0X00; //lowlevel
sendcanbuf[4]=0X17; //lowtemp 23¡æ
sendcanbuf[5]=0X1b; //hightemp 30¡æ
for(i=0;i<8;i++)
{
if(i<4)LCD_ShowxNum(60+i*32,210,sendcanbuf,3,16,0X80); //ÏÔê¾êy¾Y
else LCD_ShowxNum(60+(i-4)*32,230,sendcanbuf,3,16,0X80); //ÏÔê¾êy¾Y
}
sendres=Can_Send_Msg(0X041,sendcanbuf,8); //·¢Ëí8¸ö×Ö½ú ,·μ»ØÖμÎa0 £¬ËμÃ÷·¢Ëí3é1|
if(sendres)LCD_ShowString(18+24*8,190,200,16,16,"Failed"); //ìáê¾·¢Ëí꧰ü
else //ìáê¾·¢Ëí3é1|
{
scnt+=1; // ·¢Ëí¼Æêy
sendflag+=1; // FATFS′æ′¢·¢Ëí¼Æêy
LCD_ShowxNum(18+14*8,190,scnt,3,16,0X80);
LCD_ShowString(18+24*8,190,200,16,16,"OK ");
}
}
//KEY_UP°′Ï£¬¸Ä±äCANμÄ1¤×÷Ä£ê½ CAN1¤×÷Ä£ê½: CAN_Mode_Normal(0)£oÆÕí¨Ä£ê½; CAN_Mode_LoopBack(1)£o»·»ØÄ£ê½
// 3õê¼»ˉê±£¬can_mode=1£¬¼′»·»ØÄ£ê½
CAN_Mode_Init(CAN_SJW_1tq,CAN_BS2_8tq,CAN_BS1_9tq,4,0);
POINT_COLOR=RED;//éèÖÃ×ÖìåÎaoìé«
// can_mode==0 ÆÕí¨Ä£ê½£¬Dèòa2¸ö¿a·¢°å
LCD_ShowString(160,130,200,16,16,"Nnormal Mode ");
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
// ·μ»ØÖμÎa½óêÕμ½μı¨ÎÄμÄCID£¬resvcanbufÎa½óêÕêy¾Y»o3åÇø£¬setbitÎa±¨ÎÄéèÖÃDÅÏ¢»o3åÇø£¬reslenÎa½óêÕêy¾YμÄ3¤¶è
reslen=Can_Receive_Msg(resvcanbuf,setbit,CID );
StoM[8]=CID[0]>>8;
StoM[9]=CID[0];
// printf("StpM[8]=%x StoM[9]=%x\r\n",StoM[8],StoM[9]);
if(reslen)//½óêÕμ½óDêy¾Y
{
receflag+=1; // FATFS′æ′¢êy¾Y±êÖ¾
printf("StoM[8]=%x StoM[9]=%x\r\n",StoM[8],StoM[9]);
rcnt+=1; // ½óêÕ¼Æêy
LCD_ShowxNum(18+17*8,250,rcnt,3,16,0X80);
printf("the CID of recessived message is 0x%03x\r\n",CID[0]);
printf("the recesive message's length is %d\r\n",reslen);
LCD_Fill(60,270,130,310,WHITE);//Çå3y֮ǰμÄÏÔê¾
for(i=0;i<reslen;i++)
{
StoM=resvcanbuf; // °Ñ½óêÕμ½μÄCANêy¾Y¸3Öμμ½1«12êy¾Y»o3åÇø
if(i<4)LCD_ShowxNum(60+i*32,270,resvcanbuf,3,16,0X80); //ÏÔê¾êy¾Y
else LCD_ShowxNum(60+(i-4)*32,290,resvcanbuf,3,16,0X80); //ÏÔê¾êy¾Y
}
}
// ÅD¶Ï±¨ÎÄà′Ô′
// ò»′ÎÏìó|
if(CID[0]==0x3d1)
{
CID[0]=0;
sprintf((char*)StoM,"main station get first response \r\n"); // Ö÷Õ¾½óêÕμ½ CWU′óÕ¾ò»′ÎÏìó|
}
// ±¨ÎÄÎaà′×ÔCWUμÄ ¶t′ÎÏìó|
if(CID[0]==0x051)
{
CID[0]=0;
if(setbit[0]) sprintf((char*)bit,"the state of CWU is ok \r\n"); // CWU×′ì¬Î»
else sprintf((char*)bit,"the state of CWU is fail \r\n");
printf("%s",bit);
if(setbit[1]) sprintf((char*)bit,"the sensor's state of CWU is ok \r\n"); // ζè′«¸DÆ÷×′ì¬Î»
else sprintf((char*)bit,"the sensor's state of CWU is fail \r\n");
printf("%s",bit);
if(setbit[2]) sprintf((char*)bit,"the temp of CWU is high \r\n"); // ¸ßÎÂ3¬ÏT
else sprintf((char*)bit,"the temp of CWU is smaller than high \r\n");
printf("%s",bit);
if(setbit[3]) sprintf((char*)bit,"the temp of CWU is low \r\n"); // μíÎÂ3¬ÏT
else sprintf((char*)bit,"the temp of CWU is bigger than low \r\n");
printf("%s",bit);
if(setbit[4]) sprintf((char*)bit,"the bellstate of CWU is ok \r\n"); // ±¨¾ˉÆ÷×′ì¬
else sprintf((char*)bit,"the bellstate of CWU is fail \r\n");
printf("%s",bit);
if(setbit[5]) // Ô¶3챨¾ˉ
{
sprintf((char*)bit,"CWU need the remote warning now \r\n");
printf("%s",bit);
CWUwarningflag=1; // èç1ûÔ¶3챨¾ˉ±êÖ¾Öμ1£¬Ôòíø1ØÔ¶3챨¾ˉ
}
else
{
sprintf((char*)bit,"CWU do not need the remote warning now \r\n");
printf("%s",bit);
CWUwarningflag=0; // èç1ûÔ¶3챨¾ˉ±ê־λÎa0£¬ÔòÖ÷Õ¾Ô¶3챨¾ˉ±ê־λÎa0
}
if(setbit[6]) sprintf((char*)bit,"CWU is broadcasting \r\n"); // 1ã2¥
else sprintf((char*)bit,"CWU pass the message to gateway only\r\n");
printf("%s",bit);
if(setbit[7]) sprintf((char*)bit,"local warning of CWU is running\r\n"); // ±¾μر¨¾ˉ
else sprintf((char*)bit,"local warning of CWU have not work yeat\r\n");
printf("%s",bit);
printf(" eliminate = %d ",eliminate);
}
// ±¨ÎÄà′×ÔCWU£¬Î¶èêy¾YμÄ′«êä,I/O±¨ÎÄ
if(CID[0]==0x091)
{
CID[0]=0;
if(resvcanbuf[0]) sprintf((char*)bit,"the water level of CWU is %d \r\n",resvcanbuf[0]); // ˮλ
else sprintf((char*)bit,"the water level of CWU is %d \r\n",resvcanbuf[0]);
printf("%s",bit);
temp=resvcanbuf[2]*10+resvcanbuf[1];
printf("the temp of CWU is %d.%-d\r\n",temp/10,temp%10);
}
// ±¨ÎÄà′×ÔCWU£¬Î¶èêy¾YμÄ′«ê䣬 ÏÔê¾±¨ÎÄ
if(CID[0]==0x191)
{
CID[0]=0;
if(resvcanbuf[1]) sprintf((char*)bit,"the water level of CWU is %d \r\n",resvcanbuf[1]); // ˮλ
else sprintf((char*)bit,"the water level of CWU is %d \r\n",resvcanbuf[1]);
printf("%s",bit);
temp=resvcanbuf[2]*10+resvcanbuf[3];
printf("the temp of CWU is %d.%-d\r\n",temp/10,temp%10);
}
t++;
OSTimeDlyHMSM(0,0,0,10); //Ñóê±10ms
if(t==20)
{
LED1=!LED1;//ìáê¾Ïμí3ÕyÔúÔËDD
t=0;
}
}
}
// RTC Task
void RTC_Task(void *pdata)
{
u8 t=0;
// RTC_Set(2015,12,29,19,25,30); //éèÖÃê±¼ä
// usmart_dev.init(SystemCoreClock/1000000); //3õê¼»ˉUSMART
//show RTC
RTC_Get();
LCD_ShowString(30,30,200,20,20," - - "); //ÄêÔÂèÕ
LCD_ShowString(30+90,30,200,16,16," : : "); //ê±·ÖÃë
while(1)
{
// year=calendar.w_year;
// month=calendar.w_month;
// day=calendar.w_date;
// hour=calendar.hour;
// min=calendar.min;
// sec=calendar.sec;
if(t!=calendar.sec)
{
t=calendar.sec;
LCD_ShowNum(10,30,calendar.w_year,4,16);
LCD_ShowNum(50,30,calendar.w_month,2,16);
LCD_ShowNum(74,30,calendar.w_date,2,16);
switch(calendar.week)
{
case 0:
LCD_ShowString(198,30,200,16,16,"Sunday ");
break;
case 1:
LCD_ShowString(198,30,200,16,16,"Monday ");
break;
case 2:
LCD_ShowString(198,30,200,16,16,"Tuesday ");
break;
case 3:
LCD_ShowString(198,30,200,16,16,"Wednesday");
break;
case 4:
LCD_ShowString(198,30,200,16,16,"Thursday ");
break;
case 5:
LCD_ShowString(198,30,200,16,16,"Friday ");
break;
case 6:
LCD_ShowString(198,30,200,16,16,"Saturday ");
break;
}
LCD_ShowNum(120,30,calendar.hour,2,16);
LCD_ShowNum(144,30,calendar.min,2,16);
LCD_ShowNum(168,30,calendar.sec,2,16);
}
OSTimeDlyHMSM(0,0,0,100); //Ñóê±10ms
}
}
//FATFS TASK
void FATFS_Task(void *pdata)
{
DIR ddp; //FATFSèÎÎñÖD
FIL fil;
// FRESULT FATres;
UINT bww;
u8 storeflagr; // ½óêÕ′æ′¢±êÖ¾
u8 storeflags; // ·¢Ëí′æ′¢±êÖ¾
u8 pname[100] ;
__align(4) char FATwritbuf[50];
__align(4) char FATreadbuf[50];
u8 storetime;
u32 total,free;
u8 FATres=0;
// u16 year;
// u8 month;
// u8 day;
// u8 hour;
// u8 min;
// u8 sec;
// u8 offset=0;
while(SD_Init())//¼ì2a2»μ½SD¿¨
{
LCD_ShowString(130,110,200,16,16,"SD Card Error!");
delay_ms(500);
LCD_ShowString(130,110,200,16,16,"Please Check! ");
delay_ms(500);
LED1=!LED1;//DS1éá˸
}
exfuns_init(); //ÎafatfsÏà1رäá¿éêÇëÄú′æ
f_mount(fs[0],"0:",1); //1òÔØSD¿¨
FATres=f_mount(fs[1],"1:",1); //1òÔØFLASH.
if(FATres==0X0D)//FLASH′ÅÅì,FATÎļtÏμí3′íÎó,ÖØD¸ñê½»ˉFLASH
{
LCD_ShowString(30,10,200,16,16,"Flash Disk Formatting..."); //¸ñê½»ˉFLASH
FATres=f_mkfs("1:",1,4096);//¸ñê½»ˉFLASH,1,Åì·û;1,2»Dèòaòyμ¼Çø,8¸öéèÇøÎa1¸ö′Ø
if(FATres==0)
{
f_setlabel((const TCHAR *)"1:YYW"); //éèÖÃFlash′ÅÅìμÄÃû×ÖÎa£oALIENTEK
LCD_ShowString(30,10,200,16,16,"Flash Disk Format Finish"); //¸ñê½»ˉíê3é
}else LCD_ShowString(30,10,200,16,16,"Flash Disk Format Error "); //¸ñê½»ˉ꧰ü
delay_ms(1000);
}
// LCD_Fill(30,150,240,150+16,WHITE); //Çå3yÏÔê¾
while(exf_getfree("1",&total,&free)) //μÃμ½SD¿¨μÄ×üèYá¿oíê£óàèYá¿
{
LCD_ShowString(30,10,200,16,16,"SD Card Fatfs Error!");
delay_ms(200);
LCD_Fill(30,150,240,150+16,WHITE); //Çå3yÏÔê¾
delay_ms(200);
LED1=!LED1;//DS0éá˸
}
LCD_ShowString(130,110,200,16,16," FATFS OK ! ");
LCD_ShowString(10 ,410,200,16,16,"SD Total Size: MB");
LCD_ShowString(10 ,430,200,16,16,"SD Free Size: MB");
LCD_ShowNum(10+8*14,410,total>>10,5,16); //ÏÔê¾SD¿¨×üèYá¿ MB
LCD_ShowNum(10+8*14,430,free>>10,5,16); //ÏÔê¾SD¿¨ê£óàèYá¿ MB
RTC_Get();
while(1)
{
// year=calendar.w_year;
// month=calendar.w_month;
// day=calendar.w_date;
// hour=calendar.hour;
// min=calendar.min;
// sec=calendar.sec;
storetime= calendar.sec%30;
if(!storetime)
{
printf("we have reach the data stored step here\r\n");
sprintf((char*)FATwritbuf," store value is 12345 \r\n");
sprintf((char*)pname,"testfloder/ store data ");
printf("%s", pname);
printf("%s",FATwritbuf);
// 程序运行到此处就死机,去掉FATFS任务,其他任务都可以正常工作
f_lseek (&fil, f_size(&fil)+1);
FATres=f_write (&fil, FATwritbuf, strlen(FATwritbuf), &bww);
f_close(&fil); //1رÕDÂμÄÎļt
}
OSTimeDlyHMSM(0,0,0,100); //Ñóê±10ms
}
}
|
|