luat_mcu_air105.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #include "luat_base.h"
  22. #include "luat_mcu.h"
  23. #include "luat_spi.h"
  24. #include "app_interface.h"
  25. #include "FreeRTOS.h"
  26. extern uint32_t SystemCoreClock;
  27. int luat_mcu_set_clk(size_t mhz) {
  28. return 0;
  29. }
  30. int luat_mcu_get_clk(void) {
  31. return SystemCoreClock/1000000;
  32. }
  33. static uint8_t unique_id[16] = {0};
  34. const char* luat_mcu_unique_id(size_t* t) {
  35. OTP_GetSn(unique_id);
  36. *t = sizeof(unique_id);
  37. return unique_id;
  38. }
  39. long luat_mcu_ticks(void) {
  40. return GetSysTickMS();
  41. }
  42. uint32_t luat_mcu_hz(void) {
  43. return 1000;
  44. }
  45. uint64_t luat_mcu_tick64(void) {
  46. return GetSysTick();
  47. }
  48. uint64_t luat_mcu_tick64_ms(void) {
  49. return GetSysTickMS();
  50. }
  51. int luat_mcu_us_period(void) {
  52. return SYS_TIMER_1US;
  53. }
  54. void luat_mcu_delay_us(int delay)
  55. {
  56. Task_DelayUS(delay);
  57. }
  58. void luat_mcu_set_clk_source(uint8_t source_main, uint8_t source_32k, uint32_t delay)
  59. {
  60. switch(source_main)
  61. {
  62. case 0:
  63. PM_Set12MSource(0, delay);
  64. break;
  65. case 1:
  66. PM_Set12MSource(1, delay);
  67. break;
  68. }
  69. switch(source_32k)
  70. {
  71. case 0:
  72. PM_Set32KSource(0);
  73. break;
  74. case 1:
  75. PM_Set32KSource(1);
  76. break;
  77. }
  78. }