|
@@ -18,7 +18,7 @@
|
|
|
#include <LPC24xx.h>
|
|
|
#include "board.h"
|
|
|
|
|
|
-/* #define BOARD_DEBUG */
|
|
|
+/* #define RT_BOARD_DEBUG */
|
|
|
|
|
|
#define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */
|
|
|
|
|
@@ -36,17 +36,63 @@ void rt_timer_handler(int vector)
|
|
|
T0IR |= 0x01; /* clear interrupt flag */
|
|
|
rt_tick_increase();
|
|
|
VICVectAddr = 0; /* Acknowledge Interrupt */
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * This function is used to display a string on console, normally, it's
|
|
|
+ * invoked by rt_kprintf
|
|
|
+ *
|
|
|
+ * @param str the displayed string
|
|
|
+ */
|
|
|
+void rt_hw_console_output(const char* str)
|
|
|
+{
|
|
|
+ while (*str)
|
|
|
+ {
|
|
|
+ if (*str=='\n')
|
|
|
+ {
|
|
|
+ while (!(U0LSR & 0x20));
|
|
|
+ U0THR = '\r';
|
|
|
+ }
|
|
|
+
|
|
|
+ while (!(U0LSR & 0x20));
|
|
|
+ U0THR = *str;
|
|
|
+
|
|
|
+ str ++;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#define BAUD_RATE 115200
|
|
|
+#define U0PINS 0x50
|
|
|
+void rt_hw_console_init()
|
|
|
+{
|
|
|
+ rt_uint32_t fdiv;
|
|
|
+
|
|
|
+ /* Enable RxD and TxD pins */
|
|
|
+ PINSEL0 = U0PINS;
|
|
|
+
|
|
|
+ /* 8 bits, no Parity, 1 Stop bit */
|
|
|
+ U0LCR = 0x83;
|
|
|
+
|
|
|
+ /* Setup Baudrate */
|
|
|
+ fdiv = ( PCLK / 16 ) / BAUD_RATE ; /*baud rate */
|
|
|
+ U0DLM = fdiv / 256;
|
|
|
+ U0DLL = fdiv % 256;
|
|
|
+ U0FCR = 0x00; /* Enable and reset TX and RX FIFO. */
|
|
|
+ U0LCR = 0x03; /* DLAB = 0 */
|
|
|
+
|
|
|
+ /* DLAB = 0 */
|
|
|
+ U0LCR = 0x03;
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* This function will init LPC2478 board
|
|
|
*/
|
|
|
void rt_hw_board_init()
|
|
|
{
|
|
|
- extern void rt_serial_init(void);
|
|
|
- /* init hardware serial */
|
|
|
- rt_serial_init();
|
|
|
-
|
|
|
+ /* init console for rt_kprintf function */
|
|
|
+ rt_hw_console_init();
|
|
|
+
|
|
|
T0IR = 0xff;
|
|
|
T0TC = 0;
|
|
|
T0MCR = 0x03;
|
|
@@ -58,148 +104,4 @@ void rt_hw_board_init()
|
|
|
T0TCR = 0x01; //enable timer0 counter
|
|
|
}
|
|
|
|
|
|
-/******************************************************************************
|
|
|
-** Function name: TargetInit
|
|
|
-**
|
|
|
-** Descriptions: Initialize the target board; it is called in a necessary
|
|
|
-** place, change it as needed
|
|
|
-**
|
|
|
-** parameters: None
|
|
|
-** Returned value: None
|
|
|
-**
|
|
|
-******************************************************************************/
|
|
|
-void TargetInit(void)
|
|
|
-{
|
|
|
- /* Add your codes here */
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-/******************************************************************************
|
|
|
-** Function name: GPIOResetInit
|
|
|
-**
|
|
|
-** Descriptions: Initialize the target board before running the main()
|
|
|
-** function; User may change it as needed, but may not
|
|
|
-** deleted it.
|
|
|
-**
|
|
|
-** parameters: None
|
|
|
-** Returned value: None
|
|
|
-**
|
|
|
-******************************************************************************/
|
|
|
-void GPIOResetInit( void )
|
|
|
-{
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-/******************************************************************************
|
|
|
-** Function name: ConfigurePLL
|
|
|
-**
|
|
|
-** Descriptions: Configure PLL switching to main OSC instead of IRC
|
|
|
-** at power up and wake up from power down.
|
|
|
-** This routine is used in TargetResetInit() and those
|
|
|
-** examples using power down and wake up such as
|
|
|
-** USB suspend to resume, ethernet WOL, and power management
|
|
|
-** example
|
|
|
-** parameters: None
|
|
|
-** Returned value: None
|
|
|
-**
|
|
|
-******************************************************************************/
|
|
|
-void ConfigurePLL ( void )
|
|
|
-{
|
|
|
- unsigned long MValue, NValue;
|
|
|
-
|
|
|
- if ( PLLSTAT & (1 << 25) )
|
|
|
- {
|
|
|
- PLLCON = 1; /* Enable PLL, disconnected */
|
|
|
- PLLFEED = 0xaa;
|
|
|
- PLLFEED = 0x55;
|
|
|
- }
|
|
|
-
|
|
|
- PLLCON = 0; /* Disable PLL, disconnected */
|
|
|
- PLLFEED = 0xaa;
|
|
|
- PLLFEED = 0x55;
|
|
|
-
|
|
|
- SCS |= 0x20; /* Enable main OSC */
|
|
|
- while( !(SCS & 0x40) ); /* Wait until main OSC is usable */
|
|
|
-
|
|
|
- CLKSRCSEL = 0x1; /* select main OSC, 12MHz, as the PLL clock source */
|
|
|
-
|
|
|
- PLLCFG = PLL_MValue | (PLL_NValue << 16);
|
|
|
- PLLFEED = 0xaa;
|
|
|
- PLLFEED = 0x55;
|
|
|
-
|
|
|
- PLLCON = 1; /* Enable PLL, disconnected */
|
|
|
- PLLFEED = 0xaa;
|
|
|
- PLLFEED = 0x55;
|
|
|
-
|
|
|
- CCLKCFG = CCLKDivValue; /* Set clock divider */
|
|
|
-#if USE_USB
|
|
|
- USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */
|
|
|
-#endif
|
|
|
-
|
|
|
- while ( ((PLLSTAT & (1 << 26)) == 0) ); /* Check lock bit status */
|
|
|
-
|
|
|
- MValue = PLLSTAT & 0x00007FFF;
|
|
|
- NValue = (PLLSTAT & 0x00FF0000) >> 16;
|
|
|
- while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) );
|
|
|
-
|
|
|
- PLLCON = 3; /* enable and connect */
|
|
|
- PLLFEED = 0xaa;
|
|
|
- PLLFEED = 0x55;
|
|
|
- while ( ((PLLSTAT & (1 << 25)) == 0) ); /* Check connect bit status */
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-/******************************************************************************
|
|
|
-** Function name: TargetResetInit
|
|
|
-**
|
|
|
-** Descriptions: Initialize the target board before running the main()
|
|
|
-** function; User may change it as needed, but may not
|
|
|
-** deleted it.
|
|
|
-**
|
|
|
-** parameters: None
|
|
|
-** Returned value: None
|
|
|
-**
|
|
|
-******************************************************************************/
|
|
|
-void TargetResetInit(void)
|
|
|
-{
|
|
|
- MEMMAP = 0x1; /* remap to internal flash */
|
|
|
-
|
|
|
-#if USE_USB
|
|
|
- PCONP |= 0x80000000; /* Turn On USB PCLK */
|
|
|
-#endif
|
|
|
- /* Configure PLL, switch from IRC to Main OSC */
|
|
|
- ConfigurePLL();
|
|
|
-
|
|
|
- /* Set system timers for each component */
|
|
|
-#if (Fpclk / (Fcclk / 4)) == 1
|
|
|
- PCLKSEL0 = 0x00000000; /* PCLK is 1/4 CCLK */
|
|
|
- PCLKSEL1 = 0x00000000;
|
|
|
-#endif
|
|
|
-#if (Fpclk / (Fcclk / 4)) == 2
|
|
|
- PCLKSEL0 = 0xAAAAAAAA; /* PCLK is 1/2 CCLK */
|
|
|
- PCLKSEL1 = 0xAAAAAAAA;
|
|
|
-#endif
|
|
|
-#if (Fpclk / (Fcclk / 4)) == 4
|
|
|
- PCLKSEL0 = 0x55555555; /* PCLK is the same as CCLK */
|
|
|
- PCLKSEL1 = 0x55555555;
|
|
|
-#endif
|
|
|
-
|
|
|
- /* Set memory accelerater module*/
|
|
|
- MAMCR = 0;
|
|
|
-#if Fcclk < 20000000
|
|
|
- MAMTIM = 1;
|
|
|
-#else
|
|
|
-#if Fcclk < 40000000
|
|
|
- MAMTIM = 2;
|
|
|
-#else
|
|
|
- MAMTIM = 3;
|
|
|
-#endif
|
|
|
-#endif
|
|
|
- MAMCR = 2;
|
|
|
-
|
|
|
- GPIOResetInit();
|
|
|
-
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
/*@}*/
|