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;
|
|
|
|
uart_write(c);
|
|
|
|
}
|
|
|
|
|
2019-01-23 02:25:07 +00:00
|
|
|
static void init(void)
|
|
|
|
{
|
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
|
|
|
init_printf(NULL, rv_putchar);
|
|
|
|
}
|
|
|
|
|
2019-01-23 02:25:07 +00:00
|
|
|
#ifdef CSR_USB_EP_0_OUT_EV_PENDING_ADDR
|
|
|
|
struct usb_status
|
|
|
|
{
|
|
|
|
// uint32_t out_ev_status;
|
|
|
|
uint32_t out_ev_pending;
|
|
|
|
uint32_t in_ev_status;
|
|
|
|
uint32_t out_last_tok;
|
|
|
|
uint32_t out_obuf_empty;
|
|
|
|
uint32_t in_ibuf_empty;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_status get_status(void)
|
|
|
|
{
|
|
|
|
struct usb_status s;
|
|
|
|
// s.out_ev_status = usb_ep_0_out_ev_status_read();
|
|
|
|
s.out_ev_pending = usb_ep_0_out_ev_pending_read();
|
|
|
|
s.in_ev_status = usb_ep_0_in_ev_status_read();
|
|
|
|
s.out_last_tok = usb_ep_0_out_last_tok_read();
|
|
|
|
s.out_obuf_empty = usb_ep_0_out_obuf_empty_read();
|
|
|
|
s.in_ibuf_empty = usb_ep_0_in_ibuf_empty_read();
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_print_status(void)
|
|
|
|
{
|
|
|
|
static int loops;
|
|
|
|
int obufbuf_cnt = 0;
|
|
|
|
struct usb_status s = get_status();
|
|
|
|
|
|
|
|
// printf("i: %8d OEP: %02x OBE: %02x OLT: %02x\n",
|
|
|
|
// loops++,
|
|
|
|
// s.out_ev_pending,
|
|
|
|
// s.out_obuf_empty,
|
|
|
|
// s.out_last_tok);
|
|
|
|
|
|
|
|
if (s.out_ev_pending & (1 << 1)) {
|
|
|
|
loops++;
|
2019-01-23 03:52:47 +00:00
|
|
|
usb_isr();
|
|
|
|
// for (i = 0; i < 0x20; i++) {
|
|
|
|
// usb_ep_0_in_ibuf_head_write(i);
|
|
|
|
// }
|
|
|
|
// // Indicate that we respond with an ACK
|
|
|
|
// usb_ep_0_in_respond_write(USB_ACK);
|
|
|
|
// usb_ep_0_in_ev_pending_write(0xff);
|
2019-01-23 02:25:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void get_print_status(void)
|
|
|
|
{
|
|
|
|
static int loops;
|
|
|
|
uint32_t obe = usb_obuf_empty_read();
|
|
|
|
uint8_t obufbuf[128];
|
|
|
|
int obufbuf_cnt = 0;
|
|
|
|
loops++;
|
|
|
|
|
|
|
|
while (!usb_obuf_empty_read()) {
|
|
|
|
uint32_t obh = usb_obuf_head_read();
|
|
|
|
obufbuf[obufbuf_cnt++] = obh;
|
|
|
|
usb_obuf_head_write(1);
|
|
|
|
}
|
|
|
|
if (obufbuf_cnt) {
|
|
|
|
int i;
|
|
|
|
printf("i: %d b: %d --", loops, obufbuf_cnt);//obe: %d obh: %02x\n", i, obe, obh);
|
|
|
|
for (i = 0; i < obufbuf_cnt; i++) {
|
|
|
|
printf(" %02x", obufbuf[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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
|
|
|
printf("\nStatus: %d\n", usb_ep_0_out_ev_pending_read());
|
|
|
|
get_print_status();
|
|
|
|
usb_pullup_out_write(1);
|
|
|
|
usb_ep_0_out_ev_pending_write((1 << 1));
|
|
|
|
printf("Status: %d\n", usb_ep_0_out_obuf_empty_read());
|
|
|
|
get_print_status();
|
2019-01-01 14:10:02 +00:00
|
|
|
|
2019-01-01 02:23:52 +00:00
|
|
|
printf("Hello, world!\n");
|
2019-01-23 02:25:07 +00:00
|
|
|
|
|
|
|
int last_event = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
elapsed(&last_event, 1000);
|
|
|
|
|
|
|
|
get_print_status();
|
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
|
|
|
}
|