mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Using enum for PE events
This commit is contained in:
@@ -63,7 +63,7 @@ void InterruptHandler::Thread(const void *arg) {
|
|||||||
/* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy
|
/* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy
|
||||||
* Engine thread */
|
* Engine thread */
|
||||||
if ((status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP) && (status.status1 & FUSB_STATUS1_OVRTEMP)) {
|
if ((status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP) && (status.status1 & FUSB_STATUS1_OVRTEMP)) {
|
||||||
PolicyEngine::notify(PDB_EVT_PE_I_OVRTEMP);
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_PE_I_OVRTEMP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,10 @@ void PolicyEngine::init() {
|
|||||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolicyEngine::notify(uint32_t notification) {
|
void PolicyEngine::notify(PolicyEngine::Notifications notification) {
|
||||||
|
uint32_t val = (uint32_t)notification;
|
||||||
if (xEventGroupHandle != NULL) {
|
if (xEventGroupHandle != NULL) {
|
||||||
xEventGroupSetBits(xEventGroupHandle, notification);
|
xEventGroupSetBits(xEventGroupHandle, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,9 +157,9 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
|
|||||||
/* Fetch a message from the protocol layer */
|
/* Fetch a message from the protocol layer */
|
||||||
eventmask_t evt = 0;
|
eventmask_t evt = 0;
|
||||||
if (readMessage()) {
|
if (readMessage()) {
|
||||||
evt = PDB_EVT_PE_MSG_RX_PEND;
|
evt = (uint32_t)Notifications::PDB_EVT_PE_MSG_RX_PEND;
|
||||||
} else {
|
} else {
|
||||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET,
|
evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_MSG_RX | (uint32_t)Notifications::PDB_EVT_PE_I_OVRTEMP | (uint32_t)Notifications::PDB_EVT_PE_RESET,
|
||||||
// Wait for cap timeout
|
// Wait for cap timeout
|
||||||
PD_T_TYPEC_SINK_WAIT_CAP);
|
PD_T_TYPEC_SINK_WAIT_CAP);
|
||||||
}
|
}
|
||||||
@@ -167,18 +168,18 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
|
|||||||
return PESinkHardReset;
|
return PESinkHardReset;
|
||||||
}
|
}
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkWaitCap;
|
return PESinkWaitCap;
|
||||||
}
|
}
|
||||||
/* If we're too hot, we shouldn't negotiate power yet */
|
/* If we're too hot, we shouldn't negotiate power yet */
|
||||||
if (evt & PDB_EVT_PE_I_OVRTEMP) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_I_OVRTEMP) {
|
||||||
return PESinkWaitCap;
|
return PESinkWaitCap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we got a message */
|
/* If we got a message */
|
||||||
if (evt & (PDB_EVT_PE_MSG_RX | PDB_EVT_PE_MSG_RX_PEND)) {
|
if (evt & ((uint32_t)Notifications::PDB_EVT_PE_MSG_RX | (uint32_t)Notifications::PDB_EVT_PE_MSG_RX_PEND)) {
|
||||||
/* Get the message */
|
/* Get the message */
|
||||||
while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) {
|
while ((evt & (uint32_t)Notifications::PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) {
|
||||||
/* If we got a Source_Capabilities message, read it. */
|
/* If we got a Source_Capabilities message, read it. */
|
||||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||||
/* First, determine what PD revision we're using */
|
/* First, determine what PD revision we're using */
|
||||||
@@ -249,20 +250,20 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
|||||||
ProtocolTransmit::pushMessage(&_last_dpm_request);
|
ProtocolTransmit::pushMessage(&_last_dpm_request);
|
||||||
// Send indication that there is a message pending
|
// Send indication that there is a message pending
|
||||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
eventmask_t evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_TX_DONE | (uint32_t)Notifications::PDB_EVT_PE_TX_ERR | (uint32_t)Notifications::PDB_EVT_PE_RESET);
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET || evt == 0) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET || evt == 0) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If the message transmission failed, send a hard reset */
|
/* If the message transmission failed, send a hard reset */
|
||||||
if ((evt & PDB_EVT_PE_TX_ERR) == PDB_EVT_PE_TX_ERR) {
|
if ((evt & (uint32_t)Notifications::PDB_EVT_PE_TX_ERR) == (uint32_t)Notifications::PDB_EVT_PE_TX_ERR) {
|
||||||
return PESinkHardReset;
|
return PESinkHardReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for a response */
|
/* Wait for a response */
|
||||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE);
|
evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_MSG_RX | (uint32_t)Notifications::PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE);
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If we didn't get a response before the timeout, send a hard reset */
|
/* If we didn't get a response before the timeout, send a hard reset */
|
||||||
@@ -289,7 +290,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
|||||||
return PESinkReady;
|
return PESinkReady;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return PESinkSelectCap;
|
return PESinkSoftReset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PESinkHardReset;
|
return PESinkHardReset;
|
||||||
@@ -297,9 +298,9 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
|||||||
|
|
||||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
|
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
|
||||||
/* Wait for the PS_RDY message */
|
/* Wait for the PS_RDY message */
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_PS_TRANSITION);
|
eventmask_t evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_MSG_RX | (uint32_t)Notifications::PDB_EVT_PE_RESET, PD_T_PS_TRANSITION);
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If no message was received, send a hard reset */
|
/* If no message was received, send a hard reset */
|
||||||
@@ -333,35 +334,36 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
|||||||
eventmask_t evt;
|
eventmask_t evt;
|
||||||
|
|
||||||
/* Wait for an event */
|
/* Wait for an event */
|
||||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_GET_SOURCE_CAP | PDB_EVT_PE_NEW_POWER | PDB_EVT_PE_PPS_REQUEST);
|
evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_MSG_RX | (uint32_t)Notifications::PDB_EVT_PE_RESET | (uint32_t)Notifications::PDB_EVT_PE_I_OVRTEMP
|
||||||
|
| (uint32_t)Notifications::PDB_EVT_PE_GET_SOURCE_CAP | (uint32_t)Notifications::PDB_EVT_PE_NEW_POWER | (uint32_t)Notifications::PDB_EVT_PE_PPS_REQUEST);
|
||||||
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we overheated, send a hard reset */
|
/* If we overheated, send a hard reset */
|
||||||
if (evt & PDB_EVT_PE_I_OVRTEMP) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_I_OVRTEMP) {
|
||||||
return PESinkHardReset;
|
return PESinkHardReset;
|
||||||
}
|
}
|
||||||
/* If the DPM wants us to, send a Get_Source_Cap message */
|
/* If the DPM wants us to, send a Get_Source_Cap message */
|
||||||
if (evt & PDB_EVT_PE_GET_SOURCE_CAP) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_GET_SOURCE_CAP) {
|
||||||
return PESinkGetSourceCap;
|
return PESinkGetSourceCap;
|
||||||
}
|
}
|
||||||
/* If the DPM wants new power, let it figure out what power it wants
|
/* If the DPM wants new power, let it figure out what power it wants
|
||||||
* exactly. This isn't exactly the transition from the spec (that would be
|
* exactly. This isn't exactly the transition from the spec (that would be
|
||||||
* SelectCap, not EvalCap), but this works better with the particular
|
* SelectCap, not EvalCap), but this works better with the particular
|
||||||
* design of this firmware. */
|
* design of this firmware. */
|
||||||
if (evt & PDB_EVT_PE_NEW_POWER) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_NEW_POWER) {
|
||||||
/* Tell the protocol layer we're starting an AMS */
|
/* Tell the protocol layer we're starting an AMS */
|
||||||
return PESinkEvalCap;
|
return PESinkEvalCap;
|
||||||
}
|
}
|
||||||
/* If SinkPPSPeriodicTimer ran out, send a new request */
|
/* If SinkPPSPeriodicTimer ran out, send a new request */
|
||||||
if (evt & PDB_EVT_PE_PPS_REQUEST) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_PPS_REQUEST) {
|
||||||
return PESinkSelectCap;
|
return PESinkSelectCap;
|
||||||
}
|
}
|
||||||
/* If we received a message */
|
/* If we received a message */
|
||||||
if (evt & PDB_EVT_PE_MSG_RX) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_MSG_RX) {
|
||||||
if (messageWaiting()) {
|
if (messageWaiting()) {
|
||||||
readMessage();
|
readMessage();
|
||||||
/* Ignore vendor-defined messages */
|
/* Ignore vendor-defined messages */
|
||||||
@@ -435,14 +437,14 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_get_source_cap() {
|
|||||||
/* Transmit the Get_Source_Cap */
|
/* Transmit the Get_Source_Cap */
|
||||||
ProtocolTransmit::pushMessage(get_source_cap);
|
ProtocolTransmit::pushMessage(get_source_cap);
|
||||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
eventmask_t evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_TX_DONE | (uint32_t)Notifications::PDB_EVT_PE_TX_ERR | (uint32_t)Notifications::PDB_EVT_PE_RESET);
|
||||||
/* Free the sent message */
|
/* Free the sent message */
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If the message transmission failed, send a hard reset */
|
/* If the message transmission failed, send a hard reset */
|
||||||
if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
|
if ((evt & (uint32_t)Notifications::PDB_EVT_PE_TX_DONE) == 0) {
|
||||||
return PESinkHardReset;
|
return PESinkHardReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,16 +460,16 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_give_sink_cap() {
|
|||||||
/* Transmit our capabilities */
|
/* Transmit our capabilities */
|
||||||
ProtocolTransmit::pushMessage(snk_cap);
|
ProtocolTransmit::pushMessage(snk_cap);
|
||||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
eventmask_t evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_TX_DONE | (uint32_t)Notifications::PDB_EVT_PE_TX_ERR | (uint32_t)Notifications::PDB_EVT_PE_RESET);
|
||||||
|
|
||||||
/* Free the Sink_Capabilities message */
|
/* Free the Sink_Capabilities message */
|
||||||
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If the message transmission failed, send a hard reset */
|
/* If the message transmission failed, send a hard reset */
|
||||||
if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
|
if ((evt & (uint32_t)Notifications::PDB_EVT_PE_TX_DONE) == 0) {
|
||||||
return PESinkHardReset;
|
return PESinkHardReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,15 +514,15 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_soft_reset() {
|
|||||||
/* Transmit the Accept */
|
/* Transmit the Accept */
|
||||||
ProtocolTransmit::pushMessage(&accept);
|
ProtocolTransmit::pushMessage(&accept);
|
||||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
eventmask_t evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_TX_DONE | (uint32_t)Notifications::PDB_EVT_PE_TX_ERR | (uint32_t)Notifications::PDB_EVT_PE_RESET);
|
||||||
/* Free the sent message */
|
/* Free the sent message */
|
||||||
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If the message transmission failed, send a hard reset */
|
/* If the message transmission failed, send a hard reset */
|
||||||
if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
|
if ((evt & (uint32_t)Notifications::PDB_EVT_PE_TX_DONE) == 0) {
|
||||||
return PESinkHardReset;
|
return PESinkHardReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,20 +540,20 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
|
|||||||
/* Transmit the soft reset */
|
/* Transmit the soft reset */
|
||||||
ProtocolTransmit::pushMessage(softrst);
|
ProtocolTransmit::pushMessage(softrst);
|
||||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
eventmask_t evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_TX_DONE | (uint32_t)Notifications::PDB_EVT_PE_TX_ERR | (uint32_t)Notifications::PDB_EVT_PE_RESET);
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If the message transmission failed, send a hard reset */
|
/* If the message transmission failed, send a hard reset */
|
||||||
if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
|
if ((evt & (uint32_t)Notifications::PDB_EVT_PE_TX_DONE) == 0) {
|
||||||
return PESinkHardReset;
|
return PESinkHardReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for a response */
|
/* Wait for a response */
|
||||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE);
|
evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_MSG_RX | (uint32_t)Notifications::PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE);
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If we didn't get a response before the timeout, send a hard reset */
|
/* If we didn't get a response before the timeout, send a hard reset */
|
||||||
@@ -594,14 +596,14 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() {
|
|||||||
/* Transmit the message */
|
/* Transmit the message */
|
||||||
ProtocolTransmit::pushMessage(not_supported);
|
ProtocolTransmit::pushMessage(not_supported);
|
||||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
eventmask_t evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_TX_DONE | (uint32_t)Notifications::PDB_EVT_PE_TX_ERR | (uint32_t)Notifications::PDB_EVT_PE_RESET);
|
||||||
|
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
/* If the message transmission failed, send a soft reset */
|
/* If the message transmission failed, send a soft reset */
|
||||||
if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
|
if ((evt & (uint32_t)Notifications::PDB_EVT_PE_TX_DONE) == 0) {
|
||||||
return PESinkSendSoftReset;
|
return PESinkSendSoftReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,9 +613,9 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() {
|
|||||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_chunk_received() {
|
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_chunk_received() {
|
||||||
|
|
||||||
/* Wait for tChunkingNotSupported */
|
/* Wait for tChunkingNotSupported */
|
||||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET, PD_T_CHUNKING_NOT_SUPPORTED);
|
eventmask_t evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PE_RESET, PD_T_CHUNKING_NOT_SUPPORTED);
|
||||||
/* If we got reset signaling, transition to default */
|
/* If we got reset signaling, transition to default */
|
||||||
if (evt & PDB_EVT_PE_RESET) {
|
if (evt & (uint32_t)Notifications::PDB_EVT_PE_RESET) {
|
||||||
return PESinkTransitionDefault;
|
return PESinkTransitionDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,7 +648,7 @@ void PolicyEngine::PPSTimerCallback() {
|
|||||||
if (xTaskGetTickCount() - PPSTimeLastEvent > 3 * TICKS_100MS) {
|
if (xTaskGetTickCount() - PPSTimeLastEvent > 3 * TICKS_100MS) {
|
||||||
// Send a new PPS message
|
// Send a new PPS message
|
||||||
PPSTimeLastEvent = xTaskGetTickCount();
|
PPSTimeLastEvent = xTaskGetTickCount();
|
||||||
notify(PDB_EVT_PE_PPS_REQUEST);
|
notify(Notifications::PDB_EVT_PE_PPS_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,25 +25,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PDB_EVT_PE_RESET EVENT_MASK(0)
|
|
||||||
#define PDB_EVT_PE_MSG_RX EVENT_MASK(1)
|
|
||||||
#define PDB_EVT_PE_TX_DONE EVENT_MASK(2)
|
|
||||||
#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*/
|
|
||||||
#define PDB_EVT_PE_GET_SOURCE_CAP EVENT_MASK(8)
|
|
||||||
#define PDB_EVT_PE_NEW_POWER EVENT_MASK(9)
|
|
||||||
#define PDB_EVT_PE_ALL (EVENT_MASK(9) - 1)
|
|
||||||
class PolicyEngine {
|
class PolicyEngine {
|
||||||
public:
|
public:
|
||||||
// Sets up internal state and registers the thread
|
// Sets up internal state and registers the thread
|
||||||
static void init();
|
static void init();
|
||||||
// Push an incoming message to the Policy Engine
|
// Push an incoming message to the Policy Engine
|
||||||
static void handleMessage(union pd_msg *msg);
|
static void handleMessage(union pd_msg *msg);
|
||||||
// Send a notification
|
|
||||||
static void notify(uint32_t notification);
|
|
||||||
// Returns true if headers indicate PD3.0 compliant
|
// Returns true if headers indicate PD3.0 compliant
|
||||||
static bool isPD3_0();
|
static bool isPD3_0();
|
||||||
static bool setupCompleteOrTimedOut() {
|
static bool setupCompleteOrTimedOut() {
|
||||||
@@ -57,9 +44,26 @@ public:
|
|||||||
}
|
}
|
||||||
// Has pd negotiation completed
|
// Has pd negotiation completed
|
||||||
static bool pdHasNegotiated() { return pdNegotiationComplete; }
|
static bool pdHasNegotiated() { return pdNegotiationComplete; }
|
||||||
|
// Call this periodically, at least once every second
|
||||||
static void PPSTimerCallback();
|
static void PPSTimerCallback();
|
||||||
|
|
||||||
|
enum class Notifications {
|
||||||
|
PDB_EVT_PE_RESET = EVENT_MASK(0),
|
||||||
|
PDB_EVT_PE_MSG_RX = EVENT_MASK(1),
|
||||||
|
PDB_EVT_PE_TX_DONE = EVENT_MASK(2),
|
||||||
|
PDB_EVT_PE_TX_ERR = EVENT_MASK(3),
|
||||||
|
PDB_EVT_PE_HARD_SENT = EVENT_MASK(4),
|
||||||
|
PDB_EVT_PE_I_OVRTEMP = EVENT_MASK(5),
|
||||||
|
PDB_EVT_PE_PPS_REQUEST = EVENT_MASK(6),
|
||||||
|
PDB_EVT_PE_MSG_RX_PEND = EVENT_MASK(7), /* Never send this from user area*/
|
||||||
|
PDB_EVT_PE_GET_SOURCE_CAP = EVENT_MASK(8),
|
||||||
|
PDB_EVT_PE_NEW_POWER = EVENT_MASK(9),
|
||||||
|
PDB_EVT_PE_ALL = (PDB_EVT_PE_NEW_POWER - 1),
|
||||||
|
|
||||||
|
};
|
||||||
|
// Send a notification
|
||||||
|
static void notify(Notifications notification);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool pdNegotiationComplete;
|
static bool pdNegotiationComplete;
|
||||||
static int current_voltage_mv; // The current voltage PD is expecting
|
static int current_voltage_mv; // The current voltage PD is expecting
|
||||||
|
|||||||
@@ -63,27 +63,28 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability(const union pd_msg *capabilities
|
|||||||
for (uint8_t i = 0; i < numobj; i++) {
|
for (uint8_t i = 0; i < numobj; i++) {
|
||||||
/* If we have a fixed PDO, its V equals our desired V, and its I is
|
/* If we have a fixed PDO, its V equals our desired V, and its I is
|
||||||
* at least our desired I */
|
* at least our desired I */
|
||||||
if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
|
// if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
|
||||||
// This is a fixed PDO entry
|
// // This is a fixed PDO entry
|
||||||
// Evaluate if it can produve sufficient current based on the tipResistance (ohms*10)
|
// // Evaluate if it can produve sufficient current based on the tipResistance (ohms*10)
|
||||||
// V=I*R -> V/I => minimum resistance, if our tip resistance is >= this then we can use this supply
|
// // V=I*R -> V/I => minimum resistance, if our tip resistance is >= this then we can use this supply
|
||||||
|
|
||||||
|
// int voltage_mv = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities->obj[i])); // voltage in mV units
|
||||||
|
// int current_a_x100 = PD_PDO_SRC_FIXED_CURRENT_GET(capabilities->obj[i]); // current in 10mA units
|
||||||
|
// int min_resistance_ohmsx10 = voltage_mv / current_a_x100;
|
||||||
|
// if (voltage_mv <= (USB_PD_VMAX * 1000)) {
|
||||||
|
// if (min_resistance_ohmsx10 <= tipResistance) {
|
||||||
|
// // This is a valid power source we can select as
|
||||||
|
// if (voltage_mv > bestIndexVoltage||bestIndex == 0xFF) {
|
||||||
|
// // Higher voltage and valid, select this instead
|
||||||
|
// bestIndex = i;
|
||||||
|
// bestIndexVoltage = voltage_mv;
|
||||||
|
// bestIndexCurrent = current_a_x100;
|
||||||
|
// bestIsPPS = false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else
|
||||||
|
|
||||||
int voltage_mv = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities->obj[i])); // voltage in mV units
|
|
||||||
int current_a_x100 = PD_PDO_SRC_FIXED_CURRENT_GET(capabilities->obj[i]); // current in 10mA units
|
|
||||||
int min_resistance_ohmsx10 = voltage_mv / current_a_x100;
|
|
||||||
if (min_resistance_ohmsx10 <= tipResistance) {
|
|
||||||
// This is a valid power source we can select as
|
|
||||||
if (bestIndex == 0xFF) {
|
|
||||||
// This is the first valid source, so select to be safe
|
|
||||||
bestIndex = i;
|
|
||||||
bestIndexVoltage = voltage_mv;
|
|
||||||
bestIndexCurrent = current_a_x100;
|
|
||||||
} else if (voltage_mv > bestIndexVoltage) {
|
|
||||||
// Higher voltage and valid, select this instead
|
|
||||||
bestIndex = i;
|
|
||||||
bestIndexVoltage = voltage_mv;
|
|
||||||
bestIndexCurrent = current_a_x100;
|
|
||||||
}
|
|
||||||
if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (capabilities->obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
|
if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (capabilities->obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
|
||||||
// If this is a PPS slot, calculate the max voltage in the PPS range that can we be used and maintain
|
// If this is a PPS slot, calculate the max voltage in the PPS range that can we be used and maintain
|
||||||
uint16_t max_voltage = PD_PAV2MV(PD_APDO_PPS_MAX_VOLTAGE_GET(capabilities->obj[i]));
|
uint16_t max_voltage = PD_PAV2MV(PD_APDO_PPS_MAX_VOLTAGE_GET(capabilities->obj[i]));
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid(
|
|||||||
/* Pass the message to the policy engine. */
|
/* Pass the message to the policy engine. */
|
||||||
|
|
||||||
PolicyEngine::handleMessage(&tempMessage);
|
PolicyEngine::handleMessage(&tempMessage);
|
||||||
PolicyEngine::notify(PDB_EVT_PE_MSG_RX);
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_PE_MSG_RX);
|
||||||
taskYIELD();
|
taskYIELD();
|
||||||
/* Don't check if we got a RESET because we'd do nothing different. */
|
/* Don't check if we got a RESET because we'd do nothing different. */
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_phy_reset() {
|
|||||||
* we failed to send it */
|
* we failed to send it */
|
||||||
if (messagePending()) {
|
if (messagePending()) {
|
||||||
/* Tell the policy engine that we failed */
|
/* Tell the policy engine that we failed */
|
||||||
PolicyEngine::notify(PDB_EVT_PE_TX_ERR);
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_PE_TX_ERR);
|
||||||
/* Finish failing to send the message */
|
/* Finish failing to send the message */
|
||||||
while (messagePending()) {
|
while (messagePending()) {
|
||||||
getMessage(); // Discard
|
getMessage(); // Discard
|
||||||
@@ -168,7 +168,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_transmission_e
|
|||||||
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
||||||
|
|
||||||
/* Tell the policy engine that we failed */
|
/* Tell the policy engine that we failed */
|
||||||
PolicyEngine::notify(PDB_EVT_PE_TX_ERR);
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_PE_TX_ERR);
|
||||||
|
|
||||||
return PRLTxWaitMessage;
|
return PRLTxWaitMessage;
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_message_sent()
|
|||||||
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
||||||
|
|
||||||
/* Tell the policy engine that we succeeded */
|
/* Tell the policy engine that we succeeded */
|
||||||
PolicyEngine::notify(PDB_EVT_PE_TX_DONE);
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_PE_TX_DONE);
|
||||||
|
|
||||||
return PRLTxWaitMessage;
|
return PRLTxWaitMessage;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user