44 #ifndef UDD_NO_SLEEP_MGR 46 # include "sleepmgr.h" 49 #if !(SAMV71 || SAMV70 || SAME70 || SAMS70) 50 # error The current USBHS Device Driver supports only SAMV71, SAMV70, SAME70 and SAMS70. 52 #ifndef UDD_USB_INT_FUN 53 # define UDD_USB_INT_FUN USBHS_Handler 56 #ifndef UDD_USB_INT_LEVEL 57 # define UDD_USB_INT_LEVEL 5 // By default USB interrupt have low priority 60 #define UDD_EP_USED(ep) (USB_DEVICE_MAX_EP >= ep) 62 #if ( (UDD_EP_USED( 1) && Is_udd_endpoint_dma_supported( 1)) \ 63 ||(UDD_EP_USED( 2) && Is_udd_endpoint_dma_supported( 2)) \ 64 ||(UDD_EP_USED( 3) && Is_udd_endpoint_dma_supported( 3)) \ 65 ||(UDD_EP_USED( 4) && Is_udd_endpoint_dma_supported( 4)) \ 66 ||(UDD_EP_USED( 5) && Is_udd_endpoint_dma_supported( 5)) \ 67 ||(UDD_EP_USED( 6) && Is_udd_endpoint_dma_supported( 6)) \ 68 ||(UDD_EP_USED( 7) && Is_udd_endpoint_dma_supported( 7)) \ 69 ||(UDD_EP_USED( 8) && Is_udd_endpoint_dma_supported( 8)) \ 70 ||(UDD_EP_USED( 9) && Is_udd_endpoint_dma_supported( 9)) \ 71 ||(UDD_EP_USED(10) && Is_udd_endpoint_dma_supported(10)) \ 72 ||(UDD_EP_USED(11) && Is_udd_endpoint_dma_supported(11)) \ 73 ||(UDD_EP_USED(12) && Is_udd_endpoint_dma_supported(12)) \ 74 ||(UDD_EP_USED(13) && Is_udd_endpoint_dma_supported(13)) \ 75 ||(UDD_EP_USED(14) && Is_udd_endpoint_dma_supported(14)) \ 76 ||(UDD_EP_USED(15) && Is_udd_endpoint_dma_supported(15)) \ 78 # define UDD_EP_DMA_SUPPORTED 81 #if ( (UDD_EP_USED( 1) && !Is_udd_endpoint_dma_supported( 1)) \ 82 ||(UDD_EP_USED( 2) && !Is_udd_endpoint_dma_supported( 2)) \ 83 ||(UDD_EP_USED( 3) && !Is_udd_endpoint_dma_supported( 3)) \ 84 ||(UDD_EP_USED( 4) && !Is_udd_endpoint_dma_supported( 4)) \ 85 ||(UDD_EP_USED( 5) && !Is_udd_endpoint_dma_supported( 5)) \ 86 ||(UDD_EP_USED( 6) && !Is_udd_endpoint_dma_supported( 6)) \ 87 ||(UDD_EP_USED( 7) && !Is_udd_endpoint_dma_supported( 7)) \ 88 ||(UDD_EP_USED( 8) && !Is_udd_endpoint_dma_supported( 8)) \ 89 ||(UDD_EP_USED( 9) && !Is_udd_endpoint_dma_supported( 9)) \ 90 ||(UDD_EP_USED(10) && !Is_udd_endpoint_dma_supported(10)) \ 91 ||(UDD_EP_USED(11) && !Is_udd_endpoint_dma_supported(11)) \ 92 ||(UDD_EP_USED(12) && !Is_udd_endpoint_dma_supported(12)) \ 93 ||(UDD_EP_USED(13) && !Is_udd_endpoint_dma_supported(13)) \ 94 ||(UDD_EP_USED(14) && !Is_udd_endpoint_dma_supported(14)) \ 95 ||(UDD_EP_USED(15) && !Is_udd_endpoint_dma_supported(15)) \ 97 # define UDD_EP_FIFO_SUPPORTED 102 #define dbg_print(...) 104 #ifdef UDD_EP_DMA_SUPPORTED 111 static void _dcache_flush(
void *addr, uint32_t dsize)
113 #ifdef CONF_BOARD_ENABLE_CACHE_AT_INIT 114 int32_t op_size = dsize;
115 uint32_t op_addr = (uint32_t) addr;
116 int32_t linesize = 32U;
117 if (op_addr & (linesize - 1)) {
118 op_size += op_addr & (linesize - 1);
119 op_addr &= ~(linesize - 1);
124 while (op_size > 0) {
125 SCB->DCCMVAC = op_addr;
140 static void _dcache_invalidate_prepare(
void *addr, uint32_t dsize)
142 #ifdef CONF_BOARD_ENABLE_CACHE_AT_INIT 143 int32_t op_size = dsize;
144 uint32_t op_addr = (uint32_t) addr;
145 int32_t linesize = 32U;
146 uint32_t addr1 = op_addr;
147 uint32_t addr2 = op_addr + op_size;
148 if (addr1 & (linesize - 1) || addr2 & (linesize - 1)) {
149 addr1 &= ~(linesize - 1);
150 addr2 &= ~(linesize - 1);
153 SCB->DCCIMVAC = addr1;
154 SCB->DCCIMVAC = addr2;
166 static void _dcache_invalidate(
void *addr, uint32_t dsize)
168 #ifdef CONF_BOARD_ENABLE_CACHE_AT_INIT 169 int32_t op_size = dsize;
170 uint32_t op_addr = (uint32_t)addr;
171 int32_t linesize = 32U;
172 if (op_addr & (linesize - 1)) {
173 op_size += op_addr & (linesize - 1);
174 op_addr &= ~(linesize - 1);
179 while (op_size > 0) {
181 *(
volatile uint32_t *)(0xE000EF5C) = op_addr;
255 #ifndef USB_DEVICE_EP_CTRL_SIZE 256 # error USB_DEVICE_EP_CTRL_SIZE not defined 258 #ifndef USB_DEVICE_MAX_EP 259 # error USB_DEVICE_MAX_EP not defined 263 #if USB_DEVICE_MAX_EP > (UDD_MAX_PEP_NB-1) 264 # error USB_DEVICE_MAX_EP is too high and not supported by this part 267 #define UDD_EP_ISO_NBANK_ERROR(ep) \ 268 ( (UDD_ISOCHRONOUS_NB_BANK(ep) < 1) \ 269 || (UDD_ISOCHRONOUS_NB_BANK(ep) > 3) ) 270 #define UDD_EP_BULK_NBANK_ERROR(ep) \ 271 ( (UDD_BULK_NB_BANK(ep) < 1) || (UDD_BULK_NB_BANK(ep) > 2) ) 272 #define UDD_EP_INT_NBANK_ERROR(ep) \ 273 ( (UDD_INTERRUPT_NB_BANK(ep) < 1) || (UDD_INTERRUPT_NB_BANK(ep) > 2) ) 275 #define UDD_EP_ISO_NB_BANK_ERROR(ep) \ 276 (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep)) 277 #define UDD_EP_BULK_NB_BANK_ERROR(ep) \ 278 (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep)) 279 #define UDD_EP_INT_NB_BANK_ERROR(ep) \ 280 (UDD_EP_USED(ep) && UDD_EP_ISO_NBANK_ERROR(ep)) 282 #define UDD_EP_NB_BANK_ERROR(ep, type) \ 283 (ATPASTE3(UDD_EP_, type, _NB_BANK_ERROR(ep))) 285 #define UDD_ISO_NB_BANK_ERROR \ 286 ( UDD_EP_NB_BANK_ERROR( 1, ISO) \ 287 || UDD_EP_NB_BANK_ERROR( 2, ISO) \ 288 || UDD_EP_NB_BANK_ERROR( 3, ISO) \ 289 || UDD_EP_NB_BANK_ERROR( 4, ISO) \ 290 || UDD_EP_NB_BANK_ERROR( 5, ISO) \ 291 || UDD_EP_NB_BANK_ERROR( 6, ISO) \ 292 || UDD_EP_NB_BANK_ERROR( 7, ISO) \ 293 || UDD_EP_NB_BANK_ERROR( 8, ISO) \ 294 || UDD_EP_NB_BANK_ERROR( 9, ISO) \ 295 || UDD_EP_NB_BANK_ERROR(10, ISO) \ 296 || UDD_EP_NB_BANK_ERROR(11, ISO) \ 297 || UDD_EP_NB_BANK_ERROR(12, ISO) \ 298 || UDD_EP_NB_BANK_ERROR(13, ISO) \ 299 || UDD_EP_NB_BANK_ERROR(14, ISO) \ 300 || UDD_EP_NB_BANK_ERROR(15, ISO) ) 301 #define UDD_BULK_NB_BANK_ERROR \ 302 ( UDD_EP_NB_BANK_ERROR( 1, BULK) \ 303 || UDD_EP_NB_BANK_ERROR( 2, BULK) \ 304 || UDD_EP_NB_BANK_ERROR( 3, BULK) \ 305 || UDD_EP_NB_BANK_ERROR( 4, BULK) \ 306 || UDD_EP_NB_BANK_ERROR( 5, BULK) \ 307 || UDD_EP_NB_BANK_ERROR( 6, BULK) \ 308 || UDD_EP_NB_BANK_ERROR( 7, BULK) \ 309 || UDD_EP_NB_BANK_ERROR( 8, BULK) \ 310 || UDD_EP_NB_BANK_ERROR( 9, BULK) \ 311 || UDD_EP_NB_BANK_ERROR(10, BULK) \ 312 || UDD_EP_NB_BANK_ERROR(11, BULK) \ 313 || UDD_EP_NB_BANK_ERROR(12, BULK) \ 314 || UDD_EP_NB_BANK_ERROR(13, BULK) \ 315 || UDD_EP_NB_BANK_ERROR(14, BULK) \ 316 || UDD_EP_NB_BANK_ERROR(15, BULK) ) 317 #define UDD_INTERRUPT_NB_BANK_ERROR \ 318 ( UDD_EP_NB_BANK_ERROR( 1, INT) \ 319 || UDD_EP_NB_BANK_ERROR( 2, INT) \ 320 || UDD_EP_NB_BANK_ERROR( 3, INT) \ 321 || UDD_EP_NB_BANK_ERROR( 4, INT) \ 322 || UDD_EP_NB_BANK_ERROR( 5, INT) \ 323 || UDD_EP_NB_BANK_ERROR( 6, INT) \ 324 || UDD_EP_NB_BANK_ERROR( 7, INT) \ 325 || UDD_EP_NB_BANK_ERROR( 8, INT) \ 326 || UDD_EP_NB_BANK_ERROR( 9, INT) \ 327 || UDD_EP_NB_BANK_ERROR(10, INT) \ 328 || UDD_EP_NB_BANK_ERROR(11, INT) \ 329 || UDD_EP_NB_BANK_ERROR(12, INT) \ 330 || UDD_EP_NB_BANK_ERROR(13, INT) \ 331 || UDD_EP_NB_BANK_ERROR(14, INT) \ 332 || UDD_EP_NB_BANK_ERROR(15, INT) ) 334 #ifndef UDD_ISOCHRONOUS_NB_BANK 335 # define UDD_ISOCHRONOUS_NB_BANK(ep) 2 337 # if UDD_ISO_NB_BANK_ERROR 338 # error UDD_ISOCHRONOUS_NB_BANK(ep) must be define within 1 to 3. 342 #ifndef UDD_BULK_NB_BANK 343 # define UDD_BULK_NB_BANK(ep) 2 345 # if UDD_BULK_NB_BANK_ERROR 346 # error UDD_BULK_NB_BANK must be define with 1 or 2. 350 #ifndef UDD_INTERRUPT_NB_BANK 351 # define UDD_INTERRUPT_NB_BANK(ep) 1 353 # if UDD_INTERRUPT_NB_BANK_ERROR 354 # error UDD_INTERRUPT_NB_BANK must be define with 1 or 2. 364 #ifndef UDD_NO_SLEEP_MGR 367 #define USBHS_SLEEP_MODE_USB_SUSPEND SLEEPMGR_WAIT_FAST 368 #define USBHS_SLEEP_MODE_USB_IDLE SLEEPMGR_SLEEP_WFI 399 #endif // UDD_NO_SLEEP_MGR 409 # if !defined(UDD_NO_SLEEP_MGR) && !defined(USB_VBUS_WKUP) 411 static bool b_vbus_sleep_lock =
false;
417 if (b_lock && !b_vbus_sleep_lock) {
418 b_vbus_sleep_lock =
true;
421 if (!b_lock && b_vbus_sleep_lock) {
422 b_vbus_sleep_lock =
false;
427 # define udd_vbus_monitor_sleep_mode(lock) 444 UDC_VBUS_EVENT(b_vbus_high);
544 #if (0!=USB_DEVICE_MAX_EP) 566 uint8_t b_shortpacket:1;
568 uint8_t stall_requested:1;
576 static void udd_ep_job_table_reset(
void);
579 static void udd_ep_job_table_kill(
void);
581 #ifdef UDD_EP_FIFO_SUPPORTED 610 static void udd_ep_finish_job(udd_ep_job_t * ptr_job,
bool b_abort, uint8_t ep_num);
612 #ifdef UDD_EP_DMA_SUPPORTED 628 static bool udd_ep_interrupt(
void);
630 #endif // (0!=USB_DEVICE_MAX_EP) 652 void udd_interrupt(
void);
653 void udd_interrupt(
void)
658 #ifndef UDD_NO_SLEEP_MGR 677 goto udd_interrupt_sof_end;
683 goto udd_interrupt_sof_end;
689 goto udd_interrupt_end;
692 #if (0 != USB_DEVICE_MAX_EP) 693 if (udd_ep_interrupt()) {
694 goto udd_interrupt_end;
703 #if (USB_DEVICE_MAX_EP != 0) 704 udd_ep_job_table_kill();
712 goto udd_interrupt_end;
722 #ifdef UDC_SUSPEND_EVENT 725 goto udd_interrupt_end;
741 #ifdef UDC_RESUME_EVENT 744 goto udd_interrupt_end;
749 udd_interrupt_sof_end:
793 #if (OTG_ID_IO) && (defined UHD_ENABLE) 807 #ifdef USB_DEVICE_LOW_SPEED 811 #ifdef USB_DEVICE_HS_SUPPORT 816 #endif // USB_DEVICE_LOW_SPEED 823 #if (0!=USB_DEVICE_MAX_EP) 824 udd_ep_job_table_reset();
829 #ifndef UDD_NO_SLEEP_MGR 881 #ifndef UDD_NO_SLEEP_MGR 921 #ifdef USB_DEVICE_HS_SUPPORT 952 #ifdef USB_DEVICE_HS_SUPPORT 986 #ifndef UDD_NO_SLEEP_MGR 1004 #if (0 != USB_DEVICE_MAX_EP) 1006 uint16_t MaxEndpointSize)
1009 uint16_t ep_allocated;
1010 uint8_t nb_bank, bank, i;
1021 dbg_print(
"alloc(%x, %d) ", ep, MaxEndpointSize);
1057 Assert(MaxEndpointSize < 1024);
1058 Assert((MaxEndpointSize == 1023)
1059 || !(MaxEndpointSize & (MaxEndpointSize - 1)));
1060 Assert(MaxEndpointSize >= 8);
1064 MaxEndpointSize, bank);
1065 ep_allocated = 1 << ep;
1070 ep_allocated |= 1 << i;
1078 if (ep_allocated & (1 << i)) {
1079 udd_ep_job_t *ptr_job = &udd_ep_job[i - 1];
1080 bool b_restart = ptr_job->busy;
1083 ptr_job->busy =
false;
1089 if (
NULL == ptr_job->call_trans) {
1096 ptr_job->buf_cnt, i);
1102 # ifdef UDD_EP_FIFO_SUPPORTED 1105 ptr_job->buf_cnt -= ptr_job->buf_load;
1108 ptr_job->buf_cnt -= ptr_job->buf_load;
1111 (i | USB_EP_DIR_IN) : i,
1112 ptr_job->b_shortpacket,
1113 &ptr_job->buf[ptr_job->buf_cnt],
1116 ptr_job->call_trans);
1136 udd_ep_abort_job(ep);
1137 udd_ep_job[ep_index - 1].stall_requested =
false;
1151 udd_ep_job_t *ptr_job = &udd_ep_job[ep_index - 1];
1159 || ptr_job->stall_requested) {
1163 if (ptr_job->busy ==
true) {
1170 ptr_job->stall_requested =
true;
1171 #ifdef UDD_EP_FIFO_SUPPORTED 1192 udd_ep_job_t *ptr_job = &udd_ep_job[ep_index - 1];
1193 bool b_stall_cleared =
false;
1198 if (ptr_job->stall_requested) {
1201 ptr_job->stall_requested =
false;
1204 b_stall_cleared =
true;
1216 b_stall_cleared =
true;
1218 if (b_stall_cleared) {
1221 if (ptr_job->busy ==
true) {
1222 ptr_job->busy =
false;
1223 ptr_job->call_nohalt();
1230 bool udd_ep_run(
udd_ep_id_t ep,
bool b_shortpacket,
1235 udd_ep_job_t *ptr_job;
1244 ptr_job = &udd_ep_job[ep - 1];
1248 || ptr_job->stall_requested) {
1253 if (ptr_job->busy ==
true) {
1257 ptr_job->busy =
true;
1262 ptr_job->buf_size = buf_size;
1263 ptr_job->buf_cnt = 0;
1264 ptr_job->buf_load = 0;
1265 ptr_job->call_trans = callback;
1266 ptr_job->b_shortpacket = b_shortpacket || (buf_size == 0);
1268 #ifdef UDD_EP_FIFO_SUPPORTED 1271 dbg_print(
"ex%x.%c%d\n\r", ep, b_dir_in ?
'i':
'o', buf_size);
1284 #endif // UDD_EP_FIFO_SUPPORTED 1286 #ifdef UDD_EP_DMA_SUPPORTED 1289 if (buf && buf_size) {
1291 _dcache_invalidate_prepare(buf, buf_size);
1293 _dcache_flush(buf, buf_size);
1296 udd_ep_trans_done(ep);
1306 #ifdef UDD_EP_FIFO_SUPPORTED 1329 udd_ep_abort_job(ep);
1336 udd_ep_job_t *ptr_job;
1343 ptr_job = &udd_ep_job[ep - 1];
1350 if (ptr_job->busy ==
true) {
1355 || ptr_job->stall_requested) {
1357 ptr_job->busy =
true;
1358 ptr_job->call_nohalt = callback;
1365 #endif // (0 != USB_DEVICE_MAX_EP) 1368 #ifdef USB_DEVICE_HS_SUPPORT 1372 udd_enable_hs_test_mode();
1373 udd_enable_hs_test_mode_j();
1379 udd_enable_hs_test_mode();
1380 udd_enable_hs_test_mode_k();
1386 udd_enable_hs_test_mode();
1394 const uint8_t *ptr_src;
1396 const uint8_t test_packet[] = {
1398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1400 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
1402 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
1404 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1407 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD,
1409 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0x7E
1419 udd_enable_hs_test_mode();
1420 udd_enable_hs_test_mode_packet();
1424 ptr_src = test_packet;
1426 for (i = 0; i <
sizeof(test_packet); i++) {
1427 *ptr_dest++ = *ptr_src++;
1431 #endif // USB_DEVICE_HS_SUPPORT 1506 for (i = 0; i < nb_data; i++) {
1551 static bool b_shortpacket =
false;
1554 volatile uint8_t *ptr_dest;
1555 volatile uint8_t *ptr_src;
1572 if (0 == nb_remain) {
1598 b_shortpacket =
false;
1600 b_shortpacket =
true;
1620 for (i = 0; i < nb_remain; i++) {
1621 *ptr_dest++ = *ptr_src++;
1667 for (i = 0; i < nb_data; i++) {
1668 *ptr_dest++ = *ptr_src++;
1865 #if (0 != USB_DEVICE_MAX_EP) 1867 static void udd_ep_job_table_reset(
void)
1871 udd_ep_job[i].busy =
false;
1872 udd_ep_job[i].stall_requested =
false;
1877 static void udd_ep_job_table_kill(
void)
1883 udd_ep_finish_job(&udd_ep_job[i],
true, i + 1);
1893 udd_ep_finish_job(&udd_ep_job[ep - 1],
true, ep);
1897 static void udd_ep_finish_job(udd_ep_job_t * ptr_job,
bool b_abort, uint8_t ep_num)
1899 if (ptr_job->busy ==
false) {
1902 dbg_print(
"(JobE%x:%d) ", (ptr_job-udd_ep_job)+1, b_abort);
1903 ptr_job->busy =
false;
1904 if (
NULL == ptr_job->call_trans) {
1914 #ifdef UDD_EP_DMA_SUPPORTED 1917 uint32_t udd_dma_ctrl = 0;
1918 udd_ep_job_t *ptr_job;
1923 ptr_job = &udd_ep_job[ep - 1];
1925 if (!ptr_job->busy) {
1929 if (ptr_job->buf_cnt != ptr_job->buf_size) {
1931 next_trans = ptr_job->buf_size - ptr_job->buf_cnt;
1950 ptr_job->b_shortpacket =
false;
1975 ptr_job->buf_cnt += next_trans;
1976 ptr_job->buf_load = next_trans;
1986 ptr_job->buf_size = ptr_job->buf_cnt;
1989 if (ptr_job->b_shortpacket) {
2003 _dcache_invalidate_prepare(ptr_job->buf, ptr_job->buf_size);
2004 _dcache_invalidate(ptr_job->buf, ptr_job->buf_size);
2008 udd_ep_finish_job(ptr_job,
false, ep);
2012 #ifdef UDD_EP_FIFO_SUPPORTED 2015 udd_ep_job_t *ptr_job = &udd_ep_job[ep - 1];
2016 uint8_t *ptr_src = &ptr_job->buf[ptr_job->buf_cnt];
2019 uint32_t nb_data = 0, i;
2024 if (ptr_job->buf_cnt >= ptr_job->buf_size && !ptr_job->b_shortpacket) {
2030 ptr_job->buf_size = ptr_job->buf_cnt;
2031 udd_ep_finish_job(ptr_job,
false, ep);
2038 ptr_src = &ptr_job->buf[ptr_job->buf_cnt];
2039 nb_remain = ptr_job->buf_size - ptr_job->buf_cnt;
2041 nb_data =
min(nb_remain, pkt_size);
2043 ptr_job->buf_cnt += nb_data;
2044 ptr_job->buf_load = nb_data;
2047 for (i = 0; i < nb_data; i++) {
2048 *ptr_dst++ = *ptr_src++;
2055 if (nb_data < pkt_size) {
2056 ptr_job->b_shortpacket =
false;
2063 udd_ep_job_t *ptr_job = &udd_ep_job[ep - 1];
2064 uint32_t nb_data = 0, i;
2065 uint32_t nb_remain = ptr_job->buf_size - ptr_job->buf_cnt;
2068 uint8_t *ptr_dst = &ptr_job->buf[ptr_job->buf_cnt];
2069 bool b_full =
false, b_short =
false;
2076 if (nb_data < pkt_size) {
2083 if (nb_data >= nb_remain) {
2084 nb_data = nb_remain;
2088 ptr_job->buf_cnt += nb_data;
2089 ptr_job->buf_load = nb_data;
2091 for (i = 0; i < nb_data; i++) {
2092 *ptr_dst++ = *ptr_src++;
2100 if (b_full || b_short) {
2104 ptr_job->buf_size = ptr_job->buf_cnt;
2105 udd_ep_finish_job(ptr_job,
false, ep);
2108 #endif // #ifdef UDD_EP_FIFO_SUPPORTED 2110 static bool udd_ep_interrupt(
void)
2113 udd_ep_job_t *ptr_job;
2118 ptr_job = &udd_ep_job[ep - 1];
2120 #ifdef UDD_EP_DMA_SUPPORTED 2124 uint32_t nb_remaining;
2138 ptr_job->buf_cnt -= nb_remaining;
2140 ptr_job->buf_size = ptr_job->buf_cnt;
2142 udd_ep_trans_done(ep);
2146 #ifdef UDD_EP_FIFO_SUPPORTED 2155 udd_ep_out_received(ep);
2174 #endif // UDD_EP_FIFO_SUPPORTED 2185 udd_ep_finish_job(ptr_job,
false, ep);
2195 Assert(ptr_job->stall_requested);
2197 ptr_job->stall_requested =
false;
2207 #endif // (0 != USB_DEVICE_MAX_EP) #define cpu_irq_disable()
Disable interrupts globally.
#define udd_get_configured_address()
gets the currently configured USB device address
#define udd_enable_endpoint(ep)
enables the selected endpoint
#define USB_DEVICE_EP_CTRL_SIZE
Control endpoint size (Endpoint 0)
#define udd_enable_sof_interrupt()
#define Is_otg_host_mode_forced()
Test if host mode is forced.
#define Is_udd_write_enabled(ep)
Tests if endpoint write allowed.
void udd_test_mode_packet(void)
#define Is_udd_endpoint_interrupt_enabled(ep)
Tests if the selected endpoint interrupt is enabled.
Common API for USB Device Drivers (UDD)
USB configuration file for CDC application.
#define Is_udd_endpoint_in(ep)
#define udd_high_speed_enable()
#define udd_configure_address(addr)
configures the USB device address
#define USBHS_CTRL_UIMOD_DEVICE
(USBHS_CTRL) The module is in USB Device mode.
#define USBHS_DEVDMACONTROL_CHANN_ENB
(USBHS_DEVDMACONTROL) Channel Enable Command
USB Device Driver for USBHS. Compliant with common UDD driver.
#define USBHS_DEVDMACONTROL_END_TR_EN
(USBHS_DEVDMACONTROL) End of Transfer Enable Control (OUT transfers only)
#define USBHS_DEVEPTCFG_EPBK_3_BANK
(USBHS_DEVEPTCFG[10]) Triple-bank endpoint
#define USBHS_DEVDMACONTROL_END_B_EN
(USBHS_DEVDMACONTROL) End of Buffer Enable Control
#define Is_udd_endpoint_dma_interrupt_enabled(ep)
Tests if the selected endpoint DMA channel interrupt is enabled.
#define USBHS_SLEEP_MODE_USB_IDLE
#define udd_nb_busy_bank(ep)
Returns the number of busy banks.
#define Is_udd_suspend_interrupt_enabled()
#define Is_udd_endpoint_stall_requested(ep)
Tests if STALL handshake request is running.
#define USBHS_DEVDMASTATUS_BUFF_COUNT_Pos
#define Is_otg_id_device()
#define UDD_BULK_NB_BANK(ep)
#define USBHS_DEVDMACONTROL_END_TR_IT
(USBHS_DEVDMACONTROL) End of Transfer Interrupt Enable
#define udd_disable_nak_out_interrupt(ep)
Disables NAK OUT interrupt.
#define udd_ack_nak_in(ep)
ACKs NAK IN received.
#define udd_attach_device()
Attaches to USB bus.
#define Is_udd_endpoint_dma_supported(ep)
Get DMA support of endpoints.
void udd_disable(void)
Disables the USB Device mode.
#define Is_udd_nak_in(ep)
Tests if NAK IN received.
#define USBHS_DEVEPTCFG_EPBK_1_BANK
(USBHS_DEVEPTCFG[10]) Single-bank endpoint
#define udd_reset_data_toggle(ep)
Resets the data toggle sequence.
#define udd_disable_endpoint_bank_autoswitch(ep)
Disables the bank autoswitch for the selected endpoint.
#define udd_low_speed_disable()
#define PMC_FSMR_USBAL
(PMC_FSMR) USB Alarm Enable
#define USBHS_ARRAY(reg, index)
void udd_test_mode_se0_nak(void)
static irqflags_t cpu_irq_save(void)
Get and clear the global interrupt flags.
static void udd_ctrl_send_zlp_in(void)
Send a ZLP IN on control endpoint.
void udd_send_remotewakeup(void)
The USB driver sends a resume signal called Upstream Resume.
#define udd_endpoint_dma_set_control(ep, desc)
Set control desc to selected endpoint DMA channel.
#define udd_byte_count(ep)
Returns the byte count.
void udd_set_setup_payload(uint8_t *payload, uint16_t payload_size)
Load setup payload.
#define USB_EP_ADDR_MASK
Mask selecting the index part of an endpoint address.
uint16_t udd_get_frame_number(void)
Returns the current start of frame number.
#define otg_freeze_clock()
Stop (freeze) internal USB clock.
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
Set Interrupt Priority.
#define udd_endpoint_dma_set_addr(ep, add)
Set RAM address to selected endpoint DMA channel.
#define udd_disable_endpoint_interrupt(ep)
Disables the selected endpoint interrupt.
#define udd_disable_suspend_interrupt()
static void udd_ctrl_send_zlp_out(void)
Send a ZLP OUT on control endpoint.
#define ID_USBHS
USB Host / Device Controller (USBHS)
uint32_t pmc_disable_periph_clk(uint32_t ul_id)
Disable the specified peripheral clock.
#define udd_disable_bank_interrupt(ep)
Disables all banks full (OUT) or free (IN) interrupt.
#define Is_udd_endpoint_interrupt(ep)
Tests if an interrupt is triggered by the selected endpoint.
Global variable to give and record information of the setup request management.
#define Is_otg_clock_usable()
For parts with HS feature, this one corresponding at UTMI clock.
#define USBHS_DEVDMASTATUS_CHANN_ENB
(USBHS_DEVDMASTATUS) Channel Enable Status
#define Is_udd_crc_error(ep)
Tests if CRC ERROR ISO OUT detected.
static void udd_ctrl_out_received(void)
Managed reception of OUT packet on control endpoint.
uint32_t pmc_enable_periph_clk(uint32_t ul_id)
Enable the specified peripheral clock.
void udd_test_mode_k(void)
#define min(a, b)
Takes the minimal value of a and b.
void(* callback)(void)
Callback called after reception of ZLP from setup request.
static bool udd_b_sleep_initialized
State of sleep manager.
#define Udd_setup_is_in()
Return true if the setup request udd_g_ctrlreq indicates IN data transfer.
#define Is_otg_vbus_high()
#define udd_disable_stall_handshake(ep)
Disables the STALL handshake.
#define Is_udd_kill_last(ep)
#define udd_get_endpoint_type(ep)
Gets the configured selected endpoint type.
#define udd_ack_fifocon(ep)
Clears FIFOCON bit.
#define udd_enable_reset_interrupt()
#define udd_disable_endpoint_dma_interrupt(ep)
Disables the selected endpoint DMA channel interrupt.
static udd_ctrl_ep_state_t udd_ep_control_state
State of the endpoint control management.
#define udd_ack_out_received(ep)
ACKs OUT received.
#define udd_enable_msof_interrupt()
static void cpu_irq_restore(irqflags_t flags)
Restore global interrupt flags.
#define Is_udd_nak_out(ep)
Tests if NAK OUT received.
#define ISR(func)
Define service routine.
#define Is_udd_out_received(ep)
Tests if OUT received.
static uint16_t udd_ctrl_prev_payload_buf_cnt
Total number of data received/sent during data packet phase with previous payload buffers...
void udd_set_address(uint8_t address)
Changes the USB address of device.
#define udd_disable_nak_in_interrupt(ep)
Disables NAK IN interrupt.
#define UDD_ENDPOINT_MAX_TRANS
Maximum transfer size on USB DMA.
static void udd_ctrl_setup_received(void)
Managed reception of SETUP packet on control endpoint.
static void udd_ctrl_stall_data(void)
Managed stall event of IN/OUT packet on control endpoint.
void pmc_set_fast_startup_input(uint32_t ul_inputs)
Set the wake-up inputs for fast startup mode registers (event generation).
#define USBHS
(USBHS ) Base Address
#define USBHS_DEVDMACONTROL_BUFF_LENGTH(value)
#define udd_enable_bank_interrupt(ep)
Enables all banks full (OUT) or free (IN) interrupt.
#define udd_ack_in_send(ep)
ACKs IN sending.
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
Enable External Interrupt.
#define udd_ack_nak_out(ep)
ACKs NAK OUT received.
uint8_t udd_getaddress(void)
Returns the USB address of device.
static void udd_sleep_mode(bool b_idle)
Authorize or not the CPU powerdown mode.
#define udd_disable_endpoint(ep)
disables the selected endpoint
#define udd_low_speed_enable()
Enable/disable device low-speed mode.
#define udd_disable_out_received_interrupt(ep)
Disables OUT received interrupt.
#define Is_udd_overflow(ep)
Tests if an overflow occurs.
#define Is_udd_wake_up_interrupt_enabled()
bool udd_include_vbus_monitoring(void)
Authorizes the VBUS event.
#define udd_disable_in_send_interrupt(ep)
Disables IN sending interrupt.
#define udd_disable_address()
disables USB device address
static void udd_reset_ep_ctrl(void)
Reset control endpoint.
void udd_enable(void)
Enables the USB Device mode.
static void udd_ctrl_endofrequest(void)
Call callback associated to setup request.
#define USBHS_DEVEPTCFG_EPBK_Pos
uint8_t udd_ep_id_t
Endpoint identifier.
static void udd_ctrl_overflow(void)
Managed overflow event of OUT packet on control endpoint.
#define udd_ack_stall(ep)
ACKs STALL sent.
#define USBHS_DEVDMASTATUS_END_TR_ST
(USBHS_DEVDMASTATUS) End of Channel Transfer Status
void sysclk_enable_usb(void)
#define USB_EP_DIR_IN
Endpoint transfer direction is IN.
#define udd_enable_endpoint_bank_autoswitch(ep)
Enables the bank autoswitch for the selected endpoint.
#define udd_ack_wake_up()
#define udd_enable_out_received_interrupt(ep)
Enables OUT received interrupt.
#define udd_enable_in_send_interrupt(ep)
Enables IN sending interrupt.
static uint16_t udd_ctrl_payload_buf_cnt
Number of data received/sent to/from udd_g_ctrlreq.payload buffer.
#define Is_udd_underflow(ep)
Tests if an underflow occurs.
#define UDD_USB_INT_LEVEL
COMPILER_WORD_ALIGNED udd_ctrl_request_t udd_g_ctrlreq
Global variable to give and record information about setup request management.
#define udd_high_speed_disable()
#define USB_DEVICE_MAX_EP
3 endpoints used per CDC interface
#define Is_udd_full_speed_mode()
void(* udd_callback_trans_t)(udd_ep_status_t status, iram_size_t nb_transfered, udd_ep_id_t ep)
End of transfer callback function type. Registered by routine udd_ep_run() Callback called by USB int...
#define udd_enable_nak_in_interrupt(ep)
Enables NAK IN interrupt.
#define USBHS_DEVDMACONTROL_END_BUFFIT
(USBHS_DEVDMACONTROL) End of Buffer Interrupt Enable
#define udd_disable_wake_up_interrupt()
#define otg_vbus_init(handler)
#define udd_raise_suspend()
#define Is_udd_in_send_interrupt_enabled(ep)
Tests if IN sending interrupt is enabled.
static void udd_ctrl_in_sent(void)
Managed reception of IN packet on control endpoint.
#define udd_raise_in_send(ep)
Raises IN sending.
#define udd_get_endpoint_fifo_access(ep, scale)
#define udd_unallocate_memory(ep)
un-allocates the configuration selected endpoint in DPRAM memory
#define USBHS_DEVEPTCFG_EPBK_2_BANK
(USBHS_DEVEPTCFG[10]) Double-bank endpoint
void sysclk_disable_usb(void)
#define USBHS_SLEEP_MODE_USB_SUSPEND
Definition of sleep levels.
#define Is_udd_out_received_interrupt_enabled(ep)
Tests if OUT received interrupt is enabled.
bool udc_process_setup(void)
Main routine to manage the USB SETUP request.
void(* udd_callback_halt_cleared_t)(void)
End of halt callback function type. Registered by routine udd_ep_wait_stall_clear() Callback called w...
#define udd_enable_nak_out_interrupt(ep)
Enables NAK OUT interrupt.
static bool udd_ctrl_interrupt(void)
Main interrupt routine for control endpoint.
bool udd_is_high_speed(void)
Test whether the USB Device Controller is running at high speed or not.
#define udd_micro_frame_number()
#define udd_enable_endpoint_interrupt(ep)
Enables the selected endpoint interrupt.
#define udd_allocate_memory(ep)
Allocates the configuration selected endpoint in DPRAM memory.
#define udd_detach_device()
Detaches from USB bus.
#define udd_initiate_remote_wake_up()
void udd_detach(void)
Detaches the device from the bus.
void udd_attach(void)
Attach device to the bus when possible.
#define Is_udd_setup_received(ep)
Tests if SETUP received.
#define udd_frame_number()
bool otg_dual_enable(void)
Initialize the dual role This function is implemented in usbhs_host.c file.
#define Is_udd_endpoint_dma_interrupt(ep)
Tests if an interrupt is triggered by the selected endpoint DMA channel.
#define UDD_ISOCHRONOUS_NB_BANK(ep)
#define udd_enable_setup_received_interrupt(ep)
Enables SETUP received interrupt.
#define Is_udd_endpoint_enabled(ep)
tests if the selected endpoint is enabled
#define udd_ack_setup_received(ep)
ACKs SETUP received.
#define otg_unfreeze_clock()
#define Is_udd_stall(ep)
Tests if STALL sent.
#define Is_udd_bank_interrupt_enabled(ep)
Tests if all banks full (OUT) or free (IN) interrupt enabled.
#define Is_udd_in_send(ep)
Tests if IN sending.
#define udd_endpoint_dma_get_status(ep)
Get status to selected endpoint DMA channel.
uint16_t udd_get_micro_frame_number(void)
Returns the current micro start of frame number.
#define udd_enable_address()
enables USB device address
static void udd_vbus_handler(uint32_t id, uint32_t mask)
uint32_t irqflags_t
Type used for holding state of interrupt flag.
#define udd_kill_last_in_bank(ep)
Kills last bank.
static void udd_ctrl_underflow(void)
Managed underflow event of IN packet on control endpoint.
STALL enabled on IN & OUT packet.
bool(* over_under_run)(void)
#define USBHS_DEVDMASTATUS_BUFF_COUNT_Msk
(USBHS_DEVDMASTATUS) Buffer Byte Count
void udc_sof_notify(void)
To signal that a SOF is occurred.
static bool udd_b_idle
State of USB line.
#define udd_enable_stall_handshake(ep)
Enables the STALL handshake.
static void sleepmgr_lock_mode(enum sleepmgr_mode mode)
Increase lock count for a sleep mode.
uint16_t payload_size
Size of buffer to send or fill, and content the number of byte transfered.
#define otg_enable()
Enable USB macro.
#define UDD_INTERRUPT_NB_BANK(ep)
#define Assert(expr)
This macro is used to test fatal errors.
#define Is_udd_endpoint_configured(ep)
Tests if current endpoint is configured.
#define udd_vbus_monitor_sleep_mode(lock)
#define udd_enable_endpoint_dma_interrupt(ep)
Enables the selected endpoint DMA channel interrupt.
static void sleepmgr_unlock_mode(enum sleepmgr_mode mode)
Decrease lock count for a sleep mode.
udd_ctrl_ep_state_t
Bit definitions about endpoint control state machine for udd_ep_control_state.
#define udd_enable_wake_up_interrupt()
#define udd_enable_suspend_interrupt()
USB OTG Driver for USBHS.
void udd_test_mode_j(void)
static void udd_ctrl_init(void)
Reset control endpoint management.
void udc_reset(void)
Reset the current configuration of the USB device, This routines can be called by UDD when a RESET on...
#define udd_get_endpoint_size(ep)
Gets the configured selected endpoint size.
#define otg_disable()
Disable USB macro.
#define udd_configure_endpoint(ep, type, dir, size, bank)
Configures selected endpoint in one step.