diff options
| author | hathach <[email protected]> | 2013-03-11 12:00:25 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-03-11 12:00:25 +0700 |
| commit | 8eaad2326b26f542ba66ea305a40dd4c8e49f421 (patch) | |
| tree | dbb9cee9452ec973b6bd7f65c3c6590d09b55c38 /tinyusb | |
| parent | c1ceec067f0e5a10b891b83a13ca765b673d3e3f (diff) | |
add semphore reset & queue flush API
modify test to check control pipe semaphore created with usbh_init
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/host/ehci/ehci.c | 2 | ||||
| -rw-r--r-- | tinyusb/host/usbh.c | 19 | ||||
| -rw-r--r-- | tinyusb/host/usbh_hcd.h | 10 | ||||
| -rw-r--r-- | tinyusb/osal/osal.h | 3 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 13 |
5 files changed, 35 insertions, 12 deletions
diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 46ea67bf1..faabb4a55 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -340,7 +340,6 @@ static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr) ATTR_ALWAYS_INLINE //--------------------------------------------------------------------+ // CONTROL PIPE API //--------------------------------------------------------------------+ -// TODO subject to pure function static void init_qtd(ehci_qtd_t* p_qtd, uint32_t data_ptr, uint16_t total_bytes) { memclr_(p_qtd, sizeof(ehci_qtd_t)); @@ -537,7 +536,6 @@ static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr) } -// TODO subject to pure function static void init_qhd(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_size, uint8_t endpoint_addr, uint8_t xfer_type) { memclr_(p_qhd, sizeof(ehci_qhd_t)); diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index c84abbc5d..ad4bf3b2a 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -103,6 +103,13 @@ tusb_error_t usbh_init(void) ASSERT_STATUS( hcd_init() ); + //------------- Semaphore for Control Pipe -------------// + for(uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX; i++) + { + usbh_device_info_pool[i].sem_hdl = osal_semaphore_create( OSAL_SEM_REF(usbh_device_info_pool[i].semaphore) ); + ASSERT_PTR(usbh_device_info_pool[i].sem_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); + } + //------------- Enumeration & Reporter Task init -------------// ASSERT_STATUS( osal_task_create(&enum_task) ); enum_queue_hdl = osal_queue_create(&enum_queue); @@ -118,9 +125,19 @@ tusb_error_t usbh_init(void) return TUSB_ERROR_NONE; } +// interrupt caused by a TD (with IOC=1) in pipe of class class_code void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code) { - + if (class_code == 0) // Control transfer + { + // TODO some semaphore posting + }else if (usbh_class_drivers[class_code].isr) + { + usbh_class_drivers[class_code].isr(pipe_hdl); + }else + { + ASSERT(false, (void) 0); // something wrong, no one claims the isr's source + } } // function called within a task, requesting os blocking services, subtask input parameter must be static/global variables diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h index ab4bef49b..03901050b 100644 --- a/tinyusb/host/usbh_hcd.h +++ b/tinyusb/host/usbh_hcd.h @@ -90,20 +90,12 @@ typedef struct { // TODO internal structure, re-order members //------------- configuration descriptor info -------------// uint8_t interface_count; // bNumInterfaces alias - uint8_t status; // value from enum tusbh_device_status_ + uint8_t status; // value from enum tusbh_device_status_ -// pipe_handle_t pipe_control; NOTE: use device address/handle instead tusb_std_request_t control_request; OSAL_SEM_DEF(semaphore); osal_semaphore_handle_t sem_hdl; -#if 0 // TODO allow configure for vendor/product - struct { - uint8_t interface_count; - uint8_t attributes; - } configuration; -#endif - } usbh_device_info_t; extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; // including zero-address diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index b1f67055f..09b9560fb 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -147,6 +147,9 @@ typedef void* osal_semaphore_handle_t; #define OSAL_SEM_DEF(name)\ osal_semaphore_t name +#define OSAL_SEM_REF(name)\ + &name + osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const sem); void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error); tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl); diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index da42a969a..82bef38b1 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -150,6 +150,7 @@ static inline uint32_t osal_tick_get(void) #define SUBTASK_ASSERT_STATUS_WITH_HANDLER(...) TASK_ASSERT_STATUS_WITH_HANDLER(__VA_ARGS__) #define SUBTASK_ASSERT(...) TASK_ASSERT(__VA_ARGS__) #define SUBTASK_ASSERT_WITH_HANDLER(...) TASK_ASSERT_WITH_HANDLER(__VA_ARGS__) + //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ @@ -177,6 +178,12 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const se return TUSB_ERROR_NONE; } +static inline void osal_sempahore_reset(osal_semaphore_handle_t const sem_hdl) ATTR_ALWAYS_INLINE; +static inline void osal_sempahore_reset(osal_semaphore_handle_t const sem_hdl) +{ + (*sem_hdl) = 0; +} + #define osal_semaphore_wait(sem_hdl, msec, p_error) \ do {\ timeout = osal_tick_get();\ @@ -242,6 +249,12 @@ static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, return TUSB_ERROR_NONE; } +static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl) ATTR_ALWAYS_INLINE; +static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl) +{ + queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; +} + #define osal_queue_receive(queue_hdl, p_data, msec, p_error) \ do {\ timeout = osal_tick_get();\ |
