Skip to content

Commit 806806d

Browse files
authored
Merge pull request hathach#1501 from hathach/more-rp2040-ramfunc
make all hcd/dcd function used in isr into ram
2 parents 8c4b142 + dd035b0 commit 806806d

File tree

5 files changed

+41
-31
lines changed

5 files changed

+41
-31
lines changed

src/common/tusb_types.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,42 +492,42 @@ TU_ATTR_BIT_FIELD_ORDER_END
492492
//--------------------------------------------------------------------+
493493

494494
// Get direction from Endpoint address
495-
static inline tusb_dir_t tu_edpt_dir(uint8_t addr)
495+
TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr)
496496
{
497497
return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
498498
}
499499

500500
// Get Endpoint number from address
501-
static inline uint8_t tu_edpt_number(uint8_t addr)
501+
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_number(uint8_t addr)
502502
{
503503
return (uint8_t)(addr & (~TUSB_DIR_IN_MASK));
504504
}
505505

506-
static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir)
506+
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir)
507507
{
508508
return (uint8_t)(num | (dir ? TUSB_DIR_IN_MASK : 0));
509509
}
510510

511-
static inline uint16_t tu_edpt_packet_size(tusb_desc_endpoint_t const* desc_ep)
511+
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_edpt_packet_size(tusb_desc_endpoint_t const* desc_ep)
512512
{
513513
return tu_le16toh(desc_ep->wMaxPacketSize) & TU_GENMASK(10, 0);
514514
}
515515

516516
//--------------------------------------------------------------------+
517517
// Descriptor helper
518518
//--------------------------------------------------------------------+
519-
static inline uint8_t const * tu_desc_next(void const* desc)
519+
TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc)
520520
{
521521
uint8_t const* desc8 = (uint8_t const*) desc;
522522
return desc8 + desc8[DESC_OFFSET_LEN];
523523
}
524524

525-
static inline uint8_t tu_desc_type(void const* desc)
525+
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_type(void const* desc)
526526
{
527527
return ((uint8_t const*) desc)[DESC_OFFSET_TYPE];
528528
}
529529

530-
static inline uint8_t tu_desc_len(void const* desc)
530+
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_len(void const* desc)
531531
{
532532
return ((uint8_t const*) desc)[DESC_OFFSET_LEN];
533533
}

src/portable/raspberrypi/rp2040/dcd_rp2040.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static uint8_t *next_buffer_ptr;
5555
// USB_MAX_ENDPOINTS Endpoints, direction TUSB_DIR_OUT for out and TUSB_DIR_IN for in.
5656
static struct hw_endpoint hw_endpoints[USB_MAX_ENDPOINTS][2];
5757

58-
static inline struct hw_endpoint *hw_endpoint_get_by_num(uint8_t num, tusb_dir_t dir)
58+
TU_ATTR_ALWAYS_INLINE static inline struct hw_endpoint *hw_endpoint_get_by_num(uint8_t num, tusb_dir_t dir)
5959
{
6060
return &hw_endpoints[num][dir];
6161
}
@@ -185,7 +185,7 @@ static void hw_endpoint_xfer(uint8_t ep_addr, uint8_t *buffer, uint16_t total_by
185185
hw_endpoint_xfer_start(ep, buffer, total_bytes);
186186
}
187187

188-
static void hw_handle_buff_status(void)
188+
static void __no_inline_not_in_flash_func(hw_handle_buff_status)(void)
189189
{
190190
uint32_t remaining_buffers = usb_hw->buf_status;
191191
pico_trace("buf_status = 0x%08x\n", remaining_buffers);
@@ -214,7 +214,7 @@ static void hw_handle_buff_status(void)
214214
}
215215
}
216216

217-
static void reset_ep0_pid(void)
217+
TU_ATTR_ALWAYS_INLINE static inline void reset_ep0_pid(void)
218218
{
219219
// If we have finished this transfer on EP0 set pid back to 1 for next
220220
// setup transfer. Also clear a stall in case
@@ -226,7 +226,7 @@ static void reset_ep0_pid(void)
226226
}
227227
}
228228

229-
static void reset_non_control_endpoints(void)
229+
static void __no_inline_not_in_flash_func(reset_non_control_endpoints)(void)
230230
{
231231
// Disable all non-control
232232
for ( uint8_t i = 0; i < USB_MAX_ENDPOINTS-1; i++ )
@@ -242,7 +242,7 @@ static void reset_non_control_endpoints(void)
242242
next_buffer_ptr = &usb_dpram->epx_data[0];
243243
}
244244

245-
static void dcd_rp2040_irq(void)
245+
static void __no_inline_not_in_flash_func(dcd_rp2040_irq)(void)
246246
{
247247
uint32_t const status = usb_hw->ints;
248248
uint32_t handled = 0;
@@ -524,7 +524,7 @@ void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
524524
hw_endpoint_close(ep_addr);
525525
}
526526

