diff --git a/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp b/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp index 44fbc793..4e3dad92 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp +++ b/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp @@ -45,7 +45,8 @@ void InterruptHandler::Thread(const void *arg) { bool notifSent = false; while (true) { /* If the INT_N line is low */ - if (xTaskNotifyWait(0x00, 0x0F, NULL, 200) == pdPASS) { + if (xTaskNotifyWait(0x00, 0x0F, NULL, + PolicyEngine::setupCompleteOrTimedOut() ? 1000 : 200) == pdPASS) { //delay slightly so we catch the crc with better timing osDelay(2); } diff --git a/workspace/TS100/Core/Drivers/FUSB302/pd.h b/workspace/TS100/Core/Drivers/FUSB302/pd.h index 11c8f80f..be1f8453 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/pd.h +++ b/workspace/TS100/Core/Drivers/FUSB302/pd.h @@ -273,18 +273,18 @@ * Where a range is specified, the middle of the range (rounded down to the * nearest millisecond) is used. */ -#define PD_T_CHUNKING_NOT_SUPPORTED (450) -#define PD_T_HARD_RESET_COMPLETE (400) -#define PD_T_PS_TRANSITION (5000) -#define PD_T_SENDER_RESPONSE (2700) -#define PD_T_SINK_REQUEST (1000) -#define PD_T_TYPEC_SINK_WAIT_CAP (5000) -#define PD_T_PD_DEBOUNCE (2000) +#define PD_T_CHUNKING_NOT_SUPPORTED (45) +#define PD_T_HARD_RESET_COMPLETE (40) +#define PD_T_PS_TRANSITION (500) +#define PD_T_SENDER_RESPONSE (270) +#define PD_T_SINK_REQUEST (100) +#define PD_T_TYPEC_SINK_WAIT_CAP (45) +#define PD_T_PD_DEBOUNCE (20) /* * Counter maximums */ -#define PD_N_HARD_RESET_COUNT 20 +#define PD_N_HARD_RESET_COUNT 2 /* * Value parameters diff --git a/workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp b/workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp index a9da67bb..d015dd2a 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp +++ b/workspace/TS100/Core/Drivers/FUSB302/policy_engine.cpp @@ -263,19 +263,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() { return PESinkHardReset; } - /* If we're using PD 3.0 */ - if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { - /* If the request was for a PPS APDO, start SinkPPSPeriodicTimer */ - if (PD_RDO_OBJPOS_GET(&_last_dpm_request) >= _pps_index) { - start_pps_timer(); - /* Otherwise, stop SinkPPSPeriodicTimer */ - } else { - stop_pps_timer(); - } - } - /* This will use a virtual timer to send an event flag to this thread after - * PD_T_PPS_REQUEST */ - /* Wait for a response */ evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); @@ -367,8 +354,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() { /* Wait for an event */ evt = waitForEvent( - PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP - | PDB_EVT_PE_PPS_REQUEST); + PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP); /* If we got reset signaling, transition to default */ if (evt & PDB_EVT_PE_RESET) { @@ -380,14 +366,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() { return PESinkHardReset; } - /* If SinkPPSPeriodicTimer ran out, send a new request */ - if (evt & PDB_EVT_PE_PPS_REQUEST) { - /* Tell the protocol layer we're starting an AMS */ - ProtocolTransmit::notify( - ProtocolTransmit::Notifications::PDB_EVT_PRLTX_START_AMS); - return PESinkSelectCap; - } - /* If we received a message */ if (evt & PDB_EVT_PE_MSG_RX) { if (messageWaiting()) { @@ -717,14 +695,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_source_unresponsive() { return PESinkSourceUnresponsive; } -void PolicyEngine::PPSTimerCallBack() { - notify(PDB_EVT_PE_PPS_REQUEST); -} - -bool PolicyEngine::pdHasNegotiated() { - return pdNegotiationComplete; -} - uint32_t PolicyEngine::waitForEvent(uint32_t mask, uint32_t ticksToWait) { return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait); @@ -735,8 +705,3 @@ bool PolicyEngine::isPD3_0() { return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0; } -void PolicyEngine::start_pps_timer() { -} - -void PolicyEngine::stop_pps_timer() { -} diff --git a/workspace/TS100/Core/Drivers/FUSB302/policy_engine.h b/workspace/TS100/Core/Drivers/FUSB302/policy_engine.h index 833d368f..4aef4b0e 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/policy_engine.h +++ b/workspace/TS100/Core/Drivers/FUSB302/policy_engine.h @@ -31,7 +31,6 @@ #define PDB_EVT_PE_TX_ERR EVENT_MASK(3) #define PDB_EVT_PE_HARD_SENT EVENT_MASK(4) #define PDB_EVT_PE_I_OVRTEMP EVENT_MASK(5) -#define PDB_EVT_PE_PPS_REQUEST EVENT_MASK(6) #define PDB_EVT_PE_MSG_RX_PEND EVENT_MASK(7) /* Never SEND THIS DIRECTLY*/ class PolicyEngine { @@ -44,10 +43,19 @@ public: static void notify(uint32_t notification); //Returns true if headers indicate PD3.0 compliant static bool isPD3_0(); - - static void PPSTimerCallBack(); + static bool setupCompleteOrTimedOut() { + if (pdNegotiationComplete) + return true; + if (state == policy_engine_state::PESinkSourceUnresponsive) + return true; + if (state == policy_engine_state::PESinkReady) + return true; + return false; + } //Has pd negotiation completed - static bool pdHasNegotiated(); + static bool pdHasNegotiated() { + return pdNegotiationComplete; + } private: static bool pdNegotiationComplete; static int current_voltage_mv; //The current voltage PD is expecting @@ -125,8 +133,6 @@ private: static bool messageWaiting(); //Read a pending message into the temp message static bool readMessage(); - static void start_pps_timer(); - static void stop_pps_timer(); // These callbacks are called to implement the logic for the iron to select the desired voltage diff --git a/workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp b/workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp index a79b124f..8464e06d 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp +++ b/workspace/TS100/Core/Drivers/FUSB302/policy_engine_user.cpp @@ -84,7 +84,7 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability( PD_RDO_FV_MAX_CURRENT_SET( current) | PD_RDO_FV_CURRENT_SET(current) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(i + 1); - + //We support usb comms (ish) request->obj[0] |= PD_RDO_USB_COMMS; /* Update requested voltage */ @@ -94,69 +94,10 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability( } } } -#if 0 - /* If we have a PPS APDO, our desired V lies within its range, and - * its I is at least our desired I */ - if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED - && (capabilities->obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) { - int min_mv = PD_PAV2MV( - PD_APDO_PPS_MIN_VOLTAGE_GET(capabilities->obj[i])); - int max_mv = PD_PAV2MV( - PD_APDO_PPS_MAX_VOLTAGE_GET(capabilities->obj[i])); - int current = PD_CA2PAI( - PD_APDO_PPS_CURRENT_GET(capabilities->obj[i])); - /* We got what we wanted, so build a request for that */ -// -// request->hdr = hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1); -// -// /* Build a request */ -// request->obj[0] = -// PD_RDO_PROG_CURRENT_SET( -// PD_CA2PAI(current)) | PD_RDO_PROG_VOLTAGE_SET(PD_MV2PRV(voltage)) -// | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(i + 1); -// -// request->obj[0] |= PD_RDO_USB_COMMS; -// -// /* Update requested voltage */ -// _requested_voltage = PD_PRV2MV(PD_MV2PRV(voltage)); -// -// return true; - } -#endif + } } - /* If there's a PDO in the voltage range, use it */ -// int8_t i = dpm_get_range_fixed_pdo_index(caps, scfg); -// if (i >= 0) { -// /* We got what we wanted, so build a request for that */ -// request->hdr = hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1); -// /* Get the current we need at this voltage */ -// current = dpm_get_current(scfg, -// PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(caps->obj[i]))); -// if (scfg->flags & PDBS_CONFIG_FLAGS_GIVEBACK) { -// /* GiveBack enabled */ -// request->obj[0] = -// PD_RDO_FV_MIN_CURRENT_SET( -// DPM_MIN_CURRENT) | PD_RDO_FV_CURRENT_SET(current) | PD_RDO_NO_USB_SUSPEND -// | PD_RDO_GIVEBACK | PD_RDO_OBJPOS_SET(i + 1); -// } else { -// /* GiveBack disabled */ -// request->obj[0] = -// PD_RDO_FV_MAX_CURRENT_SET( -// current) | PD_RDO_FV_CURRENT_SET(current) | PD_RDO_NO_USB_SUSPEND -// | PD_RDO_OBJPOS_SET(i + 1); -// } -// if (usb_comms) { -// request->obj[0] |= PD_RDO_USB_COMMS; -// } -// -// /* Update requested voltage */ -// _requested_voltage = PD_PDV2MV( -// PD_PDO_SRC_FIXED_VOLTAGE_GET(caps->obj[i])); -// -// _capability_match = true; -// return true; -// } + /* Nothing matched (or no configuration), so get 5 V at low current */ request->hdr = hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1); request->obj[0] = @@ -168,7 +109,6 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability( if (pdNegotiationComplete) { request->obj[0] |= PD_RDO_CAP_MISMATCH; } - /* If we can do USB communications, tell the power supply */ request->obj[0] |= PD_RDO_USB_COMMS; /* Update requested voltage */ @@ -191,8 +131,8 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) { PD_MV2PDV(5000)) | PD_PDO_SNK_FIXED_CURRENT_SET(DPM_MIN_CURRENT); /* Get the current we want */ - uint16_t current = 100; // In centi-amps - uint16_t voltage = 9000; // in mv + uint16_t current = USB_PD_Desired_Levels[1] / 10; // In centi-amps + uint16_t voltage = USB_PD_Desired_Levels[0]; // in mv /* Add a PDO for the desired power. */ cap->obj[numobj++] = PD_PDO_TYPE_FIXED | PD_PDO_SNK_FIXED_VOLTAGE_SET( @@ -233,15 +173,6 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) { } } - /* If we're using PD 3.0, add a PPS APDO for our desired voltage */ - if (isPD3_0()) { - cap->obj[numobj++] = - PD_PDO_TYPE_AUGMENTED | PD_APDO_TYPE_PPS - | PD_APDO_PPS_MAX_VOLTAGE_SET( - PD_MV2PAV(voltage)) | PD_APDO_PPS_MIN_VOLTAGE_SET(PD_MV2PAV(voltage)) - | PD_APDO_PPS_CURRENT_SET(PD_CA2PAI(current)); - } - /* Set the unconstrained power flag. */ if (_unconstrained_power) { cap->obj[0] |= PD_PDO_SNK_FIXED_UNCONSTRAINED; @@ -259,6 +190,7 @@ bool PolicyEngine::pdbs_dpm_evaluate_typec_current( /* We don't control the voltage anymore; it will always be 5 V. */ current_voltage_mv = _requested_voltage = 5000; //For the soldering iron we accept this as a fallback, but it sucks + pdNegotiationComplete = false; return true; }