Skip to content

Commit

Permalink
Modify adn4604 config functions to return error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavosr8 committed Jan 29, 2024
1 parent 5d517dc commit 077d6bb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 28 deletions.
45 changes: 33 additions & 12 deletions modules/adn4604.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@

adn_connect_map_t con;

void adn4604_tx_control( uint8_t output, uint8_t tx_mode )
mmc_err adn4604_tx_control( uint8_t output, uint8_t tx_mode )
{
uint8_t i2c_addr, i2c_interf;
uint8_t enable[2];
uint8_t tx_len = 0;

/* TX Enable registers have an 0x20 offset from their value */
enable[0] = 0x20 + output;
Expand All @@ -69,56 +70,72 @@ void adn4604_tx_control( uint8_t output, uint8_t tx_mode )
enable[1] = tx_mode << 4;

if (i2c_take_by_chipid(CHIP_ID_ADN, &i2c_addr, &i2c_interf, (TickType_t)10) ) {
xI2CMasterWrite( i2c_interf, i2c_addr, enable, sizeof(enable) );
tx_len = xI2CMasterWrite( i2c_interf, i2c_addr, enable, sizeof(enable) );
i2c_give(i2c_interf);
}

if (!tx_len) return MMC_TIMEOUT_ERR;
return MMC_OK;
}

void adn4604_update( void )
mmc_err adn4604_update( void )
{
uint8_t i2c_addr, i2c_interf;
uint8_t update[2] = { ADN_XPT_UPDATE_REG, 0x01 };
uint8_t tx_len = 0;

if (i2c_take_by_chipid(CHIP_ID_ADN, &i2c_addr, &i2c_interf, (TickType_t)10) ) {
xI2CMasterWrite( i2c_interf, i2c_addr, update, sizeof(update) );
tx_len = xI2CMasterWrite( i2c_interf, i2c_addr, update, sizeof(update) );
i2c_give(i2c_interf);
}

if (!tx_len) return MMC_TIMEOUT_ERR;
return MMC_OK;
}

void adn4604_reset( void )
mmc_err adn4604_reset( void )
{
uint8_t i2c_addr, i2c_interf;
uint8_t update[2] = { ADN_RESET_REG, 0x01 };
uint8_t tx_len = 0;

if (i2c_take_by_chipid(CHIP_ID_ADN, &i2c_addr, &i2c_interf, (TickType_t)10) ) {
xI2CMasterWrite( i2c_interf, i2c_addr, update, sizeof(update) );
tx_len = xI2CMasterWrite( i2c_interf, i2c_addr, update, sizeof(update) );
i2c_give(i2c_interf);
}
if (!tx_len) return MMC_TIMEOUT_ERR;
return MMC_OK;
}

void adn4604_xpt_config( uint8_t map, adn_connect_map_t xpt_con )
mmc_err adn4604_xpt_config( uint8_t map, adn_connect_map_t xpt_con )
{
uint8_t i2c_addr, i2c_interf;
uint8_t tx_len = 0;

adn_connect_cfg_t cfg = { map, xpt_con };

if (i2c_take_by_chipid(CHIP_ID_ADN, &i2c_addr, &i2c_interf, (TickType_t)10) ) {
xI2CMasterWrite( i2c_interf, i2c_addr, (uint8_t *)&cfg, sizeof(cfg) );
tx_len = xI2CMasterWrite( i2c_interf, i2c_addr, (uint8_t *)&cfg, sizeof(cfg) );
i2c_give(i2c_interf);
}
if (!tx_len) return MMC_TIMEOUT_ERR;
return MMC_OK;
}

void adn4604_active_map( uint8_t map )
mmc_err adn4604_active_map( uint8_t map )
{
uint8_t i2c_addr, i2c_interf;
uint8_t tx_len = 0;

/* Select the active map */
uint8_t map_sel[2] = { ADN_XPT_MAP_TABLE_SEL_REG, map };

if ( i2c_take_by_chipid( CHIP_ID_ADN, &i2c_addr, &i2c_interf, (TickType_t)10 ) ) {
xI2CMasterWrite( i2c_interf, i2c_addr, map_sel, sizeof(map_sel) );
tx_len = xI2CMasterWrite( i2c_interf, i2c_addr, map_sel, sizeof(map_sel) );
i2c_give( i2c_interf );
}
if (!tx_len) return MMC_TIMEOUT_ERR;
return MMC_OK;
}

adn_connect_map_t adn4604_out_status( void )
Expand All @@ -139,13 +156,17 @@ adn_connect_map_t adn4604_out_status( void )
return stat_map;
}

void adn4604_termination_ctl( uint8_t cfg )
mmc_err adn4604_termination_ctl( uint8_t cfg )
{
uint8_t i2c_addr, i2c_interf;
uint8_t msg[2] = { ADN_TERMINATION_CTL_REG, (cfg & 0xF0) };
uint8_t tx_len = 0;

if ( i2c_take_by_chipid( CHIP_ID_ADN, &i2c_addr, &i2c_interf, (TickType_t)10 ) ) {
xI2CMasterWrite( i2c_interf, i2c_addr, msg, sizeof(msg) );
tx_len = xI2CMasterWrite( i2c_interf, i2c_addr, msg, sizeof(msg) );
i2c_give( i2c_interf );
}
if (!tx_len) return MMC_TIMEOUT_ERR;
return MMC_OK;

}
14 changes: 8 additions & 6 deletions modules/adn4604.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#ifndef ADN4604_H_
#define ADN4604_H_

