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.

82 lines
2.0 KiB

12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. //
  4. #include "appdep.hpp"
  5. #include "apppublic/boardid.hpp"
  6. //
  7. #include "app/main_controler/main_controler.hpp"
  8. #include "app/valvecontroler/valvecontroler.hpp"
  9. #define TAG "main"
  10. extern void umain();
  11. extern "C" {
  12. void StartDefaultTask(void const *argument) { umain(); }
  13. }
  14. /*******************************************************************************
  15. * MAIN *
  16. *******************************************************************************/
  17. using namespace iflytop;
  18. /* IWDG init function */
  19. void MX_IWDG_Init(void) {
  20. hiwdg.Instance = IWDG;
  21. hiwdg.Init.Prescaler = IWDG_PRESCALER_256;
  22. hiwdg.Init.Reload = 501;
  23. if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
  24. Error_Handler();
  25. }
  26. }
  27. static ZGPIO debuglight0;
  28. static ZGPIO debuglight1;
  29. static bool errorFlag;
  30. static inline void debugLightLoop() {
  31. static bool light = false;
  32. static uint32_t lastcall = 0;
  33. if (errorFlag) {
  34. if (zos_haspassedms(lastcall) > 30) {
  35. light = !light;
  36. debuglight0.write(light);
  37. debuglight1.write(light);
  38. lastcall = zos_get_tick();
  39. }
  40. } else {
  41. if (zos_haspassedms(lastcall) > 300) {
  42. light = !light;
  43. debuglight0.write(light);
  44. debuglight1.write(light);
  45. lastcall = zos_get_tick();
  46. }
  47. }
  48. }
  49. int32_t getDeviceIdFromFlash() {
  50. int32_t *deviceId = (int32_t *)BOARD_TYPE_ID_FLASH_ADD;
  51. if (*deviceId <= 0) {
  52. return 0;
  53. }
  54. return *deviceId;
  55. }
  56. void umain() {
  57. MX_IWDG_Init();
  58. debuglight0.initAsOutput(DEBUG_LIGHT_IO0, kxs_gpio_nopull, false, false);
  59. debuglight1.initAsOutput(DEBUG_LIGHT_IO1, kxs_gpio_nopull, false, false);
  60. int32_t id = getDeviceIdFromFlash();
  61. if (id == boardid::kbmainboard) {
  62. MainControler::ins()->init();
  63. } else if (id == boardid::kvalveboard) {
  64. ValvaControler::ins()->init();
  65. } else {
  66. errorFlag = true;
  67. }
  68. while (true) {
  69. osDelay(30);
  70. debugLightLoop();
  71. HAL_IWDG_Refresh(&hiwdg);
  72. }
  73. }