main.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. rt_kprintf("The current version of APP firmware is %s\r\n",version_with_time(1));//APP_VERSION);
  48. // rt_pin_write(SIM_ENABLE, PIN_HIGH);
  49. // rt_pin_write(SIM_ENABLE, PIN_LOW);
  50. // rt_pin_write(A720_power_PIN, PIN_HIGH);
  51. /* 重启引脚为输出模式 */
  52. rt_pin_mode(REBOOT_PIN, PIN_MODE_INPUT_PULLUP);
  53. /* 默认高电平 */
  54. rt_pin_write(REBOOT_PIN, PIN_HIGH);
  55. while (1)
  56. {
  57. if(rt_pin_read(REBOOT_PIN) == 0)
  58. {
  59. log_w("system rebooting............");
  60. rt_hw_cpu_reset();
  61. rt_pin_write(HIM_POWER_PIN , PIN_HIGH);
  62. }
  63. rt_thread_mdelay(30);
  64. }
  65. return RT_EOK;
  66. }
  67. INIT_BOARD_EXPORT(air720_poweroff);//为了实现重启4G模块断电
  68. INIT_DEVICE_EXPORT(air720_poweron);//系统初始化后air720立即上电
  69. /**
  70. * Function ota_app_vtor_reconfig
  71. * Description Set Vector Table base location to the start addr of app(RT_APP_PART_ADDR).
  72. *///修改中断向量表的跳转及地址
  73. static int ota_app_vtor_reconfig(void)
  74. {
  75. #define NVIC_VTOR_MASK 0x3FFFFF80
  76. #define RT_APP_PART_ADDR 0x8020000
  77. /* Set the Vector Table base location by user application firmware definition */
  78. SCB->VTOR = RT_APP_PART_ADDR & NVIC_VTOR_MASK;
  79. return 0;
  80. }
  81. INIT_BOARD_EXPORT(ota_app_vtor_reconfig);
  82. extern int HIM_POWER_CNT;
  83. extern rt_timer_t HIM_POWER_PIN_TIMER;
  84. void reboot_f(void *args)
  85. {
  86. log_w("system rebooting............");
  87. rt_hw_cpu_reset();
  88. }
  89. static void systerm_reboot_irq(void)
  90. {
  91. /* 重启引脚为输出模式 */
  92. rt_pin_mode(REBOOT_PIN, PIN_MODE_INPUT_PULLUP);
  93. /* 默认高电平 */
  94. rt_pin_write(REBOOT_PIN, PIN_HIGH);
  95. /* 绑定中断,下降沿模式,回调函数名为reboot */
  96. rt_pin_attach_irq(REBOOT_PIN, PIN_IRQ_MODE_FALLING, reboot_f, RT_NULL);
  97. /* 使能中断 */
  98. rt_pin_irq_enable(REBOOT_PIN, PIN_IRQ_ENABLE);
  99. }
  100. //INIT_PREV_EXPORT(systerm_reboot_irq);
  101. /* 导出到 msh 命令列表中 */
  102. MSH_CMD_EXPORT(systerm_reboot_irq, pin beep sample);