Embedded System Design 2 - Project
lora.c
Go to the documentation of this file.
1 /* ____ ____ _ __ __ ____ ___
2  * | _ \| _ \ / \ | \/ |/ ___/ _ \
3  * | | | | |_) | / _ \ | |\/| | | | | | |
4  * | |_| | _ < / ___ \| | | | |__| |_| |
5  * |____/|_| \_\/_/ \_\_| |_|\____\___/
6  * research group
7  * dramco.be/
8  *
9  * KU Leuven - Technology Campus Gent,
10  * Gebroeders De Smetstraat 1,
11  * B-9000 Gent, Belgium
12  *
13  * File: lora.c
14  * Created: 2018-03-21
15  * Author: Geoffrey Ottoy - Modified by Brecht Van Eeckhoudt
16  *
17  * Description: Basic LoRaWAN functionality (uses the RN2483 modem).
18  */
19 
20 
21 #include "lora.h" /* Corresponding header file */
22 
23 #include "lpp.h" /* LPP_Buffer_t definition */
24 #include "pm.h" /* PM_Enable */
25 #include "rn2483.h" /* RN2483_xxxx */
26 
27 #include "delay.h" /* Delay functionality */
28 #include "pin_mapping.h" /* PORT and PIN definitions */
29 #include "debug_dbprint.h" /* Enable or disable printing to UART for debugging */
30 
31 
32 #define LORA_BUFFERSIZE 64
33 #define MAX_JOIN_RETRIES 5
34 
36 
39 
40  RN2483_Init();
41 
42  int retries = 0;
43  while(retries < MAX_JOIN_RETRIES){
45  break;
46  }
47  retries++;
48 
49 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
50  dbwarnInt("Retry join in 5 seconds (LoRa_Init) (", retries, ")\n\r");
51 #endif /* DEBUG_DBPRINT */
52 
53  delay(5000);
54  }
55  if(retries == MAX_JOIN_RETRIES){
56  return (ERROR);
57  }
58  return (JOINED);
59 }
60 
62  if(ackNoAck == LORA_CONFIRMED){ // Not tested yet !!
64  return (ERROR);
65  }
66  return (SUCCESS);
67  }
68  else{
70  return (ERROR);
71  }
72  return (SUCCESS);
73  }
74 }
75 
76 void LoRa_Sleep(uint32_t durationMs, volatile bool * wakeUp){
77  RN2483_Sleep(durationMs, wakeUp, loraReceiveBuffer, LORA_BUFFERSIZE);
78 }
79 
82  return (ERROR);
83  }
84  return (SUCCESS);
85 }
86 
87 
Definition: lora.h:36
uint8_t fill
Definition: lpp.h:41
RN2483_Status_t RN2483_Wake(char *receiveBuffer, uint8_t bufferSize)
Definition: rn2483.c:379
void PM_Enable(PM_SubSystem_t pmss)
Definition: pm.c:33
Definition: rn2483.h:46
enum lora_statuses LoRaStatus_t
Basic Low Power Payload (LPP) functionality.
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:598
#define LORA_BUFFERSIZE
Definition: lora.c:32
Definition: lpp.h:38
void LoRa_Sleep(uint32_t durationMs, volatile bool *wakeUp)
Definition: lora.c:76
Definition: lora.h:34
#define LORA_CONFIRMED
Definition: lora.h:24
RN2483_Status_t RN2483_TransmitConfirmed(uint8_t *data, uint8_t payloadSize, char *receiveBuffer, uint8_t bufferSize)
Definition: rn2483.c:354
ADC_Init_TypeDef init
Definition: adc.c:71
RN2483_Status_t RN2483_Setup(LoRaSettings_t settings, char *receiveBuffer, uint8_t bufferSize)
Definition: rn2483.c:270
uint8_t * buffer
Definition: lpp.h:40
void RN2483_Init(void)
Definition: rn2483.c:123
Definition: lora.h:35
RN2483_Status_t RN2483_TransmitUnconfirmed(uint8_t *data, uint8_t payloadSize, char *receiveBuffer, uint8_t bufferSize)
Definition: rn2483.c:339
The pin definitions for the regular and custom Happy Gecko board.
LoRaStatus_t LoRa_Init(LoRaSettings_t init)
Definition: lora.c:37
Delay functionality.
Enable or disable printing to UART with dbprint.
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:124
char loraReceiveBuffer[64]
Definition: lora.c:35
LoRaStatus_t LoRa_WakeUp(void)
Definition: lora.c:80
LoRaStatus_t LoRa_SendLppBuffer(LPP_Buffer_t b, bool ackNoAck)
Definition: lora.c:61
Definition: rn2483.h:34
RN2483_Status_t RN2483_Sleep(uint32_t sleepTime, volatile bool *wakeUp, char *receiveBuffer, uint8_t bufferSize)
Definition: rn2483.c:374
Definition: pm.h:26
#define MAX_JOIN_RETRIES
Definition: lora.c:33