Better messages flowing
This commit is contained in:
@@ -42,7 +42,9 @@ static uint8_t fusb_read_byte(uint8_t addr) {
|
||||
* buf: The buffer into which data will be read
|
||||
*/
|
||||
static void fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
|
||||
I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) buf, size);
|
||||
if(!I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) buf, size)){
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +56,9 @@ static void fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
|
||||
* byte: The value to write
|
||||
*/
|
||||
static void fusb_write_byte(uint8_t addr, uint8_t byte) {
|
||||
I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &byte, 1);
|
||||
if(!I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &byte, 1)){
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +71,9 @@ static void fusb_write_byte(uint8_t addr, uint8_t byte) {
|
||||
* buf: The buffer to write
|
||||
*/
|
||||
static void fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) {
|
||||
I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &buf, size);
|
||||
if(!I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &buf, size)){
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ uint8_t fusb302_detect() {
|
||||
}
|
||||
|
||||
void fusb302_start_processing() {
|
||||
|
||||
HAL_Delay(30);
|
||||
/* Initialize the FUSB302B */
|
||||
fusb_setup();
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ void ResetHandler::init() {
|
||||
|
||||
void ResetHandler::notify(uint32_t notification) {
|
||||
xTaskNotify(TaskHandle, notification,
|
||||
eNotifyAction::eSetValueWithOverwrite);
|
||||
eNotifyAction::eSetBits);
|
||||
}
|
||||
|
||||
void ResetHandler::Thread(const void *arg) {
|
||||
|
||||
@@ -278,15 +278,13 @@
|
||||
#define PD_T_PS_TRANSITION (500)
|
||||
#define PD_T_SENDER_RESPONSE (27)
|
||||
#define PD_T_SINK_REQUEST (100)
|
||||
#define PD_T_TYPEC_SINK_WAIT_CAP (465)
|
||||
#define PD_T_PPS_REQUEST TIME_S2I(10)
|
||||
/* This is actually from Type-C, not Power Delivery, but who cares? */
|
||||
#define PD_T_TYPEC_SINK_WAIT_CAP (465+100)
|
||||
#define PD_T_PD_DEBOUNCE (15)
|
||||
|
||||
/*
|
||||
* Counter maximums
|
||||
*/
|
||||
#define PD_N_HARD_RESET_COUNT 2
|
||||
#define PD_N_HARD_RESET_COUNT 10
|
||||
|
||||
/*
|
||||
* Value parameters
|
||||
|
||||
@@ -22,21 +22,6 @@
|
||||
/* Number of messages in the message pool */
|
||||
#define PDB_MSG_POOL_SIZE 4
|
||||
|
||||
/* Size of the Policy Engine thread's working area */
|
||||
#define PDB_PE_WA_SIZE 256
|
||||
|
||||
/* Size of the protocol layer RX thread's working area */
|
||||
#define PDB_PRLRX_WA_SIZE 256
|
||||
|
||||
/* Size of the protocol layer TX thread's working area */
|
||||
#define PDB_PRLTX_WA_SIZE 256
|
||||
|
||||
/* Size of the protocol layer hard reset thread's working area */
|
||||
#define PDB_HARDRST_WA_SIZE 256
|
||||
|
||||
/* Size of the INT_N thread's working area */
|
||||
#define PDB_INT_N_WA_SIZE 128
|
||||
|
||||
#define EVENT_MASK(x) (1<<x)
|
||||
#define eventmask_t uint32_t
|
||||
/* PD Buddy thread priorities */
|
||||
|
||||
@@ -55,7 +55,7 @@ void PolicyEngine::init() {
|
||||
|
||||
void PolicyEngine::notify(uint32_t notification) {
|
||||
xTaskNotify(TaskHandle, notification,
|
||||
eNotifyAction::eSetValueWithOverwrite);
|
||||
eNotifyAction::eSetBits);
|
||||
}
|
||||
|
||||
void PolicyEngine::pe_task(const void *arg) {
|
||||
|
||||
@@ -81,6 +81,7 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability(
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#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
|
||||
@@ -108,6 +109,7 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability(
|
||||
//
|
||||
// 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);
|
||||
|
||||
@@ -34,10 +34,12 @@ uint8_t ProtocolReceive::_tx_messageidcounter;
|
||||
*/
|
||||
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
||||
/* Wait for an event */
|
||||
_rx_messageid = 0;
|
||||
eventmask_t evt = waitForEvent(0xFFFFFFFF);
|
||||
|
||||
/* If we got a reset event, reset */
|
||||
if (evt & PDB_EVT_PRLRX_RESET) {
|
||||
waitForEvent(PDB_EVT_PRLRX_RESET, 0);
|
||||
return PRLRxWaitPHY;
|
||||
}
|
||||
/* If we got an I_GCRCSENT event, read the message and decide what to do */
|
||||
@@ -75,7 +77,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
|
||||
taskYIELD();
|
||||
|
||||
/* If we got a RESET signal, reset the machine */
|
||||
if (waitForEvent(PDB_EVT_PRLRX_RESET) != 0) {
|
||||
if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) != 0) {
|
||||
return PRLRxWaitPHY;
|
||||
}
|
||||
|
||||
@@ -88,17 +90,16 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
|
||||
*/
|
||||
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid() {
|
||||
/* If we got a RESET signal, reset the machine */
|
||||
if (waitForEvent(PDB_EVT_PRLRX_RESET) != 0) {
|
||||
|
||||
if (waitForEvent(PDB_EVT_PRLRX_RESET, 0) == PDB_EVT_PRLRX_RESET) {
|
||||
return PRLRxWaitPHY;
|
||||
}
|
||||
|
||||
/* If the message has the stored ID, we've seen this message before. Free
|
||||
* it and don't pass it to the policy engine. */
|
||||
|
||||
/* Otherwise, there's either no stored ID or this message has an ID we
|
||||
* haven't just seen. Transition to the Store_MessageID state. */
|
||||
if (PD_MESSAGEID_GET(&tempMessage) == _rx_messageid) {
|
||||
return PRLRxWaitPHY;
|
||||
/* Otherwise, there's either no stored ID or this message has an ID we
|
||||
* haven't just seen. Transition to the Store_MessageID state. */
|
||||
} else {
|
||||
return PRLRxStoreMessageID;
|
||||
}
|
||||
@@ -160,12 +161,11 @@ void ProtocolReceive::thread(const void *args) {
|
||||
}
|
||||
|
||||
void ProtocolReceive::notify(uint32_t notification) {
|
||||
xTaskNotify(TaskHandle, notification,
|
||||
eNotifyAction::eSetValueWithOverwrite);
|
||||
xTaskNotify(TaskHandle, notification, eNotifyAction::eSetBits);
|
||||
}
|
||||
|
||||
uint32_t ProtocolReceive::waitForEvent(uint32_t mask, uint32_t ticksToWait) {
|
||||
uint32_t pulNotificationValue;
|
||||
xTaskNotifyWait(0x00, mask, &pulNotificationValue, ticksToWait);
|
||||
return pulNotificationValue;
|
||||
return pulNotificationValue & mask;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,9 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_phy_reset() {
|
||||
/* Tell the policy engine that we failed */
|
||||
PolicyEngine::notify( PDB_EVT_PE_TX_ERR);
|
||||
/* Finish failing to send the message */
|
||||
getMessage(); //Discard
|
||||
while (messagePending()) {
|
||||
getMessage(); //Discard
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for a message request */
|
||||
@@ -103,7 +105,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_reset() {
|
||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_message() {
|
||||
/* Make sure nobody wants us to reset */
|
||||
eventmask_t evt = waitForEvent(
|
||||
PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD);
|
||||
PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD, 0);
|
||||
|
||||
if (evt & PDB_EVT_PRLTX_RESET) {
|
||||
return PRLTxPHYReset;
|
||||
@@ -119,7 +121,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_mess
|
||||
/* PD 3.0 collision avoidance */
|
||||
if (PolicyEngine::isPD3_0()) {
|
||||
/* If we're starting an AMS, wait for permission to transmit */
|
||||
evt = waitForEvent(PDB_EVT_PRLTX_START_AMS);
|
||||
evt = waitForEvent(PDB_EVT_PRLTX_START_AMS, 0);
|
||||
if (evt & PDB_EVT_PRLTX_START_AMS) {
|
||||
while (fusb_get_typec_current() != fusb_sink_tx_ok) {
|
||||
osDelay(1);
|
||||
@@ -253,14 +255,14 @@ void ProtocolTransmit::thread(const void *args) {
|
||||
|
||||
void ProtocolTransmit::notify(uint32_t notification) {
|
||||
xTaskNotify(TaskHandle, notification,
|
||||
eNotifyAction::eSetValueWithOverwrite);
|
||||
eNotifyAction::eSetBits);
|
||||
}
|
||||
|
||||
void ProtocolTransmit::init() {
|
||||
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
|
||||
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
||||
|
||||
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize,
|
||||
osThreadStaticDef(pd_txTask, thread,osPriorityAboveNormal, 0, TaskStackSize,
|
||||
TaskBuffer, &TaskControlBlock);
|
||||
TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user