Formatting
This commit is contained in:
@@ -24,10 +24,8 @@
|
|||||||
void fusb_send_message(const union pd_msg *msg) {
|
void fusb_send_message(const union pd_msg *msg) {
|
||||||
|
|
||||||
/* Token sequences for the FUSB302B */
|
/* Token sequences for the FUSB302B */
|
||||||
static uint8_t sop_seq[5] = { FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1,
|
static uint8_t sop_seq[5] = {FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP2, FUSB_FIFO_TX_PACKSYM};
|
||||||
FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP2, FUSB_FIFO_TX_PACKSYM };
|
static const uint8_t eop_seq[4] = {FUSB_FIFO_TX_JAM_CRC, FUSB_FIFO_TX_EOP, FUSB_FIFO_TX_TXOFF, FUSB_FIFO_TX_TXON};
|
||||||
static const uint8_t eop_seq[4] = { FUSB_FIFO_TX_JAM_CRC, FUSB_FIFO_TX_EOP,
|
|
||||||
FUSB_FIFO_TX_TXOFF, FUSB_FIFO_TX_TXON };
|
|
||||||
|
|
||||||
/* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
|
/* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
|
||||||
/* Get the length of the message: a two-octet header plus NUMOBJ four-octet
|
/* Get the length of the message: a two-octet header plus NUMOBJ four-octet
|
||||||
@@ -43,10 +41,7 @@ void fusb_send_message(const union pd_msg *msg) {
|
|||||||
fusb_write_buf(FUSB_FIFOS, 4, eop_seq);
|
fusb_write_buf(FUSB_FIFOS, 4, eop_seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fusb_rx_pending() {
|
bool fusb_rx_pending() { return (fusb_read_byte(FUSB_STATUS1) & FUSB_STATUS1_RX_EMPTY) != FUSB_STATUS1_RX_EMPTY; }
|
||||||
return (fusb_read_byte( FUSB_STATUS1) & FUSB_STATUS1_RX_EMPTY)
|
|
||||||
!= FUSB_STATUS1_RX_EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t fusb_read_message(union pd_msg *msg) {
|
uint8_t fusb_read_message(union pd_msg *msg) {
|
||||||
|
|
||||||
@@ -55,12 +50,11 @@ uint8_t fusb_read_message(union pd_msg *msg) {
|
|||||||
|
|
||||||
// Read the header. If its not a SOP we dont actually want it at all
|
// Read the header. If its not a SOP we dont actually want it at all
|
||||||
// But on some revisions of the fusb if you dont both pick them up and read them out of the fifo, it gets stuck
|
// But on some revisions of the fusb if you dont both pick them up and read them out of the fifo, it gets stuck
|
||||||
if ((fusb_read_byte( FUSB_FIFOS) & FUSB_FIFO_RX_TOKEN_BITS)
|
if ((fusb_read_byte(FUSB_FIFOS) & FUSB_FIFO_RX_TOKEN_BITS) != FUSB_FIFO_RX_SOP) {
|
||||||
!= FUSB_FIFO_RX_SOP) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fusb_read_byte(FUSB_FIFOS);
|
// fusb_read_byte(FUSB_FIFOS);
|
||||||
/* Read the message header into msg */
|
/* Read the message header into msg */
|
||||||
fusb_read_buf(FUSB_FIFOS, 2, msg->bytes);
|
fusb_read_buf(FUSB_FIFOS, 2, msg->bytes);
|
||||||
/* Get the number of data objects */
|
/* Get the number of data objects */
|
||||||
@@ -144,8 +138,7 @@ bool fusb_get_status(union fusb_status *status) {
|
|||||||
enum fusb_typec_current fusb_get_typec_current() {
|
enum fusb_typec_current fusb_get_typec_current() {
|
||||||
|
|
||||||
/* Read the BC_LVL into a variable */
|
/* Read the BC_LVL into a variable */
|
||||||
enum fusb_typec_current bc_lvl = (enum fusb_typec_current) (fusb_read_byte(
|
enum fusb_typec_current bc_lvl = (enum fusb_typec_current)(fusb_read_byte(FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
|
||||||
FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
|
|
||||||
|
|
||||||
return bc_lvl;
|
return bc_lvl;
|
||||||
}
|
}
|
||||||
@@ -157,7 +150,7 @@ void fusb_reset() {
|
|||||||
/* Flush the RX buffer */
|
/* Flush the RX buffer */
|
||||||
fusb_write_byte(FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
|
fusb_write_byte(FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
|
||||||
/* Reset the PD logic */
|
/* Reset the PD logic */
|
||||||
fusb_write_byte( FUSB_RESET, FUSB_RESET_PD_RESET);
|
fusb_write_byte(FUSB_RESET, FUSB_RESET_PD_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fusb_read_id() {
|
bool fusb_read_id() {
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ union pd_msg InterruptHandler::tempMessage;
|
|||||||
|
|
||||||
void InterruptHandler::init() {
|
void InterruptHandler::init() {
|
||||||
TaskHandle = NULL;
|
TaskHandle = NULL;
|
||||||
osThreadStaticDef(intTask, Thread, PDB_PRIO_PRL_INT_N, 0, TaskStackSize,
|
osThreadStaticDef(intTask, Thread, PDB_PRIO_PRL_INT_N, 0, TaskStackSize, TaskBuffer, &TaskControlBlock);
|
||||||
TaskBuffer, &TaskControlBlock);
|
|
||||||
TaskHandle = osThreadCreate(osThread(intTask), NULL);
|
TaskHandle = osThreadCreate(osThread(intTask), NULL);
|
||||||
}
|
}
|
||||||
volatile uint32_t msgCounter = 0;
|
volatile uint32_t msgCounter = 0;
|
||||||
@@ -46,15 +45,12 @@ void InterruptHandler::readPendingMessage() {
|
|||||||
/* Read the message */
|
/* Read the message */
|
||||||
if (fusb_read_message(&tempMessage) == 0) {
|
if (fusb_read_message(&tempMessage) == 0) {
|
||||||
/* If it's a Soft_Reset, go to the soft reset state */
|
/* If it's a Soft_Reset, go to the soft reset state */
|
||||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
|
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
|
||||||
/* TX transitions to its reset state */
|
/* TX transitions to its reset state */
|
||||||
PolicyEngine::notify(
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_PE_RESET);
|
||||||
PolicyEngine::Notifications::PDB_EVT_PE_RESET);
|
|
||||||
} else {
|
} else {
|
||||||
/* Tell PolicyEngine to discard the message being transmitted */
|
/* Tell PolicyEngine to discard the message being transmitted */
|
||||||
PolicyEngine::notify(
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_TX_DISCARD);
|
||||||
PolicyEngine::Notifications::PDB_EVT_TX_DISCARD);
|
|
||||||
|
|
||||||
/* Pass the message to the policy engine. */
|
/* Pass the message to the policy engine. */
|
||||||
PolicyEngine::handleMessage(&tempMessage);
|
PolicyEngine::handleMessage(&tempMessage);
|
||||||
@@ -66,7 +62,7 @@ void InterruptHandler::readPendingMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InterruptHandler::Thread(const void *arg) {
|
void InterruptHandler::Thread(const void *arg) {
|
||||||
(void) arg;
|
(void)arg;
|
||||||
union fusb_status status;
|
union fusb_status status;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// If the irq is low continue, otherwise wait for irq or timeout
|
// If the irq is low continue, otherwise wait for irq or timeout
|
||||||
@@ -85,20 +81,16 @@ void InterruptHandler::Thread(const void *arg) {
|
|||||||
/* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX
|
/* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX
|
||||||
* thread */
|
* thread */
|
||||||
if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) {
|
if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) {
|
||||||
PolicyEngine::notify(
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_TX_I_TXSENT);
|
||||||
PolicyEngine::Notifications::PDB_EVT_TX_I_TXSENT);
|
|
||||||
}
|
}
|
||||||
if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) {
|
if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) {
|
||||||
PolicyEngine::notify(
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_TX_I_RETRYFAIL);
|
||||||
PolicyEngine::Notifications::PDB_EVT_TX_I_RETRYFAIL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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)
|
if ((status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP) && (status.status1 & FUSB_STATUS1_OVRTEMP)) {
|
||||||
&& (status.status1 & FUSB_STATUS1_OVRTEMP)) {
|
PolicyEngine::notify(PolicyEngine::Notifications::PDB_EVT_PE_I_OVRTEMP);
|
||||||
PolicyEngine::notify(
|
|
||||||
PolicyEngine::Notifications::PDB_EVT_PE_I_OVRTEMP);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,8 +98,7 @@ void InterruptHandler::Thread(const void *arg) {
|
|||||||
void InterruptHandler::irqCallback() {
|
void InterruptHandler::irqCallback() {
|
||||||
if (TaskHandle != NULL) {
|
if (TaskHandle != NULL) {
|
||||||
BaseType_t taskWoke = pdFALSE;
|
BaseType_t taskWoke = pdFALSE;
|
||||||
xTaskNotifyFromISR(TaskHandle, 0x01, eNotifyAction::eSetBits,
|
xTaskNotifyFromISR(TaskHandle, 0x01, eNotifyAction::eSetBits, &taskWoke);
|
||||||
&taskWoke);
|
|
||||||
portYIELD_FROM_ISR(taskWoke);
|
portYIELD_FROM_ISR(taskWoke);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -631,9 +631,9 @@ EventBits_t PolicyEngine::pushMessage(union pd_msg *msg) {
|
|||||||
/* 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 */
|
||||||
// while (fusb_get_typec_current() != fusb_sink_tx_ok) {
|
// while (fusb_get_typec_current() != fusb_sink_tx_ok) {
|
||||||
// vTaskDelay(TICKS_10MS);
|
// vTaskDelay(TICKS_10MS);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
/* Send the message to the PHY */
|
/* Send the message to the PHY */
|
||||||
fusb_send_message(msg);
|
fusb_send_message(msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user