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.

305 lines
10 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
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. .name = "fan0",
  75. .pwm_cfg =
  76. {
  77. .name = "fan0pwmtimer",
  78. .htim = &htim2,
  79. .freq = TIMER2_FREQ,
  80. .polarity = false,
  81. },
  82. .nfan = 2,
  83. .fan0Channel = {3, 0, 0, 0},
  84. .fanFBGpioCfg =
  85. {
  86. {.pin = PC10},
  87. {.pin = PC11},
  88. },
  89. .fanPowerGpioCfg =
  90. {
  91. {
  92. .pin = PC4,
  93. .mode = ZGPIO::kMode_nopull,
  94. .mirror = false,
  95. },
  96. },
  97. .enablefbcheck = false,
  98. .enableTrace = true,
  99. };
  100. PWMSpeedCtrlModule::config_t fan1cfg = {
  101. .name = "fan1",
  102. .pwm_cfg =
  103. {
  104. .name = "fan1pwmtimer",
  105. .htim = &htim2,
  106. .freq = TIMER2_FREQ,
  107. .polarity = false,
  108. },
  109. .nfan = 2,
  110. .fan0Channel = {4, 0, 0, 0},
  111. .fanFBGpioCfg =
  112. {
  113. {.pin = PC12},
  114. {.pin = PC13},
  115. },
  116. .fanPowerGpioCfg =
  117. {
  118. {
  119. .pin = PC5,
  120. .mode = ZGPIO::kMode_nopull,
  121. .mirror = false,
  122. },
  123. },
  124. .enablefbcheck = false,
  125. .enableTrace = true,
  126. };
  127. /*******************************************************************************
  128. * ˮ *
  129. *******************************************************************************/
  130. PWMSpeedCtrlModule::config_t pumpcfg = {
  131. .name = "pump",
  132. .pwm_cfg =
  133. {
  134. .name = "pumptime",
  135. .htim = &htim2,
  136. .freq = TIMER2_FREQ,
  137. .polarity = false,
  138. .calltrace = true,
  139. },
  140. .nfan = 1,
  141. .fan0Channel = {2, 0, 0, 0},
  142. .fanFBGpioCfg =
  143. {
  144. {.pin = PC3},
  145. },
  146. .fanPowerGpioCfg =
  147. {
  148. {
  149. .pin = PC2,
  150. .mode = ZGPIO::kMode_nopull,
  151. .mirror = false,
  152. .log_when_setstate = true,
  153. },
  154. },
  155. .enablefbcheck = false,
  156. .enableTrace = true,
  157. };
  158. DRV8710::config_t peltier_config0 = {
  159. .pwm_cfg =
  160. {
  161. .name = "peltier0_pwm",
  162. .htim = &htim1,
  163. .freq = TIMER1_FREQ,
  164. .polarity = true,
  165. },
  166. .in1_chnannel_index = 1, // PE9
  167. .in2 = PE11,
  168. .nsleep = PB2,
  169. .nfault = PB3,
  170. .shaft = HEART_SHAFT,
  171. .enableTrace = true,
  172. };
  173. DRV8710::config_t peltier_config1 = {
  174. .pwm_cfg =
  175. {
  176. .name = "peltier1_pwm",
  177. .htim = &htim1,
  178. .freq = TIMER1_FREQ,
  179. .polarity = true,
  180. },
  181. .in1_chnannel_index = 3, // PE13
  182. .in2 = PE14,
  183. .nsleep = PB13,
  184. .nfault = PB14,
  185. .shaft = HEART_SHAFT,
  186. .enableTrace = true,
  187. };
  188. static TMP117 temp[4];
  189. static PWMSpeedCtrlModule fan0;
  190. static PWMSpeedCtrlModule fan1;
  191. static PWMSpeedCtrlModule pump;
  192. static DRV8710 peltier0;
  193. static DRV8710 peltier1;
  194. temp[0].initializate(&hi2c1, TMP117::ID0);
  195. temp[1].initializate(&hi2c1, TMP117::ID1);
  196. temp[2].initializate(&hi2c1, TMP117::ID2);
  197. temp[3].initializate(&hi2c1, TMP117::ID3);
  198. fan0.initialize(&fan0cfg);
  199. fan1.initialize(&fan1cfg);
  200. pump.initialize(&pumpcfg);
  201. peltier0.initialize(&peltier_config0);
  202. peltier1.initialize(&peltier_config1);
  203. {
  204. /**
  205. * @brief ӱģʼ
  206. */
  207. static ZCanBoardModule::hardware_config_t cfg = {
  208. .input =
  209. {
  210. {PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  211. {PC7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  212. },
  213. .output =
  214. {
  215. {PD0, ZGPIO::kMode_nopull, false, false},
  216. } //
  217. };
  218. static ZCanBoardModule boardmodule;
  219. boardmodule.initialize(g_deviceId, &cfg);
  220. g_ziProtocolParser.registerModule(&boardmodule);
  221. g_zModuleDeviceManager.registerModule(&boardmodule);
  222. }
  223. {
  224. /*******************************************************************************
  225. * ģʼ *
  226. *******************************************************************************/
  227. static WaterCoolingTemperatureControlModule waterCoolingTemperatureControlModule;
  228. static WaterCoolingTemperatureControlModule::config_t temp_ctrl_config;
  229. waterCoolingTemperatureControlModule.createDefaultConfig(&temp_ctrl_config);
  230. WaterCoolingTemperatureControlModule::hardwared_config_t hardwared_config = //
  231. {
  232. .temperature_sensor = {&temp[0], &temp[1], &temp[2], &temp[3]},
  233. .fanTable = {&fan0, &fan1},
  234. .pump = &pump,
  235. .peltier_ctrl = {&peltier0, &peltier1},
  236. };
  237. waterCoolingTemperatureControlModule.initialize(g_deviceId + 1, &temp_ctrl_config, &hardwared_config);
  238. g_zModuleDeviceManager.registerModule(&waterCoolingTemperatureControlModule);
  239. g_ziProtocolParser.registerModule(&waterCoolingTemperatureControlModule);
  240. }
  241. }
  242. void umain() {
  243. chip_cfg_t chipcfg;
  244. chipcfg.us_dleay_tim = &DELAY_US_TIMER;
  245. chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
  246. chipcfg.huart = &DEBUG_UART;
  247. chipcfg.debuglight = DEBUG_LIGHT_GPIO;
  248. chip_init(&chipcfg);
  249. zos_cfg_t zoscfg;
  250. zos_init(&zoscfg);
  251. g_deviceId = getId() * 10;
  252. ZLOGI(TAG, "motorId:%d", g_deviceId);
  253. /*******************************************************************************
  254. * NVSINIT *
  255. *******************************************************************************/
  256. ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR);
  257. initcfg();
  258. ZNVS::ins().init_config();
  259. auto zcanCmder_cfg = g_zcanCmder.createCFG(g_deviceId);
  260. g_zcanCmder.init(zcanCmder_cfg);
  261. g_ziProtocolParser.initialize(&g_zcanCmder);
  262. static ZUARTDmaReceiver dmaUartReceiver;
  263. static CmdSchedulerV2 cmder;
  264. ZUARTDmaReceiver::hardware_config_t cfg = {
  265. .huart = &DEBUG_UART,
  266. .dma_rx = &DEBUG_UART_DMA,
  267. .rxbuffersize = 1024,
  268. .rxovertime_ms = 10,
  269. };
  270. dmaUartReceiver.initialize(&cfg);
  271. cmder.initialize(&dmaUartReceiver);
  272. g_zModuleDeviceManager.initialize(nullptr);
  273. g_zModuleDeviceScriptCmderPaser.initialize(&cmder, &g_zModuleDeviceManager);
  274. initmodule();
  275. while (true) {
  276. OSDefaultSchduler::getInstance()->loop();
  277. g_zcanCmder.loop();
  278. cmder.schedule();
  279. }
  280. }