From 3506cb0ba29e2b803957346cfd39d4b63fe3e752 Mon Sep 17 00:00:00 2001 From: ikari Date: Sat, 14 Jan 2012 01:05:15 +0100 Subject: [PATCH] Firmware/bootldr: size reduction and stability measures --- src/bootldr/clock.c | 4 +-- src/bootldr/config.h | 2 +- src/bootldr/ffconf.h | 4 +-- src/bootldr/iap.c | 19 +++++++++++--- src/bootldr/timer.c | 46 --------------------------------- src/bootldr/uart.c | 61 +++----------------------------------------- 6 files changed, 23 insertions(+), 113 deletions(-) diff --git a/src/bootldr/clock.c b/src/bootldr/clock.c index d766ae6..8bd7914 100644 --- a/src/bootldr/clock.c +++ b/src/bootldr/clock.c @@ -14,8 +14,8 @@ void clock_disconnect() { void clock_init() { -/* set flash access time to 5 clks (80RICTRL = BV(RITINT); - NVIC_ClearPendingIRQ(RIT_IRQn); - wokefromrit = 1; - RIT_Hook(); -} - void timer_init(void) { /* turn on power to RIT */ BITBAND(LPC_SC->PCONP, PCRIT) = 1; @@ -54,8 +28,6 @@ void timer_init(void) { /* PCLK = CCLK */ BITBAND(LPC_SC->PCLKSEL1, 26) = 1; BITBAND(LPC_SC->PCLKSEL1, PCLK_TIMER3) = 1; - /* enable SysTick */ - SysTick_Config((SysTick->CALIB & SysTick_CALIB_TENMS_Msk)); } void delay_us(unsigned int time) { @@ -84,21 +56,3 @@ void delay_ms(unsigned int time) { LPC_RIT->RICTRL = 0; } -void sleep_ms(unsigned int time) { - - wokefromrit = 0; - /* Prepare RIT */ - LPC_RIT->RICOUNTER = 0; - LPC_RIT->RICOMPVAL = (CONFIG_CPU_FREQUENCY / 1000) * time; - LPC_RIT->RICTRL = BV(RITEN) | BV(RITINT); - NVIC_EnableIRQ(RIT_IRQn); - - /* Wait until RIT signals an interrupt */ -//uart_putc(';'); - while(!wokefromrit) { - __WFI(); - } - NVIC_DisableIRQ(RIT_IRQn); - /* Disable RIT */ - LPC_RIT->RICTRL = BV(RITINT); -} diff --git a/src/bootldr/uart.c b/src/bootldr/uart.c index 15fee39..d5f224f 100644 --- a/src/bootldr/uart.c +++ b/src/bootldr/uart.c @@ -74,65 +74,14 @@ } } */ -static char txbuf[1 << CONFIG_UART_TX_BUF_SHIFT]; +//static char txbuf[1 << CONFIG_UART_TX_BUF_SHIFT]; static volatile unsigned int read_idx,write_idx; -void UART_HANDLER(void) { - int iir = UART_REGS->IIR; - if (!(iir & 1)) { - /* Interrupt is pending */ - switch (iir & 14) { -#if CONFIG_UART_NUM == 1 - case 0: /* modem status */ - (void) UART_REGS->MSR; // dummy read to clear - break; -#endif - - case 2: /* THR empty - send */ - if (read_idx != write_idx) { - int maxchars = 16; - while (read_idx != write_idx && --maxchars > 0) { - UART_REGS->THR = (unsigned char)txbuf[read_idx]; - read_idx = (read_idx+1) & (sizeof(txbuf)-1); - } - if (read_idx == write_idx) { - /* buffer empty - turn off THRE interrupt */ - BITBAND(UART_REGS->IER, 1) = 0; - } - } - break; - - case 12: /* RX timeout */ - case 4: /* data received - not implemented yet */ - (void) UART_REGS->RBR; // dummy read to clear - break; - - case 6: /* RX error */ - (void) UART_REGS->LSR; // dummy read to clear - - default: break; - } - } -} - void uart_putc(char c) { if (c == '\n') uart_putc('\r'); - - unsigned int tmp = (write_idx+1) & (sizeof(txbuf)-1) ; - - if (read_idx == write_idx && (BITBAND(UART_REGS->LSR, 5))) { - /* buffer empty, THR empty -> send immediately */ - UART_REGS->THR = (unsigned char)c; - } else { -#ifdef CONFIG_UART_DEADLOCKABLE - while (tmp == read_idx) ; -#endif - BITBAND(UART_REGS->IER, 1) = 0; // turn off UART interrupt - txbuf[write_idx] = c; - write_idx = tmp; - BITBAND(UART_REGS->IER, 1) = 1; - } + while(!(UART_REGS->LSR & (0x20))); + UART_REGS->THR = c; } /* Polling version only */ @@ -183,10 +132,6 @@ void uart_init(void) { /* reset and enable FIFO */ UART_REGS->FCR = BV(0); - /* enable transmit interrupt */ - BITBAND(UART_REGS->IER, 1) = 1; - NVIC_EnableIRQ(UART_IRQ); - UART_REGS->THR = '?'; }