maone.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include <stdio.h>
  2. #include "time.h"
  3. #include "los_swtmr.h"
  4. #include "los_sys.h"
  5. #include "ohos_init.h"
  6. // #include "iot_gpio.h"
  7. // #include "iot_gpio_ex.h"
  8. // #include "iot_i2c.h"
  9. // #include "cmsis_os2.h"
  10. // #include "ohos_init.h"
  11. // #include <stdio.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <unistd.h>
  15. // #include <cmsis_os2.h>
  16. #include <stdbool.h>
  17. // #ifdef __cplusplus
  18. // #if __cplusplus
  19. // extern "C" {
  20. // #endif /* __cplusplus */
  21. // #endif /* __cplusplus */
  22. UINT32 g_timerCount1 = 0;
  23. UINT32 g_timerCount2 = 0;
  24. VOID Timer1_CallBack(UINT32 arg)
  25. {
  26. UINT64 lastTick;
  27. g_timerCount1++;
  28. lastTick=(UINT32)LOS_TickCountGet();
  29. dprintf("g_timerCount1=%d\n", g_timerCount1);
  30. dprintf("tick_last1=%d\n", lastTick);
  31. }
  32. VOID Timer2_CallBack(UINT32 arg)
  33. {
  34. UINT64 lastTick;
  35. lastTick=(UINT32)LOS_TickCountGet();
  36. g_timerCount2++;
  37. dprintf("g_timerCount2=%d\n", g_timerCount2);
  38. dprintf("tick_last2=%d\n", lastTick);
  39. }
  40. // VOID Timer_example(VOID)
  41. // {
  42. // UINT16 id1; // Timer1 id
  43. // UINT16 id2; // Timer2 id
  44. // UINT32 tick;
  45. // LOS_SwtmrCreate(1000, LOS_SWTMR_MODE_ONCE, Timer1_CallBack, &id1, 1);
  46. // LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_CallBack, &id2, 1);
  47. // dprintf("create Timer1 success\n");
  48. // LOS_SwtmrStart(id1);
  49. // dprintf("start Timer1 sucess\n");
  50. // LOS_TaskDelay(200);
  51. // LOS_SwtmrTimeGet(id1, &tick);
  52. // dprintf("tick =%d\n", tick);
  53. // LOS_SwtmrStop(id1);
  54. // dprintf("stop Timer1 sucess\n");
  55. // LOS_SwtmrStart(id1);
  56. // LOS_TaskDelay(1000);
  57. // LOS_SwtmrDelete(id1);
  58. // dprintf("delete Timer1 sucess\n");
  59. // LOS_SwtmrStart(id2);
  60. // dprintf("start Timer2\n");
  61. // LOS_TaskDelay(1000);
  62. // LOS_SwtmrStop(id2);
  63. // LOS_SwtmrDelete(id2);
  64. // }
  65. // #ifdef __cplusplus
  66. // #if __cplusplus
  67. // }
  68. // #endif /* __cplusplus */
  69. // #endif /* __cplusplus */
  70. /***** 定时器创建 *****/
  71. static void Timer_example(void)
  72. {
  73. UINT16 id1; // Timer1 id
  74. UINT16 id2; // Timer2 id
  75. UINT32 tick;
  76. LOS_SwtmrCreate(1000, LOS_SWTMR_MODE_ONCE, Timer1_CallBack, &id1, 1);
  77. LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_CallBack, &id2, 1);
  78. dprintf("create Timer1 success\n");
  79. LOS_SwtmrStart(id1);
  80. dprintf("start Timer1 sucess\n");
  81. LOS_TaskDelay(200);
  82. LOS_SwtmrTimeGet(id1, &tick);
  83. dprintf("tick =%d\n", tick);
  84. LOS_SwtmrStop(id1);
  85. dprintf("stop Timer1 sucess\n");
  86. LOS_SwtmrStart(id1);
  87. LOS_TaskDelay(1000);
  88. LOS_SwtmrDelete(id1);
  89. dprintf("delete Timer1 sucess\n");
  90. LOS_SwtmrStart(id2);
  91. dprintf("start Timer2\n");
  92. LOS_TaskDelay(1000);
  93. LOS_SwtmrStop(id2);
  94. LOS_SwtmrDelete(id2);
  95. }
  96. APP_FEATURE_INIT(Timer_example);