|
|
|
@ -7,7 +7,7 @@ |
|
|
|
* @brief This file include main function.
|
|
|
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include "sys.h"
|
|
|
|
#include "uart.h"
|
|
|
|
#include "delay.h"
|
|
|
|
@ -198,8 +198,8 @@ void SCI1_Init(uint32_t pclk, uint32_t bound,uint8_t parity) |
|
|
|
band_rate =(pclk*4/bound)>>6;
|
|
|
|
SCI1->SCIBDH=(u8)((band_rate>>8)&0x00ff);
|
|
|
|
SCI1->SCIBDL=(u8)(band_rate&0x00ff);
|
|
|
|
SCI1->SCICR2 |= (1<<2)|(1<<3)|(1<<5)|(1 << 4); |
|
|
|
NVIC_Init(0, 0, SCI1_IRQn, 2); |
|
|
|
SCI1->SCICR2 |= (1<<2)|(1<<3)|(1<<5);// |(1 << 4) |
|
|
|
NVIC_Init(1, 1, SCI1_IRQn, 2); |
|
|
|
}
|
|
|
|
|
|
|
|
void SCI2_Init(uint32_t pclk, uint32_t bound,uint8_t parity)
|
|
|
|
@ -220,7 +220,7 @@ void SCI3_Init(uint32_t pclk, uint32_t bound,uint8_t parity) |
|
|
|
band_rate =(pclk*4/bound)>>6;
|
|
|
|
SCI3->SCIBDH=(u8)((band_rate>>8)&0x00ff);
|
|
|
|
SCI3->SCIBDL=(u8)(band_rate&0x00ff);
|
|
|
|
SCI3->SCICR2 |= (1<<2)|(1<<3)|(1<<5)|(1 << 4); |
|
|
|
SCI3->SCICR2 |= (1<<2)|(1<<3)|(1<<5);//|(1 << 4) |
|
|
|
NVIC_Init(0, 0, SCI3_IRQn, 2);
|
|
|
|
}
|
|
|
|
int fputc(int ch, FILE *f)
|
|
|
|
@ -235,7 +235,7 @@ int fputc(int ch, FILE *f) |
|
|
|
// {
|
|
|
|
// };
|
|
|
|
// SCI2->SCIDRL = (uint8_t)ch; //SCI1->SCIDRL = (uint8_t)data;
|
|
|
|
// return ch; |
|
|
|
return ch; |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -324,6 +324,7 @@ void SCI1_IRQHandler(void) |
|
|
|
extern unsigned char app_flag;
|
|
|
|
/******************************************************************/
|
|
|
|
extern uint8_t Rx_Buffer_short[512] ;
|
|
|
|
extern uint8_t Rx_Buffer1_short[512] ;
|
|
|
|
extern uint16_t Rx_Count_short ;
|
|
|
|
|
|
|
|
|
|
|
|
@ -345,40 +346,30 @@ extern unsigned short block ; |
|
|
|
extern unsigned int page ;
|
|
|
|
extern unsigned int ui_addr;
|
|
|
|
extern unsigned char last_flag;
|
|
|
|
extern unsigned char dma_flag;
|
|
|
|
//unsigned char flash[2050] = {0};
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
// printf("***app!!**\r\n");
|
|
|
|
// u8 inBuf[64];
|
|
|
|
// u16 X_pos=0;
|
|
|
|
// u16 Y_pos=0;
|
|
|
|
// uint16_t cx, cy;
|
|
|
|
// uint8_t w_temp, h_temp;
|
|
|
|
// u8 Sd_card_exist = 0; char Download_flag = 0;
|
|
|
|
|
|
|
|
NVIC_SetVectorTable(0x800A000, 0);//0x800A000 0x8010000
|
|
|
|
// NVIC_SetVectorTable(0x800F800, 0);
|
|
|
|
// PeripheralInit();
|
|
|
|
|
|
|
|
Sys_Init();
|
|
|
|
Enable_Interrupts;
|
|
|
|
|
|
|
|
SCI1_Init(g_ips_clk,921600 ,0); //115200 921600
|
|
|
|
// SCI2_Init(g_ips_clk, 115200,0);
|
|
|
|
// SCI3_Init(g_ips_clk,921600 ,0); |
|
|
|
SCI3_Init(g_ips_clk,38400 ,0); |
|
|
|
/********************升级*******************/
|
|
|
|
ota_address = LT_APP;
|
|
|
|
|
|
|
|
|
|
|
|
Make_CRC32_Table();
|
|
|
|
ota_address = 0x08010000;
|
|
|
|
printf("***bootloader1!!**\r\n");
|
|
|
|
// APP(APP_ADDR); //21KB
|
|
|
|
// SCI3_DMA_Init(g_ips_clk,115200);
|
|
|
|
SCI3_DMA_Init(g_ips_clk,921600);//921600
|
|
|
|
unsigned short i = 0;
|
|
|
|
|
|
|
|
// APP(APP2_ADDR);
|
|
|
|
// SCI3_DMA_Init(g_ips_clk,38400);
|
|
|
|
//SCI3_DMA_Init(g_ips_clk,921600);//921600 38400
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
@ -924,212 +915,32 @@ SCI3_DMA_Init(g_ips_clk,921600);//921600 |
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// APP(APP_ADDR);
|
|
|
|
#if 0
|
|
|
|
Run_Boot_ID = 0x47210659;
|
|
|
|
|
|
|
|
if((Run_Boot_ID == 0x47210659) || (EFLASH_WordRead(0x8009E00)!=0x21436587))
|
|
|
|
{
|
|
|
|
// printf("enter-updata\r\n");
|
|
|
|
uart_rx_number = 0;
|
|
|
|
uart_buf[0] = 0x0;
|
|
|
|
uart_rx_endIndex = 0;
|
|
|
|
uart_act_index = 0;
|
|
|
|
vcom_rp[0].fullIndex = 0;
|
|
|
|
vcom_rp[1].fullIndex = 0;
|
|
|
|
baud_index = 0x7F;
|
|
|
|
|
|
|
|
display_manu(0);
|
|
|
|
|
|
|
|
Enable_Interrupts;
|
|
|
|
// Uart_Init(g_ips_clk, 921600); //升级的串口初始化 1382400;//921600;//230400;//115200;
|
|
|
|
Uart_Init(g_ips_clk, 115200);
|
|
|
|
PIT1_Init_Uart(); //PIT定时器初始化,用来监控串口数据结束的
|
|
|
|
#if Display_Progress
|
|
|
|
PIT2_Loop();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LT_SingleByteToPc(0xAA);
|
|
|
|
inBuf[0]=0xAA;
|
|
|
|
inBuf[1]=0xFF;
|
|
|
|
inBuf[2]=0x42;
|
|
|
|
inBuf[3]=0x4F;
|
|
|
|
inBuf[4]=0x4F;
|
|
|
|
inBuf[5]=0x54;
|
|
|
|
inBuf[6]=0x55;
|
|
|
|
inBuf[7]=0x50;
|
|
|
|
inBuf[8]=0x44;
|
|
|
|
inBuf[9]=0x41;
|
|
|
|
inBuf[10]=0x54;
|
|
|
|
inBuf[11]=0x45;
|
|
|
|
inBuf[12]=0xA4;
|
|
|
|
inBuf[13]=0x18;
|
|
|
|
inBuf[14]=0xE4;
|
|
|
|
inBuf[15]=0x1B;
|
|
|
|
inBuf[16]=0x11;
|
|
|
|
inBuf[17]=0xEE;
|
|
|
|
uart_send(inBuf,18);
|
|
|
|
unsigned char buff[1024],buff1[1024];
|
|
|
|
|
|
|
|
LT768_Print_Internal_Font_String(50,50,Red,Blue2,"Uart_Updating,please keep power on");
|
|
|
|
// LT768_Print_Internal_Font_String(100,2*50,Red,Blue2,"Uart_Updating,do not off");
|
|
|
|
printf("***baud_index=%d***\r\n",baud_index);
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
// printf("uart updata!\r\n");
|
|
|
|
WDT_FeedDog();
|
|
|
|
#if 1
|
|
|
|
if( app_flag ==1)
|
|
|
|
{
|
|
|
|
app_flag = 0;
|
|
|
|
WDT_FeedDog();
|
|
|
|
APP(APP2_ADDR); //21KB APP_ADDR 0x8022000
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
if(uart_act_index == 1)
|
|
|
|
{
|
|
|
|
do_all_uart();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(baud_index<11)
|
|
|
|
{
|
|
|
|
DelayMS(5);
|
|
|
|
|
|
|
|
Uart_Init(g_ips_clk,bdRate[baud_index]);
|
|
|
|
|
|
|
|
printf("bdRate[baud_index]=%d\r\n",bdRate[baud_index]);
|
|
|
|
baud_index = 0x7F;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if Display_Progress
|
|
|
|
if(Flag_Loop)
|
|
|
|
{
|
|
|
|
Flag_Loop=0;
|
|
|
|
if(FLag_Pos==0)
|
|
|
|
{
|
|
|
|
X_pos=202;
|
|
|
|
Y_pos=120;
|
|
|
|
}
|
|
|
|
else if(FLag_Pos==1)
|
|
|
|
{
|
|
|
|
X_pos=226;
|
|
|
|
Y_pos=170;
|
|
|
|
}
|
|
|
|
if(count_Loop==0) LT768_Print_Internal_Font_String(X_pos,Y_pos,Red,Blue2,"* ");
|
|
|
|
else if(count_Loop==1) LT768_Print_Internal_Font_String(X_pos,Y_pos,Red,Blue2," *");
|
|
|
|
count_Loop++;
|
|
|
|
if(count_Loop>1) count_Loop=0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
display_manu(0);
|
|
|
|
printf(" date = %s,time = %s \r\n", (char *)__DATE__, (char *)__TIME__);
|
|
|
|
|
|
|
|
// for(unsigned short i = 0 ; i < 512 ; i++)
|
|
|
|
// printf(" %x",Rx_Buffer_short[i]);
|
|
|
|
// printf("--------------\r\n");
|
|
|
|
// for(unsigned short i = 0 ; i < 512 ; i++)
|
|
|
|
// printf(" %x",Rx_Buffer1_short[i]);
|
|
|
|
// printf("--------------\r\n");
|
|
|
|
|
|
|
|
// char debug[256] = {0xA5,0x5A,0x01,0x0E,0x20,0xCD,0x02,0x01,0x00,0x00,0xC8,0x3A,0x7A,0xAC,0xFF 0x02 0x59 0x0F 0x90 0xF7 0x65 0xE0 0x44 0x80 0xF0 0x22 0x02 0x55 0x0D 0x12 0x79 0x00 0x12 0x5B 0xFE 0xD2 0xC5 0x12 0x5B 0xFE 0x00 0x00 0x12 0x77 0x6D 0x00 0x00 0x00 0x00 0x22 0x02 0x4C 0x57 0x90 0xF1 0x26 0xE0 0xFE 0xEF 0xF4 0xFF 0xEE 0x5F 0xF0 0x22 0x00 0x02 0x4E 0x7A 0xEF 0x14 0x60 0x22 0x14 0x60 0x31 0x14 0x60 40 14 60 4F 14 60 5E 24 05 70 6B EC 90 F1 31 F0 90 F1 30 ED F0 90 F1 29 E0 44 01 F0 22 EC 90 F1 33 F0 90 F1 32 ED F0 90 F1 29 E0 44 02 F0 22 EC 90 F1 35 F0 90 F1 34 ED F0 90 F1 29 E0 44 04 F0 22 EC 90 F1 37 F0 90 F1 36 ED F0 90 F1 29 E0 44 08 F0 22 EC 90 F1 39 F0 90 F1 38 ED F0 90 F1 29 E0 44 10 F0 22 EC 90 F1 3B F0 90 F1 3A ED F0 90 F1 29 E0 44 20 F0 22 D2 60 02 68 CE 02 41 DB 90 06 36 E4 F0 A3};
|
|
|
|
// unsigned char check_number = CalCheckSum(debug,12);
|
|
|
|
// printf("check_number: %x\r\n",check_number);
|
|
|
|
//A5 5A 01 1B 20 06 01 01 00 00 7A 3E FB
|
|
|
|
|
|
|
|
// else //没有卡,离开BootLoader,跳转到app
|
|
|
|
// {
|
|
|
|
//
|
|
|
|
// APP(APP_ADDR);
|
|
|
|
// }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
unsigned char flash[256]={0};
|
|
|
|
unsigned char flash1[256]={0};
|
|
|
|
unsigned char flash2[256]={0};
|
|
|
|
unsigned char flash3[512]={0};
|
|
|
|
unsigned char flash4[512]={0};
|
|
|
|
for(unsigned int i = 0 ; i < 256 ; i++)
|
|
|
|
{
|
|
|
|
flash[i] = 6;
|
|
|
|
}
|
|
|
|
// W25N01GV_Erase_Block(0);//W25N01GV_Erase_Block(0x200000/131072);
|
|
|
|
for(unsigned int i = 0 ; i < 256 ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x" , flash1[i]);
|
|
|
|
}
|
|
|
|
W25N01GV_ReadPageAddr_Data(flash1,0,0,256); //W25N01GV_ReadPageAddr_Data(flash1,0,0x200000/2048,256);
|
|
|
|
printf("\r\n--------Erase---------------\r\n");
|
|
|
|
for(unsigned int i = 0 ; i < 256 ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x" , flash1[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
W25N01GV_ReadPageAddr_Data(flash1,256,0,256); //W25N01GV_ReadPageAddr_Data(flash1,256,0x200000/2048,256);
|
|
|
|
printf("\r\n--------Erase---------------\r\n");
|
|
|
|
for(unsigned int i = 0 ; i < 256 ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x" , flash1[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
W25N01GV_ReadPageAddr_Data(flash3,0,0,512); //W25N01GV_ReadPageAddr_Data(flash3,0,0x200000/2048,512);
|
|
|
|
printf("\r\n--------Erase---------------\r\n");
|
|
|
|
for(unsigned int i = 0 ; i < 512 ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x" , flash3[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//写入
|
|
|
|
W25N01GV_WritePageAddr_Data(flash,0,0,256); //W25N01GV_WritePageAddr_Data(flash,0,0x200000/2048,256);
|
|
|
|
//读取
|
|
|
|
W25N01GV_ReadPageAddr_Data(flash1,0,0,256); //W25N01GV_ReadPageAddr_Data(flash1,0,0x200000/2048,256);
|
|
|
|
printf("\r\n-----------write--flash1----------\r\n");
|
|
|
|
for(unsigned int i = 0 ; i < 256 ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x" , flash1[i]);
|
|
|
|
}
|
|
|
|
printf("\r\n-----------write---flash2---------\r\n");
|
|
|
|
W25N01GV_WritePageAddr_Data(flash,256,0,256); // W25N01GV_WritePageAddr_Data(flash,256,0x200000/2048,256);
|
|
|
|
W25N01GV_ReadPageAddr_Data(flash2,256,0,256); // W25N01GV_ReadPageAddr_Data(flash2,256,0x200000/2048,256);
|
|
|
|
for(unsigned int i = 0 ; i < 256 ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x" , flash2[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\r\n-----------write---flash3---------\r\n");
|
|
|
|
|
|
|
|
W25N01GV_ReadPageAddr_Data(flash3,0,0,512);//W25N01GV_ReadPageAddr_Data(flash3,0,0x200000/2048,512);
|
|
|
|
for(unsigned int i = 0 ; i < 512 ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x" , flash3[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\r\n-----------write---flash4---------\r\n");
|
|
|
|
|
|
|
|
W25N01GV_ReadPageAddr_Data(flash4,512,0,512);//W25N01GV_ReadPageAddr_Data(flash4,512,0x200000/2048,512);
|
|
|
|
for(unsigned int i = 0 ; i < 512 ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x" , flash4[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
//W25N01GV_Erase_Block(0);
|
|
|
|
display_manu(0);
|
|
|
|
// unsigned char my_buf[2050];
|
|
|
|
// unsigned char my_show[2050];
|
|
|
|
// for(unsigned short i = 0 ; i < 2048 ; i++)
|
|
|
|
// {
|
|
|
|
// my_buf[i] = i%9;
|
|
|
|
// }
|
|
|
|
// printf("\r\n--------------\r\n");
|
|
|
|
// W25N01GV_Erase_Block(0);
|
|
|
|
//// printf("bdRate[baud_index]=%d\r\n",bdRate[baud_index]);
|
|
|
|
// W25N01GV_WritePageAddr_Data(my_buf,0,0,2048);
|
|
|
|
// W25N01GV_ReadPageAddr_Data(my_show,0,0,2048);
|
|
|
|
// for(unsigned short i = 0 ; i<2048;i++)
|
|
|
|
// {
|
|
|
|
// printf(" %x",my_show[i]);
|
|
|
|
// }
|
|
|
|
// printf("\r\n--------------\r\n");
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
|
|
|
|
WDT_FeedDog();
|
|
|
|
// printf("init finish!\r\n");
|
|
|
|
// DelayMS(500);
|
|
|
|
// printf("f:%d\r\n",ota_lt7689_flag);
|
|
|
|
if(ota_lt7689_flag==1)
|
|
|
|
{ |
|
|
|
WDT_FeedDog(); |
|
|
|
{
|
|
|
|
// printf("ota_flag=%d\r\n",ota_lt7689_flag);
|
|
|
|
|
|
|
|
#if 0 //跳转程序
|
|
|
|
if((Rx_Buffer_short[0]==0xA5)&&
|
|
|
|
(Rx_Buffer_short[1]==0x5A)&&
|
|
|
|
(Rx_Buffer_short[2]==0x08)&&
|
|
|
|
@ -1157,107 +968,8 @@ SCI3_DMA_Init(g_ips_clk,921600);//921600 |
|
|
|
APP(APP2_ADDR);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// printf("length:%d\r\n",ui_buf_length);
|
|
|
|
for(unsigned int i = 0 ; i < Rx_Count_short; i++)
|
|
|
|
{
|
|
|
|
ui_buf[i+ui_buf_length]=Rx_Buffer_short[i];
|
|
|
|
}
|
|
|
|
ui_buf_length += Rx_Count_short;
|
|
|
|
printf("ui=%d\r\n",ui_buf_length);
|
|
|
|
if(ui_buf_length==2048)//||(ui_buf_length==662)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
W25N01GV_Erase_Block(0);
|
|
|
|
printf("erase0\r\n");
|
|
|
|
W25N01GV_Erase_Block(1);
|
|
|
|
printf("erase1\r\n");
|
|
|
|
WDT_FeedDog();
|
|
|
|
W25N01GV_WritePageAddr_Data(ui_buf,0,0,ui_buf_length);
|
|
|
|
printf("Write\r\n");
|
|
|
|
WDT_FeedDog();
|
|
|
|
W25N01GV_ReadPageAddr_Data(flash,0,0,ui_buf_length);
|
|
|
|
printf("Read\r\n");
|
|
|
|
WDT_FeedDog();
|
|
|
|
for(unsigned int i = 0 ; i < ui_buf_length; i++)
|
|
|
|
{
|
|
|
|
printf(" %x",flash[i]);
|
|
|
|
}
|
|
|
|
printf("\r\n");
|
|
|
|
#endif
|
|
|
|
if(page%64==0)
|
|
|
|
{
|
|
|
|
printf("erase:%d\r\n",block);
|
|
|
|
W25N01GV_Erase_Block(block);
|
|
|
|
|
|
|
|
block++;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("page:%d length:%d\r\n",page,ui_buf_length);
|
|
|
|
W25N01GV_WritePageAddr_Data(ui_buf,0,page,ui_buf_length);
|
|
|
|
// for(unsigned int i = 0 ; i < ui_buf_length ; i++)
|
|
|
|
// {
|
|
|
|
// printf(" %x",ui_buf[i]);
|
|
|
|
// }
|
|
|
|
// printf("\r\n");
|
|
|
|
ui_buf_length=0;
|
|
|
|
page++;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// 块擦除 每64页(128KB)的时候擦除下一块
|
|
|
|
if(page%64==0)
|
|
|
|
{
|
|
|
|
printf("block=%d\r\n",block);
|
|
|
|
W25N01GV_Erase_Block(1);
|
|
|
|
block++;
|
|
|
|
}
|
|
|
|
//写入 到2048(2KB)的时候 换页
|
|
|
|
// W25N01GV_Erase_Block(0);
|
|
|
|
// if(ui_offset%2048==0)
|
|
|
|
// {
|
|
|
|
//
|
|
|
|
// W25N01GV_Erase_Block(page);
|
|
|
|
// printf("erase\r\n");
|
|
|
|
// }
|
|
|
|
printf("%d %d %d\r\n",ui_offset,Rx_Count_short,page);
|
|
|
|
// ota_ui(page , Rx_Buffer_short ,Rx_Count_short,ui_offset);
|
|
|
|
|
|
|
|
// W25N01GV_WritePageAddr_Data(Rx_Buffer_short,ui_offset,page,Rx_Count_short);
|
|
|
|
|
|
|
|
// W25N01GV_ReadPageAddr_Data(flash,ui_offset,page,Rx_Count_short);
|
|
|
|
|
|
|
|
printf("OTA\r\n");
|
|
|
|
|
|
|
|
for(unsigned short i = 0 ; i < Rx_Count_short ; i++)
|
|
|
|
{
|
|
|
|
printf(" %x",Rx_Buffer_short[i]);//Rx_Buffer_short flash
|
|
|
|
}
|
|
|
|
printf("\r\n");
|
|
|
|
|
|
|
|
if(ui_offset==2048)
|
|
|
|
{
|
|
|
|
printf("enter 2048 \r\n");
|
|
|
|
page++;
|
|
|
|
ui_offset=0;
|
|
|
|
}
|
|
|
|
ui_offset+=Rx_Count_short;
|
|
|
|
Rx_Count_short=0;
|
|
|
|
printf("end %d %d %d\r\n",ui_offset,Rx_Count_short,page);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// for(i=0 ; i<256 ;i++)
|
|
|
|
// {
|
|
|
|
// printf("%x ",Rx_Buffer_short[i]);
|
|
|
|
// }
|
|
|
|
// printf("\r\n");
|
|
|
|
// if(Rx_Count_short<256)
|
|
|
|
// {
|
|
|
|
// printf("end number=%d Rx_Count_short=%d\r\n",number1,Rx_Count_short);
|
|
|
|
// }
|
|
|
|
#if 0 //OTA BIN-core 初版
|
|
|
|
ota_offset = Rx_Count_short;
|
|
|
|
// printf("ota_address %x\r\n",ota_address);// 256 0x8010000
|
|
|
|
@ -1281,57 +993,16 @@ SCI3_DMA_Init(g_ips_clk,921600);//921600 |
|
|
|
// printf("end number:%d\r\n",number);
|
|
|
|
// APP(APP_ADDR);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rx_Count_short=0;
|
|
|
|
ota_lt7689_flag=0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// number+=Rx_Count_short;
|
|
|
|
// for(unsigned short i = 0 ; i < Rx_Count_short; i++)
|
|
|
|
// {
|
|
|
|
// printf(" %x",Rx_Buffer_short[i]);
|
|
|
|
// }
|
|
|
|
// printf("\r\n");
|
|
|
|
#if 0 //
|
|
|
|
//保存数据 2048
|
|
|
|
// for(offset=0;offset<Rx_Count_short;offset++)
|
|
|
|
// {
|
|
|
|
// ui_buf[offset+ui_offset]=Rx_Buffer_short[offset];
|
|
|
|
// }
|
|
|
|
|
|
|
|
ui_offset+=Rx_Count_short;
|
|
|
|
ui_addr+=Rx_Count_short;
|
|
|
|
|
|
|
|
printf("addr=%x offset=%d\r\n",ui_addr,ui_offset);
|
|
|
|
|
|
|
|
// if(ui_addr%0x20000==0)//128KB 擦除
|
|
|
|
// {
|
|
|
|
// W25N01GV_Erase_Block(block);
|
|
|
|
// printf("block=%d\r\n",block);
|
|
|
|
// block++;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if((ui_offset%2048==0))
|
|
|
|
// {
|
|
|
|
// W25N01GV_WritePageAddr_Data(ui_buf,0,page,2048);
|
|
|
|
// ui_offset = 0;
|
|
|
|
// printf("page:%d offset:%d\r\n",page,ui_offset);
|
|
|
|
// page++;
|
|
|
|
// }
|
|
|
|
// else if (last_flag == 1)
|
|
|
|
// {
|
|
|
|
// W25N01GV_WritePageAddr_Data(ui_buf,0,page,ui_offset);
|
|
|
|
// ui_offset = 0;
|
|
|
|
// printf("page:%d offset:%d\r\n",page,ui_offset);
|
|
|
|
// page++;
|
|
|
|
// last_flag=0;
|
|
|
|
// printf("ui_addr=%x\r\n",ui_addr+Rx_Count_short);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1 //OTA-UI-BIN 初版
|
|
|
|
#if 0 //OTA-UI-BIN 初版
|
|
|
|
if((ui_addr%131072)==0)//128KB 擦除
|
|
|
|
{
|
|
|
|
W25N01GV_Erase_Block(block);
|
|
|
|
@ -1371,12 +1042,282 @@ SCI3_DMA_Init(g_ips_clk,921600);//921600 |
|
|
|
printf("ui_addr=%x\r\n",ui_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Rx_Count_short=0;
|
|
|
|
ota_lt7689_flag=0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0 //对比DMA
|
|
|
|
// printf("ui_offset=%d\r\n",ui_offset);
|
|
|
|
printf("\r\n**1**\r\n");
|
|
|
|
|
|
|
|
// if(dma_flag==1)
|
|
|
|
// {
|
|
|
|
// printf("Rx_Buffer_short\r\n");
|
|
|
|
for(unsigned short i = 0; i < Rx_Count_short ; i++) //Rx_Count_short ui_offset
|
|
|
|
{
|
|
|
|
printf(" %x",Rx_Buffer_short[i]);//Rx_Buffer_short[i] ui_buf[i]
|
|
|
|
// printf(" %d",i);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
// else if (dma_flag==0)
|
|
|
|
// {
|
|
|
|
// printf("Rx_Buffer_short1\r\n");
|
|
|
|
// for(unsigned short i = 0; i < Rx_Count_short ; i++) //Rx_Count_short ui_offset
|
|
|
|
// {
|
|
|
|
// printf(" %x",Rx_Buffer1_short[i]);//Rx_Buffer_short[i] ui_buf[i]
|
|
|
|
//// printf(" %d",i);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// ui_offset=0;
|
|
|
|
printf("\r\n****\r\n");
|
|
|
|
Rx_Count_short=0;
|
|
|
|
ota_lt7689_flag=0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// printf("number=%d\r\n",number);
|
|
|
|
|
|
|
|
#if 1 //3-enhance //211
|
|
|
|
//
|
|
|
|
|
|
|
|
// ota_analysis(Rx_Buffer_short,Rx_Count_short);
|
|
|
|
|
|
|
|
// printf("\r\n--------\r\n");
|
|
|
|
// for(unsigned char i = 0 ; i < Rx_Count_short; i++)
|
|
|
|
// printf(" %x",Rx_Buffer_short[i]);
|
|
|
|
// printf("\r\n %x \r\n",CalCheckSum(Rx_Buffer_short,Rx_Count_short-1));
|
|
|
|
|
|
|
|
// if(Rx_Count_short<200)
|
|
|
|
// {
|
|
|
|
// printf("all: %d\r\n",);
|
|
|
|
// }
|
|
|
|
// pkg_seq = 0;
|
|
|
|
// Rx_Count_short=0;
|
|
|
|
// ota_lt7689_flag=0;
|
|
|
|
// 收到WIFI开始升级报文
|
|
|
|
|
|
|
|
|
|
|
|
//收到WIFI固件发送完成
|
|
|
|
|
|
|
|
|
|
|
|
//收到WIFI 请求固件失败
|
|
|
|
|
|
|
|
|
|
|
|
//收到WIFI OTA超时
|
|
|
|
|
|
|
|
|
|
|
|
//收到WIFI 发送固件内容
|
|
|
|
|
|
|
|
/*******************rev_status**********************/
|
|
|
|
|
|
|
|
// 判断校验码是否准确
|
|
|
|
// ota_analysis(wifi_buf,mes_length);
|
|
|
|
|
|
|
|
printf("rev:%d check:%x\r\n",mes_length,CalCheckSum( (char *)wifi_buf, mes_length-1));
|
|
|
|
|
|
|
|
if(wifi_buf[mes_length-1]!= CalCheckSum( (char *)wifi_buf, mes_length-1))
|
|
|
|
{
|
|
|
|
printf("%x check_erro %x\r\n",CalCheckSum( (char *)wifi_buf, mes_length-1),wifi_buf[mes_length-1]);
|
|
|
|
// return 1;
|
|
|
|
// inf_wifi_data_check_error( inf_wifi_buf,wifi_buf[3]);
|
|
|
|
}
|
|
|
|
if((wifi_buf[0]!=0xA5)&&(wifi_buf[1]!=0x5A)&&(wifi_buf[2]!=0x01))
|
|
|
|
{
|
|
|
|
printf("illegal_new!\r\n");
|
|
|
|
// return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(unsigned char i = 0 ; i < mes_length; i++)
|
|
|
|
{
|
|
|
|
printf(" %x",wifi_buf[i]);
|
|
|
|
}
|
|
|
|
printf("\r\n");
|
|
|
|
//实现算法
|
|
|
|
|
|
|
|
// 收到wifi-ota通知
|
|
|
|
|
|
|
|
if((wifi_buf[4]==0x20)&&(wifi_buf[6]==0x01)&&(wifi_buf[7]==0x01))
|
|
|
|
{
|
|
|
|
|
|
|
|
pkg_seq = wifi_buf[3];
|
|
|
|
|
|
|
|
//ACK
|
|
|
|
|
|
|
|
unsigned char send_length=inf_wifi_ack(inf_wifi_buf,pkg_seq);
|
|
|
|
|
|
|
|
inf_wifi_buf[send_length] = CalCheckSum( (char *)inf_wifi_buf,send_length);
|
|
|
|
send_length++;
|
|
|
|
|
|
|
|
inf_wifi_buf_length = 0; // ACK
|
|
|
|
mes_length =0;
|
|
|
|
ota_lt7689_flag = 0;
|
|
|
|
send_meg_wifi(inf_wifi_buf,send_length);
|
|
|
|
// printf("ACK:");
|
|
|
|
// for(unsigned char i = 0 ; i < send_length ; i++)
|
|
|
|
// {
|
|
|
|
// printf(" %x",inf_wifi_buf[i]);
|
|
|
|
// }
|
|
|
|
// printf("\r\n---\r\n");
|
|
|
|
|
|
|
|
//发送 通知wifi 开始发送固件
|
|
|
|
DelayMS(30);//跳转Bootloader!!80
|
|
|
|
unsigned char length=inf_wifi_ota_start(inf_wifi_buf, pkg_seq);
|
|
|
|
|
|
|
|
// printf("inf:");
|
|
|
|
// for(unsigned char i = 0 ; i < length ; i++)
|
|
|
|
// {
|
|
|
|
// printf(" %x",inf_wifi_buf[i]);
|
|
|
|
// }
|
|
|
|
// printf("\r\n---\r\n");
|
|
|
|
inf_wifi_buf_length = 0;
|
|
|
|
mes_length =0;
|
|
|
|
ota_lt7689_flag = 0;
|
|
|
|
printf("start updata\r\n");
|
|
|
|
send_meg_wifi(inf_wifi_buf, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ((wifi_buf[4]==0x20)&&(wifi_buf[6]==0x02)&&(wifi_buf[7]==0x01))//wifi 发送固件内容报文
|
|
|
|
{
|
|
|
|
// printf("%d %d\r\n",wifi_buf[8],wifi_buf[9]);
|
|
|
|
// unsigned short updata_seq = 256*wifi_buf[8]+wifi_buf[9];//(wifi_buf[8] || (wifi_buf[9]<<8));
|
|
|
|
// printf("0***%d %d\r\n",updata_seq,ota_seq);
|
|
|
|
|
|
|
|
// updata_seq = wifi_buf[9] || (wifi_buf[8]<<8);
|
|
|
|
// printf("1***%d %d\r\n",updata_seq,ota_seq);
|
|
|
|
printf("***%d %d\r\n",ota_seq,256*wifi_buf[8]+wifi_buf[9]);
|
|
|
|
if(ota_seq==(256*wifi_buf[8]+wifi_buf[9]))
|
|
|
|
{
|
|
|
|
printf("bin:");
|
|
|
|
for(unsigned char i = 0 ; i < wifi_buf[10]; i++)
|
|
|
|
{
|
|
|
|
printf(" %x",wifi_buf[i+11]);
|
|
|
|
}
|
|
|
|
printf("\r\n");
|
|
|
|
|
|
|
|
ota_seq++;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("***repeat!\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
//封装ACK
|
|
|
|
pkg_seq = wifi_buf[3]; //包序号
|
|
|
|
|
|
|
|
unsigned char send_length=inf_wifi_ack(inf_wifi_buf,pkg_seq);
|
|
|
|
|
|
|
|
inf_wifi_buf[send_length] = CalCheckSum( (char *)inf_wifi_buf,send_length);
|
|
|
|
send_length++;
|
|
|
|
|
|
|
|
// 发送ACK
|
|
|
|
|
|
|
|
inf_wifi_buf_length = 0; // ACK
|
|
|
|
mes_length =0;
|
|
|
|
ota_lt7689_flag = 0;
|
|
|
|
send_meg_wifi(inf_wifi_buf,send_length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
//wifi 发送固件完成
|
|
|
|
else if ((wifi_buf[4]==0x20)&&(wifi_buf[6]==0x01)&&(wifi_buf[7]==0x02))
|
|
|
|
{
|
|
|
|
printf("OTA-finish\r\n");
|
|
|
|
//封装ACK
|
|
|
|
pkg_seq = wifi_buf[3]; //包序号
|
|
|
|
|
|
|
|
unsigned char send_length=inf_wifi_ack(inf_wifi_buf,pkg_seq);
|
|
|
|
|
|
|
|
inf_wifi_buf[send_length] = CalCheckSum( (char *)inf_wifi_buf,send_length);
|
|
|
|
send_length++;
|
|
|
|
|
|
|
|
// 发送ACK
|
|
|
|
|
|
|
|
inf_wifi_buf_length = 0; // ACK
|
|
|
|
mes_length =0;
|
|
|
|
ota_lt7689_flag = 0;
|
|
|
|
ota_seq = 0;
|
|
|
|
printf("ota_seq=%d\r\n",ota_seq);
|
|
|
|
send_meg_wifi(inf_wifi_buf,send_length);
|
|
|
|
|
|
|
|
|
|
|
|
// mcu inform wifi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
//wifi 请求失败
|
|
|
|
else if ((wifi_buf[4]==0x20)&&(wifi_buf[6]==0x01)&&(wifi_buf[7]==0x02))
|
|
|
|
{
|
|
|
|
printf("OTA-request-fail\r\n");
|
|
|
|
//封装ACK
|
|
|
|
pkg_seq = wifi_buf[3]; //包序号
|
|
|
|
|
|
|
|
unsigned char send_length=inf_wifi_ack(inf_wifi_buf,pkg_seq);
|
|
|
|
|
|
|
|
inf_wifi_buf[send_length] = CalCheckSum( (char *)inf_wifi_buf,send_length);
|
|
|
|
send_length++;
|
|
|
|
|
|
|
|
// 发送ACK
|
|
|
|
|
|
|
|
inf_wifi_buf_length = 0; // ACK
|
|
|
|
mes_length =0;
|
|
|
|
ota_lt7689_flag = 0;
|
|
|
|
send_meg_wifi(inf_wifi_buf,send_length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//wifi 超时
|
|
|
|
else if ((wifi_buf[4]==0x20)&&(wifi_buf[6]==0x01)&&(wifi_buf[7]==0x02))
|
|
|
|
{
|
|
|
|
printf("OTA-timeout\r\n");
|
|
|
|
//封装ACK
|
|
|
|
pkg_seq = wifi_buf[3]; //包序号
|
|
|
|
|
|
|
|
unsigned char send_length=inf_wifi_ack(inf_wifi_buf,pkg_seq);
|
|
|
|
|
|
|
|
inf_wifi_buf[send_length] = CalCheckSum( (char *)inf_wifi_buf,send_length);
|
|
|
|
send_length++;
|
|
|
|
|
|
|
|
// 发送ACK
|
|
|
|
|
|
|
|
inf_wifi_buf_length = 0; // ACK
|
|
|
|
mes_length =0;
|
|
|
|
ota_lt7689_flag = 0;
|
|
|
|
send_meg_wifi(inf_wifi_buf,send_length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("other new!\r\n");
|
|
|
|
//封装ACK
|
|
|
|
|
|
|
|
pkg_seq = wifi_buf[3]; //包序号
|
|
|
|
|
|
|
|
unsigned char send_length=inf_wifi_ack(inf_wifi_buf,pkg_seq);
|
|
|
|
|
|
|
|
inf_wifi_buf[send_length] = CalCheckSum( (char *)inf_wifi_buf,send_length);
|
|
|
|
send_length++;
|
|
|
|
|
|
|
|
// 发送ACK
|
|
|
|
|
|
|
|
inf_wifi_buf_length = 0; // ACK
|
|
|
|
mes_length =0;
|
|
|
|
ota_lt7689_flag = 0;
|
|
|
|
send_meg_wifi(inf_wifi_buf,send_length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|