main.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-06 SummerGift first version
  9. */
  10. #define LOG_TAG "main" // 该模块对应的标签。不定义时,默认:NO_TAG
  11. #define LOG_LVL ELOG_LVL_WARN // ELOG_LVL_WARN // 该模块对应的日志输出级别。不定义时,默认:调试级别
  12. #include <ulog.h> // 必须在 LOG_TAG 与 LOG_LVL 下面
  13. #include <rtthread.h>
  14. #include <rtdevice.h>
  15. #include <board.h>
  16. #include "sys_config.h"
  17. #define uart1_rx GET_PIN(A, 10)
  18. /*生成带日期的版本号*/
  19. extern char *version_with_time(uint8_t option);
  20. /* defined the LED0 pin: PE9 */
  21. // #define SIM_ENABLE GET_PIN(E, 8)
  22. #define A720_power_PIN GET_PIN(E, 4) // 720供电控制脚
  23. #define REBOOT_PIN GET_PIN(E, 15) // 系统重启按键
  24. #define A720_POWERON GET_PIN(E, 9) // 720开机控制脚
  25. #define HIM_POWER_PIN GET_PIN(C, 8)
  26. void reboot_f(void *args);
  27. void air720_poweroff(void)
  28. {
  29. rt_pin_mode(A720_power_PIN, PIN_MODE_OUTPUT);
  30. rt_pin_write(A720_power_PIN, PIN_LOW);
  31. // rt_kprintf("air720_poweroff\n");
  32. }
  33. void air720_poweron(void)
  34. {
  35. // rt_thread_mdelay(1000);
  36. rt_pin_mode(A720_power_PIN, PIN_MODE_OUTPUT);
  37. rt_pin_write(A720_power_PIN, PIN_HIGH);
  38. // rt_kprintf("air720_poweron\n");
  39. }
  40. extern void touch_p(void);
  41. int main(void)
  42. {
  43. // rt_pin_mode(uart1_rx, PIN_MODE_INPUT_PULLUP);
  44. // rt_pin_write(uart1_rx, PIN_HIGH);
  45. rt_pin_mode(A720_POWERON, PIN_MODE_OUTPUT);
  46. // rt_pin_mode(SIM_ENABLE, PIN_MODE_OUTPUT);
  47. rt_pin_write(A720_POWERON, PIN_LOW); // 上电开机
  48. rt_kprintf("The current version of APP firmware is %s\r\n", version_with_time(1)); // APP_VERSION);
  49. // rt_pin_write(SIM_ENABLE, PIN_HIGH);
  50. // rt_pin_write(SIM_ENABLE, PIN_LOW);
  51. // rt_pin_write(A720_power_PIN, PIN_HIGH);
  52. /* 重启引脚为输出模式 */
  53. rt_pin_mode(REBOOT_PIN, PIN_MODE_INPUT_PULLUP);
  54. /* 默认高电平 */
  55. rt_pin_write(REBOOT_PIN, PIN_HIGH);
  56. char cnt = 0;
  57. while (1)
  58. {
  59. if (rt_pin_read(REBOOT_PIN) == 0)
  60. {
  61. touch_p();
  62. for(char a = 0 ; a < 31 ; a++)
  63. {
  64. if (rt_pin_read(REBOOT_PIN) == 0)
  65. {
  66. cnt++;
  67. }
  68. rt_thread_mdelay(10);
  69. }
  70. if(cnt >= 30)
  71. {
  72. rt_kprintf("system rebooting............\n\n");
  73. rt_hw_cpu_reset();
  74. }
  75. else
  76. {
  77. cnt = 0;
  78. }
  79. }
  80. rt_thread_mdelay(30);
  81. }
  82. return RT_EOK;
  83. }
  84. INIT_BOARD_EXPORT(air720_poweroff); // 为了实现重启4G模块断电
  85. INIT_DEVICE_EXPORT(air720_poweron); // 系统初始化后air720立即上电
  86. /**
  87. * Function ota_app_vtor_reconfig
  88. * Description Set Vector Table base location to the start addr of app(RT_APP_PART_ADDR).
  89. */
  90. // 修改中断向量表的跳转及地址
  91. static int ota_app_vtor_reconfig(void)
  92. {
  93. #define NVIC_VTOR_MASK 0x3FFFFF80
  94. #define RT_APP_PART_ADDR 0x8020000
  95. /* Set the Vector Table base location by user application firmware definition */
  96. SCB->VTOR = RT_APP_PART_ADDR & NVIC_VTOR_MASK;
  97. return 0;
  98. }
  99. INIT_BOARD_EXPORT(ota_app_vtor_reconfig);
  100. extern int HIM_POWER_CNT;
  101. extern rt_timer_t HIM_POWER_PIN_TIMER;
  102. void reboot_f(void *args)
  103. {
  104. log_w("system rebooting............");
  105. rt_hw_cpu_reset();
  106. }
  107. static void systerm_reboot_irq(void)
  108. {
  109. /* 重启引脚为输出模式 */
  110. rt_pin_mode(REBOOT_PIN, PIN_MODE_INPUT_PULLUP);
  111. /* 默认高电平 */
  112. rt_pin_write(REBOOT_PIN, PIN_HIGH);
  113. /* 绑定中断,下降沿模式,回调函数名为reboot */
  114. rt_pin_attach_irq(REBOOT_PIN, PIN_IRQ_MODE_FALLING, reboot_f, RT_NULL);
  115. /* 使能中断 */
  116. rt_pin_irq_enable(REBOOT_PIN, PIN_IRQ_ENABLE);
  117. }
  118. // INIT_PREV_EXPORT(systerm_reboot_irq);
  119. /* 导出到 msh 命令列表中 */
  120. MSH_CMD_EXPORT(systerm_reboot_irq, pin beep sample);
  121. /*
  122. {"element":[
  123. {"num":7, "sensor_addr":6, "start_reg":0,"count":1,"d_pos":0,"factor":-10, "d_length":1,"err_cnt":0,"online_flag":0,"value":0,"cName":"日 雨 量:", "units":"mm/d", "eName":"YPRECD2", "elem_type":"PRECA", "eValue":"0", "eKey":"e8 ", "eNum":"115", "dotled_s":"%s日 雨:%s%6smm "}
  124. ]
  125. }
  126. {
  127. "config": "ch_conf",
  128. "ext": {
  129. "App_mod": "0",
  130. "c0": "YTEMP01",
  131. "c1": "YHUMI00",
  132. "c2": "YSM01D0",
  133. "c3": "YWIND01",
  134. "c4": "YWDIR01",
  135. "c5": "YPRECD2",
  136. "c6": "YILLU00",
  137. "c7": "YSTEMD0",
  138. "c8": "YPRES00"
  139. }
  140. }
  141. */