Skip to content

Commit 1466afa

Browse files
committed
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()
1 parent 4c846af commit 1466afa

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed

src/common/tusb_common.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@
7575

7676
#include "tusb_timeout.h" // TODO remove
7777

78+
//--------------------------------------------------------------------+
79+
// Optional API implemented by application if needed
80+
// TODO move to a more ovious place/file
81+
//--------------------------------------------------------------------+
82+
83+
// flush data cache
84+
TU_ATTR_WEAK extern void tusb_app_dcache_flush(uintptr_t addr, uint32_t data_size);
85+
86+
// invalidate data cache
87+
TU_ATTR_WEAK extern void tusb_app_dcache_invalidate(uintptr_t addr, uint32_t data_size);
88+
89+
// Optional physical <-> virtual address translation
90+
TU_ATTR_WEAK extern void* tusb_app_virt_to_phys(void *virt_addr);
91+
TU_ATTR_WEAK extern void* tusb_app_phys_to_virt(void *phys_addr);
92+
7893
//--------------------------------------------------------------------+
7994
// Internal Inline Functions
8095
//--------------------------------------------------------------------+

src/common/tusb_mcu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#define TUSB_MCU_H_
2929

3030
//--------------------------------------------------------------------+
31-
// Port Specific
32-
// TUP stand for TinyUSB Port (can be renamed)
31+
// Port/Platform Specific
32+
// TUP stand for TinyUSB Port/Platform (can be renamed)
3333
//--------------------------------------------------------------------+
3434

3535
//------------- Unaligned Memory Access -------------//

src/host/hcd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ typedef struct
106106
// Controller API
107107
//--------------------------------------------------------------------+
108108

109-
// optional hcd configuration, called by tuh_config()
109+
// optional hcd configuration, called by tuh_configure()
110110
bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) TU_ATTR_WEAK;
111111

112112
// Initialize controller to host mode

src/osal/osal_none.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
// TASK API
3636
//--------------------------------------------------------------------+
3737

38+
#if CFG_TUH_ENABLED
39+
// currently only needed/available in host mode
40+
void osal_task_delay(uint32_t msec);
41+
#endif
3842

3943
//--------------------------------------------------------------------+
4044
// Binary Semaphore API

src/portable/ohci/ohci.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,16 @@ static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr);
162162
// USBH-HCD API
163163
//--------------------------------------------------------------------+
164164

165-
//If your system requires separation of virtual and physical memory, implement
166-
//tuh_get_phys_addr and tuh_get_virt_addr in your application.
167-
TU_ATTR_WEAK void *tuh_get_phys_addr(void *virtual_address);
168-
TU_ATTR_WEAK void *tuh_get_virt_addr(void *physical_address);
169-
TU_ATTR_ALWAYS_INLINE static void *_phys_addr(void *virtual_address)
165+
// If your system requires separation of virtual and physical memory, implement
166+
// tusb_app_virt_to_phys and tusb_app_virt_to_phys in your application.
167+
TU_ATTR_ALWAYS_INLINE static inline void *_phys_addr(void *virtual_address)
170168
{
171-
if (tuh_get_phys_addr) return tuh_get_phys_addr(virtual_address);
169+
if (tusb_app_virt_to_phys) return tusb_app_virt_to_phys(virtual_address);
172170
return virtual_address;
173171
}
174-
TU_ATTR_ALWAYS_INLINE static void *_virt_addr(void *physical_address)
172+
TU_ATTR_ALWAYS_INLINE static inline void *_virt_addr(void *physical_address)
175173
{
176-
if (tuh_get_virt_addr) return tuh_get_virt_addr(physical_address);
174+
if (tusb_app_phys_to_virt) return tusb_app_phys_to_virt(physical_address);
177175
return physical_address;
178176
}
179177

@@ -206,7 +204,13 @@ bool hcd_init(uint8_t rhport)
206204
{
207205
//Wait 20 ms. (Ref Usb spec 7.1.7.7)
208206
OHCI_REG->control_bit.hc_functional_state = OHCI_CONTROL_FUNCSTATE_RESUME;
207+
208+
#if CFG_TUSB_OS != OPT_OS_NONE
209+
// os_none implement task delay using usb frame counter which is not started yet
210+
// therefore cause infinite delay.
211+
// TODO find a way to delay in case of os none e.g __nop
209212
osal_task_delay(20);
213+
#endif
210214
}
211215

212216
// reset controller
@@ -233,6 +237,7 @@ bool hcd_init(uint8_t rhport)
233237

234238
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)
235239
OHCI_REG->rh_status_bit.local_power_status_change = 1; // set global power for ports
240+
236241
osal_task_delay(OHCI_REG->rh_descriptorA_bit.power_on_to_good_time * 2); // Wait POTG after power up
237242

238243
return true;

src/portable/ohci/ohci.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ typedef struct {
5858

5959
TU_VERIFY_STATIC( sizeof(ohci_hcca_t) == 256, "size is not correct" );
6060

61-
typedef struct {
61+
// common link item for gtd and itd for list travel
62+
// use as pointer only
63+
typedef struct TU_ATTR_ALIGNED(16) {
6264
uint32_t reserved[2];
6365
volatile uint32_t next;
6466
uint32_t reserved2;

0 commit comments

Comments
 (0)