Firmware SDK
twr_td1207r.h
1 #ifndef _TWR_TD1207R_H
2 #define _TWR_TD1207R_H
3 
4 #include <twr_scheduler.h>
5 #include <twr_gpio.h>
6 #include <twr_uart.h>
7 
11 
13 
14 #define TWR_TD1207R_TX_FIFO_BUFFER_SIZE 64
15 #define TWR_TD1207R_RX_FIFO_BUFFER_SIZE 64
16 
18 
20 
21 typedef enum
22 {
25 
28 
31 
34 
36 
38 
39 typedef struct twr_td1207r_t twr_td1207r_t;
40 
42 
43 typedef enum
44 {
45  TWR_TD1207R_STATE_READY = 0,
46  TWR_TD1207R_STATE_ERROR = 1,
47  TWR_TD1207R_STATE_INITIALIZE = 2,
48  TWR_TD1207R_STATE_INITIALIZE_RESET_L = 3,
49  TWR_TD1207R_STATE_INITIALIZE_RESET_H = 4,
50  TWR_TD1207R_STATE_INITIALIZE_AT_COMMAND = 5,
51  TWR_TD1207R_STATE_INITIALIZE_AT_RESPONSE = 6,
52  TWR_TD1207R_STATE_SEND_RF_FRAME_COMMAND = 7,
53  TWR_TD1207R_STATE_SEND_RF_FRAME_RESPONSE = 8
54 
55 } twr_td1207r_state_t;
56 
57 struct twr_td1207r_t
58 {
59  twr_scheduler_task_id_t _task_id;
60  twr_gpio_channel_t _reset_signal;
61  twr_uart_channel_t _uart_channel;
62  twr_td1207r_state_t _state;
63  twr_fifo_t _tx_fifo;
64  twr_fifo_t _rx_fifo;
65  uint8_t _tx_fifo_buffer[TWR_TD1207R_TX_FIFO_BUFFER_SIZE];
66  uint8_t _rx_fifo_buffer[TWR_TD1207R_RX_FIFO_BUFFER_SIZE];
67  void (*_event_handler)(twr_td1207r_t *, twr_td1207r_event_t, void *);
68  void *_event_param;
69  char _command[TWR_TD1207R_TX_FIFO_BUFFER_SIZE];
70  char _response[TWR_TD1207R_RX_FIFO_BUFFER_SIZE];
71  uint8_t _message_buffer[12];
72  size_t _message_length;
73 };
74 
76 
81 
82 void twr_td1207r_init(twr_td1207r_t *self, twr_gpio_channel_t reset_signal, twr_uart_channel_t uart_channel);
83 
88 
89 void twr_td1207r_set_event_handler(twr_td1207r_t *self, void (*event_handler)(twr_td1207r_t *, twr_td1207r_event_t, void *), void *event_param);
90 
95 
97 
104 
105 bool twr_td1207r_send_rf_frame(twr_td1207r_t *self, const void *buffer, size_t length);
106 
108 
109 #endif // _TWR_TD1207R_H
twr_gpio_channel_t
GPIO channels.
Definition: twr_gpio.h:13
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
bool twr_td1207r_send_rf_frame(twr_td1207r_t *self, const void *buffer, size_t length)
Send RF frame command.
Definition: twr_td1207r.c:47
bool twr_td1207r_is_ready(twr_td1207r_t *self)
Check if modem is ready for commands.
Definition: twr_td1207r.c:42
void twr_td1207r_init(twr_td1207r_t *self, twr_gpio_channel_t reset_signal, twr_uart_channel_t uart_channel)
Initialize TD1207R.
Definition: twr_td1207r.c:13
void twr_td1207r_set_event_handler(twr_td1207r_t *self, void(*event_handler)(twr_td1207r_t *, twr_td1207r_event_t, void *), void *event_param)
Set callback function.
Definition: twr_td1207r.c:36
twr_td1207r_event_t
Callback events.
Definition: twr_td1207r.h:22
struct twr_td1207r_t twr_td1207r_t
TD1207R instance.
Definition: twr_td1207r.h:39
@ TWR_TD1207R_EVENT_SEND_RF_FRAME_DONE
RF frame transmission finished event.
Definition: twr_td1207r.h:33
@ TWR_TD1207R_EVENT_READY
Ready event.
Definition: twr_td1207r.h:24
@ TWR_TD1207R_EVENT_SEND_RF_FRAME_START
RF frame transmission started event.
Definition: twr_td1207r.h:30
@ TWR_TD1207R_EVENT_ERROR
Error event.
Definition: twr_td1207r.h:27
twr_uart_channel_t
UART channels.
Definition: twr_uart.h:14
Structure of FIFO instance.
Definition: twr_fifo.h:13