From 94a9de9f9d6d118f7ac6fa15fbe912c4b6164a46 Mon Sep 17 00:00:00 2001 From: Gustavo de Souza dos Reis Date: Mon, 23 Oct 2023 14:32:03 -0300 Subject: [PATCH] Move to rtm_check_presence function to board specific directory --- modules/rtm.h | 10 ++++++++++ port/board/afc-v3/CMakeLists.txt | 5 +++++ port/board/afc-v3/rtm.c | 18 ++++++++++++++++++ port/board/afc-v4/rtm.c | 12 ++++++++++++ port/board/rtm-8sfp/rtm_user.c | 21 --------------------- port/board/rtm-8sfp/rtm_user.h | 1 - port/board/rtm-lamp/rtm_user.c | 21 --------------------- port/board/rtm-lamp/rtm_user.h | 1 - 8 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 port/board/afc-v3/rtm.c create mode 100644 port/board/afc-v4/rtm.c diff --git a/modules/rtm.h b/modules/rtm.h index fa7c87559..2329be049 100644 --- a/modules/rtm.h +++ b/modules/rtm.h @@ -44,4 +44,14 @@ extern volatile bool rtm_present; */ void rtm_manage_init( void ); +/** + * @brief Check RTM Presence + * + * This task use some GPIO pins to detect the RTM Board presence + * + * @return None + */ +void rtm_check_presence(uint8_t *status); + + #endif diff --git a/port/board/afc-v3/CMakeLists.txt b/port/board/afc-v3/CMakeLists.txt index c22a95f1b..60a0f91b8 100644 --- a/port/board/afc-v3/CMakeLists.txt +++ b/port/board/afc-v3/CMakeLists.txt @@ -46,6 +46,11 @@ if (";${TARGET_MODULES};" MATCHES ";PAYLOAD;") set(MODULES_FLAGS "${MODULES_FLAGS} -DMODULE_PAYLOAD") endif() +if (";${TARGET_MODULES};" MATCHES ";RTM;") + set(PROJ_SRCS ${PROJ_SRCS} ${BOARD_PATH}/rtm.c) + set(MODULES_FLAGS "${MODULES_FLAGS} -DMODULE_RTM") +endif() + #Extra definitions if (FRU_WRITE_EEPROM) message(STATUS "FRU EEPROM will be written if no valid data is found!") diff --git a/port/board/afc-v3/rtm.c b/port/board/afc-v3/rtm.c new file mode 100644 index 000000000..17d71295c --- /dev/null +++ b/port/board/afc-v3/rtm.c @@ -0,0 +1,18 @@ +#include "port.h" +#include "rtm_i2c_mapping.h" +#include "eeprom_24xx64.h" +#include "hotswap.h" + +void rtm_check_presence( uint8_t *status ) + { + /* Due to a hardware limitation in the AFC board, we can't rely on reading the PS signal + since this pin doesn't have a pull-up resistor, it's always read as 0. + A very dirty workaround is to 'ping' the RTM EEPROM, if it responds, then the board is connected */ + + uint8_t dumb; + *status = HOTSWAP_STATE_URTM_ABSENT; + + if(eeprom_24xx64_read(CHIP_ID_RTM_EEPROM, 0, &dumb, 1, 100)) { + *status = HOTSWAP_STATE_URTM_PRSENT; + } + } diff --git a/port/board/afc-v4/rtm.c b/port/board/afc-v4/rtm.c new file mode 100644 index 000000000..85ae468dc --- /dev/null +++ b/port/board/afc-v4/rtm.c @@ -0,0 +1,12 @@ +#include "i2c_mapping.h" +#include "port.h" +#include "hotswap.h" + +void rtm_check_presence( uint8_t *status ) + { + *status = HOTSWAP_STATE_URTM_ABSENT; + + if (!gpio_read_pin(PIN_PORT(GPIO_RTM_PS), PIN_NUMBER(GPIO_RTM_PS))) { + *status = HOTSWAP_STATE_URTM_PRSENT; + } + } diff --git a/port/board/rtm-8sfp/rtm_user.c b/port/board/rtm-8sfp/rtm_user.c index c1849335f..33406a933 100644 --- a/port/board/rtm-8sfp/rtm_user.c +++ b/port/board/rtm-8sfp/rtm_user.c @@ -65,27 +65,6 @@ uint8_t rtm_get_hotswap_handle_status( uint8_t *state ) return false; } -void rtm_check_presence( uint8_t *status ) -{ - /* Due to a hardware limitation in the AFC board, we can't rely on reading the PS signal - since this pin doesn't have a pull-up resistor, it's always read as 0. - A very dirty workaround is to 'ping' the RTM IO Expander(PCA9554), if it responds, then the board is connected */ - rtm_enable_i2c(); - - uint8_t i2c_addr, i2c_interface; - uint8_t dumb; - - /* Defaults to absent - in case of I2C failure */ - *status = HOTSWAP_STATE_URTM_ABSENT; - - if (i2c_take_by_chipid( CHIP_ID_RTM_PCA9554, &i2c_addr, &i2c_interface, 100)) { - if (xI2CMasterRead( i2c_interface, i2c_addr, &dumb, 1)) { - *status = HOTSWAP_STATE_URTM_PRSENT; - } - i2c_give(i2c_interface); - } -} - void rtm_hardware_init( void ) { rtm_enable_i2c(); diff --git a/port/board/rtm-8sfp/rtm_user.h b/port/board/rtm-8sfp/rtm_user.h index 9ceb47e3e..7cc352acd 100644 --- a/port/board/rtm-8sfp/rtm_user.h +++ b/port/board/rtm-8sfp/rtm_user.h @@ -33,7 +33,6 @@ void rtm_enable_payload_power( void ); void rtm_disable_payload_power( void ); uint8_t rtm_get_hotswap_handle_status( uint8_t *state ); -void rtm_check_presence( uint8_t *status ); void rtm_hardware_init( void ); void rtm_ctrl_led( uint8_t id, uint8_t state ); uint8_t rtm_read_led( uint8_t id ); diff --git a/port/board/rtm-lamp/rtm_user.c b/port/board/rtm-lamp/rtm_user.c index 6d2d8ab08..536eb1952 100644 --- a/port/board/rtm-lamp/rtm_user.c +++ b/port/board/rtm-lamp/rtm_user.c @@ -88,27 +88,6 @@ uint8_t rtm_get_hotswap_handle_status( uint8_t *state ) return false; } -void rtm_check_presence( uint8_t *status ) -{ - /* Due to a hardware limitation in the AFC board, we can't rely on reading the PS signal - since this pin doesn't have a pull-up resistor, it's always read as 0. - A very dirty workaround is to 'ping' the RTM IO Expander(PCA9554), if it responds, then the board is connected */ - rtm_enable_i2c(); - - uint8_t i2c_addr, i2c_interface; - uint8_t dumb; - - /* Defaults to absent - in case of I2C failure */ - *status = HOTSWAP_STATE_URTM_ABSENT; - - if (i2c_take_by_chipid( CHIP_ID_RTM_PCA9554_LEDS, &i2c_addr, &i2c_interface, 100)) { - if (xI2CMasterRead( i2c_interface, i2c_addr, &dumb, 1)) { - *status = HOTSWAP_STATE_URTM_PRSENT; - } - i2c_give(i2c_interface); - } -} - void rtm_hardware_init( void ) { rtm_enable_i2c(); diff --git a/port/board/rtm-lamp/rtm_user.h b/port/board/rtm-lamp/rtm_user.h index 269d2ca85..4717f39ae 100644 --- a/port/board/rtm-lamp/rtm_user.h +++ b/port/board/rtm-lamp/rtm_user.h @@ -39,7 +39,6 @@ void rtm_enable_payload_power( void ); void rtm_disable_payload_power( void ); uint8_t rtm_get_hotswap_handle_status( uint8_t *state ); -void rtm_check_presence( uint8_t *status ); void rtm_hardware_init( void ); void rtm_ctrl_led( uint8_t id, uint8_t state ); uint8_t rtm_read_led( uint8_t id );