UDSService.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. #include "bsp.h"
  2. #include "bsp_custom.h"
  3. #include "osasys.h"
  4. #include "ostask.h"
  5. #include "queue.h"
  6. #include "ps_event_callback.h"
  7. #include "cmisim.h"
  8. #include "cmimm.h"
  9. #include "cmips.h"
  10. #include "sockets.h"
  11. #include "psifevent.h"
  12. #include "ps_lib_api.h"
  13. #include "lwip/netdb.h"
  14. #include <cis_def.h>
  15. #include "debug_log.h"
  16. #include "slpman_ec616.h"
  17. #include "plat_config.h"
  18. #include "ec_tcpip_api.h"
  19. #include "hal_module_adapter.h"
  20. #include "UartTask.h"
  21. #include "MainTask.h"
  22. #include "app.h"
  23. #include "CANTask.h"
  24. #include "flash_ec616_rt.h"
  25. #include "UDSService.h"
  26. //
  27. extern UartReadMsgType UartReadMsg;
  28. extern osMutexId_t UartMutex;
  29. extern AppSocketConnectionContext socContext;
  30. extern UINT8 GpsData[16];
  31. void UDS_Service(void);
  32. void UDS_CAN_Update(void);
  33. BOOL UDSClearFotaDownloadRegion(void);
  34. BOOL UDSAskforDownLoadData(void);
  35. UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode);
  36. UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode);
  37. extern void appSaveConfigValue(void);
  38. UINT8 UDSService[2];
  39. UINT8 UDSSubService[2];
  40. UINT8 UDSSubServiceActionCode[2];
  41. UINT8 UDSSwitch = 0;
  42. UINT8 UDSDialogMode = 01;
  43. UINT8 UDSBattSN[BATT_SN_LEN];
  44. UINT32 updateDifferDataByteLen = 0;
  45. //each package means 100 bytes, max PackageCounter = updateDifferDataByteLen%100 + 1
  46. UINT16 updateDifferDataPackageCounter = 0;
  47. //each slice means 4 bytes, max SliceCounter = 25;
  48. UINT32 updateDifferDataSliceCounter = 0;
  49. static BOOL downloadReady = FALSE;
  50. UINT8 updateDataBuffer[100];
  51. void UDS_Service()
  52. {
  53. UINT8 i,j= 0;
  54. UINT32 k=0;
  55. INT8 ret,errorCount = 0;
  56. BOOL boolRet = false;
  57. static UINT8 snFlag = 0;
  58. static UINT32 sliceCounterFlag = 0;
  59. UINT32 tempSliceCounter=0;
  60. static UINT8 counter=0;
  61. CAN_Msg_Type UDSAnswer ={0};
  62. static UINT8 battInfo[8*14] = {0};
  63. UINT32 posCode,negCode;
  64. //UartReadMsg Uart_Recv_Msg;
  65. //UINT8 temp00[94] ={0x00,0x0E,0x00,0x05,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0x7A,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0E,0x42,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x13,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0x00,0x24,0x00,0x26,0x00,0x22,0x00,0x24,0x00,0x00,0x00,0x00,0x6e,0x78,0x00,0x00,0x00,0x00,0x00,0x5F,0x00,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x74,0x0E,0x42,0x0D,0x7A,0x00,0x00};
  66. //MEMCPY(battInfo, temp00, 94);
  67. //while(true)
  68. //{
  69. //if(UDSSwitch == 1)
  70. {
  71. for(i=0; i<2; i++)
  72. {
  73. if(CanRxMsg[i].Id == 0x7A0)
  74. {
  75. switch (UDSService[i])
  76. {
  77. case 0x10:
  78. if(UDSSubService[i] == 0x01)
  79. {
  80. if((UDSDialogMode == 0x01 || UDSDialogMode==0x02)||UDSSwitch == 0)
  81. {
  82. UDSPositiveAnswer(0x04,i,0x00);
  83. UDSSwitch = 0;
  84. UDSDialogMode = 1;
  85. }
  86. else
  87. {
  88. UDSNegtiveAnswer(0x05,i,0xFF);
  89. }
  90. }
  91. else if(UDSSubService[i] == 0x02)
  92. {
  93. UDSPositiveAnswer(0x04,i,0x00);
  94. UDSSwitch = 1;
  95. UDSDialogMode = 2;
  96. }
  97. else if(UDSSubService[i] == 0x03)
  98. {
  99. if(UDSSwitch == 1)
  100. {
  101. UDSPositiveAnswer(0x04,i,0x00);
  102. UDSSwitch = 1;
  103. UDSDialogMode = 3;
  104. }
  105. else
  106. {
  107. UDSNegtiveAnswer(0x05,i,0xFF);
  108. }
  109. }
  110. else if(UDSSubService[i] == 0x11) //make NB software reset
  111. {
  112. if(UDSDialogMode == 2)
  113. {
  114. UDSPositiveAnswer(0x04,i,0x00);
  115. osDelay(100);
  116. appSaveNVMData();
  117. appSetCFUN(0);
  118. osDelay(1000);
  119. EC_SystemReset();
  120. }
  121. else
  122. {
  123. UDSNegtiveAnswer(0x05,i,0xFF);
  124. }
  125. }
  126. else
  127. {
  128. UDSNegtiveAnswer(0x05,i,0xEE);
  129. }
  130. break;
  131. case 0x22:
  132. if(UDSDialogMode == 2)
  133. {
  134. if(UDSSubService[i] == 0x01) //check the sw of NB
  135. {
  136. UDSPositiveAnswer(0x08,i,APPSWVERSION);
  137. }
  138. else if(UDSSubService[i] == 0x02) //check the hw of NB
  139. {
  140. UDSPositiveAnswer(0x06,i,HWVERSION);
  141. }
  142. else if(UDSSubService[i] == 0x03) //check the SN number
  143. {
  144. UDSAnswer.DLC = 8;
  145. switch(UDSSubServiceActionCode[i])
  146. {
  147. case 00:
  148. UDSAnswer.Id = 0x20;
  149. for(k=0; k<8; k++)
  150. {
  151. UDSAnswer.Data[k] = AppNVMData.battSN[k+8*0];
  152. }
  153. ret = HAL_Can_Transmit(UDSAnswer);
  154. break;
  155. case 01:
  156. UDSAnswer.Id = 0x21;
  157. for(k=0; k<8; k++)
  158. {
  159. UDSAnswer.Data[k] = AppNVMData.battSN[k+8*1];
  160. }
  161. ret = HAL_Can_Transmit(UDSAnswer);
  162. break;
  163. case 02:
  164. UDSAnswer.Id = 0x22;
  165. UDSAnswer.Data[0] = AppNVMData.battSN[16];;
  166. for(k=1; k<8; k++)
  167. {
  168. UDSAnswer.Data[k] = 0x00;
  169. }
  170. ret = HAL_Can_Transmit(UDSAnswer);
  171. break;
  172. default:
  173. break;
  174. }
  175. }
  176. else if(UDSSubService[i] == 0x04) //check the batt message
  177. {
  178. osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
  179. if(CanRxMsg[i].Data[2] == 0x00)
  180. {
  181. MEMCPY(battInfo,UartReadMsg.data,14*8);
  182. /*
  183. #ifdef USING_PRINTF
  184. printf("battInfo=\n");
  185. for(int jj = 0;jj<14*8;jj++)
  186. printf("%x ",battInfo[jj]);
  187. printf("\n");
  188. #endif
  189. */
  190. }
  191. osMutexRelease(UartMutex);
  192. UDSAnswer.Id = 0x30+UDSSubServiceActionCode[i];
  193. UDSAnswer.DLC = 8;
  194. MEMCPY(UDSAnswer.Data, &(battInfo[UDSSubServiceActionCode[i]*8]),8);
  195. ret = HAL_Can_Transmit(UDSAnswer);
  196. }
  197. else if(UDSSubService[i] == 0x05) //check the enviroment temp of NB
  198. {
  199. UDSPositiveAnswer(0x08,i,0x00); //ntcvalue
  200. }
  201. else if(UDSSubService[i] == 0x06) //check the tcp link of NB
  202. {
  203. UDSPositiveAnswer(0x06,i,socContext.status); //TcpconnectStatus
  204. }
  205. else if(UDSSubService[i] == 0x07) //check the GPS link of NB
  206. {
  207. posCode =(UINT32) GpsData[1];
  208. UDSPositiveAnswer(0x05,i,posCode); //gps satellite num(uint8), should be modified
  209. }
  210. else
  211. {
  212. UDSNegtiveAnswer(0x05,i,0xEE);
  213. }
  214. }
  215. else //the service is not surpported in current dialog mode
  216. {
  217. UDSNegtiveAnswer(0x05,i,0xFF);
  218. }
  219. break;
  220. case 0x2E: //write service
  221. if(UDSDialogMode == 2)
  222. {
  223. if(UDSSubService[i] == 0x03) // write the battSN
  224. {
  225. if(UDSSubServiceActionCode[i] == 0x00 && snFlag == 0x00)
  226. {
  227. for(j=0; j<5; j++)
  228. {
  229. UDSBattSN[j+5*0] = CanRxMsg[i].Data[j+3];
  230. }
  231. snFlag = snFlag|0x01;
  232. }
  233. else if(UDSSubServiceActionCode[i] == 0x01 && snFlag == 0x01)
  234. {
  235. for(j=0; j<5; j++)
  236. {
  237. UDSBattSN[j+5*1] = CanRxMsg[i].Data[j+3];
  238. }
  239. snFlag = snFlag|0x02;
  240. }
  241. else if(UDSSubServiceActionCode[i] == 0x02 && snFlag == 0x03)
  242. {
  243. for(j=0; j<5; j++)
  244. {
  245. UDSBattSN[j+5*2] = CanRxMsg[i].Data[j+3];
  246. }
  247. snFlag = snFlag|0x04;
  248. }
  249. else if(UDSSubServiceActionCode[i] == 0x03 && snFlag == 0x07)
  250. {
  251. for(j=0; j<2; j++)
  252. {
  253. UDSBattSN[j+5*3] = CanRxMsg[i].Data[j+3];
  254. }
  255. snFlag = snFlag|0x08;
  256. }
  257. if(snFlag == 0x0F)
  258. {
  259. snFlag = 0;
  260. UDSPositiveAnswer(0x04,i,00);
  261. MEMCPY(AppNVMData.battSN, UDSBattSN, BATT_SN_LEN);
  262. AppNVMData.EOLState = 1; //SN号写入完成,表明已经进行过下线配置
  263. appSaveNVMData();
  264. }
  265. else
  266. {
  267. UDSAnswer.Id = 0x7A8;
  268. UDSAnswer.DLC = 8;
  269. UDSAnswer.Data[0] = 0x05;
  270. UDSAnswer.Data[1] = 0x3E;
  271. UDSAnswer.Data[2] = UDSService[i];
  272. UDSAnswer.Data[3] = UDSSubService[i];
  273. UDSAnswer.Data[4] = snFlag;
  274. UDSAnswer.Data[5] = 0x00;
  275. UDSAnswer.Data[6] = 0x00;
  276. UDSAnswer.Data[7] = 0x00;
  277. ret = HAL_Can_Transmit(UDSAnswer);
  278. }
  279. }
  280. else if(UDSSubService[i] == 0x0F) //write the update config:updateDifferDataByteLen
  281. {
  282. updateDifferDataByteLen = (CanRxMsg[i].Data[2]<<16)|(CanRxMsg[i].Data[3]<<8)|CanRxMsg[i].Data[4];
  283. UDSPositiveAnswer(0x04,i,00);
  284. }
  285. else
  286. {
  287. UDSNegtiveAnswer(0x05,i,0xEE);
  288. }
  289. break;
  290. }
  291. else
  292. {
  293. UDSNegtiveAnswer(0x05,i,0xFF);
  294. }
  295. break;
  296. case 0x31: //clear the flash service
  297. if(UDSDialogMode == 3)
  298. {
  299. if(UDSSubService[i] == 0x0F) //clear the fota flash
  300. {
  301. if(UDSSubServiceActionCode[i] == 0x01)
  302. {
  303. //Clear the Flash
  304. boolRet = UDSClearFotaDownloadRegion();
  305. //if ok
  306. UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
  307. }
  308. else
  309. {
  310. UDSNegtiveAnswer(0x06,i,UDSSubServiceActionCode[i]<<8|0xFF); //重点测试
  311. }
  312. }
  313. else
  314. {
  315. UDSNegtiveAnswer(0x05,i,0xEE); //the subservice is not surpported
  316. }
  317. }
  318. else
  319. {
  320. UDSNegtiveAnswer(0x05,i,0xFF); //the survie is not surpported in current dialog mode
  321. }
  322. break;
  323. case 0x34: //prepare for some one process
  324. if(UDSDialogMode == 3)
  325. {
  326. if(UDSSubService[i] == 0x0F) //ask for download update data
  327. {
  328. boolRet = UDSAskforDownLoadData();
  329. //if ok
  330. UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
  331. }
  332. else
  333. {
  334. UDSNegtiveAnswer(0x05,i,0xEE);
  335. }
  336. }
  337. else
  338. {
  339. UDSNegtiveAnswer(0x05,i,0xFF);
  340. }
  341. break;
  342. case 0x36: //download the update data
  343. if(UDSDialogMode == 3)
  344. {
  345. if(downloadReady == TRUE)
  346. {
  347. counter++; //记录报文数量
  348. tempSliceCounter = (CanRxMsg[i].Data[1]<<16)|(CanRxMsg[i].Data[2]<<8)|(CanRxMsg[i].Data[3]);
  349. /*
  350. #ifdef USING_PRINTF
  351. printf("tempSliceCounter = %x\n",tempSliceCounter);
  352. #endif
  353. */
  354. if(tempSliceCounter < (updateDifferDataPackageCounter+1)*25 && tempSliceCounter>=updateDifferDataPackageCounter*25)
  355. {
  356. updateDifferDataSliceCounter = tempSliceCounter % 25;
  357. for(j=0;j<4;j++)
  358. {
  359. updateDataBuffer[updateDifferDataSliceCounter*4+j] = CanRxMsg[i].Data[4+j];
  360. }
  361. if(updateDifferDataSliceCounter>0)
  362. {
  363. sliceCounterFlag = sliceCounterFlag |(0x01<<updateDifferDataSliceCounter);
  364. }
  365. else
  366. {
  367. sliceCounterFlag = sliceCounterFlag |0x01;
  368. }
  369. /*
  370. #ifdef USING_PRINTF
  371. printf("sliceCounterFlag = %x counter=%d\n",sliceCounterFlag,counter);
  372. #endif
  373. */
  374. }
  375. if(counter == 25)
  376. {
  377. counter = 0;
  378. if(sliceCounterFlag == 0x1FFFFFF) //received all the 25 message of current package
  379. {
  380. sliceCounterFlag = 0x0;
  381. updateDifferDataPackageCounter++;
  382. /*
  383. #ifdef USING_PRINTF
  384. printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter);
  385. printf("updateDataBuffer\n");
  386. for(k=0;k<100;k++)
  387. {
  388. printf("%x ",updateDataBuffer[k]);
  389. }
  390. printf("\n");
  391. printf("startAddr = 0x%x,endAddr = 0x%x\n",
  392. FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,FLASH_FOTA_REGION_START+updateDifferDataPackageCounter*100-1);
  393. #endif
  394. */
  395. //write the buffer(100 byte) to flash
  396. ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
  397. errorCount = 0;
  398. while(ret != QSPI_OK && errorCount<3) //try to write most 3 times
  399. {
  400. errorCount++;
  401. BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
  402. ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
  403. }
  404. if(ret == QSPI_OK)
  405. {
  406. UDSPositiveAnswer(0x08,i,tempSliceCounter);
  407. }
  408. else
  409. {
  410. UDSNegtiveAnswer(0x08,i,0xFFFFFFFF); //failed to write this package to flash
  411. }
  412. memset(updateDataBuffer,0, 100);
  413. sliceCounterFlag = 0x0;
  414. }
  415. else
  416. {
  417. //received 25 messages, but lose one or more messages
  418. //in this case, updater will try to send the package again(most 4 times)
  419. UDSNegtiveAnswer(0x08,i,sliceCounterFlag);
  420. //sliceCounterFlag = 0x0;
  421. /*
  422. #ifdef USING_PRINTF
  423. printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter+1);
  424. printf("updateDataBuffer:\n");
  425. for(k=0;k<100;k++)
  426. {
  427. printf("%x ",updateDataBuffer[k]);
  428. }
  429. printf("\n");
  430. #endif
  431. */
  432. //memset(updateDataBuffer,0, 100);
  433. }
  434. }
  435. }
  436. else
  437. {
  438. UDSNegtiveAnswer(0x05,i,0xEF); //the download process is not ready
  439. }
  440. }
  441. else
  442. {
  443. UDSNegtiveAnswer(0x05,i,0xFF); //the service is not surpported in current dialog mode
  444. }
  445. break;
  446. case 0x37: //exit some one process
  447. if(UDSDialogMode == 3)
  448. {
  449. if(UDSSubService[i] == 0x0F) // exit the download
  450. {
  451. UDSPositiveAnswer(0x04,i,0x00);
  452. downloadReady = FALSE;
  453. }
  454. else
  455. {
  456. UDSNegtiveAnswer(0x05,i,0xEE);
  457. }
  458. }
  459. else
  460. {
  461. UDSNegtiveAnswer(0x05,i,0xFF);
  462. }
  463. break;
  464. default:
  465. UDSNegtiveAnswer(0x04,i,0xFF); //the service is not surpported
  466. break;
  467. }
  468. }
  469. }
  470. }
  471. //}
  472. for(i=0; i<2; i++)
  473. {
  474. UDSService[i] = 0;
  475. UDSSubService[i] = 0;
  476. }
  477. }
  478. UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode)
  479. {
  480. CAN_Msg_Type UDSAnswer;
  481. UINT8 ret;
  482. UDSAnswer.Id = 0x7A8;
  483. UDSAnswer.DLC = 8;
  484. UDSAnswer.Data[0] = answerLen;
  485. UDSAnswer.Data[1] = 0x78;
  486. UDSAnswer.Data[2] = UDSService[messageIndex];
  487. UDSAnswer.Data[3] = UDSSubService[messageIndex];
  488. if(answerLen == 4)
  489. {
  490. UDSAnswer.Data[4] = 0x00;
  491. UDSAnswer.Data[5] = 0x00;
  492. UDSAnswer.Data[6] = 0x00;
  493. UDSAnswer.Data[7] = 0x00;
  494. }
  495. else if(answerLen==5)
  496. { UDSAnswer.Data[4] = posCode;
  497. UDSAnswer.Data[5] = 0x00;
  498. UDSAnswer.Data[6] = 0x00;
  499. UDSAnswer.Data[7] = 0x00;
  500. }
  501. else if(answerLen==6)
  502. {
  503. UDSAnswer.Data[4] = posCode>>8;
  504. UDSAnswer.Data[5] = posCode;
  505. UDSAnswer.Data[6] = 0x00;
  506. UDSAnswer.Data[7] = 0x00;
  507. }
  508. else if(answerLen==7)
  509. {
  510. UDSAnswer.Data[4] = posCode>>16;
  511. UDSAnswer.Data[5] = posCode>>8;
  512. UDSAnswer.Data[6] = posCode;
  513. UDSAnswer.Data[7] = 0x00;
  514. }
  515. else if(answerLen==8)
  516. {
  517. UDSAnswer.Data[4] = posCode>>24;
  518. UDSAnswer.Data[5] = posCode>>16;
  519. UDSAnswer.Data[6] = posCode>>8;
  520. UDSAnswer.Data[7] = posCode;
  521. }
  522. ret = HAL_Can_Transmit(UDSAnswer);
  523. return ret;
  524. }
  525. UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode)
  526. {
  527. CAN_Msg_Type UDSAnswer;
  528. UINT8 ret;
  529. UDSAnswer.Id = 0x7A8;
  530. UDSAnswer.DLC = 8;
  531. UDSAnswer.Data[0] = answerLen;
  532. UDSAnswer.Data[1] = 0x7F;
  533. UDSAnswer.Data[2] = UDSService[messageIndex];
  534. UDSAnswer.Data[3] = UDSSubService[messageIndex];
  535. if(answerLen==4)
  536. {
  537. UDSAnswer.Data[3] = negCode;
  538. UDSAnswer.Data[4] = 0x00;
  539. UDSAnswer.Data[5] = 0x00;
  540. UDSAnswer.Data[6] = 0x00;
  541. UDSAnswer.Data[7] = 0x00;
  542. }
  543. if(answerLen==5)
  544. { UDSAnswer.Data[4] = negCode;
  545. UDSAnswer.Data[5] = 0x00;
  546. UDSAnswer.Data[6] = 0x00;
  547. UDSAnswer.Data[7] = 0x00;
  548. }
  549. else if(answerLen==6)
  550. {
  551. UDSAnswer.Data[4] = negCode>>8;
  552. UDSAnswer.Data[5] = negCode;
  553. UDSAnswer.Data[6] = 0x00;
  554. UDSAnswer.Data[7] = 0x00;
  555. }
  556. else if(answerLen==7)
  557. {
  558. UDSAnswer.Data[4] = negCode>>16;
  559. UDSAnswer.Data[5] = negCode>>8;
  560. UDSAnswer.Data[6] = negCode;
  561. UDSAnswer.Data[7] = 0x00;
  562. }
  563. else if(answerLen==8)
  564. {
  565. UDSAnswer.Data[4] = negCode>>24;
  566. UDSAnswer.Data[5] = negCode>>16;
  567. UDSAnswer.Data[6] = negCode>>8;
  568. UDSAnswer.Data[7] = negCode;
  569. }
  570. ret = HAL_Can_Transmit(UDSAnswer);
  571. return ret;
  572. }
  573. BOOL UDSAskforDownLoadData()
  574. {
  575. updateDifferDataPackageCounter = 0;
  576. downloadReady = true;
  577. return TRUE;
  578. }
  579. BOOL UDSClearFotaDownloadRegion()
  580. {
  581. UINT8 ret = FALSE;
  582. ret = BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x78000); //512k-32k = 480k -> 0x75300
  583. if(ret == QSPI_OK)
  584. {
  585. return TRUE;
  586. }
  587. else
  588. {
  589. return FALSE;
  590. }
  591. }