Bye bye Wii Motion Plus, hello MPU6050. Also, increase control loop
to 200Hz, add SD card logging, and a number of other changes.
This commit is contained in:
62
uart.c
62
uart.c
@@ -2,6 +2,8 @@
|
||||
#include "types.h"
|
||||
#include "interrupt.h"
|
||||
#include "event.h"
|
||||
#include "led.h"
|
||||
#include "panic.h"
|
||||
|
||||
#define UARTBASE 0xE000C000
|
||||
|
||||
@@ -30,10 +32,10 @@
|
||||
|
||||
char uart_txbuf[UART_TXBUFSIZE];
|
||||
char uart_rxbuf[UART_RXBUFSIZE];
|
||||
volatile int uart_txread;
|
||||
volatile int uart_txwrite;
|
||||
volatile int uart_rxread;
|
||||
volatile int uart_rxwrite;
|
||||
volatile unsigned int uart_txread;
|
||||
volatile unsigned int uart_txwrite;
|
||||
volatile unsigned int uart_rxread;
|
||||
volatile unsigned int uart_rxwrite;
|
||||
volatile bool tx_running;
|
||||
|
||||
void __attribute__((interrupt("IRQ"))) uart_interrupt_handler(void);
|
||||
@@ -46,7 +48,7 @@ void init_uart(void)
|
||||
|
||||
UREG(LCR) = 0x80;
|
||||
UREG(DLM) = 0x00;
|
||||
UREG(DLL) = 0x08; /* 14745600 / (16*115200) */
|
||||
UREG(DLL) = 0x20; /* 58982400 / (16*115200) */
|
||||
UREG(LCR) = 0x13;
|
||||
UREG(FCR) = 0x07;
|
||||
|
||||
@@ -61,9 +63,42 @@ void init_uart(void)
|
||||
}
|
||||
|
||||
void putch(char c) {
|
||||
CHECKPOINT(4);
|
||||
/* Wait for space in the buffer */
|
||||
while (uart_txread == ((uart_txwrite+1) % UART_TXBUFSIZE));
|
||||
while (uart_txread == ((uart_txwrite+1) % UART_TXBUFSIZE)) ;
|
||||
|
||||
interrupt_block();
|
||||
|
||||
if (uart_txread == uart_txwrite) {
|
||||
if (U0THRE) {
|
||||
tx_running = TRUE;
|
||||
UREG(THR) = c;
|
||||
interrupt_unblock();
|
||||
CHECKPOINT(5);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uart_txbuf[uart_txwrite] = c;
|
||||
uart_txwrite = (uart_txwrite + 1) % UART_TXBUFSIZE;
|
||||
|
||||
if (!tx_running) {
|
||||
if (uart_txread != uart_txwrite) {
|
||||
tx_running = TRUE;
|
||||
uart_txread = (uart_txread + 1) % UART_TXBUFSIZE;
|
||||
UREG(THR) = c;
|
||||
}
|
||||
}
|
||||
interrupt_unblock();
|
||||
CHECKPOINT(5);
|
||||
}
|
||||
|
||||
void putch_irq(char c) {
|
||||
/* Hope for space in the buffer */
|
||||
// if (uart_txread == ((uart_txwrite+1) % UART_TXBUFSIZE))
|
||||
// return;
|
||||
|
||||
#if 1
|
||||
if (uart_txread == uart_txwrite) {
|
||||
if (U0THRE) {
|
||||
tx_running = TRUE;
|
||||
@@ -82,6 +117,9 @@ void putch(char c) {
|
||||
UREG(THR) = c;
|
||||
}
|
||||
}
|
||||
#else
|
||||
UREG(THR) = c;
|
||||
#endif
|
||||
}
|
||||
|
||||
void __attribute__((interrupt("IRQ"))) uart_interrupt_handler(void)
|
||||
@@ -93,10 +131,12 @@ void __attribute__((interrupt("IRQ"))) uart_interrupt_handler(void)
|
||||
* to treat them as such in this handler, so let the compiler
|
||||
* have an easier time.
|
||||
*/
|
||||
int local_txwrite;
|
||||
int local_txread;
|
||||
int local_rxwrite;
|
||||
int local_rxread;
|
||||
unsigned int local_txwrite;
|
||||
unsigned int local_txread;
|
||||
unsigned int local_rxwrite;
|
||||
unsigned int local_rxread;
|
||||
|
||||
CHECKPOINT(((checkpoint & 0x00ff) | 0x0100));
|
||||
|
||||
source = UREG(IIR);
|
||||
|
||||
@@ -136,6 +176,8 @@ void __attribute__((interrupt("IRQ"))) uart_interrupt_handler(void)
|
||||
break;
|
||||
}
|
||||
|
||||
CHECKPOINT((checkpoint & 0x00ff) | 0x0200);
|
||||
|
||||
interrupt_clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user