Europalab Devices produces a LoRaWAN transmitting client node, specialised for higher research of actuator and sensor assisted IoT networks. https://dev.europalab.com/nlnet/20200000/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

167 lines
4.5KB

  1. /**
  2. * \file main.c
  3. *
  4. * \brief LORAWAN Parser Application
  5. *
  6. *
  7. * Copyright (c) 2018 Microchip Technology Inc. and its subsidiaries.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip
  14. * software and any derivatives exclusively with Microchip products.
  15. * It is your responsibility to comply with third party license terms applicable
  16. * to your use of third party software (including open source software) that
  17. * may accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  20. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  21. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  22. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  23. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  24. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  25. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  26. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  27. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  28. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  29. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  30. *
  31. * \asf_license_stop
  32. *
  33. */
  34. /****************************** NOTES **************************************/
  35. //Guidance for design, build, and use of this firmware is available:
  36. //https://www.github.com/MicrochipTech/atsamr34_lorawan_rn_parser/tree/master/01_quick_start_guide/
  37. //https://www.github.com/MicrochipTech/atsamr34_lorawan_rn_parser/tree/master/02_command_guide/
  38. /****************************** INCLUDES **************************************/
  39. #include "system_assert.h"
  40. #include "sw_timer.h"
  41. #include "system_low_power.h"
  42. #include "radio_interface.h"
  43. #include "radio_driver_hal.h"
  44. #include "lorawan.h"
  45. #include "sys.h"
  46. #include "sio2host.h"
  47. #include "parser.h"
  48. #include "parser_tsp.h"
  49. #include "parser_system.h"
  50. #include "system_init.h"
  51. #include "aes_engine.h"
  52. #ifdef CONF_PMM_ENABLE
  53. #include "sleep_timer.h"
  54. #endif /* CONF_PMM_ENABLE */
  55. #if (ENABLE_PDS == 1)
  56. #include "pds_interface.h"
  57. #endif
  58. #include "sal.h"
  59. #include "edbg_eui.h"
  60. /************************** macro definition ***********************************/
  61. /************************** Global variables ***********************************/
  62. /****************************** PROTOTYPES *************************************/
  63. SYSTEM_TaskStatus_t APP_TaskHandler(void);
  64. #if (_DEBUG_ == 1)
  65. static void assertHandler(SystemAssertLevel_t level, uint16_t code);
  66. #endif
  67. /****************************** FUNCTIONS *************************************/
  68. static void print_reset_causes(void)
  69. {
  70. enum system_reset_cause rcause = system_get_reset_cause();
  71. printf("\r\nLast reset cause: ");
  72. if(rcause & (1 << 6)) {
  73. printf("System Reset Request\r\n");
  74. }
  75. if(rcause & (1 << 5)) {
  76. printf("Watchdog Reset\r\n");
  77. }
  78. if(rcause & (1 << 4)) {
  79. printf("External Reset\r\n");
  80. }
  81. if(rcause & (1 << 2)) {
  82. printf("Brown Out 33 Detector Reset\r\n");
  83. }
  84. if(rcause & (1 << 1)) {
  85. printf("Brown Out 12 Detector Reset\r\n");
  86. }
  87. if(rcause & (1 << 0)) {
  88. printf("Power-On Reset\r\n");
  89. }
  90. }
  91. #if (_DEBUG_ == 1)
  92. static void assertHandler(SystemAssertLevel_t level, uint16_t code)
  93. {
  94. printf("\r\n%04x\r\n", code);
  95. (void)level;
  96. }
  97. #endif /* #if (_DEBUG_ == 1) */
  98. /**
  99. * \mainpage
  100. * \section preface Preface
  101. * This is the reference manual for the LORAWAN Parser Application of EU Band
  102. */
  103. int main(void)
  104. {
  105. system_init();
  106. delay_init();
  107. board_init();
  108. INTERRUPT_GlobalInterruptEnable();
  109. sio2host_init();
  110. print_reset_causes();
  111. #if (_DEBUG_ == 1)
  112. SYSTEM_AssertSubscribe(assertHandler);
  113. #endif
  114. /* Configure board button as external interrupt pin */
  115. configure_extint();
  116. /* Register External Interrupt callback */
  117. configure_eic_callback();
  118. printf("LoRaWAN Stack UP\r\n");
  119. HAL_RadioInit();
  120. // Initialize AES only (crypto is on-demand)
  121. SAL_Init(false) ;
  122. // Read edbg eui only once and store in ram
  123. edbg_eui_read() ;
  124. // Initialize Timers
  125. SystemTimerInit();
  126. #ifdef CONF_PMM_ENABLE
  127. SleepTimerInit();
  128. #endif /* CONF_PMM_ENABLE */
  129. #if (ENABLE_PDS == 1)
  130. PDS_Init();
  131. #endif
  132. Stack_Init();
  133. Parser_Init();
  134. Parser_SetConfiguredJoinParameters(0x01);
  135. Parser_GetSwVersion(aParserData);
  136. Parser_TxAddReply((char *)aParserData, (uint16_t)strlen((char *)aParserData));
  137. while (1)
  138. {
  139. parser_serial_data_handler();
  140. SYSTEM_RunTasks();
  141. }
  142. }
  143. SYSTEM_TaskStatus_t APP_TaskHandler(void)
  144. {
  145. Parser_Main();
  146. return SYSTEM_TASK_SUCCESS;
  147. }
  148. /**
  149. End of File
  150. */