AM243x Motor Control SDK  09.02.00
nikon_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 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 EXPRESS 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 #ifndef NIKON_DRV_H_
35 #define NIKON_DRV_H_
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include <stdio.h>
42 #include <string.h>
43 #include <math.h>
44 #include <drivers/pruicss.h>
46 
47 /* Minimum and Maximum NIKON cycle time depends on various params as below:
48  TCycle_max = TMA ∗ (number of RX frames * 18) + TX frame(32)
49  + delay between TX and RX + (delay between Multi Transmission commands
50  * (maximum encoder address delay t6))
51  + Delay between two EEPROM access commands(30milisec)
52  TCycle_min = TMA * (number of Rx frames * 18) + TX frame(32)
53  + delay between TX and RX
54  Instead wait for max of 35 ms as this can vary for different encoders,
55  different commands and multi transmission connection.
56 */
57 /* Single PRU - Single channel configuration */
58 #define NIKON_MODE_SINGLE_CHANNEL_SINGLE_PRU (0U)
59 /* Single PRU - Multichannel configuration */
60 #define NIKON_MODE_MULTI_CHANNEL_SINGLE_PRU (1U)
61 /* Multichannel - Load Share configuration */
62 #define NIKON_MODE_MULTI_CHANNEL_MULTI_PRU (2U)
63 
64 /* 35 milisec as max cycle timeout (more than 30 mili sec delay is required
65 between two cycles in memory access commands) */
66 #define NIKON_MAX_CYCLE_TIMEOUT 35
67 /* Maximum number of 3-ch peripheral interface Channels*/
68 #define NUM_ED_CH_MAX 3
69 /* Maximum number of Nikon Encoders connected in bus connection*/
70 #define NUM_ENCODERS_MAX 3
71 /* Maximum number of Memory Data Frames to be sent on Tx*/
72 #define NUM_MDF_CMD_MAX 3
73 
74 #define NIKON_RX_SAMPLE_SIZE_16MHZ 3 /* 4x over sample rate */
75 #define NIKON_RX_SAMPLE_SIZE_6_67MHZ 5 /* 6x over sample rate */
76 #define NIKON_RX_SAMPLE_SIZE 7 /* 8x over sample rate */
77 /* Allowed frequencies in MHz for NIKON */
78 #define NIKON_FREQ_2_5MHZ 2.5 /* 2.5 MHz frequency */
79 #define NIKON_FREQ_4MHZ 4 /* 4 MHz frequency */
80 #define NIKON_FREQ_6_67MHZ 6 /* 6.67 MHz frequency */
81 #define NIKON_FREQ_8MHZ 8 /* 8 MHz frequency */
82 #define NIKON_FREQ_16MHZ 16 /* 16 MHz frequency */
83 /* Number of Rx data CRC bits */
84 #define NIKON_POS_CRC_LEN 8
85 /* Default data length instead of garbage*/
86 #define NIKON_POS_DATA_LEN_DEFAULT 17
87 
88 /* Enable cycle trigger for firmware*/
89 #define NIKON_ENABLE_CYCLE_TRIGGER 0x1
90  /* Disable cycle trigger */
91 #define NIKON_DISABLE_CYCLE_TRIGGER 0x0
92 /* Configure firmware in continuous mode*/
93 #define NIKON_CONFIG_PERIODIC_TRIGGER_MODE 0x0
94 /* Configure firmware in host trigger mode*/
95 #define NIKON_CONFIG_HOST_TRIGGER_MODE 0x1
96 /* General Macro for clearing any status flag */
97 #define NIKON_CLEAR_STATUS_FLAG 0x0
98 /* General Macro for setting any status flag */
99 #define NIKON_SET_STATUS_FLAG 0x1
100 
101 #define NIKON_CHANNEL0_MASK 0x1 /* Mask for channel 0 */
102 #define NIKON_CHANNEL1_MASK 0x2 /* Mask for channel 1 */
103 #define NIKON_CHANNEL2_MASK 0x4 /* Mask for channel 2 */
104 
105 /* 1000usec sleep for timeout count*/
106 #define NIKON_1MILLISEC_SLEEP_TIME 1000
107 /* 30milli sec delay for EEPROM update */
108 #define NIKON_30_MILLI_SEC_DELAY 30000
109 
110 /* Middle bit indexes for Given Oversampling rates */
111 #define NIKON_FIFO_BIT_IDX_8X_OS 4 /* 8x Oversampling */
112 #define NIKON_FIFO_BIT_IDX_6X_OS 3 /* 6x Oversampling */
113 #define NIKON_FIFO_BIT_IDX_4X_OS 2 /* 4x Oversampling */
114 
115 #define NIKON_BASE_VALID_BIT_IDX 24 /* Base valid bit index */
116 
117 /* Lengths of the Specified fields */
118 #define NIKON_DB_BITS_LEN 10 /* temperature bits*/
119 #define NIKON_RX_ONE_FRAME_LEN 16 /* Rx frame*/
120 #define NIKON_EEPROM_ADDR_LEN 8 /* EEPROM memory address*/
121 #define NIKON_COMMAND_CODE_LEN 5 /* command code */
122 #define NIKON_ENC_STATUS_LEN 4 /* encoder status field */
123 #define NIKON_ENC_ADDR_LEN 3 /* encoder address */
124 #define NIKON_SYNC_CODE_LEN 3 /* sync code */
125 #define NIKON_TX_CRC_LEN 3 /* 3bit Tx CRC */
126 #define NIKON_FRAME_CODE_LEN 2 /* frame code */
127 #define NIKON_START_BIT_LEN 1 /* start bit */
128 #define NIKON_STOP_BIT_LEN 1 /* stop bit */
129 #define NIKON_FIXED_BIT_LEN 1 /* fix bit in info field*/
130 
131 /* Status for request or access */
132 #define NIKON_EEPROM_READ_ACCESS 1 /* eeprom read access */
133 #define NIKON_EEPROM_WRITE_ACCESS 2 /* eeprom write access */
134 #define NIKON_ENABLE_ID_CODE_WRITE 2 /* ID code write request */
135 
136 /* Maximum possible parameters */
137 #define NIKON_MAX_NUM_RX_FRAMES 4 /* Rx frames */
138 #define NIKON_MAX_ABS_LEN 40 /* ABS data length */
139 #define NIKON_MAX_NUM_DATA_FIELDS 3 /* Rx Data fields */
140 /* Common parameters for most of the commands */
141 #define NIKON_AVG_NUM_RX_FRAMES 3 /* Rx frames */
142 #define NIKON_AVG_ABS_LEN 24 /* ABS data length*/
143 /*Minimum possible parameters */
144 #define NIKON_MIN_NUM_RX_FRAMES 2 /* Rx frames */
145 #define NIKON_MIN_ABS_LEN 17 /* ABS data length*/
146 
147 /* Masks for speecified fields */
148 #define NIKON_DB_BITS_MASK 0x3FF /* temperature bits(DB) */
149 #define NIKON_ENC_STATUS_MASK 0xF /* encoder status field */
150 #define NIKON_CMD_CODE_MASK 0x1F /* command code field*/
151 #define NIKON_ENC_ADDR_MASK 0x7 /* encoder address field */
152 
153 /* Number of cycles required to perform operation or reset specific commands */
154 #define NIKON_NUM_OF_CYCLE_FOR_RESET 7
155 
159 {
183  CMD_27 = 27,
185  CMD_29,
187  CMD_30,
195 };
196 
206 {
207  uint16_t rx_div;
209  uint16_t tx_div;
211  uint16_t rx_div_attr;
213  uint16_t is_core_clk;
215 };
217 {
238 };
239 struct enc_info
240 {
247 };
256 struct alm_bits
257 {
258  uint8_t batt;
261  uint8_t mt_err;
264  uint8_t ov_flow;
268  uint8_t ov_spd;
271  uint8_t mem_err;
274  uint8_t st_err;
277  uint8_t ps_err;
281  uint8_t busy;
284  uint8_t mem_busy;
287  uint8_t ov_temp;
290  uint8_t inc_err;
293 };
304 {
305  uint32_t pruicss_slicex;
307  uint32_t load_share;
323  uint32_t has_safety;
325  void *pruicss_cfg;
329  uint32_t tx_mdf;
331  uint32_t num_rx_frames;
333  uint32_t totalchannels;
335  float_t baud_rate;
337  uint32_t core_clk_freq;
339  uint32_t uart_clk_freq;
341  uint32_t eax[NUM_ED_CH_MAX];
343  uint32_t fc;
345  uint32_t sync_code;
347  uint32_t tx_crc;
365  uint32_t abs_len;
369  void *pruicss_iep;
371  uint64_t cmp3;
374 };
375 
376 #ifdef __cplusplus
377 }
378 #endif
379 
380 #endif
alm_bits::ov_temp
uint8_t ov_temp
Definition: nikon_drv.h:287
CMD_16
@ CMD_16
Definition: nikon_drv.h:176
nikon_priv::uart_clk_freq
uint32_t uart_clk_freq
Definition: nikon_drv.h:339
CMD_13
@ CMD_13
Definition: nikon_drv.h:173
CMD_28
@ CMD_28
Definition: nikon_drv.h:184
nikon_priv::has_safety
uint32_t has_safety
Definition: nikon_drv.h:323
CMD_5
@ CMD_5
Definition: nikon_drv.h:165
CMD_18
@ CMD_18
Definition: nikon_drv.h:178
pos_data_info::crc_err_cnt
uint32_t crc_err_cnt[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:230
CMD_30
@ CMD_30
Definition: nikon_drv.h:187
nikon_pruicss_xchg
Structure defining Nikon interface.
Definition: nikon_interface.h:94
pos_data_info::multi_turn
uint32_t multi_turn[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:234
pos_data_info::abs
uint64_t abs[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:232
CMD_15
@ CMD_15
Definition: nikon_drv.h:175
CMD_17
@ CMD_17
Definition: nikon_drv.h:177
CMD_CODE_NUM
@ CMD_CODE_NUM
Definition: nikon_drv.h:194
alm_bits::busy
uint8_t busy
Definition: nikon_drv.h:281
nikon_priv::is_continuous_mode
uint32_t is_continuous_mode
Definition: nikon_drv.h:367
nikon_priv::load_share
uint32_t load_share
Definition: nikon_drv.h:307
pos_data_info::raw_data1
uint32_t raw_data1[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:220
nikon_clk_cfg::is_core_clk
uint16_t is_core_clk
Definition: nikon_drv.h:213
CMD_0
@ CMD_0
Definition: nikon_drv.h:160
nikon_priv::data_len
uint32_t data_len[NUM_ED_CH_MAX][NUM_ENCODERS_MAX]
Definition: nikon_drv.h:309
pos_data_info::raw_data3
uint32_t raw_data3[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:224
NUM_MDF_CMD_MAX
#define NUM_MDF_CMD_MAX
Definition: nikon_drv.h:72
CMD_9
@ CMD_9
Definition: nikon_drv.h:169
nikon_priv::num_enc_access
uint32_t num_enc_access[NUM_ED_CH_MAX]
Definition: nikon_drv.h:313
CMD_22
@ CMD_22
Definition: nikon_drv.h:182
pos_data_info::raw_data0
uint32_t raw_data0[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:218
CMD_29
@ CMD_29
Definition: nikon_drv.h:185
cmd_code
cmd_code
Command codes[4:0].
Definition: nikon_drv.h:159
CMD_20
@ CMD_20
Definition: nikon_drv.h:180
CMD_12
@ CMD_12
Definition: nikon_drv.h:172
CMD_1
@ CMD_1
Definition: nikon_drv.h:161
nikon_priv::num_rx_frames
uint32_t num_rx_frames
Definition: nikon_drv.h:331
alm_bits::mt_err
uint8_t mt_err
Definition: nikon_drv.h:261
alm_bits::mem_err
uint8_t mem_err
Definition: nikon_drv.h:271
ENCODER_ADR_CHANGE
@ ENCODER_ADR_CHANGE
Definition: nikon_drv.h:190
nikon_priv::identification_code
uint32_t identification_code[NUM_ED_CH_MAX]
Definition: nikon_drv.h:359
nikon_clk_cfg::rx_div_attr
uint16_t rx_div_attr
Definition: nikon_drv.h:211
CMD_6
@ CMD_6
Definition: nikon_drv.h:166
nikon_clk_cfg::tx_div
uint16_t tx_div
Definition: nikon_drv.h:209
nikon_priv::pruicss_xchg
struct nikon_pruicss_xchg * pruicss_xchg
Definition: nikon_drv.h:321
nikon_priv::mem_data
uint32_t mem_data[NUM_MDF_CMD_MAX]
Definition: nikon_drv.h:349
enc_info::enc_status
uint32_t enc_status[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:241
CMD_8
@ CMD_8
Definition: nikon_drv.h:168
pos_data_info
Definition: nikon_drv.h:217
alm_bits
Structure defining Alarm bits receivedd by the encoder.
Definition: nikon_drv.h:257
NUM_ENCODERS_MAX
#define NUM_ENCODERS_MAX
Definition: nikon_drv.h:70
nikon_priv::temperature
uint32_t temperature[NUM_ED_CH_MAX][NUM_ENCODERS_MAX]
Definition: nikon_drv.h:357
nikon_priv::core_clk_freq
uint32_t core_clk_freq
Definition: nikon_drv.h:337
nikon_priv::pruicss_slicex
uint32_t pruicss_slicex
Definition: nikon_drv.h:305
alm_bits::ov_spd
uint8_t ov_spd
Definition: nikon_drv.h:268
nikon_priv::cmp3
uint64_t cmp3
Definition: nikon_drv.h:371
CMD_3
@ CMD_3
Definition: nikon_drv.h:163
nikon_priv::tx_crc
uint32_t tx_crc
Definition: nikon_drv.h:347
nikon_priv::tx_mdf
uint32_t tx_mdf
Definition: nikon_drv.h:329
nikon_priv
Initialize NIKON firmware interface address and get the pointer to struct nikon_priv instance.
Definition: nikon_drv.h:304
UPDATE_ENC_LEN
@ UPDATE_ENC_LEN
Definition: nikon_drv.h:193
nikon_priv::eax
uint32_t eax[NUM_ED_CH_MAX]
Definition: nikon_drv.h:341
nikon_priv::pruicss_iep
void * pruicss_iep
Definition: nikon_drv.h:369
nikon_priv::tx_cdf
uint32_t tx_cdf[NUM_ED_CH_MAX]
Definition: nikon_drv.h:327
nikon_clk_cfg::rx_div
uint16_t rx_div
Definition: nikon_drv.h:207
nikon_interface.h
CMD_10
@ CMD_10
Definition: nikon_drv.h:170
alm_bits::batt
uint8_t batt
Definition: nikon_drv.h:258
nikon_priv::single_turn_len
uint32_t single_turn_len[NUM_ED_CH_MAX][NUM_ENCODERS_MAX]
Definition: nikon_drv.h:315
nikon_priv::baud_rate
float_t baud_rate
Definition: nikon_drv.h:335
nikon_priv::sync_code
uint32_t sync_code
Definition: nikon_drv.h:345
nikon_priv::alm_field
uint32_t alm_field[NUM_ED_CH_MAX][NUM_ENCODERS_MAX]
Definition: nikon_drv.h:361
nikon_clk_cfg
Structure defining 3-ch peripheral interface clock configuration for selected frequency.
Definition: nikon_drv.h:206
nikon_priv::multi_turn_len
uint32_t multi_turn_len[NUM_ED_CH_MAX][NUM_ENCODERS_MAX]
Definition: nikon_drv.h:317
alm_bits::ps_err
uint8_t ps_err
Definition: nikon_drv.h:277
CMD_19
@ CMD_19
Definition: nikon_drv.h:179
enc_info::enc_addr
uint32_t enc_addr[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:245
pos_data_info::otf_crc
uint32_t otf_crc[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:228
pos_data_info::raw_data2
uint32_t raw_data2[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:222
CMD_27
@ CMD_27
Definition: nikon_drv.h:183
enc_info
Definition: nikon_drv.h:240
alm_bits::st_err
uint8_t st_err
Definition: nikon_drv.h:274
alm_bits::ov_flow
uint8_t ov_flow
Definition: nikon_drv.h:264
UPDATE_CLOCK_FREQ
@ UPDATE_CLOCK_FREQ
Definition: nikon_drv.h:192
CMD_11
@ CMD_11
Definition: nikon_drv.h:171
CMD_2
@ CMD_2
Definition: nikon_drv.h:162
nikon_priv::num_encoders
uint32_t num_encoders[NUM_ED_CH_MAX]
Definition: nikon_drv.h:311
nikon_priv::channel
uint32_t channel[NUM_ED_CH_MAX]
Definition: nikon_drv.h:319
nikon_priv::totalchannels
uint32_t totalchannels
Definition: nikon_drv.h:333
nikon_priv::abs_len
uint32_t abs_len
Definition: nikon_drv.h:365
alm_bits::mem_busy
uint8_t mem_busy
Definition: nikon_drv.h:284
START_CONTINUOUS_MODE
@ START_CONTINUOUS_MODE
Definition: nikon_drv.h:191
CMD_7
@ CMD_7
Definition: nikon_drv.h:167
pos_data_info::rcv_crc
uint32_t rcv_crc[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:226
pos_data_info::angle
float angle[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:236
CMD_14
@ CMD_14
Definition: nikon_drv.h:174
enc_info::enc_cmd
uint32_t enc_cmd[NUM_ENCODERS_MAX]
Definition: nikon_drv.h:243
nikon_priv::pruicss_cfg
void * pruicss_cfg
Definition: nikon_drv.h:325
CMD_4
@ CMD_4
Definition: nikon_drv.h:164
CMD_21
@ CMD_21
Definition: nikon_drv.h:181
NUM_ED_CH_MAX
#define NUM_ED_CH_MAX
Definition: nikon_drv.h:68
alm_bits::inc_err
uint8_t inc_err
Definition: nikon_drv.h:290
nikon_priv::fc
uint32_t fc
Definition: nikon_drv.h:343