#define disable_intr() asm volatile ("cpsid i")
#define mem_barrier() asm volatile ("dmb" ::: "memory")
-/*
#define delay(x) asm volatile ( \
"0: subs %0, %0, #1\n\t" \
"bne 0b\n\t" \
:: "r"(x) : "cc")
-*/
#endif /* ASM_H_ */
}
}
-void delay(uint32_t x); /* in startup.s */
-
static inline void gpio_pullups(uint32_t mask0, uint32_t mask1, int state)
{
REG_GPPUD = state;
--- /dev/null
+#include "ctype.h"
+
+int isalnum(int c)
+{
+ return isalpha(c) || isdigit(c);
+}
+
+int isalpha(int c)
+{
+ return isupper(c) || islower(c);
+}
+
+int isblank(int c)
+{
+ return c == ' ' || c == '\t';
+}
+
+int isdigit(int c)
+{
+ return c >= '0' && c <= '9';
+}
+
+int isupper(int c)
+{
+ return c >= 'A' && c <= 'Z';
+}
+
+int islower(int c)
+{
+ return c >= 'a' && c <= 'z';
+}
+
+int isgraph(int c)
+{
+ return c > ' ' && c <= '~';
+}
+
+int isprint(int c)
+{
+ return isgraph(c) || c == ' ';
+}
+
+int isspace(int c)
+{
+ return isblank(c) || c == '\f' || c == '\n' || c == '\r' || c == '\v';
+}
+
+int toupper(int c)
+{
+ return islower(c) ? (c + ('A' - 'a')) : c;
+}
+
+int tolower(int c)
+{
+ return isupper(c) ? (c + ('A' - 'a')) : c;
+}
--- /dev/null
+#ifndef CTYPES_H_
+#define CTYPES_H_
+
+int isalnum(int c);
+int isalpha(int c);
+#define isascii(c) ((c) < 128)
+int isblank(int c);
+int isdigit(int c);
+int isupper(int c);
+int islower(int c);
+int isprint(int c);
+int isspace(int c);
+
+int toupper(int c);
+int tolower(int c);
+
+
+#endif /* CTYPES_H_ */
}
return dest;
}
+
+int strcmp(const char *a, const char *b)
+{
+ while(*a && *a == *b) {
+ a++;
+ b++;
+ }
+
+ if(!*a && !*b) return 0;
+
+ if(!*a) return -1;
+ if(!*b) return 1;
+ return *a - *b > 0 ? 1 : -1;
+}
void *memset(void *ptr, int val, int size);
void *memcpy(void *dest, void *src, int size);
+int strcmp(const char *a, const char *b);
+
#endif /* LIBC_STRING_H_ */
#include <string.h>
#include <stdint.h>
+#include <ctype.h>
#include "asm.h"
#include "serial.h"
void dbgled(int x);
void exit(int x);
+static void cmdrun(char *cmd);
+
int main(void)
{
- disable_intr();
+ int lastnl = 0;
+ static char cmdbuf[256];
+ static int cmdend;
dbgled(2);
init_serial(115200);
- ser_printstr("starting rpkern\n");
+ ser_printstr("starting rpikern\n");
for(;;) {
int c = ser_getchar();
- if(c == -1) {
+
+ switch(c) {
+ case '\r':
+ case '\n':
+ if(!lastnl) {
+ ser_printstr("\r\n");
+ cmdbuf[cmdend] = 0;
+ cmdend = 0;
+ cmdrun(cmdbuf);
+ }
+ lastnl = 1;
+ break;
+
+ case -1:
+ lastnl = 0;
ser_printstr("error!\n");
- } else {
- ser_printstr("got: ");
+ break;
+
+ default:
+ lastnl = 0;
ser_putchar(c);
- ser_putchar('\r');
- ser_putchar('\n');
+ if(cmdend < sizeof cmdbuf) {
+ cmdbuf[cmdend++] = c;
+ }
}
}
dbgled(1);
exit(0);
}
+
+static void cmdrun(char *cmd)
+{
+ char *ptr, *args;
+
+ while(*cmd && isspace(*cmd)) cmd++;
+ ptr = cmd;
+ while(*ptr && !isspace(*ptr)) ptr++;
+ *ptr = 0;
+ args = ptr + 1;
+
+ if(strcmp(cmd, "help") == 0) {
+ ser_printstr("help not implemented yet\n");
+ } else if(strcmp(cmd, "ver") == 0) {
+ ser_printstr("rpikern version 0.0\n");
+ } else {
+ ser_printstr("Unknown command: ");
+ ser_printstr(cmd);
+ ser_printstr("\n");
+ }
+}
/* disable pullups for GPIO 14 & 15 */
gpio_pullups(0xc000, 0, PUD_DISABLE);
/* select alt0 function for GPIO 14 & 15 */
- gpio_fsel(14, FSEL_ALT0);
- gpio_fsel(15, FSEL_ALT0);
+ /*gpio_fsel(14, FSEL_ALT0);
+ gpio_fsel(15, FSEL_ALT0);*/
REG_ICR = 0x7ff; /* clear pending interrupts */
/* calculate baud rate divisor */
bdiv_fp6 = (UART_CLK << 6) / (16 * baud);
- REG_IBRD = 1;//(bdiv_fp6 >> 6) & 0xffff; /* 16 bits integer part */
- REG_FBRD = 40;//bdiv_fp6 & 0x3f; /* 6 bits fractional precision */
+ REG_IBRD = (bdiv_fp6 >> 6) & 0xffff; /* 16 bits integer part */
+ REG_FBRD = bdiv_fp6 & 0x3f; /* 6 bits fractional precision */
/* line control: fifo enable, 8n1 */
REG_LCRH = LCRH_FIFOEN | LCRH_8BITS;
streq r2, [r3, #0x28] @ GPCLR0
bx lr
- .global delay
-delay:
- subs r0, r0, #1
- bne delay
- bx lr
-
@ vi:set filetype=armasm:
#include "config.h"
#define UART0_BASE (IO_BASE | 0x201000)
-#define UART0_REG(x) *(volatile uint32_t*)(UART0_BASE | (x))
+#define UART0_REG(x) (*(volatile uint32_t*)(UART0_BASE | (x)))
#define REG_DR UART0_REG(0x00) /* data register */
#define REG_RSRECR UART0_REG(0x04) /* receive status & error clear */