You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
9.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include "sdk/os/zos.hpp"
  4. #include "sdk\components\flash\zsimple_flash.hpp"
  5. #include "sdk\components\zcancmder\zcanreceiver.hpp"
  6. #include "sdk\components\zcancmder_module\zcan_basic_order_module.hpp"
  7. //
  8. #include "sdk\components\flash\znvs.hpp"
  9. //
  10. #include "sdk\components\sensors\tmp117\tmp117.hpp"
  11. #include "sdk\components\ti\drv8710.hpp"
  12. #include "sdk\components\water_cooling_temperature_control_module\pwm_ctrl_module.hpp"
  13. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module.hpp"
  14. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.cpp"
  15. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.hpp"
  16. // cancmder basic
  17. #include "sdk\components\cmdscheduler\cmd_scheduler_v2.hpp"
  18. #include "sdk\components\hardware\uart\zuart_dma_receiver.hpp"
  19. #include "sdk\components\zcancmder\zcan_board_module.hpp"
  20. #include "sdk\components\zprotocol_helper\micro_computer_module_device_script_cmder_paser.hpp"
  21. #include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp"
  22. #include "sdk\components\zprotocols\zcancmder_v2\zmodule_device_manager.hpp"
  23. //
  24. #define TAG "main"
  25. using namespace iflytop;
  26. using namespace std;
  27. extern void umain();
  28. extern "C" {
  29. void StartDefaultTask(void const* argument) { umain(); }
  30. }
  31. // static ZCanCmder g_zcanCmder;
  32. // static ZIProtocolParser g_ziProtocolParser;
  33. static ZCanCmder g_zcanCmder;
  34. static ZIProtocolParser g_ziProtocolParser;
  35. static ZModuleDeviceManager g_zModuleDeviceManager;
  36. static MicroComputerModuleDeviceScriptCmderPaser g_zModuleDeviceScriptCmderPaser;
  37. static uint32_t g_deviceId = 0;
  38. uint8_t getId() {
  39. static bool init = false;
  40. static ZGPIO ID0;
  41. static ZGPIO ID1;
  42. static ZGPIO ID2;
  43. static ZGPIO ID3;
  44. static ZGPIO ID4;
  45. if (!init) {
  46. ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  47. ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  48. ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  49. ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  50. ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  51. init = true;
  52. }
  53. uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
  54. return id;
  55. }
  56. void initcfg() {
  57. /**
  58. * @brief ʼãϵͳҪöҪгʼ
  59. */
  60. #if 0
  61. static I_StepMotorCtrlModule::flash_config_t cfg;
  62. StepMotorCtrlModule::create_default_cfg(cfg);
  63. ZNVS::ins().alloc_config(MOTOR_CFG_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg));
  64. #endif
  65. }
  66. void initmodule() {
  67. #define TIMER2_FREQ 1000
  68. #define TIMER1_FREQ 1000
  69. #define HEART_SHAFT false
  70. /*******************************************************************************
  71. * *
  72. *******************************************************************************/
  73. PWMSpeedCtrlModule::config_t fan0cfg = {
  74. .pwm_cfg =
  75. {
  76. .name = "fan0pwmtimer",
  77. .htim = &htim2,
  78. .freq = TIMER2_FREQ,
  79. .polarity = true,
  80. },
  81. .nfan = 2,
  82. .fan0Channel = {3, 0, 0, 0},
  83. .fanFBGpioCfg =
  84. {
  85. {.pin = PC10},
  86. {.pin = PC11},
  87. },
  88. .fanPowerGpioCfg =
  89. {
  90. {
  91. .pin = PC4,
  92. .mode = ZGPIO::kMode_nopull,
  93. .mirror = false,
  94. },
  95. },
  96. .enablefbcheck = true,
  97. .enableTrace = true,
  98. };
  99. PWMSpeedCtrlModule::config_t fan1cfg = {
  100. .pwm_cfg =
  101. {
  102. .name = "fan1pwmtimer",
  103. .htim = &htim2,
  104. .freq = TIMER2_FREQ,
  105. .polarity = true,
  106. },
  107. .nfan = 2,
  108. .fan0Channel = {4, 0, 0, 0},
  109. .fanFBGpioCfg =
  110. {
  111. {.pin = PC12},
  112. {.pin = PC13},
  113. },
  114. .fanPowerGpioCfg =
  115. {
  116. {
  117. .pin = PC5,
  118. .mode = ZGPIO::kMode_nopull,
  119. .mirror = false,
  120. },
  121. },
  122. .enablefbcheck = true,
  123. .enableTrace = true,
  124. };
  125. /*******************************************************************************
  126. * ˮ *
  127. *******************************************************************************/
  128. PWMSpeedCtrlModule::config_t pumpcfg = {
  129. .pwm_cfg =
  130. {
  131. .name = "pumptime",
  132. .htim = &htim2,
  133. .freq = TIMER2_FREQ,
  134. .polarity = true,
  135. .calltrace = true,
  136. },
  137. .nfan = 1,
  138. .fan0Channel = {2, 0, 0, 0},
  139. .fanFBGpioCfg =
  140. {
  141. {.pin = PC3},
  142. },
  143. .fanPowerGpioCfg =
  144. {
  145. {
  146. .pin = PC2,
  147. .mode = ZGPIO::kMode_nopull,
  148. .mirror = false,
  149. .log_when_setstate = true,
  150. },
  151. },
  152. .enablefbcheck = false,
  153. .enableTrace = true,
  154. };
  155. DRV8710::config_t peltier_config0 = {
  156. .pwm_cfg =
  157. {
  158. .name = "peltier0_pwm",
  159. .htim = &htim1,
  160. .freq = TIMER1_FREQ,
  161. .polarity = true,
  162. },
  163. .in1_chnannel_index = 1, // PE9
  164. .in2 = PE11,
  165. .nsleep = PB2,
  166. .nfault = PB3,
  167. .shaft = HEART_SHAFT,
  168. .enableTrace = true,
  169. };
  170. DRV8710::config_t peltier_config1 = {
  171. .pwm_cfg =
  172. {
  173. .name = "peltier1_pwm",
  174. .htim = &htim1,
  175. .freq = TIMER1_FREQ,
  176. .polarity = true,
  177. },
  178. .in1_chnannel_index = 3, // PE13
  179. .in2 = PE14,
  180. .nsleep = PB13,
  181. .nfault = PB14,
  182. .shaft = HEART_SHAFT,
  183. .enableTrace = true,
  184. };
  185. static TMP117 temp[4];
  186. static PWMSpeedCtrlModule fan0;
  187. static PWMSpeedCtrlModule fan1;
  188. static PWMSpeedCtrlModule pump;
  189. static DRV8710 peltier0;
  190. static DRV8710 peltier1;
  191. temp[0].initializate(&hi2c1, TMP117::ID0);
  192. temp[1].initializate(&hi2c1, TMP117::ID1);
  193. temp[2].initializate(&hi2c1, TMP117::ID2);
  194. temp[3].initializate(&hi2c1, TMP117::ID3);
  195. fan0.initialize(&fan0cfg);
  196. fan1.initialize(&fan1cfg);
  197. pump.initialize(&pumpcfg);
  198. peltier0.initialize(&peltier_config0);
  199. peltier1.initialize(&peltier_config1);
  200. {
  201. /**
  202. * @brief ӱģʼ
  203. */
  204. static ZCanBoardModule::hardware_config_t cfg = {
  205. .input =
  206. {
  207. {PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  208. {PC7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  209. },
  210. .output =
  211. {
  212. {PD0, ZGPIO::kMode_nopull, false, false},
  213. } //
  214. };
  215. static ZCanBoardModule boardmodule;
  216. boardmodule.initialize(g_deviceId, &cfg);
  217. g_ziProtocolParser.registerModule(&boardmodule);
  218. g_zModuleDeviceManager.registerModule(&boardmodule);
  219. }
  220. {
  221. /*******************************************************************************
  222. * ģʼ *
  223. *******************************************************************************/
  224. static WaterCoolingTemperatureControlModule waterCoolingTemperatureControlModule;
  225. static WaterCoolingTemperatureControlModule::config_t temp_ctrl_config;
  226. waterCoolingTemperatureControlModule.createDefaultConfig(&temp_ctrl_config);
  227. WaterCoolingTemperatureControlModule::hardwared_config_t hardwared_config = //
  228. {
  229. .temperature_sensor = {&temp[0], &temp[1], &temp[2], &temp[3]},
  230. .fanTable = {&fan0, &fan1},
  231. .pump = &pump,
  232. .peltier_ctrl = {&peltier0, &peltier1},
  233. };
  234. waterCoolingTemperatureControlModule.initialize(g_deviceId + 1, &temp_ctrl_config, &hardwared_config);
  235. g_zModuleDeviceManager.registerModule(&waterCoolingTemperatureControlModule);
  236. g_ziProtocolParser.registerModule(&waterCoolingTemperatureControlModule);
  237. }
  238. }
  239. void umain() {
  240. chip_cfg_t chipcfg;
  241. chipcfg.us_dleay_tim = &DELAY_US_TIMER;
  242. chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
  243. chipcfg.huart = &DEBUG_UART;
  244. chipcfg.debuglight = DEBUG_LIGHT_GPIO;
  245. chip_init(&chipcfg);
  246. zos_cfg_t zoscfg;
  247. zos_init(&zoscfg);
  248. g_deviceId = getId() * 10;
  249. ZLOGI(TAG, "motorId:%d", g_deviceId);
  250. /*******************************************************************************
  251. * NVSINIT *
  252. *******************************************************************************/
  253. ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR);
  254. initcfg();
  255. ZNVS::ins().init_config();
  256. auto zcanCmder_cfg = g_zcanCmder.createCFG(g_deviceId);
  257. g_zcanCmder.init(zcanCmder_cfg);
  258. g_ziProtocolParser.initialize(&g_zcanCmder);
  259. static ZUARTDmaReceiver dmaUartReceiver;
  260. static CmdSchedulerV2 cmder;
  261. ZUARTDmaReceiver::hardware_config_t cfg = {
  262. .huart = &DEBUG_UART,
  263. .dma_rx = &DEBUG_UART_DMA,
  264. .rxbuffersize = 1024,
  265. .rxovertime_ms = 10,
  266. };
  267. dmaUartReceiver.initialize(&cfg);
  268. cmder.initialize(&dmaUartReceiver);
  269. g_zModuleDeviceManager.initialize(nullptr);
  270. g_zModuleDeviceScriptCmderPaser.initialize(&cmder, &g_zModuleDeviceManager);
  271. initmodule();
  272. while (true) {
  273. OSDefaultSchduler::getInstance()->loop();
  274. g_zcanCmder.loop();
  275. cmder.schedule();
  276. }
  277. }