diff options
| author | hathach <[email protected]> | 2013-03-12 12:06:40 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-03-12 12:06:40 +0700 |
| commit | 453ea3986563c11c74ab3bf9d773a90458635ede (patch) | |
| tree | 458c107257cb73cfcdb5b77aa2ef7131e19dbdd8 /tinyusb | |
| parent | 38ff7123b4f43aa85ce1848a0cb99bb73303cadd (diff) | |
add project file for keil
fix binary.h compiler specific
add hal_init code to reset & set usbmode --> able to get USB ISR
remove const qualifier from return function of
- get_operational_register
- get_period_frame_list
- get_async_head
- get_period_head
- get_control_qhd
add stub for
- hcd_port_connect_status
- hcd_port_speed
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/class/hid.h | 16 | ||||
| -rw-r--r-- | tinyusb/class/msc_host.c | 59 | ||||
| -rw-r--r-- | tinyusb/class/msc_host.h | 83 | ||||
| -rw-r--r-- | tinyusb/common/binary.h | 20 | ||||
| -rw-r--r-- | tinyusb/hal/hal_lpc43xx.c | 16 | ||||
| -rw-r--r-- | tinyusb/host/ehci/ehci.c | 43 | ||||
| -rw-r--r-- | tinyusb/host/ehci/ehci.h | 3 | ||||
| -rw-r--r-- | tinyusb/host/hcd.h | 1 | ||||
| -rw-r--r-- | tinyusb/host/usbh.c | 9 | ||||
| -rw-r--r-- | tinyusb/host/usbh.h | 12 | ||||
| -rw-r--r-- | tinyusb/osal/osal_common.h | 2 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 2 |
12 files changed, 222 insertions, 44 deletions
diff --git a/tinyusb/class/hid.h b/tinyusb/class/hid.h index 93438a264..f658c4f97 100644 --- a/tinyusb/class/hid.h +++ b/tinyusb/class/hid.h @@ -124,14 +124,14 @@ enum */ enum { - KEYBOARD_MODIFIER_LEFTCTRL = BIN8(00000001), - KEYBOARD_MODIFIER_LEFTSHIFT = BIN8(00000010), - KEYBOARD_MODIFIER_LEFTALT = BIN8(00000100), - KEYBOARD_MODIFIER_LEFTGUI = BIN8(00001000), - KEYBOARD_MODIFIER_RIGHTCTRL = BIN8(00010000), - KEYBOARD_MODIFIER_RIGHTSHIFT = BIN8(00100000), - KEYBOARD_MODIFIER_RIGHTALT = BIN8(01000000), - KEYBOARD_MODIFIER_RIGHTGUI = BIN8(10000000) + KEYBOARD_MODIFIER_LEFTCTRL = BIT_(0), + KEYBOARD_MODIFIER_LEFTSHIFT = BIT_(1), + KEYBOARD_MODIFIER_LEFTALT = BIT_(2), + KEYBOARD_MODIFIER_LEFTGUI = BIT_(3), + KEYBOARD_MODIFIER_RIGHTCTRL = BIT_(4), + KEYBOARD_MODIFIER_RIGHTSHIFT = BIT_(5), + KEYBOARD_MODIFIER_RIGHTALT = BIT_(6), + KEYBOARD_MODIFIER_RIGHTGUI = BIT_(7) }; enum diff --git a/tinyusb/class/msc_host.c b/tinyusb/class/msc_host.c new file mode 100644 index 000000000..f4e8b5cd5 --- /dev/null +++ b/tinyusb/class/msc_host.c @@ -0,0 +1,59 @@ +/* + * msc_host.c + * + * Created on: Mar 8, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +#include "tusb_option.h" + + + +#define _TINY_USB_SOURCE_FILE_ + + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// IMPLEMENTATION +//--------------------------------------------------------------------+ diff --git a/tinyusb/class/msc_host.h b/tinyusb/class/msc_host.h new file mode 100644 index 000000000..7fc1ce48c --- /dev/null +++ b/tinyusb/class/msc_host.h @@ -0,0 +1,83 @@ +/* + * msc_host.h + * + * Created on: Mar 8, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_MSC_HOST_H_ +#define _TUSB_MSC_HOST_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "common/common.h" +#include "host/usbh.h" +#include "hid.h" + +//--------------------------------------------------------------------+ +// APPLICATION API +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// INTERNAL API +//--------------------------------------------------------------------+ +#ifdef _TINY_USB_SOURCE_FILE_ + +void msch_init(void) ATTR_WEAK; +tusb_error_t msch_install_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; +void msch_isr(pipe_handle_t pipe_hdl) ATTR_WEAK; + +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_MSC_HOST_H_ */ + +/** @} */ diff --git a/tinyusb/common/binary.h b/tinyusb/common/binary.h index f2e12acee..e9bd51e5e 100644 --- a/tinyusb/common/binary.h +++ b/tinyusb/common/binary.h @@ -65,7 +65,7 @@ #define BIT_CLR_(x, n) ( (x) & (~BIT_(n)) ) -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(__CC_ARM) #define BIN8(x) (0b##x) #define BIN16(b1, b2) (0b##b1##b2) @@ -74,16 +74,16 @@ #else // internal macro of B8, B16, B32 -#define _B8__(x) ((x&0x0000000FLU)?1:0) \ - +((x&0x000000F0LU)?2:0) \ - +((x&0x00000F00LU)?4:0) \ - +((x&0x0000F000LU)?8:0) \ - +((x&0x000F0000LU)?16:0) \ - +((x&0x00F00000LU)?32:0) \ - +((x&0x0F000000LU)?64:0) \ - +((x&0xF0000000LU)?128:0) +#define _B8__(x) (((x&0x0000000FUL)?1:0) \ + +((x&0x000000F0UL)?2:0) \ + +((x&0x00000F00UL)?4:0) \ + +((x&0x0000F000UL)?8:0) \ + +((x&0x000F0000UL)?16:0) \ + +((x&0x00F00000UL)?32:0) \ + +((x&0x0F000000UL)?64:0) \ + +((x&0xF0000000UL)?128:0)) -#define BIN8(d) ((uint8_t)_B8__(0x##d##LU)) +#define BIN8(d) ((uint8_t) _B8__(0x##d##UL)) #define BIN16(dmsb,dlsb) (((uint16_t)BIN8(dmsb)<<8) + BIN8(dlsb)) #define BIN32(dmsb,db2,db3,dlsb) \ (((uint32_t)BIN8(dmsb)<<24) \ diff --git a/tinyusb/hal/hal_lpc43xx.c b/tinyusb/hal/hal_lpc43xx.c index 770ffd4ce..f86d5ec2a 100644 --- a/tinyusb/hal/hal_lpc43xx.c +++ b/tinyusb/hal/hal_lpc43xx.c @@ -42,6 +42,16 @@ #include "lpc43xx_cgu.h" +enum { + LPC43XX_USBMODE_DEVICE = 2, + LPC43XX_USBMODE_HOST = 3 +}; + +enum { + LPC43XX_USBMODE_VBUS_LOW = 0, + LPC43XX_USBMODE_VBUS_HIGH = 1 +}; + tusb_error_t hal_init() { /* Set up USB0 clock */ @@ -51,6 +61,12 @@ tusb_error_t hal_init() CGU_EnableEntity(CGU_CLKSRC_PLL0, ENABLE); /* Enable PLL after all setting is done */ LPC_CREG->CREG0 &= ~(1<<5); /* Turn on the phy */ + //------------- reset controller & set role -------------// + hcd_controller_reset(0); + LPC_USB0->USBMODE_H = LPC43XX_USBMODE_HOST | (LPC43XX_USBMODE_VBUS_HIGH << 5); + + hal_interrupt_enable(); + return TUSB_ERROR_NONE; } diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index faabb4a55..2fefed23e 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -71,14 +71,14 @@ STATIC_ASSERT( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4 //--------------------------------------------------------------------+ // IMPLEMENTATION //--------------------------------------------------------------------+ -STATIC_ INLINE_ ehci_registers_t* const get_operational_register(uint8_t hostid) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; -STATIC_ INLINE_ ehci_registers_t* const get_operational_register(uint8_t hostid) +STATIC_ INLINE_ ehci_registers_t* get_operational_register(uint8_t hostid) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; +STATIC_ INLINE_ ehci_registers_t* get_operational_register(uint8_t hostid) { - return (ehci_registers_t* const) (hostid ? (&LPC_USB1->USBCMD_H) : (&LPC_USB0->USBCMD_H) ); + return (ehci_registers_t*) (hostid ? (&LPC_USB1->USBCMD_H) : (&LPC_USB0->USBCMD_H) ); } -STATIC_ INLINE_ ehci_link_t* const get_period_frame_list(uint8_t list_idx) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; -STATIC_ INLINE_ ehci_link_t* const get_period_frame_list(uint8_t list_idx) +STATIC_ INLINE_ ehci_link_t* get_period_frame_list(uint8_t list_idx) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; +STATIC_ INLINE_ ehci_link_t* get_period_frame_list(uint8_t list_idx) { #if CONTROLLER_HOST_NUMBER > 1 return list_idx ? period_frame_list1 : period_frame_list0; // TODO more than 2 controller @@ -98,14 +98,14 @@ STATIC_ INLINE_ uint8_t hostid_to_data_idx(uint8_t hostid) #endif } -STATIC_ INLINE_ ehci_qhd_t* const get_async_head(uint8_t hostid) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; -STATIC_ INLINE_ ehci_qhd_t* const get_async_head(uint8_t hostid) +STATIC_ INLINE_ ehci_qhd_t* get_async_head(uint8_t hostid) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; +STATIC_ INLINE_ ehci_qhd_t* get_async_head(uint8_t hostid) { return &ehci_data.async_head[ hostid_to_data_idx(hostid) ]; } -STATIC_ INLINE_ ehci_qhd_t* const get_period_head(uint8_t hostid) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; -STATIC_ INLINE_ ehci_qhd_t* const get_period_head(uint8_t hostid) +STATIC_ INLINE_ ehci_qhd_t* get_period_head(uint8_t hostid) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; +STATIC_ INLINE_ ehci_qhd_t* get_period_head(uint8_t hostid) { return &ehci_data.period_head[ hostid_to_data_idx(hostid) ]; } @@ -211,7 +211,7 @@ void hcd_isr(uint8_t hostid) if (int_status & EHCI_INT_MASK_PORT_CHANGE) { - +// port_status_change_isr(h) } if (int_status & EHCI_INT_MASK_ASYNC_ADVANCE) @@ -304,17 +304,16 @@ tusb_error_t hcd_controller_stop(uint8_t hostid) return timeout_expired(&timeout) ? TUSB_ERROR_OSAL_TIMEOUT : TUSB_ERROR_NONE; } -//TODO host/device mode must be set immediately after a reset -tusb_error_t hcd_controller_reset(uint8_t hostid) ATTR_WARN_UNUSED_RESULT; tusb_error_t hcd_controller_reset(uint8_t hostid) { ehci_registers_t* const regs = get_operational_register(hostid); timeout_timer_t timeout; - if (regs->usb_sts_bit.hc_halted == 0) // need to stop before reset - { - ASSERT_STATUS( hcd_controller_stop(hostid) ); - } +// NXP chip powered with non-host mode --> sts bit is not correctly reflected +// if (regs->usb_sts_bit.hc_halted == 0) // need to stop before reset +// { +// ASSERT_STATUS( hcd_controller_stop(hostid) ); +// } regs->usb_cmd_bit.reset = 1; @@ -327,14 +326,22 @@ tusb_error_t hcd_controller_reset(uint8_t hostid) //--------------------------------------------------------------------+ // PORT API //--------------------------------------------------------------------+ +bool hcd_port_connect_status(uint8_t core_id) +{ + return false; +} +tusb_speed_t hcd_port_speed(uint8_t core_id) +{ + return TUSB_SPEED_HIGH; +} //--------------------------------------------------------------------+ // PIPE API //--------------------------------------------------------------------+ 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); -static inline ehci_qhd_t* const get_control_qhd(uint8_t dev_addr) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; +static inline ehci_qhd_t* get_control_qhd(uint8_t dev_addr) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr) ATTR_ALWAYS_INLINE ATTR_PURE ATTR_WARN_UNUSED_RESULT; //--------------------------------------------------------------------+ @@ -522,7 +529,7 @@ tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t t //--------------------------------------------------------------------+ // HELPER //--------------------------------------------------------------------+ -static inline ehci_qhd_t* const get_control_qhd(uint8_t dev_addr) +static inline ehci_qhd_t* get_control_qhd(uint8_t dev_addr) { return (dev_addr == 0) ? get_async_head( usbh_device_info_pool[dev_addr].core_id ) : diff --git a/tinyusb/host/ehci/ehci.h b/tinyusb/host/ehci/ehci.h index 8ff1f52ea..cd03c2b96 100644 --- a/tinyusb/host/ehci/ehci.h +++ b/tinyusb/host/ehci/ehci.h @@ -453,6 +453,9 @@ typedef struct { }device[TUSB_CFG_HOST_DEVICE_MAX]; }ehci_data_t; +//For NXP's MCU, host/device mode must be set immediately after a reset +tusb_error_t hcd_controller_reset(uint8_t hostid) ATTR_WARN_UNUSED_RESULT; + #ifdef __cplusplus } #endif diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h index 7091e6c54..95eea8718 100644 --- a/tinyusb/host/hcd.h +++ b/tinyusb/host/hcd.h @@ -93,6 +93,7 @@ tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; /// return the current connect status of roothub port bool hcd_port_connect_status(uint8_t core_id) ATTR_WARN_UNUSED_RESULT; tusb_speed_t hcd_port_speed(uint8_t core_id) ATTR_WARN_UNUSED_RESULT; +//tusb_error_t hcd_port_reset(uint8_t core_id) ATTR_WARN_UNUSED_RESULT; #ifdef __cplusplus } diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index fa16e5403..f0b79dabd 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -47,6 +47,10 @@ #include "tusb.h" #include "usbh_hcd.h" +void tusb_tick_tock(void) +{ + osal_tick_tock(); +} //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ @@ -165,6 +169,11 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) return TUSB_ERROR_NONE; } +pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl) +{ + return PIPE_STATUS_BUSY; +} + //--------------------------------------------------------------------+ // ENUMERATION TASK //--------------------------------------------------------------------+ diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h index 2c367d743..b89cc3bb9 100644 --- a/tinyusb/host/usbh.h +++ b/tinyusb/host/usbh.h @@ -125,7 +125,7 @@ enum { TUSB_FLAGS_CLASS_WIRELESS_CONTROLLER = BIT_(28), TUSB_FLAGS_CLASS_MISC = BIT_(29), TUSB_FLAGS_CLASS_APPLICATION_SPECIFIC = BIT_(30), - TUSB_FLAGS_CLASS_VENDOR_SPECIFIC = BIT_(31) + TUSB_FLAGS_CLASS_VENDOR_SPECIFIC = BIT_(31) // TODO out of range for int type }; /// Device Status @@ -169,11 +169,11 @@ tusb_error_t tusbh_configuration_set (tusb_handle_device_t device_hdl, uint8 tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl) ATTR_WARN_UNUSED_RESULT; #if TUSB_CFG_OS == TUSB_OS_NONE // TODO move later -static inline void tusb_tick_tock(void) ATTR_ALWAYS_INLINE; -static inline void tusb_tick_tock(void) -{ - osal_tick_tock(); -} +//static inline void tusb_tick_tock(void) ATTR_ALWAYS_INLINE; +//static inline void tusb_tick_tock(void) +//{ +// osal_tick_tock(); +//} #endif //--------------------------------------------------------------------+ diff --git a/tinyusb/osal/osal_common.h b/tinyusb/osal/osal_common.h index 55860cb68..d896b2c01 100644 --- a/tinyusb/osal/osal_common.h +++ b/tinyusb/osal/osal_common.h @@ -61,7 +61,7 @@ enum { OSAL_TIMEOUT_NOTIMEOUT = 0, // for use within ISR, return immediately OSAL_TIMEOUT_NORMAL = 10, // default is 10 msec - OSAL_TIMEOUT_WAIT_FOREVER = 0xFFFF0000 + OSAL_TIMEOUT_WAIT_FOREVER = 0x0EEEEEEE }; typedef enum { diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index af96213f5..27f460ed9 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -120,7 +120,7 @@ static inline uint32_t osal_tick_get(void) return status;\ }/* sub task finished ok --> continue */\ }\ - }while(1) + }while(0) #define OSAL_SUBTASK_BEGIN OSAL_TASK_LOOP_BEGIN #define OSAL_SUBTASK_END OSAL_TASK_LOOP_END |
