main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. int main(void)
  41. {
  42. // rt_pin_mode(uart1_rx, PIN_MODE_INPUT_PULLUP);
  43. // rt_pin_write(uart1_rx, PIN_HIGH);
  44. rt_pin_mode(A720_POWERON, PIN_MODE_OUTPUT);
  45. // rt_pin_mode(SIM_ENABLE, PIN_MODE_OUTPUT);
  46. rt_pin_write(A720_POWERON, PIN_LOW);//上电开机
  47. /* 版本号 + 设备 ID。device_sn 是 char[20],不保证 '\0' 结尾,
  48. 先拷进本地缓冲补终止符,避免 %s 越界读到相邻字段 */
  49. {
  50. char dev_id[sizeof(qxz.Param.device_sn) + 1];
  51. rt_memset(dev_id, 0, sizeof(dev_id));
  52. rt_memcpy(dev_id, qxz.Param.device_sn, sizeof(qxz.Param.device_sn));
  53. rt_kprintf("The current version of APP firmware is %s ID: %s\r\n",
  54. version_with_time(1), (dev_id[0] != '\0') ? dev_id : "-");
  55. }
  56. // rt_pin_write(SIM_ENABLE, PIN_HIGH);
  57. // rt_pin_write(SIM_ENABLE, PIN_LOW);
  58. // rt_pin_write(A720_power_PIN, PIN_HIGH);
  59. /* 重启引脚为输出模式 */
  60. rt_pin_mode(REBOOT_PIN, PIN_MODE_INPUT_PULLUP);
  61. /* 默认高电平 */
  62. rt_pin_write(REBOOT_PIN, PIN_HIGH);
  63. while (1)
  64. {
  65. if(rt_pin_read(REBOOT_PIN) == 0)
  66. {
  67. log_w("system rebooting............");
  68. rt_hw_cpu_reset();
  69. rt_pin_write(HIM_POWER_PIN , PIN_HIGH);
  70. }
  71. rt_thread_mdelay(30);
  72. }
  73. return RT_EOK;
  74. }
  75. INIT_BOARD_EXPORT(air720_poweroff);//为了实现重启4G模块断电
  76. INIT_DEVICE_EXPORT(air720_poweron);//系统初始化后air720立即上电
  77. /**
  78. * Function ota_app_vtor_reconfig
  79. * Description Set Vector Table base location to the start addr of app(RT_APP_PART_ADDR).
  80. *///修改中断向量表的跳转及地址
  81. static int ota_app_vtor_reconfig(void)
  82. {
  83. #define NVIC_VTOR_MASK 0x3FFFFF80
  84. #define RT_APP_PART_ADDR 0x8020000
  85. /* Set the Vector Table base location by user application firmware definition */
  86. SCB->VTOR = RT_APP_PART_ADDR & NVIC_VTOR_MASK;
  87. return 0;
  88. }
  89. INIT_BOARD_EXPORT(ota_app_vtor_reconfig);
  90. extern int HIM_POWER_CNT;
  91. extern rt_timer_t HIM_POWER_PIN_TIMER;
  92. void reboot_f(void *args)
  93. {
  94. log_w("system rebooting............");
  95. rt_hw_cpu_reset();
  96. }
  97. static void systerm_reboot_irq(void)
  98. {
  99. /* 重启引脚为输出模式 */
  100. rt_pin_mode(REBOOT_PIN, PIN_MODE_INPUT_PULLUP);
  101. /* 默认高电平 */
  102. rt_pin_write(REBOOT_PIN, PIN_HIGH);
  103. /* 绑定中断,下降沿模式,回调函数名为reboot */
  104. rt_pin_attach_irq(REBOOT_PIN, PIN_IRQ_MODE_FALLING, reboot_f, RT_NULL);
  105. /* 使能中断 */
  106. rt_pin_irq_enable(REBOOT_PIN, PIN_IRQ_ENABLE);
  107. }
  108. //INIT_PREV_EXPORT(systerm_reboot_irq);
  109. /* 导出到 msh 命令列表中 */
  110. MSH_CMD_EXPORT(systerm_reboot_irq, pin beep sample);