2024-08-02 13:51:35 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
// Create external function at 0x00006f88
|
|
|
|
extern void maybe_usb_setup_read(char endpoint,void *fun,uint32_t target_buffer);
|
|
|
|
extern void dwc3_ep0_start_trans(char endpoint,uint32_t target_buf, uint32_t len);
|
|
|
|
extern int usb_event_handler(void);
|
2024-08-02 19:11:18 +00:00
|
|
|
extern uint32_t get_endpoint_recv_buffer(char endpoint);
|
2024-08-02 13:51:35 +00:00
|
|
|
extern void sleep(int endpoint,uint32_t timeout);
|
|
|
|
extern void usb_send(uint32_t address,uint32_t size);
|
|
|
|
extern void rom_send();
|
|
|
|
|
2024-08-02 19:18:08 +00:00
|
|
|
#define recv_buffer 0x02021800 + 0x3000
|
2024-08-02 13:51:35 +00:00
|
|
|
#define data_received 0x02021800 + 0x2004
|
|
|
|
|
|
|
|
void recv_data_cb(uint32_t endpoint, uint32_t len){
|
2024-08-02 19:18:08 +00:00
|
|
|
char *dest_buf = (char *)recv_buffer;
|
2024-08-02 13:51:35 +00:00
|
|
|
volatile void *dref = (void *)data_received;
|
|
|
|
|
2024-08-02 19:18:08 +00:00
|
|
|
void *rbuf = get_endpoint_recv_buffer(endpoint);
|
2024-08-02 13:51:35 +00:00
|
|
|
for(int i= 0; i < len; i++){
|
2024-08-02 19:18:08 +00:00
|
|
|
dest_buf[i] = *(char *)(void *)((int)rbuf + i);
|
2024-08-02 13:51:35 +00:00
|
|
|
}
|
|
|
|
*(uint8_t *)dref = 1; // Mark as ready
|
|
|
|
}
|
|
|
|
|
|
|
|
void recv_data(){
|
|
|
|
// Set data_received to 0
|
|
|
|
// uint32_t *r = (uint32_t *) data_received;
|
|
|
|
// r = 0;
|
|
|
|
volatile void *dref = (void *)data_received;
|
|
|
|
*(uint8_t *)dref = 0;
|
|
|
|
|
|
|
|
maybe_usb_setup_read(2, recv_data_cb, 0x200);
|
2024-08-02 19:11:18 +00:00
|
|
|
uint32_t rbuf = get_endpoint_recv_buffer(2);
|
|
|
|
dwc3_ep0_start_trans(2, rbuf, 0x200);
|
2024-08-02 13:51:35 +00:00
|
|
|
while(1){
|
|
|
|
usb_event_handler();
|
|
|
|
if(*(uint8_t *)dref == 1){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void send_data_cb(uint32_t endpoint, uint32_t len){
|
2024-08-02 20:13:27 +00:00
|
|
|
// Tell event handler that the data was received
|
2024-08-02 13:51:35 +00:00
|
|
|
volatile void *dref = (void *)data_received;
|
|
|
|
*(uint8_t *)dref = 1; // Mark as ready
|
|
|
|
}
|
|
|
|
|
2024-08-02 19:18:08 +00:00
|
|
|
void send_data(uint32_t address, uint32_t size){
|
2024-08-02 13:51:35 +00:00
|
|
|
volatile void *dref = (void *)data_received;
|
|
|
|
*(uint8_t *)dref = 0;
|
|
|
|
maybe_usb_setup_read(0x1, send_data_cb, 0x200);
|
2024-08-02 20:13:27 +00:00
|
|
|
// uint32_t rbuf = get_endpoint_recv_buffer(1);
|
2024-08-02 19:18:08 +00:00
|
|
|
dwc3_ep0_start_trans(1, address, 0x200);
|
2024-08-02 13:51:35 +00:00
|
|
|
while(1){
|
|
|
|
usb_event_handler();
|
|
|
|
if(*(uint8_t *)dref == 1){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
2024-08-02 19:11:18 +00:00
|
|
|
uint32_t count = 0;
|
2024-08-02 13:51:35 +00:00
|
|
|
while(1){
|
|
|
|
recv_data();
|
2024-08-02 19:18:08 +00:00
|
|
|
send_data(recv_buffer, 0x200);
|
2024-08-02 13:51:35 +00:00
|
|
|
}
|
2024-08-02 19:11:18 +00:00
|
|
|
}
|