The unified diff between revisions [b85a3bbc..] and [961b04dd..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'main.c'
# # old_revision [b85a3bbccc40f21e02f50101af764be93eeb9538] # new_revision [961b04ddb07ba2b5dd6bccfa66a03e442e40d8f0] # # patch "main.c" # from [3a525d062c198ad4a596f4bfb7360c3acbf5acfb] # to [f3f04a92cb8f9ba8fdecd0b2fd95773011c1e076] # ============================================================ --- main.c 3a525d062c198ad4a596f4bfb7360c3acbf5acfb +++ main.c f3f04a92cb8f9ba8fdecd0b2fd95773011c1e076 @@ -2,93 +2,17 @@ #include "wmp.h" #include "i2c.h" #include "timer.h" +#include "uart.h" +#include "interrupt.h" -#define UARTBASE 0xE000C000 - -#define RBR 0x00 -#define THR 0x00 -#define DLL 0x00 -#define DLM 0x04 -#define IER 0x04 -#define IIR 0x08 -#define FCR 0x08 - -#define LCR 0x0c -#define LSR 0x14 -#define SCR 0x1c -#define ACR 0x20 -#define FDR 0x28 -#define TER 0x30 - -#define UREG(x) (((volatile unsigned char *)UARTBASE)[x]) - -#define U0THRE ((UREG(LSR) & (1<<5))) /* UART0 transmitter holding register is empty */ -#define U0DR ((UREG(LSR) & (1<<0))) /* UART0 data ready */ - #define PINSEL0 (*((volatile unsigned char *) 0xE002C000)) -void init_uart(void) -{ - UREG(FDR) = 0x10; /* DivAddVal = 0, MulVal = 1 */ - - UREG(LCR) = 0x80; - UREG(DLM) = 0x00; - UREG(DLL) = 0x08; /* 14745600 / (16*115200) */ - UREG(LCR) = 0x13; - UREG(FCR) = 0x07; -} - void init_pins(void) { PINSEL0 = 0x00000055; /* P0.0 and P0.1 assigned to UART */ /* P0.2 and P0.3 assigned to I2C */ } -void putch(char c) { - while (!U0THRE); - UREG(THR) = c; -} - -void putstr(char *s) { - while (*s) putch(*s++); -} - -void putint(unsigned int n) { - char s[11]; - int i; - - i = 10; - s[i] = '\0'; - - do { - s[--i] = n % 10 + '0'; - } while ((n /= 10) > 0); - - putstr(s+i); -} - -void puthex(unsigned int n) { - char s[9]; - int i; - - i = 8; - s[i] = '\0'; - - do { - int x = n % 16; - if (x > 9) - x += 'A' - '0' - 10; - s[--i] = x + '0'; - } while ((n /= 16) > 0); - - putstr(s+i); -} - -char getch(void) { - while (!U0DR); - return UREG(RBR); -} - void reply(char *str) { putstr(str); @@ -100,12 +24,12 @@ void minmax_sample(void) void minmax_sample(void) { int count; - int fast_roll_min, fast_roll_max; - int fast_pitch_min, fast_pitch_max; - int fast_yaw_min, fast_yaw_max; - int slow_roll_min, slow_roll_max; - int slow_pitch_min, slow_pitch_max; - int slow_yaw_min, slow_yaw_max; + unsigned int fast_roll_min, fast_roll_max; + unsigned int fast_pitch_min, fast_pitch_max; + unsigned int fast_yaw_min, fast_yaw_max; + unsigned int slow_roll_min, slow_roll_max; + unsigned int slow_pitch_min, slow_pitch_max; + unsigned int slow_yaw_min, slow_yaw_max; putstr("Sampling min/max values\r\n"); if (!wmp_sample()) { @@ -228,7 +152,7 @@ int main(void) { int main(void) { int i; - int data; + init_interrupt(); init_uart(); init_i2c(); init_pins(); @@ -331,6 +255,11 @@ int main(void) { puthex(timer_read()); reply("."); break; + case 'P': + putstr("Initialising timer... "); + timer_set_period(10000*TIMER_MS); + reply("done"); + break; default: reply("Unrecognised command."); break;