metastable fix: wip
Trying to figure out what's causing this problem. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
@ -73,6 +73,7 @@ int main(int argc, char **argv)
|
||||
printf("USB enabled, waiting for packet...\n");
|
||||
// usb_print_status();
|
||||
int last = 0;
|
||||
static uint8_t bfr[12];
|
||||
while (1)
|
||||
{
|
||||
if (usb_irq_happened() != last) {
|
||||
@ -80,6 +81,14 @@ int main(int argc, char **argv)
|
||||
printf("USB %d IRQ happened\n", last);
|
||||
}
|
||||
usb_poll();
|
||||
printf("Press any key to send... ");
|
||||
uart_read();
|
||||
printf("Sending... ");
|
||||
bfr[0] = ~0;
|
||||
bfr[1] = 0;
|
||||
bfr[2] = 0;
|
||||
usb_send(NULL, 0, bfr, 3);
|
||||
printf("Sent\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
#include <usb.h>
|
||||
#include <irq.h>
|
||||
#include <generated/csr.h>
|
||||
#include <string.h>
|
||||
#include <printf.h>
|
||||
#include <uart.h>
|
||||
|
||||
#ifdef CSR_USB_OBUF_EMPTY_ADDR
|
||||
|
||||
static inline unsigned char usb_obuf_head_read(void);
|
||||
static inline void usb_obuf_head_write(unsigned char value);
|
||||
|
||||
static inline unsigned char usb_obuf_empty_read(void);
|
||||
|
||||
static inline unsigned char usb_arm_read(void);
|
||||
static inline void usb_arm_write(unsigned char value);
|
||||
|
||||
static inline unsigned char usb_ibuf_head_read(void);
|
||||
static inline void usb_ibuf_head_write(unsigned char value);
|
||||
|
||||
static inline unsigned char usb_ibuf_empty_read(void);
|
||||
|
||||
static inline unsigned char usb_pullup_out_read(void);
|
||||
static inline void usb_pullup_out_write(unsigned char value);
|
||||
|
||||
static inline unsigned char usb_ev_status_read(void);
|
||||
static inline void usb_ev_status_write(unsigned char value);
|
||||
|
||||
static inline unsigned char usb_ev_pending_read(void);
|
||||
static inline void usb_ev_pending_write(unsigned char value);
|
||||
|
||||
static inline unsigned char usb_ev_enable_read(void);
|
||||
static inline void usb_ev_enable_write(unsigned char value);
|
||||
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
|
||||
uint8_t usb_ep0out_wr_ptr;
|
||||
uint8_t usb_ep0out_rd_ptr;
|
||||
#define EP0OUT_BUFFERS 64
|
||||
static uint8_t usb_ep0out_buffer[EP0OUT_BUFFERS][128];
|
||||
void usb_print_status(void)
|
||||
{
|
||||
static int loops;
|
||||
loops++;
|
||||
|
||||
while (usb_ep0out_rd_ptr != usb_ep0out_wr_ptr) {
|
||||
uint8_t *obuf = usb_ep0out_buffer[usb_ep0out_rd_ptr];
|
||||
uint8_t cnt = obuf[0];
|
||||
unsigned int i;
|
||||
if (cnt) {
|
||||
for (i = 0; i < cnt; i++) {
|
||||
uart_write(' ');
|
||||
uart_write(hex[(obuf[i+1] >> 4) & 0xf]);
|
||||
uart_write(hex[obuf[i+1] & (0xf)]);
|
||||
// printf(" %02x", obufbuf[i]);
|
||||
}
|
||||
uart_write('\r');
|
||||
uart_write('\n');
|
||||
}
|
||||
// printf("\n");
|
||||
usb_ep0out_rd_ptr = (usb_ep0out_rd_ptr + 1) & (EP0OUT_BUFFERS-1);
|
||||
}
|
||||
// if (!obe) {
|
||||
// uint32_t obh = usb_obuf_head_read();
|
||||
// usb_obuf_head_write(1);
|
||||
// if (i < 300)
|
||||
// printf("i: %8d obe: %d obh: %02x\n", i, obe, obh);
|
||||
// }
|
||||
}
|
||||
|
||||
int irq_happened;
|
||||
|
||||
void usb_init(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
void usb_isr(void) {
|
||||
uint8_t pending = usb_ev_pending_read();
|
||||
|
||||
// Advance the obuf head, which will reset the obuf_empty bit
|
||||
if (pending & 1) {
|
||||
int byte_count = 0;
|
||||
uint8_t *obuf = usb_ep0out_buffer[usb_ep0out_wr_ptr];
|
||||
while (1) {
|
||||
if (usb_obuf_empty_read())
|
||||
break;
|
||||
obuf[++byte_count] = usb_obuf_head_read();
|
||||
usb_obuf_head_write(0);
|
||||
}
|
||||
usb_ev_pending_write(1);
|
||||
obuf[0] = byte_count;
|
||||
usb_ep0out_wr_ptr = (usb_ep0out_wr_ptr + 1) & (EP0OUT_BUFFERS-1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void usb_connect(void) {
|
||||
usb_pullup_out_write(1);
|
||||
|
||||
usb_ev_pending_write(usb_ev_pending_read());
|
||||
usb_ev_enable_write(0xff);
|
||||
|
||||
irq_setmask(irq_getmask() | (1 << USB_INTERRUPT));
|
||||
}
|
||||
|
||||
void usb_wait(void) {
|
||||
while (!irq_happened)
|
||||
;
|
||||
}
|
||||
|
||||
int usb_irq_happened(void) {
|
||||
return irq_happened;
|
||||
}
|
||||
|
||||
#endif /* CSR_USB_OBUF_EMPTY_ADDR */
|
@ -178,10 +178,14 @@ void usb_init(void) {
|
||||
int usb_send(struct usb_device *dev, int epnum, const void *data, int total_count) {
|
||||
unsigned int i;
|
||||
const uint8_t *data_bfr = data;
|
||||
while (!usb_ibuf_empty_read())
|
||||
printf(".");
|
||||
usb_arm_write(0);
|
||||
for (i = 0; i < total_count; i++) {
|
||||
printf("Writing %02x ", data_bfr[i]);
|
||||
usb_ibuf_head_write(data_bfr[i]);
|
||||
}
|
||||
usb_arm_write(0);
|
||||
usb_arm_write(1);
|
||||
}
|
||||
|
||||
void usb_isr(void) {
|
||||
|
Reference in New Issue
Block a user