aboutsummaryrefslogtreecommitdiff
path: root/src/sys/core.c
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2021-12-23 21:42:32 -0800
committerChristian Cunningham <cc@localhost>2021-12-23 21:42:32 -0800
commit9bc94963aefcb5028c3529ff59c974e48d814690 (patch)
treeeb90b58da616bce55176b4f8f72a238cce19cd0d /src/sys/core.c
parenta905c499ceddc47a5fcd46f863e453919c196722 (diff)
Intro USB
Diffstat (limited to 'src/sys/core.c')
-rw-r--r--src/sys/core.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/sys/core.c b/src/sys/core.c
index ed88570..3f2d117 100644
--- a/src/sys/core.c
+++ b/src/sys/core.c
@@ -1,5 +1,6 @@
#include "../cpu/irq.h"
#include "../drivers/uart.h"
+#include "../drivers/usb.h"
#include "../graphics/lfb.h"
#include "../graphics/drawer.h"
#include "../lib/mem.h"
@@ -18,14 +19,44 @@ char* os_info_v = VERSION;
// Initialize IRQs
void sysinit() {
+ // Route GPU interrupts to Core 0
+ store32(0x00, GPU_INTERRUPTS_ROUTING);
+
// Mask Overrun of UART0
store32(1<<4, UART0_IMSC);
// Enable UART GPU IRQ
store32(1<<25, IRQ_ENABLE2);
- // Route GPU interrupts to Core 0
- store32(0x00, GPU_INTERRUPTS_ROUTING);
+ // Enable USB Interrupt
+ store32(1<<9, IRQ_ENABLE1);
+ // USB Host power on
+ // HPRT.PrtPwr = 1'b1 -> HPRT.PrtRst = 1'b1 -> wait 60msec -> HPRT.PrtRst = 1'b0
+ *USB_HOST_HPRT |= 1 << 12;
+ *USB_HOST_HPRT |= 1 << 8;
+ delay(0x100000);
+ *USB_HOST_HPRT &= ~(1 << 8);
+
+ // enable irq
+ // GAHBCFG.GlblIntrMsk = 1'b1
+ // GINTMSK.ConIDStsChngMsk = 1'b1, GINTMSK.PrtIntMsk = 1'b1, GINTMSK.SofMsk = 1'b1
+ *USB_CORE_GAHBCFG |= 1;
+ *USB_CORE_GINTMSK = 1 << 28 | 1 << 24 | 0 << 3;
+
+ // port enable and retry detect
+ // HPRT.PrtPwr = 1'b1, HPRT.PrtEnChng = 1'b1, HPRT.PrtConnDet = 1'b1
+ *USB_HOST_HPRT = 1 << 12 | 1 << 3 | 1 << 1;
+
+ // enable channel irq
+ // HAINTMASK.HAINTMsk = 16'h3
+ // HCINTMSK0.XferComplMsk = 1'b1
+ *USB_HOST_HAINTMSK |= 0x3;
+ *USB_HOST_HCINTMSK0 |= 1;
+ *USB_HOST_HCINTMSK1 |= 1;
+
+ // HCCAR1.EPDir = 1'b0 (OUT) / 1'b01(IN), HCCAR1.MPS = 11'h40
+ *USB_HOST_HCCHAR0 |= 0x40; // OUT
+ *USB_HOST_HCCHAR1 |= 1 << 15 | 0x40; // IN
// Enable Timer
// As an IRQ
@@ -128,4 +159,10 @@ void postinit() {
}
write_string(&g_Drawer, "\n> ");
+
+ send_packet();
+ for (int i = 0; i < 18; i++) {
+ uart_hex(usb_buffer1[i]);
+ uart_char('\n');
+ }
}