move protocol message to stack, disable battery in PWR's CR3

there is still issue with CC1/CC2 pull down resistor and vstate is not
correct.
This commit is contained in:
hathach
2023-06-09 18:15:28 +07:00
parent 8181d470e5
commit 912802456b
6 changed files with 162 additions and 75 deletions

View File

@@ -38,10 +38,28 @@ extern "C" {
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
enum {
TCD_EVENT_INVALID = 0,
TCD_EVENT_CC_CHANGED,
TCD_EVENT_RX_COMPLETE,
};
typedef struct {
uint8_t rhport;
uint8_t event_id;
union {
struct {
uint8_t cc_state[2];
} cc_changed;
struct {
uint16_t xferred_bytes;
uint8_t result;
} rx_complete;
};
} tcd_event_t;;
@@ -68,4 +86,38 @@ void tcd_int_handler(uint8_t rhport);
bool tcd_rx_start(uint8_t rhport, uint8_t* buffer, uint16_t total_bytes);
bool tcd_tx_start(uint8_t rhport, uint8_t const* buffer, uint16_t total_bytes);
//--------------------------------------------------------------------+
// Event API (implemented by stack)
// Called by TCD to notify stack
//--------------------------------------------------------------------+
extern void tcd_event_handler(tcd_event_t const * event, bool in_isr);
TU_ATTR_ALWAYS_INLINE static inline
void tcd_event_cc_changed(uint8_t rhport, uint8_t cc1, uint8_t cc2, bool in_isr) {
tcd_event_t event = {
.rhport = rhport,
.event_id = TCD_EVENT_CC_CHANGED,
.cc_changed = {
.cc_state = {cc1, cc2 }
}
};
tcd_event_handler(&event, in_isr);
}
TU_ATTR_ALWAYS_INLINE static inline
void tcd_event_rx_complete(uint8_t rhport, uint16_t xferred_bytes, uint8_t result, bool in_isr) {
tcd_event_t event = {
.rhport = rhport,
.event_id = TCD_EVENT_RX_COMPLETE,
.rx_complete = {
.xferred_bytes = xferred_bytes,
.result = result
}
};
tcd_event_handler(&event, in_isr);
}
#endif