summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2007-09-30 08:18:46 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2007-09-30 08:18:46 +0000
commita5e788fe8533f6172b3d6b52d2430fe163f7a6fd (patch)
tree3c02a246e903d743126658bfb94bbacbdeba8fc4 /firmware/target/arm
parentf548336e271f970d7ccd8a84e85ce8590ff7deab (diff)
slow - but working - IRQ based uart/button driver.
change some of the uart function names from CamelCase git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14908 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/olympus/mrobe-500/button-mr500.c14
-rw-r--r--firmware/target/arm/olympus/mrobe-500/uart-mr500.c52
-rw-r--r--firmware/target/arm/olympus/mrobe-500/uart-target.h10
3 files changed, 59 insertions, 17 deletions
diff --git a/firmware/target/arm/olympus/mrobe-500/button-mr500.c b/firmware/target/arm/olympus/mrobe-500/button-mr500.c
index 7410875fd1..1d0d2714a8 100644
--- a/firmware/target/arm/olympus/mrobe-500/button-mr500.c
+++ b/firmware/target/arm/olympus/mrobe-500/button-mr500.c
@@ -37,7 +37,7 @@
void button_init_device(void)
{
/* GIO is the power button, set as input */
- IO_GIO_DIR0|=0x01;
+ IO_GIO_DIR0 |= 0x01;
}
inline bool button_hold(void)
@@ -48,20 +48,17 @@ inline bool button_hold(void)
int button_read_device(void)
{
char data[5], c;
- int val;
int i = 0;
- int btn = BUTTON_NONE, timeout = BUTTON_TIMEOUT;
+ int btn = BUTTON_NONE;
if ((IO_GIO_BITSET0&0x01) == 0)
btn |= BUTTON_POWER;
- uartHeartbeat();
- while (timeout > 0)
+ uart1_heartbeat();
+ while (uartAvailable())
{
- val = uartPollch(BUTTON_TIMEOUT*100);
- if (val > -1)
+ if (uart1_getch(&c))
{
- c = val&0xff;
if (i && (data[0] == BUTTON_START_BYTE || data[0] == BUTTON_START_BYTE2))
{
data[i++] = c;
@@ -94,7 +91,6 @@ int button_read_device(void)
break;
}
}
- timeout--;
}
return btn;
}
diff --git a/firmware/target/arm/olympus/mrobe-500/uart-mr500.c b/firmware/target/arm/olympus/mrobe-500/uart-mr500.c
index 99cf0f2d36..66e59eaaac 100644
--- a/firmware/target/arm/olympus/mrobe-500/uart-mr500.c
+++ b/firmware/target/arm/olympus/mrobe-500/uart-mr500.c
@@ -23,7 +23,10 @@
/* UART 0/1 */
-#define CONFIG_UART_BRSR 87
+#define CONFIG_UART_BRSR 87
+#define MAX_UART_BUFFER 32
+static unsigned char uart1buffer[MAX_UART_BUFFER];
+int uart1read = 0, uart1write = 0, uart1count = 0;
void do_checksums(char *data, int len, char *xor, char *add)
{
@@ -37,10 +40,24 @@ void do_checksums(char *data, int len, char *xor, char *add)
}
}
-void uartSetup(void) {
+void uart_init(void)
+{
// 8-N-1
IO_UART1_MSR=0x8000;
IO_UART1_BRSR=CONFIG_UART_BRSR;
+ IO_UART1_RFCR = 0x8000;
+ /* gio 27 is input, uart1 rx
+ gio 28 is output, uart1 tx */
+ IO_GIO_DIR1 |= (1<<11); /* gio 27 */
+ IO_GIO_DIR1 &= ~(1<<12); /* gio 28 */
+
+ /* init the recieve buffer */
+ uart1read = 0;
+ uart1write = 0;
+ uart1count = 0;
+
+ /* Enable the interrupt */
+ IO_INTC_EINT0 |= (1<<IRQ_UART1);
}
void uartPutc(char ch) {
@@ -111,10 +128,10 @@ int uartPollch(unsigned int ticks) {
bool uartAvailable(void)
{
- return (IO_UART1_RFCR & 0x3f)?true:false;
+ return uart1count > 0;
}
-void uartHeartbeat(void)
+void uart1_heartbeat(void)
{
char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
uartPuts(data);
@@ -126,3 +143,30 @@ void uartSendData(char* data, int len)
for(i=0;i<len;i++)
uartPutc(data[i]);
}
+
+bool uart1_getch(char *c)
+{
+ if (uart1count > 0)
+ {
+ *c = uart1buffer[uart1read];
+ uart1read = (uart1read+1) % MAX_UART_BUFFER;
+ uart1count--;
+ return true;
+ }
+ return false;
+}
+
+/* UART1 receive intterupt handler */
+void UART1(void)
+{
+ if (IO_UART1_RFCR & 0x3f)
+ {
+ if (uart1count >= MAX_UART_BUFFER)
+ panicf("UART1 buffer overflow");
+ uart1buffer[uart1write] = IO_UART1_DTRR & 0xff;
+ uart1write = (uart1write+1) % MAX_UART_BUFFER;
+ uart1count++;
+ }
+
+ IO_INTC_IRQ0 = (1<<IRQ_UART1);
+}
diff --git a/firmware/target/arm/olympus/mrobe-500/uart-target.h b/firmware/target/arm/olympus/mrobe-500/uart-target.h
index b4e049f897..f077dc1025 100644
--- a/firmware/target/arm/olympus/mrobe-500/uart-target.h
+++ b/firmware/target/arm/olympus/mrobe-500/uart-target.h
@@ -20,12 +20,14 @@
#ifndef UART_H
#define UART_H
-void uartPutc(char ch);
-void uartPutHex(unsigned int n);
-void uartSetup(void);
+void uart_init(void);
+bool uart1_getch(char *c);
+void uart1_heartbeat(void);
+
void uartPuts(const char *str);
void uartGets(char *str, unsigned int size);
int uartPollch(unsigned int ticks);
-void uartHeartbeat(void);
+void uartPutc(char ch);
+void uartPutHex(unsigned int n);
#endif