Skip to content

Commit

Permalink
[RTM] Move 12V turn on/off to AFC specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavosr8 authored and augustofg committed Feb 22, 2024
1 parent 028b253 commit dd130a3
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 109 deletions.
1 change: 0 additions & 1 deletion modules/pca9554.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
* @}
*/


/* Pins Read/Write */
/**
* @brief Read all pins status
Expand Down
2 changes: 1 addition & 1 deletion modules/rtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void RTM_Manage( void * Parameters )
current_evt = xEventGroupGetBits( rtm_payload_evt );

if ( current_evt & PAYLOAD_MESSAGE_QUIESCE ) {
if ( rtm_quiesce() ) {
if ( rtm_disable_payload_power() ) {
/* Quiesced event */
printf("[RTM] Quiesced RTM successfuly!\n");
hotswap_set_mask_bit( HOTSWAP_RTM, HOTSWAP_QUIESCED_MASK );
Expand Down
16 changes: 16 additions & 0 deletions modules/rtm.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,21 @@ void rtm_manage_init( void );
*/
void rtm_check_presence(uint8_t *status);

/**
* @brief Enable payload power
*
* This function turn on the 12V payload power rail and initialise the RTM powered by it.
*
*/
mmc_err rtm_enable_payload_power( void );

/**
* @brief Disable payload power
*
* This function turn off the 12V payload power rail and de-initialise the RTM powered by it.
*
*/
mmc_err rtm_disable_payload_power( void );


#endif
13 changes: 13 additions & 0 deletions port/board/afc-v3/rtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ void rtm_check_presence( uint8_t *status )
*status = HOTSWAP_STATE_URTM_PRSENT;
}
}

mmc_err rtm_enable_payload_power( void )
{
gpio_set_pin_state( PIN_PORT(GPIO_EN_RTM_PWR), PIN_NUMBER(GPIO_EN_RTM_PWR), 1 );
return rtm_enable_payload_power_post();
}

mmc_err rtm_disable_payload_power( void )
{
mmc_err error = rtm_disable_payload_power_pre();
gpio_set_pin_state( PIN_PORT(GPIO_EN_RTM_PWR), PIN_NUMBER(GPIO_EN_RTM_PWR), 0 );
return error;
}
1 change: 1 addition & 0 deletions port/board/afc-v4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ set(BOARD_PATH ${CMAKE_CURRENT_SOURCE_DIR})
##Sensors SDR list
set( PROJ_SRCS ${PROJ_SRCS} ${BOARD_PATH}/sdr_list.c )
set( PROJ_SRCS ${PROJ_SRCS} ${BOARD_PATH}/i2c_mapping.c )
set( PROJ_SRCS ${PROJ_SRCS} ${BOARD_PATH}/pin_mapping.c )

if (";${TARGET_MODULES};" MATCHES ";PAYLOAD;")
set(PROJ_SRCS ${PROJ_SRCS} ${BOARD_PATH}/payload.c)
Expand Down
22 changes: 2 additions & 20 deletions port/board/afc-v4/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "clock_config.h"
#include "eeprom_24xx02.h"
#include "i2c_mapping.h"
#include "pin_mapping.h"

/* payload states
* 0 - No power
Expand All @@ -67,26 +68,6 @@
* Wait until payload power goes down to restart the cycle
*/

const external_gpio_t ext_gpios[16] = {
[EXT_GPIO_P1V5_VTT_EN] = { 1, 7 },
[EXT_GPIO_EN_P1V8] = { 1, 6 },
[EXT_GPIO_EN_P1V2] = { 1, 5 },
[EXT_GPIO_EN_FMC1_P12V] = { 1, 4 },
[EXT_GPIO_EN_FMC2_P12V] = { 1, 3 },
[EXT_GPIO_EN_FMC1_PVADJ] = { 1, 2 },
[EXT_GPIO_EN_FMC2_PVADJ] = { 1, 1 },
[EXT_GPIO_EN_FMC1_P3V3] = { 1, 0 },
[EXT_GPIO_EN_FMC2_P3V3] = { 0, 7 },
[EXT_GPIO_EN_P1V0] = { 0, 6 },
[EXT_GPIO_EN_P3V3] = { 0, 5 },
[EXT_GPIO_EN_RTM_PWR] = { 0, 4 },
[EXT_GPIO_EN_RTM_MP] = { 0, 3 },
[EXT_GPIO_FPGA_I2C_RESET] = { 0, 2 },
[EXT_GPIO_DAC_VADJ_RSTn] = { 0, 1 },
[EXT_GPIO_PROGRAM_B] = { 0, 0 }
};


