Firmware SDK
twr_module_rs485

Driver for RS-485 Module. More...

Enumerations

enum  twr_module_rs485_event_t {
  TWR_MODULE_RS485_EVENT_ERROR = 0 ,
  TWR_MODULE_RS485_EVENT_VOLTAGE = 1 ,
  TWR_MODULE_RS485_EVENT_ASYNC_WRITE_DONE = 2 ,
  TWR_MODULE_RS485_EVENT_ASYNC_READ_DATA = 2 ,
  TWR_MODULE_RS485_EVENT_ASYNC_READ_TIMEOUT = 3
}
 Callback events. More...
 
enum  twr_module_rs485_baudrate_t {
  TWR_MODULE_RS485_BAUDRATE_9600 = TWR_SC16IS740_BAUDRATE_9600 ,
  TWR_MODULE_RS485_BAUDRATE_19200 = TWR_SC16IS740_BAUDRATE_19200 ,
  TWR_MODULE_RS485_BAUDRATE_38400 = TWR_SC16IS740_BAUDRATE_38400 ,
  TWR_MODULE_RS485_BAUDRATE_57600 = TWR_SC16IS740_BAUDRATE_57600 ,
  TWR_MODULE_RS485_BAUDRATE_115200 = TWR_SC16IS740_BAUDRATE_115200
}
 Baudrates.
 

Functions

bool twr_module_rs485_init (void)
 Initialize RS-485 Module. More...
 
bool twr_module_rs485_deinit (void)
 Deinitialize RS-485 Module. More...
 
bool twr_module_rs485_measure (void)
 Start single voltage measurement. More...
 
bool twr_module_rs485_get_voltage (float *volt)
 Get measured voltage. More...
 
void twr_module_rs485_set_event_handler (void(*event_handler)(twr_module_rs485_event_t, void *), void *event_param)
 Set callback function. More...
 
void twr_module_rs485_set_update_interval (twr_tick_t interval)
 Set measurement interval. More...
 
size_t twr_module_rs485_write (uint8_t *buffer, size_t length)
 Write data to RS-485 bus. More...
 
bool twr_module_rs485_available (size_t *available)
 Get number of received bytes. More...
 
size_t twr_module_rs485_read (uint8_t *buffer, size_t length, twr_tick_t timeout)
 Read the received data. More...
 
bool twr_module_rs485_set_baudrate (twr_module_rs485_baudrate_t baudrate)
 Set baudrate. More...
 
void twr_module_rs485_set_async_fifo (twr_fifo_t *write_fifo, twr_fifo_t *read_fifo)
 Set FIFO. More...
 
size_t twr_module_rs485_async_write (uint8_t *buffer, size_t length)
 Add data to be transmited in async mode. More...
 
bool twr_module_rs485_async_read_start (twr_tick_t timeout)
 Start async reading. More...
 
bool twr_module_rs485_async_read_stop (void)
 Stop async reading. More...
 
size_t twr_module_rs485_async_read (void *buffer, size_t length)
 Get data that has been received in async mode. More...
 

Detailed Description

Driver for RS-485 Module.

Enumeration Type Documentation

◆ twr_module_rs485_event_t

Callback events.

Enumerator
TWR_MODULE_RS485_EVENT_ERROR 

Error event.

TWR_MODULE_RS485_EVENT_VOLTAGE 

Update event.

TWR_MODULE_RS485_EVENT_ASYNC_WRITE_DONE 

Async write done.

TWR_MODULE_RS485_EVENT_ASYNC_READ_DATA 

Reading done event.

TWR_MODULE_RS485_EVENT_ASYNC_READ_TIMEOUT 

Timeout event.

Definition at line 15 of file twr_module_rs485.h.

Function Documentation

◆ twr_module_rs485_async_read()

size_t twr_module_rs485_async_read ( void *  buffer,
size_t  length 
)

Get data that has been received in async mode.

Parameters
[in]bufferPointer to buffer
[in]lengthMaximum length of received data
Returns
Number of received bytes

Definition at line 406 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_async_read_start()

bool twr_module_rs485_async_read_start ( twr_tick_t  timeout)

Start async reading.

Parameters
[in]timeoutMaximum timeout in ms
Returns
true On success
false On failure

Definition at line 379 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_async_read_stop()

bool twr_module_rs485_async_read_stop ( void  )

Stop async reading.

Returns
true On success
false On failure

Definition at line 393 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_async_write()

size_t twr_module_rs485_async_write ( uint8_t *  buffer,
size_t  length 
)

Add data to be transmited in async mode.

Parameters
[in]bufferPointer to buffer
[in]lengthLength of data to be added
Returns
Number of bytes added

Definition at line 358 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_available()

bool twr_module_rs485_available ( size_t *  available)

Get number of received bytes.

Parameters
[out]availableNumber of received bytes

Definition at line 427 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_deinit()

bool twr_module_rs485_deinit ( void  )

Deinitialize RS-485 Module.

Returns
true On success
false When module is not detected

Definition at line 110 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_get_voltage()

bool twr_module_rs485_get_voltage ( float *  volt)

Get measured voltage.

Parameters
[out]voltMeasured voltage in volts

Definition at line 146 of file twr_module_rs485.c.

◆ twr_module_rs485_init()

bool twr_module_rs485_init ( void  )

Initialize RS-485 Module.

Returns
true On success
false When module is not detected

Definition at line 63 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_measure()

bool twr_module_rs485_measure ( void  )

Start single voltage measurement.

Returns
true On success
false When other measurement is in progress

Definition at line 167 of file twr_module_rs485.c.

Referenced by twr_module_rs485_set_update_interval().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_module_rs485_read()

size_t twr_module_rs485_read ( uint8_t *  buffer,
size_t  length,
twr_tick_t  timeout 
)

Read the received data.

Parameters
[out]bufferPointer to the buffer where the data will be copied
[in]lengthSize of the buffer
[in]timeoutReceive timeout. Write 0 for no timeout

Definition at line 432 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_set_async_fifo()

void twr_module_rs485_set_async_fifo ( twr_fifo_t write_fifo,
twr_fifo_t read_fifo 
)

Set FIFO.

Parameters
[in]write_fifoPointer to the created and initialized write FIFO
[in]read_fifoPointer to the created and initialized read FIFO

Definition at line 352 of file twr_module_rs485.c.

◆ twr_module_rs485_set_baudrate()

bool twr_module_rs485_set_baudrate ( twr_module_rs485_baudrate_t  baudrate)

Set baudrate.

Parameters
[in]selfInstance
[in]baudrate
Returns
true On success
false On failure

Definition at line 437 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_set_event_handler()

void twr_module_rs485_set_event_handler ( void(*)(twr_module_rs485_event_t, void *)  event_handler,
void *  event_param 
)

Set callback function.

Parameters
[in]event_handlerFunction address
[in]event_paramOptional event parameter (can be NULL)

Definition at line 416 of file twr_module_rs485.c.

◆ twr_module_rs485_set_update_interval()

void twr_module_rs485_set_update_interval ( twr_tick_t  interval)

Set measurement interval.

Parameters
[in]intervalMeasurement interval

Definition at line 130 of file twr_module_rs485.c.

Here is the call graph for this function:

◆ twr_module_rs485_write()

size_t twr_module_rs485_write ( uint8_t *  buffer,
size_t  length 
)

Write data to RS-485 bus.

Parameters
[in]bufferData to send
[in]intervalNumber of bytes to send

Definition at line 422 of file twr_module_rs485.c.

Here is the call graph for this function: