AM263Px Motor Control SDK  2025.00.00
Tamagawa PRU-ICSS Interface Structures

Introduction

This module contains structures that define the PRU-ICSS firmware interface for Tamagawa encoder communication. These structures are mapped to PRU DRAM and provide the communication interface between ARM and PRU cores.

Data Structures

struct  tamagawa_ch_info
 Structure defining Tamagawa per channel interface. More...
 
struct  tamagawa_cmd
 Structure defining Tamagawa command interface. More...
 
struct  tamagawa_fw_config
 Structure defining Tamagawa configuration interface. More...
 
struct  tamagawa_rx_frames
 Tamagawa received frame data. More...
 
struct  tamagawa_interface
 Tamagawa main interface structure. More...
 
struct  tamagawa_channel_config
 Tamagawa channel configuration structure. More...
 
struct  tamagawa_periodic_trigger_cfg
 Tamagawa periodic trigger configuration structure. More...
 
struct  tamagawa_eeprom_interface
 Tamagawa EEPROM interface structure. More...
 
struct  tamagawa_xchg
 Structure defining complete Tamagawa PRU-ICSS exchange interface. More...
 
struct  tamagawa_clk_cfg
 Tamagawa clock configuration structure. More...
 
struct  tamagawa_attrs
 Tamagawa attributes structure. More...
 
struct  tamagawa_priv
 Tamagawa private runtime state structure. More...
 
struct  tamagawa_config
 Tamagawa configuration structure (handle) More...
 
struct  tamagawa_params
 Tamagawa initialization parameters structure. More...
 

Functions

void tamagawa_params_init (tamagawa_params *params)
 Initialize Tamagawa parameters structure with default values. More...
 
tamagawa_handle tamagawa_init (uint32_t index, const tamagawa_params *params)
 Initialize a Tamagawa instance. More...
 
void tamagawa_deinit (tamagawa_handle handle)
 Deinitialize Tamagawa interface and release resources. More...
 
int32_t tamagawa_command_process (tamagawa_handle handle, int32_t cmd)
 Process a Tamagawa command (build, send, and wait for completion) More...
 
int32_t tamagawa_command_build (tamagawa_handle handle, int32_t cmd)
 Build a Tamagawa command in the PRU interface. More...
 
int32_t tamagawa_command_send (tamagawa_handle handle)
 Trigger sending the Tamagawa command in PRU. More...
 
int32_t tamagawa_command_wait (tamagawa_handle handle)
 Wait until PRU finishes Tamagawa transaction. More...
 
int32_t tamagawa_config_global_rx_arm_cnt (tamagawa_handle handle, uint16_t rx_en_cnt)
 Configure global RX auto arm counter for Tamagawa interface. More...
 
int32_t tamagawa_config_clock (tamagawa_handle handle, tamagawa_clk_cfg *clk_cfg)
 Configure Tamagawa clock dividers and source selection. More...
 
int32_t tamagawa_config_host_trigger (tamagawa_handle handle)
 Configure Tamagawa interface for host trigger mode. More...
 
int32_t tamagawa_config_periodic_trigger_cmp_mode (tamagawa_handle handle)
 Configure Tamagawa interface for periodic trigger using IEP compare mode. More...
 
int32_t tamagawa_config_channel (tamagawa_handle handle, uint8_t mask)
 Configure channel mask for Tamagawa interface. More...
 
int32_t tamagawa_multi_channel_set_cur (tamagawa_handle handle, uint8_t ch)
 Set current channel for receive processing in multi-channel mode. More...
 
int32_t tamagawa_update_data_id (tamagawa_handle handle, int32_t cmd)
 Update the current requested command ID in Tamagawa interface. More...
 
int32_t tamagawa_update_adf (tamagawa_handle handle, uint32_t val, uint8_t ch)
 Update the ADF (EEPROM address) field for EEPROM command. More...
 
int32_t tamagawa_update_edf (tamagawa_handle handle, uint32_t val, uint8_t ch)
 Update the EDF (EEPROM data) field for EEPROM Write command. More...
 
int32_t tamagawa_parse (tamagawa_handle handle, int32_t cmd)
 Parse the data in Tamagawa interface received from the encoder. More...
 
int32_t tamagawa_crc_verify (tamagawa_handle handle)
 Verify the CRC computed by PRU firmware against encoder CRC. More...
 
int32_t tamagawa_update_crc (tamagawa_handle handle, int32_t cmd, uint8_t ch)
 Update CRC field for EEPROM command. More...
 
int32_t tamagawa_set_baudrate (tamagawa_handle handle, double baud_rate)
 Set Tamagawa communication baud rate. More...
 
const tamagawa_attrstamagawa_get_attrs (tamagawa_handle handle)
 Get pointer to Tamagawa attributes structure. More...
 
tamagawa_privtamagawa_get_priv (tamagawa_handle handle)
 Get pointer to Tamagawa private structure. More...
 
int32_t tamagawa_config_iep_cmp_event (tamagawa_handle handle, uint8_t channel, uint8_t event_num)
 Configure IEP CMP event for periodic trigger (DMEM configuration only) More...
 
int32_t tamagawa_config_iep_cap_event (tamagawa_handle handle, uint8_t channel, uint8_t event_num)
 Configure IEP CAP event for periodic trigger (DMEM configuration only) More...
 
int32_t tamagawa_config_periodic_trigger_cap_mode (tamagawa_handle handle)
 Configure Tamagawa interface for periodic trigger using IEP capture mode. More...
 

Typedefs

typedef tamagawa_configtamagawa_handle
 Tamagawa handle type. More...
 

Enumerations

enum  tamagawa_data_id {
  DATA_ID_0, DATA_ID_1, DATA_ID_2, DATA_ID_3,
  DATA_ID_6, DATA_ID_7, DATA_ID_8, DATA_ID_C,
  DATA_ID_D, PERIODIC_TRIGGER_CMP_CMD, PERIODIC_TRIGGER_CAP_CMD, DATA_ID_NUM
}
 Tamagawa Data ID codes. More...
 

Macros

#define TAMAGAWA_MAX_CHANNELS_PER_SLICE   (3)
 Maximum number of channels supported per PRU slice. More...
 
#define TAMAGAWA_MODE_SINGLE_CHANNEL_SINGLE_PRU   (0U)
 Single PRU - Single channel configuration mode. More...
 
#define TAMAGAWA_MODE_MULTI_CHANNEL_SINGLE_PRU   (1U)
 Single PRU - Multichannel configuration mode. More...
 
#define TAMAGAWA_MODE_MULTI_CHANNEL_MULTI_PRU   (2U)
 Multi PRU - Load share configuration mode. More...
 
#define TAMAGAWA_OPMODE_PERIODIC_CMP   (0x0U)
 Tamagawa operation mode: Periodic trigger mode using iep compare event. More...
 
#define TAMAGAWA_OPMODE_HOST_TRIGGER   (0x1U)
 Tamagawa operation mode: Host trigger. More...
 
#define TAMAGAWA_OPMODE_PERIODIC_CAP   (0x2U)
 Tamagawa operation mode: Periodic trigger mode using iep capture event. More...
 
#define TAMAGAWA_ENABLE_CYCLE_TRIGGER   (0x1)
 Enable cycle trigger for firmware. More...
 
#define TAMAGAWA_DISABLE_CYCLE_TRIGGER   (0x0)
 Disable cycle trigger for firmware. More...
 
#define TAMAGAWA_FREQ_2_5_MHZ   (2500000U)
 Allowed Tamagawa communication frequency: 2.5 MHz. More...
 
#define TAMAGAWA_FREQ_5_MHZ   (5000000U)
 Allowed Tamagawa communication frequency: 5 MHz. More...
 
#define TAMAGAWA_IEP_MAX_CAP_EVENT   (0x8U)
 Maximum IEP CAP event number (0-7) More...
 
#define TAMAGAWA_IEP_MAX_CMP_EVENT   (0x10U)
 Maximum IEP CMP event number (0-15) More...
 
#define TAMAGAWA_MAX_EEPROM_ADDRESS   (127)
 Maximum EEPROM address that can be used for EEPROM Read/Write. More...
 
#define TAMAGAWA_MAX_EEPROM_WRITE_DATA   (255)
 Maximum value that can be written to EEPROM. More...
 
#define TAMAGAWA_RX_OVERSAMPLING_RATE   (7)
 RX oversampling rate. Set 7 for 8x oversampling. More...
 
#define TAMAGAWA_DELAY_COUNTER_INCREMENT   (5)
 Delay counter increment value. 5 ns based on 200 MHz clock, as Three Channel Peripheral interface needs this value in 200 MHz clock units. More...
 
#define TAMAGAWA_EEPROM_WRITE_CRC_BYTES   (3)
 Number of bytes in CRC calculation for EEPROM Write (CF + ADF + EDF) More...
 
#define TAMAGAWA_EEPROM_READ_CRC_BYTES   (2)
 Number of bytes in CRC calculation for EEPROM Read (CF + ADF) More...
 
#define TAMAGAWA_BITS_PER_BYTE   (8)
 Number of bits in a byte. More...
 
#define TAMAGAWA_CRC_DATA_ARRAY_SIZE   (12)
 CRC calculation array size for storing frame data. More...
 
#define TAMAGAWA_DEFAULT_CMD_WAIT_DELAY_US   (100)
 Default command process delay in microseconds. More...
 
#define TAMAGAWA_DEFAULT_MAX_WAIT_LOOP_COUNT   (50U)
 Default maximum wait loop count. More...
 
#define TAMAGAWA_CF_EEPROM_WRITE   (0x32U)
 Tamagawa EEPROM Control Field value for Write operation. More...
 
#define TAMAGAWA_CF_EEPROM_READ   (0xEAU)
 Tamagawa EEPROM Control Field value for Read operation. More...
 
#define TAMAGAWA_CFG_REG_SIZE   (4U)
 IEP CAP0 register offset - cslr common file does not have defined cap registers FIXME: Remove these definitions once they are available in cslr_common.h. More...
 
#define TAMAGAWA_CSL_ICSS_PR1_IEP0_SLV_CAP0_REG0   (CSL_ICSS_PR1_IEP0_SLV_CAP_CFG_REG + 2U*TAMAGAWA_CFG_REG_SIZE)
 
#define TAMAGAWA_8_BYTE_REG_OFFSET   (8U)
 8-byte register offset for IEP registers More...
 

Macro Definition Documentation

◆ TAMAGAWA_MAX_CHANNELS_PER_SLICE

#define TAMAGAWA_MAX_CHANNELS_PER_SLICE   (3)

Maximum number of channels supported per PRU slice.

◆ TAMAGAWA_MODE_SINGLE_CHANNEL_SINGLE_PRU

#define TAMAGAWA_MODE_SINGLE_CHANNEL_SINGLE_PRU   (0U)

Single PRU - Single channel configuration mode.

Only one channel (ch0, ch1, or ch2) is used with a single PRU core. This is the simplest configuration for single encoder applications.

◆ TAMAGAWA_MODE_MULTI_CHANNEL_SINGLE_PRU

#define TAMAGAWA_MODE_MULTI_CHANNEL_SINGLE_PRU   (1U)

Single PRU - Multichannel configuration mode.

Multiple channels (up to 3: ch0, ch1, ch2) are managed by a single PRU core. All channels share the same PRU core resources without load sharing.

◆ TAMAGAWA_MODE_MULTI_CHANNEL_MULTI_PRU

#define TAMAGAWA_MODE_MULTI_CHANNEL_MULTI_PRU   (2U)

Multi PRU - Load share configuration mode.

Multiple channels are distributed across multiple PRU cores with load sharing. Each PRU core handles different channels with synchronized global reinit operations.

◆ TAMAGAWA_OPMODE_PERIODIC_CMP

#define TAMAGAWA_OPMODE_PERIODIC_CMP   (0x0U)

Tamagawa operation mode: Periodic trigger mode using iep compare event.

In periodic mode, the PRU firmware automatically triggers position readout based on IEP compare events.

◆ TAMAGAWA_OPMODE_HOST_TRIGGER

#define TAMAGAWA_OPMODE_HOST_TRIGGER   (0x1U)

Tamagawa operation mode: Host trigger.

In host trigger mode, the R5F host processor explicitly triggers each position readout by setting the trigger bit.

◆ TAMAGAWA_OPMODE_PERIODIC_CAP

#define TAMAGAWA_OPMODE_PERIODIC_CAP   (0x2U)

Tamagawa operation mode: Periodic trigger mode using iep capture event.

In periodic mode, the PRU firmware automatically triggers position readout based on IEP capture events.

◆ TAMAGAWA_ENABLE_CYCLE_TRIGGER

#define TAMAGAWA_ENABLE_CYCLE_TRIGGER   (0x1)

Enable cycle trigger for firmware.

◆ TAMAGAWA_DISABLE_CYCLE_TRIGGER

#define TAMAGAWA_DISABLE_CYCLE_TRIGGER   (0x0)

Disable cycle trigger for firmware.

◆ TAMAGAWA_FREQ_2_5_MHZ

#define TAMAGAWA_FREQ_2_5_MHZ   (2500000U)

Allowed Tamagawa communication frequency: 2.5 MHz.

◆ TAMAGAWA_FREQ_5_MHZ

#define TAMAGAWA_FREQ_5_MHZ   (5000000U)

Allowed Tamagawa communication frequency: 5 MHz.

◆ TAMAGAWA_IEP_MAX_CAP_EVENT

#define TAMAGAWA_IEP_MAX_CAP_EVENT   (0x8U)

Maximum IEP CAP event number (0-7)

IEP supports 8 capture events (CAP0-CAP7)

◆ TAMAGAWA_IEP_MAX_CMP_EVENT

#define TAMAGAWA_IEP_MAX_CMP_EVENT   (0x10U)

Maximum IEP CMP event number (0-15)

IEP supports 16 compare events (CMP0-CMP15)

◆ TAMAGAWA_MAX_EEPROM_ADDRESS

#define TAMAGAWA_MAX_EEPROM_ADDRESS   (127)

Maximum EEPROM address that can be used for EEPROM Read/Write.

◆ TAMAGAWA_MAX_EEPROM_WRITE_DATA

#define TAMAGAWA_MAX_EEPROM_WRITE_DATA   (255)

Maximum value that can be written to EEPROM.

◆ TAMAGAWA_RX_OVERSAMPLING_RATE

#define TAMAGAWA_RX_OVERSAMPLING_RATE   (7)

RX oversampling rate. Set 7 for 8x oversampling.

◆ TAMAGAWA_DELAY_COUNTER_INCREMENT

#define TAMAGAWA_DELAY_COUNTER_INCREMENT   (5)

Delay counter increment value. 5 ns based on 200 MHz clock, as Three Channel Peripheral interface needs this value in 200 MHz clock units.

◆ TAMAGAWA_EEPROM_WRITE_CRC_BYTES

#define TAMAGAWA_EEPROM_WRITE_CRC_BYTES   (3)

Number of bytes in CRC calculation for EEPROM Write (CF + ADF + EDF)

◆ TAMAGAWA_EEPROM_READ_CRC_BYTES

#define TAMAGAWA_EEPROM_READ_CRC_BYTES   (2)

Number of bytes in CRC calculation for EEPROM Read (CF + ADF)

◆ TAMAGAWA_BITS_PER_BYTE

#define TAMAGAWA_BITS_PER_BYTE   (8)

Number of bits in a byte.

◆ TAMAGAWA_CRC_DATA_ARRAY_SIZE

#define TAMAGAWA_CRC_DATA_ARRAY_SIZE   (12)

CRC calculation array size for storing frame data.

◆ TAMAGAWA_DEFAULT_CMD_WAIT_DELAY_US

#define TAMAGAWA_DEFAULT_CMD_WAIT_DELAY_US   (100)

Default command process delay in microseconds.

This delay is used in command wait loops to prevent busy-waiting and allow timeout detection. Can be overridden via tamagawa_params.

◆ TAMAGAWA_DEFAULT_MAX_WAIT_LOOP_COUNT

#define TAMAGAWA_DEFAULT_MAX_WAIT_LOOP_COUNT   (50U)

Default maximum wait loop count.

Maximum number of wait loop iterations in tamagawa_command_wait to detect communication failures. The actual timeout is: max_wait_loop_count × cmd_wait_delay_us. With defaults (50 × 100 us = 5000 us). Can be overridden via tamagawa_params.

◆ TAMAGAWA_CF_EEPROM_WRITE

#define TAMAGAWA_CF_EEPROM_WRITE   (0x32U)

Tamagawa EEPROM Control Field value for Write operation.

◆ TAMAGAWA_CF_EEPROM_READ

#define TAMAGAWA_CF_EEPROM_READ   (0xEAU)

Tamagawa EEPROM Control Field value for Read operation.

◆ TAMAGAWA_CFG_REG_SIZE

#define TAMAGAWA_CFG_REG_SIZE   (4U)

IEP CAP0 register offset - cslr common file does not have defined cap registers FIXME: Remove these definitions once they are available in cslr_common.h.

◆ TAMAGAWA_CSL_ICSS_PR1_IEP0_SLV_CAP0_REG0

#define TAMAGAWA_CSL_ICSS_PR1_IEP0_SLV_CAP0_REG0   (CSL_ICSS_PR1_IEP0_SLV_CAP_CFG_REG + 2U*TAMAGAWA_CFG_REG_SIZE)

◆ TAMAGAWA_8_BYTE_REG_OFFSET

#define TAMAGAWA_8_BYTE_REG_OFFSET   (8U)

8-byte register offset for IEP registers

Typedef Documentation

◆ tamagawa_handle

Tamagawa handle type.

Opaque pointer to a Tamagawa configuration structure. Returned by tamagawa_init and used in all Tamagawa APIs.

Enumeration Type Documentation

◆ tamagawa_data_id

Tamagawa Data ID codes.

Enumerator
DATA_ID_0 

Data readout: data in one revolution

DATA_ID_1 

Data readout: multi-turn data

DATA_ID_2 

Data readout: encoder ID

DATA_ID_3 

Data readout: data in one revolution, encoder ID, multi-turn, encoder error

DATA_ID_6 

EEPROM write

DATA_ID_7 

Reset

DATA_ID_8 

Reset

DATA_ID_C 

Reset

DATA_ID_D 

EEPROM read

PERIODIC_TRIGGER_CMP_CMD 

Periodic trigger command using IEP compare event

PERIODIC_TRIGGER_CAP_CMD 

Periodic trigger command using IEP capture event

DATA_ID_NUM 

Number of Data ID codes

Function Documentation

◆ tamagawa_params_init()

void tamagawa_params_init ( tamagawa_params params)

Initialize Tamagawa parameters structure with default values.

This function initializes a tamagawa_params structure with default values. Call this function before setting custom parameters and passing to tamagawa_init.

Parameters
[out]paramsPointer to tamagawa_params structure to initialize

◆ tamagawa_init()

tamagawa_handle tamagawa_init ( uint32_t  index,
const tamagawa_params params 
)

Initialize a Tamagawa instance.

This function initializes a Tamagawa instance by setting up the firmware interface and configuring hardware based on tamagawa_attrs and tamagawa_params. The function validates all input parameters and initializes the PRU-ICSS interface.

This function performs the following operations:

  • Validates index against the number of configured instances (gTamagawaConfigNum)
  • Validates PRUICSS handle is not NULL
  • Validates PRU slice value (0 or 1)
  • Validates IEP compare event (0-15) and capture event (0-7) for enabled channels
  • Validates clock frequencies (must be positive)
  • Validates IEP instance (0 or 1)
  • Validates clock source selection (0 or 1)
  • Validates baud rate (must be TAMAGAWA_FREQ_2_5_MHZ or TAMAGAWA_FREQ_5_MHZ)
  • Sets up PRU DRAM base address for firmware interface
  • Marks handle as open

Internal API calls (in order):

  • tamagawa_config_clr_cfg0() - Clears PRU Three Channel Peripheral Interface CFG0 registers
  • tamagawa_config_channel() - Configures channel mask for both single and multi-channel modes
  • PRUICSS_setGpMuxSelect() - Sets GP mux selection for Three Channel Peripheral Interface
  • tamagawa_config_iep_base_address() - Writes IEP base address offset to PRU DRAM
  • tamagawa_config_iep_cmp_event() - Configures IEP CMP event number in PRU DRAM for enabled channels
  • tamagawa_config_iep_cap_event() - Configures IEP CAP event number and capture register in PRU DRAM for enabled channels
  • tamagawa_config_load_share() - Configures primary core mask and enables load-share hardware (for TAMAGAWA_MODE_MULTI_CHANNEL_MULTI_PRU mode only)
  • tamagawa_set_baudrate() - Configures communication baud rate from attrs configuration
  • tamagawa_config_host_trigger() - Sets default trigger mode to host trigger
Parameters
[in]indexIndex of Tamagawa handle to use in the gTamagawaHandle handle array
[in]paramsPointer to structure containing Tamagawa parameters. Use tamagawa_params_init to initialize with defaults before setting custom values. Must not be NULL.
Return values
handlePointer to initialized tamagawa_handle instance
NULLOn validation failure (invalid index, NULL params, invalid configuration, or internal API call failure)
Note
Channel configuration, trigger mode, and baud rate are automatically set during initialization based on SysConfig parameters. Applications do not need to call configuration functions separately.

◆ tamagawa_deinit()

void tamagawa_deinit ( tamagawa_handle  handle)

Deinitialize Tamagawa interface and release resources.

This function deinitializes a Tamagawa instance by marking it as closed. It does not free memory as the handle is statically allocated via SysConfig. After calling this function, the handle should not be used until reinitialized with tamagawa_init.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
Note
NULL check: If handle is NULL, function returns without performing any operation.

◆ tamagawa_command_process()

int32_t tamagawa_command_process ( tamagawa_handle  handle,
int32_t  cmd 
)

Process a Tamagawa command (build, send, and wait for completion)

This function combines command setup, triggering, and waiting for completion in a single call. It internally calls:

For EEPROM commands (DATA_ID_6, DATA_ID_D), the function also resets the command ID for all channels after completion. The multi-channel mask for EEPROM operations is determined automatically from the enabled channels configured in the attrs structure.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]cmdTamagawa command number (see tamagawa_data_id)
Return values
SystemP_SUCCESSCommand processed successfully
SystemP_TIMEOUTOn timeout waiting for firmware acknowledgment (propagated from tamagawa_command_wait)
SystemP_FAILURECommand processing failed (invalid handle or invalid command)

◆ tamagawa_command_build()

int32_t tamagawa_command_build ( tamagawa_handle  handle,
int32_t  cmd 
)

Build a Tamagawa command in the PRU interface.

This function sets up the Tamagawa command parameters in the PRU interface based on the command type. The command is not sent until tamagawa_command_send is called. For EEPROM commands (DATA_ID_6, DATA_ID_D), this function prepares the TX data with CF, ADF, EDF, and CRC fields. The multi-channel mask for EEPROM operations is determined automatically from the enabled channels configured in the attrs structure.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]cmdTamagawa command number (see tamagawa_data_id)
Return values
SystemP_SUCCESSCommand built successfully
SystemP_FAILURECommand build failed (invalid handle, unsupported command)

◆ tamagawa_command_send()

int32_t tamagawa_command_send ( tamagawa_handle  handle)

Trigger sending the Tamagawa command in PRU.

This function triggers the PRU firmware to send the command that was previously set up using tamagawa_command_build. It sets the trigger bit in the PRU interface, which signals the firmware to start the transaction.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
Return values
SystemP_SUCCESSCommand trigger successful
SystemP_FAILURENULL handle provided

◆ tamagawa_command_wait()

int32_t tamagawa_command_wait ( tamagawa_handle  handle)

Wait until PRU finishes Tamagawa transaction.

This function waits in a polling loop until the PRU firmware clears the trigger bit, indicating that the command has been completed. This is a blocking call with timeout protection.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
Return values
SystemP_SUCCESSCommand completed successfully
SystemP_FAILURENULL handle provided
SystemP_TIMEOUTTimeout occurred (configured via tamagawa_params.max_wait_loop_count before calling tamagawa_init, default: 5000 us = 50 loops × 100 us/loop)

◆ tamagawa_config_global_rx_arm_cnt()

int32_t tamagawa_config_global_rx_arm_cnt ( tamagawa_handle  handle,
uint16_t  rx_en_cnt 
)

Configure global RX auto arm counter for Tamagawa interface.

This function configures the global RX auto arm counter register for all three channels. The counter value determines the timing for RX enable.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]rx_en_cntValue to be set in global RX auto arm counter register
Return values
SystemP_SUCCESSConfiguration successful
SystemP_FAILURENULL handle provided

◆ tamagawa_config_clock()

int32_t tamagawa_config_clock ( tamagawa_handle  handle,
tamagawa_clk_cfg clk_cfg 
)

Configure Tamagawa clock dividers and source selection.

This function configures the PRU Three Channel Peripheral Interface's RX and TX clock dividers and clock source selection. It writes to PRUx_ED_RXCFG and PRUx_ED_TXCFG registers.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]clk_cfgPointer to structure containing clock configuration data
Return values
SystemP_SUCCESSConfiguration successful
SystemP_FAILURENULL handle or NULL clk_cfg provided

◆ tamagawa_config_host_trigger()

int32_t tamagawa_config_host_trigger ( tamagawa_handle  handle)

Configure Tamagawa interface for host trigger mode.

In this mode, commands are sent when explicitly triggered by the host using tamagawa_command_send.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
Return values
SystemP_SUCCESSConfiguration successful
SystemP_FAILURENULL handle provided

◆ tamagawa_config_periodic_trigger_cmp_mode()

int32_t tamagawa_config_periodic_trigger_cmp_mode ( tamagawa_handle  handle)

Configure Tamagawa interface for periodic trigger using IEP compare mode.

Configures the Tamagawa firmware to use IEP CMP (compare) events for periodic triggering. Position data is sampled automatically when the IEP compare event occurs.

Configuration requirements:

Parameters
[in]handleTamagawa handle returned by tamagawa_init
Return values
SystemP_SUCCESSConfiguration successful
SystemP_FAILURENULL handle provided

◆ tamagawa_config_channel()

int32_t tamagawa_config_channel ( tamagawa_handle  handle,
uint8_t  mask 
)

Configure channel mask for Tamagawa interface.

This function configures the channel mask for both single-channel and multi-channel modes. In single-channel mode, it also stores the specific channel index in priv->channel based on the channel enable flags (channel0_enabled, channel1_enabled, channel2_enabled).

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]maskChannel mask (valid range 1-7 for up to 3 channels)
  • Bit 0: Channel 0
  • Bit 1: Channel 1
  • Bit 2: Channel 2
Return values
SystemP_SUCCESSConfiguration successful
SystemP_FAILURENULL handle or invalid mask (mask == 0 or mask > 0x07)
Note
NULL check: Strict check on handle. Mask bounds checked (1-7).

◆ tamagawa_multi_channel_set_cur()

int32_t tamagawa_multi_channel_set_cur ( tamagawa_handle  handle,
uint8_t  ch 
)

Set current channel for receive processing in multi-channel mode.

In multi-channel configuration, after the receive transaction is complete, call this function to select each channel before invoking RX parsing APIs to process the data received on that channel.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]chChannel number to be selected (0-2, see TAMAGAWA_MAX_CHANNELS_PER_SLICE)
Return values
SystemP_SUCCESSConfiguration successful
SystemP_FAILURENULL handle or invalid channel (ch >= TAMAGAWA_MAX_CHANNELS_PER_SLICE)
Note
NULL check: Strict check on handle. Channel bounds checked (0-2).

◆ tamagawa_update_data_id()

int32_t tamagawa_update_data_id ( tamagawa_handle  handle,
int32_t  cmd 
)

Update the current requested command ID in Tamagawa interface.

This function updates the data_id field in the Tamagawa interface structure. For EEPROM commands (DATA_ID_6, DATA_ID_D), it also sets the command ID for all three channels in the EEPROM interface.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]cmdTamagawa command number (see tamagawa_data_id)
Return values
SystemP_SUCCESSUpdate successful
SystemP_FAILURENULL handle provided

◆ tamagawa_update_adf()

int32_t tamagawa_update_adf ( tamagawa_handle  handle,
uint32_t  val,
uint8_t  ch 
)

Update the ADF (EEPROM address) field for EEPROM command.

This function updates the ADF (Address Field) in the Tamagawa EEPROM interface for the specified channel. This is used for both EEPROM Read (DATA_ID_D) and EEPROM Write (DATA_ID_6) commands.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]valADF value to be updated (valid range 0-127, see TAMAGAWA_MAX_EEPROM_ADDRESS)
[in]chChannel number that is currently selected (0-2, see TAMAGAWA_MAX_CHANNELS_PER_SLICE)
Return values
SystemP_SUCCESSUpdate successful
SystemP_FAILURENULL handle, invalid channel (ch >= TAMAGAWA_MAX_CHANNELS_PER_SLICE), or invalid ADF value (val > TAMAGAWA_MAX_EEPROM_ADDRESS)
Note
NULL check: Strict check on handle. Channel and ADF value bounds checked.

◆ tamagawa_update_edf()

int32_t tamagawa_update_edf ( tamagawa_handle  handle,
uint32_t  val,
uint8_t  ch 
)

Update the EDF (EEPROM data) field for EEPROM Write command.

This function updates the EDF (Encoder Data Field) in the Tamagawa EEPROM interface for the specified channel. This is used only for EEPROM Write (DATA_ID_6) commands.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]valEDF value to be updated (valid range 0-255, see TAMAGAWA_MAX_EEPROM_WRITE_DATA)
[in]chChannel number that is currently selected (0-2, see TAMAGAWA_MAX_CHANNELS_PER_SLICE)
Return values
SystemP_SUCCESSUpdate successful
SystemP_FAILURENULL handle, invalid channel (ch >= TAMAGAWA_MAX_CHANNELS_PER_SLICE), or invalid EDF value (val > TAMAGAWA_MAX_EEPROM_WRITE_DATA)
Note
NULL check: Strict check on handle. Channel and EDF value bounds checked.

◆ tamagawa_parse()

int32_t tamagawa_parse ( tamagawa_handle  handle,
int32_t  cmd 
)

Parse the data in Tamagawa interface received from the encoder.

This function extracts and parses the received frame data based on the command type. It populates the rx_frames_received structure in the Tamagawa interface with the parsed data (CF, SF, ABS, ABM, ENID, ALMC, ADF, EDF, CRC).

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]cmdTamagawa command number (see tamagawa_data_id)
Return values
SystemP_SUCCESSData parsed successfully
SystemP_FAILUREParsing failed (invalid handle or unsupported command)

◆ tamagawa_crc_verify()

int32_t tamagawa_crc_verify ( tamagawa_handle  handle)

Verify the CRC computed by PRU firmware against encoder CRC.

This function checks the CRC verification result computed by the PRU firmware. The firmware calculates CRC and stores the result in cal_crc field. A value of 1 indicates successful CRC verification.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
Return values
SystemP_SUCCESSCRC verification passed
SystemP_FAILURECRC verification failed or NULL handle

◆ tamagawa_update_crc()

int32_t tamagawa_update_crc ( tamagawa_handle  handle,
int32_t  cmd,
uint8_t  ch 
)

Update CRC field for EEPROM command.

This function calculates and updates the CRC field for EEPROM commands based on CF, ADF, and EDF values. It internally calls the CRC calculation function. For EEPROM Write (DATA_ID_6), CRC is calculated over 3 bytes (CF + ADF + EDF). For EEPROM Read (DATA_ID_D), CRC is calculated over 2 bytes (CF + ADF).

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]cmdTamagawa command number (DATA_ID_6 or DATA_ID_D)
[in]chChannel number that is currently selected (0-2, see TAMAGAWA_MAX_CHANNELS_PER_SLICE)
Return values
SystemP_SUCCESSCRC update successful
SystemP_FAILURENULL handle or invalid channel (ch >= TAMAGAWA_MAX_CHANNELS_PER_SLICE)
Note
NULL check: Strict check on handle. Channel bounds checked (0-2).

◆ tamagawa_set_baudrate()

int32_t tamagawa_set_baudrate ( tamagawa_handle  handle,
double  baud_rate 
)

Set Tamagawa communication baud rate.

This function calculates and configures the RX/TX division factors and oversampling rate based on the specified baud rate. It internally calls:

The function also updates the firmware interface with the calculated division factors and oversampling rate.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]baud_rateBaud rate of the Tamagawa encoder in Hz (2.5 MHz or 5 MHz)
Return values
SystemP_SUCCESSConfiguration successful
SystemP_FAILURENULL handle provided
Note
The RX auto arm counter is configured for 1us delay. This may need adjustment based on specific encoder requirements.

◆ tamagawa_get_attrs()

const tamagawa_attrs* tamagawa_get_attrs ( tamagawa_handle  handle)

Get pointer to Tamagawa attributes structure.

This function returns a const pointer to the attributes structure containing compile-time configuration parameters from SysConfig. The attrs structure is read-only and should not be modified.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
Return values
attrsPointer to const tamagawa_attrs structure
NULLIf handle is NULL
Note
NULL check: Strict check on handle. Returns NULL on NULL handle.

◆ tamagawa_get_priv()

tamagawa_priv* tamagawa_get_priv ( tamagawa_handle  handle)

Get pointer to Tamagawa private structure.

This function returns a pointer to the private structure containing runtime state information. This is typically used for advanced operations or debugging.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
Return values
privPointer to tamagawa_priv structure
NULLIf handle is NULL
Note
NULL check: Strict check on handle. Returns NULL on NULL handle.
Warning
Modifying priv structure fields directly can lead to undefined behavior. Use provided APIs for configuration changes.

◆ tamagawa_config_iep_cmp_event()

int32_t tamagawa_config_iep_cmp_event ( tamagawa_handle  handle,
uint8_t  channel,
uint8_t  event_num 
)

Configure IEP CMP event for periodic trigger (DMEM configuration only)

This function configures the IEP compare event information in PRU shared memory (DMEM) for firmware access. It writes the event number to trigger_params structure. This function does NOT configure IEP hardware registers.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]channelTamagawa channel number (0-2). Used in load share mode, ignored in single PRU mode (always uses index 0).
[in]event_numCMP event number (0-15)
Return values
SystemP_SUCCESSCMP event configured successfully
SystemP_FAILUREOn NULL handle or invalid event_num/channel
Note
This function only configures firmware DMEM, not IEP hardware. Application must separately configure IEP CMP hardware registers.

◆ tamagawa_config_iep_cap_event()

int32_t tamagawa_config_iep_cap_event ( tamagawa_handle  handle,
uint8_t  channel,
uint8_t  event_num 
)

Configure IEP CAP event for periodic trigger (DMEM configuration only)

This function configures the IEP capture event information in PRU shared memory (DMEM) for firmware access. It writes the capture register address and event number to trigger_params structure. This function does NOT configure IEP hardware registers.

Parameters
[in]handleTamagawa handle returned by tamagawa_init
[in]channelTamagawa channel number (0-2). Used in load share mode, ignored in single PRU mode (always uses index 0).
[in]event_numCAP event number (0-7)
Return values
SystemP_SUCCESSCAP event configured successfully
SystemP_FAILUREOn NULL handle, invalid event_num/channel, or NULL IEP base address
Note
This function only configures firmware DMEM, not IEP hardware. Application must separately configure IEP CAP hardware registers.

◆ tamagawa_config_periodic_trigger_cap_mode()

int32_t tamagawa_config_periodic_trigger_cap_mode ( tamagawa_handle  handle)

Configure Tamagawa interface for periodic trigger using IEP capture mode.

Configures the Tamagawa firmware to use IEP CAP (capture) events for periodic triggering. Position data is sampled automatically when an external signal triggers the IEP capture event.

Configuration requirements:

  • IEP hardware CAP registers must be configured separately
  • External signal to IEP capture input should be configured
  • Use tamagawa_config_iep_cap_event to set event number in firmware. This function is called inside tamagawa_init by default.
  • CAP event range: 0-7
Parameters
[in]handleTamagawa handle returned by tamagawa_init
Return values
SystemP_SUCCESSCAP mode configured successfully
SystemP_FAILUREOn NULL handle
Note
This function only configures firmware DMEM, not IEP hardware. Application must separately configure IEP CAP hardware registers.