AM243x MCU+ SDK  08.04.00
endat_api.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPgResS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * \par
35  *
36  *
37  * Example API usage (host trigger mode, single channel):
38  * ------------------------------------------------------
39  *
40  * A. Obtain handle
41  *
42  * struct endat_priv priv = endat_init(<interface base>);
43  * [AM437x: endat_init(0x54440000);]
44  *
45  * B. Configure to host trigger mode
46  *
47  * endat_config_host_trigger(priv);
48  *
49  * C. Select channel
50  *
51  * endat_config_channel(priv, <#channel>);
52  *
53  * D. Load & run the firmware
54  *
55  * E. Wait for firmware to initialize, clock frequency would be set to 8MHz by the end of the following command
56  *
57  * endat_wait_initialization(priv, <timeout>);
58  *
59  * F. Set 200KHz frequency to read encoder information so as to not to be affected by propagation delay
60  *
61  * endat_config_clock(priv, clk_cfg);
62  *
63  * G. Get encoder information
64  *
65  * endat_get_encoder_info(priv);
66  *
67  * H. Set operating frequency, say 8MHz
68  *
69  * endat_config_clock(priv, &clk_cfg);
70  *
71  * I. Get the propagation delay estimated by the firmware
72  *
73  * prop_delay = endat_get_prop_delay(priv);
74  *
75  * J. Handle propagation delay
76  *
77  * endat_config_rx_arm_cnt(priv, <prop_delay (minimum 2T, T - period of operating frequency)>);
78  * endat_config_rx_clock_disable(priv, <prop_delay - 2T (if < 0, use 0)>);
79  *
80  * K. Configure tST
81  *
82  * endat_config_tst_delay(priv, <tST delay (if f > 1MHz, use 2000, else 0)>);
83  *
84  * L. Process the EnDat command, transmit, this returns upon receive & command is complete,
85  *
86  * endat_command_process(priv, cmd, cmd_supplement);
87  *
88  * M. Process the received data
89  *
90  * endat_recvd_process(priv, cmd, &endat_format_data);
91  *
92  * N. Do CRC verification
93  *
94  * endat_recvd_validate(priv, cmd, &endat_format_data);
95  *
96  * O. Update additional information state tracking, if needed
97  *
98  * endat_addinfo_track(priv, cmd, &cmd_supplement);
99  *
100  * Result would be in union endat_format_data
101  *
102  *
103  * Example API usage [simplified] (periodic trigger mode, single channel):
104  * -----------------------------------------------------------------------
105  *
106  * Note: IEP CMP2 is the trigger event in periodic trigger mode and has to be setup beforehand.
107  *
108  * A. Get encoder info, follow steps A, B, C, D, E, G of host trigger mode, firmware defaults to 8MHz frequency
109  *
110  * B. Switch to periodic trigger mode, this will take effect after the next command completes
111  *
112  * endat_config_periodic_trigger(priv);
113  *
114  * C. Setup & send the 2.2 position periodic command, needs to be done only once
115  *
116  * endat_command_process(priv, 8, NULL);
117  *
118  * D. After giving enough time to complete the command after periodic event, to read angle for rotary encoder quickly
119  *
120  * endat_get_2_2_angle(priv);
121  *
122  *
123  * Example API usage (periodic trigger mode, single channel):
124  * ---------------------------------------------------------
125  *
126  * Note: IEP CMP2 is the trigger event in periodic trigger mode and has to be setup beforehand.
127  *
128  * A. Get encoder info & set desired timings for required frequency taking care of propagation delay, steps A-K of host trigger mode
129  *
130  * B. Switch to periodic trigger mode, this will take effect after the next command completes
131  *
132  * endat_config_periodic_trigger(priv);
133  *
134  * C. Setup the command to be periodically sent
135  *
136  * endat_command_build(priv, cmd, cmd_supplement);
137  *
138  * D. Send the command
139  *
140  * endat_command_send(priv);
141  *
142  * E. Wait for the command to finish
143  *
144  * endat_command_wait(priv);
145  *
146  * F. Process the received data
147  *
148  * endat_recvd_process(priv, cmd, &endat_format_data);
149  *
150  * G. Do CRC verification
151  *
152  * endat_recvd_validate(priv, cmd, &endat_format_data);
153  *
154  * H. Update additional information state tracking, if needed
155  *
156  * endat_addinfo_track(priv, cmd, &cmd_supplement);
157  *
158  * Result would be in union endat_format_data
159  *
160  * Repeat E-H to get periodic update after the next periodic event <br>
161  * happens, this can be done in say ISR (which could be linked to the <br>
162  * periodic event). For a new command to be executed periodically, <br>
163  * endat_command_build() can invoked after step H, this will take effect <br>
164  * from the next periodic event.
165  *
166  * EnDat commands:
167  * ---------------
168  *
169  * Command description of command numbers passed to endat_command_process()
170  * and endat_command_build() as follows,
171  *
172  * 1: Encoder send position values <br>
173  * 2: Selection of memory area <br>
174  * 3: Encoder receive parameter <br>
175  * 4: Encoder send parameter <br>
176  * 5: Encoder receive reset <br>
177  * 6: Encoder send test values <br>
178  * 7: Encoder receive test command <br>
179  * 8: Encoder to send position + AI(s) <br>
180  * 9: Encoder to send position + AI(s) and receive selection of memory area <br>
181  * 10: Encoder to send position + AI(s) and receive parameter <br>
182  * 11: Encoder to send position + AI(s) and send parameter <br>
183  * 12: Encoder to send position + AI(s) and receive error reset <br>
184  * 13: Encoder to send position + AI(s) and receive test command <br>
185  * 14: Encoder receive communication command <br>
186  *
187  */
188 
189 #ifndef ENDAT_API_H_
190 #define ENDAT_API_H_
191 
192 #ifdef __cplusplus
193 extern "C" {
194 #endif
195 
221 int endat_recvd_process(struct endat_priv *priv, int cmd,
222  union endat_format_data *u);
223 
240 unsigned endat_recvd_validate(struct endat_priv *priv, int cmd,
241  union endat_format_data *u);
242 
253 int endat_command_process(struct endat_priv *priv, int cmd,
255 
266 int endat_command_build(struct endat_priv *priv, int cmd,
268 
276 void endat_command_send(struct endat_priv *priv);
277 
285 void endat_command_wait(struct endat_priv *priv);
286 
297 
306 unsigned int endat_get_prop_delay(struct endat_priv *priv);
307 
317 void endat_addinfo_track(struct endat_priv *priv, int cmd,
319 
328 void endat_config_clock(struct endat_priv *priv,
329  struct endat_clk_cfg *clk_cfg);
330 
339 void endat_config_tst_delay(struct endat_priv *priv, unsigned short delay);
340 
349 void endat_config_rx_arm_cnt(struct endat_priv *priv, unsigned short val);
350 
359 void endat_config_wire_delay(struct endat_priv *priv, unsigned short val);
360 
370  unsigned short val);
371 
381 
390 
399 
408 
417 void endat_config_channel(struct endat_priv *priv, int ch);
418 
428  unsigned char mask);
429 
441 unsigned char endat_multi_channel_detected(struct endat_priv *priv);
442 
453 void endat_multi_channel_set_cur(struct endat_priv *priv, int ch);
454 
464 int endat_wait_initialization(struct endat_priv *priv, unsigned timeout);
465 
476 struct endat_priv *endat_init(struct endat_pruss_xchg *pruss_xchg,
477  void *pruss_cfg);
478 
495 int endat_get_2_2_angle(struct endat_priv *priv);
496 
499 #ifdef __cplusplus
500 }
501 #endif
502 
503 #endif
endat_command_send
void endat_command_send(struct endat_priv *priv)
trigger sending the EnDat command in PRU
endat_config_rx_arm_cnt
void endat_config_rx_arm_cnt(struct endat_priv *priv, unsigned short val)
configure rx arm counter
endat_get_prop_delay
unsigned int endat_get_prop_delay(struct endat_priv *priv)
get propagation delay automatically estimated by the firmware
endat_command_build
int endat_command_build(struct endat_priv *priv, int cmd, struct cmd_supplement *cmd_supplement)
setup the EnDat command in the PRU interface buffer
endat_addinfo_track
void endat_addinfo_track(struct endat_priv *priv, int cmd, struct cmd_supplement *cmd_supplement)
track presence of additional information in priv
endat_config_wire_delay
void endat_config_wire_delay(struct endat_priv *priv, unsigned short val)
configure wire delay for the selected channel
endat_priv
Definition: endat_drv.h:132
endat_command_process
int endat_command_process(struct endat_priv *priv, int cmd, struct cmd_supplement *cmd_supplement)
send the EnDat command and wait till firmware acknowledges
endat_wait_initialization
int endat_wait_initialization(struct endat_priv *priv, unsigned timeout)
wait for EnDat master firmware to initialize
endat_stop_continuous_mode
void endat_stop_continuous_mode(struct endat_priv *priv)
stop continuous mode
endat_format_data
Definition: endat_drv.h:214
endat_get_2_2_angle
int endat_get_2_2_angle(struct endat_priv *priv)
Read EnDat 2.2 angular position in steps for rotary encoders (prior to invoking this,...
endat_config_channel
void endat_config_channel(struct endat_priv *priv, int ch)
select channel to be used by EnDat master
endat_priv::pruss_xchg
struct endat_pruss_xchg * pruss_xchg
Definition: endat_drv.h:147
endat_clk_cfg
Definition: endat_drv.h:103
endat_recvd_process
int endat_recvd_process(struct endat_priv *priv, int cmd, union endat_format_data *u)
process raw recieved data and format based on the command
endat_config_clock
void endat_config_clock(struct endat_priv *priv, struct endat_clk_cfg *clk_cfg)
configure EnDat clock
endat_multi_channel_detected
unsigned char endat_multi_channel_detected(struct endat_priv *priv)
select channels detected in multi channel configuration by EnDat master. required to be invoked onl...
endat_init
struct endat_priv * endat_init(struct endat_pruss_xchg *pruss_xchg, void *pruss_cfg)
Initialize EnDat firmware interface address and get the pointer to struct endat_priv instance.
endat_multi_channel_set_cur
void endat_multi_channel_set_cur(struct endat_priv *priv, int ch)
In multi channel configuration, select channel before receive processing in multi channel configura...
endat_config_multi_channel_mask
void endat_config_multi_channel_mask(struct endat_priv *priv, unsigned char mask)
select mask of channels to be used in multi channel configuration by EnDat master
endat_config_tst_delay
void endat_config_tst_delay(struct endat_priv *priv, unsigned short delay)
configure tST delay
endat_command_wait
void endat_command_wait(struct endat_priv *priv)
wait till PRU finishes EnDat transaction
endat_priv::pruss_cfg
void * pruss_cfg
Definition: endat_drv.h:149
endat_config_periodic_trigger
void endat_config_periodic_trigger(struct endat_priv *priv)
configure EnDat master in periodic trigger mode
endat_config_rx_clock_disable
void endat_config_rx_clock_disable(struct endat_priv *priv, unsigned short val)
configure clocks to be disabled at the end of rx to account for tD
endat_start_continuous_mode
int endat_start_continuous_mode(struct endat_priv *priv)
start continuous mode
endat_get_encoder_info
int endat_get_encoder_info(struct endat_priv *priv)
update priv with position resolution, id, serial number, encoder type and supported command set
endat_config_host_trigger
void endat_config_host_trigger(struct endat_priv *priv)
configure EnDat master for host trigger mode
endat_recvd_validate
unsigned endat_recvd_validate(struct endat_priv *priv, int cmd, union endat_format_data *u)
CRC result indicated in return value as follows, 0th bit high position/address/params/test CRC succ...
cmd_supplement
Definition: endat_drv.h:153