@@ -9,16 +9,26 @@ hm2_pktuart - functions to access the Mesa FPGA card packeted UARTs
99
1010*#include hostmot2-serial.h*
1111
12+
1213*int hm2_pktuart_setup(char *name, int bitrate, rtapi_s32 tx_mode, rtapi_s32 rx_mode, int txclear, int rxclear)*
14+
1315*int hm2_pktuart_send(char *name, unsigned char data[], rtapi_u8 *num_frames, rtapi_u16 frame_sizes[])*
16+
1417*int hm2_pktuart_read(char *name, unsigned char data[], rtapi_u8 *num_frames, rtapi_u16 *max_frame_length, rtapi_u16 frame_sizes[])*
18+
1519*int hm2_pktuart_queue_get_frame_sizes(char *name, rtapi_u32 fsizes[])*
20+
1621*int hm2_pktuart_queue_read_data(char *name, rtapi_u32 *data, int bytes)*
22+
1723*int hm2_pktuart_get_clock(char *name)*
24+
1825*int hm2_pktuart_get_version(char *name)*
26+
1927*rtapi_u32 hm2_pktuart_get_rx_status(char *name)*
28+
2029*rtapi_u32 hm2_pktuart_get_tx_status(char *name)*
2130
31+
2232== DESCRIPTION
2333
2434In this context a "Packeted UART" sends data as a burst of bytes
@@ -33,8 +43,8 @@ Instead interfaxes are created to allow secondary drivers to use them.
3343In LinuxCNC v2.8 and earlier the PktUART driver was entirely inactive.
3444In LinuxCNC v2.9 onwards the driver polls the Rx and Tx status registers
3545every servo thread, and these can be read with the functions
36- rtapi_u32 hm2_pktuart_get_rx_status(char *name ) and
37- rtapi_u32 hm2_pktuart_get_tx_status(char *name ).
46+ rtapi_u32 hm2_pktuart_get_rx_status() and
47+ rtapi_u32 hm2_pktuart_get_tx_status().
3848
3949=== Acessing the UARTs ===
4050
@@ -58,7 +68,7 @@ You should refer to the Hostmot2 "regmap" file for up-to-date register
5868setup information. The latest version will normally be found at
5969http://freeby.mesanet.com/regmap.
6070
61- You should use the function **hm2_pktuart_get_version(char *name )** to
71+ You should use the function **hm2_pktuart_get_version()** to
6272check the module version loaded to the FPGA board. This documentation
6373is valid for Rx v0 / v1 and Tx v0. The return value of the function is
647416 * Tx + Rx. If viewed in Hex then 0x01 would indicate Tx v0 and Rx v1
@@ -71,13 +81,14 @@ when read or written.
7181
7282To configure the UART use
7383
74- *int hm2_pktuart_setup(char * name, int bitrate, rtapi_s32 tx_mode, rtapi_s32 rx_mode, int txclear, int rxclear)*
84+ *int hm2_pktuart_setup(name, bitrate, tx_mode, rx_mode, txclear, rxclear)*
7585
7686**bitrate** is simply the bitrate. (eg 9600, 115200 etc).
7787
7888**txmode** is built up from the following bits (directly copied from the
7989regmap)
8090
91+ ----
8192 Bit 17 Parity enable WO
8293 Bit 18 Odd Parity WO (1=odd, 0=even)
8394 Bits 15..8 InterFrame delay in bit times RW
@@ -88,9 +99,12 @@ regmap)
8899 to start of data transmit. In Clock Low periods RW
89100 Drive enable delay is important to avoid start bit timing errors
90101 at high baud rates in RS-485 (half duplex) modes
102+ ----
91103
92104A reasonable starting value for txmode is **0x00000A20**
93105
106+ ----
107+
94108**rxmode** is built from the following:
95109
96110 Bits 29..22 RX data digital filter (in ClockLow periods)
@@ -102,11 +116,11 @@ A reasonable starting value for txmode is **0x00000A20**
102116 Bit 6 RXMask RO
103117 Bit 3 RXEnable (must be set to receive packets) RW
104118 Bit 2 RXMask Enable (enables input data masking when transmitting) RW
105-
119+ ----
106120For low baudrates **0x3FC0140C** will generally work, but the filter bits
107121should really be set according to the actual baudrate.
108122
109- The function **int hm2_pktuart_get_clock(char * name)** is provided to
123+ The function **int hm2_pktuart_get_clock(name)** is provided to
110124enable calculation of the required filter period. It returns units of Hz.
111125
112126[Note] It is expected that v2 of Rx will extend the number of bits in
@@ -115,12 +129,15 @@ the filter definition for better behaviour at low bitrates.
115129=== Direct reads and writes ===
116130
117131The function:
118- *int hm2_pktuart_send(char *name, unsigned char data[], rtapi_u8 *num_frames, rtapi_u16 frame_sizes[])*
132+
133+ *int hm2_pktuart_send()*
119134
120135Will always use the hm2_llio_queue_write function where available.
121136
122137However:
123- *int hm2_pktuart_read(char *name, unsigned char data[], rtapi_u8 *num_frames, rtapi_u16 *max_frame_length, rtapi_u16 frame_sizes[])*
138+
139+ *int hm2_pktuart_read()*
140+
124141Will force an immediate read transaction. It may be used in setup and
125142teardown code, but should not be called in the realtime functions as
126143this will cause extra packets to be transmitted.
@@ -132,8 +149,9 @@ In the realtime threads the queued reads and writes should be used. This
132149means that most transactions will be spread over more than one thread
133150period.
134151
135- *rtapi_u32 hm2_pktuart_get_rx_status(char *name)*
136- *rtapi_u32 hm2_pktuart_get_tx_status(char *name)*
152+ *rtapi_u32 hm2_pktuart_get_rx_status(name)*
153+
154+ *rtapi_u32 hm2_pktuart_get_tx_status(name)*
137155
138156These functions will always return the latest status from the most
139157recent data packet from the FPGA. The status should be used to check if
@@ -142,13 +160,18 @@ transmissions.
142160
143161The Tx status is encoded as:
144162
163+ ----
164+
145165Bit 21 FrameBuffer Has Data RO
146166Bits 20..16 Frames to send RO
147167Bit 7 Send busy RO
148168Bit 4 SCFIFO Error RO
169+ ----
149170
150171The Rx status is:
151172
173+ ----
174+
152175Bit 21 FrameBuffer has data RO
153176Bits 20..16 Frames received RO
154177Bit 7 Buffer error (RX idle but data in RX data FIFO) RO
@@ -157,14 +180,15 @@ Bit 5 Parity Error RW
157180Bit 4 RCFIFO Error RW
158181Bit 1 Overrun error (no stop bit when expected) (sticky) RW
159182Bit 0 False Start bit error (sticky) RW
183+ ----
160184
161185Based on the status of the Rx and Tx components reads or writes from the
162186FPGA can then be set up. This is typically a multi-step process:
163187
1641881) rxstatus indicates that there are packets of data, but at this point
165189we need to know how big each packet is (and reading two much or two
166190little data from the FIFOs will cause problems).
167- 2) Queue a read of the frame sizes. **hm2_pktuart_queue_get_frame_sizes(char * name, rtapi_u32 fsizes[])**
191+ 2) Queue a read of the frame sizes. **hm2_pktuart_queue_get_frame_sizes(name, fsizes[])**
168192On return, the fsizes[] array will have been loaded with the frame sizes
169193(size in bytes). If fsizes are [8] [7] [6] and you only read 1 frame from
170194the data FIFO then on the next call to get_frame_sizes the returned array
@@ -173,7 +197,7 @@ would be [7] [6].
173197latency here, the data is already on the FPGA but we can only know how
174198much data to request once we know the packet size
1751994) Queue enough data reads to get all the data frames that the packet
176- is spread over. **int hm2_pktuart_queue_read_data(char * name, rtapi_u32 * data, int bytes)**
200+ is spread over. **int hm2_pktuart_queue_read_data(name, data, bytes)**
177201On return the data[] array will have been loaded with enough 32-bit
178202frames to include "bytes" bytes.
1792035) Parse the data.
@@ -204,6 +228,8 @@ some steps will have serial-port latency delays it is recommended to use
204228a state machine in the realtime code where waiting on input is not
205229possible.
206230
231+ [source, C]
232+ ----
207233int process(void *arg, long period) {
208234 static int state = START;
209235
@@ -261,7 +287,7 @@ int process(void *arg, long period) {
261287 break;
262288 }
263289}
264-
290+ ----
265291
266292
267293== PINS
0 commit comments