main.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "gd32f10x.h"
  2. #include "main.h"
  3. #include "delay.h"
  4. #include "fmc.h"
  5. #include "ota_message.h"
  6. #include "usart.h"
  7. #include "ec800m.h"
  8. #include "boot.h"
  9. #include "w25q32.h"
  10. void task_fwdgt_reload(void);
  11. OTA_STRUCT UpDataA; //A区更新用到的结构体
  12. #if 0
  13. void my_test(void) //往UFS写好文件
  14. {
  15. static OTA_MESSAGE ota_message = {0};
  16. char str[100];
  17. char string[] = "{\"otaflag\":1,\"XmodemByte\":102400}";
  18. uint32_t i = 0;
  19. ota_message.otaflag = 1;
  20. ota_message.XmodemByte = 17152;
  21. memcpy(str,string,strlen(string)+1);
  22. char OPEN_FILE[] = "AT+QFOPEN=\"otaMSG.txt\",0\r\n";
  23. char OPEN_NEW_FILE[] = "AT+QFOPEN=\"otaMSG.txt\",1\r\n";
  24. char WRITEFILE[] = "AT+QFWRITE=1,8\r\n";
  25. char CLOSEFILE[] = "AT+QFCLOSE=1\r\n";
  26. char LOADFILE[] = "AT+QFDWL=otaMSG.txt\r\n";
  27. // GD32_EraseFlash(420,1);
  28. // GD32_WriteFlash(0x08069000,(uint32_t *)&ota_message,sizeof(OTA_MESSAGE));
  29. // i = *(uint32_t*)(0x08069000);
  30. // i = *(uint32_t*)(0x08069004);
  31. EC800MSendCmd(OPEN_NEW_FILE,strlen(OPEN_NEW_FILE));
  32. memset(str,0,sizeof(str));
  33. strcpy(str,(char *)&UART0_RX_BUF);
  34. i = WaitResponse("QFOPEN:", 2000);
  35. EC800MSendCmd(WRITEFILE,strlen(WRITEFILE));
  36. memset(str,0,sizeof(str));
  37. strcpy(str,(char *)&UART0_RX_BUF);
  38. i = WaitResponse("CONNECT", 2000);
  39. EC800MSendCmd((uint8_t *)&ota_message,8);
  40. memset(str,0,sizeof(str));
  41. strcpy(str,(char *)&UART0_RX_BUF);
  42. i = WaitResponse("QFWRITE", 2000);
  43. EC800MSendCmd(CLOSEFILE,strlen(CLOSEFILE));
  44. memset(str,0,sizeof(str));
  45. strcpy(str,(char *)&UART0_RX_BUF);
  46. i = WaitResponse("OK", 2000);
  47. free(str);
  48. Delay_Ms(10);
  49. }
  50. #endif
  51. int main(void)
  52. {
  53. Delay_Init();
  54. /* 弃用w25q32改用EC800存储ota文件 */
  55. // W25Q32_Init();
  56. nvic_config();
  57. gd_com_init(COM_EC800);
  58. dma_config();
  59. gd_EC800M_pin_init();
  60. EC800MPwoerOn();
  61. EC800MWaitReady();
  62. // my_test();
  63. OTA_MESSAGE *ota_data;
  64. task_fwdgt_reload();
  65. if(load_ota_message_config_params()==0)
  66. {
  67. //ota事件产生了,进入Bootloader分支
  68. ota_data=get_config_params();
  69. BootLoader_Brance(ota_data->XmodemByte);
  70. }
  71. //没有OTA事件产生跳转A区
  72. else
  73. {
  74. LOAD_A(GD32_A_SADDR);
  75. }
  76. while(1)
  77. {
  78. }
  79. }
  80. void task_fwdgt_reload(void)
  81. {
  82. /* uncock fwdgt write protect*/
  83. fwdgt_write_enable();
  84. /* feed fwdgt */
  85. fwdgt_counter_reload();
  86. }