srv_dtr.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _SRV_DTR_H_
  13. #define _SRV_DTR_H_
  14. #include "srv_config.h"
  15. #include "osi_api.h"
  16. /**
  17. * DTR is simulated by a GPIO input. Typical usages:
  18. * - AT&D1: At ON->OFF, escape from data mode.
  19. * - AT&D2: At ON->OFF, disconnect from data mode to command mode.
  20. * And when DTR is OFF, auto-answer is off.
  21. * - AT+CSCLK=1: At HIGH, sleep is enabled. At low, should quit
  22. * sleep mode.
  23. *
  24. * DTR service is a simple wrapper of GPIO. Two calbacks will be registered,
  25. * which will be called on DTR level is changed.
  26. *
  27. * If configured, DTR service will provide software debounce, besides
  28. * hardware debounce. For example, after a raising edge of DTR, and there
  29. * are no falling edge of DTR in 20ms, the rasing edge event will be sent
  30. * out.
  31. *
  32. * Due to DTR level is changing, it is possible DTR level is changed between
  33. * event send and event handling (for example, after a raising event is sent,
  34. * and just before event is handled, a falling event is triggered). So, user
  35. * should avoid to call API to get DTR level in most cases.
  36. */
  37. /**
  38. * \brief DTR callback function type
  39. *
  40. * This callback will be triggered in DTR service thread (usually, wq_hi will
  41. * be reused), and the callback will be executed in specified thread.
  42. *
  43. * \param param the registered callback parameter
  44. */
  45. typedef void (*srvDtrCallback_t)(void *param);
  46. /**
  47. * \brief start DTR service
  48. *
  49. * Both of \p rising_cb and \p falling_cb can be NULL. However, when one of
  50. * them is not NULL, \p thread can't be NULL.
  51. *
  52. * When DTR service is started, it will return false at calling \p srvDtrStart
  53. * again, even the parameters are the same.
  54. *
  55. * \param thread the thread to execute callbacks
  56. * \param rising_cb callback to be called at raising edge
  57. * \param falling_cb callback to be called at falling edge
  58. * \param cb_ctx parameter of callbacks
  59. * \return
  60. * - true on success
  61. * - false on invalid parameter
  62. */
  63. bool srvDtrStart(osiThread_t *thread, srvDtrCallback_t rising_cb,
  64. srvDtrCallback_t falling_cb, void *cb_ctx);
  65. /**
  66. * \brief stop DTR service
  67. */
  68. void srvDtrStop(void);
  69. /**
  70. * \brief whether DTR level is high
  71. *
  72. * In most cases, it shouldn't be called. When DTR service is not started,
  73. * it will return false.
  74. *
  75. * \return
  76. * - true if DTR level is high
  77. * - false if DTR level is low, or not started
  78. */
  79. bool srvDtrIsHigh(void);
  80. #ifdef CONFIG_QUEC_PROJECT_FEATURE_GPIO
  81. void prvDtrRising(void *param);
  82. void prvDtrFalling(void *param);
  83. #endif
  84. #endif