led_cfg_demo.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. 
  2. /*================================================================
  3. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  4. Quectel Wireless Solutions Proprietary and Confidential.
  5. =================================================================*/
  6. /*=================================================================
  7. EDIT HISTORY FOR MODULE
  8. This section contains comments describing changes made to the module.
  9. Notice that changes are listed in reverse chronological order.
  10. WHEN WHO WHAT, WHERE, WHY
  11. ------------ ------- -------------------------------------------------------------------------------
  12. =================================================================*/
  13. /*===========================================================================
  14. * include files
  15. ===========================================================================*/
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include "ql_api_osi.h"
  20. #include "ql_log.h"
  21. #include "ql_gpio.h"
  22. #include "ql_pin_cfg.h"
  23. #include "led_cfg_demo.h"
  24. /*===========================================================================
  25. * Macro Definition
  26. ===========================================================================*/
  27. #define QL_LEDCFGDEMO_LOG_LEVEL QL_LOG_LEVEL_INFO
  28. #define QL_LEDCFGDEMO_LOG(msg, ...) QL_LOG(QL_LEDCFGDEMO_LOG_LEVEL, "ql_LEDCFGDEMO", msg, ##__VA_ARGS__)
  29. #define QL_LEDCFGDEMO_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_LEDCFGDEMO", msg, ##__VA_ARGS__)
  30. #define QL_PWM_DEMO_26M (26000000)
  31. #define QL_PWM_DEMO_PRESCALER (26000)
  32. #ifdef QL_APP_PROJECT_DEF_EG700G
  33. #define QL_PWM_NUM QL_PWM_0
  34. #else
  35. #define QL_PWM_NUM QL_PWM_10
  36. #endif
  37. /*===========================================================================
  38. * Variate
  39. ===========================================================================*/
  40. ql_task_t ledcfg_task = NULL;
  41. /*===========================================================================
  42. * Functions
  43. ===========================================================================*/
  44. static void _ledcfg_demo_cb(unsigned int ind_type, uint32_t net_status, uint32_t net_type)
  45. {
  46. if( ind_type == QUEC_LEDCFG_EVENT_IND )
  47. {
  48. ql_event_t event;
  49. event.id = ind_type;
  50. event.param1 = net_status;
  51. event.param2 = net_type;
  52. ql_rtos_event_send(ledcfg_task, &event);
  53. QL_LEDCFGDEMO_LOG("led config net_status is %d, net_type is %d", event.param1, event.param2);
  54. }
  55. else
  56. {
  57. QL_LEDCFGDEMO_LOG("led config ind error!");
  58. }
  59. }
  60. void ql_led_pwm_enable(int period, int ontime)
  61. {
  62. ql_pwm_cfg_s pwm_cfg;
  63. pwm_cfg.clk_sel = QL_CLK_XTAL_LP;
  64. pwm_cfg.prescaler = QL_PWM_DEMO_PRESCALER - 1;
  65. pwm_cfg.period = (QL_PWM_DEMO_26M/QL_PWM_DEMO_PRESCALER/1000)*period - 1;
  66. pwm_cfg.duty = (ontime*pwm_cfg.period)/period;
  67. ql_pwm_enable(QL_PWM_NUM, &pwm_cfg);
  68. }
  69. static void ql_ledcfg_demo_thread(void *param)
  70. {
  71. QL_LEDCFGDEMO_LOG("led config demo thread enter, param 0x%x", param);
  72. /* set NET_STATUS */
  73. ql_pin_set_func(QL_PIN_NET_STATUS, QL_PIN_NET_STATUS_FUNC);
  74. ql_pwm_open(QL_PWM_NUM);
  75. #ifndef QL_APP_PROJECT_DEF_EC800G
  76. #ifndef QL_APP_PROJECT_DEF_EG800G
  77. ql_pin_set_func(QL_PIN_NET_MODE, QL_PIN_NET_MODE_FUNC_GPIO);
  78. ql_gpio_init(QL_GPIO_NET_MODE, GPIO_OUTPUT, PULL_NONE, LVL_LOW);
  79. #endif
  80. #endif
  81. ql_event_t event;
  82. ql_ledcfg_callback_register(_ledcfg_demo_cb);
  83. while(1)
  84. {
  85. if( ql_event_try_wait(&event) != 0 )
  86. {
  87. continue;
  88. }
  89. if( event.id == QUEC_LEDCFG_EVENT_IND )
  90. {
  91. switch( event.param1 )
  92. {
  93. case IND_SIM_NOT_INSERT:
  94. case IND_SIM_INITIALIZING:
  95. case IND_SIM_PIN_LOCK:
  96. case IND_SIM_CPIN_READY:
  97. case IND_SEARCHING:
  98. case IND_CAMP_ON_CELL:
  99. case IND_REGISTERING:
  100. QL_LEDCFGDEMO_LOG("led config slow1 twinkle [%d]", event.param1);
  101. ql_led_pwm_enable(QL_LED_TWINKLE_SLOW1_PERIOD, QL_LED_TWINKLE_SLOW1_ONTIME);
  102. break;
  103. case IND_STANDBY:
  104. case IND_PDP_ACTIVING:
  105. case IND_PDP_ACTIVED:
  106. case IND_SOCKET_SET_UP:
  107. case IND_PDP_DEACTIVING:
  108. QL_LEDCFGDEMO_LOG("led config slow2 twinkle [%d]", event.param1);
  109. ql_led_pwm_enable(QL_LED_TWINKLE_SLOW2_PERIOD, QL_LED_TWINKLE_SLOW2_ONTIME);
  110. break;
  111. case IND_DATA_TRANSMIT:
  112. QL_LEDCFGDEMO_LOG("led config fast twinkle [%d]", event.param1);
  113. ql_led_pwm_enable(QL_LED_TWINKLE_FAST_PERIOD, QL_LED_TWINKLE_FAST_ONTIME);
  114. break;
  115. case IND_DIALING:
  116. QL_LEDCFGDEMO_LOG("led config keep on [%d]", event.param1);
  117. ql_led_pwm_enable(QL_LED_TWINKLE_ON_PERIOD, QL_LED_TWINKLE_ON_ONTIME);
  118. break;
  119. default:
  120. QL_LEDCFGDEMO_LOG("led config error!");
  121. break;
  122. }
  123. #ifndef QL_APP_PROJECT_DEF_EC800G
  124. #ifndef QL_APP_PROJECT_DEF_EG800G
  125. if( event.param2 == IND_NET_TYPE_4G )
  126. {
  127. QL_LEDCFGDEMO_LOG("led config network is 4G");
  128. ql_gpio_set_level(QL_GPIO_NET_MODE, LVL_HIGH);
  129. }
  130. else
  131. {
  132. QL_LEDCFGDEMO_LOG("led config network is not 4G");
  133. ql_gpio_set_level(QL_GPIO_NET_MODE, LVL_LOW);
  134. }
  135. #endif
  136. #endif
  137. }
  138. }
  139. ql_rtos_task_delete(NULL);
  140. }
  141. void ql_ledcfg_app_init(void)
  142. {
  143. QlOSStatus err = QL_OSI_SUCCESS;
  144. err = ql_rtos_task_create(&ledcfg_task, 1024, APP_PRIORITY_NORMAL, "ql_ledcfgdemo", ql_ledcfg_demo_thread, NULL, 1);
  145. if( err != QL_OSI_SUCCESS )
  146. {
  147. QL_LEDCFGDEMO_LOG("led config demo task created failed");
  148. }
  149. }