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.

206 lines
6.6 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
  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. #include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp"
  8. //
  9. #include "sdk\components\flash\znvs.hpp"
  10. //
  11. #include "sdk\components\sensors\tmp117\tmp117.hpp"
  12. #include "sdk\components\ti\drv8710.hpp"
  13. #include "sdk\components\water_cooling_temperature_control_module\pwm_ctrl_module.hpp"
  14. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module.hpp"
  15. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.cpp"
  16. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.hpp"
  17. #define TAG "main"
  18. using namespace iflytop;
  19. using namespace std;
  20. extern void umain();
  21. extern "C" {
  22. void StartDefaultTask(void const* argument) { umain(); }
  23. }
  24. static ZCanCmder g_zcanCmder;
  25. static ZIProtocolParser g_ziProtocolParser;
  26. uint8_t getId() {
  27. static bool init = false;
  28. static ZGPIO ID0;
  29. static ZGPIO ID1;
  30. static ZGPIO ID2;
  31. static ZGPIO ID3;
  32. static ZGPIO ID4;
  33. if (!init) {
  34. ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  35. ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  36. ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  37. ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  38. ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  39. init = true;
  40. }
  41. uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
  42. return id;
  43. }
  44. void umain() {
  45. chip_cfg_t chipcfg;
  46. chipcfg.us_dleay_tim = &DELAY_US_TIMER;
  47. chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
  48. chipcfg.huart = &DEBUG_UART;
  49. chipcfg.debuglight = DEBUG_LIGHT_GPIO;
  50. chip_init(&chipcfg);
  51. zos_cfg_t zoscfg;
  52. zos_init(&zoscfg);
  53. uint8_t deviceId = getId();
  54. ZLOGI(TAG, "motorId:%d", deviceId);
  55. if (deviceId == 0) {
  56. ZLOGE(TAG, "motorId can't be 0");
  57. chip_set_error();
  58. while (true) {
  59. }
  60. }
  61. #if 0
  62. /*******************************************************************************
  63. * NVSINIT *
  64. *******************************************************************************/
  65. ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR);
  66. {
  67. static I_StepMotorCtrlModule::flash_config_t cfg;
  68. StepMotorCtrlModule::create_default_cfg(cfg);
  69. ZNVS::ins().alloc_config(MOTOR_CFG_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg));
  70. }
  71. ZNVS::ins().init_config();
  72. #endif
  73. /*******************************************************************************
  74. * *
  75. *******************************************************************************/
  76. PWMSpeedCtrlModule::config_t fan0cfg = {
  77. .fanCtrlTim = &htim2,
  78. .nfan = 2,
  79. .fan0Channel = {3, 0, 0, 0},
  80. .fanFBGpioCfg =
  81. {
  82. {.pin = PC10},
  83. {.pin = PC11},
  84. },
  85. .fanPowerGpioCfg =
  86. {
  87. {.pin = PC4, .mode = ZGPIO::kMode_nopull, .mirror = false},
  88. },
  89. };
  90. PWMSpeedCtrlModule::config_t fan1cfg = {
  91. .fanCtrlTim = &htim2,
  92. .nfan = 2,
  93. .fan0Channel = {4, 0, 0, 0},
  94. .fanFBGpioCfg =
  95. {
  96. {.pin = PC12},
  97. {.pin = PC13},
  98. },
  99. .fanPowerGpioCfg =
  100. {
  101. {.pin = PC5, .mode = ZGPIO::kMode_nopull, .mirror = false},
  102. },
  103. };
  104. /*******************************************************************************
  105. * ˮ *
  106. *******************************************************************************/
  107. PWMSpeedCtrlModule::config_t pumpcfg = {
  108. .fanCtrlTim = &htim2,
  109. .nfan = 1,
  110. .fan0Channel = {2, 0, 0, 0},
  111. .fanFBGpioCfg =
  112. {
  113. {.pin = PC3},
  114. },
  115. .fanPowerGpioCfg =
  116. {
  117. {.pin = PC2, .mode = ZGPIO::kMode_nopull, .mirror = false},
  118. },
  119. };
  120. DRV8710::config_t peltier_config0 = {
  121. .tim = &htim1,
  122. .in1_chnannel_index = 1,
  123. .in2 = PE10,
  124. .nsleep = PB2,
  125. .nfault = PB3,
  126. .shaft = false,
  127. };
  128. DRV8710::config_t peltier_config1 = {
  129. .tim = &htim1,
  130. .in1_chnannel_index = 3,
  131. .in2 = PE14,
  132. .nsleep = PB13,
  133. .nfault = PB14,
  134. .shaft = false,
  135. };
  136. static TMP117 temp[4];
  137. static PWMSpeedCtrlModule fan0;
  138. static PWMSpeedCtrlModule fan1;
  139. static PWMSpeedCtrlModule pump;
  140. static DRV8710 peltier0;
  141. static DRV8710 peltier1;
  142. static WaterCoolingTemperatureControlModule waterCoolingTemperatureControlModule;
  143. fan0.initialize(&fan0cfg, true);
  144. fan1.initialize(&fan1cfg, true);
  145. pump.initialize(&pumpcfg, false);
  146. peltier0.initialize(&peltier_config0);
  147. peltier1.initialize(&peltier_config1);
  148. temp[0].initializate(&hi2c1, TMP117::ID0);
  149. temp[1].initializate(&hi2c1, TMP117::ID1);
  150. temp[2].initializate(&hi2c1, TMP117::ID2);
  151. temp[3].initializate(&hi2c1, TMP117::ID3);
  152. WaterCoolingTemperatureControlModule::config_t temp_ctrl_config;
  153. waterCoolingTemperatureControlModule.createDefaultConfig(&temp_ctrl_config);
  154. WaterCoolingTemperatureControlModule::hardwared_config_t hardwared_config = //
  155. {
  156. .temperature_sensor = {&temp[0], &temp[1], &temp[2], &temp[3]},
  157. .fanTable = {&fan0, &fan1},
  158. .pump = &pump,
  159. .peltier_ctrl = {&peltier0, &peltier1},
  160. .ext_input =
  161. {
  162. {PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  163. {PC7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  164. },
  165. .ext_output =
  166. {
  167. {PD0, ZGPIO::kMode_nopull, false, false},
  168. } //
  169. };
  170. waterCoolingTemperatureControlModule.initialize(deviceId, &temp_ctrl_config, &hardwared_config);
  171. auto zcanCmder_cfg = g_zcanCmder.createCFG(deviceId);
  172. g_zcanCmder.init(zcanCmder_cfg);
  173. g_ziProtocolParser.initialize(&g_zcanCmder);
  174. g_ziProtocolParser.registerModule(&waterCoolingTemperatureControlModule);
  175. while (true) {
  176. OSDefaultSchduler::getInstance()->loop();
  177. g_zcanCmder.loop();
  178. }
  179. };