Port from test env cleanups
This commit is contained in:
@@ -296,12 +296,12 @@ bool PolicyEngine::messageWaiting() {
|
|||||||
return uxQueueMessagesWaiting(messagesWaiting) > 0;
|
return uxQueueMessagesWaiting(messagesWaiting) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolicyEngine::readMessage() {
|
bool PolicyEngine::readMessage() {
|
||||||
xQueueReceive(messagesWaiting, &tempMessage, 1);
|
return xQueueReceive(messagesWaiting, &tempMessage, 1) == pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolicyEngine::pdbs_dpm_transition_typec() {
|
void PolicyEngine::pdbs_dpm_transition_typec() {
|
||||||
//This means PD failed, so we either have a dumb 5V only type C or a QC charger
|
//This means PD failed, so we either have a dump 5V only type C or a QC charger
|
||||||
//For now; treat this as failed neg
|
//For now; treat this as failed neg
|
||||||
pdNegotiationComplete = false;
|
pdNegotiationComplete = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "protocol_rx.h"
|
#include "protocol_rx.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "string.h"
|
||||||
#include <pd.h>
|
#include <pd.h>
|
||||||
#include "policy_engine.h"
|
#include "policy_engine.h"
|
||||||
#include "protocol_tx.h"
|
#include "protocol_tx.h"
|
||||||
@@ -36,7 +36,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
|||||||
/* Wait for an event */
|
/* Wait for an event */
|
||||||
_rx_messageid = 0;
|
_rx_messageid = 0;
|
||||||
eventmask_t evt = waitForEvent(
|
eventmask_t evt = waitForEvent(
|
||||||
PDB_EVT_PRLRX_RESET | PDB_EVT_PRLRX_I_GCRCSENT);
|
PDB_EVT_PRLRX_RESET | PDB_EVT_PRLRX_I_GCRCSENT | PDB_EVT_PRLRX_I_RXPEND);
|
||||||
|
|
||||||
/* If we got a reset event, reset */
|
/* If we got a reset event, reset */
|
||||||
if (evt & PDB_EVT_PRLRX_RESET) {
|
if (evt & PDB_EVT_PRLRX_RESET) {
|
||||||
@@ -48,6 +48,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
|||||||
/* Get a buffer to read the message into. Guaranteed to not fail
|
/* Get a buffer to read the message into. Guaranteed to not fail
|
||||||
* because we have a big enough pool and are careful. */
|
* because we have a big enough pool and are careful. */
|
||||||
union pd_msg *_rx_message = &tempMessage;
|
union pd_msg *_rx_message = &tempMessage;
|
||||||
|
memset(&tempMessage, 0, sizeof(tempMessage));
|
||||||
/* Read the message */
|
/* Read the message */
|
||||||
fusb_read_message(_rx_message);
|
fusb_read_message(_rx_message);
|
||||||
/* If it's a Soft_Reset, go to the soft reset state */
|
/* If it's a Soft_Reset, go to the soft reset state */
|
||||||
@@ -58,6 +59,12 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
|||||||
/* Otherwise, check the message ID */
|
/* Otherwise, check the message ID */
|
||||||
return PRLRxCheckMessageID;
|
return PRLRxCheckMessageID;
|
||||||
}
|
}
|
||||||
|
} else if (evt & PDB_EVT_PRLRX_I_RXPEND) {
|
||||||
|
//There is an RX message pending that is not a Good CRC
|
||||||
|
union pd_msg *_rx_message = &tempMessage;
|
||||||
|
/* Read the message */
|
||||||
|
fusb_read_message(_rx_message);
|
||||||
|
return PRLRxWaitPHY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PRLRxWaitPHY;
|
return PRLRxWaitPHY;
|
||||||
@@ -92,17 +99,18 @@ volatile uint32_t rxCounter = 0;
|
|||||||
*/
|
*/
|
||||||
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid() {
|
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid() {
|
||||||
/* If we got a RESET signal, reset the machine */
|
/* If we got a RESET signal, reset the machine */
|
||||||
if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) == PDB_EVT_PRLRX_RESET) {
|
// if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) == PDB_EVT_PRLRX_RESET) {
|
||||||
return PRLRxWaitPHY;
|
// return PRLRxWaitPHY;
|
||||||
}
|
// }
|
||||||
/* If the message has the stored ID, we've seen this message before. Free
|
/* If the message has the stored ID, we've seen this message before. Free
|
||||||
* it and don't pass it to the policy engine. */
|
* it and don't pass it to the policy engine. */
|
||||||
|
|
||||||
/* Otherwise, there's either no stored ID or this message has an ID we
|
/* Otherwise, there's either no stored ID or this message has an ID we
|
||||||
* haven't just seen. Transition to the Store_MessageID state. */
|
* haven't just seen. Transition to the Store_MessageID state. */
|
||||||
if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
|
// if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
|
||||||
return PRLRxWaitPHY;
|
// return PRLRxWaitPHY;
|
||||||
} else {
|
// } else
|
||||||
|
{
|
||||||
rxCounter++;
|
rxCounter++;
|
||||||
return PRLRxStoreMessageID;
|
return PRLRxStoreMessageID;
|
||||||
}
|
}
|
||||||
@@ -125,7 +133,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid(
|
|||||||
|
|
||||||
PolicyEngine::handleMessage(&tempMessage);
|
PolicyEngine::handleMessage(&tempMessage);
|
||||||
PolicyEngine::notify(PDB_EVT_PE_MSG_RX);
|
PolicyEngine::notify(PDB_EVT_PE_MSG_RX);
|
||||||
|
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. */
|
||||||
|
|
||||||
return PRLRxWaitPHY;
|
return PRLRxWaitPHY;
|
||||||
@@ -134,10 +142,10 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid(
|
|||||||
EventGroupHandle_t ProtocolReceive::xEventGroupHandle;
|
EventGroupHandle_t ProtocolReceive::xEventGroupHandle;
|
||||||
StaticEventGroup_t ProtocolReceive::xCreatedEventGroup;
|
StaticEventGroup_t ProtocolReceive::xCreatedEventGroup;
|
||||||
void ProtocolReceive::init() {
|
void ProtocolReceive::init() {
|
||||||
osThreadStaticDef(Task, thread, PDB_PRIO_PRL, 0, TaskStackSize, TaskBuffer,
|
osThreadStaticDef(protRX, thread, PDB_PRIO_PRL, 0, TaskStackSize,
|
||||||
&TaskControlBlock);
|
TaskBuffer, &TaskControlBlock);
|
||||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||||
TaskHandle = osThreadCreate(osThread(Task), NULL);
|
TaskHandle = osThreadCreate(osThread(protRX), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolReceive::thread(const void *args) {
|
void ProtocolReceive::thread(const void *args) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ osThreadId ProtocolTransmit::TaskHandle;
|
|||||||
uint32_t ProtocolTransmit::TaskBuffer[ProtocolTransmit::TaskStackSize];
|
uint32_t ProtocolTransmit::TaskBuffer[ProtocolTransmit::TaskStackSize];
|
||||||
osStaticThreadDef_t ProtocolTransmit::TaskControlBlock;
|
osStaticThreadDef_t ProtocolTransmit::TaskControlBlock;
|
||||||
StaticQueue_t ProtocolTransmit::xStaticQueue;
|
StaticQueue_t ProtocolTransmit::xStaticQueue;
|
||||||
|
bool ProtocolTransmit::messageSending = false;
|
||||||
uint8_t ProtocolTransmit::ucQueueStorageArea[PDB_MSG_POOL_SIZE
|
uint8_t ProtocolTransmit::ucQueueStorageArea[PDB_MSG_POOL_SIZE
|
||||||
* sizeof(union pd_msg)];
|
* sizeof(union pd_msg)];
|
||||||
QueueHandle_t ProtocolTransmit::messagesWaiting;
|
QueueHandle_t ProtocolTransmit::messagesWaiting;
|
||||||
@@ -67,9 +67,6 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message()
|
|||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
|
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
|
||||||
return PRLTxPHYReset;
|
return PRLTxPHYReset;
|
||||||
}
|
}
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD) {
|
|
||||||
return PRLTxDiscardMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the policy engine is trying to send a message */
|
/* If the policy engine is trying to send a message */
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX) {
|
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX) {
|
||||||
@@ -87,7 +84,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Silence the compiler warning */
|
/* Silence the compiler warning */
|
||||||
return PRLTxDiscardMessage;
|
return PRLTxWaitMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_reset() {
|
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_reset() {
|
||||||
@@ -105,35 +102,24 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_reset() {
|
|||||||
* PRL_Tx_Construct_Message state
|
* PRL_Tx_Construct_Message state
|
||||||
*/
|
*/
|
||||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_message() {
|
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_message() {
|
||||||
/* Make sure nobody wants us to reset */
|
ProtocolTransmit::Notifications evt;
|
||||||
ProtocolTransmit::Notifications evt = waitForEvent(
|
|
||||||
(uint32_t) Notifications::PDB_EVT_PRLTX_RESET
|
|
||||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD, 0);
|
|
||||||
|
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_RESET) {
|
|
||||||
return PRLTxPHYReset;
|
|
||||||
}
|
|
||||||
if ((uint32_t) evt & (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD) {
|
|
||||||
return PRLTxDiscardMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set the correct MessageID in the message */
|
/* Set the correct MessageID in the message */
|
||||||
temp_msg.hdr &= ~PD_HDR_MESSAGEID;
|
temp_msg.hdr &= ~PD_HDR_MESSAGEID;
|
||||||
temp_msg.hdr |= (_tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
|
temp_msg.hdr |= (_tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
|
||||||
|
|
||||||
/* PD 3.0 collision avoidance */
|
/* PD 3.0 collision avoidance */
|
||||||
if (PolicyEngine::isPD3_0()) {
|
// if (PolicyEngine::isPD3_0()) {
|
||||||
/* If we're starting an AMS, wait for permission to transmit */
|
// /* If we're starting an AMS, wait for permission to transmit */
|
||||||
evt = waitForEvent((uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS,
|
// evt = waitForEvent((uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS,
|
||||||
0);
|
// 0);
|
||||||
if ((uint32_t) evt
|
// if ((uint32_t) evt
|
||||||
& (uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS) {
|
// & (uint32_t) Notifications::PDB_EVT_PRLTX_START_AMS) {
|
||||||
while (fusb_get_typec_current() != fusb_sink_tx_ok) {
|
// while (fusb_get_typec_current() != fusb_sink_tx_ok) {
|
||||||
osDelay(1);
|
// osDelay(1);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
messageSending = true;
|
||||||
/* Send the message to the PHY */
|
/* Send the message to the PHY */
|
||||||
fusb_send_message(&temp_msg);
|
fusb_send_message(&temp_msg);
|
||||||
|
|
||||||
@@ -202,6 +188,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_transmission_e
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_message_sent() {
|
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_message_sent() {
|
||||||
|
messageSending = false;
|
||||||
/* Increment MessageIDCounter */
|
/* Increment MessageIDCounter */
|
||||||
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
||||||
|
|
||||||
@@ -213,11 +200,14 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_message_sent()
|
|||||||
|
|
||||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_discard_message() {
|
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_discard_message() {
|
||||||
/* If we were working on sending a message, increment MessageIDCounter */
|
/* If we were working on sending a message, increment MessageIDCounter */
|
||||||
|
if (messageSending) {
|
||||||
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
_tx_messageidcounter = (_tx_messageidcounter + 1) % 8;
|
||||||
|
|
||||||
return PRLTxPHYReset;
|
return PRLTxPHYReset;
|
||||||
|
} else {
|
||||||
|
return PRLTxWaitMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolTransmit::thread(const void *args) {
|
void ProtocolTransmit::thread(const void *args) {
|
||||||
(void) args;
|
(void) args;
|
||||||
ProtocolTransmit::protocol_tx_state state = PRLTxPHYReset;
|
ProtocolTransmit::protocol_tx_state state = PRLTxPHYReset;
|
||||||
@@ -270,7 +260,7 @@ void ProtocolTransmit::init() {
|
|||||||
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
|
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
|
||||||
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
||||||
|
|
||||||
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PE, 0, TaskStackSize,
|
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize,
|
||||||
TaskBuffer, &TaskControlBlock);
|
TaskBuffer, &TaskControlBlock);
|
||||||
TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
|
TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
|
||||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||||
|
|||||||
Reference in New Issue
Block a user