upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
rn2903_defs.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 // maximum buffer size
32 #define RN2903_MAX_BUFFER (512)
33 
34 // size of hex encoded 64b EUI (IPV6 Extended Unique Identifier)
35 #define RN2903_MAX_HEX_EUI64 (16)
36 
37 // default baudrate
38 #define RN2903_DEFAULT_BAUDRATE (57600)
39 
40 // response wait times in milliseconds
41 #define RN2903_DEFAULT_RESP_DELAY (1000) // 1 second
42 #define RN2903_DEFAULT_RESP2_DELAY (60000) // 60 seconds
43 
44 // This byte sequence must follow all commands. All responses
45 // will also be followed by these bytes (\r\n - CR LF).
46 #define RN2903_PHRASE_TERM "\r\n"
47 #define RN2903_PHRASE_TERM_LEN (2)
48 
49 // invalid parameter
50 #define RN2903_PHRASE_INV_PARAM "invalid_param"
51 // ok
52 #define RN2903_PHRASE_OK "ok"
53 
54  // RN2903_MAC_STATUS_BITS_T from "mac get status" cmd
55  typedef enum {
56  RN2903_MAC_STATUS_JOINED = 0x0001,
57 
58  RN2903_MAC_STATUS_MAC_STATUS0 = 0x0002,
59  RN2903_MAC_STATUS_MAC_STATUS1 = 0x0004,
60  RN2903_MAC_STATUS_MAC_STATUS2 = 0x0008,
61  _RN2903_MAC_STATUS_MAC_STATUS_MASK = 7,
62  _RN2903_MAC_STATUS_MAC_STATUS_SHIFT = 1,
63 
64  RN2903_MAC_STATUS_AUTO_REPLY = 0x0010,
65  RN2903_MAC_STATUS_ADR = 0x0020,
66  RN2903_MAC_STATUS_SILENT = 0x0040,
67  RN2903_MAC_STATUS_PAUSED = 0x0080,
68  RN2903_MAC_STATUS_RFU = 0x0100,
69  RN2903_MAC_STATUS_LINK_CHK = 0x0200,
70 
71  RN2903_MAC_STATUS_CHAN_UPD = 0x0400,
72  RN2903_MAC_STATUS_OUT_PWR_UPD = 0x0800,
73  RN2903_MAC_STATUS_NBREP_UPD = 0x1000,
74  RN2903_MAC_STATUS_PRESCALER_UPD = 0x2000,
75  RN2903_MAC_STATUS_SECOND_RX_UPD = 0x4000,
76  RN2903_MAC_STATUS_TX_TIMING_UPD = 0x8000,
77  } RN2903_MAC_STATUS_BITS_T;
78 
79  // RN2903_MAC_STATUS_MAC_STATUS values
80  typedef enum {
81  RN2903_MAC_STAT_IDLE = 0,
82  RN2903_MAC_STAT_TX_IN_PROGESS = 1,
83  RN2903_MAC_STAT_BEFORE_RX_WIN1 = 2,
84  RN2903_MAC_STAT_RX_WIN1_OPEN = 3,
85  RN2903_MAC_STAT_BETWEEN_RX_WIN1_WIN2 = 4,
86  RN2903_MAC_STAT_RX_WIN2_OPEN = 5,
87  RN2903_MAC_STAT_ACK_TIMEOUT = 6,
88  } RN2903_MAC_STATUS_T;
89 
90  // Join types
91  typedef enum {
92  RN2903_JOIN_TYPE_OTAA = 0, // over-the-air-activation
93  RN2903_JOIN_TYPE_ABP = 1, // activation-by
94  // personalization
95  } RN2903_JOIN_TYPE_T;
96 
97  // Join status
98  typedef enum {
99  RN2903_JOIN_STATUS_ACCEPTED = 0,
100  RN2903_JOIN_STATUS_BAD_KEYS = 1,
101  RN2903_JOIN_STATUS_NO_CHAN = 2,
102  RN2903_JOIN_STATUS_SILENT = 3,
103  RN2903_JOIN_STATUS_BUSY = 4,
104  RN2903_JOIN_STATUS_MAC_PAUSED = 5,
105  RN2903_JOIN_STATUS_DENIED = 6,
106  RN2903_JOIN_STATUS_ALREADY_JOINED = 7,
107  RN2903_JOIN_STATUS_UPM_ERROR = 8,
108  } RN2903_JOIN_STATUS_T;
109 
110  // possible flow control methods
111  typedef enum {
112  RN2903_FLOW_CONTROL_NONE = 0,
113  RN2903_FLOW_CONTROL_HARD, // hardware flow control
114  } RN2903_FLOW_CONTROL_T;
115 
116  // MAC TX message types
117  typedef enum {
118  RN2903_MAC_MSG_TYPE_UNCONFIRMED = 0,
119  RN2903_MAC_MSG_TYPE_CONFIRMED = 1,
120  } RN2903_MAC_MSG_TYPE_T;
121 
122  // MAC TX status
123  typedef enum {
124  RN2903_MAC_TX_STATUS_TX_OK = 0, // tx was sent successfully
125  RN2903_MAC_TX_STATUS_NOT_JOINED = 1,
126  RN2903_MAC_TX_STATUS_NO_CHAN = 2,
127  RN2903_MAC_TX_STATUS_SILENT = 3,
128  RN2903_MAC_TX_STATUS_FC_NEED_REJOIN = 4, // frame counter overflow
129  RN2903_MAC_TX_STATUS_BUSY = 5,
130  RN2903_MAC_TX_STATUS_MAC_PAUSED = 6,
131  RN2903_MAC_TX_STATUS_BAD_DATA_LEN = 7,
132  RN2903_MAC_TX_STATUS_RX_RECEIVED = 8, // received a packet
133  RN2903_MAC_TX_STATUS_MAC_ERR = 9, // error during tx
134  RN2903_MAC_TX_STATUS_UPM_ERROR = 10, // error during tx
135  } RN2903_MAC_TX_STATUS_T;
136 
137  // last command status
138  typedef enum {
139  RN2903_RESPONSE_OK = 0, // "ok", or data
140  RN2903_RESPONSE_INVALID_PARAM = 1, // "invalid_param"
141  RN2903_RESPONSE_TIMEOUT = 3,
142  RN2903_RESPONSE_UPM_ERROR = 4,
143  } RN2903_RESPONSE_T;
144 
145 #ifdef __cplusplus
146 }
147 #endif