527-
void dcd_int_handler(uint8_t rhport)
527+
void __no_inline_not_in_flash_func(dcd_int_handler)(uint8_t rhport)
528528
{
529529
(void) rhport;
530530
dcd_rp2040_irq();

src/portable/raspberrypi/rp2040/hcd_rp2040.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static struct hw_endpoint *get_dev_ep(uint8_t dev_addr, uint8_t ep_addr)
7979
return NULL;
8080
}
8181

82-
static inline uint8_t dev_speed(void)
82+
TU_ATTR_ALWAYS_INLINE static inline uint8_t dev_speed(void)
8383
{
8484
return (usb_hw->sie_status & USB_SIE_STATUS_SPEED_BITS) >> USB_SIE_STATUS_SPEED_LSB;
8585
}
@@ -91,7 +91,7 @@ static bool need_pre(uint8_t dev_addr)
9191
return hcd_port_speed_get(0) != tuh_speed_get(dev_addr);
9292
}
9393

94-
static void hw_xfer_complete(struct hw_endpoint *ep, xfer_result_t xfer_result)
94+
static void __no_inline_not_in_flash_func(hw_xfer_complete)(struct hw_endpoint *ep, xfer_result_t xfer_result)
9595
{
9696
// Mark transfer as done before we tell the tinyusb stack
9797
uint8_t dev_addr = ep->dev_addr;
@@ -101,7 +101,7 @@ static void hw_xfer_complete(struct hw_endpoint *ep, xfer_result_t xfer_result)
101101
hcd_event_xfer_complete(dev_addr, ep_addr, xferred_len, xfer_result, true);
102102
}
103103

104-
static void _handle_buff_status_bit(uint bit, struct hw_endpoint *ep)
104+
static void __no_inline_not_in_flash_func(_handle_buff_status_bit)(uint bit, struct hw_endpoint *ep)
105105
{
106106
usb_hw_clear->buf_status = bit;
107107
bool done = hw_endpoint_xfer_continue(ep);
@@ -111,7 +111,7 @@ static void _handle_buff_status_bit(uint bit, struct hw_endpoint *ep)
111111
}
112112
}
113113

114-
static void hw_handle_buff_status(void)
114+
static void __no_inline_not_in_flash_func(hw_handle_buff_status)(void)
115115
{
116116
uint32_t remaining_buffers = usb_hw->buf_status;
117117
pico_trace("buf_status 0x%08x\n", remaining_buffers);
@@ -159,7 +159,7 @@ static void hw_handle_buff_status(void)
159159
}
160160
}
161161

162-
static void hw_trans_complete(void)
162+
static void __no_inline_not_in_flash_func(hw_trans_complete)(void)
163163
{
164164
if (usb_hw->sie_ctrl & USB_SIE_CTRL_SEND_SETUP_BITS)
165165
{
@@ -175,7 +175,7 @@ static void hw_trans_complete(void)
175175
}
176176
}
177177

178-
static void hcd_rp2040_irq(void)
178+
static void __no_inline_not_in_flash_func(hcd_rp2040_irq)(void)
179179
{
180180
uint32_t status = usb_hw->ints;
181181
uint32_t handled = 0;
@@ -240,6 +240,12 @@ static void hcd_rp2040_irq(void)
240240
}
241241
}
242242

243+
void __no_inline_not_in_flash_func(hcd_int_handler)(uint8_t rhport)
244+
{
245+
(void) rhport;
246+
hcd_rp2040_irq();
247+
}
248+
243249
static struct hw_endpoint *_next_free_interrupt_ep(void)
244250
{
245251
struct hw_endpoint *ep = NULL;

src/portable/raspberrypi/rp2040/rp2040_usb.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const char *ep_dir_string[] = {
3838
"in",
3939
};
4040

41-
static inline void _hw_endpoint_lock_update(__unused struct hw_endpoint * ep, __unused int delta) {
41+
TU_ATTR_ALWAYS_INLINE static inline void _hw_endpoint_lock_update(__unused struct hw_endpoint * ep, __unused int delta) {
4242
// todo add critsec as necessary to prevent issues between worker and IRQ...
4343
// note that this is perhaps as simple as disabling IRQs because it would make
4444
// sense to have worker and IRQ on same core, however I think using critsec is about equivalent.
@@ -69,15 +69,15 @@ void rp2040_usb_init(void)
6969
usb_hw->muxing = USB_USB_MUXING_TO_PHY_BITS | USB_USB_MUXING_SOFTCON_BITS;
7070
}
7171

72-
void hw_endpoint_reset_transfer(struct hw_endpoint *ep)
72+
void __no_inline_not_in_flash_func(hw_endpoint_reset_transfer)(struct hw_endpoint *ep)
7373
{
7474
ep->active = false;
7575
ep->remaining_len = 0;
7676
ep->xferred_len = 0;
7777
ep->user_buf = 0;
7878
}
7979

80-
void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask) {
80+
void __no_inline_not_in_flash_func(_hw_endpoint_buffer_control_update32)(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask) {
8181
uint32_t value = 0;
8282
if (and_mask) {
8383
value = *ep->buffer_control & and_mask;
@@ -108,7 +108,7 @@ void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_m
108108
}
109109

110110
// prepare buffer, return buffer control
111-
static uint32_t prepare_ep_buffer(struct hw_endpoint *ep, uint8_t buf_id)
111+
static uint32_t __no_inline_not_in_flash_func(prepare_ep_buffer)(struct hw_endpoint *ep, uint8_t buf_id)
112112
{
113113
uint16_t const buflen = tu_min16(ep->remaining_len, ep->wMaxPacketSize);
114114
ep->remaining_len = (uint16_t)(ep->remaining_len - buflen);
@@ -143,7 +143,7 @@ static uint32_t prepare_ep_buffer(struct hw_endpoint *ep, uint8_t buf_id)
143143
}
144144

145145
// Prepare buffer control register value
146-
static void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep)
146+
static void __no_inline_not_in_flash_func(_hw_endpoint_start_next_buffer)(struct hw_endpoint *ep)
147147
{
148148
uint32_t ep_ctrl = *ep->endpoint_control;
149149

@@ -205,7 +205,7 @@ void hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t to
205205
}
206206

207207
// sync endpoint buffer and return transferred bytes
208-
static uint16_t sync_ep_buffer(struct hw_endpoint *ep, uint8_t buf_id)
208+
static uint16_t __no_inline_not_in_flash_func(sync_ep_buffer)(struct hw_endpoint *ep, uint8_t buf_id)
209209
{
210210
uint32_t buf_ctrl = _hw_endpoint_buffer_control_get_value32(ep);
211211
if (buf_id) buf_ctrl = buf_ctrl >> 16;
@@ -241,7 +241,7 @@ static uint16_t sync_ep_buffer(struct hw_endpoint *ep, uint8_t buf_id)
241241
return xferred_bytes;
242242
}
243243

244-
static void _hw_endpoint_xfer_sync (struct hw_endpoint *ep)
244+
static void __no_inline_not_in_flash_func(_hw_endpoint_xfer_sync) (struct hw_endpoint *ep)
245245
{
246246
// Update hw endpoint struct with info from hardware
247247
// after a buff status interrupt
@@ -292,7 +292,7 @@ static void _hw_endpoint_xfer_sync (struct hw_endpoint *ep)
292292
}
293293

294294
// Returns true if transfer is complete
295-
bool hw_endpoint_xfer_continue(struct hw_endpoint *ep)
295+
bool __no_inline_not_in_flash_func(hw_endpoint_xfer_continue)(struct hw_endpoint *ep)
296296
{
297297
_hw_endpoint_lock_update(ep, 1);
298298
// Part way through a transfer

src/portable/raspberrypi/rp2040/rp2040_usb.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,20 @@ bool hw_endpoint_xfer_continue(struct hw_endpoint *ep);
7272
void hw_endpoint_reset_transfer(struct hw_endpoint *ep);
7373

7474
void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask);
75-
static inline uint32_t _hw_endpoint_buffer_control_get_value32(struct hw_endpoint *ep) {
75+
76+
TU_ATTR_ALWAYS_INLINE static inline uint32_t _hw_endpoint_buffer_control_get_value32(struct hw_endpoint *ep) {
7677
return *ep->buffer_control;
7778
}
78-
static inline void _hw_endpoint_buffer_control_set_value32(struct hw_endpoint *ep, uint32_t value) {
79+
80+
TU_ATTR_ALWAYS_INLINE static inline void _hw_endpoint_buffer_control_set_value32(struct hw_endpoint *ep, uint32_t value) {
7981
return _hw_endpoint_buffer_control_update32(ep, 0, value);
8082
}
81-
static inline void _hw_endpoint_buffer_control_set_mask32(struct hw_endpoint *ep, uint32_t value) {
83+
84+
TU_ATTR_ALWAYS_INLINE static inline void _hw_endpoint_buffer_control_set_mask32(struct hw_endpoint *ep, uint32_t value) {
8285
return _hw_endpoint_buffer_control_update32(ep, ~value, value);
8386
}
84-
static inline void _hw_endpoint_buffer_control_clear_mask32(struct hw_endpoint *ep, uint32_t value) {
87+
88+
TU_ATTR_ALWAYS_INLINE static inline void _hw_endpoint_buffer_control_clear_mask32(struct hw_endpoint *ep, uint32_t value) {
8589
return _hw_endpoint_buffer_control_update32(ep, ~value, 0);
8690
}
8791

0 commit comments

Comments
 (0)