PRU-based high performance serial communication
Author:
Patricia H. Nallin ( patricia.nallin@lnls.br )
Enter the folder src
and run make install
. This will compile PRU and host codes, install it to your Beaglebone and create a Python module to use these libraries.
Before using it
-
Apply the Device Tree Overlay (DTO) to configure Beaglebone pins to PRU. Run
overlay.sh
script each time you restart your Beaglebone. -
In your python3 code, you can just:
import PRUserial485
It is not needed to copy any library files to your project.
General Purpose
-
PRUserial485_open(int baudrate, char mode)
PRU initialization. Shared memory configuration and loading binaries into PRU.
- baudrate:
RS485 serial desired baudrate. Available: 9600, 14400, 19200, 38400, 57600, 115200 bps and 6, 10, 12 Mbps - mode:
"M" for master and "S" for slave mode.
- baudrate:
-
PRUserial485_address()
Gets SERIALxxCON board address (hardware defined) Returns: integer value (0 to 31)
-
PRUserial485_close()
Closes PRUs and memory mapping.
-
PRUserial485_write(bytes, float timeout)
Sending data through RS485 network
Parameters
- data:
Python bytes containing values to be transmitted through serial network. - timeout:
Maximum waiting time to start getting an answer, in milliseconds (ms). Minimum: 15ns / Maximum: 64s. If 0, does not wait for response. ATTENTION: in slave mode, this parameter is ignored.
Return
- MASTER MODE:
Returns only after response received (valid response, timeout or ignored) - SLAVE MODE:
Returns just after data completely sent.
- data:
-
PRUserial485_read(uint32_t nbytes)
Receiving data through RS485 network
Parameters
- nbytes (OPTIONAL):
Number of bytes to read. If empty or 0, all data will be read. If nbytes is greater than available bytes, return all available bytes. Note: This function does not block or wait for incoming data.
Return: bytes corresponding to data received.
- nbytes (OPTIONAL):
-
PRUserial485_read_flush()
Flush receive FIFO buffer.
Curves
-
PRUserial485_curve(int block, [float_list curve1, float_list curve2, float_list curve3, float_list curve4])
Storing curves into memory. Each curve correspond to a power supply in the crate.
Parameters
- curveX:
Python float list containing curve points, up to 6250 points. Curves must all have same length. - block:
Identification of block which will be loaded with curve points. (0 to 3)
- curveX:
-
PRUserial485_set_curve_block(int block)
Selection of block which will be performed in next cycle. Default value is 0.
Parameters
- block:
Identification of block (0 to 3)
- block:
-
PRUserial485_read_curve_block()
Read block identification which will be performed in next cycle.
Returns: Block identification (0 to 3)
-
PRUserial485_set_curve_pointer(int next_point)
Selection of point of curve that will be performed after the next sync pulse
Parameters
- next_point:
index of next point (0 to (len(curve)-1))
- next_point:
-
PRUserial485_read_curve_pointer()
Read curve index (point) which will be sent in next sync pulse.
Returns: index of next point (0 to (len(curve)-1))
Sync Operation
-
PRUserial485_sync_start(int sync_mode, float delay, int sync_address)
Sync mode operation.
Parameters
- sync_mode:
| 0x51 - Single curve sequence & Intercalated read messages
| 0x5E - Single curve sequence & Read messages at End of curve
| 0xC1 - Continuous curve sequence & Intercalated read messages
| 0xCE - Continuous curve sequence & Read messages at End of curve
| 0x5B - Single Sequence - Single Broadcast Function command - delay:
time between end of sync serial message and start of a normal message, when sending normal commands after sync pulses. - sync_address:
PS Controller address to which setpoints will be addressed to. Parameter only needed if sync_mode != 0x5B
- sync_mode:
-
PRUserial485_sync_stop()
Stops sync operation mode.
-
PRUserial485_sync_status()
Verifies whether PRU is waiting for a sync pulse or not
Returns: 1 if true, 0 if false
-
PRUserial485_read_pulse_count_sync()
Read number of sync pulses already received.
Returns: counting value (0 to (2^32 - 1))
-
PRUserial485_clear_pulse_count_sync()
Clears pulse counting registers. Action is only performed if sync mode is disabled.