sync with tinyusb repo
This commit is contained in:
1 parent
086bc9f05a
commit
5abacd9dd9
15 files changed
+199
-249
No files matched your search
@@ -185,7 +185,7 @@ bool tud_cdc_n_write_flush (uint8_t itf)
|
||||
//--------------------------------------------------------------------+
|
||||
void cdcd_init(void)
|
||||
{
|
||||
arrclr_( _cdcd_itf );
|
||||
tu_memclr(_cdcd_itf, sizeof(_cdcd_itf));
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_CDC; i++)
|
||||
{
|
||||
@@ -209,7 +209,7 @@ void cdcd_reset(uint8_t rhport)
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_CDC; i++)
|
||||
{
|
||||
memclr_(&_cdcd_itf[i], ITF_BUS_RESET_SZ);
|
||||
tu_memclr(&_cdcd_itf[i], ITF_BUS_RESET_SZ);
|
||||
tu_fifo_clear(&_cdcd_itf[i].rx_ff);
|
||||
tu_fifo_clear(&_cdcd_itf[i].tx_ff);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ static cusd_interface_t _cusd_itf;
|
||||
*------------------------------------------------------------------*/
|
||||
void cusd_init(void)
|
||||
{
|
||||
varclr_(&_cusd_itf);
|
||||
tu_varclr(&_cusd_itf);
|
||||
}
|
||||
|
||||
tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len)
|
||||
|
||||
@@ -188,7 +188,7 @@ bool tud_hid_keyboard_keycode(uint8_t modifier, uint8_t keycode[6])
|
||||
memcpy(report.keycode, keycode, 6);
|
||||
}else
|
||||
{
|
||||
memclr_(report.keycode, 6);
|
||||
tu_memclr(report.keycode, 6);
|
||||
}
|
||||
|
||||
return hidd_kbd_report(&report);
|
||||
@@ -307,14 +307,14 @@ void hidd_init(void)
|
||||
|
||||
void hidd_reset(uint8_t rhport)
|
||||
{
|
||||
arrclr_(_hidd_itf);
|
||||
tu_memclr(_hidd_itf, sizeof(_hidd_itf));
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
varclr_(&_kbd_rpt);
|
||||
tu_varclr(&_kbd_rpt);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
varclr_(&_mse_rpt);
|
||||
tu_varclr(&_mse_rpt);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -100,13 +100,13 @@ typedef enum
|
||||
/// Command Block Wrapper
|
||||
typedef struct ATTR_PACKED
|
||||
{
|
||||
uint32_t signature ; ///< Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.
|
||||
uint32_t tag ; ///< Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTagfield of the associated CSW. The dCSWTagpositively associates a CSW with the corresponding CBW.
|
||||
uint32_t xfer_bytes ; ///< The number of bytes of data that the host expects to transfer on the Bulk-In or Bulk-Out endpoint (as indicated by the Direction bit) during the execution of this command. If this field is zero, the device and the host shall transfer no data between the CBW and the associated CSW, and the device shall ignore the value of the Direction bit in bmCBWFlags.
|
||||
uint8_t dir ; ///< Bit 7 of this field define transfer direction \n - 0 : Data-Out from host to the device. \n - 1 : Data-In from the device to the host.
|
||||
uint8_t lun ; ///< The device Logical Unit Number (LUN) to which the command block is being sent. For devices that support multiple LUNs, the host shall place into this field the LUN to which this command block is addressed. Otherwise, the host shall set this field to zero.
|
||||
uint8_t cmd_len ; ///< The valid length of the CBWCBin bytes. This defines the valid length of the command block. The only legal values are 1 through 16
|
||||
uint8_t command[16] ; ///< The command block to be executed by the device. The device shall interpret the first cmd_len bytes in this field as a command block
|
||||
uint32_t signature; ///< Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.
|
||||
uint32_t tag; ///< Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTagfield of the associated CSW. The dCSWTagpositively associates a CSW with the corresponding CBW.
|
||||
uint32_t total_bytes; ///< The number of bytes of data that the host expects to transfer on the Bulk-In or Bulk-Out endpoint (as indicated by the Direction bit) during the execution of this command. If this field is zero, the device and the host shall transfer no data between the CBW and the associated CSW, and the device shall ignore the value of the Direction bit in bmCBWFlags.
|
||||
uint8_t dir; ///< Bit 7 of this field define transfer direction \n - 0 : Data-Out from host to the device. \n - 1 : Data-In from the device to the host.
|
||||
uint8_t lun; ///< The device Logical Unit Number (LUN) to which the command block is being sent. For devices that support multiple LUNs, the host shall place into this field the LUN to which this command block is addressed. Otherwise, the host shall set this field to zero.
|
||||
uint8_t cmd_len; ///< The valid length of the CBWCBin bytes. This defines the valid length of the command block. The only legal values are 1 through 16
|
||||
uint8_t command[16]; ///< The command block to be executed by the device. The device shall interpret the first cmd_len bytes in this field as a command block
|
||||
}msc_cbw_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct");
|
||||
|
||||
@@ -62,9 +62,9 @@ enum
|
||||
typedef struct {
|
||||
CFG_TUSB_MEM_ALIGN msc_cbw_t cbw;
|
||||
|
||||
#if defined (__ICCARM__) && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX)
|
||||
uint8_t padding1[64-sizeof(msc_cbw_t)]; // IAR cannot align struct's member
|
||||
#endif
|
||||
//#if defined (__ICCARM__) && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX)
|
||||
// uint8_t padding1[64-sizeof(msc_cbw_t)]; // IAR cannot align struct's member
|
||||
//#endif
|
||||
|
||||
CFG_TUSB_MEM_ALIGN msc_csw_t csw;
|
||||
|
||||
@@ -74,7 +74,7 @@ typedef struct {
|
||||
|
||||
// Bulk Only Transfer (BOT) Protocol
|
||||
uint8_t stage;
|
||||
uint32_t data_len;
|
||||
uint32_t total_len;
|
||||
uint32_t xferred_len; // numbered of bytes transferred so far in the Data Stage
|
||||
|
||||
// Sense Response Data
|
||||
@@ -141,12 +141,12 @@ bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, u
|
||||
//--------------------------------------------------------------------+
|
||||
void mscd_init(void)
|
||||
{
|
||||
memclr_(&_mscd_itf, sizeof(mscd_interface_t));
|
||||
tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
|
||||
}
|
||||
|
||||
void mscd_reset(uint8_t rhport)
|
||||
{
|
||||
memclr_(&_mscd_itf, sizeof(mscd_interface_t));
|
||||
tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
|
||||
}
|
||||
|
||||
tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len)
|
||||
@@ -251,12 +251,11 @@ int32_t proc_builtin_scsi(msc_cbw_t const * p_cbw, uint8_t* buffer, uint32_t buf
|
||||
|
||||
case SCSI_CMD_MODE_SENSE_6:
|
||||
{
|
||||
scsi_mode_sense6_resp_t const mode_resp =
|
||||
{
|
||||
.data_len = 3,
|
||||
.medium_type = 0,
|
||||
.device_specific_para = 0,
|
||||
.block_descriptor_len = 0 // no block descriptor are included
|
||||
scsi_mode_sense6_resp_t const mode_resp = {
|
||||
.data_len = 3,
|
||||
.medium_type = 0,
|
||||
.device_specific_para = 0,
|
||||
.block_descriptor_len = 0 // no block descriptor are included
|
||||
};
|
||||
|
||||
ret = sizeof(mode_resp);
|
||||
@@ -302,11 +301,10 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
{
|
||||
case MSC_STAGE_CMD:
|
||||
//------------- new CBW received -------------//
|
||||
|
||||
// Complete IN while waiting for CMD is usually Status of previous SCSI op, ignore it
|
||||
if(ep_addr != p_msc->ep_out) return TUSB_ERROR_NONE;
|
||||
|
||||
TU_ASSERT( event == TUSB_EVENT_XFER_COMPLETE &&
|
||||
TU_ASSERT( event == DCD_XFER_SUCCESS &&
|
||||
xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE, TUSB_ERROR_INVALID_PARA );
|
||||
|
||||
p_csw->signature = MSC_CSW_SIGNATURE;
|
||||
@@ -314,8 +312,8 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
p_csw->data_residue = 0;
|
||||
|
||||
/*------------- Parse command and prepare DATA -------------*/
|
||||
p_msc->stage = MSC_STAGE_DATA;
|
||||
p_msc->data_len = p_cbw->xfer_bytes;
|
||||
p_msc->stage = MSC_STAGE_DATA;
|
||||
p_msc->total_len = p_cbw->total_bytes;
|
||||
p_msc->xferred_len = 0;
|
||||
|
||||
if (SCSI_CMD_READ_10 == p_cbw->command[0])
|
||||
@@ -332,13 +330,12 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
// 1. Zero : Invoke app callback, skip DATA and move to STATUS stage
|
||||
// 2. OUT : queue transfer (invoke app callback after done)
|
||||
// 3. IN : invoke app callback to get response
|
||||
|
||||
if ( p_cbw->xfer_bytes == 0)
|
||||
if ( p_cbw->total_bytes == 0)
|
||||
{
|
||||
int32_t const cb_result = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, NULL, 0);
|
||||
|
||||
p_msc->data_len = 0;
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
p_msc->total_len = 0;
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
|
||||
if ( cb_result < 0 )
|
||||
{
|
||||
@@ -353,7 +350,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
else if ( !BIT_TEST_(p_cbw->dir, 7) )
|
||||
{
|
||||
// OUT transfer
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->data_len), TUSB_ERROR_DCD_EDPT_XFER );
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len), TUSB_ERROR_DCD_EDPT_XFER );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -366,21 +363,21 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
// Not an built-in command, invoke user callback
|
||||
if ( cb_result < 0 )
|
||||
{
|
||||
cb_result = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->data_len);
|
||||
cb_result = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->total_len);
|
||||
}
|
||||
|
||||
if ( cb_result > 0 )
|
||||
{
|
||||
p_msc->data_len = (uint32_t) cb_result;
|
||||
p_csw->status = MSC_CSW_STATUS_PASSED;
|
||||
p_msc->total_len = (uint32_t) cb_result;
|
||||
p_csw->status = MSC_CSW_STATUS_PASSED;
|
||||
|
||||
TU_ASSERT( p_cbw->xfer_bytes >= p_msc->data_len, TUSB_ERROR_INVALID_PARA ); // cannot return more than host expect
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->data_len), TUSB_ERROR_DCD_EDPT_XFER );
|
||||
TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len, TUSB_ERROR_INVALID_PARA ); // cannot return more than host expect
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len), TUSB_ERROR_DCD_EDPT_XFER );
|
||||
}else
|
||||
{
|
||||
p_msc->data_len = 0;
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
p_msc->total_len = 0;
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
|
||||
dcd_edpt_stall(rhport, p_msc->ep_in);
|
||||
@@ -395,7 +392,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
{
|
||||
if ( SCSI_CMD_WRITE_10 != p_cbw->command[0] )
|
||||
{
|
||||
int32_t cb_result = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->data_len);
|
||||
int32_t cb_result = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->total_len);
|
||||
|
||||
if ( cb_result < 0 )
|
||||
{
|
||||
@@ -408,7 +405,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t const block_sz = p_cbw->xfer_bytes / rdwr10_get_blockcount(p_cbw->command);
|
||||
uint16_t const block_sz = p_cbw->total_bytes / rdwr10_get_blockcount(p_cbw->command);
|
||||
|
||||
// Adjust lba with transferred bytes
|
||||
uint32_t const lba = rdwr10_get_lba(p_cbw->command) + (p_msc->xferred_len / block_sz);
|
||||
@@ -419,7 +416,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
if ( nbytes < 0 )
|
||||
{
|
||||
// negative means error -> skip to status phase, status in CSW set to failed
|
||||
p_csw->data_residue = p_cbw->xfer_bytes - p_msc->xferred_len;
|
||||
p_csw->data_residue = p_cbw->total_bytes - p_msc->xferred_len;
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
|
||||
@@ -437,7 +434,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
}
|
||||
|
||||
// simulate an transfer complete with adjusted parameters --> this driver callback will fired again
|
||||
dcd_xfer_complete(rhport, p_msc->ep_out, xferred_bytes-nbytes, true);
|
||||
dcd_event_xfer_complete(rhport, p_msc->ep_out, xferred_bytes-nbytes, DCD_XFER_SUCCESS, false);
|
||||
|
||||
return TUSB_ERROR_NONE; // skip the rest
|
||||
}
|
||||
@@ -452,7 +449,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
// Accumulate data so far
|
||||
p_msc->xferred_len += xferred_bytes;
|
||||
|
||||
if ( p_msc->xferred_len >= p_msc->data_len )
|
||||
if ( p_msc->xferred_len >= p_msc->total_len )
|
||||
{
|
||||
// Data Stage is complete
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
@@ -471,7 +468,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
}else
|
||||
{
|
||||
// No other command take more than one transfer yet -> unlikely error
|
||||
verify_breakpoint();
|
||||
TU_BREAKPOINT();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -486,7 +483,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
|
||||
if ( dcd_edpt_stalled(rhport, p_msc->ep_in) || dcd_edpt_stalled(rhport, p_msc->ep_out) )
|
||||
{
|
||||
// simulate an transfer complete with adjusted parameters --> this driver callback will fired again
|
||||
dcd_xfer_complete(rhport, p_msc->ep_out, 0, true);
|
||||
dcd_event_xfer_complete(rhport, p_msc->ep_out, 0, DCD_XFER_SUCCESS, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -525,13 +522,13 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
msc_cbw_t const * p_cbw = &p_msc->cbw;
|
||||
msc_csw_t * p_csw = &p_msc->csw;
|
||||
|
||||
uint16_t const block_sz = p_cbw->xfer_bytes / rdwr10_get_blockcount(p_cbw->command);
|
||||
uint16_t const block_sz = p_cbw->total_bytes / rdwr10_get_blockcount(p_cbw->command);
|
||||
|
||||
// Adjust lba with transferred bytes
|
||||
uint32_t const lba = rdwr10_get_lba(p_cbw->command) + (p_msc->xferred_len / block_sz);
|
||||
|
||||
// remaining bytes capped at class buffer
|
||||
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->xfer_bytes-p_msc->xferred_len);
|
||||
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
|
||||
|
||||
// Application can consume smaller bytes
|
||||
nbytes = tud_msc_read10_cb(p_cbw->lun, lba, p_msc->xferred_len % block_sz, _mscd_buf, (uint32_t) nbytes);
|
||||
@@ -539,7 +536,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
if ( nbytes < 0 )
|
||||
{
|
||||
// negative means error -> pipe is stalled & status in CSW set to failed
|
||||
p_csw->data_residue = p_cbw->xfer_bytes - p_msc->xferred_len;
|
||||
p_csw->data_residue = p_cbw->total_bytes - p_msc->xferred_len;
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
|
||||
@@ -548,7 +545,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
else if ( nbytes == 0 )
|
||||
{
|
||||
// zero means not ready -> simulate an transfer complete so that this driver callback will fired again
|
||||
dcd_xfer_complete(rhport, p_msc->ep_in, 0, true);
|
||||
dcd_event_xfer_complete(rhport, p_msc->ep_in, 0, DCD_XFER_SUCCESS, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -561,7 +558,7 @@ static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
msc_cbw_t const * p_cbw = &p_msc->cbw;
|
||||
|
||||
// remaining bytes capped at class buffer
|
||||
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->xfer_bytes-p_msc->xferred_len);
|
||||
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
|
||||
|
||||
// Write10 callback will be called later when usb transfer complete
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
|
||||
|
||||
@@ -73,8 +73,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// MACROS
|
||||
//--------------------------------------------------------------------+
|
||||
#define MAX_OF(a, b) ( (a) > (b) ? (a) : (b) )
|
||||
#define MIN_OF(a, b) ( (a) < (b) ? (a) : (b) )
|
||||
#define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
|
||||
|
||||
#define U16_HIGH_U8(u16) ((uint8_t) (((u16) >> 8) & 0x00ff))
|
||||
#define U16_LOW_U8(u16) ((uint8_t) ((u16) & 0x00ff))
|
||||
@@ -137,12 +136,10 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// INLINE FUNCTION
|
||||
//--------------------------------------------------------------------+
|
||||
#define memclr_(buffer, size) memset((buffer), 0, (size))
|
||||
#define varclr_(_var) memclr_(_var, sizeof(*(_var)))
|
||||
#define arrclr_(_arr) memclr_(_arr, sizeof(_arr))
|
||||
#define arrcount_(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
|
||||
#define tu_memclr(buffer, size) memset((buffer), 0, (size))
|
||||
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
|
||||
|
||||
static inline bool mem_all_zero(void const* buffer, uint32_t size)
|
||||
static inline bool tu_mem_test_zero (void const* buffer, uint32_t size)
|
||||
{
|
||||
uint8_t const* p_mem = (uint8_t const*) buffer;
|
||||
for(uint32_t i=0; i<size; i++) if (p_mem[i] != 0) return false;
|
||||
@@ -193,11 +190,6 @@ static inline uint32_t tu_max32(uint32_t x, uint32_t y)
|
||||
return (x > y) ? x : y;
|
||||
}
|
||||
|
||||
static inline uint16_t tu_max16(uint16_t x, uint16_t y)
|
||||
{
|
||||
return (x > y) ? x : y;
|
||||
}
|
||||
|
||||
//------------- Align -------------//
|
||||
static inline uint32_t tu_align32 (uint32_t value)
|
||||
{
|
||||
@@ -249,24 +241,6 @@ static inline uint8_t tu_log2(uint32_t value)
|
||||
return result;
|
||||
}
|
||||
|
||||
// return the number of set bits in value
|
||||
static inline uint8_t tu_cardof(uint32_t value)
|
||||
{
|
||||
// Brian Kernighan's method goes through as many iterations as there are set bits. So if we have a 32-bit word with only
|
||||
// the high bit set, then it will only go once through the loop
|
||||
// Published in 1988, the C Programming Language 2nd Ed. (by Brian W. Kernighan and Dennis M. Ritchie)
|
||||
// mentions this in exercise 2-9. On April 19, 2006 Don Knuth pointed out to me that this method
|
||||
// "was first published by Peter Wegner in CACM 3 (1960), 322. (Also discovered independently by Derrick Lehmer and
|
||||
// published in 1964 in a book edited by Beckenbach.)"
|
||||
uint8_t count;
|
||||
for (count = 0; value; count++)
|
||||
{
|
||||
value &= value - 1; // clear the least significant bit set
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -197,9 +197,6 @@ typedef enum
|
||||
TUSB_EVENT_XFER_COMPLETE,
|
||||
TUSB_EVENT_XFER_ERROR,
|
||||
TUSB_EVENT_XFER_STALLED,
|
||||
|
||||
TUSB_EVENT_BUS_RESET, // TODO refractor
|
||||
TUSB_EVENT_SETUP_RECEIVED,
|
||||
}tusb_event_t;
|
||||
|
||||
enum {
|
||||
|
||||
@@ -74,14 +74,14 @@
|
||||
// Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7
|
||||
#if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__)
|
||||
|
||||
#define verify_breakpoint() \
|
||||
#define TU_BREAKPOINT() \
|
||||
do {\
|
||||
volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */ \
|
||||
if ( (*ARM_CM_DHCSR) & 1UL ) __asm("BKPT #0\n"); /* Only halt mcu if debugger is attached */\
|
||||
} while(0)
|
||||
|
||||
#else
|
||||
#define verify_breakpoint()
|
||||
#define TU_BREAKPOINT()
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
@@ -157,21 +157,21 @@
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* ASSERT
|
||||
* basically TU_VERIFY with verify_breakpoint() as handler
|
||||
* basically TU_VERIFY with TU_BREAKPOINT() as handler
|
||||
* - 1 arg : return false if failed
|
||||
* - 2 arg : return error if failed
|
||||
*------------------------------------------------------------------*/
|
||||
#define ASSERT_1ARGS(_cond) TU_VERIFY_DEFINE(_cond, _MESS_FAILED(); verify_breakpoint(), false)
|
||||
#define ASSERT_2ARGS(_cond, _ret) TU_VERIFY_DEFINE(_cond, _MESS_FAILED(); verify_breakpoint(), _ret)
|
||||
#define ASSERT_1ARGS(_cond) TU_VERIFY_DEFINE(_cond, _MESS_FAILED(); TU_BREAKPOINT(), false)
|
||||
#define ASSERT_2ARGS(_cond, _ret) TU_VERIFY_DEFINE(_cond, _MESS_FAILED(); TU_BREAKPOINT(), _ret)
|
||||
|
||||
#define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS)(__VA_ARGS__)
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* ASSERT Error
|
||||
* basically TU_VERIFY Error with verify_breakpoint() as handler
|
||||
* basically TU_VERIFY Error with TU_BREAKPOINT() as handler
|
||||
*------------------------------------------------------------------*/
|
||||
#define ASERT_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, verify_breakpoint())
|
||||
#define ASERT_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, verify_breakpoint(), _ret)
|
||||
#define ASERT_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, TU_BREAKPOINT())
|
||||
#define ASERT_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, TU_BREAKPOINT(), _ret)
|
||||
|
||||
#define TU_ASSERT_ERR(...) GET_3RD_ARG(__VA_ARGS__, ASERT_ERR_2ARGS, ASERT_ERR_1ARGS)(__VA_ARGS__)
|
||||
|
||||
|
||||
@@ -49,14 +49,52 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
DCD_XFER_SUCCESS = 0,
|
||||
DCD_XFER_FAILED,
|
||||
DCD_XFER_STALLED
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
USBD_BUS_EVENT_RESET = 1,
|
||||
USBD_BUS_EVENT_UNPLUGGED,
|
||||
USBD_BUS_EVENT_SOF,
|
||||
USBD_BUS_EVENT_SUSPENDED,
|
||||
USBD_BUS_EVENT_RESUME
|
||||
}usbd_bus_event_type_t;
|
||||
DCD_EVENT_BUS_RESET = 1,
|
||||
DCD_EVENT_UNPLUGGED,
|
||||
DCD_EVENT_SOF,
|
||||
DCD_EVENT_SUSPENDED,
|
||||
DCD_EVENT_RESUME,
|
||||
|
||||
DCD_EVENT_SETUP_RECEIVED,
|
||||
DCD_EVENT_XFER_COMPLETE,
|
||||
|
||||
USBD_EVT_FUNC_CALL
|
||||
}usbd_eventid_t;
|
||||
|
||||
typedef struct ATTR_ALIGNED(4)
|
||||
{
|
||||
uint8_t rhport;
|
||||
uint8_t event_id;
|
||||
|
||||
union {
|
||||
// USBD_EVT_SETUP_RECEIVED
|
||||
tusb_control_request_t setup_received;
|
||||
|
||||
// USBD_EVT_XFER_COMPLETE
|
||||
struct {
|
||||
uint8_t ep_addr;
|
||||
uint8_t result;
|
||||
uint32_t len;
|
||||
}xfer_complete;
|
||||
|
||||
// USBD_EVT_FUNC_CALL
|
||||
struct {
|
||||
void (*func) (void*);
|
||||
void* param;
|
||||
}func_call;
|
||||
};
|
||||
} dcd_event_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct");
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Device API (Weak is optional)
|
||||
@@ -72,14 +110,21 @@ void dcd_disconnect (uint8_t rhport) ATTR_WEAK;
|
||||
/* Event Function
|
||||
* Called by DCD to notify USBD
|
||||
*------------------------------------------------------------------*/
|
||||
void dcd_bus_event (uint8_t rhport, usbd_bus_event_type_t bus_event);
|
||||
void dcd_setup_received (uint8_t rhport, uint8_t const* p_request);
|
||||
void dcd_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, bool succeeded);
|
||||
void dcd_event_handler(dcd_event_t const * event, bool in_isr);
|
||||
|
||||
static inline void dcd_control_complete(uint8_t rhport, uint32_t xferred_bytes)
|
||||
static inline void dcd_event_xfer_complete(uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr)
|
||||
{
|
||||
// all control complete is successful !!
|
||||
dcd_xfer_complete(rhport, 0, xferred_bytes, true);
|
||||
dcd_event_t event =
|
||||
{
|
||||
.rhport = 0,
|
||||
.event_id = DCD_EVENT_XFER_COMPLETE,
|
||||
};
|
||||
|
||||
event.xfer_complete.ep_addr = ep_addr;
|
||||
event.xfer_complete.len = xferred_bytes;
|
||||
event.xfer_complete.result = result;
|
||||
|
||||
dcd_event_handler(&event, true);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
||||
@@ -156,50 +156,15 @@ enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_
|
||||
//--------------------------------------------------------------------+
|
||||
// DCD Event
|
||||
//--------------------------------------------------------------------+
|
||||
typedef enum
|
||||
{
|
||||
USBD_EVT_SETUP_RECEIVED = 1,
|
||||
USBD_EVT_XFER_DONE,
|
||||
USBD_EVT_SOF,
|
||||
|
||||
USBD_EVT_FUNC_CALL
|
||||
}usbd_eventid_t;
|
||||
|
||||
typedef struct ATTR_ALIGNED(4)
|
||||
{
|
||||
uint8_t rhport;
|
||||
uint8_t event_id;
|
||||
|
||||
union {
|
||||
// USBD_EVT_SETUP_RECEIVED
|
||||
tusb_control_request_t setup_received;
|
||||
|
||||
// USBD_EVT_XFER_DONE
|
||||
struct {
|
||||
uint8_t ep_addr;
|
||||
uint8_t result;
|
||||
uint32_t xferred_byte;
|
||||
}xfer_done;
|
||||
|
||||
// USBD_EVT_FUNC_CALL
|
||||
struct {
|
||||
osal_task_func_t func;
|
||||
void* param;
|
||||
}func_call;
|
||||
};
|
||||
} usbd_task_event_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbd_task_event_t) <= 12, "size is not correct");
|
||||
|
||||
OSAL_TASK_DEF(_usbd_task_def, "usbd", usbd_task, CFG_TUD_TASK_PRIO, CFG_TUD_TASK_STACK_SZ);
|
||||
|
||||
/*------------- event queue -------------*/
|
||||
OSAL_QUEUE_DEF(_usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, usbd_task_event_t);
|
||||
OSAL_QUEUE_DEF(_usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
|
||||
static osal_queue_t _usbd_q;
|
||||
|
||||
/*------------- control transfer semaphore -------------*/
|
||||
static osal_semaphore_def_t _usbd_sem_def;
|
||||
/*static*/ osal_semaphore_t _usbd_ctrl_sem;
|
||||
osal_semaphore_t _usbd_ctrl_sem;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL FUNCTION
|
||||
@@ -264,7 +229,7 @@ void usbd_task( void* param)
|
||||
|
||||
static tusb_error_t usbd_main_st(void)
|
||||
{
|
||||
static usbd_task_event_t event;
|
||||
static dcd_event_t event;
|
||||
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
@@ -274,26 +239,26 @@ static tusb_error_t usbd_main_st(void)
|
||||
tusb_error_t err;
|
||||
err = TUSB_ERROR_NONE;
|
||||
|
||||
memclr_(&event, sizeof(usbd_task_event_t));
|
||||
tu_memclr(&event, sizeof(dcd_event_t));
|
||||
|
||||
osal_queue_receive(_usbd_q, &event, OSAL_TIMEOUT_WAIT_FOREVER, &err);
|
||||
|
||||
if ( USBD_EVT_SETUP_RECEIVED == event.event_id )
|
||||
if ( DCD_EVENT_SETUP_RECEIVED == event.event_id )
|
||||
{
|
||||
STASK_INVOKE( proc_control_request_st(event.rhport, &event.setup_received), err );
|
||||
}
|
||||
else if (USBD_EVT_XFER_DONE == event.event_id)
|
||||
else if (DCD_EVENT_XFER_COMPLETE == event.event_id)
|
||||
{
|
||||
// Invoke the class callback associated with the endpoint address
|
||||
uint8_t const ep_addr = event.xfer_done.ep_addr;
|
||||
uint8_t const ep_addr = event.xfer_complete.ep_addr;
|
||||
uint8_t const drv_id = _usbd_dev.ep2drv[ edpt_dir(ep_addr) ][ edpt_number(ep_addr) ];
|
||||
|
||||
if (drv_id < USBD_CLASS_DRIVER_COUNT)
|
||||
{
|
||||
usbd_class_drivers[drv_id].xfer_cb( event.rhport, ep_addr, (tusb_event_t) event.xfer_done.result, event.xfer_done.xferred_byte);
|
||||
usbd_class_drivers[drv_id].xfer_cb( event.rhport, ep_addr, (tusb_event_t) event.xfer_complete.result, event.xfer_complete.len);
|
||||
}
|
||||
}
|
||||
else if (USBD_EVT_SOF == event.event_id)
|
||||
else if (DCD_EVENT_SOF == event.event_id)
|
||||
{
|
||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
||||
{
|
||||
@@ -309,7 +274,7 @@ static tusb_error_t usbd_main_st(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
verify_breakpoint();
|
||||
TU_BREAKPOINT();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,7 +283,7 @@ static tusb_error_t usbd_main_st(void)
|
||||
|
||||
static void usbd_reset(uint8_t rhport)
|
||||
{
|
||||
varclr_(&_usbd_dev);
|
||||
tu_varclr(&_usbd_dev);
|
||||
memset(_usbd_dev.itf2drv, 0xff, sizeof(_usbd_dev.itf2drv)); // invalid mapping
|
||||
memset(_usbd_dev.ep2drv , 0xff, sizeof(_usbd_dev.ep2drv )); // invalid mapping
|
||||
|
||||
@@ -567,83 +532,69 @@ static void mark_interface_endpoint(uint8_t const* p_desc, uint16_t desc_len, ui
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD-DCD Callback API
|
||||
//--------------------------------------------------------------------+
|
||||
void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event)
|
||||
void dcd_event_handler(dcd_event_t const * event, bool in_isr)
|
||||
{
|
||||
switch(bus_event)
|
||||
uint8_t const rhport = event->rhport;
|
||||
|
||||
switch (event->event_id)
|
||||
{
|
||||
case USBD_BUS_EVENT_RESET:
|
||||
case DCD_EVENT_BUS_RESET:
|
||||
usbd_reset(rhport);
|
||||
|
||||
osal_queue_flush(_usbd_q);
|
||||
osal_semaphore_reset_isr(_usbd_ctrl_sem);
|
||||
break;
|
||||
|
||||
case USBD_BUS_EVENT_SOF:
|
||||
case DCD_EVENT_SOF:
|
||||
{
|
||||
#if 0
|
||||
usbd_task_event_t task_event =
|
||||
dcd_event_t task_event =
|
||||
{
|
||||
.rhport = rhport,
|
||||
.event_id = USBD_EVT_SOF,
|
||||
.event_id = DCD_EVENT_SOF,
|
||||
};
|
||||
osal_queue_send_isr(_usbd_q, &task_event);
|
||||
osal_queue_send(_usbd_q, &task_event, in_isr);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_BUS_EVENT_UNPLUGGED:
|
||||
case DCD_EVENT_UNPLUGGED:
|
||||
usbd_reset(rhport);
|
||||
tud_umount_cb(); // invoke callback
|
||||
break;
|
||||
|
||||
case USBD_BUS_EVENT_SUSPENDED:
|
||||
case DCD_EVENT_SUSPENDED:
|
||||
// TODO support suspended
|
||||
break;
|
||||
|
||||
case DCD_EVENT_RESUME:
|
||||
// TODO support resume
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SETUP_RECEIVED:
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
break;
|
||||
|
||||
case DCD_EVENT_XFER_COMPLETE:
|
||||
if (event->xfer_complete.ep_addr == 0)
|
||||
{
|
||||
// only signal data stage, skip status (zero byte)
|
||||
if (event->xfer_complete.len)
|
||||
{
|
||||
(void) event->xfer_complete.result; // TODO handle control error/stalled
|
||||
osal_semaphore_post( _usbd_ctrl_sem, in_isr);
|
||||
}
|
||||
}else
|
||||
{
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
}
|
||||
TU_ASSERT(event->xfer_complete.result == DCD_XFER_SUCCESS,);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void dcd_setup_received(uint8_t rhport, uint8_t const* p_request)
|
||||
{
|
||||
usbd_task_event_t task_event =
|
||||
{
|
||||
.rhport = rhport,
|
||||
.event_id = USBD_EVT_SETUP_RECEIVED,
|
||||
};
|
||||
|
||||
memcpy(&task_event.setup_received, p_request, sizeof(tusb_control_request_t));
|
||||
osal_queue_send_isr(_usbd_q, &task_event);
|
||||
}
|
||||
|
||||
void dcd_xfer_complete(uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, bool succeeded)
|
||||
{
|
||||
if (ep_addr == 0 )
|
||||
{
|
||||
// Control Transfer
|
||||
(void) rhport;
|
||||
(void) succeeded;
|
||||
|
||||
// only signal data stage, skip status (zero byte)
|
||||
if (xferred_bytes) osal_semaphore_post_isr( _usbd_ctrl_sem );
|
||||
}else
|
||||
{
|
||||
usbd_task_event_t event =
|
||||
{
|
||||
.rhport = rhport,
|
||||
.event_id = USBD_EVT_XFER_DONE,
|
||||
};
|
||||
|
||||
event.xfer_done.ep_addr = ep_addr;
|
||||
event.xfer_done.xferred_byte = xferred_bytes;
|
||||
event.xfer_done.result = succeeded ? TUSB_EVENT_XFER_COMPLETE : TUSB_EVENT_XFER_ERROR;
|
||||
|
||||
osal_queue_send_isr(_usbd_q, &event);
|
||||
}
|
||||
|
||||
TU_ASSERT(succeeded, );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Helper
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -670,9 +621,9 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
void usbd_defer_func(osal_task_func_t func, void* param, bool isr )
|
||||
void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr )
|
||||
{
|
||||
usbd_task_event_t event =
|
||||
dcd_event_t event =
|
||||
{
|
||||
.rhport = 0,
|
||||
.event_id = USBD_EVT_FUNC_CALL,
|
||||
@@ -681,13 +632,7 @@ void usbd_defer_func(osal_task_func_t func, void* param, bool isr )
|
||||
event.func_call.func = func;
|
||||
event.func_call.param = param;
|
||||
|
||||
if ( isr )
|
||||
{
|
||||
osal_queue_send_isr(_usbd_q, &event);
|
||||
}else
|
||||
{
|
||||
osal_queue_send(_usbd_q, &event);
|
||||
}
|
||||
osal_queue_send(_usbd_q, &event, in_isr);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -81,7 +81,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Other Helpers
|
||||
*------------------------------------------------------------------*/
|
||||
void usbd_defer_func( osal_task_func_t func, void* param, bool isr );
|
||||
void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -80,15 +80,13 @@ typedef void (*osal_task_func_t)( void * );
|
||||
* osal_queue_def_t, osal_queue_t
|
||||
* osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
||||
* osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error)
|
||||
* bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data)
|
||||
* bool osal_queue_send(osal_queue_t const queue_hdl, void const * data)
|
||||
* bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
|
||||
* osal_queue_flush() TODO remove
|
||||
*
|
||||
* Semaphore
|
||||
* osal_semaphore_def_t, osal_semaphore_t
|
||||
* osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
|
||||
* bool osal_semaphore_post_isr(osal_semaphore_t sem_hdl)
|
||||
* bool osal_semaphore_post(osal_semaphore_t sem_hdl)
|
||||
* bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
||||
* void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error)
|
||||
* void osal_semaphore_reset_isr(osal_semaphore_t const sem_hdl)
|
||||
*
|
||||
|
||||
@@ -120,14 +120,9 @@ static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_dat
|
||||
(*p_error) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data)
|
||||
static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
|
||||
{
|
||||
return xQueueSendToBackFromISR(queue_hdl, data, NULL);
|
||||
}
|
||||
|
||||
static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data)
|
||||
{
|
||||
return xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER) == pdTRUE;
|
||||
return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER);
|
||||
}
|
||||
|
||||
static inline void osal_queue_flush(osal_queue_t const queue_hdl)
|
||||
@@ -147,14 +142,9 @@ static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semde
|
||||
return xSemaphoreCreateBinaryStatic(semdef);
|
||||
}
|
||||
|
||||
static inline bool osal_semaphore_post_isr(osal_semaphore_t sem_hdl)
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
||||
{
|
||||
return xSemaphoreGiveFromISR(sem_hdl, NULL) == pdTRUE;
|
||||
}
|
||||
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl)
|
||||
{
|
||||
return xSemaphoreGive(sem_hdl) == pdTRUE;
|
||||
return in_isr ? xSemaphoreGiveFromISR(sem_hdl, NULL) : xSemaphoreGive(sem_hdl);
|
||||
}
|
||||
|
||||
static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error)
|
||||
|
||||
@@ -113,11 +113,11 @@ static inline bool osal_task_create(osal_task_def_t* taskdef)
|
||||
//------------- Sub Task Assert -------------//
|
||||
#define STASK_RETURN(error) do { TASK_RESTART; return error; } while(0)
|
||||
|
||||
#define STASK_ASSERT_ERR(_err) TU_VERIFY_ERR_HDLR(_err, verify_breakpoint(); TASK_RESTART, TUSB_ERROR_FAILED)
|
||||
#define STASK_ASSERT_ERR_HDLR(_err, _func) TU_VERIFY_ERR_HDLR(_err, verify_breakpoint(); _func; TASK_RESTART, TUSB_ERROR_FAILED )
|
||||
#define STASK_ASSERT_ERR(_err) TU_VERIFY_ERR_HDLR(_err, TU_BREAKPOINT(); TASK_RESTART, TUSB_ERROR_FAILED)
|
||||
#define STASK_ASSERT_ERR_HDLR(_err, _func) TU_VERIFY_ERR_HDLR(_err, TU_BREAKPOINT(); _func; TASK_RESTART, TUSB_ERROR_FAILED )
|
||||
|
||||
#define STASK_ASSERT(_cond) TU_VERIFY_HDLR(_cond, verify_breakpoint(); TASK_RESTART, TUSB_ERROR_FAILED)
|
||||
#define STASK_ASSERT_HDLR(_cond, _func) TU_VERIFY_HDLR(_cond, verify_breakpoint(); _func; TASK_RESTART, TUSB_ERROR_FAILED)
|
||||
#define STASK_ASSERT(_cond) TU_VERIFY_HDLR(_cond, TU_BREAKPOINT(); TASK_RESTART, TUSB_ERROR_FAILED)
|
||||
#define STASK_ASSERT_HDLR(_cond, _func) TU_VERIFY_HDLR(_cond, TU_BREAKPOINT(); _func; TASK_RESTART, TUSB_ERROR_FAILED)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// QUEUE API
|
||||
@@ -133,13 +133,12 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
||||
return (osal_queue_t) qdef;
|
||||
}
|
||||
|
||||
static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data)
|
||||
static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
|
||||
{
|
||||
(void) in_isr;
|
||||
return tu_fifo_write( (tu_fifo_t*) queue_hdl, data);
|
||||
}
|
||||
|
||||
#define osal_queue_send osal_queue_send_isr
|
||||
|
||||
static inline void osal_queue_flush(osal_queue_t const queue_hdl)
|
||||
{
|
||||
queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
|
||||
@@ -182,10 +181,9 @@ static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semde
|
||||
return semdef;
|
||||
}
|
||||
|
||||
#define osal_semaphore_post_isr osal_semaphore_post
|
||||
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl)
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
||||
{
|
||||
(void) in_isr;
|
||||
if (sem_hdl->count < sem_hdl->max_count ) sem_hdl->count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ void bus_reset(void)
|
||||
NRF_USBD->TASKS_STARTISOIN = 0;
|
||||
NRF_USBD->TASKS_STARTISOOUT = 0;
|
||||
|
||||
varclr_(&_dcd);
|
||||
tu_varclr(&_dcd);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
@@ -418,7 +418,9 @@ void USBD_IRQHandler(void)
|
||||
if ( int_status & USBD_INTEN_USBRESET_Msk )
|
||||
{
|
||||
bus_reset();
|
||||
dcd_bus_event(0, USBD_BUS_EVENT_RESET);
|
||||
|
||||
dcd_event_t event = { .rhport = 0, .event_id = DCD_EVENT_BUS_RESET };
|
||||
dcd_event_handler(&event, true);
|
||||
}
|
||||
|
||||
if ( int_status & EDPT_END_ALL_MASK )
|
||||
@@ -435,7 +437,10 @@ void USBD_IRQHandler(void)
|
||||
NRF_USBD->WINDEXL , NRF_USBD->WINDEXH , NRF_USBD->WLENGTHL, NRF_USBD->WLENGTHH
|
||||
};
|
||||
|
||||
dcd_setup_received(0, setup);
|
||||
dcd_event_t event = { .rhport = 0, .event_id = DCD_EVENT_SETUP_RECEIVED };
|
||||
memcpy(&event.setup_received, setup, 8);
|
||||
|
||||
dcd_event_handler(&event, true);
|
||||
}
|
||||
|
||||
if ( int_status & USBD_INTEN_EP0DATADONE_Msk )
|
||||
@@ -454,7 +459,7 @@ void USBD_IRQHandler(void)
|
||||
}else
|
||||
{
|
||||
// Control IN complete
|
||||
dcd_control_complete(0, _dcd.control.actual_len);
|
||||
dcd_event_xfer_complete(0, 0, _dcd.control.actual_len, DCD_XFER_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -468,7 +473,7 @@ void USBD_IRQHandler(void)
|
||||
}else
|
||||
{
|
||||
// Control OUT complete
|
||||
dcd_control_complete(0, _dcd.control.actual_len);
|
||||
dcd_event_xfer_complete(0, 0, _dcd.control.actual_len, DCD_XFER_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,7 +504,7 @@ void USBD_IRQHandler(void)
|
||||
xfer->total_len = xfer->actual_len;
|
||||
|
||||
// BULK/INT OUT complete
|
||||
dcd_xfer_complete(0, epnum, xfer->actual_len, true);
|
||||
dcd_event_xfer_complete(0, epnum, xfer->actual_len, DCD_XFER_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,7 +533,7 @@ void USBD_IRQHandler(void)
|
||||
} else
|
||||
{
|
||||
// Bulk/Int IN complete
|
||||
dcd_xfer_complete(0, epnum | TUSB_DIR_IN_MASK, xfer->actual_len, true);
|
||||
dcd_event_xfer_complete(0, epnum | TUSB_DIR_IN_MASK, xfer->actual_len, DCD_XFER_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -556,7 +561,8 @@ void USBD_IRQHandler(void)
|
||||
// SOF interrupt
|
||||
if ( int_status & USBD_INTEN_SOF_Msk )
|
||||
{
|
||||
dcd_bus_event(0, USBD_BUS_EVENT_SOF);
|
||||
dcd_event_t event = { .rhport = 0, .event_id = DCD_EVENT_SOF };
|
||||
dcd_event_handler(&event, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user