/**
* @brief Set AFC's DCDC Converters state
*
Expand Down Expand Up @@ -242,6 +223,7 @@ void payload_init( void )
amc_payload_evt = xEventGroupCreate();
#ifdef MODULE_RTM
rtm_payload_evt = xEventGroupCreate();
mcp23016_write_pin(ext_gpios[EXT_GPIO_EN_RTM_MP].port_num, ext_gpios[EXT_GPIO_EN_RTM_MP].pin_num, true);
#endif

#ifdef MODULE_ADC
Expand Down
23 changes: 0 additions & 23 deletions port/board/afc-v4/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,6 @@ extern enum {
/**
* @}
*/
typedef struct external_gpio {
uint8_t port_num;
uint8_t pin_num;
} external_gpio_t;

enum {
EXT_GPIO_EN_P1V0,
EXT_GPIO_EN_P1V8,
EXT_GPIO_EN_P3V3,
EXT_GPIO_EN_FMC1_PVADJ,
EXT_GPIO_EN_FMC2_PVADJ,
EXT_GPIO_P1V5_VTT_EN,
EXT_GPIO_EN_P1V2,
EXT_GPIO_EN_FMC1_P12V,
EXT_GPIO_EN_FMC1_P3V3,
EXT_GPIO_EN_FMC2_P12V,
EXT_GPIO_EN_FMC2_P3V3,
EXT_GPIO_EN_RTM_PWR,
EXT_GPIO_EN_RTM_MP,
EXT_GPIO_FPGA_I2C_RESET,
EXT_GPIO_DAC_VADJ_RSTn,
EXT_GPIO_PROGRAM_B,
};

/**
* @brief Payload task unblock delay
Expand Down
28 changes: 28 additions & 0 deletions port/board/afc-v4/pin_mapping.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "pin_mapping.h"

/**
* @defgroup AFC_V4_0_PIN_MAPPING AFCv4.0 Pin Mapping
* @ingroup AFC_V4_0
* @{
*/
const external_gpio_t ext_gpios[16] = {
[EXT_GPIO_P1V5_VTT_EN] = { 1, 7 },
[EXT_GPIO_EN_P1V8] = { 1, 6 },
[EXT_GPIO_EN_P1V2] = { 1, 5 },
[EXT_GPIO_EN_FMC1_P12V] = { 1, 4 },
[EXT_GPIO_EN_FMC2_P12V] = { 1, 3 },
[EXT_GPIO_EN_FMC1_PVADJ] = { 1, 2 },
[EXT_GPIO_EN_FMC2_PVADJ] = { 1, 1 },
[EXT_GPIO_EN_FMC1_P3V3] = { 1, 0 },
[EXT_GPIO_EN_FMC2_P3V3] = { 0, 7 },
[EXT_GPIO_EN_P1V0] = { 0, 6 },
[EXT_GPIO_EN_P3V3] = { 0, 5 },
[EXT_GPIO_EN_RTM_PWR] = { 0, 4 },
[EXT_GPIO_EN_RTM_MP] = { 0, 3 },
[EXT_GPIO_FPGA_I2C_RESET] = { 0, 2 },
[EXT_GPIO_DAC_VADJ_RSTn] = { 0, 1 },
[EXT_GPIO_PROGRAM_B] = { 0, 0 }
};
/**
* @}
*/
30 changes: 29 additions & 1 deletion port/board/afc-v4/pin_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,36 @@
GPIO_FMC1_PRSNT_M2C, \
GPIO_FMC2_PRSNT_M2C, \
GPIO_RTM_PS
#endif

/**
* @}
*/
#include <stdint.h>

typedef struct external_gpio {
uint8_t port_num;
uint8_t pin_num;
} external_gpio_t;

extern const external_gpio_t ext_gpios[16];

enum {
EXT_GPIO_EN_P1V0,
EXT_GPIO_EN_P1V8,
EXT_GPIO_EN_P3V3,
EXT_GPIO_EN_FMC1_PVADJ,
EXT_GPIO_EN_FMC2_PVADJ,
EXT_GPIO_P1V5_VTT_EN,
EXT_GPIO_EN_P1V2,
EXT_GPIO_EN_FMC1_P12V,
EXT_GPIO_EN_FMC1_P3V3,
EXT_GPIO_EN_FMC2_P12V,
EXT_GPIO_EN_FMC2_P3V3,
EXT_GPIO_EN_RTM_PWR,
EXT_GPIO_EN_RTM_MP,
EXT_GPIO_FPGA_I2C_RESET,
EXT_GPIO_DAC_VADJ_RSTn,
EXT_GPIO_PROGRAM_B,
};

#endif
15 changes: 15 additions & 0 deletions port/board/afc-v4/rtm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "i2c_mapping.h"
#include "port.h"
#include "hotswap.h"
#include "pin_mapping.h"
#include "mcp23016.h"

void rtm_check_presence( uint8_t *status )
{
Expand All @@ -10,3 +12,16 @@ void rtm_check_presence( uint8_t *status )
*status = HOTSWAP_STATE_URTM_PRSENT;
}
}

mmc_err rtm_enable_payload_power( void )
{
mmc_err err = mcp23016_write_pin(ext_gpios[EXT_GPIO_EN_RTM_PWR].port_num, ext_gpios[EXT_GPIO_EN_RTM_PWR].pin_num, true);
rtm_enable_payload_power_post();
return err;
}

mmc_err rtm_disable_payload_power( void )
{
rtm_disable_payload_power_pre();
return mcp23016_write_pin(ext_gpios[EXT_GPIO_EN_RTM_PWR].port_num, ext_gpios[EXT_GPIO_EN_RTM_PWR].pin_num, false);
}
39 changes: 11 additions & 28 deletions port/board/rtm-8sfp/rtm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,29 @@
#include "led.h"
#include "board_led.h"
#include "uart_debug.h"
/* RTM Management functions */

void rtm_enable_payload_power( void )

/* RTM Management functions */
/*
* This functions are not necessary for RTM-8SFP because it doesn't need any power up/down specific
* procedure other than controlling the 12V payload power rail.
*
*/
mmc_err rtm_enable_payload_power_post( void )
{
gpio_set_pin_state( PIN_PORT(GPIO_EN_RTM_PWR), PIN_NUMBER(GPIO_EN_RTM_PWR), 1 );
return MMC_OK;
}

void rtm_disable_payload_power( void )
mmc_err rtm_disable_payload_power_pre( void )
{
gpio_set_pin_state( PIN_PORT(GPIO_EN_RTM_PWR), PIN_NUMBER(GPIO_EN_RTM_PWR), 0 );
return MMC_OK;
}

uint8_t rtm_get_hotswap_handle_status( uint8_t *state )
{
static uint8_t falling, rising;
uint8_t pin_read;

rtm_enable_i2c();

if (pca9554_read_pin( CHIP_ID_RTM_PCA9554, RTM_GPIO_HOTSWAP_HANDLE, &pin_read ) == 0 ) {
return false;
}
Expand All @@ -67,24 +71,9 @@ uint8_t rtm_get_hotswap_handle_status( uint8_t *state )

void rtm_hardware_init( void )
{
rtm_enable_i2c();
pca9554_set_port_dir( CHIP_ID_RTM_PCA9554, 0x1F );
}

void rtm_enable_i2c( void )
{
/* Enable I2C communication with RTM */
gpio_set_pin_dir( PIN_PORT(GPIO_RTM_PS), PIN_NUMBER(GPIO_RTM_PS), GPIO_DIR_OUTPUT );
gpio_set_pin_dir( PIN_PORT(GPIO_EN_RTM_I2C), PIN_NUMBER(GPIO_EN_RTM_I2C), GPIO_DIR_OUTPUT );
gpio_set_pin_state( PIN_PORT(GPIO_EN_RTM_I2C), PIN_NUMBER(GPIO_EN_RTM_I2C), GPIO_LEVEL_HIGH );
}

void rtm_disable_i2c( void )
{
gpio_set_pin_dir( PIN_PORT(GPIO_RTM_PS), PIN_NUMBER(GPIO_RTM_PS), GPIO_DIR_INPUT );
gpio_set_pin_dir( PIN_PORT(GPIO_EN_RTM_I2C), PIN_NUMBER(GPIO_EN_RTM_I2C), GPIO_DIR_INPUT );
}

bool rtm_compatibility_check( void )
{
uint8_t i;
Expand Down Expand Up @@ -132,12 +121,6 @@ bool rtm_compatibility_check( void )
return false;
}

bool rtm_quiesce( void )
{
/* In this board, no action is needed to quiesce */
return true;
}

void rtm_ctrl_led( uint8_t id, uint8_t state )
{
uint8_t pca_pin;
Expand Down
7 changes: 4 additions & 3 deletions port/board/rtm-8sfp/rtm_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
#define RTM_GPIO_LED_GREEN 6
#define RTM_GPIO_LED_BLUE 7

#include "mmc_error.h"

/* Mandatory RTM module functions */
void rtm_enable_payload_power( void );
void rtm_disable_payload_power( void );
mmc_err rtm_enable_payload_power_post( void );
mmc_err rtm_disable_payload_power_pre( void );
uint8_t rtm_get_hotswap_handle_status( uint8_t *state );
void rtm_hardware_init( void );
void rtm_ctrl_led( uint8_t id, uint8_t state );
uint8_t rtm_read_led( uint8_t id );
bool rtm_quiesce( void );
bool rtm_compatibility_check( void );

/* User defined functions */
Expand Down
Loading

0 comments on commit dd130a3

Please sign in to comment.