config: update TCPMv2 config options

Reorganize how the TCPMv2 options are used

- Update documentation in config.h and bring TCPMv2 items close together
- Make the layer defines consistent on how they include compilation
units
- Update tests to account for how files are included now
- Remove unnecessary defines in board.h since they are default on

BRANCH=none
BUG=none
TEST=builds

Change-Id: I91fca51648912deef44db23492ecc7775b2e3062
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2120063
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
This commit is contained in:
Jett Rink 2020-03-24 16:31:59 -06:00 committed by Commit Bot
parent 90d47e5e3b
commit cb893a4257
8 changed files with 108 additions and 108 deletions

View File

@ -135,9 +135,6 @@
/* TODO: b/145756626 - re-enable once all blocking issues resolved */
#if 0
#define CONFIG_USB_PD_TCPMV2
#define CONFIG_USB_TYPEC_SM
#define CONFIG_USB_PRL_SM
#define CONFIG_USB_PE_SM
#define CONFIG_USB_DRP_ACC_TRYSRC
#else
/*

View File

@ -8,17 +8,30 @@
_usbc_dir:=$(dir $(lastword $(MAKEFILE_LIST)))
ifneq ($(CONFIG_USB_PD_TCPMV2),)
all-obj-$(CONFIG_USB_PD_TCPMV2)+=$(_usbc_dir)usb_sm.o
all-obj-$(CONFIG_USB_TYPEC_SM)+=$(_usbc_dir)usbc_task.o
all-obj-$(CONFIG_USB_PRL_SM)+=$(_usbc_dir)usb_prl_sm.o
all-obj-y+=$(_usbc_dir)usb_sm.o
all-obj-y+=$(_usbc_dir)usbc_task.o
# Type-C state machines
ifneq ($(CONFIG_USB_TYPEC_SM),)
all-obj-$(CONFIG_USB_VPD)+=$(_usbc_dir)usb_tc_vpd_sm.o
all-obj-$(CONFIG_USB_CTVPD)+=$(_usbc_dir)usb_tc_ctvpd_sm.o
all-obj-$(CONFIG_USB_DRP_ACC_TRYSRC)+=$(_usbc_dir)usb_tc_drp_acc_trysrc_sm.o
endif # CONFIG_USB_TYPEC_SM
# Protocol state machine
ifneq ($(CONFIG_USB_PRL_SM),)
all-obj-y+=$(_usbc_dir)usb_prl_sm.o
endif # CONFIG_USB_PRL_SM
# Policy Engine state machines
ifneq ($(CONFIG_USB_PE_SM),)
all-obj-$(CONFIG_USB_VPD)+=$(_usbc_dir)usb_pe_ctvpd_sm.o
all-obj-$(CONFIG_USB_CTVPD)+=$(_usbc_dir)usb_pe_ctvpd_sm.o
all-obj-$(CONFIG_USB_DRP_ACC_TRYSRC)+=$(_usbc_dir)usb_pe_drp_sm.o
endif # CONFIG_USB_PE_SM
endif # CONFIG_USB_PD_TCPMV2
# For testing
all-obj-$(CONFIG_TEST_USB_PE_SM)+=$(_usbc_dir)usb_pe_drp_sm.o
endif
all-obj-$(CONFIG_USB_VPD)+=$(_usbc_dir)usb_tc_vpd_sm.o
all-obj-$(CONFIG_USB_CTVPD)+=$(_usbc_dir)usb_tc_ctvpd_sm.o
all-obj-$(CONFIG_USB_DRP_ACC_TRYSRC)+=\
$(_usbc_dir)usb_tc_drp_acc_trysrc_sm.o
endif
all-obj-$(CONFIG_TEST_SM)+=$(_usbc_dir)usb_sm.o

View File

@ -111,7 +111,8 @@ void pd_task(void *u)
{
int port = TASK_ID_TO_PD_PORT(task_get_current());
tc_state_init(port);
if (IS_ENABLED(CONFIG_USB_TYPEC_SM))
tc_state_init(port);
if (IS_ENABLED(CONFIG_USBC_PPC))
ppc_init(port);
@ -135,7 +136,8 @@ void pd_task(void *u)
: USBC_EVENT_TIMEOUT);
/* handle events that affect the state machine as a whole */
tc_event_check(port, evt);
if (IS_ENABLED(CONFIG_USB_TYPEC_SM))
tc_event_check(port, evt);
/*
* run port controller task to check CC and/or read incoming
@ -144,15 +146,16 @@ void pd_task(void *u)
if (IS_ENABLED(CONFIG_USB_PD_TCPC))
tcpc_run(port, evt);
/* Run policy engine state machine */
if (IS_ENABLED(CONFIG_USB_PE_SM))
/* Run policy engine state machine */
pe_run(port, evt, tc_get_pd_enabled(port));
/* Run protocol state machine */
if (IS_ENABLED(CONFIG_USB_PRL_SM))
/* Run protocol state machine */
prl_run(port, evt, tc_get_pd_enabled(port));
/* Run TypeC state machine */
tc_run(port);
if (IS_ENABLED(CONFIG_USB_TYPEC_SM))
tc_run(port);
}
}

