main.c 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. #include "cmsis_os.h"
  23. #include "FreeRTOS.h"
  24. #include "task.h"
  25. #include "timers.h"
  26. #include "event_groups.h"
  27. /* Private includes ----------------------------------------------------------*/
  28. /* USER CODE BEGIN Includes */
  29. #include "string.h"
  30. #include "stdio.h"
  31. #include "usart.h"
  32. #include "config.h"
  33. #include "rkg.h"
  34. #include "cang.h"
  35. #include "kzq.h"
  36. #include "level.h"
  37. #include "tem.h"
  38. #include "angle.h"
  39. #include "xyf.h"
  40. #include "hdf.h"
  41. #include "bgy.h"
  42. #include "yqhs.h"
  43. #include "pressure.h"
  44. #include "iap.h"
  45. /* USER CODE END Includes */
  46. #if 1
  47. #define IR_ROM1 0x08000000
  48. #else
  49. #define IR_ROM1 0x08020000
  50. #endif
  51. /* Private typedef -----------------------------------------------------------*/
  52. /* USER CODE BEGIN PTD */
  53. #define ADDR_Is_In_ElecFence 0x05D0 // 1488 车是否在电子围栏内
  54. uint8_t REST = 0;
  55. uint32_t usage_Tsk12=0;
  56. //============================================================
  57. sT2C_RemoteCaliDat T2C_RemoteCaliDat001 =
  58. {
  59. 0x3901,
  60. 0x9551000,
  61. 0x0003,
  62. ADDR_Is_In_ElecFence,//0x0000,
  63. 0x0001, //操作的数据个数
  64. 0x55aa55aa, //保留字4字节
  65. {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,\
  66. 25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44},
  67. 0x7788,//保留字2字节
  68. 0x99aa //校验2字节
  69. };
  70. sT2C_RemoteCaliDat *pT2C_RemoteCaliData = &T2C_RemoteCaliDat001;
  71. /* USER CODE END PTD */
  72. /* Private define ------------------------------------------------------------*/
  73. /* USER CODE BEGIN PD */
  74. #define RT_ERRORCNT 60 //串口收发数据错误上限
  75. /* USER CODE END PD */
  76. /* Private macro -------------------------------------------------------------*/
  77. /* USER CODE BEGIN PM */
  78. uint8_t CMD_KZQ[256] =
  79. {0x39,0x01,0x95,0x50,0x00,0x01,0x00,0x03,
  80. 0x00,0x00,0x00,0x00,0x95,0x05,0xaa,0xaa,
  81. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  82. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  83. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  84. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  85. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  86. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  87. };
  88. //卸油阀指令
  89. uint8_t CMD_XYF[8] = {0x11,0x03,0x00,0x00,0x00,0x01,0x00,0x00};
  90. uint8_t Data_Head[2] = {0x0D,0x0A};
  91. //海底阀指令
  92. uint8_t CMD_HDF[16] =
  93. {0x21,0x03,0x2a,0,0,0,0,0,0xaa,0xbb,0xcc,0xdd,0xee,0xdd,0xcc,0xbb};
  94. //人孔盖指令31 03 00 02 00 02
  95. uint8_t CMD_RKG[8] = {0x31,0x03,0x00,0x02,0x00,0x02,0x00,0x00};
  96. uint8_t CMD_RKG_CBM[12] = {0x0D,0x0A,0x31,0x03,0x00,0x02,0x00,0x02,0x00,0x00,0x0D,0x0A};
  97. uint8_t CMD_RKG_XG[12] = {0x41,0x03,0x00,0x02,0x00,0x02,0x00,0x00};
  98. //油气回收
  99. uint8_t CMD_YQHS[8] = {0xE4,0x03,0x00,0x00,0x00,0x01,0x00,0x00};
  100. //倾角传感器读取协议 01 03 00 02 00 02 CRC
  101. uint8_t CMD_Angle_XY[] = {0x71,0x03,0x00,0x3d,0x00,0x03,0x00,0x00};
  102. //卸尽传感器读取协议
  103. uint8_t CMD_Biguayou[] = {0x81,0x03,0x00,0x00,0x00,0x01,0x9B,0xCA};
  104. //uint8_t CMD_Angle_X[] = {0xE0,0x03,0x00,0x02,0x00,0x02,0x00,0x00};
  105. //uint8_t CMD_Angle_Y[] = {0xE1,0x03,0x00,0x02,0x00,0x02,0x00,0x00};
  106. uint8_t CMD_LDYW[8]={LEVEL_STARTADDR,0x04,0x0a,0x0f,0x00,0x02, 0, 0};//设备地址,功能码,地址4字节 反回:设备地址,功能码,数据长度,数据4字节
  107. uint8_t CMD_GetTempAndYewei[8]={0x51, 0x04, 00, 00, 00, 0x10, 0x03 ,0xae};//读取编号为04地址的温度传感器数据
  108. //61-6f 03 00 04 00 01 C6 8A----读取华天传感器的第1个温度点,地址为x10;最接近电子仓的温度点
  109. uint8_t CMD_GetTempHuaTian[8]={0x61, 0x03, 00, 04, 00, 01,0,0};//读取华天传感器的第一个温度点
  110. uint8_t CMD_TemAng[8]={TEM_STARTADDR, 0x03, 00, 00, 00, 02,0,0};//FST100-611 通过模拟量模块,读取温度
  111. uint8_t CMD_Pressure[8]={PRESSURE_STARTADDR, 0x03, 0x00, 0x00, 0x00, 0x02,0,0}; //FST800-801 读取压力数据, 没有标零指令
  112. //磁编码传感器读取协议 。
  113. /* USER CODE END PM */
  114. /* Private variables ---------------------------------------------------------*/
  115. CRC_HandleTypeDef hcrc;
  116. DAC_HandleTypeDef hdac;
  117. DMA_HandleTypeDef hdma_dac_ch2;
  118. TIM_HandleTypeDef htim1;
  119. TIM_HandleTypeDef htim4;
  120. UART_HandleTypeDef huart5;
  121. UART_HandleTypeDef huart1;
  122. UART_HandleTypeDef huart2;
  123. UART_HandleTypeDef huart3;
  124. DMA_HandleTypeDef hdma_usart1_rx;
  125. DMA_HandleTypeDef hdma_usart1_tx;
  126. DMA_HandleTypeDef hdma_usart2_rx;
  127. DMA_HandleTypeDef hdma_usart3_rx;
  128. uint8_t bufMain[128];
  129. /* Definitions for defaultTask */
  130. osThreadId_t defaultTaskHandle;
  131. const osThreadAttr_t defaultTask_attributes = {
  132. .name = "defaultTask",
  133. .stack_size = 128 * 4,
  134. .priority = (osPriority_t) osPriorityNormal,
  135. };
  136. /* Definitions for myTask02 */
  137. osThreadId_t myTask02Handle;
  138. const osThreadAttr_t myTask02_attributes = {
  139. .name = "myTask02",
  140. .stack_size = 256 * 4,
  141. .priority = (osPriority_t) osPriorityLow,
  142. };
  143. /* Definitions for myTask03 */
  144. osThreadId_t myTask03Handle;
  145. const osThreadAttr_t myTask03_attributes = {
  146. .name = "myTask03",
  147. .stack_size = 256 * 4,
  148. .priority = (osPriority_t) osPriorityLow,
  149. };
  150. /* Definitions for myTask04 */
  151. osThreadId_t myTask04Handle;
  152. const osThreadAttr_t myTask04_attributes = {
  153. .name = "myTask04",
  154. .stack_size = 256 * 4,
  155. .priority = (osPriority_t) osPriorityLow,
  156. };
  157. /* Definitions for myTask05 */
  158. osThreadId_t myTask05Handle;
  159. const osThreadAttr_t myTask05_attributes = {
  160. .name = "myTask05",
  161. .stack_size = 128 * 4,
  162. .priority = (osPriority_t) osPriorityLow,
  163. };
  164. /* Definitions for myTask06 */
  165. osThreadId_t myTask06Handle;
  166. const osThreadAttr_t myTask06_attributes = {
  167. .name = "myTask06",
  168. .stack_size = 128 * 4,
  169. .priority = (osPriority_t) osPriorityLow,
  170. };
  171. /* Definitions for myTask07 */
  172. osThreadId_t myTask07Handle;
  173. const osThreadAttr_t myTask07_attributes = {
  174. .name = "myTask07",
  175. .stack_size = 128 * 4,
  176. .priority = (osPriority_t) osPriorityLow,
  177. };
  178. /* Definitions for myTask08 */
  179. osThreadId_t myTask08Handle;
  180. const osThreadAttr_t myTask08_attributes = {
  181. .name = "myTask08",
  182. .stack_size = 128 * 4,
  183. .priority = (osPriority_t) osPriorityLow,
  184. };
  185. /* Definitions for myTask09 */
  186. osThreadId_t myTask09Handle;
  187. const osThreadAttr_t myTask09_attributes = {
  188. .name = "myTask09",
  189. .stack_size = 128 * 4,
  190. .priority = (osPriority_t) osPriorityLow,
  191. };
  192. /* Definitions for myTask10 */
  193. osThreadId_t myTask10Handle;
  194. const osThreadAttr_t myTask10_attributes = {
  195. .name = "myTask10",
  196. .stack_size = 128 * 4,
  197. .priority = (osPriority_t) osPriorityLow,
  198. };
  199. /* Definitions for myTask11 */
  200. osThreadId_t myTask11Handle;
  201. const osThreadAttr_t myTask11_attributes = {
  202. .name = "myTask11",
  203. .stack_size = 128 * 4,
  204. .priority = (osPriority_t) osPriorityLow,
  205. };
  206. /* Definitions for myTask12 */
  207. osThreadId_t myTask12Handle;
  208. const osThreadAttr_t myTask12_attributes = {
  209. .name = "myTask12",
  210. .stack_size = 128 * 4,
  211. .priority = (osPriority_t) (osPriorityLow-6),
  212. };
  213. /* Definitions for myQueue01 */
  214. osMessageQueueId_t myQueue01Handle;
  215. const osMessageQueueAttr_t myQueue01_attributes = {
  216. .name = "myQueue01"
  217. };
  218. /* Definitions for myQueue02 */
  219. osMessageQueueId_t myQueue02Handle;
  220. const osMessageQueueAttr_t myQueue02_attributes = {
  221. .name = "myQueue02"
  222. };
  223. /* Definitions for myQueue03 */
  224. osMessageQueueId_t myQueue03Handle;
  225. const osMessageQueueAttr_t myQueue03_attributes = {
  226. .name = "myQueue03"
  227. };
  228. /* Definitions for myQueue04 */
  229. osMessageQueueId_t myQueue04Handle;
  230. const osMessageQueueAttr_t myQueue04_attributes = {
  231. .name = "myQueue04"
  232. };
  233. /* Definitions for myQueue05 */
  234. osMessageQueueId_t myQueue05Handle;
  235. const osMessageQueueAttr_t myQueue05_attributes = {
  236. .name = "myQueue05"
  237. };
  238. /* Definitions for myQueue06 */
  239. osMessageQueueId_t myQueue06Handle;
  240. const osMessageQueueAttr_t myQueue06_attributes = {
  241. .name = "myQueue06"
  242. };
  243. /* Definitions for myTimer01 */
  244. osTimerId_t myTimer01Handle;
  245. const osTimerAttr_t myTimer01_attributes = {
  246. .name = "myTimer01"
  247. };
  248. /* Definitions for myTimer02 */
  249. osTimerId_t myTimer02Handle;
  250. const osTimerAttr_t myTimer02_attributes = {
  251. .name = "myTimer02"
  252. };
  253. /* Definitions for myTimer03 */
  254. osTimerId_t myTimer03Handle;
  255. const osTimerAttr_t myTimer03_attributes = {
  256. .name = "myTimer03"
  257. };
  258. /* Definitions for myTimer04 */
  259. osTimerId_t myTimer04Handle;
  260. const osTimerAttr_t myTimer04_attributes = {
  261. .name = "myTimer04"
  262. };
  263. /* Definitions for myTimer05 */
  264. osTimerId_t myTimer05Handle;
  265. const osTimerAttr_t myTimer05_attributes = {
  266. .name = "myTimer05"
  267. };
  268. /* Definitions for myTimer06 */
  269. osTimerId_t myTimer06Handle;
  270. const osTimerAttr_t myTimer06_attributes = {
  271. .name = "myTimer06"
  272. };
  273. /* Definitions for myTimer07 */
  274. osTimerId_t myTimer07Handle;
  275. const osTimerAttr_t myTimer07_attributes = {
  276. .name = "myTimer07"
  277. };
  278. /* Definitions for myTimer08 */
  279. osTimerId_t myTimer08Handle;
  280. const osTimerAttr_t myTimer08_attributes = {
  281. .name = "myTimer08"
  282. };
  283. /* Definitions for myTimer09 */
  284. osTimerId_t myTimer09Handle;
  285. const osTimerAttr_t myTimer09_attributes = {
  286. .name = "myTimer09"
  287. };
  288. /* Definitions for myTimer10 */
  289. osTimerId_t myTimer10Handle;
  290. const osTimerAttr_t myTimer10_attributes = {
  291. .name = "myTimer10"
  292. };
  293. /* Definitions for myMutex01 */
  294. osMutexId_t myMutex01Handle;
  295. const osMutexAttr_t myMutex01_attributes = {
  296. .name = "myMutex01"
  297. };
  298. /* Definitions for myMutex02 */
  299. osMutexId_t myMutex02Handle;
  300. const osMutexAttr_t myMutex02_attributes = {
  301. .name = "myMutex02"
  302. };
  303. /* Definitions for myMutex03 */
  304. osMutexId_t myMutex03Handle;
  305. const osMutexAttr_t myMutex03_attributes = {
  306. .name = "myMutex03"
  307. };
  308. /* Definitions for myMutex04 */
  309. osMutexId_t myMutex04Handle;
  310. const osMutexAttr_t myMutex04_attributes = {
  311. .name = "myMutex04"
  312. };
  313. /* Definitions for myMutex05 */
  314. osMutexId_t myMutex05Handle;
  315. const osMutexAttr_t myMutex05_attributes = {
  316. .name = "myMutex05"
  317. };
  318. /* Definitions for myMutex06 */
  319. osMutexId_t myMutex06Handle;
  320. const osMutexAttr_t myMutex06_attributes = {
  321. .name = "myMutex06"
  322. };
  323. /* Definitions for myMutex07 */
  324. osMutexId_t myMutex07Handle;
  325. const osMutexAttr_t myMutex07_attributes = {
  326. .name = "myMutex07"
  327. };
  328. /* Definitions for myMutex08 */
  329. osMutexId_t myMutex08Handle;
  330. const osMutexAttr_t myMutex08_attributes = {
  331. .name = "myMutex08"
  332. };
  333. /* Definitions for myRecursiveMutex01 */
  334. osMutexId_t myRecursiveMutex01Handle;
  335. const osMutexAttr_t myRecursiveMutex01_attributes = {
  336. .name = "myRecursiveMutex01",
  337. .attr_bits = osMutexRecursive,
  338. };
  339. /* Definitions for myRecursiveMutex02 */
  340. osMutexId_t myRecursiveMutex02Handle;
  341. const osMutexAttr_t myRecursiveMutex02_attributes = {
  342. .name = "myRecursiveMutex02",
  343. .attr_bits = osMutexRecursive,
  344. };
  345. /* Definitions for myRecursiveMutex03 */
  346. osMutexId_t myRecursiveMutex03Handle;
  347. const osMutexAttr_t myRecursiveMutex03_attributes = {
  348. .name = "myRecursiveMutex03",
  349. .attr_bits = osMutexRecursive,
  350. };
  351. /* Definitions for myRecursiveMutex04 */
  352. osMutexId_t myRecursiveMutex04Handle;
  353. const osMutexAttr_t myRecursiveMutex04_attributes = {
  354. .name = "myRecursiveMutex04",
  355. .attr_bits = osMutexRecursive,
  356. };
  357. /* Definitions for myBinarySem01 */
  358. osSemaphoreId_t myBinarySem01Handle;
  359. const osSemaphoreAttr_t myBinarySem01_attributes = {
  360. .name = "myBinarySem01"
  361. };
  362. /* Definitions for myBinarySem02 */
  363. osSemaphoreId_t myBinarySem02Handle;
  364. const osSemaphoreAttr_t myBinarySem02_attributes = {
  365. .name = "myBinarySem02"
  366. };
  367. /* Definitions for myBinarySem03 */
  368. osSemaphoreId_t myBinarySem03Handle;
  369. const osSemaphoreAttr_t myBinarySem03_attributes = {
  370. .name = "myBinarySem03"
  371. };
  372. /* Definitions for myBinarySem04 */
  373. osSemaphoreId_t myBinarySem04Handle;
  374. const osSemaphoreAttr_t myBinarySem04_attributes = {
  375. .name = "myBinarySem04"
  376. };
  377. /* Definitions for myBinarySem05 */
  378. osSemaphoreId_t myBinarySem05Handle;
  379. const osSemaphoreAttr_t myBinarySem05_attributes = {
  380. .name = "myBinarySem05"
  381. };
  382. /* Definitions for myBinarySem06 */
  383. osSemaphoreId_t myBinarySem06Handle;
  384. const osSemaphoreAttr_t myBinarySem06_attributes = {
  385. .name = "myBinarySem06"
  386. };
  387. /* Definitions for myBinarySem07 */
  388. osSemaphoreId_t myBinarySem07Handle;
  389. const osSemaphoreAttr_t myBinarySem07_attributes = {
  390. .name = "myBinarySem07"
  391. };
  392. /* Definitions for myBinarySem08 */
  393. osSemaphoreId_t myBinarySem08Handle;
  394. const osSemaphoreAttr_t myBinarySem08_attributes = {
  395. .name = "myBinarySem08"
  396. };
  397. /* Definitions for myCountingSem01 */
  398. osSemaphoreId_t myCountingSem01Handle;
  399. const osSemaphoreAttr_t myCountingSem01_attributes = {
  400. .name = "myCountingSem01"
  401. };
  402. /* Definitions for myCountingSem02 */
  403. osSemaphoreId_t myCountingSem02Handle;
  404. const osSemaphoreAttr_t myCountingSem02_attributes = {
  405. .name = "myCountingSem02"
  406. };
  407. /* Definitions for myCountingSem03 */
  408. osSemaphoreId_t myCountingSem03Handle;
  409. const osSemaphoreAttr_t myCountingSem03_attributes = {
  410. .name = "myCountingSem03"
  411. };
  412. /* Definitions for myCountingSem04 */
  413. osSemaphoreId_t myCountingSem04Handle;
  414. const osSemaphoreAttr_t myCountingSem04_attributes = {
  415. .name = "myCountingSem04"
  416. };
  417. /* Definitions for myEvent01 */
  418. osEventFlagsId_t myEvent01Handle;
  419. const osEventFlagsAttr_t myEvent01_attributes = {
  420. .name = "myEvent01"
  421. };
  422. /* Definitions for myEvent02 */
  423. osEventFlagsId_t myEvent02Handle;
  424. const osEventFlagsAttr_t myEvent02_attributes = {
  425. .name = "myEvent02"
  426. };
  427. /* Definitions for myEvent03 */
  428. osEventFlagsId_t myEvent03Handle;
  429. const osEventFlagsAttr_t myEvent03_attributes = {
  430. .name = "myEvent03"
  431. };
  432. /* Definitions for myEvent04 */
  433. osEventFlagsId_t myEvent04Handle;
  434. const osEventFlagsAttr_t myEvent04_attributes = {
  435. .name = "myEvent04"
  436. };
  437. /* Definitions for myEvent05 */
  438. osEventFlagsId_t myEvent05Handle;
  439. const osEventFlagsAttr_t myEvent05_attributes = {
  440. .name = "myEvent05"
  441. };
  442. /* Definitions for myEvent06 */
  443. osEventFlagsId_t myEvent06Handle;
  444. const osEventFlagsAttr_t myEvent06_attributes = {
  445. .name = "myEvent06"
  446. };
  447. /* Definitions for myEvent07 */
  448. osEventFlagsId_t myEvent07Handle;
  449. const osEventFlagsAttr_t myEvent07_attributes = {
  450. .name = "myEvent07"
  451. };
  452. /* Definitions for myEvent08 */
  453. osEventFlagsId_t myEvent08Handle;
  454. const osEventFlagsAttr_t myEvent08_attributes = {
  455. .name = "myEvent08"
  456. };
  457. /* USER CODE BEGIN PV */
  458. /* USER CODE END PV */
  459. /* Private function prototypes -----------------------------------------------*/
  460. void SystemClock_Config(void);
  461. static void MX_GPIO_Init(void);
  462. static void MX_DMA_Init(void);
  463. static void MX_USART1_UART_Init(void);
  464. static void MX_UART5_Init(void);
  465. static void MX_USART2_UART_Init(void);
  466. static void MX_USART3_UART_Init(void);
  467. static void MX_CRC_Init(void);
  468. static void MX_DAC_Init(void);
  469. static void MX_TIM1_Init(void);
  470. static void MX_TIM4_Init(void);
  471. void StartDefaultTask(void *argument);
  472. void StartTask02(void *argument);
  473. void StartTask03(void *argument);
  474. void StartTask04(void *argument);
  475. void StartTask05(void *argument);
  476. void StartTask06(void *argument);
  477. void StartTask07(void *argument);
  478. void StartTask08(void *argument);
  479. void StartTask09(void *argument);
  480. void StartTask10(void *argument);
  481. void StartTask11(void *argument);
  482. void StartTask12(void *argument);
  483. void Callback01(void *argument);
  484. void Callback02(void *argument);
  485. void Callback03(void *argument);
  486. void Callback04(void *argument);
  487. void Callback05(void *argument);
  488. void Callback06(void *argument);
  489. void Callback07(void *argument);
  490. void Callback08(void *argument);
  491. void Callback09(void *argument);
  492. void Callback010(void *argument);
  493. void Cang_Init(void);
  494. static void MX_NVIC_Init(void);
  495. // for debug,将信息输出到指定的uart总线上
  496. static void DumpMsg(uint8_t *msg)
  497. {
  498. HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_RESET);
  499. delay_sys_us(80);
  500. HAL_UART_Transmit_IT(&huart2,msg,strlen(msg));
  501. while (huart2.gState == HAL_UART_STATE_BUSY_TX)
  502. {
  503. osDelay(1);
  504. }
  505. delay_sys_us(80);
  506. HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);
  507. }
  508. #include <stdarg.h>
  509. void printx(const char *log,...)
  510. {
  511. osMutexAcquire(myMutex01Handle, portMAX_DELAY);
  512. va_list ap;
  513. va_start(ap,log);
  514. vsnprintf(bufMain,sizeof(bufMain),log,ap);
  515. va_end(ap);
  516. DumpMsg(bufMain);
  517. osMutexRelease(myMutex01Handle);
  518. }
  519. /* USER CODE BEGIN PFP */
  520. void Flash_ReadBytes(uint16_t* sorBuf,uint32_t FlashAddr,uint16_t len)
  521. {
  522. uint16_t* p = sorBuf;
  523. uint8_t i = 0,j = 0;
  524. uint32_t addr = FlashAddr;
  525. while(len--)
  526. {
  527. i = *(uint32_t*)addr++;
  528. j = *(uint32_t*)addr++;
  529. *p++ = j<<8|i;
  530. }
  531. }
  532. uint16_t Flashbuf[2048]__attribute__ ((at(0X20001000)));// {0};
  533. //uint8_t UART_RX_BUF[1024] __attribute__ ((at(0X20001000)));
  534. void Flash_WriteBytes(uint16_t* sorBuf,uint32_t FlashAddr,uint16_t len)
  535. {
  536. uint32_t Offset_ADDR = 0,Page_StartAddr = 0,i = 0;
  537. Offset_ADDR = FlashAddr%0x800;
  538. Page_StartAddr = FlashAddr - Offset_ADDR;
  539. //设置PageError
  540. uint32_t PageError = 0;
  541. FLASH_EraseInitTypeDef f;
  542. f.TypeErase = FLASH_TYPEERASE_PAGES;
  543. __nop();
  544. f.PageAddress =Page_StartAddr;
  545. f.NbPages = 1;
  546. Flash_ReadBytes(Flashbuf,Page_StartAddr,0x400);
  547. for(i = 0;i<len;i++)
  548. Flashbuf[Offset_ADDR/2+i] = sorBuf[i];
  549. //1、解锁FLASH
  550. HAL_FLASH_Unlock();
  551. __nop();
  552. //2、擦除FLASH
  553. //初始化FLASH_EraseInitTypeDef
  554. //调用擦除函数
  555. HAL_FLASHEx_Erase(&f, &PageError);
  556. __nop();
  557. //3、对FLASH烧写
  558. for(uint16_t i = 0;i< 0x400 ;i++)
  559. {
  560. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD , Page_StartAddr + (i * 2), Flashbuf[i]);
  561. }
  562. //4、锁住FLASH
  563. HAL_FLASH_Lock();
  564. }
  565. typedef union{
  566. float Ldcal_zero_temp; //青鸟贵和磁致伸缩液位温度一体传感器
  567. uint8_t arr[4];
  568. }Hex_to_float1;
  569. Hex_to_float1 hex_to_float1;
  570. void Cang_Init(void)
  571. {
  572. Cang_Inf* pcang = &cang_inf;
  573. RKG_Inf* prkg = rkg_inf;
  574. XYF_Inf* pxyf = xyf_inf;
  575. HDF_Inf* phdf = hdf_inf;
  576. Angle_Inf* pangle = &angle_inf;
  577. Level_Inf* plevel = level_inf;
  578. Tem_Inf* ptem = tem_inf;
  579. uint16_t Flash_buff[64] = {0};
  580. uint16_t i = 0;
  581. Flash_ReadBytes(Flash_buff,ADDR_CANG_NUM,6);
  582. if(Flash_buff[0] == 0xffff)
  583. {
  584. //Flash_WriteBytes(Volume_1cang,ADD_CANG1_TABLE,200);
  585. //Flash_WriteBytes(Volume_2cang,ADD_CANG2_TABLE,200);
  586. //Flash_WriteBytes(Volume_3cang,ADD_CANG3_TABLE,200);
  587. //Flash_WriteBytes(Volume_4cang,ADD_CANG4_TABLE,200);
  588. pcang->Cang_Num = 3; //默认三仓
  589. }
  590. else
  591. pcang->Cang_Num = Flash_buff[0];
  592. if(Flash_buff[1] == 0xffff)
  593. {
  594. i = 0;
  595. while(i < pcang->Cang_Num)
  596. {
  597. pcang->RKG_Num[i] = 1; //默认每仓1人孔大盖
  598. pcang->RKG_DG = 1; //默认有大盖
  599. i++;
  600. }
  601. }
  602. else
  603. {
  604. i = 0;
  605. while(i <pcang->Cang_Num)
  606. {
  607. pcang->RKG_Num[i] = Flash_buff[1]; //默认每仓1人孔盖
  608. pcang->RKG_DG = Flash_buff[1];
  609. i++;
  610. }
  611. }
  612. if(Flash_buff[2] == 0xffff)
  613. pcang->RKG_XG = 0; //默认无人孔小盖
  614. else
  615. pcang->RKG_XG = Flash_buff[2];
  616. if(Flash_buff[3] == 0xffff)
  617. {
  618. i = 0;
  619. while(i <pcang->Cang_Num)
  620. {
  621. pcang->XYF_INSTALL = 1; // 默认有卸油阀SLM
  622. pcang->XYF_Num[i] = 1; //默认每仓1卸油阀
  623. i++;
  624. }
  625. }
  626. else
  627. {
  628. i = 0;
  629. while(i <pcang->Cang_Num)
  630. {
  631. pcang->XYF_INSTALL = 1; // 默认有卸油阀SLM
  632. pcang->XYF_Num[i] = Flash_buff[3]; i++;
  633. }
  634. }
  635. if(Flash_buff[4] == 0xffff)
  636. {
  637. i = 0;
  638. while(i <pcang->Cang_Num)
  639. {
  640. pcang->HDF_INSTALL = 1;
  641. pcang->HDF_Num[i] = 1; //默认每仓1海底阀
  642. i++;
  643. }
  644. }
  645. else
  646. {
  647. i = 0;
  648. while(i <pcang->Cang_Num)
  649. {
  650. pcang->HDF_INSTALL = 1;//slm
  651. pcang->HDF_Num[i] = Flash_buff[4];
  652. i++;
  653. }
  654. }
  655. Flash_ReadBytes(Flash_buff,ADDR_RKGSENSOR_TYPE,1);
  656. if(Flash_buff[0] == 0xffff)
  657. pcang->RKG_Type = 1; //默认人孔盖角度传感器 1磁电编码传感器
  658. else
  659. pcang->RKG_Type = Flash_buff[0];
  660. Flash_ReadBytes(Flash_buff,ADDR_XYFSENSOR_TYPE,1);
  661. if(Flash_buff[0] == 0xffff)
  662. pcang->XYF_Type = 0; //默认卸油阀霍尔二合一
  663. else
  664. pcang->XYF_Type = Flash_buff[0];
  665. Flash_ReadBytes(Flash_buff,ADDR_HDFSENSOR_TYPE,1);
  666. if(Flash_buff[0] == 0xffff)
  667. pcang->HDF_Type = 1; //默认底阀监测器 1智能底阀
  668. else
  669. pcang->HDF_Type = Flash_buff[0];
  670. Flash_ReadBytes(Flash_buff,ADDR_RKG_NUM,8); //检测是否对阀门种类及数量进行配置
  671. for(i = 0;i < 8;i++)
  672. {
  673. if((Flash_buff[i] < 8))
  674. pcang->RKG_Num[i] = Flash_buff[i];
  675. else
  676. pcang->RKG_Num[i] = 1; //默认每仓1人孔阀
  677. }
  678. Flash_ReadBytes(Flash_buff,ADDR_XYF_NUM,8);
  679. for(i = 0;i < 8;i++)
  680. {
  681. if((Flash_buff[i] < 8))
  682. pcang->XYF_Num[i] = Flash_buff[i];
  683. else
  684. pcang->XYF_Num[i] = 1; //默认每仓1卸油阀 slm
  685. }
  686. Flash_ReadBytes(Flash_buff,ADDR_HDF_NUM,8);
  687. for(i = 0;i < 8;i++)
  688. {
  689. if((Flash_buff[i] < 8))
  690. pcang->HDF_Num[i] = Flash_buff[i];
  691. else
  692. pcang->HDF_Num[i] = 1; //默认每仓1海底阀 slm
  693. }
  694. Flash_ReadBytes(Flash_buff,ADDR_YQHS_TYPE,1);
  695. if(Flash_buff[0] == 0xffff)
  696. pcang->YQHS = 0; //默认无油气回收 slm
  697. else
  698. pcang->YQHS = Flash_buff[0];
  699. Flash_ReadBytes(Flash_buff,ADDR_LEVEL_TYPE,1);
  700. if(Flash_buff[0] == 0xffff)
  701. pcang->Level = LEVEL_NONE; //默认无液位传感器 slm
  702. else
  703. pcang->Level = Flash_buff[0];
  704. Flash_ReadBytes(Flash_buff,CANG1_LEVEL_CAL,8);
  705. if(Flash_buff[0] == 0xffff)
  706. {
  707. for(i=0;i<pcang->Cang_Num;++i)
  708. {
  709. plevel[i].zero = 0;
  710. }
  711. }
  712. else
  713. {
  714. for (i = 0; i < pcang->Cang_Num; ++i)
  715. {
  716. hex_to_float1.arr[3] = (uint8_t)(Flash_buff[0+2*i] >> 8);
  717. hex_to_float1.arr[2] = (uint8_t)(Flash_buff[0+2*i] & 0xFF); // Flash_buff[3];
  718. hex_to_float1.arr[1] = (uint8_t)(Flash_buff[1+2*i] >> 8);
  719. hex_to_float1.arr[0] = (uint8_t)(Flash_buff[1+2*i] & 0xFF);
  720. plevel[i].zero = hex_to_float1.Ldcal_zero_temp;
  721. }
  722. }
  723. Flash_ReadBytes(Flash_buff,ADDR_SENSOR_BUS_MAX_RETRY,1);
  724. if(Flash_buff[0] == 0xffff)
  725. pcang->sensorBusMaxReTry = 10;
  726. else
  727. pcang->sensorBusMaxReTry = Flash_buff[0];
  728. Flash_ReadBytes(Flash_buff,ADDR_PIN_IO_HIT_SAME,1);
  729. if(Flash_buff[0] == 0xffff)
  730. pcang->pinIOHitSameParam = 3;
  731. else
  732. pcang->pinIOHitSameParam = Flash_buff[0];
  733. Flash_ReadBytes(Flash_buff,ADDR_TEM_TYPE,1);
  734. if(Flash_buff[0] == 0xffff)
  735. pcang->Temperture = 1; //默认无温度传感器
  736. else
  737. pcang->Temperture = Flash_buff[0];
  738. Flash_ReadBytes(Flash_buff,ADDR_ANGLE_TYPE,1);
  739. if(Flash_buff[0] == 0xffff)
  740. pcang->Angle = 1; //默认无姿态传感器
  741. else
  742. pcang->Angle = Flash_buff[0];
  743. Flash_ReadBytes(Flash_buff,ADDR_SDATEJUDGE_NUM,1);
  744. if(Flash_buff[0] == 0xffff)
  745. {
  746. for (i = 0; i < 8; i++)
  747. {
  748. prkg[i].RKG_StateKeepNum = 5; //默认人孔盖角度传感器
  749. pxyf[i].XYF_StateKeepNum = 5;
  750. plevel[i].StateKeepNum = 5;
  751. ptem[i].StateKeepNum = 5;
  752. }
  753. phdf->HDF_StateKeepNum = 5;
  754. pangle->Angle_StateKeepNum = 5;
  755. //plevel->StateKeepNum = 5;
  756. //ptem->TEM_StateKeepNum = 5;
  757. }
  758. else
  759. {
  760. for (i = 0; i < 8; i++)
  761. {
  762. prkg[i].RKG_StateKeepNum = Flash_buff[0];
  763. pxyf[i].XYF_StateKeepNum = Flash_buff[0];
  764. plevel[i].StateKeepNum = Flash_buff[0];
  765. ptem[i].StateKeepNum = Flash_buff[0];
  766. }
  767. pxyf->XYF_StateKeepNum = Flash_buff[0];
  768. phdf->HDF_StateKeepNum = Flash_buff[0];
  769. __NOP();
  770. pangle->Angle_StateKeepNum = Flash_buff[0];
  771. //plevel->StateKeepNum = Flash_buff[0];
  772. //ptem->TEM_StateKeepNum = Flash_buff[0];
  773. }
  774. }
  775. /* USER CODE END PFP */
  776. /* Private user code ---------------------------------------------------------*/
  777. /* USER CODE BEGIN 0 */
  778. /* USER CODE END 0 */
  779. /**4
  780. * @brief The application entry point.
  781. * @retval int
  782. */
  783. int main(void)
  784. {
  785. /* USER CODE BEGIN 1 */
  786. GPIO_InitTypeDef GPIO_InitStruct = {0};
  787. int spr000;
  788. /* USER CODE END 1 */
  789. #if IR_ROM1 == 0x08000000
  790. Start_BootLoader();
  791. #else
  792. SCB->VTOR = 0x08020000;
  793. __set_PRIMASK(0);
  794. #endif
  795. /* MCU Configuration--------------------------------------------------------*/
  796. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  797. HAL_Init();
  798. /* USER CODE BEGIN Init */
  799. Cang_Init(); //应用程序初始化函数
  800. RKG_Init();
  801. XYF_Init();
  802. BGY_Init();
  803. Pressure_Init();
  804. /* USER CODE END Init */
  805. /* Configure the system clock */
  806. SystemClock_Config();
  807. /* USER CODE BEGIN SysInit */
  808. /* USER CODE END SysInit */
  809. /* Initialize all configured peripherals */
  810. MX_GPIO_Init();
  811. MX_DMA_Init();
  812. MX_USART1_UART_Init();
  813. MX_UART5_Init();
  814. MX_USART2_UART_Init();
  815. MX_USART3_UART_Init();
  816. MX_CRC_Init();
  817. MX_DAC_Init();
  818. MX_TIM1_Init();
  819. MX_TIM4_Init();
  820. /* Initialize interrupts */
  821. MX_NVIC_Init();
  822. /* USER CODE BEGIN 2 */
  823. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//切换为接收模式
  824. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);//切换为接收模式
  825. HAL_GPIO_WritePin(con03_uart2_kongzhiqi_GPIO_Port,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);//切换为接收模式
  826. //看门狗重新根据宏定义初始化
  827. GPIO_InitStruct.Pin = WDI_sp706_kanmemgou_Pin;
  828. if(WatchDogOn)//打开看门狗sp706
  829. //if(1)//打开看门狗sp706
  830. {
  831. //
  832. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  833. }
  834. else
  835. {
  836. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  837. }
  838. GPIO_InitStruct.Pull = GPIO_NOPULL;
  839. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  840. HAL_GPIO_Init(WDI_sp706_kanmemgou_GPIO_Port, &GPIO_InitStruct);
  841. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//切换为发送模式CON=0;//
  842. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//切换为接收模式
  843. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);//切换为接收模式
  844. HAL_GPIO_WritePin(con03_uart2_kongzhiqi_GPIO_Port,con03_uart2_kongzhiqi_Pin,GPIO_PIN_RESET);//切换为接收模式
  845. HAL_Delay(2);
  846. memset(bufMain,0,128);
  847. spr000=sprintf((char*)bufMain,"sysytem reset...%5d, watchDogOn=%d, version:%d-%d",5,WatchDogOn,Version_Soft[7],Version_Soft[3]);
  848. //HAL_UART_Transmit(&huart1,bufMain,32,300);
  849. HAL_UART_Transmit(&huart2,bufMain,spr000,300);
  850. //HAL_UART_Transmit(&huart3,bufMain,32,300);
  851. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//切换为接收模式
  852. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);//切换为接收模式
  853. HAL_GPIO_WritePin(con03_uart2_kongzhiqi_GPIO_Port,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);//切换为接收模式
  854. /* USER CODE END 2 */
  855. /* Init scheduler */
  856. osKernelInitialize();
  857. /* Create the mutex(es) */
  858. /* creation of myMutex01 */
  859. myMutex01Handle = osMutexNew(&myMutex01_attributes);
  860. /* creation of myMutex02 */
  861. myMutex02Handle = osMutexNew(&myMutex02_attributes);
  862. /* creation of myMutex03 */
  863. myMutex03Handle = osMutexNew(&myMutex03_attributes);
  864. /* creation of myMutex04 */
  865. myMutex04Handle = osMutexNew(&myMutex04_attributes);
  866. /* creation of myMutex05 */
  867. myMutex05Handle = osMutexNew(&myMutex05_attributes);
  868. /* creation of myMutex06 */
  869. myMutex06Handle = osMutexNew(&myMutex06_attributes);
  870. /* creation of myMutex07 */
  871. myMutex07Handle = osMutexNew(&myMutex07_attributes);
  872. /* creation of myMutex08 */
  873. myMutex08Handle = osMutexNew(&myMutex08_attributes);
  874. /* Create the recursive mutex(es) */
  875. /* creation of myRecursiveMutex01 */
  876. myRecursiveMutex01Handle = osMutexNew(&myRecursiveMutex01_attributes);
  877. /* creation of myRecursiveMutex02 */
  878. myRecursiveMutex02Handle = osMutexNew(&myRecursiveMutex02_attributes);
  879. /* creation of myRecursiveMutex03 */
  880. myRecursiveMutex03Handle = osMutexNew(&myRecursiveMutex03_attributes);
  881. /* creation of myRecursiveMutex04 */
  882. myRecursiveMutex04Handle = osMutexNew(&myRecursiveMutex04_attributes);
  883. /* USER CODE BEGIN RTOS_MUTEX */
  884. /* add mutexes, ... */
  885. /* USER CODE END RTOS_MUTEX */
  886. /* Create the semaphores(s) */
  887. /* creation of myBinarySem01 */
  888. myBinarySem01Handle = osSemaphoreNew(1, 1, &myBinarySem01_attributes);
  889. /* creation of myBinarySem02 */
  890. myBinarySem02Handle = osSemaphoreNew(1, 1, &myBinarySem02_attributes);
  891. /* creation of myBinarySem03 */
  892. myBinarySem03Handle = osSemaphoreNew(1, 1, &myBinarySem03_attributes);
  893. /* creation of myBinarySem04 */
  894. myBinarySem04Handle = osSemaphoreNew(1, 1, &myBinarySem04_attributes);
  895. /* creation of myBinarySem05 */
  896. myBinarySem05Handle = osSemaphoreNew(1, 1, &myBinarySem05_attributes);
  897. /* creation of myBinarySem06 */
  898. myBinarySem06Handle = osSemaphoreNew(1, 1, &myBinarySem06_attributes);
  899. /* creation of myBinarySem07 */
  900. myBinarySem07Handle = osSemaphoreNew(1, 1, &myBinarySem07_attributes);
  901. /* creation of myBinarySem08 */
  902. myBinarySem08Handle = osSemaphoreNew(1, 1, &myBinarySem08_attributes);
  903. /* creation of myCountingSem01 */
  904. myCountingSem01Handle = osSemaphoreNew(2, 2, &myCountingSem01_attributes);
  905. /* creation of myCountingSem02 */
  906. myCountingSem02Handle = osSemaphoreNew(2, 2, &myCountingSem02_attributes);
  907. /* creation of myCountingSem03 */
  908. myCountingSem03Handle = osSemaphoreNew(2, 2, &myCountingSem03_attributes);
  909. /* creation of myCountingSem04 */
  910. myCountingSem04Handle = osSemaphoreNew(2, 2, &myCountingSem04_attributes);
  911. /* USER CODE BEGIN RTOS_SEMAPHORES */
  912. /* add semaphores, ... */
  913. /* USER CODE END RTOS_SEMAPHORES */
  914. /* Create the timer(s) */
  915. /* creation of myTimer01 */
  916. myTimer01Handle = osTimerNew(Callback01, osTimerPeriodic, NULL, &myTimer01_attributes);
  917. /* creation of myTimer02 */
  918. myTimer02Handle = osTimerNew(Callback02, osTimerPeriodic, NULL, &myTimer02_attributes);
  919. /* creation of myTimer03 */
  920. myTimer03Handle = osTimerNew(Callback03, osTimerPeriodic, NULL, &myTimer03_attributes);
  921. /* creation of myTimer04 */
  922. myTimer04Handle = osTimerNew(Callback04, osTimerPeriodic, NULL, &myTimer04_attributes);
  923. /* creation of myTimer05 */
  924. myTimer05Handle = osTimerNew(Callback05, osTimerPeriodic, NULL, &myTimer05_attributes);
  925. /* creation of myTimer06 */
  926. myTimer06Handle = osTimerNew(Callback06, osTimerPeriodic, NULL, &myTimer06_attributes);
  927. /* creation of myTimer07 */
  928. myTimer07Handle = osTimerNew(Callback07, osTimerPeriodic, NULL, &myTimer07_attributes);
  929. /* creation of myTimer08 */
  930. myTimer08Handle = osTimerNew(Callback08, osTimerPeriodic, NULL, &myTimer08_attributes);
  931. /* creation of myTimer09 */
  932. myTimer09Handle = osTimerNew(Callback09, osTimerPeriodic, NULL, &myTimer09_attributes);
  933. /* creation of myTimer10 */
  934. myTimer10Handle = osTimerNew(Callback010, osTimerPeriodic, NULL, &myTimer10_attributes);
  935. /* USER CODE BEGIN RTOS_TIMERS */
  936. /* start timers, add new ones, ... */
  937. /* USER CODE END RTOS_TIMERS */
  938. /* Create the queue(s) */
  939. /* creation of myQueue01 */
  940. myQueue01Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue01_attributes);
  941. /* creation of myQueue02 */
  942. myQueue02Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue02_attributes);
  943. /* creation of myQueue03 */
  944. myQueue03Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue03_attributes);
  945. /* creation of myQueue04 */
  946. myQueue04Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue04_attributes);
  947. /* creation of myQueue05 */
  948. myQueue05Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue05_attributes);
  949. /* creation of myQueue06 */
  950. myQueue06Handle = osMessageQueueNew (16, sizeof(uint16_t), &myQueue06_attributes);
  951. /* USER CODE BEGIN RTOS_QUEUES */
  952. /* add queues, ... */
  953. /* USER CODE END RTOS_QUEUES */
  954. /* Create the thread(s) */
  955. /* creation of defaultTask */
  956. defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
  957. /* creation of myTask02 */
  958. myTask02Handle = osThreadNew(StartTask02, NULL, &myTask02_attributes);
  959. /* creation of myTask03 */
  960. myTask03Handle = osThreadNew(StartTask03, NULL, &myTask03_attributes);
  961. /* creation of myTask04 */
  962. myTask04Handle = osThreadNew(StartTask04, NULL, &myTask04_attributes);
  963. /* creation of myTask05 */
  964. myTask05Handle = osThreadNew(StartTask05, NULL, &myTask05_attributes);
  965. /* creation of myTask06 */
  966. myTask06Handle = osThreadNew(StartTask06, NULL, &myTask06_attributes);
  967. /* creation of myTask07 */
  968. myTask07Handle = osThreadNew(StartTask07, NULL, &myTask07_attributes);
  969. /* creation of myTask08 */
  970. myTask08Handle = osThreadNew(StartTask08, NULL, &myTask08_attributes);
  971. /* creation of myTask09 */
  972. myTask09Handle = osThreadNew(StartTask09, NULL, &myTask09_attributes);
  973. /* creation of myTask10 */
  974. myTask10Handle = osThreadNew(StartTask10, NULL, &myTask10_attributes);
  975. /* creation of myTask11 */
  976. myTask11Handle = osThreadNew(StartTask11, NULL, &myTask11_attributes);
  977. /* creation of myTask12 */
  978. myTask12Handle = osThreadNew(StartTask12, NULL, &myTask12_attributes);
  979. /* USER CODE BEGIN RTOS_THREADS */
  980. /* add threads, ... */
  981. /* USER CODE END RTOS_THREADS */
  982. /* creation of myEvent01 */
  983. myEvent01Handle = osEventFlagsNew(&myEvent01_attributes);
  984. /* creation of myEvent02 */
  985. myEvent02Handle = osEventFlagsNew(&myEvent02_attributes);
  986. /* creation of myEvent03 */
  987. myEvent03Handle = osEventFlagsNew(&myEvent03_attributes);
  988. /* creation of myEvent04 */
  989. myEvent04Handle = osEventFlagsNew(&myEvent04_attributes);
  990. /* creation of myEvent05 */
  991. myEvent05Handle = osEventFlagsNew(&myEvent05_attributes);
  992. /* creation of myEvent06 */
  993. myEvent06Handle = osEventFlagsNew(&myEvent06_attributes);
  994. /* creation of myEvent07 */
  995. myEvent07Handle = osEventFlagsNew(&myEvent07_attributes);
  996. /* creation of myEvent08 */
  997. myEvent08Handle = osEventFlagsNew(&myEvent08_attributes);
  998. /* USER CODE BEGIN RTOS_EVENTS */
  999. /* add events, ... */
  1000. /* USER CODE END RTOS_EVENTS */
  1001. /* Start scheduler */
  1002. osKernelStart();
  1003. /* We should never get here as control is now taken by the scheduler */
  1004. /* Infinite loop */
  1005. /* USER CODE BEGIN WHILE */
  1006. while (1)
  1007. {
  1008. }
  1009. /* USER CODE END WHILE */
  1010. /* USER CODE BEGIN 3 */
  1011. /* USER CODE END 3 */
  1012. }
  1013. /**
  1014. * @brief System Clock Configuration
  1015. * @retval None
  1016. */
  1017. void SystemClock_Config(void)
  1018. {
  1019. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  1020. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  1021. /** Initializes the RCC Oscillators according to the specified parameters
  1022. * in the RCC_OscInitTypeDef structure.
  1023. */
  1024. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  1025. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  1026. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  1027. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  1028. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  1029. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  1030. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  1031. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  1032. {
  1033. Error_Handler();
  1034. }
  1035. /** Initializes the CPU, AHB and APB buses clocks
  1036. */
  1037. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  1038. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  1039. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  1040. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  1041. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  1042. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  1043. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  1044. {
  1045. Error_Handler();
  1046. }
  1047. }
  1048. /**
  1049. * @brief NVIC Configuration.
  1050. * @retval None
  1051. */
  1052. static void MX_NVIC_Init(void)
  1053. {
  1054. /* USART3_IRQn interrupt configuration */
  1055. HAL_NVIC_SetPriority(USART3_IRQn, 5, 0);
  1056. HAL_NVIC_EnableIRQ(USART3_IRQn);
  1057. /* USART1_IRQn interrupt configuration */
  1058. HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
  1059. HAL_NVIC_EnableIRQ(USART1_IRQn);
  1060. /* USART2_IRQn interrupt configuration */
  1061. HAL_NVIC_SetPriority(USART2_IRQn, 5, 0);
  1062. HAL_NVIC_EnableIRQ(USART2_IRQn);
  1063. /* TIM4_IRQn interrupt configuration */
  1064. HAL_NVIC_SetPriority(TIM4_IRQn, 5, 0);
  1065. HAL_NVIC_EnableIRQ(TIM4_IRQn);
  1066. /* TIM1_UP_IRQn interrupt configuration */
  1067. HAL_NVIC_SetPriority(TIM1_UP_IRQn, 5, 0);
  1068. HAL_NVIC_EnableIRQ(TIM1_UP_IRQn);
  1069. /* DMA1_Channel6_IRQn interrupt configuration */
  1070. HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 5, 0);
  1071. HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
  1072. /* DMA1_Channel5_IRQn interrupt configuration */
  1073. HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 5, 0);
  1074. HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
  1075. /* DMA1_Channel3_IRQn interrupt configuration */
  1076. HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 5, 0);
  1077. HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
  1078. }
  1079. /**
  1080. * @brief CRC Initialization Function
  1081. * @param None
  1082. * @retval None
  1083. */
  1084. static void MX_CRC_Init(void)
  1085. {
  1086. /* USER CODE BEGIN CRC_Init 0 */
  1087. /* USER CODE END CRC_Init 0 */
  1088. /* USER CODE BEGIN CRC_Init 1 */
  1089. /* USER CODE END CRC_Init 1 */
  1090. hcrc.Instance = CRC;
  1091. if (HAL_CRC_Init(&hcrc) != HAL_OK)
  1092. {
  1093. Error_Handler();
  1094. }
  1095. /* USER CODE BEGIN CRC_Init 2 */
  1096. /* USER CODE END CRC_Init 2 */
  1097. }
  1098. /**
  1099. * @brief DAC Initialization Function
  1100. * @param None
  1101. * @retval None
  1102. */
  1103. static void MX_DAC_Init(void)
  1104. {
  1105. /* USER CODE BEGIN DAC_Init 0 */
  1106. /* USER CODE END DAC_Init 0 */
  1107. DAC_ChannelConfTypeDef sConfig = {0};
  1108. /* USER CODE BEGIN DAC_Init 1 */
  1109. /* USER CODE END DAC_Init 1 */
  1110. /** DAC Initialization
  1111. */
  1112. hdac.Instance = DAC;
  1113. if (HAL_DAC_Init(&hdac) != HAL_OK)
  1114. {
  1115. Error_Handler();
  1116. }
  1117. /** DAC channel OUT2 config
  1118. */
  1119. sConfig.DAC_Trigger = DAC_TRIGGER_SOFTWARE;
  1120. sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
  1121. if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_2) != HAL_OK)
  1122. {
  1123. Error_Handler();
  1124. }
  1125. /* USER CODE BEGIN DAC_Init 2 */
  1126. /* USER CODE END DAC_Init 2 */
  1127. }
  1128. /**
  1129. * @brief TIM1 Initialization Function
  1130. * @param None
  1131. * @retval None
  1132. */
  1133. static void MX_TIM1_Init(void)
  1134. {
  1135. /* USER CODE BEGIN TIM1_Init 0 */
  1136. /* USER CODE END TIM1_Init 0 */
  1137. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  1138. TIM_MasterConfigTypeDef sMasterConfig = {0};
  1139. /* USER CODE BEGIN TIM1_Init 1 */
  1140. /* USER CODE END TIM1_Init 1 */
  1141. htim1.Instance = TIM1;
  1142. htim1.Init.Prescaler = 0;
  1143. htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  1144. htim1.Init.Period = 65535;
  1145. htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
  1146. htim1.Init.RepetitionCounter = 0;
  1147. htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1148. if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
  1149. {
  1150. Error_Handler();
  1151. }
  1152. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1153. if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
  1154. {
  1155. Error_Handler();
  1156. }
  1157. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1158. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1159. if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  1160. {
  1161. Error_Handler();
  1162. }
  1163. /* USER CODE BEGIN TIM1_Init 2 */
  1164. /* USER CODE END TIM1_Init 2 */
  1165. }
  1166. /**
  1167. * @brief TIM4 Initialization Function
  1168. * @param None
  1169. * @retval None
  1170. */
  1171. static void MX_TIM4_Init(void)
  1172. {
  1173. /* USER CODE BEGIN TIM4_Init 0 */
  1174. /* USER CODE END TIM4_Init 0 */
  1175. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  1176. TIM_MasterConfigTypeDef sMasterConfig = {0};
  1177. /* USER CODE BEGIN TIM4_Init 1 */
  1178. /* USER CODE END TIM4_Init 1 */
  1179. htim4.Instance = TIM4;
  1180. htim4.Init.Prescaler = 0;
  1181. htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
  1182. htim4.Init.Period = 65535;
  1183. htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  1184. htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  1185. if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
  1186. {
  1187. Error_Handler();
  1188. }
  1189. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  1190. if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
  1191. {
  1192. Error_Handler();
  1193. }
  1194. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  1195. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  1196. if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
  1197. {
  1198. Error_Handler();
  1199. }
  1200. /* USER CODE BEGIN TIM4_Init 2 */
  1201. /* USER CODE END TIM4_Init 2 */
  1202. }
  1203. /**
  1204. * @brief UART5 Initialization Function
  1205. * @param None
  1206. * @retval None
  1207. */
  1208. static void MX_UART5_Init(void)
  1209. {
  1210. /* USER CODE BEGIN UART5_Init 0 */
  1211. /* USER CODE END UART5_Init 0 */
  1212. /* USER CODE BEGIN UART5_Init 1 */
  1213. /* USER CODE END UART5_Init 1 */
  1214. huart5.Instance = UART5;
  1215. huart5.Init.BaudRate = 115200;
  1216. huart5.Init.WordLength = UART_WORDLENGTH_8B;
  1217. huart5.Init.StopBits = UART_STOPBITS_1;
  1218. huart5.Init.Parity = UART_PARITY_NONE;
  1219. huart5.Init.Mode = UART_MODE_TX_RX;
  1220. huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1221. huart5.Init.OverSampling = UART_OVERSAMPLING_16;
  1222. if (HAL_UART_Init(&huart5) != HAL_OK)
  1223. {
  1224. Error_Handler();
  1225. }
  1226. /* USER CODE BEGIN UART5_Init 2 */
  1227. /* USER CODE END UART5_Init 2 */
  1228. }
  1229. /**
  1230. * @brief USART1 Initialization Function
  1231. * @param None
  1232. * @retval None
  1233. */
  1234. static void MX_USART1_UART_Init(void)
  1235. {
  1236. /* USER CODE BEGIN USART1_Init 0 */
  1237. extern uint8_t USART1_RX_BUF[Uart1_BUF_SIZE];
  1238. /* USER CODE END USART1_Init 0 */
  1239. /* USER CODE BEGIN USART1_Init 1 */
  1240. /* USER CODE END USART1_Init 1 */
  1241. huart1.Instance = USART1;
  1242. huart1.Init.BaudRate = 9600;
  1243. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  1244. huart1.Init.StopBits = UART_STOPBITS_1;
  1245. huart1.Init.Parity = UART_PARITY_NONE;
  1246. huart1.Init.Mode = UART_MODE_TX_RX;
  1247. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1248. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  1249. if (HAL_UART_Init(&huart1) != HAL_OK)
  1250. {
  1251. Error_Handler();
  1252. }
  1253. /* USER CODE BEGIN USART1_Init 2 */
  1254. __HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);
  1255. HAL_UART_Receive_DMA(&huart1,USART1_RX_BUF,Uart1_BUF_SIZE);
  1256. /* USER CODE END USART1_Init 2 */
  1257. }
  1258. /**
  1259. * @brief USART2 Initialization Function
  1260. * @param None
  1261. * @retval None
  1262. */
  1263. static void MX_USART2_UART_Init(void)
  1264. {
  1265. /* USER CODE BEGIN USART2_Init 0 */
  1266. /* USER CODE END USART2_Init 0 */
  1267. /* USER CODE BEGIN USART2_Init 1 */
  1268. /* USER CODE END USART2_Init 1 */
  1269. huart2.Instance = USART2;
  1270. huart2.Init.BaudRate = 19200;//19200
  1271. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  1272. huart2.Init.StopBits = UART_STOPBITS_1;
  1273. huart2.Init.Parity = UART_PARITY_NONE;
  1274. huart2.Init.Mode = UART_MODE_TX_RX;
  1275. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1276. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  1277. if (HAL_UART_Init(&huart2) != HAL_OK)
  1278. {
  1279. Error_Handler();
  1280. }
  1281. /* USER CODE BEGIN USART2_Init 2 */
  1282. __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE);
  1283. HAL_UART_Receive_DMA(&huart2,USART2_RX_BUF,Uart2_BUF_SIZE);
  1284. /* USER CODE END USART2_Init 2 */
  1285. }
  1286. /**
  1287. * @brief USART3 Initialization Function
  1288. * @param None
  1289. * @retval None
  1290. */
  1291. static void MX_USART3_UART_Init(void)
  1292. {
  1293. /* USER CODE BEGIN USART3_Init 0 */
  1294. /* USER CODE END USART3_Init 0 */
  1295. /* USER CODE BEGIN USART3_Init 1 */
  1296. /* USER CODE END USART3_Init 1 */
  1297. huart3.Instance = USART3;
  1298. huart3.Init.BaudRate = 9600;
  1299. huart3.Init.WordLength = UART_WORDLENGTH_8B;
  1300. huart3.Init.StopBits = UART_STOPBITS_1;
  1301. huart3.Init.Parity = UART_PARITY_NONE;
  1302. huart3.Init.Mode = UART_MODE_TX_RX;
  1303. huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  1304. huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  1305. if (HAL_UART_Init(&huart3) != HAL_OK)
  1306. {
  1307. Error_Handler();
  1308. }
  1309. /* USER CODE BEGIN USART3_Init 2 */
  1310. __HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);
  1311. HAL_UART_Receive_DMA(&huart3,USART3_RX_BUF,Uart3_BUF_SIZE);
  1312. /* USER CODE END USART3_Init 2 */
  1313. }
  1314. /**
  1315. * Enable DMA controller clock
  1316. */
  1317. static void MX_DMA_Init(void)
  1318. {
  1319. /* DMA controller clock enable */
  1320. __HAL_RCC_DMA1_CLK_ENABLE();
  1321. __HAL_RCC_DMA2_CLK_ENABLE();
  1322. /* DMA interrupt init */
  1323. /* DMA1_Channel4_IRQn interrupt configuration */
  1324. HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 5, 0);
  1325. HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn);
  1326. /* DMA2_Channel4_5_IRQn interrupt configuration */
  1327. HAL_NVIC_SetPriority(DMA2_Channel4_5_IRQn, 5, 0);
  1328. HAL_NVIC_EnableIRQ(DMA2_Channel4_5_IRQn);
  1329. }
  1330. /**
  1331. * @brief GPIO Initialization Function
  1332. * @param None
  1333. * @retval None
  1334. */
  1335. static void MX_GPIO_Init(void)
  1336. {
  1337. GPIO_InitTypeDef GPIO_InitStruct = {0};
  1338. /* GPIO Ports Clock Enable */
  1339. __HAL_RCC_GPIOD_CLK_ENABLE();
  1340. __HAL_RCC_GPIOA_CLK_ENABLE();
  1341. __HAL_RCC_GPIOB_CLK_ENABLE();
  1342. __HAL_RCC_GPIOC_CLK_ENABLE();
  1343. /*Configure GPIO pin Output Level */
  1344. HAL_GPIO_WritePin(GPIOA, LED1_Pin|LED2_Pin|con03_uart2_kongzhiqi_Pin, GPIO_PIN_RESET);
  1345. /*Configure GPIO pin Output Level */
  1346. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin|Con01_uart1_rankonggai_Pin, GPIO_PIN_RESET);
  1347. /*Configure GPIO pin Output Level */
  1348. HAL_GPIO_WritePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin, GPIO_PIN_RESET);
  1349. /*Configure GPIO pins : LED1_Pin LED2_Pin con03_uart2_kongzhiqi_Pin */
  1350. GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin|con03_uart2_kongzhiqi_Pin;
  1351. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1352. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1353. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1354. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  1355. /*Configure GPIO pins : con02_uart3_xieyoufa_Pin Con01_uart1_rankonggai_Pin */
  1356. GPIO_InitStruct.Pin = con02_uart3_xieyoufa_Pin|Con01_uart1_rankonggai_Pin;
  1357. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1358. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1359. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1360. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1361. /*Configure GPIO pins : IN01_Pin PB15 */
  1362. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  1363. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1364. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1365. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1366. /*Configure GPIO pins : PC6 PC7 PC8 PC9 */
  1367. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
  1368. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1369. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1370. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1371. /*Configure GPIO pins : PA8 PA11 */
  1372. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_11;
  1373. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1374. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1375. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  1376. /*Configure GPIO pin : WDI_sp706_kanmemgou_Pin */
  1377. GPIO_InitStruct.Pin = WDI_sp706_kanmemgou_Pin;
  1378. if(WatchDogOn)//打开看门狗sp706
  1379. //if(1)//打开看门狗sp706
  1380. {
  1381. //
  1382. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1383. }
  1384. else
  1385. {
  1386. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1387. }
  1388. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1389. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1390. HAL_GPIO_Init(WDI_sp706_kanmemgou_GPIO_Port, &GPIO_InitStruct);
  1391. }
  1392. /* USER CODE BEGIN 4 */
  1393. /**
  1394. * @funNm : delay_sys_us
  1395. * @brief : 延时nus
  1396. * @param : nus:要延时的us数. 0~204522252(最大值即2^32/fac_us@fac_us=168)
  1397. * @retval: void
  1398. */
  1399. void delay_sys_us(uint32_t Delay)//1个delay,大概1.5us
  1400. {
  1401. uint32_t cnt = Delay * 8;
  1402. uint32_t i = 0;
  1403. for(i = 0; i < cnt; i++)__NOP();
  1404. }
  1405. /* USER CODE END 4 */
  1406. /* USER CODE BEGIN Header_StartDefaultTask */
  1407. /**
  1408. * @brief Function implementing the defaultTask thread.
  1409. * @param argument: Not used
  1410. * @retval None
  1411. */
  1412. /* USER CODE END Header_StartDefaultTask */
  1413. void StartDefaultTask(void *argument)
  1414. {
  1415. /* USER CODE BEGIN 5 */
  1416. /* Infinite loop */
  1417. for(;;)
  1418. {
  1419. osDelay(1);
  1420. }
  1421. /* USER CODE END 5 */
  1422. }
  1423. /* USER CODE BEGIN Header_StartTask02 */
  1424. /**
  1425. * @brief Function implementing the myTask02 thread.
  1426. * @param argument: Not used
  1427. * @retval None
  1428. */
  1429. uint8_t Flash_Change = 0; //定义接收数组
  1430. uni_float tprture001,tprture002,tprture003,Yewei001,tprtureAver;
  1431. /* USER CODE END Header_StartTask02 */
  1432. /*
  1433. //发送卸油阀传感器命令轮询
  1434. //发送角度传感器命令轮询
  1435. //发送壁挂油传感器命令轮询
  1436. //发送智能海底阀传感器命令轮询
  1437. //发送油气回收传感器命令轮询
  1438. */
  1439. void StartTask02(void *argument) //卸油阀总线传感器命令轮询 UART3
  1440. {
  1441. /* USER CODE BEGIN StartTask02 */
  1442. uint8_t i001=0,i002 = 0;
  1443. uint16_t ModbusCRC = 0,xyfaddr_max = 0,hdfaddr_max; //xyfaddr_max:卸油阀最高地址,根据每仓卸油阀之和计算得出
  1444. static uint16_t i = 0,j = 0,receive_error = 0;
  1445. HDF_Inf* phdf = hdf_inf;
  1446. KZQ_Inf* pkzq = &kzq_inf;
  1447. XYF_Inf* pxyf = xyf_inf;
  1448. Cang_Inf* pcang = &cang_inf;
  1449. Angle_Inf* pangle = &angle_inf;
  1450. Pressure_Inf* pPressure = pressure_inf;
  1451. uint8_t pressureaddr_max = 0;
  1452. xyfaddr_max=0;
  1453. hdfaddr_max=0;
  1454. for(i = 0;i < pcang->Cang_Num;i++)
  1455. {
  1456. xyfaddr_max += pcang->XYF_Num[i];
  1457. hdfaddr_max += pcang->HDF_Num[i];
  1458. pressureaddr_max += pcang->Pressure_Num[i];
  1459. }
  1460. i = 0;
  1461. extern uint8_t USART2_RX_BUF002[Uart2_BUF_SIZE];
  1462. extern uint8_t USART1_RX_BUF002[Uart2_BUF_SIZE];
  1463. extern uint8_t USART3_RX_BUF002[Uart2_BUF_SIZE];
  1464. extern int data_lengthU2,data_lengthU1,data_lengthU3;
  1465. extern int flagU1Rx,flagU2Rx,flagU3Rx;
  1466. extern uint8_t USART3_RX_BUF002_print[Uart3_BUF_SIZE];
  1467. extern uint8_t XYF_TxBuf[70];
  1468. extern uint16_t Uart_len_TouChuan;
  1469. /* Infinite loop */
  1470. for(;;)
  1471. {
  1472. osDelay(10); //以ms为单位
  1473. //HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0);
  1474. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  1475. // continue;
  1476. if(Flash_Change) //如果有对Flash进行改动,则重新计算xyfaddr_max
  1477. {
  1478. xyfaddr_max = 0;
  1479. hdfaddr_max = 0;
  1480. pressureaddr_max = 0;
  1481. for(i = 0;i < pcang->Cang_Num;i++)
  1482. {
  1483. xyfaddr_max += pcang->XYF_Num[i];
  1484. hdfaddr_max += pcang->HDF_Num[i];
  1485. pressureaddr_max += pcang->Pressure_Num[i];
  1486. }
  1487. Flash_Change = 0;
  1488. }
  1489. if(pkzq->USE_XYF == 0) //平台未控制卸油阀总线,正常轮询数据
  1490. {
  1491. if(i001==0) //发送卸油阀传感器命令轮询
  1492. {
  1493. //pcang->XYF_Type=2;
  1494. if ((pcang->XYF_INSTALL != 0) && (pcang->XYF_Type != 2))
  1495. {
  1496. ModbusCRC = LIB_CRC_MODBUS(CMD_XYF, 6);
  1497. CMD_XYF[6] = ModbusCRC >> 8;
  1498. CMD_XYF[7] = ModbusCRC & 0xff;
  1499. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_RESET); //
  1500. delay_sys_us(80);
  1501. HAL_UART_Transmit_IT(&huart3, CMD_XYF, 8);
  1502. while (huart3.gState == HAL_UART_STATE_BUSY_TX)
  1503. {
  1504. osDelay(1);
  1505. }
  1506. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_SET); //
  1507. pxyf[CMD_XYF[0] - 0x10].RTData_Num++; //每个传感器发送帧累加
  1508. if (CMD_XYF[0] - 0x10 < xyfaddr_max)
  1509. CMD_XYF[0]++;
  1510. else
  1511. CMD_XYF[0] = 0x11;
  1512. }
  1513. else
  1514. {
  1515. i001 = 3;
  1516. }
  1517. }
  1518. if (i001 == 3) //发送姿态传感器轮询
  1519. {
  1520. if (pcang->Angle) //发送角度传感器命令轮询
  1521. {
  1522. ModbusCRC = LIB_CRC_MODBUS(CMD_Angle_XY, 6);
  1523. CMD_Angle_XY[6] = ModbusCRC >> 8;
  1524. CMD_Angle_XY[7] = ModbusCRC & 0xff;
  1525. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_RESET);
  1526. delay_sys_us(80);
  1527. HAL_UART_Transmit(&huart3, CMD_Angle_XY, 8, 100); //只支持单指令读角度取传感器数据
  1528. delay_sys_us(80);
  1529. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_SET);
  1530. if (pangle->RTData_NumX > RT_ERRORCNT)
  1531. {
  1532. pangle->RTData_NumX = RT_ERRORCNT;
  1533. pangle->Angle_ErrorCnt = RT_ERRORCNT;
  1534. }
  1535. else
  1536. pangle->RTData_NumX++;
  1537. }
  1538. else
  1539. {
  1540. i001 = 6;
  1541. }
  1542. }
  1543. if(i001==6) //发送壁挂油传感器命令轮询
  1544. {
  1545. if(pcang->BGY_INSTALL)
  1546. {
  1547. ModbusCRC = LIB_CRC_MODBUS(CMD_Biguayou,6);
  1548. CMD_Biguayou[6] = ModbusCRC>>8;
  1549. CMD_Biguayou[7] = ModbusCRC&0xff;
  1550. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);
  1551. delay_sys_us(80);
  1552. HAL_UART_Transmit(&huart3,CMD_Biguayou,8,100); //只支持单指令读角度取传感器数据
  1553. delay_sys_us(80);
  1554. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);
  1555. }
  1556. else
  1557. {
  1558. i001=9;
  1559. }
  1560. }
  1561. if (i001 == 9) //发送智能海底阀传感器命令轮询
  1562. {
  1563. if (pcang->HDF_INSTALL != 0 && pcang->HDF_Type)
  1564. {
  1565. ModbusCRC = LIB_CRC_MODBUS(CMD_HDF, 14);
  1566. CMD_HDF[14] = ModbusCRC >> 8;
  1567. CMD_HDF[15] = ModbusCRC & 0xff;
  1568. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_RESET);
  1569. delay_sys_us(80);
  1570. HAL_UART_Transmit(&huart3, CMD_HDF, 16, 100); //只支持单指令读角度取传感器数据
  1571. delay_sys_us(80);
  1572. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_SET);
  1573. if (phdf[CMD_HDF[0] - 0x20].RTData_Num > 50) //收发数据错误次数RT_ERRORCNT
  1574. {
  1575. // phdf[CMD_HDF[0]-0x20].RTData_Num = RT_ERRORCNT;
  1576. // phdf[CMD_HDF[0]-0x20].HDF_ErrorCnt = RT_ERRORCNT;
  1577. }
  1578. else
  1579. phdf[CMD_HDF[0] - 0x20].RTData_Num++; //每个传感器发送帧累加
  1580. if (CMD_HDF[0] - 0x21 < hdfaddr_max)
  1581. CMD_HDF[0]++;
  1582. else
  1583. CMD_HDF[0] = 0x21;
  1584. }
  1585. else
  1586. {
  1587. i001 = 12;
  1588. }
  1589. }
  1590. if(i001==12) //发送油气回收传感器命令轮询
  1591. {
  1592. if(pcang->YQHS)
  1593. {
  1594. ModbusCRC = LIB_CRC_MODBUS(CMD_YQHS,6);
  1595. CMD_YQHS[6] = ModbusCRC>>8;
  1596. CMD_YQHS[7] = ModbusCRC&0xff;
  1597. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);
  1598. delay_sys_us(80);
  1599. HAL_UART_Transmit(&huart3,CMD_YQHS,8,100); //只支持单指令读角度取传感器数据
  1600. delay_sys_us(80);
  1601. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);
  1602. }
  1603. else
  1604. {
  1605. i001=15;
  1606. }
  1607. }
  1608. if(i001 == 15){
  1609. if(pcang->Pressure){
  1610. ModbusCRC = LIB_CRC_MODBUS(CMD_Pressure, 6);
  1611. CMD_Pressure[6] = ModbusCRC >> 8;
  1612. CMD_Pressure[7] = ModbusCRC & 0xff;
  1613. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_RESET);
  1614. delay_sys_us(80);
  1615. HAL_UART_Transmit(&huart3, CMD_Pressure, 8, 200); //只支持单指令读角度取传感器数据
  1616. delay_sys_us(80);
  1617. HAL_GPIO_WritePin(GPIOB, con02_uart3_xieyoufa_Pin, GPIO_PIN_SET);
  1618. pPressure[CMD_Pressure[0] - PRESSURE_STARTADDR].RTData_Num++; //每个传感器发送帧累加
  1619. if (CMD_Pressure[0] - PRESSURE_STARTADDR +1 < pressureaddr_max)
  1620. CMD_Pressure[0]++;
  1621. else
  1622. CMD_Pressure[0] = PRESSURE_STARTADDR;
  1623. }else{
  1624. i001=0;
  1625. continue;
  1626. }
  1627. }
  1628. }
  1629. else //平台通过卸油阀总线直接操作传感器
  1630. {
  1631. if(i002 == 3)
  1632. {
  1633. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);//
  1634. delay_sys_us(80);
  1635. #if 0
  1636. if((XYF_TxBuf[0] == 0x0D)&&(XYF_TxBuf[0] == 0x0A))
  1637. HAL_UART_Transmit(&huart3,XYF_TxBuf,12,100);
  1638. else
  1639. HAL_UART_Transmit(&huart3,XYF_TxBuf,8,100);
  1640. delay_sys_us(80);
  1641. #else
  1642. HAL_UART_Transmit_IT(&huart3,XYF_TxBuf,Uart_len_TouChuan);
  1643. while (huart3.gState == HAL_UART_STATE_BUSY_TX)
  1644. {
  1645. osDelay(1);
  1646. }
  1647. #endif
  1648. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET); //
  1649. }
  1650. else if(i002 == 0x06)
  1651. {
  1652. #if 0
  1653. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);//
  1654. delay_sys_us(80);
  1655. HAL_UART_Transmit(&huart3,ALL_TxBuf,16,100);
  1656. delay_sys_us(80);
  1657. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);//
  1658. }
  1659. else if(i002 == 0x09)//slm 0x0c
  1660. {
  1661. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_RESET);//
  1662. delay_sys_us(80);
  1663. HAL_UART_Transmit(&huart3,ALL_TxBuf,Uart_len_TouChuan,100);
  1664. delay_sys_us(80);
  1665. HAL_GPIO_WritePin(GPIOB,con02_uart3_xieyoufa_Pin,GPIO_PIN_SET);//
  1666. #endif
  1667. pkzq->USE_XYF = 0;
  1668. i002 = 0;
  1669. }
  1670. i002++;
  1671. if((flagU3Rx==1) && (i002 > 3))
  1672. {
  1673. pkzq->USE_XYF = 0;
  1674. i002 = 0;
  1675. continue;
  1676. }
  1677. }
  1678. //来自UART3的命令 电路板上标志位卸油阀
  1679. if(flagU3Rx==1)
  1680. {
  1681. flagU3Rx=0;
  1682. #if 0
  1683. if(USART3_RX_BUF002[0]!=0x11)
  1684. {
  1685. pxyf[1].XYF_ErrorCnt++;
  1686. if(pxyf[1].XYF_ErrorCnt>35)
  1687. {
  1688. pxyf[1].XYF_Error = 1;
  1689. }
  1690. }
  1691. if(USART3_RX_BUF002[0]!=0x12)
  1692. {
  1693. pxyf[2].XYF_ErrorCnt++;
  1694. if(pxyf[2].XYF_ErrorCnt>35)
  1695. {
  1696. pxyf[2].XYF_Error = 1;
  1697. }
  1698. }
  1699. #endif
  1700. if(USART3_RX_BUF002[0] >= 0x10 && USART3_RX_BUF002[0] <= 0x1F) //卸油阀数据
  1701. {
  1702. ModbusCRC = USART3_RX_BUF002[5]<<8;
  1703. ModbusCRC |= USART3_RX_BUF002[6];
  1704. //pxyf[USART3_RX_BUF002[0]-0x10].RTData_Num = 1;
  1705. if(USART3_RX_BUF002[1]!=0x03&&USART3_RX_BUF002[1]!=0x06) //校验读写属性
  1706. {
  1707. receive_error = 1;
  1708. }
  1709. else if(USART3_RX_BUF002[2] != 0x02) //校验数据长度
  1710. {
  1711. receive_error = 1;
  1712. }
  1713. else if(ModbusCRC != LIB_CRC_MODBUS(USART3_RX_BUF002,5)) //校验CRC
  1714. {
  1715. receive_error = 1;
  1716. }
  1717. if(receive_error == 0)
  1718. {
  1719. pxyf[USART3_RX_BUF002[0]-0x10].XYF_ErrorCnt = 0;
  1720. pxyf[USART3_RX_BUF002[0]-0x10].XYF_Error = 0;
  1721. if(USART3_RX_BUF002[1] == 0x03) //读取数据返回
  1722. {
  1723. #if 0
  1724. if(USART3_RX_BUF002[3]>0x01)//阀门开关状态
  1725. {
  1726. pxyf[i].XYF_ErrorCnt++;
  1727. }
  1728. else if(i < XYF_BUF_DEP)
  1729. {
  1730. i++;
  1731. }
  1732. if(i == XYF_BUF_DEP)
  1733. {
  1734. i = 0;
  1735. }
  1736. #else
  1737. pxyf[USART3_RX_BUF002[0] - 0x10].XYF_Data1[0] = USART3_RX_BUF002[3];
  1738. //pxyf[USART3_RX_BUF002[0] - 0x10].XYF_Data2[0] = USART3_RX_BUF002[4];
  1739. pxyf[USART3_RX_BUF002[0] - 0x10].XYF_Data2[0] = 0xFF; //泄尽状态,比IO 输入获取
  1740. #endif
  1741. XYF_state(USART3_RX_BUF002[0] - 0x10);
  1742. }
  1743. else if(USART3_RX_BUF002[1] == 0x06) //写入数据返回 判断写入是否成功
  1744. {
  1745. //清除控制器占用标志
  1746. //整理卸油阀协议后添加
  1747. }
  1748. i001=12;
  1749. //continue;
  1750. }
  1751. }
  1752. else if(USART3_RX_BUF002[0] >=0x70 && USART3_RX_BUF002[0] <= 0x7f) //姿态数据,目前最多支持3轴
  1753. {
  1754. ModbusCRC = USART3_RX_BUF002[7]<<8;
  1755. ModbusCRC |= USART3_RX_BUF002[8];
  1756. pangle->RTData_NumX = 1;
  1757. if(USART3_RX_BUF002[1]!=0x03&&USART3_RX_BUF002[1]!=0x06) //校验读写属性
  1758. {
  1759. receive_error = 1;
  1760. }
  1761. else if(USART3_RX_BUF002[2] >= 0x08) //校验数据长度
  1762. {
  1763. receive_error = 1;
  1764. }
  1765. else if(ModbusCRC != LIB_CRC_MODBUS(USART3_RX_BUF002,USART3_RX_BUF002[2]+3)) //校验CRC
  1766. {
  1767. //receive_error = 1;
  1768. }
  1769. if(receive_error == 0)
  1770. {
  1771. if(USART3_RX_BUF002[1] ==0x03)
  1772. {
  1773. if(j < ANGLE_BUF_DEP)
  1774. {
  1775. pangle->Angle_ErrorCnt = 0;
  1776. //if(USART3_RX_BUF002[2] == 0x02)
  1777. pangle->Angle_DataX[j] = USART3_RX_BUF002[3]<<8|USART3_RX_BUF002[4];
  1778. //if(USART3_RX_BUF002[2] > 0x02)
  1779. pangle->Angle_DataY[j] = USART3_RX_BUF002[5]<<8|USART3_RX_BUF002[6];
  1780. // if(USART3_RX_BUF002[2] > 0x04)
  1781. pangle->Angle_DataZ[j] = USART3_RX_BUF002[7]<<8|USART3_RX_BUF002[8];
  1782. j++;
  1783. }
  1784. if(j == ANGLE_BUF_DEP)
  1785. {
  1786. j = 0;
  1787. }
  1788. }
  1789. else
  1790. {
  1791. //整理卸油阀协议后添加
  1792. }
  1793. i001=6;
  1794. continue;
  1795. }
  1796. }
  1797. else if(USART3_RX_BUF002[0] >= 0x20 && USART3_RX_BUF002[0] <= 0x2F ) //智能海底阀数据
  1798. {
  1799. Get_ZN_hdf_data();
  1800. i001 = 12;
  1801. continue;
  1802. }
  1803. else if(USART3_RX_BUF002[0] == 0xe4) //油气回收数据
  1804. {
  1805. Get_Yqhuishou_data();
  1806. i001 = 15;
  1807. continue;
  1808. }
  1809. else if(USART3_RX_BUF002[0] >= 0x81 && USART3_RX_BUF002[0] <= 0x8F) //壁挂油数据
  1810. {
  1811. Get_Biguayou_data();
  1812. i001 = 9;
  1813. continue;
  1814. }else if(USART3_RX_BUF002[0] >= 0x91 && USART3_RX_BUF002[0] <= 0x9F)
  1815. {
  1816. if(0 == Prase_Pressure(USART3_RX_BUF002, 9)){
  1817. //i001 = 0;
  1818. //continue;
  1819. }
  1820. }
  1821. receive_error = 0;
  1822. }
  1823. else
  1824. {
  1825. if (i001 == 2)
  1826. {
  1827. if(CMD_XYF[0] == 0x11)
  1828. {
  1829. i = xyfaddr_max;
  1830. }
  1831. else
  1832. {
  1833. i = CMD_XYF[0] - 0x11;
  1834. }
  1835. pxyf[i].XYF_ErrorCnt++;
  1836. if (pxyf[i].XYF_ErrorCnt > pcang->sensorBusMaxReTry)
  1837. {
  1838. pxyf[i].XYF_ErrorCnt = pcang->sensorBusMaxReTry + 1;
  1839. pxyf[i].XYF_Error = 1;
  1840. }
  1841. }
  1842. }
  1843. if(i001< 18)
  1844. i001++;
  1845. else
  1846. i001 = 0;
  1847. osDelay(40);
  1848. }
  1849. /* USER CODE END StartTask02 */
  1850. }
  1851. /* USER CODE BEGIN Header_StartTask03 */
  1852. /**
  1853. * @brief Function implementing the myTask03 thread.
  1854. * @param argument: Not used
  1855. * @retval None
  1856. */
  1857. /* USER CODE END Header_StartTask03 */
  1858. /*
  1859. //发送华天三点式温度传感器命令轮询
  1860. //发送人控大盖盖命令轮询
  1861. //雷达液位传感器命令
  1862. //发送小盖传感器轮询
  1863. //发送磁致伸缩液位计命令轮询
  1864. ?
  1865. */
  1866. #include "rkg.h"
  1867. void StartTask03(void *argument) //人孔盖总线传感器 UART1
  1868. {
  1869. /* USER CODE BEGIN StartTask03 */
  1870. /* Infinite loop */
  1871. /* USER CODE BEGIN StartTask02 */
  1872. static uint8_t i001=0,i002 = 0,i003 = 0,receive_error = 0;
  1873. uint16_t rkgaddr_max = 0,temaddr_max = 0,leveladdr_max = 0,RKG_angle = 0;
  1874. static uint16_t i = 0,rkdg_cnt = 0,rkxg_cnt = 0,level_cnt = 0,tem_cnt = 0,temp_dot_cnt=0,temp_dot_dex=0,ModbusCRC = 0,ModbusCRC1 = 0;
  1875. uint16_t rx_len,head = 0;
  1876. S_ANGLEDATA* psATsk3 = gs_AngleData;
  1877. KZQ_Inf* pkzq = &kzq_inf;
  1878. RKG_Inf* prkg = rkg_inf;
  1879. Cang_Inf* pcang = &cang_inf;
  1880. Level_Inf* plevel = level_inf;
  1881. Tem_Inf* ptem = tem_inf;
  1882. typedef union{
  1883. float QDGH_data_temp; //青鸟贵和磁致伸缩液位温度一体传感器
  1884. uint8_t arr[4];
  1885. }Hex_to_float;
  1886. static Hex_to_float hex_to_float;
  1887. leveladdr_max=0;
  1888. if(pcang->Temperture==2)
  1889. pcang->Temperture=3;
  1890. for(i = 0;i < pcang->Cang_Num;i++)
  1891. {
  1892. rkgaddr_max += pcang->RKG_Num[i]; //人孔盖最大地址
  1893. leveladdr_max++;
  1894. temaddr_max++;
  1895. }
  1896. /*if(pcang->RKG_Type==0)
  1897. {
  1898. rkgaddr_max += 1;
  1899. }*/
  1900. i = 0;
  1901. extern uint8_t USART1_RX_BUF002[Uart2_BUF_SIZE];
  1902. extern int data_lengthU1;
  1903. extern int flagU1Rx;
  1904. extern uint8_t USART1_RX_BUF002_print[Uart1_BUF_SIZE];
  1905. /* Infinite loop */
  1906. for(;;)
  1907. {
  1908. osDelay(10); //以ms为单位
  1909. //HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0); //已经移至task12 500ms闪烁 邵磊明修改
  1910. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  1911. if(Flash_Change)
  1912. {
  1913. rkgaddr_max = 0;
  1914. leveladdr_max=0;
  1915. temaddr_max = 0;
  1916. if(pcang->Temperture==2)
  1917. pcang->Temperture=3;
  1918. for(i = 0;i < pcang->Cang_Num;i++)
  1919. {
  1920. rkgaddr_max += pcang->RKG_Num[i]; //人孔盖最大地址
  1921. leveladdr_max++;
  1922. temaddr_max++;
  1923. }
  1924. /*if(pcang->RKG_Type==0)
  1925. {
  1926. rkgaddr_max += 1;
  1927. }*/
  1928. Flash_Change = 0;
  1929. }
  1930. if(pkzq->USE_RKG == 0) //平台未控制卸油阀总线,正常轮询数据
  1931. {
  1932. if(i001==0) //发送人控大盖盖命令轮询
  1933. {
  1934. if((pcang->RKG_DG != 0) && (pcang->RKG_Type!=2))
  1935. {
  1936. if(pcang->RKG_Type == 0)
  1937. {
  1938. if(CMD_RKG[0] == 0x1)
  1939. {
  1940. if(i003 >= rkgaddr_max)
  1941. i003 = 0;
  1942. ++i003;
  1943. CMD_RKG[0] = 1+i003*2;
  1944. prkg[i003].RTData_Num++;
  1945. }
  1946. else
  1947. {
  1948. CMD_RKG[0] = 0x1;
  1949. prkg[0].RTData_Num++;
  1950. }
  1951. }
  1952. else
  1953. {
  1954. prkg[CMD_RKG[0] - 0x30].RTData_Num++;
  1955. if(CMD_RKG[0] - 0x30 < rkgaddr_max)
  1956. {
  1957. ++i003;
  1958. CMD_RKG[0]=0x30+i003;
  1959. }
  1960. else
  1961. {
  1962. CMD_RKG[0] = 0x31;
  1963. i003 = 1;
  1964. }
  1965. }
  1966. ModbusCRC = LIB_CRC_MODBUS(CMD_RKG,6);
  1967. CMD_RKG[6] = ModbusCRC>>8;
  1968. CMD_RKG[7] = ModbusCRC&0xff;
  1969. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  1970. delay_sys_us(80);
  1971. //if(pcang->RKG_Type == 0x01)
  1972. // HAL_UART_Transmit(&huart1,Data_Head,2,10);
  1973. {
  1974. HAL_UART_Transmit_IT(&huart1,CMD_RKG,8);
  1975. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  1976. {
  1977. osDelay(1);
  1978. }
  1979. } //HAL_UART_Transmit(&huart1,CMD_RKG,8,100);
  1980. //if(pcang->RKG_Type == 0x01)
  1981. // HAL_UART_Transmit(&huart1,Data_Head,2,10);
  1982. //delay_sys_us(80);
  1983. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  1984. #if 0
  1985. if(prkg[CMD_RKG[0] - 0x30].RTData_Num > RT_ERRORCNT) //每个传感器每发送一帧 基准角度为0x30
  1986. {
  1987. prkg[CMD_RKG[0] - 0x30].RTData_Num = RT_ERRORCNT;
  1988. prkg[CMD_RKG[0] - 0x30].RKDG_ErrorCnt = RT_ERRORCNT;
  1989. }
  1990. else
  1991. #endif
  1992. }
  1993. else
  1994. i001 = 3;
  1995. }
  1996. if(i001==3) //发送小盖传感器轮询
  1997. {
  1998. if(pcang->RKG_XG == 0x01)
  1999. {
  2000. ModbusCRC = LIB_CRC_MODBUS(CMD_RKG_XG,6);
  2001. CMD_RKG_XG[6] = ModbusCRC>>8;
  2002. CMD_RKG_XG[7] = ModbusCRC&0xff;
  2003. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2004. delay_sys_us(80);
  2005. if(pcang->RKG_Type == 0x01)
  2006. HAL_UART_Transmit(&huart1,Data_Head,2,10);
  2007. HAL_UART_Transmit(&huart1,CMD_RKG_XG,8,100);
  2008. if(pcang->RKG_Type == 0x01)
  2009. HAL_UART_Transmit(&huart1,Data_Head,2,10);
  2010. delay_sys_us(80);
  2011. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2012. if(prkg[CMD_RKG_XG[0]-0x40].RTData_Num > RT_ERRORCNT)
  2013. {
  2014. prkg[CMD_RKG_XG[0]-0x40].RTData_Num = RT_ERRORCNT;
  2015. prkg[CMD_RKG_XG[0]-0x40].RKXG_ErrorCnt = RT_ERRORCNT;
  2016. }
  2017. else
  2018. prkg[CMD_RKG_XG[0]-0x40].RTData_Num++; //每个传感器发送帧累加
  2019. if(CMD_RKG_XG[0] - 0x41 < rkgaddr_max -1)
  2020. CMD_RKG_XG[0]++;
  2021. else
  2022. CMD_RKG_XG[0] = 0x41;
  2023. }
  2024. else
  2025. i001 = 6;
  2026. }
  2027. if(i001==6) //发送磁致伸缩液位计命令轮询 邵磊明增加
  2028. {
  2029. if(pcang->Level == LEVEL_CZSS) //磁致伸缩传感器轮询 邵磊明增加
  2030. {
  2031. ModbusCRC = LIB_CRC_MODBUS(CMD_GetTempAndYewei,6);
  2032. CMD_GetTempAndYewei[6] = ModbusCRC>>8;
  2033. CMD_GetTempAndYewei[7] = ModbusCRC&0xff;
  2034. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2035. delay_sys_us(80);
  2036. //HAL_UART_Transmit(&huart1,CMD_GetTempAndYewei,8,100);
  2037. //delay_sys_us(80);
  2038. HAL_UART_Transmit_IT(&huart1,CMD_GetTempAndYewei,8);
  2039. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2040. {
  2041. osDelay(1);
  2042. }
  2043. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2044. /*if(plevel[CMD_GetTempAndYewei[0]-0x50].RTData_Num > RT_ERRORCNT)
  2045. {
  2046. plevel[CMD_GetTempAndYewei[0]-0x50].RTData_Num = RT_ERRORCNT;
  2047. plevel[CMD_GetTempAndYewei[0]-0x50].Level_ErrorCnt = RT_ERRORCNT;
  2048. }
  2049. else*/
  2050. plevel[CMD_GetTempAndYewei[0]-0x50].RTData_Num++; //每个传感器发送帧累加 基准角度为0x30
  2051. if(CMD_GetTempAndYewei[0]-0x50 < leveladdr_max)
  2052. CMD_GetTempAndYewei[0]++;
  2053. else
  2054. CMD_GetTempAndYewei[0] = 0x51;
  2055. }
  2056. else if(pcang->Level == LEVEL_LDYW) //雷达液位传感器命令轮询 20210818邵增加
  2057. {
  2058. ModbusCRC = LIB_CRC_MODBUS(CMD_LDYW,6);
  2059. CMD_LDYW[6] = ModbusCRC>>8;
  2060. CMD_LDYW[7] = ModbusCRC&0xff;
  2061. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2062. delay_sys_us(80);
  2063. //HAL_UART_Transmit(&huart1,CMD_LDYW,8,100);
  2064. //delay_sys_us(80);
  2065. HAL_UART_Transmit_IT(&huart1, CMD_LDYW, 8);
  2066. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2067. {
  2068. osDelay(1);
  2069. }
  2070. HAL_GPIO_WritePin(GPIOB, Con01_uart1_rankonggai_Pin, GPIO_PIN_SET); //
  2071. /*if (prkg[CMD_RKG[0] - 0x50].RTData_Num > RT_ERRORCNT) //每个传感器每发送一帧 基准角度为0x30
  2072. {
  2073. plevel[CMD_RKG[0] - 0x50].RTData_Num = RT_ERRORCNT;
  2074. plevel[CMD_RKG[0] - 0x50].Level_ErrorCnt = RT_ERRORCNT;
  2075. }
  2076. else*/
  2077. plevel[CMD_LDYW[0] - LEVEL_STARTADDR].RTData_Num++;
  2078. if ((CMD_LDYW[0] - LEVEL_STARTADDR+1) < leveladdr_max)
  2079. CMD_LDYW[0]++;
  2080. else
  2081. CMD_LDYW[0] = LEVEL_STARTADDR;
  2082. }
  2083. else
  2084. i001=9;
  2085. }
  2086. if(i001==9) //发送华天三点式温度传感器命令轮询 邵磊明增加
  2087. {
  2088. if(Tem_FST100_611 == pcang->Temperture )
  2089. {
  2090. // taskENTER_CRITICAL();
  2091. ModbusCRC = LIB_CRC_MODBUS(CMD_TemAng,6);
  2092. CMD_TemAng[6] = ModbusCRC>>8;
  2093. CMD_TemAng[7] = ModbusCRC&0xff;
  2094. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2095. delay_sys_us(80);
  2096. HAL_UART_Transmit_IT(&huart1,CMD_TemAng,8);
  2097. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2098. {
  2099. osDelay(1);
  2100. }
  2101. //HAL_UART_Transmit(&huart1,CMD_GetTempHuaTian,8,100);
  2102. //delay_sys_us(80);
  2103. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2104. // taskEXIT_CRITICAL();
  2105. ptem[CMD_TemAng[0] - TEM_STARTADDR].RTData_Num++;
  2106. ptem[CMD_TemAng[0] - TEM_STARTADDR+1].RTData_Num++;
  2107. if((CMD_TemAng[0] - TEM_STARTADDR+1)*2 < temaddr_max)
  2108. CMD_TemAng[0] = CMD_TemAng[0]+1;
  2109. else
  2110. CMD_TemAng[0] = TEM_STARTADDR;
  2111. }
  2112. else
  2113. {
  2114. i001=0x0;
  2115. continue;
  2116. }
  2117. }
  2118. }
  2119. else //平台通过卸油阀总线直接操作传感器
  2120. {
  2121. if(i002 == 3)
  2122. {
  2123. extern uint16_t Uart_len_TouChuan;
  2124. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_RESET);//
  2125. delay_sys_us(80);
  2126. #if 0
  2127. if((RKG_TxBuf[0] == 0x0D)&&(RKG_TxBuf[1] == 0x0A))
  2128. HAL_UART_Transmit(&huart1,RKG_TxBuf,12,100);
  2129. else
  2130. HAL_UART_Transmit(&huart1,RKG_TxBuf,8,100);
  2131. delay_sys_us(80);
  2132. #else
  2133. HAL_UART_Transmit_IT(&huart1,RKG_TxBuf,Uart_len_TouChuan);
  2134. while (huart1.gState == HAL_UART_STATE_BUSY_TX)
  2135. {
  2136. osDelay(1);
  2137. }
  2138. #endif
  2139. HAL_GPIO_WritePin(GPIOB,Con01_uart1_rankonggai_Pin,GPIO_PIN_SET);//
  2140. flagU1Rx=0;
  2141. }
  2142. i002++;
  2143. if(((flagU1Rx==1) && (i002 > 3)) || i002>10)
  2144. {
  2145. pkzq->USE_RKG = 0;
  2146. i002 = 0;
  2147. continue;
  2148. }
  2149. }
  2150. //来自UART1,即人孔盖总线的命令 电路板上标志位人孔盖
  2151. if(flagU1Rx==1)
  2152. {
  2153. flagU1Rx = 0;
  2154. receive_error = 0;
  2155. rx_len = USART1_RX_BUF002[2];
  2156. ModbusCRC = USART1_RX_BUF002[(3+rx_len)]<<8;
  2157. ModbusCRC |= USART1_RX_BUF002[(3+rx_len+1)];
  2158. if((USART1_RX_BUF002[head+0] >= 0x30 && USART1_RX_BUF002[head+0] <= 0x3F) || (USART1_RX_BUF002[head+0] >= 0x1 && USART1_RX_BUF002[head+0] <= 0x10)) //人孔大盖数据 地址0x30为基准传感器
  2159. {
  2160. if(USART1_RX_BUF002[head+1]!=0x03&&USART1_RX_BUF002[head+1]!=0x06) //校验读写属性
  2161. {
  2162. receive_error = 1;
  2163. }
  2164. else if(USART1_RX_BUF002[head+2] != 0x04) //校验数据长度
  2165. {
  2166. receive_error = 1;
  2167. }
  2168. else if(ModbusCRC != LIB_CRC_MODBUS(USART1_RX_BUF002,7)) //校验CRC
  2169. {
  2170. receive_error = 1;
  2171. }
  2172. // if((pcang->RKG_Type == 0)&&(USART1_RX_BUF002[head]>=0x30)&&(USART1_RX_BUF002[head] <=0x4F))
  2173. RKG_angle = (USART1_RX_BUF002[head+4]<<8)|USART1_RX_BUF002[head+3];
  2174. // else
  2175. // RKG_angle = (USART1_RX_BUF002[head+3]<<8)|USART1_RX_BUF002[head+4];
  2176. if((USART1_RX_BUF002[head+1] == 0x03)&&(receive_error == 0)) //读取数据返回
  2177. {//童赟 磁电编码 磁编码 人孔盖
  2178. if(USART1_RX_BUF002[head]==1)
  2179. {
  2180. prkg[0].RKDG_ErrorCnt = 0;
  2181. prkg[0].RKDG_Error=0;
  2182. }
  2183. else
  2184. {
  2185. prkg[i003].RKDG_ErrorCnt = 0;
  2186. prkg[i003].RKDG_Error=0;
  2187. }
  2188. if(USART1_RX_BUF002[head]==1)
  2189. {
  2190. AGL_AddNewData(RKG_angle,0);
  2191. }
  2192. else
  2193. {
  2194. AGL_AddNewData(RKG_angle,i003);
  2195. }
  2196. #if 0
  2197. //邵磊明修改 20211027 从rkg.c剪切到此处
  2198. if(psATsk3[i003].uiDG < 0 ||psATsk3[USART1_RX_BUF002[head]-0x30].uiDG >= 27000)//角度
  2199. {
  2200. prkg[USART1_RX_BUF002[head]-0x30].RKDG_ErrorCnt++;
  2201. }
  2202. #endif
  2203. // if( - psATsk3[USART1_RX_BUF002[head]-0x30].uiDG > prkg->RKG_Threshold || psATsk3[USART1_RX_BUF002[head]-0x30].uiDG > prkg->RKG_Threshold)
  2204. // prkg[USART1_RX_BUF002[head]-0x30].RKDG_StateCnt++;
  2205. // else
  2206. // prkg[USART1_RX_BUF002[head]-0x30].RKDG_StateCnt = 0;
  2207. if(pcang->RKG_Type == 0)
  2208. {
  2209. AGL_CalcDeltaAll(USART1_RX_BUF002[head],0);
  2210. }
  2211. #if 0 //倾角大盖计算
  2212. if(rkdg_cnt < RKG_BUF_DEP)
  2213. {
  2214. if(USART1_RX_BUF002[head] == 0x30)
  2215. {
  2216. prkg[USART1_RX_BUF002[head] - 0x30].RKG_JZData[rkdg_cnt] = RKG_angle;
  2217. }
  2218. else
  2219. {
  2220. prkg[USART1_RX_BUF002[head] - 0x30].RKG_DGData[rkdg_cnt] = RKG_angle;
  2221. rkdg_cnt++;
  2222. }
  2223. }
  2224. if(rkdg_cnt == RKG_BUF_DEP)
  2225. {
  2226. rkdg_cnt = 0;
  2227. }
  2228. #endif
  2229. //李伟修改 20211027 从rkg.c剪切到此处;开始
  2230. if (USART1_RX_BUF002[head] != 1)
  2231. {
  2232. if (psATsk3[i003].uiDG >= 0 || psATsk3[i003].uiDG <= 27000) //角度
  2233. {
  2234. if (-psATsk3[i003].uiDG > prkg->RKG_Threshold || psATsk3[i003].uiDG > prkg->RKG_Threshold)
  2235. prkg[i003].RKDG_StateCnt++;
  2236. else
  2237. prkg[i003].RKDG_StateCnt = 0;
  2238. if (prkg[i003].RKDG_StateCnt >= prkg[i003].RKG_StateKeepNum)
  2239. {
  2240. // RisingEdge++;
  2241. prkg[i003].RKDG_StateCnt = prkg[i003].RKG_StateKeepNum;
  2242. prkg[i003].RKDG_State = 1;
  2243. }
  2244. else
  2245. {
  2246. prkg[i003].RKDG_State = 0;
  2247. }
  2248. }
  2249. }
  2250. //李伟修改 20211027 从rkg.c剪切到此处;开始
  2251. i001 = 3;
  2252. continue;
  2253. }
  2254. }
  2255. else if(USART1_RX_BUF002[head+0] >= 0x40 && USART1_RX_BUF002[head+0] <= 0x4F) //人孔小盖数据 地址0x30为基准传感器
  2256. {
  2257. prkg[USART1_RX_BUF002[head] - 0x30].RKXG_ErrorCnt = 0;
  2258. prkg[USART1_RX_BUF002[head+0]-0x40].RTData_Num = 1;
  2259. if(USART1_RX_BUF002[head+1]!=0x03&&USART1_RX_BUF002[head+1]!=0x06) //校验读写属性
  2260. {
  2261. receive_error = 1;
  2262. }
  2263. else if(USART1_RX_BUF002[head+2] != 0x04) //校验数据长度
  2264. {
  2265. receive_error = 1;
  2266. }
  2267. else if(ModbusCRC != LIB_CRC_MODBUS(USART1_RX_BUF002,7)) //校验CRC
  2268. {
  2269. receive_error = 1;
  2270. }
  2271. if((USART1_RX_BUF002[head+1] == 0x03)&&(receive_error == 0)) //读取数据返回
  2272. {
  2273. AGL_AddNewData((USART1_RX_BUF002[head+3]<<8)|USART1_RX_BUF002[head+4],USART1_RX_BUF002[head]);
  2274. if(rkxg_cnt < RKG_BUF_DEP)
  2275. {
  2276. prkg[USART1_RX_BUF002[head] - 0x40].RKG_XGData[rkxg_cnt] = USART1_RX_BUF002[head+4]<<8;
  2277. prkg[USART1_RX_BUF002[head] - 0x40].RKG_XGData[rkxg_cnt] |= USART1_RX_BUF002[head+3];
  2278. rkxg_cnt++;
  2279. }
  2280. if(rkxg_cnt == RKG_BUF_DEP)
  2281. {
  2282. rkxg_cnt = 0;
  2283. }
  2284. }
  2285. else if((USART1_RX_BUF002[head+1] == 0x06)&&(receive_error == 0)) //写入数据返回
  2286. {
  2287. }
  2288. i001 = 6;
  2289. continue;
  2290. }
  2291. else if(USART1_RX_BUF002[0] >= 0x50 && USART1_RX_BUF002[0] <= 0x5F) //液位计数据 邵磊明增加
  2292. {
  2293. Prase_Level(USART1_RX_BUF002, pcang->Level);
  2294. i001 = 9;
  2295. continue;
  2296. }
  2297. else if(USART1_RX_BUF002[0] >=0x60 && USART1_RX_BUF002[0] <= 0x6f) //华天三点式温度传感器接收数据 邵磊明增加
  2298. {
  2299. Parse_Tem(USART1_RX_BUF002, pcang->Temperture);
  2300. i001 = 0;
  2301. continue;
  2302. }
  2303. else if(0) //暂未使用
  2304. {
  2305. }
  2306. else if(0) //暂未使用
  2307. {
  2308. }
  2309. }
  2310. else
  2311. {
  2312. if (i001 == 2)
  2313. {
  2314. if(pcang->RKG_Type == 0)
  2315. {
  2316. if(CMD_RKG[0] == 0x1)
  2317. {
  2318. i = 0;
  2319. }
  2320. else
  2321. {
  2322. i = i003;
  2323. }
  2324. }
  2325. else
  2326. {
  2327. i = i003;
  2328. }
  2329. prkg[i].RKDG_ErrorCnt++;
  2330. if (prkg[i].RKDG_ErrorCnt > pcang->sensorBusMaxReTry)
  2331. {
  2332. prkg[i].RKDG_ErrorCnt = pcang->sensorBusMaxReTry + 1;
  2333. prkg[i].RKDG_Error = 1;
  2334. }
  2335. }
  2336. if (i001 == 8) //液位错误
  2337. {
  2338. Level_Error(CMD_LDYW[0]);
  2339. }else if(i001 == 11){
  2340. Tem_Error(CMD_TemAng[0]);
  2341. }
  2342. }
  2343. if(i001<0x0c)
  2344. i001++;
  2345. else
  2346. i001 = 0;
  2347. osDelay(40);
  2348. }
  2349. /* USER CODE END StartTask03 */
  2350. }
  2351. /* USER CODE BEGIN Header_StartTask04 */
  2352. /**
  2353. * @brief Function implementing the myTask04 thread.
  2354. * @param argument: Not used
  2355. * @retval None
  2356. */
  2357. #include "Data_deal.h"
  2358. uint8_t USART2_RX_BUF003[128];
  2359. uint8_t F_STATE[70] = {0};
  2360. uint8_t ptxCang01Temp[150];
  2361. uint32_t KZQ_RTerror = 0;
  2362. /* USER CODE END Header_StartTask04 */
  2363. void StartTask04(void *argument) //控制器数据处理 uart2
  2364. {
  2365. /* USER CODE BEGIN StartTask04 */
  2366. /* Infinite loop */
  2367. uint8_t* ptx = CMD_KZQ;
  2368. uint16_t ModbusCRC_lsb = 0,ModbusCRC = 0,SetSuccess = 0,ModbusCRC1 = 0,SetSuccess1 = 0,SetSuccess2=0,SetSuccess3=0;
  2369. static uint16_t i = 0;
  2370. int i000;
  2371. uint8_t* send_ptr;
  2372. uint16_t send_len;
  2373. uint32_t tmpU32;
  2374. KZQ_Inf* pkzq = &kzq_inf;
  2375. extern uint8_t USART2_RX_BUF002[Uart2_BUF_SIZE];
  2376. extern int data_lengthU2;
  2377. extern int flagU2Rx;
  2378. extern uint8_t USART2_RX_BUF002_print[Uart2_BUF_SIZE];
  2379. //延时1S 启动
  2380. osDelay(1000);
  2381. /* Infinite loop */
  2382. for(;;)
  2383. {
  2384. osDelay(2); //以ms为单位
  2385. // HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0);
  2386. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  2387. if (flagU2Rx == 1)
  2388. {
  2389. flagU2Rx = 0;
  2390. if ((rx1_len > 300) || ((USART2_RX_BUF002[0] == 0xa5) && (USART2_RX_BUF002[1] == 0x5a)))
  2391. {
  2392. tmpU32 = (USART2_RX_BUF002[0] << 24) | (USART2_RX_BUF002[1] << 16) | (USART2_RX_BUF002[2] << 8) | (USART2_RX_BUF002[3]);
  2393. if (StartBytes_IAP == tmpU32)
  2394. {
  2395. Process_CMD_IAP_Update();
  2396. continue;
  2397. }
  2398. }
  2399. // KZQ_RTerror = 0;
  2400. // ASC转换为16进制,收到数据为:3901开头的数据总长度131字节
  2401. if ((USART2_RX_BUF002[0] == 0x3A) && (USART2_RX_BUF002[1] == 0x33) && (USART2_RX_BUF002[2] == 0x39) && (USART2_RX_BUF002[3] == 0x30)) //判断帧头
  2402. {
  2403. if (data_lengthU2 != 131)
  2404. {
  2405. ++KZQ_RTerror;
  2406. continue;
  2407. }
  2408. for (i000 = 0; i000 < (data_lengthU2 - 3) / 2; i000++)
  2409. {
  2410. T2C_RemoteCaliDat001.PayLoadData[i000] = MODBUS_ASCII_AsciiToHex(USART2_RX_BUF002 + 1 + 0 + i000 * 2);
  2411. USART2_RX_BUF003[i000] = MODBUS_ASCII_AsciiToHex(USART2_RX_BUF002 + 1 + 0 + i000 * 2);
  2412. }
  2413. //解析后的数据拷贝过来
  2414. memcpy(USART2_RX_BUF002, USART2_RX_BUF003, (data_lengthU2 - 3) / 2);
  2415. data_lengthU2 = (data_lengthU2 - 3) / 2;
  2416. }
  2417. if (data_lengthU2 < 5)
  2418. continue;
  2419. ModbusCRC = USART2_RX_BUF002[data_lengthU2 - 1] << 8;
  2420. ModbusCRC |= USART2_RX_BUF002[data_lengthU2 - 2];
  2421. ModbusCRC_lsb = USART2_RX_BUF002[data_lengthU2 - 2] << 8;
  2422. ModbusCRC_lsb |= USART2_RX_BUF002[data_lengthU2 - 1];
  2423. ModbusCRC1 = LIB_CRC_MODBUS(USART2_RX_BUF002, data_lengthU2 - 2);
  2424. if ((USART2_RX_BUF002[0] != 0x39) && (USART2_RX_BUF002[1] <= 0x01) && (USART2_RX_BUF002[2] <= 0x95) && (USART2_RX_BUF002[3] <= 0x50)) //判断帧头
  2425. {
  2426. pkzq->KZQ_Error++;
  2427. KZQ_RTerror = 1;
  2428. }
  2429. else if (USART2_RX_BUF002[5] != 0x01) //校验地址
  2430. {
  2431. pkzq->KZQ_Error++;
  2432. KZQ_RTerror = 1;
  2433. }
  2434. else if ((USART2_RX_BUF002[7] != 0x03) && (USART2_RX_BUF002[7] != 0x06)) //校验数据长度
  2435. {
  2436. pkzq->KZQ_Error++;
  2437. KZQ_RTerror = 1;
  2438. }
  2439. /*else if(ModbusCRC != ModbusCRC1 && ModbusCRC_lsb != ModbusCRC1) //校验CRC
  2440. {
  2441. pkzq->KZQ_Error++;
  2442. KZQ_RTerror = 1;
  2443. }*/
  2444. else
  2445. {
  2446. pkzq->KZQ_Error = 0;
  2447. KZQ_RTerror = 0;
  2448. for (i = 0; i < 64; i++)
  2449. pkzq->data_buf[i] = USART2_RX_BUF002[i];
  2450. for(i = 0;i < 16;i++)
  2451. ptx[i] = USART2_RX_BUF002[i];
  2452. }
  2453. if(KZQ_RTerror == 0)
  2454. {
  2455. send_len=0;
  2456. pkzq->sensor_reg = USART2_RX_BUF002[8];
  2457. pkzq->sensor_reg = pkzq->sensor_reg<<8;
  2458. pkzq->sensor_reg |= USART2_RX_BUF002[9];
  2459. switch(pkzq->sensor_reg)
  2460. {
  2461. case 0x10:
  2462. RstCPU(); //复位
  2463. break;
  2464. case 0x13:
  2465. Sen_CangState_old(F_STATE); //老协议 传输阀门状态
  2466. send_ptr = F_STATE;
  2467. send_len = 62;
  2468. break;
  2469. case 0x20:
  2470. SetSuccess = Read_CangState(ptx); //读取仓状态
  2471. break;
  2472. case 0x27:
  2473. SetSuccess = Read_CangSensorData(ptx); //读取仓传感器
  2474. break;
  2475. case 0x40:
  2476. SetSuccess = Angle_SetZero(ptx); //姿态传感器置零
  2477. for(i = 0;i < 64;i++)
  2478. ptx[i] = USART2_RX_BUF002[i];
  2479. break;
  2480. case 0x50:
  2481. SetSuccess = XYF_SetOFF(ptx); //远程卸油阀标定关 slm
  2482. for(i = 0;i < 64;i++)
  2483. ptx[i] = USART2_RX_BUF002[i];
  2484. break;
  2485. case 0x51:
  2486. SetSuccess = XYF_SetThreshold(ptx); //设置卸油阀传感器开关门限
  2487. break;
  2488. case 0x52:
  2489. SetSuccess = RKG_SetZero(ptx); //人孔盖传感器置零
  2490. for(i = 0;i < 64;i++)
  2491. ptx[i] = USART2_RX_BUF002[i];
  2492. break;
  2493. case 0x55:
  2494. SetSuccess = Read_Sensor(ptx); // 远程读取传感器数据 slm
  2495. break;
  2496. case 0x70:
  2497. break;
  2498. case 0x71:
  2499. SetSuccess = BGY_SetThreshold(ptx); //设置壁挂油门限
  2500. break;
  2501. case 0x72:
  2502. SetSuccess = RKG_SetThreshold(ptx); //设置人孔盖开关门限
  2503. break;
  2504. case 0x73:
  2505. SetSuccess = Sensor_SetJudgefNum(ptx); //设置开关判断次数
  2506. break;
  2507. case 0x74:
  2508. SetSuccess = CJQ_SetConfig(ptx); //设置采集器参数
  2509. Flash_Change = 1;
  2510. break;
  2511. case 0x75:
  2512. SetSuccess = RKG_SetTypeNum(ptx); //设置人孔盖种类、数量
  2513. Flash_Change = 1;
  2514. break;
  2515. case 0x76:
  2516. SetSuccess = XYF_SetTypeNum(ptx); //设置卸油阀种类、数量
  2517. Flash_Change = 1;
  2518. break;
  2519. case 0x77:
  2520. SetSuccess = HDF_SetTypeNum(ptx); //设置海底阀种类、数量
  2521. Flash_Change = 1;
  2522. break;
  2523. case 0x78:
  2524. SetSuccess = Level_SetType(ptx); //设置液位计种类
  2525. Flash_Change = 1;
  2526. break;
  2527. case 0x79:
  2528. SetSuccess = Angle_SetType(ptx); //设置姿态传感器种类
  2529. Flash_Change = 1;
  2530. break;
  2531. case 0x7a:
  2532. SetSuccess = Tem_SetType(ptx); //设置温度传感器种类
  2533. // Flash_Change = 1;
  2534. break;
  2535. case 0x7b:
  2536. HDF_Set_CloseVal(ptx); //设置智能海底阀放大倍数
  2537. Flash_Change = 1;
  2538. break;
  2539. case 0x7c:
  2540. HDF_Set_Threshold(ptx); //设置智能海底阀放大倍数
  2541. Flash_Change = 1;
  2542. break;
  2543. case 0x7d:
  2544. HDF_Set_Gain(ptx); //设置智能海底阀放大倍数
  2545. Flash_Change = 1;
  2546. break;
  2547. case 0x7e: HDF_Reset(ptx); //设置智能海底阀放大倍数
  2548. Flash_Change = 1;
  2549. break;
  2550. case 0x80:
  2551. SetSuccess = RW_SensorBusMaxRetry(ptx); //传感器总线重试最大值来获取异常
  2552. break;
  2553. case 0x81:
  2554. SetSuccess = RW_PinIoHitSameParam(ptx); //
  2555. break;
  2556. case 0x017e:
  2557. TOUCHUAN_UART_NUM(ptx); //设置智能海底阀放大倍数
  2558. Flash_Change = 1;
  2559. break;
  2560. //case 0x0180:
  2561. // SetSuccess = GRB_SET_Table(ptx); //罐容表配置 邵磊明增加
  2562. // Flash_Change = 1;
  2563. // break;
  2564. case 0x0190:
  2565. SetSuccess = Level_SetCalvalue(ptx); //设置液位计零点 邵磊明增加
  2566. Flash_Change = 1;
  2567. case 0x0121:
  2568. //SetSuccess = Level_SetCalvalue(ptx); //设置液位计种类
  2569. // Flash_Change = 1;
  2570. break;
  2571. case 0x0122:
  2572. //SetSuccess = Level_SetCalvalue(ptx); //设置液位计种类
  2573. // Flash_Change = 1;
  2574. break;
  2575. case 0x0220:
  2576. SetSuccess=Read_SoftVersion(ptx);
  2577. break;
  2578. case 0x1121:
  2579. SetSuccess1 = Read_CangSensorData_1to4(ptx); //读仓1-4传感器
  2580. if(SetSuccess1)
  2581. {
  2582. SetSuccess1=0;
  2583. ptx[232] = 0x00;
  2584. ptx[233] = 0x00;
  2585. send_ptr = ptx;
  2586. send_len = 234;
  2587. }
  2588. break;
  2589. #if 0
  2590. #else
  2591. case 0x1193:
  2592. case 0x1194:
  2593. case 0x1195:
  2594. case 0x1196:
  2595. case 0x1197:
  2596. case 0x1198:
  2597. case 0x1199:
  2598. case 0x119a:
  2599. SetSuccess2 = Read_CangSensorData_V2(ptx, (uint8_t)(pkzq->sensor_reg-0x1193+1));
  2600. if(SetSuccess2){
  2601. send_ptr = ptx;
  2602. send_len = 148;
  2603. SetSuccess2 = 0;
  2604. }
  2605. break;
  2606. #endif
  2607. case 0x119b:
  2608. SetSuccess3 = Read_ZhencheSensorData1(ptx); //读仓1-4传感器
  2609. if(SetSuccess3)
  2610. {
  2611. SetSuccess3=0;
  2612. send_ptr = ptx;
  2613. send_len = 96;
  2614. }
  2615. break;
  2616. case 0x1130:
  2617. Read_SensorData_New(ptx, &send_len);
  2618. send_ptr = ptx;
  2619. break;
  2620. default:
  2621. break;
  2622. }
  2623. //send_len=0;
  2624. if(0 == send_len){
  2625. if(SetSuccess){
  2626. ptx[60] = 0x00;
  2627. ptx[61] = 0x00;
  2628. }else{
  2629. ptx[60] = 0xFF;
  2630. ptx[61] = 0xFF;
  2631. }
  2632. send_ptr = ptx;
  2633. send_len = 62;
  2634. }
  2635. SetSuccess = 0;
  2636. if(send_len)
  2637. {
  2638. ModbusCRC = LIB_CRC_MODBUS(send_ptr,send_len);
  2639. send_ptr[send_len] = ModbusCRC>>8;
  2640. send_ptr[send_len+1] = ModbusCRC&0xff;
  2641. HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_RESET);//
  2642. delay_sys_us(80);
  2643. HAL_UART_Transmit_IT(&huart2,send_ptr,send_len+2);
  2644. while (huart2.gState == HAL_UART_STATE_BUSY_TX)
  2645. {
  2646. osDelay(1);
  2647. }
  2648. delay_sys_us(80);
  2649. HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);//
  2650. }
  2651. }
  2652. flagU2Rx = 0;
  2653. }
  2654. }
  2655. /* USER CODE END StartTask04 */
  2656. }
  2657. /* USER CODE BEGIN Header_StartTask05 */
  2658. /**
  2659. * @brief Function implementing the myTask05 thread.
  2660. * @param argument: Not used
  2661. * @retval None
  2662. */
  2663. /* USER CODE END Header_StartTask05 */
  2664. //#include"level.h"
  2665. void StartTask05(void *argument)
  2666. {
  2667. /* USER CODE BEGIN StartTask05 */
  2668. /* Infinite loop */
  2669. Level_Inf *plevel = level_inf;
  2670. Cang_Inf *pcang = &cang_inf;
  2671. uint8_t i;
  2672. //float v000;
  2673. //uint16_t *VolArrayTsk05 = Volume_1cang;
  2674. //const uint16_t *HArrayTsk05 = H_1cang;
  2675. for (;;)
  2676. {
  2677. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  2678. AGL_JudgeState();
  2679. for (i = 0; i < pcang->Cang_Num; i++)
  2680. {
  2681. // Value_Manage(i);
  2682. // for(uint8_t i = 0;i < 5;i++)
  2683. {
  2684. #if 0
  2685. switch (i)
  2686. {
  2687. case 0:
  2688. VolArrayTsk05 = Volume_1cang;
  2689. HArrayTsk05 = H_1cang;
  2690. break;
  2691. case 1:
  2692. VolArrayTsk05 = Volume_1cang;
  2693. HArrayTsk05 = H_1cang;
  2694. break;
  2695. case 2:
  2696. VolArrayTsk05 = Volume_2cang;
  2697. HArrayTsk05 = H_2cang;
  2698. break;
  2699. case 3:
  2700. VolArrayTsk05 = Volume_3cang;
  2701. HArrayTsk05 = H_3cang;
  2702. break;
  2703. case 4:
  2704. VolArrayTsk05 = Volume_4cang;
  2705. HArrayTsk05 = H_4cang;
  2706. break;
  2707. default:
  2708. VolArrayTsk05 = Volume_4cang;
  2709. HArrayTsk05 = H_4cang;
  2710. break;
  2711. }
  2712. v000 = Calc_Vol(plevel[i].Level_Data, VolArrayTsk05, HArrayTsk05, i);
  2713. plevel[i].Volume_Data = v000;
  2714. #endif
  2715. DF_State(i);
  2716. // BGY_state(i);
  2717. osDelay(100);
  2718. }
  2719. }
  2720. }
  2721. /* USER CODE END StartTask05 */
  2722. }
  2723. /* USER CODE BEGIN Header_StartTask06 */
  2724. /**
  2725. * @brief Function implementing the myTask06 thread.
  2726. * @param argument: Not used
  2727. * @retval None
  2728. */
  2729. /* USER CODE END Header_StartTask06 */
  2730. void StartTask06(void *argument)
  2731. {
  2732. /* USER CODE BEGIN StartTask06 */
  2733. /* Infinite loop */
  2734. for(;;)
  2735. {
  2736. osDelay(1);
  2737. }
  2738. /* USER CODE END StartTask06 */
  2739. }
  2740. /* USER CODE BEGIN Header_StartTask07 */
  2741. /**
  2742. * @brief Function implementing the myTask07 thread.
  2743. * @param argument: Not used
  2744. * @retval None
  2745. */
  2746. /* USER CODE END Header_StartTask07 */
  2747. void StartTask07(void *argument)
  2748. {
  2749. /* USER CODE BEGIN StartTask07 */
  2750. /* Infinite loop */
  2751. for(;;)
  2752. {
  2753. osDelay(1);
  2754. }
  2755. /* USER CODE END StartTask07 */
  2756. }
  2757. /* USER CODE BEGIN Header_StartTask08 */
  2758. /**
  2759. * @brief Function implementing the myTask08 thread.
  2760. * @param argument: Not used
  2761. * @retval None
  2762. */
  2763. /* USER CODE END Header_StartTask08 */
  2764. void StartTask08(void *argument)
  2765. {
  2766. /* USER CODE BEGIN StartTask08 */
  2767. /* Infinite loop */
  2768. for(;;)
  2769. {
  2770. osDelay(1);
  2771. }
  2772. /* USER CODE END StartTask08 */
  2773. }
  2774. /* USER CODE BEGIN Header_StartTask09 */
  2775. /**
  2776. * @brief Function implementing the myTask09 thread.
  2777. * @param argument: Not used
  2778. * @retval None
  2779. */
  2780. /* USER CODE END Header_StartTask09 */
  2781. void StartTask09(void *argument)
  2782. {
  2783. /* USER CODE BEGIN StartTask09 */
  2784. /* Infinite loop */
  2785. for(;;)
  2786. {
  2787. osDelay(1);
  2788. }
  2789. /* USER CODE END StartTask09 */
  2790. }
  2791. /* USER CODE BEGIN Header_StartTask10 */
  2792. /**
  2793. * @brief Function implementing the myTask10 thread.
  2794. * @param argument: Not used
  2795. * @retval None
  2796. */
  2797. /* USER CODE END Header_StartTask10 */
  2798. void StartTask10(void *argument)
  2799. {
  2800. /* USER CODE BEGIN StartTask10 */
  2801. /* Infinite loop */
  2802. for(;;)
  2803. {
  2804. osDelay(1);
  2805. }
  2806. /* USER CODE END StartTask10 */
  2807. }
  2808. /* USER CODE BEGIN Header_StartTask11 */
  2809. /**
  2810. * @brief Function implementing the myTask11 thread.
  2811. * @param argument: Not used
  2812. * @retval None
  2813. */
  2814. /* USER CODE END Header_StartTask11 */
  2815. void StartTask11(void *argument)
  2816. {
  2817. /* USER CODE BEGIN StartTask11 */
  2818. /* Infinite loop */
  2819. for(;;)
  2820. {
  2821. osDelay(1);
  2822. }
  2823. /* USER CODE END StartTask11 */
  2824. }
  2825. /* USER CODE BEGIN Header_StartTask12 */
  2826. /**
  2827. * @brief Function implementing the myTask12 thread.
  2828. * @param argument: Not used
  2829. * @retval None
  2830. */
  2831. /* USER CODE END Header_StartTask12 */
  2832. void StartTask12(void *argument)
  2833. {
  2834. /* USER CODE BEGIN StartTask12 */
  2835. /* Infinite loop */
  2836. for(;;)
  2837. {
  2838. osDelay(500);
  2839. usage_Tsk12++;
  2840. HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0);
  2841. HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
  2842. }
  2843. /* USER CODE END StartTask12 */
  2844. }
  2845. /* Callback01 function */
  2846. void Callback01(void *argument)
  2847. {
  2848. /* USER CODE BEGIN Callback01 */
  2849. /* USER CODE END Callback01 */
  2850. }
  2851. /* Callback02 function */
  2852. void Callback02(void *argument)
  2853. {
  2854. /* USER CODE BEGIN Callback02 */
  2855. /* USER CODE END Callback02 */
  2856. }
  2857. /* Callback03 function */
  2858. void Callback03(void *argument)
  2859. {
  2860. /* USER CODE BEGIN Callback03 */
  2861. /* USER CODE END Callback03 */
  2862. }
  2863. /* Callback04 function */
  2864. void Callback04(void *argument)
  2865. {
  2866. /* USER CODE BEGIN Callback04 */
  2867. /* USER CODE END Callback04 */
  2868. }
  2869. /* Callback05 function */
  2870. void Callback05(void *argument)
  2871. {
  2872. /* USER CODE BEGIN Callback05 */
  2873. /* USER CODE END Callback05 */
  2874. }
  2875. /* Callback06 function */
  2876. void Callback06(void *argument)
  2877. {
  2878. /* USER CODE BEGIN Callback06 */
  2879. /* USER CODE END Callback06 */
  2880. }
  2881. /* Callback07 function */
  2882. void Callback07(void *argument)
  2883. {
  2884. /* USER CODE BEGIN Callback07 */
  2885. /* USER CODE END Callback07 */
  2886. }
  2887. /* Callback08 function */
  2888. void Callback08(void *argument)
  2889. {
  2890. /* USER CODE BEGIN Callback08 */
  2891. /* USER CODE END Callback08 */
  2892. }
  2893. /* Callback09 function */
  2894. void Callback09(void *argument)
  2895. {
  2896. /* USER CODE BEGIN Callback09 */
  2897. /* USER CODE END Callback09 */
  2898. }
  2899. /* Callback010 function */
  2900. void Callback010(void *argument)
  2901. {
  2902. /* USER CODE BEGIN Callback010 */
  2903. /* USER CODE END Callback010 */
  2904. }
  2905. /**
  2906. * @brief Period elapsed callback in non blocking mode
  2907. * @note This function is called when TIM8 interrupt took place, inside
  2908. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  2909. * a global variable "uwTick" used as application time base.
  2910. * @param htim : TIM handle
  2911. * @retval None
  2912. */
  2913. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  2914. {
  2915. /* USER CODE BEGIN Callback 0 */
  2916. /* USER CODE END Callback 0 */
  2917. if (htim->Instance == TIM8) {
  2918. HAL_IncTick();
  2919. }
  2920. /* USER CODE BEGIN Callback 1 */
  2921. /* USER CODE END Callback 1 */
  2922. }
  2923. /**
  2924. * @brief This function is executed in case of error occurrence.
  2925. * @retval None
  2926. */
  2927. void Error_Handler(void)
  2928. {
  2929. /* USER CODE BEGIN Error_Handler_Debug */
  2930. /* User can add his own implementation to report the HAL error return state */
  2931. __disable_irq();
  2932. while (1)
  2933. {
  2934. }
  2935. /* USER CODE END Error_Handler_Debug */
  2936. }
  2937. #ifdef USE_FULL_ASSERT
  2938. /**
  2939. * @brief Reports the name of the source file and the source line number
  2940. * where the assert_param error has occurred.
  2941. * @param file: pointer to the source file name
  2942. * @param line: assert_param error line source number
  2943. * @retval None
  2944. */
  2945. void assert_failed(uint8_t *file, uint32_t line)
  2946. {
  2947. /* USER CODE BEGIN 6 */
  2948. /* User can add his own implementation to report the file name and line number,
  2949. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  2950. /* USER CODE END 6 */
  2951. }
  2952. #endif /* USE_FULL_ASSERT */
  2953. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/