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-03-28 03:13:25 +00:00
|
|
|
#include <dfu.h>
|
2019-04-02 10:10:56 +00:00
|
|
|
#include <rgb.h>
|
2019-03-28 03:13:25 +00:00
|
|
|
#include <spi.h>
|
2019-01-01 14:10:02 +00:00
|
|
|
#include <generated/csr.h>
|
|
|
|
|
2019-03-25 09:39:06 +00:00
|
|
|
struct ff_spi *spi;
|
|
|
|
|
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
|
|
|
|
2019-03-28 03:13:25 +00:00
|
|
|
#ifdef CSR_UART_BASE
|
2019-01-01 14:37:14 +00:00
|
|
|
if (irqs & (1 << UART_INTERRUPT))
|
|
|
|
uart_isr();
|
2019-03-28 03:13:25 +00:00
|
|
|
#endif
|
2019-01-01 14:10:02 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 03:13:25 +00:00
|
|
|
#ifdef CSR_UART_BASE
|
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-03-28 03:13:25 +00:00
|
|
|
#endif
|
2019-01-01 14:10:02 +00:00
|
|
|
|
2019-01-23 02:25:07 +00:00
|
|
|
static void init(void)
|
|
|
|
{
|
2019-03-28 03:13:25 +00:00
|
|
|
#ifdef CSR_UART_BASE
|
2019-01-25 01:28:03 +00:00
|
|
|
init_printf(NULL, rv_putchar);
|
2019-03-28 03:13:25 +00:00
|
|
|
#endif
|
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-03-26 01:39:55 +00:00
|
|
|
dfu_init();
|
2019-01-23 02:25:07 +00:00
|
|
|
time_init();
|
2019-04-02 10:10:56 +00:00
|
|
|
rgb_init();
|
2019-03-25 09:39:06 +00:00
|
|
|
|
|
|
|
spi = spiAlloc();
|
|
|
|
spiSetPin(spi, SP_MOSI, 0);
|
|
|
|
spiSetPin(spi, SP_MISO, 1);
|
|
|
|
spiSetPin(spi, SP_WP, 2);
|
|
|
|
spiSetPin(spi, SP_HOLD, 3);
|
|
|
|
spiSetPin(spi, SP_CLK, 4);
|
|
|
|
spiSetPin(spi, SP_CS, 5);
|
|
|
|
spiSetPin(spi, SP_D0, 0);
|
|
|
|
spiSetPin(spi, SP_D1, 1);
|
|
|
|
spiSetPin(spi, SP_D2, 2);
|
|
|
|
spiSetPin(spi, SP_D3, 3);
|
|
|
|
spiInit(spi);
|
2019-01-01 14:10:02 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 01:39:55 +00:00
|
|
|
#if 0
|
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
|
|
|
}
|
2019-03-26 01:39:55 +00:00
|
|
|
#endif
|
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
|
|
|
usb_connect();
|
2019-01-23 02:25:07 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2019-03-28 03:13:25 +00:00
|
|
|
usb_poll(NULL);
|
2019-04-05 07:10:19 +00:00
|
|
|
dfu_poll();
|
2019-03-28 03:13:25 +00:00
|
|
|
// if (i > 200)
|
|
|
|
// reboot_ctrl_write(0xac);
|
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
|
|
|
}
|