View File

@ -893,30 +893,6 @@
*/
#undef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA
/*
* Define to enable Type-C State Machine. Must be enabled
* with CONFIG_USB_PD_TCPMV2
*/
#define CONFIG_USB_TYPEC_SM
/*
* Define to enable Protocol Layer State Machine. Must be enabled
* with CONFIG_USB_PD_TCPMV2 and CONFIG_USB_TYPEC_SM
*/
#define CONFIG_USB_PRL_SM
/*
* Define to enable Policy Engine State Machine. Must be enabled
* with CONFIG_USB_SM_PD_TCPMV2 and CONFIG_USB_TYPEC_SM
*/
#define CONFIG_USB_PE_SM
/*
* Define to enable Policy Engine State Machine. This is an override
* that is used to just pull in PE for unit testing.
*/
#undef CONFIG_TEST_USB_PE_SM
/*
* Board specific maximum input current limit, in mA.
*/
@ -3651,16 +3627,39 @@
/*
* Enables Version 2 of the Power Delivery state machine
*
* Along with CONFIG_USB_PD_TCPMV2, you must ensure the follow
* options are defined to use the new statemachine for USB-C:
*
* CONFIG_USB_PD_DECODE_SOP
* CONFIG_USB_TYPEC_SM (defined by default)
* CONFIG_USB_PRL_SM (defined by default)
* One of CONFIG_USB_PE_* policy engine options.
* Along with CONFIG_USB_PD_TCPMV2, you must ensure a device type is also
* enabled otherwise an error will be emitted.
*/
#undef CONFIG_USB_PD_TCPMV2
/*
* Device Types for TCPMv2.
*
* Exactly one must be defined when CONFIG_USB_PD_TCPMV2 is defined.
*
* VPD - Vconn Powered Device
* CTVPD - Charge Through Vconn Powered Device
* DRP_ACC_TRYSRC - Dual Role Port, Audio Accessory, and Try.SRC Device
*/
#undef CONFIG_USB_VPD
#undef CONFIG_USB_CTVPD
#undef CONFIG_USB_DRP_ACC_TRYSRC
/*
* TCPMv2 statemachine layers
*
* All layers are defined by default. To opt-out, you must undef in your board.
* Also these defines don't take effect unless CONFIG_USB_PD_TCPMV2 is also
* defined.
*
* TYPEC_SM - Type-C deals with CC lines voltage level connections
* PRL_SM - Protocol handles flow and chunking TX and RX messages
* PE - Policy Engine handles PD communication flow
*/
#define CONFIG_USB_TYPEC_SM
#define CONFIG_USB_PRL_SM
#define CONFIG_USB_PE_SM
/* Enables Zork Auto Discharge Disconnect Changes */
#undef CONFIG_ZORK_AUTO_DISCHARGE
@ -3994,15 +3993,6 @@
*/
#undef CONFIG_USB_PD_PREFER_MV
/* Type-C VCONN Powered Device */
#undef CONFIG_USB_VPD
/* Type-C Charge Through VCONN Powered Device */
#undef CONFIG_USB_CTVPD
/* Type-C DRP with Accessory and Try.SRC */
#undef CONFIG_USB_DRP_ACC_TRYSRC
/* Type-C Fast Role Swap */
#undef CONFIG_USB_TYPEC_PD_FAST_ROLE_SWAP
@ -4508,6 +4498,18 @@
*/
#undef CONFIG_INTEL_VIRTUAL_MUX
/*
* TEST ONLY defines (CONFIG_TEST_*)
*
* Used to include files for unit and other builds tests.
*/
/* Define to enable Policy Engine State Machine. */
#undef CONFIG_TEST_USB_PE_SM
/* Define to enable USB State Machine framework. */
#undef CONFIG_TEST_SM
/*****************************************************************************/
/*
* Include board and core configs, since those hold the CONFIG_ constants for a
@ -4559,6 +4561,19 @@
#endif
#endif
/******************************************************************************/
/*
* Ensure that CONFIG_USB_PD_TCPMV2 is being used with exactly one device type
*/
#ifdef CONFIG_USB_PD_TCPMV2
#if defined(CONFIG_USB_VPD) + \
defined(CONFIG_USB_CTVPD) + \
defined(CONFIG_USB_DRP_ACC_TRYSRC) != 1
#error Must define exactly one CONFIG_USB_ device type.
#endif
#endif
/******************************************************************************/
/*
* Automatically define CONFIG_HOSTCMD_X86 if either child option is defined.

View File

@ -304,36 +304,11 @@ int ncp15wb_calculate_temp(uint16_t adc);
#define CONFIG_SW_CRC
#endif
#if defined(TEST_USB_SM_FRAMEWORK_H3)
#define CONFIG_USB_PD_PORT_MAX_COUNT 1
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#undef CONFIG_USB_TYPEC_SM
#define CONFIG_USB_PD_TCPMV2
#endif
#if defined(TEST_USB_SM_FRAMEWORK_H2)
#define CONFIG_USB_PD_PORT_MAX_COUNT 1
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#undef CONFIG_USB_TYPEC_SM
#define CONFIG_USB_PD_TCPMV2
#endif
#if defined(TEST_USB_SM_FRAMEWORK_H1)
#define CONFIG_USB_PD_PORT_MAX_COUNT 1
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#undef CONFIG_USB_TYPEC_SM
#define CONFIG_USB_PD_TCPMV2
#endif
#if defined(TEST_USB_SM_FRAMEWORK_H0)
#define CONFIG_USB_PD_PORT_MAX_COUNT 1
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#undef CONFIG_USB_TYPEC_SM
#define CONFIG_USB_PD_TCPMV2
#if defined(TEST_USB_SM_FRAMEWORK_H3) || \
defined(TEST_USB_SM_FRAMEWORK_H2) || \
defined(TEST_USB_SM_FRAMEWORK_H1) || \
defined(TEST_USB_SM_FRAMEWORK_H0)
#define CONFIG_TEST_SM
#endif
#if defined(TEST_USB_PRL)

View File

@ -41,6 +41,11 @@ void pd_set_vbus_discharge(int port, int enable)
gpio_set_level(GPIO_USB_C0_DISCHARGE, enable);
}
uint8_t tc_get_pd_enabled(int port)
{
return 1;
}
/**
* Test section
*/

