The EnDAT3 API module provides functions for initializing and communicating with EnDAT3-compatible encoders. It supports both host-triggered and periodic communication, and provides interfaces for command transmission and response parsing.
The EnDAT3 driver implements following parameter validation approach:
The following sequence demonstrates typical usage of the EnDAT3 driver:
1. Initialization:
2. Operating Mode Configuration:
3. Command Execution (Host Trigger Mode):
4. Data Retrieval:
5. Error Handling:
6. Cleanup:
Data Structures | |
| struct | endat3_bg_cmd_params |
| Background command request parameters. More... | |
| struct | endat3_clock_config |
| Structure defining ENDAT3 clock configuration for selected frequency. More... | |
| struct | endat3_params |
| EnDAT3 initialization parameters. More... | |
| struct | endat3_attrs |
| EnDAT3 attributes (compile-time/SysConfig configuration data) More... | |
| struct | endat3_hpf |
| High Priority Frame structure. More... | |
| struct | endat3_lph |
| Low Priority Header structure. More... | |
| struct | endat3_lpf |
| Low Priority Frame structure. More... | |
| struct | endat3_periodic_trigger_cfg |
| Structure defining ENDAT3 periodic trigger configuration. More... | |
| struct | endat3_interface |
| EnDAT3 Interface structure. More... | |
| struct | endat3_priv |
| EnDAT3 private data structure (runtime state and configuration) More... | |
| struct | endat3_config |
| EnDAT3 configuration handle structure. More... | |
Functions | |
| void | endat3_params_init (endat3_params *params) |
| Initialize EnDAT3 parameters with default values. More... | |
| endat3_handle | endat3_init (uint32_t index, const endat3_params *endat3_params) |
| Initialize an EnDAT3 instance. More... | |
| void | endat3_deinit (endat3_handle handle) |
| De-initialize an EnDAT3 instance. More... | |
| const endat3_attrs * | endat3_get_attrs (endat3_handle handle) |
| Get pointer to EnDAT3 attributes structure. More... | |
| endat3_priv * | endat3_get_priv (endat3_handle handle) |
| Get pointer to EnDAT3 private data structure. More... | |
| int32_t | endat3_send_command (endat3_handle handle, uint8_t cmd, uint8_t frames) |
| Send EnDAT3 command. More... | |
| int32_t | endat3_receive_response (endat3_handle handle) |
| Receive EnDAT3 response. More... | |
| const char * | endat3_get_error_description (endat3_error_code error_code) |
| Get error description string. More... | |
| const char * | endat3_get_error_action (endat3_error_code error_code) |
| Get recommended action for error code. More... | |
| int32_t | endat3_handle_background_command_request (endat3_handle handle, const endat3_bg_cmd_params *params, uint8_t *mode, const char **acc_level_desc) |
| Handle background command request. More... | |
| int32_t | endat3_get_hpf_status (endat3_handle handle, uint8_t *status) |
| Get HPF status byte. More... | |
| int32_t | endat3_get_hpf_data (endat3_handle handle, uint8_t *data) |
| Get HPF data array. More... | |
| int32_t | endat3_get_hpf_crc (endat3_handle handle, uint8_t *crc) |
| Get HPF CRC value. More... | |
| int32_t | endat3_get_hpf_data_64_bit (endat3_handle handle, uint64_t *data) |
| Get HPF data as 64-bit value. More... | |
| int32_t | endat3_is_hpf_data_valid (endat3_handle handle, uint8_t *is_valid) |
| Check if HPF data is valid. More... | |
| int32_t | endat3_has_hpf_error (endat3_handle handle, uint8_t *has_error) |
| Check if HPF has error flag set. More... | |
| int32_t | endat3_has_hpf_warning (endat3_handle handle, uint8_t *has_warning) |
| Check if HPF has warning flag set. More... | |
| int32_t | endat3_has_absolute_value (endat3_handle handle, uint8_t *has_absolute) |
| Check if absolute value is available. More... | |
| int32_t | endat3_get_lph_status (endat3_handle handle, uint8_t *status) |
| Get LPH status byte. More... | |
| int32_t | endat3_get_lph_lpf_count (endat3_handle handle, uint8_t *num_lpf) |
| Get number of LPF frames. More... | |
| int32_t | endat3_get_lph_crc (endat3_handle handle, uint8_t *crc) |
| Get LPH CRC value. More... | |
| int32_t | endat3_get_lph_state (endat3_handle handle, endat3_lph_status *state) |
| Get LPH communication state. More... | |
| int32_t | endat3_has_bg_error (endat3_handle handle, uint8_t *has_error) |
| Check if background operation has error. More... | |
| int32_t | endat3_is_bg_busy (endat3_handle handle, uint8_t *is_busy) |
| Check if background processor is busy. More... | |
| int32_t | endat3_has_bg_rtx_error (endat3_handle handle, uint8_t *has_error) |
| Check if background RTX error occurred. More... | |
| int32_t | endat3_get_lpf_status (endat3_handle handle, uint8_t index, uint8_t *status) |
| Get LPF status byte for specific frame. More... | |
| int32_t | endat3_get_lpf_data (endat3_handle handle, uint8_t index, uint8_t *data) |
| Get LPF data array for specific frame. More... | |
| int32_t | endat3_get_lpf_crc (endat3_handle handle, uint8_t index, uint8_t *crc) |
| Get LPF CRC value for specific frame. More... | |
| int32_t | endat3_get_lpf_fid (endat3_handle handle, uint8_t index, uint8_t *fid) |
| Get LPF FID (Frame ID) for specific frame. More... | |
| int32_t | endat3_is_connected (endat3_handle handle, uint8_t *is_connected) |
| Get connection status. More... | |
| int32_t | endat3_is_busy (endat3_handle handle, uint8_t *is_busy) |
| Get busy status. More... | |
| int32_t | endat3_set_busy (endat3_handle handle, uint8_t busy) |
| Set or clear busy status. More... | |
| int32_t | endat3_get_expected_tx_frame_count (endat3_handle handle, uint32_t *count) |
| Get expected TX frame count. More... | |
| int32_t | endat3_set_expected_tx_frame_count (endat3_handle handle, uint32_t count) |
| Set expected TX frame count. More... | |
| int32_t | endat3_get_propagation_time (endat3_handle handle, uint32_t *prop_time) |
| Get propagation time. More... | |
| int32_t | endat3_get_foreground_op_code (endat3_handle handle, uint32_t *opcode) |
| Get foreground operation code. More... | |
| int32_t | endat3_set_foreground_op_code (endat3_handle handle, uint32_t opcode) |
| Set foreground operation code. More... | |
| int32_t | endat3_get_background_op_code (endat3_handle handle, uint32_t *opcode) |
| Get background operation code. More... | |
| int32_t | endat3_set_background_op_code (endat3_handle handle, uint32_t opcode) |
| Set background operation code. More... | |
| int32_t | endat3_get_bg_data (endat3_handle handle, uint8_t index, uint32_t *data) |
| Get background data word. More... | |
| int32_t | endat3_set_bg_data (endat3_handle handle, uint8_t index, uint32_t data) |
| Set background data word. More... | |
| int32_t | endat3_get_all_bg_data (endat3_handle handle, uint32_t *data) |
| Get all background data. More... | |
| int32_t | endat3_set_all_bg_data (endat3_handle handle, const uint32_t *data) |
| Set all background data. More... | |
| const volatile uint8_t * | endat3_get_rx_buffer (endat3_handle handle) |
| Get RX buffer pointer. More... | |
| const volatile uint8_t * | endat3_get_tx_buffer (endat3_handle handle) |
| Get TX buffer pointer. More... | |
| int32_t | endat3_set_tx_buffer (endat3_handle handle, const uint8_t *data, uint32_t length) |
| Copy data to TX buffer. More... | |
| int32_t | endat3_get_hpf_frame (endat3_handle handle, endat3_hpf *hpf) |
| Get complete HPF structure. More... | |
| int32_t | endat3_get_lph_frame (endat3_handle handle, endat3_lph *lph) |
| Get complete LPH structure. More... | |
| int32_t | endat3_get_lpf_frame (endat3_handle handle, uint8_t index, endat3_lpf *lpf) |
| Get complete LPF structure. More... | |
| int32_t | endat3_get_error_code (endat3_handle handle, endat3_error_code *error_code) |
| Extract error code from HPF or LPF. More... | |
| endat3_interface * | endat3_get_interface (endat3_handle handle) |
| Get interface pointer (advanced use) More... | |
| int32_t | endat3_set_operating_mode (endat3_handle handle, uint8_t opmode) |
| Set operating mode (host trigger or periodic trigger) More... | |
| int32_t | endat3_get_operating_mode (endat3_handle handle, uint8_t *opmode) |
| Get current operating mode. More... | |
| int32_t | endat3_config_iep_cap_event (endat3_handle handle, uint8_t event_num) |
| Configure IEP CAP event number in PRU DMEM. More... | |
| int32_t | endat3_config_iep_cmp_event (endat3_handle handle, uint8_t event_num) |
| Configure IEP CMP event number in PRU DMEM. More... | |
| int32_t | endat3_release_start_trigger (endat3_handle handle) |
| Release start trigger to firmware. More... | |
| int32_t | endat3_clear_start_trigger (endat3_handle handle) |
| Clear start trigger flag. More... | |
| int32_t | endat3_get_start_trigger_status (endat3_handle handle, uint8_t *trigger_status) |
| Get current start trigger status. More... | |
Typedefs | |
| typedef endat3_config * | endat3_handle |
| EnDAT3 Driver Handle. More... | |
EnDat3 PRU Operating Modes | |
| #define | ENDAT3_MODE_SINGLE_CHANNEL_SINGLE_PRU (0U) |
| Single channel, single PRU mode (non-load-share) More... | |
| #define | ENDAT3_TX_START_DELAY_1_REF_CYCLES (218U) |
| #define | ENDAT3_TX_START_DELAY_2_REF_CYCLES (1748U) |
| #define | ENDAT3_TX_START_DELAY_3_REF_CYCLES (438U) |
| #define | ENDAT3_DELAY_10MS_REF_CYCLES (10486U) |
| #define | ENDAT3_BAUD_RATE_12_5_MBPS_VALUE (12500000U) |
| #define | ENDAT3_BAUD_RATE_25_MBPS_VALUE (25000000U) |
| #define | ENDAT3_IEP_MAX_CAP_EVENT (0x8U) |
| #define | ENDAT3_IEP_MAX_CMP_EVENT (0x10U) |
| #define | ENDAT3_CFG_REG_SIZE (4U) |
| #define | ENDAT3_CSL_ICSS_PR1_IEP0_SLV_CAP0_REG0 (CSL_ICSS_PR1_IEP0_SLV_CAP_CFG_REG + 2U*ENDAT3_CFG_REG_SIZE) |
| #define | ENDAT3_8_BYTE_REG_OFFSET (8U) |
| #define | HPF_DATA_SIZE (6) |
| #define | LPF_DATA_SIZE (6) |
| #define | MAX_LPF_COUNT (8) |
| #define | LUT_SIZE (64) |
| #define | RX_BUFFER_SIZE (64) |
| #define | TX_BUFFER_SIZE (24) |
| #define | BG_DATA_SIZE (6) |
| #define ENDAT3_MODE_SINGLE_CHANNEL_SINGLE_PRU (0U) |
Single channel, single PRU mode (non-load-share)
| #define ENDAT3_OPMODE_PERIODIC_CMP (0x0U) |
EnDat3 Operation Mode: Periodic trigger with CMP event.
In periodic CMP mode, the PRU firmware automatically triggers position readout at regular intervals using IEP CMP (Compare) events.
| #define ENDAT3_OPMODE_HOST_TRIGGER (0x1U) |
EnDat3 Operation Mode: Host trigger.
In host trigger mode, the R5F host processor explicitly triggers each position readout by setting the trigger bit.
| #define ENDAT3_OPMODE_PERIODIC_CAP (0x2U) |
EnDat3 Operation Mode: Periodic trigger with CAP event.
In periodic CAP mode, the PRU firmware automatically triggers position readout at regular intervals using IEP CAP (Capture) events.
| #define ENDAT3_SUCCESS (0) |
Success code
| #define ENDAT3_ERR_INVALID_INPUT (-1) |
Invalid input parameter (NULL pointer, invalid value, out of bounds)
| #define ENDAT3_ERR_BUSY (-2) |
Encoder busy (transfer in progress)
| #define ENDAT3_ERR_RX_FAIL (-3) |
Reception failure
| #define ENDAT3_ERR_LPH_CRC_FAIL (-4) |
LPH (Low Priority Header) CRC mismatch
| #define ENDAT3_ERR_HPF_CRC_FAIL (-5) |
HPF (High Priority Frame) CRC mismatch
| #define ENDAT3_ERR_LPF_CRC_FAIL (-6) |
LPF (Low Priority Frame) CRC mismatch
| #define ENDAT3_ERR_SAMPLING_ERROR (-7) |
Encoder sampling/timing error
| #define ENDAT3_ERR_INVALID_OPMODE (-8) |
Invalid operating mode (mode > 2)
| #define ENCODER_IDLE (0x0) |
Encoder idle, ready for communication
| #define ENCODER_BUSY (0x1) |
Encoder busy, transfer in progress
| #define ENCODER_ERROR (0x2) |
Encoder error detected during transfer
| #define ENDAT3_FRAME_SIZE_BYTES (4U) |
EnDAT3 frame size in bytes
| #define ENDAT3_CHANNEL_MASK_MAX (0x7U) |
Maximum valid channel mask (ch0|ch1|ch2)
| #define ENDAT3_MAX_BG_CMD_INDEX (3U) |
Exclusive upper bound for background command index (valid range: 0-2)
| #define ENDAT3_CORE_CLK_200MHZ (200000000U) |
200 MHz core clock frequency
| #define ENDAT3_CORE_CLK_300MHZ (300000000U) |
300 MHz core clock frequency
| #define REFERENCE_PRU_FREQ_HZ (1000000ULL) |
Reference frequency for delay calculations (1 MHz)
| #define REFERENCE_PRU_FREQ_HZ_FOR_SAMPLING (5000000ULL) |
5 MHz reference for sampling delay (gives 60 cycles @ 300MHz, 40 cycles @ 200MHz)
| #define ENDAT3_TX_START_DELAY_1_REF_CYCLES (218U) |
These values are derived from the original 300 MHz PRU frequency implementation and are scaled to actual PRU frequency at runtime using the formula: actual_cycles = (reference_cycles * actual_freq) / REFERENCE_PRU_FREQ_HZ TX start delay 1 reference (65535 / 300)
| #define ENDAT3_TX_START_DELAY_2_REF_CYCLES (1748U) |
TX start delay 2 reference (524288 / 300)
| #define ENDAT3_TX_START_DELAY_3_REF_CYCLES (438U) |
TX start delay 3 reference (131328 / 300)
| #define ENDAT3_DELAY_10MS_REF_CYCLES (10486U) |
10ms delay reference (3145728 / 300)
| #define ENDAT3_BAUD_RATE_12_5_MBPS (0U) |
12.5 Mbps mode selector
| #define ENDAT3_BAUD_RATE_25_MBPS (1U) |
25 Mbps mode selector
| #define ENDAT3_BAUD_RATE_12_5_MBPS_VALUE (12500000U) |
Clock configuration constants 12.5 Mbps baud rate value in Hz
| #define ENDAT3_BAUD_RATE_25_MBPS_VALUE (25000000U) |
25 Mbps baud rate value in Hz
| #define ENDAT3_IEP_MAX_CAP_EVENT (0x8U) |
IEP (Industrial Ethernet Peripheral) event limits for periodic trigger mode Maximum IEP CAP events (0-7)
| #define ENDAT3_IEP_MAX_CMP_EVENT (0x10U) |
Maximum IEP CMP events (0-15)
| #define ENDAT3_CFG_REG_SIZE (4U) |
IEP register offsets for periodic trigger mode IEP configuration register size in bytes
| #define ENDAT3_CSL_ICSS_PR1_IEP0_SLV_CAP0_REG0 (CSL_ICSS_PR1_IEP0_SLV_CAP_CFG_REG + 2U*ENDAT3_CFG_REG_SIZE) |
IEP CAP0 register 0 offset
| #define ENDAT3_8_BYTE_REG_OFFSET (8U) |
8-byte register offset for IEP CMP/CAP registers
| #define ENDAT3_OVERSAMPLE_RATE_8X (8U) |
8x oversampling rate for RX clock
| #define ENDAT3_SB_POLARITY (0U) |
Start bit polarity configuration
| #define ENDAT3_TX_CLOCK_MULTIPLIER (2U) |
TX clock multiplier: TX clock = 2x baud rate
| #define HPF_DATA_SIZE (6) |
Buffer and data size definitions High Priority Frame data size in bytes
| #define LPF_DATA_SIZE (6) |
Low Priority Frame data size in bytes
| #define MAX_LPF_COUNT (8) |
Maximum number of LPF frames
| #define LUT_SIZE (64) |
Lookup table size (256 bytes / 4 bytes per uint32_t)
| #define RX_BUFFER_SIZE (64) |
Receive buffer size
| #define TX_BUFFER_SIZE (24) |
Transmit buffer size
| #define BG_DATA_SIZE (6) |
Background data array size
| #define ENDAT3_HPF_TOTAL_SIZE (8) |
HPF total frame size: 6 data + 1 status + 1 CRC
| #define ENDAT3_LPH_TOTAL_SIZE (4) |
LPH total frame size: 2 data + 1 status + 1 CRC
| #define ENDAT3_LPF_TOTAL_SIZE (8) |
LPF total frame size: 6 data + 1 FID/status + 1 CRC
| #define ENDAT3_HPF_OFFSET (0) |
HPF offset in RX buffer
| #define ENDAT3_LPH_OFFSET (8) |
LPH offset in RX buffer (after HPF)
| #define ENDAT3_LPF_OFFSET (12) |
LPF offset in RX buffer (after HPF + LPH)
| #define ENDAT3_MIN_RX_BUFFER_SIZE (20) |
Minimum RX buffer size: HPF(8) + LPH(4) + LPF(8)
| #define ENDAT3_RESET_HARD (0x01) |
Hard reset command data
| #define ENDAT3_RESET_SOFT (0x00) |
Soft reset command data
| #define ENDAT3_CLEAR_F (0x01) |
Clear F (error) flag
| #define ENDAT3_CLEAR_W (0x02) |
Clear W (warning) flag
| #define ENDAT3_CLEAR_REF (0x04) |
Clear reference flag
| #define ENDAT3_RATE_12_5MBPS (0x00) |
12.5 Mbps data rate
| #define ENDAT3_RATE_25MBPS (0x01) |
25 Mbps data rate
| #define ENDAT3_BUSINIT_RESET_ADDR (0x01) |
Bus init with address reset
| #define ENDAT3_BUSINIT_KEEP_ADDR (0x00) |
Bus init keeping addresses
| #define ENDAT3_PROTECT_QUERY (0x01) |
Query current access levels
| #define ENDAT3_PROTECT_SET_READ (0x02) |
Set access level for read operations
| #define ENDAT3_PROTECT_SET_WRITE (0x03) |
Set access level for write operations
| #define ENDAT3_PASSWORD_HIGH_MASK (0xFFFF0000) |
Upper 16 bits mask
| #define ENDAT3_PASSWORD_LOW_MASK (0x0000FFFF) |
Lower 16 bits mask
| #define ENDAT3_PASSWORD_HIGH_SHIFT (16) |
Shift for upper 16 bits
| #define ENDAT3_PRE_LENGTH (25) |
Minimum preamble length in halfbits
| #define ENDAT3_POST_LENGTH (4) |
Postamble length in halfbits
| typedef endat3_config* endat3_handle |
EnDAT3 Driver Handle.
Opaque handle to an EnDAT3 instance. Obtained from endat3_init() and used in all subsequent EnDAT3 API calls.
| enum endat3_lph_status |
| enum endat3_bg_req_opcode |
EnDAT3 Background Request (BGREQ) OpCodes.
Operation codes for background processing operations.
| enum endat3_req_code |
EnDAT3 Foreground Request (REQ.CODE) OpCodes.
Operation codes for foreground request commands.
| enum endat3_menu_option |
EnDAT3 Menu Options.
Menu options for user interface commands.
HPF STATUS bits.
Individual bits in the HPF status byte.
LPH Status Flags.
Status flags for the Low Priority Header (LPH).
| enum endat3_error_code |
EnDat3 Error Codes.
Error codes used in foreground and background communication.
| void endat3_params_init | ( | endat3_params * | params | ) |
Initialize EnDAT3 parameters with default values.
Populates the endat3_params structure with default values. Must be called before passing params to endat3_init.
| [out] | params | Pointer to params structure to initialize |
| endat3_handle endat3_init | ( | uint32_t | index, |
| const endat3_params * | endat3_params | ||
| ) |
Initialize an EnDAT3 instance.
Initializes an EnDAT3 driver instance with the specified configuration. This function validates all parameters, sets up the firmware interface, and configures hardware based on both SysConfig attributes and runtime params.
| [in] | index | Index of EnDAT3 (0 to gEndat3ConfigNum - 1) |
| [in] | endat3_params | Pointer to structure containing EnDAT3 initialization parameters |
| handle | Pointer to initialized endat3_handle instance |
| NULL | On validation failure including:
|
| void endat3_deinit | ( | endat3_handle | handle | ) |
De-initialize an EnDAT3 instance.
De-initializes the EnDAT3 instance by marking the handle as closed (is_open = 0). It does not free memory or disable PRU cores.
| [in] | handle | Handle to EnDAT3 instance |
| const endat3_attrs* endat3_get_attrs | ( | endat3_handle | handle | ) |
Get pointer to EnDAT3 attributes structure.
Provides access to the read-only attributes structure containing configuration parameters set during initialization or generated by SysConfig.
| [in] | handle | EnDAT3 handle |
| attrs | Pointer to const endat3_attrs structure |
| NULL | If handle is NULL |
| endat3_priv* endat3_get_priv | ( | endat3_handle | handle | ) |
Get pointer to EnDAT3 private data structure.
Provides access to the private data structure containing runtime state information.
| [in] | handle | EnDAT3 handle |
| priv | Pointer to endat3_priv structure |
| NULL | If handle is NULL |
| int32_t endat3_send_command | ( | endat3_handle | handle, |
| uint8_t | cmd, | ||
| uint8_t | frames | ||
| ) |
Send EnDAT3 command.
Prepares and sends an EnDAT3 command with the specified command code and number of frames. Validates input parameters and checks for buffer overflow conditions before transmission.
| handle | EnDAT3 handle |
| cmd | Command code |
| frames | Number of frames to transmit (1-6, limited by TX_BUFFER_SIZE/4) |
| int32_t endat3_receive_response | ( | endat3_handle | handle | ) |
Receive EnDAT3 response.
Receives and processes EnDAT3 response frames, verifying CRC integrity and parsing the data into appropriate structures.
| handle | EnDAT3 handle |
| const char* endat3_get_error_description | ( | endat3_error_code | error_code | ) |
Get error description string.
Returns a human-readable description for the given EnDAT3 error code. Useful for logging and debugging error conditions.
| error_code | The error code to get description for |
| const char* endat3_get_error_action | ( | endat3_error_code | error_code | ) |
Get recommended action for error code.
Returns a recommended action string for the given EnDAT3 error code. Helps users understand what to do when an error occurs.
| error_code | The error code to get recommended action for |
| int32_t endat3_handle_background_command_request | ( | endat3_handle | handle, |
| const endat3_bg_cmd_params * | params, | ||
| uint8_t * | mode, | ||
| const char ** | acc_level_desc | ||
| ) |
Handle background command request.
Processes and prepares a background command request for transmission. Handles various background operations like READ, WRITE, AUTH, PROTECT, etc. Formats the command data according to the operation code and parameters.
| handle | EnDAT3 handle |
| params | Pointer to background command parameters structure (endat3_bg_cmd_params) |
| mode | Pointer to store mode value (optional, can be NULL if not needed). Only populated when op_code is ENDAT3_BGREQ_PROTECT and mode is not NULL. |
| acc_level_desc | Pointer to store access level description string (optional, can be NULL if not needed). Only populated when op_code is ENDAT3_BGREQ_PROTECT and acc_level_desc is not NULL. |
| ENDAT3_SUCCESS | (0) on success |
| ENDAT3_ERR_INVALID_INPUT | (-1) on validation failure (NULL handle, NULL params, or index >= ENDAT3_MAX_BG_CMD_INDEX) |
| int32_t endat3_get_hpf_status | ( | endat3_handle | handle, |
| uint8_t * | status | ||
| ) |
Get HPF status byte.
Retrieves the status byte from the High Priority Frame, which contains critical status flags including F, W, HPFV, RM, and ERR_REQ bits.
| handle | EnDAT3 handle |
| status | Pointer to store HPF status byte |
| int32_t endat3_get_hpf_data | ( | endat3_handle | handle, |
| uint8_t * | data | ||
| ) |
Get HPF data array.
Retrieves the 6-byte data payload from the High Priority Frame. The data is copied to the provided buffer.
| handle | EnDAT3 handle |
| data | Buffer to store HPF data (must be at least 6 bytes) |
| int32_t endat3_get_hpf_crc | ( | endat3_handle | handle, |
| uint8_t * | crc | ||
| ) |
Get HPF CRC value.
Retrieves the CRC checksum from the High Priority Frame.
| handle | EnDAT3 handle |
| crc | Pointer to store HPF CRC value |
| int32_t endat3_get_hpf_data_64_bit | ( | endat3_handle | handle, |
| uint64_t * | data | ||
| ) |
Get HPF data as 64-bit value.
Retrieves the HPF data payload as a single 64-bit unsigned integer. Useful for position data extraction. Data is packed in little-endian format.
| handle | EnDAT3 handle |
| data | Pointer to store HPF data as uint64_t |
| int32_t endat3_is_hpf_data_valid | ( | endat3_handle | handle, |
| uint8_t * | is_valid | ||
| ) |
Check if HPF data is valid.
Checks the HPFV bit in the HPF status to determine if the data is valid.
| handle | EnDAT3 handle |
| is_valid | Pointer to store result (1 if HPF data is valid, 0 otherwise) |
| int32_t endat3_has_hpf_error | ( | endat3_handle | handle, |
| uint8_t * | has_error | ||
| ) |
Check if HPF has error flag set.
Checks the F bit in the HPF status to determine if an error is present.
| handle | EnDAT3 handle |
| has_error | Pointer to store result (1 if error flag is set, 0 otherwise) |
| int32_t endat3_has_hpf_warning | ( | endat3_handle | handle, |
| uint8_t * | has_warning | ||
| ) |
Check if HPF has warning flag set.
Checks the W bit in the HPF status to determine if a warning is present.
| handle | EnDAT3 handle |
| has_warning | Pointer to store result (1 if warning flag is set, 0 otherwise) |
| int32_t endat3_has_absolute_value | ( | endat3_handle | handle, |
| uint8_t * | has_absolute | ||
| ) |
Check if absolute value is available.
Checks the RM bit in the HPF status to determine if absolute position value is available.
| handle | EnDAT3 handle |
| has_absolute | Pointer to store result (1 if absolute value is available, 0 otherwise) |
| int32_t endat3_get_lph_status | ( | endat3_handle | handle, |
| uint8_t * | status | ||
| ) |
Get LPH status byte.
Retrieves the status byte from the Low Priority Header, which contains the communication state and error flags.
| handle | EnDAT3 handle |
| status | Pointer to store LPH status byte |
| int32_t endat3_get_lph_lpf_count | ( | endat3_handle | handle, |
| uint8_t * | num_lpf | ||
| ) |
Get number of LPF frames.
Retrieves the number of Low Priority Frames indicated in the LPH.
| handle | EnDAT3 handle |
| num_lpf | Pointer to store number of LPF frames (0 to MAX_LPF_COUNT) |
| int32_t endat3_get_lph_crc | ( | endat3_handle | handle, |
| uint8_t * | crc | ||
| ) |
Get LPH CRC value.
Retrieves the CRC checksum from the Low Priority Header.
| handle | EnDAT3 handle |
| crc | Pointer to store LPH CRC value |
| int32_t endat3_get_lph_state | ( | endat3_handle | handle, |
| endat3_lph_status * | state | ||
| ) |
Get LPH communication state.
Extracts the communication state from the LPH status byte (bits 0-1).
| handle | EnDAT3 handle |
| state | Pointer to store LPH state (IDLE, RX_START, RX_LAST, BUSY) |
| int32_t endat3_has_bg_error | ( | endat3_handle | handle, |
| uint8_t * | has_error | ||
| ) |
Check if background operation has error.
Checks the BG.ERR_EXEC bit in the LPH status.
| handle | EnDAT3 handle |
| has_error | Pointer to store result (1 if background error is present, 0 otherwise) |
| int32_t endat3_is_bg_busy | ( | endat3_handle | handle, |
| uint8_t * | is_busy | ||
| ) |
Check if background processor is busy.
Checks the BG.BUSY bit in the LPH status.
| handle | EnDAT3 handle |
| is_busy | Pointer to store result (1 if background processor is busy, 0 otherwise) |
| int32_t endat3_has_bg_rtx_error | ( | endat3_handle | handle, |
| uint8_t * | has_error | ||
| ) |
Check if background RTX error occurred.
Checks the BG.RTX_ERROR bit in the LPH status.
| handle | EnDAT3 handle |
| has_error | Pointer to store result (1 if background RTX error occurred, 0 otherwise) |
| int32_t endat3_get_lpf_status | ( | endat3_handle | handle, |
| uint8_t | index, | ||
| uint8_t * | status | ||
| ) |
Get LPF status byte for specific frame.
Retrieves the status byte from a specific Low Priority Frame.
| handle | EnDAT3 handle |
| index | LPF frame index (0 to MAX_LPF_COUNT-1) |
| status | Pointer to store LPF status byte |
| int32_t endat3_get_lpf_data | ( | endat3_handle | handle, |
| uint8_t | index, | ||
| uint8_t * | data | ||
| ) |
Get LPF data array for specific frame.
Retrieves the 6-byte data payload from a specific Low Priority Frame.
| handle | EnDAT3 handle |
| index | LPF frame index (0 to MAX_LPF_COUNT-1) |
| data | Buffer to store LPF data (must be at least 6 bytes) |
| int32_t endat3_get_lpf_crc | ( | endat3_handle | handle, |
| uint8_t | index, | ||
| uint8_t * | crc | ||
| ) |
Get LPF CRC value for specific frame.
Retrieves the CRC checksum from a specific Low Priority Frame for validation.
| handle | EnDAT3 handle |
| index | LPF frame index (0 to MAX_LPF_COUNT-1) |
| crc | Pointer to store LPF CRC byte |
| int32_t endat3_get_lpf_fid | ( | endat3_handle | handle, |
| uint8_t | index, | ||
| uint8_t * | fid | ||
| ) |
Get LPF FID (Frame ID) for specific frame.
Extracts the Frame ID from the LPF status byte.
| handle | EnDAT3 handle |
| index | LPF frame index (0 to MAX_LPF_COUNT-1) |
| fid | Pointer to store FID value (0-255) |
| int32_t endat3_is_connected | ( | endat3_handle | handle, |
| uint8_t * | is_connected | ||
| ) |
Get connection status.
Checks if the encoder is connected and communicating.
| handle | EnDAT3 handle |
| is_connected | Pointer to store connection status (1 if connected, 0 otherwise) |
| int32_t endat3_is_busy | ( | endat3_handle | handle, |
| uint8_t * | is_busy | ||
| ) |
Get busy status.
Checks if a transfer is currently in progress. Returns 1 only when encoder state is ENCODER_BUSY. Both ENCODER_IDLE and ENCODER_ERROR states return 0.
| handle | EnDAT3 handle |
| is_busy | Pointer to store busy status (1 if state == ENCODER_BUSY, 0 otherwise) |
| int32_t endat3_set_busy | ( | endat3_handle | handle, |
| uint8_t | busy | ||
| ) |
Set or clear busy status.
Sets or clears the busy flag. Set busy=1 to mark a transfer as in progress; set busy=0 to clear the busy state when no transfer is active.
| handle | EnDAT3 handle |
| busy | Busy state to set (1 for busy, 0 for not busy) |
| int32_t endat3_get_expected_tx_frame_count | ( | endat3_handle | handle, |
| uint32_t * | count | ||
| ) |
Get expected TX frame count.
Retrieves the number of frames expected to be transmitted.
| handle | EnDAT3 handle |
| count | Pointer to store expected TX frame count |
| int32_t endat3_set_expected_tx_frame_count | ( | endat3_handle | handle, |
| uint32_t | count | ||
| ) |
Set expected TX frame count.
Sets the number of frames expected to be transmitted.
| handle | EnDAT3 handle |
| count | Expected frame count |
| int32_t endat3_get_propagation_time | ( | endat3_handle | handle, |
| uint32_t * | prop_time | ||
| ) |
Get propagation time.
Retrieves the measured propagation time from ECHO command. The value is in PRU clock cycles.
| handle | EnDAT3 handle |
| prop_time | Pointer to store propagation time in PRU clock cycles |
| int32_t endat3_get_foreground_op_code | ( | endat3_handle | handle, |
| uint32_t * | opcode | ||
| ) |
Get foreground operation code.
Retrieves the current foreground operation code.
| handle | EnDAT3 handle |
| opcode | Pointer to store foreground operation code |
| int32_t endat3_set_foreground_op_code | ( | endat3_handle | handle, |
| uint32_t | opcode | ||
| ) |
Set foreground operation code.
Sets the foreground operation code for the next command.
| handle | EnDAT3 handle |
| opcode | Operation code to set (use endat3_req_code enum values) |
| int32_t endat3_get_background_op_code | ( | endat3_handle | handle, |
| uint32_t * | opcode | ||
| ) |
Get background operation code.
Retrieves the current background operation code.
| handle | EnDAT3 handle |
| opcode | Pointer to store background operation code |
| int32_t endat3_set_background_op_code | ( | endat3_handle | handle, |
| uint32_t | opcode | ||
| ) |
Set background operation code.
Sets the background operation code for the next command.
| handle | EnDAT3 handle |
| opcode | Operation code to set (use endat3_bg_req_opcode enum values) |
| int32_t endat3_get_bg_data | ( | endat3_handle | handle, |
| uint8_t | index, | ||
| uint32_t * | data | ||
| ) |
Get background data word.
Retrieves a specific word from the background data array.
| handle | EnDAT3 handle |
| index | Data word index (0 to BG_DATA_SIZE-1) |
| data | Pointer to store the retrieved data value |
| int32_t endat3_set_bg_data | ( | endat3_handle | handle, |
| uint8_t | index, | ||
| uint32_t | data | ||
| ) |
Set background data word.
Sets a specific word in the background data array.
| handle | EnDAT3 handle |
| index | Data word index (0 to BG_DATA_SIZE-1) |
| data | Data value to set |
| int32_t endat3_get_all_bg_data | ( | endat3_handle | handle, |
| uint32_t * | data | ||
| ) |
Get all background data.
Retrieves all background data words into the provided buffer.
| handle | EnDAT3 handle |
| data | Buffer to store background data (must be at least BG_DATA_SIZE words = 6 words = 24 bytes) |
| int32_t endat3_set_all_bg_data | ( | endat3_handle | handle, |
| const uint32_t * | data | ||
| ) |
Set all background data.
Sets all background data words from the provided buffer. Copies exactly BG_DATA_SIZE (6) words (24 bytes) from the source buffer to the internal background data array.
| handle | EnDAT3 handle |
| data | Buffer containing background data (must be at least BG_DATA_SIZE words = 6 words = 24 bytes) |
| const volatile uint8_t* endat3_get_rx_buffer | ( | endat3_handle | handle | ) |
Get RX buffer pointer.
Provides read-only access to the receive buffer.
| handle | EnDAT3 handle |
| const volatile uint8_t* endat3_get_tx_buffer | ( | endat3_handle | handle | ) |
Get TX buffer pointer.
Provides read-only access to the transmit buffer.
| handle | EnDAT3 handle |
| int32_t endat3_set_tx_buffer | ( | endat3_handle | handle, |
| const uint8_t * | data, | ||
| uint32_t | length | ||
| ) |
Copy data to TX buffer.
Safely copies data to the transmit buffer with bounds checking.
| handle | EnDAT3 handle |
| data | Source data buffer |
| length | Number of bytes to copy (1-24) |
| int32_t endat3_get_hpf_frame | ( | endat3_handle | handle, |
| endat3_hpf * | hpf | ||
| ) |
Get complete HPF structure.
Retrieves the entire High Priority Frame structure.
| handle | EnDAT3 handle |
| hpf | Pointer to HPF structure to fill |
| int32_t endat3_get_lph_frame | ( | endat3_handle | handle, |
| endat3_lph * | lph | ||
| ) |
Get complete LPH structure.
Retrieves the entire Low Priority Header structure.
| handle | EnDAT3 handle |
| lph | Pointer to LPH structure to fill |
| int32_t endat3_get_lpf_frame | ( | endat3_handle | handle, |
| uint8_t | index, | ||
| endat3_lpf * | lpf | ||
| ) |
Get complete LPF structure.
Retrieves the entire Low Priority Frame structure for a specific index.
| handle | EnDAT3 handle |
| index | LPF frame index (0 to MAX_LPF_COUNT-1) |
| lpf | Pointer to LPF structure to fill |
| int32_t endat3_get_error_code | ( | endat3_handle | handle, |
| endat3_error_code * | error_code | ||
| ) |
Extract error code from HPF or LPF.
Extracts the error code from HPF data (when HPFV=0) or LPF data (when BG.ERR_EXEC is set).
| handle | EnDAT3 handle |
| error_code | Pointer to store error code value |
| endat3_interface* endat3_get_interface | ( | endat3_handle | handle | ) |
Get interface pointer (advanced use)
Provides direct access to the endat3_interface structure for advanced users who need full control. Use with caution.
| handle | EnDAT3 handle |
| int32_t endat3_set_operating_mode | ( | endat3_handle | handle, |
| uint8_t | opmode | ||
| ) |
Set operating mode (host trigger or periodic trigger)
Configures the firmware operating mode for the EnDAT3 interface. This determines whether the encoder is triggered by host command, or sampled automatically when IEP counter reaches the configured CMP event compare value, or sampled automatically when an external signal triggers the IEP capture event.
**Configuration requirements for ENDAT3_OPMODE_PERIODIC_CMP :**
**Configuration requirements for ENDAT3_OPMODE_PERIODIC_CAP :**
| handle | EnDAT3 handle |
| opmode | Operating mode: 0 = periodic CMP trigger, 1 = host trigger, 2 = periodic CAP trigger |
| int32_t endat3_get_operating_mode | ( | endat3_handle | handle, |
| uint8_t * | opmode | ||
| ) |
Get current operating mode.
Retrieves the current firmware operating mode.
| handle | EnDAT3 handle |
| opmode | Pointer to store operating mode (0 = periodic CMP, 1 = host trigger, 2 = periodic CAP) |
| int32_t endat3_config_iep_cap_event | ( | endat3_handle | handle, |
| uint8_t | event_num | ||
| ) |
Configure IEP CAP event number in PRU DMEM.
| handle | EnDAT3 handle |
| event_num | CAP event number (0-7) to use for periodic triggering |
| int32_t endat3_config_iep_cmp_event | ( | endat3_handle | handle, |
| uint8_t | event_num | ||
| ) |
Configure IEP CMP event number in PRU DMEM.
| handle | EnDAT3 handle |
| event_num | CMP event number (0-15) to use for periodic triggering |
| int32_t endat3_release_start_trigger | ( | endat3_handle | handle | ) |
Release start trigger to firmware.
Signals the firmware to begin processing by setting the start_trigger flag. The firmware will process the command based on the current operating mode:
| handle | EnDAT3 handle |
| int32_t endat3_clear_start_trigger | ( | endat3_handle | handle | ) |
Clear start trigger flag.
Clears the start_trigger flag after the firmware has processed the command. This prepares the interface for the next command.
| handle | EnDAT3 handle |
| int32_t endat3_get_start_trigger_status | ( | endat3_handle | handle, |
| uint8_t * | trigger_status | ||
| ) |
Get current start trigger status.
Retrieves the current state of the start_trigger flag.
| handle | EnDAT3 handle |
| trigger_status | Pointer to store trigger status (1 if set, 0 if cleared) |