diff options
| author | Nathan Conrad <[email protected]> | 2019-10-02 01:15:47 -0400 |
|---|---|---|
| committer | Nathan Conrad <[email protected]> | 2019-10-02 01:15:47 -0400 |
| commit | cef388b7bd956adbc6af4904d4d95ca4120ebb7b (patch) | |
| tree | 61541614bb829acde7088c99d1c69a31070db32b /src/device | |
| parent | 4ea2a4ed60c41c8b55bfb40459e5f54615e2dc72 (diff) | |
| parent | d84a31fd5fd62b9458504615983591a4c4c34f89 (diff) | |
Merge branch 'master' into ZLP_Request2
Diffstat (limited to 'src/device')
| -rw-r--r-- | src/device/usbd.c | 31 | ||||
| -rw-r--r-- | src/device/usbd_pvt.h | 11 |
2 files changed, 28 insertions, 14 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c index 3700fb988..14e56a9b7 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -52,14 +52,19 @@ typedef struct { uint8_t self_powered : 1; // configuration descriptor's attribute
};
- uint8_t ep_busy_map[2]; // bit mask for busy endpoint
- uint8_t ep_stall_map[2]; // bit map for stalled endpoint
-
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
+
+ struct TU_ATTR_PACKED
+ {
+ volatile bool busy : 1;
+ volatile bool stalled : 1;
+
+ // TODO merge ep2drv here, 4-bit should be sufficient
+ }ep_status[8][2];
}usbd_device_t;
-static usbd_device_t _usbd_dev = { 0 };
+static usbd_device_t _usbd_dev;
// Invalid driver ID in itf2drv[] ep2drv[][] mapping
enum { DRVID_INVALID = 0xFFu };
@@ -310,7 +315,7 @@ void tud_task (void) uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const ep_dir = tu_edpt_dir(ep_addr);
- _usbd_dev.ep_busy_map[ep_dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[ep_dir], epnum);
+ _usbd_dev.ep_status[epnum][ep_dir].busy = false;
if ( 0 == epnum )
{
@@ -864,8 +869,7 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t uint8_t const dir = tu_edpt_dir(ep_addr);
TU_VERIFY( dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes) );
-
- _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum);
+ _usbd_dev.ep_status[epnum][dir].busy = true;
return true;
}
@@ -877,18 +881,17 @@ bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr) uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
- return tu_bit_test(_usbd_dev.ep_busy_map[dir], epnum);
+ return _usbd_dev.ep_status[epnum][dir].busy;
}
-
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
{
uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_stall(rhport, ep_addr);
- _usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_map[dir], epnum);
- _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum);
+ _usbd_dev.ep_status[epnum][dir].stalled = true;
+ _usbd_dev.ep_status[epnum][dir].busy = true;
}
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
@@ -897,8 +900,8 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_clear_stall(rhport, ep_addr);
- _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[dir], epnum);
- _usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_map[dir], epnum);
+ _usbd_dev.ep_status[epnum][dir].stalled = false;
+ _usbd_dev.ep_status[epnum][dir].busy = false;
}
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
@@ -908,7 +911,7 @@ bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
- return tu_bit_test(_usbd_dev.ep_stall_map[dir], epnum);
+ return _usbd_dev.ep_status[epnum][dir].stalled;
}
#endif
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index fbf030ce3..892680142 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -47,10 +47,21 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t // Check if endpoint transferring is complete bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr); +// Stall endpoint void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr); + +// Clear stalled endpoint void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr); + +// Check if endpoint is stalled bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr); +static inline +bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr) +{ + return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr); +} + /*------------------------------------------------------------------*/ /* Helper *------------------------------------------------------------------*/ |