#include "mmc_error.h"

typedef struct __attribute__((__packed__)) {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t out1:4,
Expand Down Expand Up @@ -118,35 +120,35 @@ enum adn4604_tx_ctl {
* @param output Output number (0 to 15)
* @param tx_mode Selected mode: (TX_DISABLED, TX_STANDBY, TX_SQUELCHED or TX_ENABLED)
*/
void adn4604_tx_control( uint8_t output, uint8_t tx_mode );
mmc_err adn4604_tx_control( uint8_t output, uint8_t tx_mode );

/**
* @brief Activates the current stored configuration
*
* @note The Update pin has precedence over the software register, so if the Update pin is asserted, but the low-to-high step doesn't occur, you won't be able to update the IC configuration
*
*/
void adn4604_update( void );
mmc_err adn4604_update( void );

/**
* @brief ADN4604 Software Reset
*/
void adn4604_reset( void );
mmc_err adn4604_reset( void );

/**
* @brief Configures the cross-connection map
*
* @param map Selected map to configure (0 or 1)
* @param xpt_con Outputs assignment
*/
void adn4604_xpt_config( uint8_t map, adn_connect_map_t xpt_con );
mmc_err adn4604_xpt_config( uint8_t map, adn_connect_map_t xpt_con );

/**
* @brief Sets the active map on the IC
*
* @param map Selected map (0 or 1)
*/
void adn4604_active_map( uint8_t map );
mmc_err adn4604_active_map( uint8_t map );

/**
* @brief Reads the outputs current connections
Expand All @@ -160,6 +162,6 @@ adn_connect_map_t adn4604_out_status( void );
*
* @param cfg Selected in/outputs (separated in quadrants defined in #adn4604_term_ctl)
*/
void adn4604_termination_ctl( uint8_t cfg );
mmc_err adn4604_termination_ctl( uint8_t cfg );

#endif
28 changes: 19 additions & 9 deletions port/board/afc-v3/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ void vTaskPayload( void *pvParameters )
*/

if (state == PAYLOAD_QUIESCED) {
QUIESCED_req = 0;
} else {
QUIESCED_req = 0;
} else {
QUIESCED_req = 1;
}
}
xEventGroupClearBits( amc_payload_evt, PAYLOAD_MESSAGE_QUIESCE );
}

Expand Down Expand Up @@ -313,9 +313,12 @@ void vTaskPayload( void *pvParameters )
case PAYLOAD_STATE_FPGA_SETUP:
#ifdef MODULE_ADN4604
/* Configure clock switch */
clock_configuration();
#endif
if (clock_configuration() == MMC_OK) {
new_state = PAYLOAD_FPGA_ON;
}
#else
new_state = PAYLOAD_FPGA_ON;
#endif
break;

case PAYLOAD_FPGA_ON:
Expand Down Expand Up @@ -477,9 +480,10 @@ uint8_t payload_hpm_activate_firmware( void )
return IPMI_CC_OK;
}

void clock_configuration()
mmc_err clock_configuration( void )
{
adn_connect_map_t con;
mmc_err error;

/* Read the clock configuration from the eeprom */
eeprom_24xx02_read(CHIP_ID_RTC_EEPROM, 0x0, clock_config, 16, 10);
Expand Down Expand Up @@ -530,7 +534,10 @@ void clock_configuration()
con.out14 = clock_config[14] & 0x0F;
con.out15 = clock_config[15] & 0x0F;

adn4604_xpt_config( ADN_XPT_MAP0_CON_REG, con );
error = adn4604_xpt_config( ADN_XPT_MAP0_CON_REG, con );
if (error != MMC_OK) {
return error;
}

/* Enable desired outputs */
for ( uint8_t i = 0; i < 16; i++ ) {
Expand All @@ -541,8 +548,11 @@ void clock_configuration()
}
}

adn4604_active_map( ADN_XPT_MAP0 );
error = adn4604_active_map( ADN_XPT_MAP0 );
if (error != MMC_OK) {
return error;
}

adn4604_update();
return adn4604_update();
}
#endif
3 changes: 2 additions & 1 deletion port/board/afc-v3/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define PAYLOAD_H_

#include "event_groups.h"
#include "mmc_error.h"

/**
* @brief Payload state machine state numbers
Expand Down Expand Up @@ -114,7 +115,7 @@ uint8_t payload_hpm_activate_firmware( void );
* @brief Configure the clock switch interconects according to the configuration
* saved in EEPROM
*/
void clock_configuration();
mmc_err clock_configuration( void );


#endif /* IPMI_PAYLOAD_H_ */
Expand Down

0 comments on commit 077d6bb

Please sign in to comment.