Skip to content

Commit

Permalink
Move to rtm_check_presence function to board specific directory
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavosr8 committed Oct 31, 2023
1 parent 8ed196b commit 94a9de9
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
10 changes: 10 additions & 0 deletions modules/rtm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions port/board/afc-v3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
18 changes: 18 additions & 0 deletions port/board/afc-v3/rtm.c
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 12 additions & 0 deletions port/board/afc-v4/rtm.c
Original file line number Diff line number Diff line change
@@ -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;
}
}
21 changes: 0 additions & 21 deletions port/board/rtm-8sfp/rtm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion port/board/rtm-8sfp/rtm_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
21 changes: 0 additions & 21 deletions port/board/rtm-lamp/rtm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion port/board/rtm-lamp/rtm_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 94a9de9

Please sign in to comment.