2019-01-01 02:23:52 +00:00
|
|
|
#include <stdio.h>
|
2019-01-01 14:37:14 +00:00
|
|
|
#include <irq.h>
|
2019-01-01 14:10:02 +00:00
|
|
|
#include <printf.h>
|
|
|
|
#include <uart.h>
|
2019-01-01 14:37:14 +00:00
|
|
|
#include <usb.h>
|
2019-01-23 02:25:07 +00:00
|
|
|
#include <time.h>
|
2019-01-01 02:23:52 +00:00
|
|
|
|
2019-01-01 14:10:02 +00:00
|
|
|
#include <generated/csr.h>
|
|
|
|
|
2019-01-23 02:25:07 +00:00
|
|
|
void isr(void)
|
|
|
|
{
|
2019-01-01 14:37:14 +00:00
|
|
|
unsigned int irqs;
|
2019-01-23 02:25:07 +00:00
|
|
|
|
2019-01-01 14:37:14 +00:00
|
|
|
irqs = irq_pending() & irq_getmask();
|
2019-01-23 02:25:07 +00:00
|
|
|
|
|
|
|
if (irqs & (1 << USB_INTERRUPT))
|
|
|
|
usb_isr();
|
2019-01-01 14:37:14 +00:00
|
|
|
|
|
|
|
if (irqs & (1 << UART_INTERRUPT))
|
|
|
|
uart_isr();
|
2019-01-01 14:10:02 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 02:25:07 +00:00
|
|
|
static void rv_putchar(void *ignored, char c)
|
|
|
|
{
|
2019-01-01 14:10:02 +00:00
|
|
|
(void)ignored;
|
2019-02-28 02:48:25 +00:00
|
|
|
if (c == '\n')
|
|
|
|
uart_write('\r');
|
|
|
|
if (c == '\r')
|
|
|
|
return;
|
2019-01-01 14:10:02 +00:00
|
|
|
uart_write(c);
|
|
|
|
}
|
|
|
|
|
2019-01-23 02:25:07 +00:00
|
|
|
static void init(void)
|
|
|
|
{
|
2019-01-25 01:28:03 +00:00
|
|
|
init_printf(NULL, rv_putchar);
|
2019-01-01 14:10:02 +00:00
|
|
|
irq_setmask(0);
|
2019-01-01 14:37:14 +00:00
|
|
|
irq_setie(1);
|
|
|
|
uart_init();
|
2019-01-01 15:03:45 +00:00
|
|
|
usb_init();
|
2019-01-23 02:25:07 +00:00
|
|
|
time_init();
|
2019-01-01 14:10:02 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 02:48:25 +00:00
|
|
|
static const char *usb_hw_api(void) {
|
2019-01-23 02:25:07 +00:00
|
|
|
#ifdef CSR_USB_EP_0_OUT_EV_PENDING_ADDR
|
2019-02-28 02:48:25 +00:00
|
|
|
return "epfifo";
|
2019-01-23 02:25:07 +00:00
|
|
|
#else
|
2019-02-28 02:48:25 +00:00
|
|
|
#ifdef CSR_USB_OBUF_EMPTY_ADDR
|
|
|
|
return "rawfifo";
|
|
|
|
#else
|
|
|
|
#ifdef CSR_USB_WHATEVER
|
|
|
|
return "whatever";
|
|
|
|
#else
|
|
|
|
return "unrecognized hw api";
|
|
|
|
#endif /* CSR_USB_WHATEVER */
|
|
|
|
#endif /* CSR_USB_OBUF_EMPTY_ADDR */
|
|
|
|
#endif /* CSR_USB_EP_0_OUT_EV_PENDING_ADDR */
|
2019-01-23 02:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2019-01-01 14:10:02 +00:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
init();
|
2019-01-23 02:25:07 +00:00
|
|
|
|
2019-02-28 02:48:25 +00:00
|
|
|
printf("\n\nUSB API: %s\n", usb_hw_api());
|
|
|
|
// printf("Press any key to enable USB...\n");
|
|
|
|
|
2019-03-05 03:54:48 +00:00
|
|
|
// usb_print_status();
|
2019-02-28 02:48:25 +00:00
|
|
|
// uart_read();
|
|
|
|
printf("Enabling USB\n");
|
|
|
|
usb_connect();
|
2019-03-10 07:25:33 +00:00
|
|
|
printf("USB enabled.\n");
|
2019-03-05 03:54:48 +00:00
|
|
|
// usb_print_status();
|
2019-02-28 02:48:25 +00:00
|
|
|
int last = 0;
|
2019-03-05 12:28:54 +00:00
|
|
|
static uint8_t bfr[12];
|
2019-01-23 02:25:07 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2019-02-28 02:48:25 +00:00
|
|
|
if (usb_irq_happened() != last) {
|
|
|
|
last = usb_irq_happened();
|
|
|
|
printf("USB %d IRQ happened\n", last);
|
|
|
|
}
|
2019-03-05 03:54:48 +00:00
|
|
|
usb_poll();
|
2019-03-10 07:25:33 +00:00
|
|
|
/*
|
2019-03-05 12:28:54 +00:00
|
|
|
printf("Press any key to send... ");
|
|
|
|
uart_read();
|
|
|
|
printf("Sending... ");
|
2019-03-10 07:25:33 +00:00
|
|
|
bfr[0] = 0;
|
|
|
|
bfr[1] = ~0;
|
2019-03-05 12:28:54 +00:00
|
|
|
bfr[2] = 0;
|
2019-03-10 07:25:33 +00:00
|
|
|
usb_send(NULL, 0, bfr, 1);
|
2019-03-05 12:28:54 +00:00
|
|
|
printf("Sent\n");
|
2019-03-10 07:25:33 +00:00
|
|
|
*/
|
2019-01-01 02:23:52 +00:00
|
|
|
}
|
2019-01-01 14:10:02 +00:00
|
|
|
return 0;
|
2019-01-01 02:23:52 +00:00
|
|
|
}
|