summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-02-22 22:14:50 +0700
committerhathach <[email protected]>2023-02-22 22:14:50 +0700
commit1466afafeb927621f9cbb6efd2a0d7e4b6cf8d41 (patch)
tree7fb9b6a1e67b0da37da027c04314f81ae29336d6 /src
parent4c846af53e993d635e6fff7e2611a554b55fc441 (diff)
move and add optional tusb_app_virt_to_phys/tusb_app_phys_to_virt
also add place holder for tusb_app_dcache_flush() and tusb_app_dcache_invalidate()
Diffstat (limited to 'src')
-rw-r--r--src/common/tusb_common.h15
-rw-r--r--src/common/tusb_mcu.h4
-rw-r--r--src/host/hcd.h2
-rw-r--r--src/osal/osal_none.h4
-rw-r--r--src/portable/ohci/ohci.c21
-rw-r--r--src/portable/ohci/ohci.h4
6 files changed, 38 insertions, 12 deletions
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h
index b1ee40a1a..270339cca 100644
--- a/src/common/tusb_common.h
+++ b/src/common/tusb_common.h
@@ -76,6 +76,21 @@
#include "tusb_timeout.h" // TODO remove
//--------------------------------------------------------------------+
+// Optional API implemented by application if needed
+// TODO move to a more ovious place/file
+//--------------------------------------------------------------------+
+
+// flush data cache
+TU_ATTR_WEAK extern void tusb_app_dcache_flush(uintptr_t addr, uint32_t data_size);
+
+// invalidate data cache
+TU_ATTR_WEAK extern void tusb_app_dcache_invalidate(uintptr_t addr, uint32_t data_size);
+
+// Optional physical <-> virtual address translation
+TU_ATTR_WEAK extern void* tusb_app_virt_to_phys(void *virt_addr);
+TU_ATTR_WEAK extern void* tusb_app_phys_to_virt(void *phys_addr);
+
+//--------------------------------------------------------------------+
// Internal Inline Functions
//--------------------------------------------------------------------+
diff --git a/src/common/tusb_mcu.h b/src/common/tusb_mcu.h
index a599c4fe9..e7d4e2c32 100644
--- a/src/common/tusb_mcu.h
+++ b/src/common/tusb_mcu.h
@@ -28,8 +28,8 @@
#define TUSB_MCU_H_
//--------------------------------------------------------------------+
-// Port Specific
-// TUP stand for TinyUSB Port (can be renamed)
+// Port/Platform Specific
+// TUP stand for TinyUSB Port/Platform (can be renamed)
//--------------------------------------------------------------------+
//------------- Unaligned Memory Access -------------//
diff --git a/src/host/hcd.h b/src/host/hcd.h
index deebc59d4..a400626e4 100644
--- a/src/host/hcd.h
+++ b/src/host/hcd.h
@@ -106,7 +106,7 @@ typedef struct
// Controller API
//--------------------------------------------------------------------+
-// optional hcd configuration, called by tuh_config()
+// optional hcd configuration, called by tuh_configure()
bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) TU_ATTR_WEAK;
// Initialize controller to host mode
diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h
index 1ad130557..2e2b3c7ce 100644
--- a/src/osal/osal_none.h
+++ b/src/osal/osal_none.h
@@ -35,6 +35,10 @@
// TASK API
//--------------------------------------------------------------------+
+#if CFG_TUH_ENABLED
+// currently only needed/available in host mode
+void osal_task_delay(uint32_t msec);
+#endif
//--------------------------------------------------------------------+
// Binary Semaphore API
diff --git a/src/portable/ohci/ohci.c b/src/portable/ohci/ohci.c
index 792ef65ff..339f8e896 100644
--- a/src/portable/ohci/ohci.c
+++ b/src/portable/ohci/ohci.c
@@ -162,18 +162,16 @@ static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr);
// USBH-HCD API
//--------------------------------------------------------------------+
-//If your system requires separation of virtual and physical memory, implement
-//tuh_get_phys_addr and tuh_get_virt_addr in your application.
-TU_ATTR_WEAK void *tuh_get_phys_addr(void *virtual_address);
-TU_ATTR_WEAK void *tuh_get_virt_addr(void *physical_address);
-TU_ATTR_ALWAYS_INLINE static void *_phys_addr(void *virtual_address)
+// If your system requires separation of virtual and physical memory, implement
+// tusb_app_virt_to_phys and tusb_app_virt_to_phys in your application.
+TU_ATTR_ALWAYS_INLINE static inline void *_phys_addr(void *virtual_address)
{
- if (tuh_get_phys_addr) return tuh_get_phys_addr(virtual_address);
+ if (tusb_app_virt_to_phys) return tusb_app_virt_to_phys(virtual_address);
return virtual_address;
}
-TU_ATTR_ALWAYS_INLINE static void *_virt_addr(void *physical_address)
+TU_ATTR_ALWAYS_INLINE static inline void *_virt_addr(void *physical_address)
{
- if (tuh_get_virt_addr) return tuh_get_virt_addr(physical_address);
+ if (tusb_app_phys_to_virt) return tusb_app_phys_to_virt(physical_address);
return physical_address;
}
@@ -206,7 +204,13 @@ bool hcd_init(uint8_t rhport)
{
//Wait 20 ms. (Ref Usb spec 7.1.7.7)
OHCI_REG->control_bit.hc_functional_state = OHCI_CONTROL_FUNCSTATE_RESUME;
+
+#if CFG_TUSB_OS != OPT_OS_NONE
+ // os_none implement task delay using usb frame counter which is not started yet
+ // therefore cause infinite delay.
+ // TODO find a way to delay in case of os none e.g __nop
osal_task_delay(20);
+#endif
}
// reset controller
@@ -233,6 +237,7 @@ bool hcd_init(uint8_t rhport)
OHCI_REG->control_bit.hc_functional_state = OHCI_CONTROL_FUNCSTATE_OPERATIONAL; // make HC's state to operational state TODO use this to suspend (save power)
OHCI_REG->rh_status_bit.local_power_status_change = 1; // set global power for ports
+
osal_task_delay(OHCI_REG->rh_descriptorA_bit.power_on_to_good_time * 2); // Wait POTG after power up
return true;
diff --git a/src/portable/ohci/ohci.h b/src/portable/ohci/ohci.h
index 38c258e80..2081ffabb 100644
--- a/src/portable/ohci/ohci.h
+++ b/src/portable/ohci/ohci.h
@@ -58,7 +58,9 @@ typedef struct {
TU_VERIFY_STATIC( sizeof(ohci_hcca_t) == 256, "size is not correct" );
-typedef struct {
+// common link item for gtd and itd for list travel
+// use as pointer only
+typedef struct TU_ATTR_ALIGNED(16) {
uint32_t reserved[2];
volatile uint32_t next;
uint32_t reserved2;