View File

@ -7,19 +7,19 @@
#include "common.h"
#include "crc.h"
#include "task.h"
#include "tcpm.h"
#include "test_util.h"
#include "timer.h"
#include "tcpm.h"
#include "usb_emsg.h"
#include "usb_pe_sm.h"
#include "usb_pd.h"
#include "usb_pd_test_util.h"
#include "usb_pd.h"
#include "usb_pe_sm.h"
#include "usb_prl_sm.h"
#include "usb_sm_checks.h"
#include "usb_tc_sm.h"
#include "util.h"
#define PORT0 0
#define PORT1 1
/*
* These enum definitions are declared in usb_prl_sm and are private to that
@ -703,6 +703,11 @@ static int simulate_send_extended_data_msg(int port,
len);
}
uint8_t tc_get_pd_enabled(int port)
{
return pd_port[port].pd_enable;
}
static void enable_prl(int port, int en)
{
tcpm_set_rx_enable(port, en);
@ -1334,24 +1339,12 @@ static int test_phy_execute_hard_reset_msg(void)
return EC_SUCCESS;
}
int pd_task(void *u)
{
int port = PORT0;
int evt;
while (1) {
evt = task_wait_event(-1);
tcpc_run(port, evt);
prl_run(port, evt, pd_port[port].pd_enable);
}
return EC_SUCCESS;
}
/* Reset the state machine between each test */
void before_test(void)
{
/* This test relies on explicitly cycling through events manually */
tc_pause_event_loop(PORT0);
pd_port[PORT0].mock_pe_message_sent = 0;
pd_port[PORT0].mock_pe_error = -1;
pd_port[PORT0].mock_pe_hard_reset_sent = 0;

View File

@ -7,5 +7,4 @@
* See CONFIG_TEST_TASK_LIST in config.h for details.
*/
#define CONFIG_TEST_TASK_LIST \
TASK_TEST(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_TEST(PD_C1, pd_task, NULL, LARGER_TASK_STACK_SIZE)
TASK_TEST(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE)