Firmware SDK
twr_module_rs485.h
1 #ifndef _TWR_MODULE_RS485_H
2 #define _TWR_MODULE_RS485_H
3 
4 #include "twr_tick.h"
5 #include "twr_sc16is740.h"
6 #include "twr_scheduler.h"
7 #include "twr_fifo.h"
8 
12 
14 
15 typedef enum
16 {
19 
22 
25 
28 
31 
33 
35 
36 typedef enum
37 {
38  TWR_MODULE_RS485_BAUDRATE_9600 = TWR_SC16IS740_BAUDRATE_9600,
39  TWR_MODULE_RS485_BAUDRATE_19200 = TWR_SC16IS740_BAUDRATE_19200,
40  TWR_MODULE_RS485_BAUDRATE_38400 = TWR_SC16IS740_BAUDRATE_38400,
41  TWR_MODULE_RS485_BAUDRATE_57600 = TWR_SC16IS740_BAUDRATE_57600,
42  TWR_MODULE_RS485_BAUDRATE_115200 = TWR_SC16IS740_BAUDRATE_115200
43 
45 
49 
50 bool twr_module_rs485_init(void);
51 
55 
56 bool twr_module_rs485_deinit(void);
57 
61 
62 bool twr_module_rs485_measure(void);
63 
66 
67 bool twr_module_rs485_get_voltage(float *volt);
68 
72 
73 void twr_module_rs485_set_event_handler(void (*event_handler)(twr_module_rs485_event_t, void *), void *event_param);
74 
77 
79 
83 
84 size_t twr_module_rs485_write(uint8_t *buffer, size_t length);
85 
88 
89 bool twr_module_rs485_available(size_t *available);
90 
95 
96 size_t twr_module_rs485_read(uint8_t *buffer, size_t length, twr_tick_t timeout);
97 
103 
105 
109 
110 void twr_module_rs485_set_async_fifo(twr_fifo_t *write_fifo, twr_fifo_t *read_fifo);
111 
116 
117 size_t twr_module_rs485_async_write(uint8_t *buffer, size_t length);
118 
123 
125 
129 
131 
136 
137 size_t twr_module_rs485_async_read(void *buffer, size_t length);
138 
140 
141 #endif
bool twr_module_rs485_measure(void)
Start single voltage measurement.
size_t twr_module_rs485_read(uint8_t *buffer, size_t length, twr_tick_t timeout)
Read the received data.
size_t twr_module_rs485_async_write(uint8_t *buffer, size_t length)
Add data to be transmited in async mode.
void twr_module_rs485_set_event_handler(void(*event_handler)(twr_module_rs485_event_t, void *), void *event_param)
Set callback function.
size_t twr_module_rs485_write(uint8_t *buffer, size_t length)
Write data to RS-485 bus.
twr_module_rs485_event_t
Callback events.
void twr_module_rs485_set_async_fifo(twr_fifo_t *write_fifo, twr_fifo_t *read_fifo)
Set FIFO.
bool twr_module_rs485_get_voltage(float *volt)
Get measured voltage.
bool twr_module_rs485_available(size_t *available)
Get number of received bytes.
bool twr_module_rs485_deinit(void)
Deinitialize RS-485 Module.
size_t twr_module_rs485_async_read(void *buffer, size_t length)
Get data that has been received in async mode.
bool twr_module_rs485_init(void)
Initialize RS-485 Module.
bool twr_module_rs485_async_read_start(twr_tick_t timeout)
Start async reading.
bool twr_module_rs485_set_baudrate(twr_module_rs485_baudrate_t baudrate)
Set baudrate.
twr_module_rs485_baudrate_t
Baudrates.
void twr_module_rs485_set_update_interval(twr_tick_t interval)
Set measurement interval.
bool twr_module_rs485_async_read_stop(void)
Stop async reading.
@ TWR_MODULE_RS485_EVENT_ASYNC_READ_DATA
Reading done event.
@ TWR_MODULE_RS485_EVENT_ERROR
Error event.
@ TWR_MODULE_RS485_EVENT_VOLTAGE
Update event.
@ TWR_MODULE_RS485_EVENT_ASYNC_READ_TIMEOUT
Timeout event.
@ TWR_MODULE_RS485_EVENT_ASYNC_WRITE_DONE
Async write done.
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16
Structure of FIFO instance.
Definition: twr_fifo.h:13