diff --git a/firmware/ec/inc/subsystem/rffe/rffe_ctrl.h b/firmware/ec/inc/subsystem/rffe/rffe_ctrl.h index ad90642b32..10da6130af 100644 --- a/firmware/ec/inc/subsystem/rffe/rffe_ctrl.h +++ b/firmware/ec/inc/subsystem/rffe/rffe_ctrl.h @@ -68,6 +68,10 @@ typedef struct Fe_Ch_Pwr_Cfg { rffeChannel channel; Fe_Cfg *fe_Rffecfg; } Fe_Ch_Pwr_Cfg; + +typedef enum FE_ParamCfg { + FE_CFG_BAND = 0, +} FE_ParamCfg; /***************************************************************************** * FUNCTION DECLARATIONS *****************************************************************************/ diff --git a/firmware/ec/src/devices/ocmp_wrappers/ocmp_fe.c b/firmware/ec/src/devices/ocmp_wrappers/ocmp_fe.c index 71edebfb61..3f96814808 100644 --- a/firmware/ec/src/devices/ocmp_wrappers/ocmp_fe.c +++ b/firmware/ec/src/devices/ocmp_wrappers/ocmp_fe.c @@ -11,10 +11,6 @@ #include "inc/subsystem/rffe/rffe_ctrl.h" static FE_Band_Cfg FE_BandCfg[RFFE_MAX_CHANNEL]; -typedef enum FE_ParamCfg { - FE_CFG_BAND = 0, -} FE_ParamCfg; - /***************************************************************************** ** FUNCTION NAME : rffe_ctrl_set_band ** diff --git a/firmware/ec/src/devices/ocmp_wrappers/ocmp_rfwatchdog.c b/firmware/ec/src/devices/ocmp_wrappers/ocmp_rfwatchdog.c index 81eba4b7dd..35177f7254 100644 --- a/firmware/ec/src/devices/ocmp_wrappers/ocmp_rfwatchdog.c +++ b/firmware/ec/src/devices/ocmp_wrappers/ocmp_rfwatchdog.c @@ -20,7 +20,8 @@ void _rffe_watchdog_handler(void *context) OCMP_GenerateAlert(context, 1, NULL); } } - +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" static ePostCode _rffe_watchdog_init(void *driver, const void *config, const void *alert_token) { @@ -39,7 +40,7 @@ static ePostCode _rffe_watchdog_init(void *driver, const void *config, ThreadedInt_Init(cfg->pin_interrupt, _rffe_watchdog_handler, cfg); return POST_DEV_CFG_DONE; } - +#pragma GCC diagnostic pop const Driver_fxnTable RFFEWatchdogP_fxnTable = { .cb_init = _rffe_watchdog_init, }; diff --git a/firmware/ec/src/subsystem/rffe/rffe_ctrl.c b/firmware/ec/src/subsystem/rffe/rffe_ctrl.c index e84b576278..3341b3d985 100644 --- a/firmware/ec/src/subsystem/rffe/rffe_ctrl.c +++ b/firmware/ec/src/subsystem/rffe/rffe_ctrl.c @@ -19,11 +19,6 @@ #include #include - -typedef enum FE_ParamCfg { - FE_CFG_BAND = 0, -} FE_ParamCfg; - /***************************************************************************** ** FUNCTION NAME : rffe_ctrl_configure_power_amplifier ** diff --git a/firmware/ec/test/Makefile b/firmware/ec/test/Makefile index 69a7b1f4fa..223522d6f6 100644 --- a/firmware/ec/test/Makefile +++ b/firmware/ec/test/Makefile @@ -184,6 +184,9 @@ $(PATHB)Test_ltc4274$(TARGET_EXTENSION): $(STD_FILES) $(TEST_LTC4274_SRC) $(INC_ TEST_OCMP_DEBUGI2C_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_debugi2c.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_debugI2C.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c $(PATHB)Test_ocmp_debugi2c$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_DEBUGI2C_SRC) +TEST_OCMP_RFWATCHDOG_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_rfwatchdog.c $(OCWARE_ROOT)/src/devices/i2cbus.c $(OCWARE_ROOT)/src/helpers/memory.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_PCA9557.c fake/fake_rfwatchdog.c stub/stub_GateMutex.c $(OCWARE_ROOT)/src/drivers/GpioPCA9557.c $(OCWARE_ROOT)/src/devices/pca9557.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_FE.c +$(PATHB)Test_ocmp_rfwatchdog$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_RFWATCHDOG_SRC) + $(PATHB)%$(TARGET_EXTENSION): $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $^ -o $@ $(COV_CMDS) diff --git a/firmware/ec/test/fake/fake_PCA9557.c b/firmware/ec/test/fake/fake_PCA9557.c index ee6e1f027d..438415a76d 100644 --- a/firmware/ec/test/fake/fake_PCA9557.c +++ b/firmware/ec/test/fake/fake_PCA9557.c @@ -13,4 +13,5 @@ uint8_t PCA9557_regs[] = { [PCA9557_REGS_OUTPUT_VALUE] = 0x00, /* Output values */ [PCA9557_REGS_POLARITY] = 0x00, /* Polarity */ [PCA9557_REGS_DIR_CONFIG] = 0x00, /* Dir Config */ + [PCA9557_REGS_END] = 0x00, }; diff --git a/firmware/ec/test/fake/fake_rfwatchdog.c b/firmware/ec/test/fake/fake_rfwatchdog.c new file mode 100644 index 0000000000..97d4372a52 --- /dev/null +++ b/firmware/ec/test/fake/fake_rfwatchdog.c @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include "include/test_rfwatchdog.h" + +extern Fe_gpioCfg fe_gpiocfg; +extern Fe_Watchdog_Cfg fe_watchdog_cfg; + +const I2C_Dev I2C_DEV = { + .bus = OC_CONNECT1_I2C2, + .slave_addr = RFFE_IO_REVPOWER_ALERT_ADDR, +}; +OcGpio_Port ec_io = { + .fn_table = &FakeGpio_fnTable, + .object_data = &(FakeGpio_Obj){}, +}; +bool OcGpio_GpioPins[] = { + [RFWATCHDOG_PIN_1] = OCGPIO_CFG_INPUT, + [RFWATCHDOG_PIN_2] = OCGPIO_CFG_INPUT, + [OC_EC_FE_TRXFE_CONN_RESET] = OCGPIO_CFG_INPUT, +}; +uint32_t OcGpio_GpioConfig[] = { + [RFWATCHDOG_PIN_1] = OCGPIO_CFG_INPUT, + [RFWATCHDOG_PIN_2] = OCGPIO_CFG_INPUT, + [OC_EC_FE_TRXFE_CONN_RESET] = OCGPIO_CFG_INPUT, +}; + +OcGpio_Port fe_watchdog_io = { + .fn_table = &GpioPCA9557_fnTable, + .cfg = + &(PCA9557_Cfg){ + .i2c_dev = { OC_CONNECT1_I2C2, RFFE_IO_REVPOWER_ALERT_ADDR }, + }, + .object_data = &(PCA9557_Obj){}, +}; + +Fe_gpioCfg fe_gpiocfg_invalid = { + /* EC_TRXFECONN_GPIO3/RF_PGOOD_LDO */ + .pin_rf_pgood_ldo = { &ec_io, OC_EC_FE_PWR_GD }, + .pin_fe_12v_ctrl = { &ec_io, OC_EC_FE_CONTROL }, +}; +// FE watch dog +Fe_Watchdog_Cfg fe_watchdog_invalid = { + /* CO6_WD */ + .pin_co6_wd = { &fe_watchdog_io, -1 }, + /* CO5_WD INVALID */ + .pin_co5_wd = { &fe_watchdog_io, -1 }, + /* CO4_WD */ + .pin_co4_wd = { &fe_watchdog_io, -1 }, + /* CO3_WD INVALID */ + .pin_co3_wd = { &fe_watchdog_io, -1 }, +}; + +/* FE CH watch dog */ +RfWatchdog_Cfg fe_NULL = { + .pin_alert_lb = NULL, + .pin_alert_hb = NULL, + .pin_interrupt = NULL, +}; +RfWatchdog_Cfg fe_ch1_invalid_alert_lb = { + .pin_alert_lb = NULL, + .pin_alert_hb = &fe_watchdog_cfg.pin_co5_wd, + .pin_interrupt = &fe_gpiocfg.pin_trxfe_conn_reset, +}; + +RfWatchdog_Cfg fe_ch1_invalid_alert_hb = { + .pin_alert_lb = &fe_watchdog_cfg.pin_co6_wd, + .pin_alert_hb = NULL, + .pin_interrupt = &fe_gpiocfg.pin_trxfe_conn_reset, +}; + +RfWatchdog_Cfg fe_ch1_invalid_interrupt = { + .pin_alert_lb = &fe_watchdog_cfg.pin_co6_wd, + .pin_alert_hb = &fe_watchdog_cfg.pin_co5_wd, + .pin_interrupt = &fe_gpiocfg_invalid.pin_trxfe_conn_reset, +}; +RfWatchdog_Cfg fe_ch2_invalid_alert_lb = { + .pin_alert_lb = NULL, + .pin_alert_hb = &fe_watchdog_cfg.pin_co4_wd, + .pin_interrupt = &fe_gpiocfg.pin_trxfe_conn_reset, +}; + +RfWatchdog_Cfg fe_ch2_invalid_alert_hb = { + .pin_alert_lb = &fe_watchdog_cfg.pin_co3_wd, + .pin_alert_hb = NULL, + .pin_interrupt = &fe_gpiocfg.pin_trxfe_conn_reset, +}; + +RfWatchdog_Cfg fe_ch2_invalid_interrupt = { + .pin_alert_lb = &fe_watchdog_cfg.pin_co3_wd, + .pin_alert_hb = &fe_watchdog_cfg.pin_co4_wd, + .pin_interrupt = &fe_gpiocfg_invalid.pin_trxfe_conn_reset, +}; diff --git a/firmware/ec/test/include/test_PCA9557.h b/firmware/ec/test/include/test_PCA9557.h index c8dc9c658b..fae030c311 100644 --- a/firmware/ec/test/include/test_PCA9557.h +++ b/firmware/ec/test/include/test_PCA9557.h @@ -16,6 +16,7 @@ typedef enum PCA9557Regs { PCA9557_REGS_INPUT_VALUE = 0x00, PCA9557_REGS_OUTPUT_VALUE, PCA9557_REGS_POLARITY, - PCA9557_REGS_DIR_CONFIG + PCA9557_REGS_DIR_CONFIG, + PCA9557_REGS_END = 0x10, } PCA9557Regs; #endif diff --git a/firmware/ec/test/include/test_rfwatchdog.h b/firmware/ec/test/include/test_rfwatchdog.h new file mode 100644 index 0000000000..bee9263e0a --- /dev/null +++ b/firmware/ec/test/include/test_rfwatchdog.h @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _TEST_RFWATCHDOG_H +#define _TEST_RFWATCHDOG_H + +#include "common/inc/global/Framework.h" +#include "common/inc/global/OC_CONNECT1.h" +#include "common/inc/ocmp_wrappers/ocmp_rfwatchdog.h" +#include "fake/fake_GPIO.h" +#include "fake/fake_I2C.h" +#include "inc/subsystem/rffe/rffe_ctrl.h" +#include "include/test_PCA9557.h" +#include "src/drivers/GpioPCA9557.h" +#include +#include "unity.h" + +#define RFWATCHDOG_CH1_DIR_CONFIG_VALUE 0x0C +#define RFWATCHDOG_CH2_DIR_CONFIG_VALUE 0x3C +#define RFWATCHDOG_DIR_CONFIG_DEFAULT_VALUE 0x00 +#define RFWATCHDOG_PIN_1 0x01 +#define RFWATCHDOG_PIN_2 0x02 + +#endif diff --git a/firmware/ec/test/suites/Doc/TestCaseList.xlsx b/firmware/ec/test/suites/Doc/TestCaseList.xlsx index 4bb300cc48..bafbc4970c 100644 Binary files a/firmware/ec/test/suites/Doc/TestCaseList.xlsx and b/firmware/ec/test/suites/Doc/TestCaseList.xlsx differ diff --git a/firmware/ec/test/suites/Test_ocmp_rfwatchdog.c b/firmware/ec/test/suites/Test_ocmp_rfwatchdog.c new file mode 100644 index 0000000000..b512358d4e --- /dev/null +++ b/firmware/ec/test/suites/Test_ocmp_rfwatchdog.c @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#include "include/test_rfwatchdog.h" + +/* ======================== Constants & variables =========================== */ +extern bool OcGpio_GpioPins[OC_EC_FE_TRXFE_CONN_RESET]; +extern const Component sys_schema[]; +extern const I2C_Dev I2C_DEV; +extern const OcGpio_FnTable GpioPCA9557_fnTable; +extern Fe_Watchdog_Cfg fe_watchdog_cfg; +extern Fe_Watchdog_Cfg fe_watchdog_invalid; +extern OcGpio_Port ec_io; +extern OcGpio_Port fe_watchdog_io; +extern RfWatchdog_Cfg fe_ch1_invalid_alert_hb; +extern RfWatchdog_Cfg fe_ch1_invalid_alert_lb; +extern RfWatchdog_Cfg fe_ch1_invalid_interrupt; +extern RfWatchdog_Cfg fe_ch1_watchdog; +extern RfWatchdog_Cfg fe_ch2_invalid_alert_hb; +extern RfWatchdog_Cfg fe_ch2_invalid_alert_lb; +extern RfWatchdog_Cfg fe_ch2_invalid_interrupt; +extern RfWatchdog_Cfg fe_ch2_watchdog; +extern RfWatchdog_Cfg fe_NULL; +extern uint8_t PCA9557_regs[PCA9557_REGS_END]; +extern uint32_t OcGpio_GpioConfig[OC_EC_FE_TRXFE_CONN_RESET]; + +/* ============================= Fake Functions ============================= */ +#include +unsigned int s_task_sleep_ticks; +xdc_Void ti_sysbios_knl_Task_sleep__E(xdc_UInt32 nticks) +{ + s_task_sleep_ticks += nticks; +} +void test_alert(void) +{ +} +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +void OCMP_GenerateAlert(const AlertData *alert_data, unsigned int alert_id, + const void *data) +{ +} +#pragma GCC diagnostic pop +/* ============================= Boilerplate ================================ */ +void suite_setUp(void) +{ + FakeGpio_registerDevSimple(OcGpio_GpioPins, OcGpio_GpioConfig); + fake_I2C_init(); + fake_I2C_registerDevSimple(I2C_DEV.bus, I2C_DEV.slave_addr, PCA9557_regs, + sizeof(PCA9557_regs), sizeof(PCA9557_regs[0]), + sizeof(uint8_t), FAKE_I2C_DEV_BIG_ENDIAN); +} +void setUp(void) +{ +} +void tearDown(void) +{ +} +void suite_tearDown(void) +{ + fake_I2C_deinit(); /* This will automatically unregister devices */ +} + +/* ================================ Tests =================================== */ +void test_init(void) +{ + PCA9557_regs[PCA9557_REGS_DIR_CONFIG] = + RFWATCHDOG_DIR_CONFIG_DEFAULT_VALUE; /* Dir Config */ + OcGpio_GpioConfig[OC_EC_FE_TRXFE_CONN_RESET] = OCGPIO_CFG_OUTPUT; + TEST_ASSERT_EQUAL(POST_DEV_CFG_DONE, RFFEWatchdogP_fxnTable.cb_init( + &fe_ch1_watchdog, NULL, NULL)); + TEST_ASSERT_EQUAL_HEX8(RFWATCHDOG_CH1_DIR_CONFIG_VALUE, + PCA9557_regs[PCA9557_REGS_DIR_CONFIG]); + TEST_ASSERT_EQUAL_HEX8(OCGPIO_CFG_INPUT | OCGPIO_CFG_INT_FALLING, + OcGpio_GpioConfig[OC_EC_FE_TRXFE_CONN_RESET]); + + OcGpio_GpioConfig[OC_EC_FE_TRXFE_CONN_RESET] = + RFWATCHDOG_DIR_CONFIG_DEFAULT_VALUE; + TEST_ASSERT_EQUAL(POST_DEV_CFG_DONE, RFFEWatchdogP_fxnTable.cb_init( + &fe_ch2_watchdog, NULL, NULL)); + TEST_ASSERT_EQUAL_HEX8(RFWATCHDOG_CH2_DIR_CONFIG_VALUE, + PCA9557_regs[PCA9557_REGS_DIR_CONFIG]); + TEST_ASSERT_EQUAL_HEX8(OCGPIO_CFG_INPUT | OCGPIO_CFG_INT_FALLING, + OcGpio_GpioConfig[OC_EC_FE_TRXFE_CONN_RESET]); + + /* Invalid Null test */ + TEST_ASSERT_EQUAL(POST_DEV_CFG_FAIL, + RFFEWatchdogP_fxnTable.cb_init(&fe_NULL, NULL, NULL)); + + /* Invalid ch1 alert_lb test */ + TEST_ASSERT_EQUAL( + POST_DEV_CFG_FAIL, + RFFEWatchdogP_fxnTable.cb_init(&fe_ch1_invalid_alert_lb, NULL, NULL)); + + /* Invalid ch1 alert_hb test */ + TEST_ASSERT_EQUAL( + POST_DEV_CFG_FAIL, + RFFEWatchdogP_fxnTable.cb_init(&fe_ch1_invalid_alert_hb, NULL, NULL)); + + /* Invalid ch1 interrupt test */ + TEST_ASSERT_EQUAL( + POST_DEV_CFG_FAIL, + RFFEWatchdogP_fxnTable.cb_init(&fe_ch1_invalid_interrupt, NULL, NULL)); + + /* Invalid ch2 alert_lb test */ + TEST_ASSERT_EQUAL( + POST_DEV_CFG_FAIL, + RFFEWatchdogP_fxnTable.cb_init(&fe_ch2_invalid_alert_lb, NULL, NULL)); + + /* Invalid ch2 alert_hb test */ + TEST_ASSERT_EQUAL( + POST_DEV_CFG_FAIL, + RFFEWatchdogP_fxnTable.cb_init(&fe_ch2_invalid_alert_hb, NULL, NULL)); + + /* Invalid ch2 interrupt test */ + TEST_ASSERT_EQUAL( + POST_DEV_CFG_FAIL, + RFFEWatchdogP_fxnTable.cb_init(&fe_ch2_invalid_interrupt, NULL, NULL)); +}