diff --git a/firmware/ec/inc/devices/eth_sw.h b/firmware/ec/inc/devices/eth_sw.h index 49e341ffae..dd73f8a0b7 100644 --- a/firmware/ec/inc/devices/eth_sw.h +++ b/firmware/ec/inc/devices/eth_sw.h @@ -147,9 +147,9 @@ typedef struct Eth_TcpClient_Params { uint8_t repeat; } Eth_TcpClient_Params; -ePostCode eth_sw_probe(); -ePostCode eth_sw_init(); -void eth_enable_interrupt(); +ePostCode eth_sw_probe(POSTData *postData); +ePostCode eth_sw_init(Eth_cfg *ethCfg); +void eth_enable_interrupt(void); ReturnStatus get_interrupt(uint8_t port); ReturnStatus eth_sw_get_status_speed(uint8_t port, port_speed *speed); ReturnStatus eth_sw_get_status_duplex(uint8_t port, port_duplex *duplex); diff --git a/firmware/ec/inc/devices/powerSource.h b/firmware/ec/inc/devices/powerSource.h index c7a59f50b8..22d0de5622 100644 --- a/firmware/ec/inc/devices/powerSource.h +++ b/firmware/ec/inc/devices/powerSource.h @@ -92,5 +92,5 @@ void pwr_get_source_info(PWRSRC_Dev *pwrSrcDev); ReturnStatus pwr_process_get_status_parameters_data(ePower_StatusParamId paramIndex, uint8_t *pPowerStatusData); - +void pwr_source_config(PWRSRC_Dev *driver); #endif /* POWERSOURCE_H_ */ diff --git a/firmware/ec/src/devices/ocmp_wrappers/ocmp_powerSource.c b/firmware/ec/src/devices/ocmp_wrappers/ocmp_powerSource.c index 6cc01c2f67..5e582edf56 100644 --- a/firmware/ec/src/devices/ocmp_wrappers/ocmp_powerSource.c +++ b/firmware/ec/src/devices/ocmp_wrappers/ocmp_powerSource.c @@ -26,7 +26,11 @@ static bool _get_status(void *driver, unsigned int param_id, void *return_buf) return ret; } -static ePostCode _probe(void *driver) +/* Parameters are not used as this is just used to test assigning the + alert_handler right now.*/ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +static ePostCode _probe(void *driver, POSTData *postData) { pwr_source_config(driver); return POST_DEV_NOSTATUS; @@ -38,6 +42,7 @@ static ePostCode _init(void *driver, const void *config, pwr_source_init(); return POST_DEV_NO_CFG_REQ; } +#pragma GCC diagnostic pop const Driver_fxnTable PWRSRC_fxnTable = { /* Message handlers */ diff --git a/firmware/ec/test/Makefile b/firmware/ec/test/Makefile index d7a36beac9..cef4ab8dc1 100644 --- a/firmware/ec/test/Makefile +++ b/firmware/ec/test/Makefile @@ -156,6 +156,9 @@ $(PATHB)Test_PinGroup_driver$(TARGET_EXTENSION): $(STD_FILES) $(TEST_PINGROUP_SR TEST_OCGPIO_SRC=$(OCWARE_ROOT)/src/drivers/OcGpio.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_I2C.c fake/fake_GPIO.c fake/fake_ThreadedISR.c $(OCWARE_ROOT)/src/helpers/memory.c stub/stub_GateMutex.c $(PATHB)Test_OcGpio$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCGPIO_SRC) +TEST_OCMP_powerSource_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_powerSource.c $(OCWARE_ROOT)/src/devices/powerSource.c $(OCWARE_ROOT)/src/drivers/GpioSX1509.c $(OCWARE_ROOT)/src/devices/sx1509.c $(OCWARE_ROOT)/src/helpers/memory.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c stub/stub_GateMutex.c stub/stub_GateMutex.c $(OCWARE_ROOT)/src/post/post_util.c fake/fake_SX1509_register.c fake/fake_powerSource.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c +$(PATHB)Test_ocmp_powerSource$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_powerSource_SRC) $(INC_M) + $(PATHB)%$(TARGET_EXTENSION): $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $^ -o $@ $(COV_CMDS) diff --git a/firmware/ec/test/fake/fake_GPIO.c b/firmware/ec/test/fake/fake_GPIO.c index 0fd4b3ecc3..c8bf1cec7e 100644 --- a/firmware/ec/test/fake/fake_GPIO.c +++ b/firmware/ec/test/fake/fake_GPIO.c @@ -72,7 +72,7 @@ static int FakeGpio_setCallback(const OcGpio_Pin *pin, if (pin->idx >= FAKE_GPIO_PIN_COUNT) { return OCGPIO_FAILURE; - } + } obj->callback[pin->idx].fn = callback; obj->callback[pin->idx].context = context; diff --git a/firmware/ec/test/fake/fake_I2C.c b/firmware/ec/test/fake/fake_I2C.c index a9c0d5e511..2a4aed0972 100644 --- a/firmware/ec/test/fake/fake_I2C.c +++ b/firmware/ec/test/fake/fake_I2C.c @@ -208,6 +208,8 @@ bool I2C_transfer(I2C_Handle handle, I2C_Transaction *transaction) * in chunks in the event that we have 16-bit (or larger) registers with * a different endianness than the host */ if (write_count > 0) { + write_count = + ((dev->addr_size) * (transaction->writeCount)) - dev->addr_size; size_t write_size = MIN(write_count, dev->tbl_size - reg_addr); for (size_t i = 0; i < write_size / dev->reg_size; i += dev->reg_size) { endian_conversion(write_buf + i, dev->reg_size, dev->endianness, diff --git a/firmware/ec/test/fake/fake_SX1509_register.c b/firmware/ec/test/fake/fake_SX1509_register.c new file mode 100644 index 0000000000..558a625e75 --- /dev/null +++ b/firmware/ec/test/fake/fake_SX1509_register.c @@ -0,0 +1,137 @@ +/** + * 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_sx1509.h" + +uint8_t SX1509_regs[] = { + [SX1509_REG_INPUT_DISABLE_B] = + 0x00, /* Input buffer disableSX1509_REGister B */ + [SX1509_REG_INPUT_DISABLE_A] = + 0x00, /* Input buffer disableSX1509_REGister A */ + [SX1509_REG_LONG_SLEW_B] = + 0x00, /* Output buffer long slewSX1509_REGister B */ + [SX1509_REG_LONG_SLEW_A] = + 0x00, /* Output buffer long slewSX1509_REGister A */ + [SX1509_REG_LOW_DRIVE_B] = + 0x00, /* Output buffer low driveSX1509_REGister B */ + [SX1509_REG_LOW_DRIVE_A] = + 0x00, /* Output buffer low driveSX1509_REGister A */ + [SX1509_REG_PULL_UP_B] = 0x00, /* Pull UpSX1509_REGister B */ + [SX1509_REG_PULL_UP_A] = 0x00, /* Pull UpSX1509_REGister A */ + [SX1509_REG_PULL_DOWN_B] = 0x00, /* Pull DownSX1509_REGister B */ + [SX1509_REG_PULL_DOWN_A] = 0x00, /* Pull DownSX1509_REGister A */ + [SX1509_REG_OPEN_DRAIN_B] = 0x00, /* Open drainSX1509_REGister B */ + [SX1509_REG_OPEN_DRAIN_A] = 0x00, /* Open drainSX1509_REGister A */ + [SX1509_REG_POLARITY_B] = 0x00, /* PolaritySX1509_REGister B */ + [SX1509_REG_POLARITY_A] = 0x00, /* PolaritySX1509_REGister A */ + [SX1509_REG_DIR_B] = 0x00, /* DirectionSX1509_REGister B */ + [SX1509_REG_DIR_A] = 0x00, /* DirectionSX1509_REGister A */ + [SX1509_REG_DATA_B] = 0x00, /* DataSX1509_REGister B */ + [SX1509_REG_DATA_A] = 0x00, /* DataSX1509_REGister A */ + [SX1509_REG_INTERRUPT_MASK_B] = 0x00, /* Interrupt maskSX1509_REGister B */ + [SX1509_REG_INTERRUPT_MASK_A] = 0x00, /* Interrupt maskSX1509_REGister A */ + [SX1509_REG_SENSE_HIGH_B] = 0x00, /* Sense HighSX1509_REGister B */ + [SX1509_REG_SENSE_LOW_B] = 0x00, /* Sense LowSX1509_REGister B */ + [SX1509_REG_SENSE_HIGH_A] = 0x00, /* Sense HighSX1509_REGister A */ + [SX1509_REG_SENSE_LOW_A] = 0x00, /* Sense LowSX1509_REGister A */ + [SX1509_REG_INTERRUPT_SOURCE_B] = + 0x00, /* Interrupt sourceSX1509_REGister B */ + [SX1509_REG_INTERRUPT_SOURCE_A] = + 0x00, /* Interrupt sourceSX1509_REGister A */ + [SX1509_REG_EVENT_STATUS_B] = 0x00, /* Event statusSX1509_REGister B */ + [SX1509_REG_EVENT_STATUS_A] = 0x00, /* Event statusSX1509_REGister A */ + [SX1509_REG_LEVEL_SHIFTER_1] = 0x00, /* Level shifterSX1509_REGister 1 */ + [SX1509_REG_LEVEL_SHIFTER_2] = 0x00, /* Level shifterSX1509_REGister 2 */ + [SX1509_REG_CLOCK] = 0x00, /* Clock managementSX1509_REGister */ + [SX1509_REG_MISC] = 0x00, /* Miscellaneous device settingsSX1509_REGister */ + [SX1509_REG_LED_DRIVER_ENABLE_B] = + 0x00, /* LED driver enableSX1509_REGister B */ + [SX1509_REG_LED_DRIVER_ENABLE_A] = + 0x00, /* LED driver enableSX1509_REGister A */ + [SX1509_REG_DEBOUNCW_CONFIG] = + 0x00, /* Debounce configurationSX1509_REGister */ + [SX1509_REG_DEBOUNCW_ENABLE_B] = + 0x00, /* Debounce enableSX1509_REGister B */ + [SX1509_REG_DEBOUNCW_ENABLE_A] = + 0x00, /* Debounce enableSX1509_REGister A */ + [SX1509_REG_KEY_CONFIG_1] = + 0x00, /* Key scan configurationSX1509_REGister 1 */ + [SX1509_REG_KEY_CONFIG_2] = + 0x00, /* Key scan configurationSX1509_REGister 2 */ + [SX1509_REG_KEY_DATA_1] = 0x00, /* Key value (column) 1 */ + [SX1509_REG_KEY_DATA_2] = 0x00, /* Key value (row) 2 */ + [SX1509_REG_T_ON_0] = 0x00, /* ON timeSX1509_REGister I/O[0] */ + [SX1509_REG_I_ON_0] = 0x00, /* ON intensitySX1509_REGister I/O[0] */ + [SX1509_REG_OFF_0] = 0x00, /* OFF time/intensitySX1509_REGister I/O[0] */ + [SX1509_REG_T_ON_1] = 0x00, /* ON timeSX1509_REGister I/O[1] */ + [SX1509_REG_I_ON_1] = 0x00, /* ON intensitySX1509_REGister I/O[1] */ + [SX1509_REG_OFF_1] = 0x00, /* OFF time/intensitySX1509_REGister I/O[1] */ + [SX1509_REG_T_ON_2] = 0x00, /* ON timeSX1509_REGister I/O[2] */ + [SX1509_REG_I_ON_2] = 0x00, /* ON intensitySX1509_REGister I/O[2] */ + [SX1509_REG_OFF_2] = 0x00, /* OFF time/intensitySX1509_REGister I/O[2] */ + [SX1509_REG_T_ON_3] = 0x00, /* ON timeSX1509_REGister I/O[3] */ + [SX1509_REG_I_ON_3] = 0x00, /* ON intensitySX1509_REGister I/O[3] */ + [SX1509_REG_OFF_3] = 0x00, /* OFF time/intensitySX1509_REGister I/O[3] */ + [SX1509_REG_T_ON_4] = 0x00, /* ON timeSX1509_REGister I/O[4] */ + [SX1509_REG_I_ON_4] = 0x00, /* ON intensitySX1509_REGister I/O[4] */ + [SX1509_REG_OFF_4] = 0x00, /* OFF time/intensitySX1509_REGister I/O[4] */ + [SX1509_REG_T_RISE_4] = 0x00, /* Fade inSX1509_REGister I/O[4] */ + [SX1509_REG_T_Fall_4] = 0x00, /* Fade outSX1509_REGister I/O[4] */ + [SX1509_REG_T_ON_5] = 0x00, /* ON timeSX1509_REGister I/O[5] */ + [SX1509_REG_I_ON_5] = 0x00, /* ON intensitySX1509_REGister I/O[5] */ + [SX1509_REG_OFF_5] = 0x00, /* OFF time/intensitySX1509_REGister I/O[5] */ + [SX1509_REG_T_RISE_5] = 0x00, /* Fade inSX1509_REGister I/O[5] */ + [SX1509_REG_T_Fall_5] = 0x00, /* Fade outSX1509_REGister I/O[5] */ + [SX1509_REG_T_ON_6] = 0x00, /* ON timeSX1509_REGister I/O[6] */ + [SX1509_REG_I_ON_6] = 0x00, /* ON intensitySX1509_REGister I/O[6] */ + [SX1509_REG_OFF_6] = 0x00, /* OFF time/intensitySX1509_REGister I/O[6] */ + [SX1509_REG_T_RISE_6] = 0x00, /* Fade inSX1509_REGister I/O[6] */ + [SX1509_REG_T_Fall_6] = 0x00, /* Fade outSX1509_REGister I/O[6] */ + [SX1509_REG_T_ON_7] = 0x00, /* ON timeSX1509_REGister I/O[6] */ + [SX1509_REG_I_ON_7] = 0x00, /* ON intensitySX1509_REGister I/O[7] */ + [SX1509_REG_OFF_7] = 0x00, /* OFF time/intensitySX1509_REGister I/O[7] */ + [SX1509_REG_T_RISE_7] = 0x00, /* Fade inSX1509_REGister I/O[7] */ + [SX1509_REG_T_Fall_7] = 0x00, /* Fade outSX1509_REGister I/O[7] */ + [SX1509_REG_T_ON_8] = 0x00, /* ON timeSX1509_REGister I/O[8] */ + [SX1509_REG_I_ON_8] = 0x00, /* ON intensitySX1509_REGister I/O[8] */ + [SX1509_REG_OFF_8] = 0x00, /* OFF time/intensitySX1509_REGister I/O[8] */ + [SX1509_REG_T_ON_9] = 0x00, /* ON timeSX1509_REGister I/O[9] */ + [SX1509_REG_I_ON_9] = 0x00, /* ON intensitySX1509_REGister I/O[9] */ + [SX1509_REG_OFF_9] = 0x00, /* OFF time/intensitySX1509_REGister I/O[9] */ + [SX1509_REG_T_ON_10] = 0x00, /* ON timeSX1509_REGister I/O[10] */ + [SX1509_REG_I_ON_10] = 0x00, /* ON intensitySX1509_REGister I/O[10] */ + [SX1509_REG_OFF_10] = 0x00, /* OFF time/intensitySX1509_REGister I/O[10] */ + [SX1509_REG_T_ON_11] = 0x00, /* ON timeSX1509_REGister I/O[11] */ + [SX1509_REG_I_ON_11] = 0x00, /* ON intensitySX1509_REGister I/O[11] */ + [SX1509_REG_OFF_11] = 0x00, /* OFF time/intensitySX1509_REGister I/O[11] */ + [SX1509_REG_T_ON_12] = 0x00, /* ON timeSX1509_REGister I/O[12] */ + [SX1509_REG_I_ON_12] = 0x00, /* ON intensitySX1509_REGister I/O[12] */ + [SX1509_REG_OFF_12] = 0x00, /* OFF time/intensitySX1509_REGister I/O[12] */ + [SX1509_REG_T_RISE_12] = 0x00, /* Fade inSX1509_REGister I/O[12] */ + [SX1509_REG_T_Fall_12] = 0x00, /* Fade outSX1509_REGister I/O[12] */ + [SX1509_REG_T_ON_13] = 0x00, /* ON timeSX1509_REGister I/O[13] */ + [SX1509_REG_I_ON_13] = 0x00, /* ON intensitySX1509_REGister I/O[13] */ + [SX1509_REG_OFF_13] = 0x00, /* OFF time/intensitySX1509_REGister I/O[13] */ + [SX1509_REG_T_RISE_13] = 0x00, /* Fade inSX1509_REGister I/O[13] */ + [SX1509_REG_T_Fall_13] = 0x00, /* Fade outSX1509_REGister I/O[13] */ + [SX1509_REG_T_ON_14] = 0x00, /* ON timeSX1509_REGister I/O[14] */ + [SX1509_REG_I_ON_14] = 0x00, /* ON intensitySX1509_REGister I/O[14] */ + [SX1509_REG_OFF_14] = 0x00, /* OFF time/intensitySX1509_REGister I/O[14] */ + [SX1509_REG_T_RISE_14] = 0x00, /* Fade inSX1509_REGister I/O[14] */ + [SX1509_REG_T_Fall_14] = 0x00, /* Fade outSX1509_REGister I/O[14] */ + [SX1509_REG_T_ON_15] = 0x00, /* ON timeSX1509_REGister I/O[15] */ + [SX1509_REG_I_ON_15] = 0x00, /* ON intensitySX1509_REGister I/O[15] */ + [SX1509_REG_OFF_15] = 0x00, /* OFF time/intensitySX1509_REGister I/O[15] */ + [SX1509_REG_T_RISE_15] = 0x00, /* Fade inSX1509_REGister I/O[115] */ + [SX1509_REG_T_Fall_15] = 0x00, /* Fade outSX1509_REGister I/O[15] */ + [SX1509_REG_HIGH_INPUT_B] = 0x00, /* */ + [SX1509_REG_HIGH_INPUT_A] = 0x00, /* */ + [SX1509_REG_RESET] = 0x00, /* */ + [SX1509_REG_TEST_1] = 0x00, /* */ + [SX1509_REG_TEST_2] = 0x00, /* */ +}; diff --git a/firmware/ec/test/fake/fake_powerSource.c b/firmware/ec/test/fake/fake_powerSource.c new file mode 100644 index 0000000000..4bc18f17bc --- /dev/null +++ b/firmware/ec/test/fake/fake_powerSource.c @@ -0,0 +1,37 @@ +/** + * 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_powerSource.h" +#include + +extern const OcGpio_FnTable GpioSX1509_fnTable; + +bool PWR_GpioPins[] = { + [OC_EC_PWR_PRSNT_SOLAR_AUX] = 0x1, + [OC_EC_PWR_PRSNT_POE] = 0x1, +}; + +uint32_t PWR_GpioConfig[] = { + [OC_EC_PWR_PRSNT_SOLAR_AUX] = OCGPIO_CFG_INPUT, + [OC_EC_PWR_PRSNT_POE] = OCGPIO_CFG_INPUT, +}; + +/* ============================= Boilerplate ================================ */ +OcGpio_Port ec_io = { + .fn_table = &FakeGpio_fnTable, + .object_data = &(FakeGpio_Obj){}, +}; + +OcGpio_Port gbc_io_0 = { + .fn_table = &GpioSX1509_fnTable, + .cfg = + &(SX1509_Cfg){ + .i2c_dev = { I2C_BUS, I2C_ADDR }, + }, + .object_data = &(SX1509_Obj){}, +}; \ No newline at end of file diff --git a/firmware/ec/test/include/test_powerSource.h b/firmware/ec/test/include/test_powerSource.h new file mode 100644 index 0000000000..1239c8ff40 --- /dev/null +++ b/firmware/ec/test/include/test_powerSource.h @@ -0,0 +1,48 @@ +/** + * 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_POWERSOURCE_H +#define _TEST_POWERSOURCE_H + +#include "common/inc/global/Framework.h" +#include "common/inc/ocmp_wrappers/ocmp_powersource.h" +#include "drivers/GpioSX1509.h" +#include "drivers/OcGpio.h" +#include "fake/fake_GPIO.h" +#include "fake/fake_I2C.h" +#include "fake/fake_ThreadedISR.h" +#include "helpers/array.h" +#include "helpers/attribute.h" +#include "helpers/memory.h" +#include "inc/devices/powerSource.h" +#include "include/test_sx1509.h" +#include +#include "unity.h" +/* ======================== Constants & variables =========================== */ +#define I2C_BUS 5 +#define I2C_ADDR 0x71 +#define OC_EC_PWR_PRSNT_SOLAR_AUX 0x1E +#define OC_EC_PWR_PRSNT_POE 0x55 +#define OC_EC_PWR_INVALID_PIN 0x57 +#define OC_EC_PWR_INVALID_IO 0x82 +#define PWR_EXT_BAT_ENABLE_FIRST_BYTE 0x08 +#define PWR_EXT_BAT_ENABLE_SECOND_BYTE 0x00 +#define PWR_INT_BAT_ENABLE_FIRST_BYTE 0x10 +#define PWR_INT_BAT_ENABLE_SECOND_BYTE 0x00 +#define PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE 0x18 +#define PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE 0x00 +#define PWR_STATE_DISABLE 0x01 +#define PWR_STATE_ENABLE 0x00 +#define PWR_STAT_INVALID_PARAM 0x09 + +typedef enum ePowerSourceStatus { + PWR_SRC_NOT_AVAILABLE = 0, + PWR_SRC_ACTIVE_AVAILABLE, +} ePowerSourceStatus; + +#endif diff --git a/firmware/ec/test/include/test_sx1509.h b/firmware/ec/test/include/test_sx1509.h new file mode 100644 index 0000000000..31757667ef --- /dev/null +++ b/firmware/ec/test/include/test_sx1509.h @@ -0,0 +1,127 @@ +/** + * 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_SX1509_H +#define _TEST_SX1509_H + +#include + +/*Enumes are defined as per the SX1509 datasheet*/ +typedef enum SX1509Regs { + SX1509_REG_INPUT_DISABLE_B = 0x00, + SX1509_REG_INPUT_DISABLE_A, + SX1509_REG_LONG_SLEW_B, + SX1509_REG_LONG_SLEW_A, + SX1509_REG_LOW_DRIVE_B, + SX1509_REG_LOW_DRIVE_A, + SX1509_REG_PULL_UP_B, + SX1509_REG_PULL_UP_A, + SX1509_REG_PULL_DOWN_B, + SX1509_REG_PULL_DOWN_A, + SX1509_REG_OPEN_DRAIN_B, + SX1509_REG_OPEN_DRAIN_A, + SX1509_REG_POLARITY_B, + SX1509_REG_POLARITY_A, + SX1509_REG_DIR_B, + SX1509_REG_DIR_A, + SX1509_REG_DATA_B, + SX1509_REG_DATA_A, + SX1509_REG_INTERRUPT_MASK_B, + SX1509_REG_INTERRUPT_MASK_A, + SX1509_REG_SENSE_HIGH_B, + SX1509_REG_SENSE_LOW_B, + SX1509_REG_SENSE_HIGH_A, + SX1509_REG_SENSE_LOW_A, + SX1509_REG_INTERRUPT_SOURCE_B, + SX1509_REG_INTERRUPT_SOURCE_A, + SX1509_REG_EVENT_STATUS_B, + SX1509_REG_EVENT_STATUS_A, + SX1509_REG_LEVEL_SHIFTER_1, + SX1509_REG_LEVEL_SHIFTER_2, + SX1509_REG_CLOCK, + SX1509_REG_MISC, + SX1509_REG_LED_DRIVER_ENABLE_B, + SX1509_REG_LED_DRIVER_ENABLE_A, + SX1509_REG_DEBOUNCW_CONFIG, + SX1509_REG_DEBOUNCW_ENABLE_B, + SX1509_REG_DEBOUNCW_ENABLE_A, + SX1509_REG_KEY_CONFIG_1, + SX1509_REG_KEY_CONFIG_2, + SX1509_REG_KEY_DATA_1, + SX1509_REG_KEY_DATA_2, + SX1509_REG_T_ON_0, + SX1509_REG_I_ON_0, + SX1509_REG_OFF_0, + SX1509_REG_T_ON_1, + SX1509_REG_I_ON_1, + SX1509_REG_OFF_1, + SX1509_REG_T_ON_2, + SX1509_REG_I_ON_2, + SX1509_REG_OFF_2, + SX1509_REG_T_ON_3, + SX1509_REG_I_ON_3, + SX1509_REG_OFF_3, + SX1509_REG_T_ON_4, + SX1509_REG_I_ON_4, + SX1509_REG_OFF_4, + SX1509_REG_T_RISE_4, + SX1509_REG_T_Fall_4, + SX1509_REG_T_ON_5, + SX1509_REG_I_ON_5, + SX1509_REG_OFF_5, + SX1509_REG_T_RISE_5, + SX1509_REG_T_Fall_5, + SX1509_REG_T_ON_6, + SX1509_REG_I_ON_6, + SX1509_REG_OFF_6, + SX1509_REG_T_RISE_6, + SX1509_REG_T_Fall_6, + SX1509_REG_T_ON_7, + SX1509_REG_I_ON_7, + SX1509_REG_OFF_7, + SX1509_REG_T_RISE_7, + SX1509_REG_T_Fall_7, + SX1509_REG_T_ON_8, + SX1509_REG_I_ON_8, + SX1509_REG_OFF_8, + SX1509_REG_T_ON_9, + SX1509_REG_I_ON_9, + SX1509_REG_OFF_9, + SX1509_REG_T_ON_10, + SX1509_REG_I_ON_10, + SX1509_REG_OFF_10, + SX1509_REG_T_ON_11, + SX1509_REG_I_ON_11, + SX1509_REG_OFF_11, + SX1509_REG_T_ON_12, + SX1509_REG_I_ON_12, + SX1509_REG_OFF_12, + SX1509_REG_T_RISE_12, + SX1509_REG_T_Fall_12, + SX1509_REG_T_ON_13, + SX1509_REG_I_ON_13, + SX1509_REG_OFF_13, + SX1509_REG_T_RISE_13, + SX1509_REG_T_Fall_13, + SX1509_REG_T_ON_14, + SX1509_REG_I_ON_14, + SX1509_REG_OFF_14, + SX1509_REG_T_RISE_14, + SX1509_REG_T_Fall_14, + SX1509_REG_T_ON_15, + SX1509_REG_I_ON_15, + SX1509_REG_OFF_15, + SX1509_REG_T_RISE_15, + SX1509_REG_T_Fall_15, + SX1509_REG_HIGH_INPUT_B, + SX1509_REG_HIGH_INPUT_A, + SX1509_REG_RESET = 0x7D, + SX1509_REG_TEST_1, + SX1509_REG_TEST_2 +} SX1509Regs; +#endif diff --git a/firmware/ec/test/suites/Doc/TestCaseList.xlsx b/firmware/ec/test/suites/Doc/TestCaseList.xlsx index f15c78f0eb..f6cd0442f4 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_powerSource.c b/firmware/ec/test/suites/Test_ocmp_powerSource.c new file mode 100644 index 0000000000..51533cf341 --- /dev/null +++ b/firmware/ec/test/suites/Test_ocmp_powerSource.c @@ -0,0 +1,292 @@ +#include "include/test_powerSource.h" + +extern bool PWR_GpioPins[OC_EC_PWR_PRSNT_POE]; +extern const OcGpio_FnTable GpioSX1509_fnTable; +extern OcGpio_Port ec_io; +extern OcGpio_Port gbc_io_0; +extern PWRSRC_Dev gbc_pwr_powerSource; +extern PWRSRC_Dev gbc_pwr_powerSource_invalid; +extern uint32_t PWR_GpioConfig[OC_EC_PWR_PRSNT_POE]; +extern uint8_t SX1509_regs[SX1509_REG_TEST_2]; +/* ============================= Boilerplate ================================ */ +void suite_setUp(void) +{ + FakeGpio_registerDevSimple(PWR_GpioPins, PWR_GpioConfig); + fake_I2C_init(); + fake_I2C_registerDevSimple(I2C_BUS, I2C_ADDR, SX1509_regs, + sizeof(SX1509_regs), sizeof(SX1509_regs[0]), + sizeof(uint8_t), FAKE_I2C_DEV_LITTLE_ENDIAN); +} + +void setUp(void) +{ + memset(SX1509_regs, 0, sizeof(SX1509_regs)); + OcGpio_init(&gbc_io_0); +} + +void tearDown(void) +{ +} + +void suite_tearDown(void) +{ + fake_I2C_deinit(); +} +/* ================================ Tests =================================== */ +void test_init(void) +{ + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = 0x1; + AlertData alert_data = { + .subsystem = 7, + .componentId = 1, + .deviceId = 0, + }; + AlertData *alert_data_cp = malloc(sizeof(AlertData)); + *alert_data_cp = alert_data; + TEST_ASSERT_EQUAL( + POST_DEV_NO_CFG_REQ, + PWRSRC_fxnTable.cb_init(&gbc_pwr_powerSource, NULL, alert_data_cp)); +} + +void test_probe(void) +{ + POSTData postData; + PWR_GpioConfig[OC_EC_PWR_PRSNT_SOLAR_AUX] = OCGPIO_CFG_OUTPUT; + PWR_GpioConfig[OC_EC_PWR_PRSNT_POE] = OCGPIO_CFG_OUTPUT; + + TEST_ASSERT_EQUAL(POST_DEV_NOSTATUS, PWRSRC_fxnTable.cb_probe( + &gbc_pwr_powerSource, &postData)); + TEST_ASSERT_EQUAL(OCGPIO_CFG_INPUT, + PWR_GpioConfig[OC_EC_PWR_PRSNT_SOLAR_AUX]); + TEST_ASSERT_EQUAL(OCGPIO_CFG_INPUT, PWR_GpioConfig[OC_EC_PWR_PRSNT_POE]); +} + +void test_get_status_poeAvailable(void) +{ + /* POE State available */ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_ENABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, PWR_STAT_POE_AVAILABILITY, + &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus); + + /* POE State Not Available */ + powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, PWR_STAT_POE_AVAILABILITY, + &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +} + +void test_get_status_poeAccessible(void) +{ + /* POE State Accessible */ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_ENABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_POE_ACCESSIBILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus); + + /* POE State Not Accessible */ + powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_POE_ACCESSIBILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +} + +void test_get_status_solaravailable(void) +{ + /* Solar State Available */ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_ENABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_SOLAR_AVAILABILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus); + + /* Solar State Not Available */ + powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_SOLAR_AVAILABILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +} + +void test_get_status_solaraccessible(void) +{ + /* Solar State Accessible */ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_ENABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_SOLAR_ACCESSIBILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus); + + /* Solar State Not Accessible */ + powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_SOLAR_ACCESSIBILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +} + +void test_get_status_extavailable(void) +{ + /* EXT Battery Available */ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_EXT_BAT_ENABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_EXT_BAT_ENABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_EXTBATT_AVAILABILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus); + + /* EXT Battery Not Available */ + powerStatus = PWR_SRC_NOT_AVAILABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_EXTBATT_AVAILABILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +} + +void test_get_status_extaccessible(void) +{ + /* EXT Battery Accessible */ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_EXT_BAT_ENABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_EXT_BAT_ENABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_EXTBATT_ACCESSIBILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus); + + /* EXT Battery Not Accessible */ + powerStatus = PWR_SRC_NOT_AVAILABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_EXTBATT_ACCESSIBILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +} + +void test_get_status_intavailable(void) +{ + /* Int Battery Available */ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_BAT_ENABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_BAT_ENABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_INTBATT_AVAILABILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus); + + /* Int Battery Not Available */ + powerStatus = PWR_SRC_NOT_AVAILABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_INTBATT_AVAILABILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +} + +void test_get_status_intaccessible(void) +{ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + /* Int Battery Not Accessible */ + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_BAT_ENABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_BAT_ENABLE_SECOND_BYTE; + + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_INTBATT_ACCESSIBILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus); + + /* Int Battery Not Accessible */ + powerStatus = PWR_SRC_NOT_AVAILABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE; + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, + PWR_STAT_INTBATT_ACCESSIBILITY, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +} + +void test_get_status_invalid_param(void) +{ + uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE; + /* Invalid Param Test */ + PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE; + PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE; + SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_BAT_ENABLE_FIRST_BYTE; + SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_BAT_ENABLE_SECOND_BYTE; + + pwr_source_init(); + pwr_get_source_info(&gbc_pwr_powerSource); + TEST_ASSERT_EQUAL( + true, PWRSRC_fxnTable.cb_get_status( + &gbc_pwr_powerSource, PWR_STAT_INVALID_PARAM, &powerStatus)); + TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus); +}