?? probe_rs232c.c
字號:
/*
*********************************************************************************************************
* uC/Probe Communication
*
* (c) Copyright 2007; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may NOT be used to develop a similar product.
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* uC/Probe
*
* Communication: RS-232
* Port for the NXP LPC21xx
*
* Filename : probe_rs232c.c
* Version : V1.00
* Programmer(s) : BAN
* Note(s) : (1) The UARTs on all NXP LPC21xx and LPC22xx controllers are supported by this port.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <probe_rs232.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/* ------------- Register Base Specifications ------------- */
#define U0_BASE ((CPU_INT32U)0xE000C000)
#define U1_BASE ((CPU_INT32U)0xE0010000)
#define VIC_BASE ((CPU_INT32U)0xFFFFF000)
#define PINSEL_BASE ((CPU_INT32U)0xE002C000)
/* ------------------ VIC Peripheral IDs ------------------ */
#define VIC_UART0 6
#define VIC_UART1 7
/* ---------------- UART0 Register Defines ---------------- */
#define U0RBR (*(CPU_INT08U *)(U0_BASE + 0x0000))
#define U0THR (*(CPU_INT08U *)(U0_BASE + 0x0000))
#define U0DLL (*(CPU_INT08U *)(U0_BASE + 0x0000))
#define U0DLM (*(CPU_INT08U *)(U0_BASE + 0x0004))
#define U0IER (*(CPU_INT08U *)(U0_BASE + 0x0004))
#define U0IIR (*(CPU_INT08U *)(U0_BASE + 0x0008))
#define U0FCR (*(CPU_INT08U *)(U0_BASE + 0x0008))
#define U0LCR (*(CPU_INT08U *)(U0_BASE + 0x000C))
#define U0LSR (*(CPU_INT08U *)(U0_BASE + 0x0014))
/* ---------------- UART1 Register Defines ---------------- */
#define U1RBR (*(CPU_INT08U *)(U1_BASE + 0x0000))
#define U1THR (*(CPU_INT08U *)(U1_BASE + 0x0000))
#define U1DLL (*(CPU_INT08U *)(U1_BASE + 0x0000))
#define U1DLM (*(CPU_INT08U *)(U1_BASE + 0x0004))
#define U1IER (*(CPU_INT08U *)(U1_BASE + 0x0004))
#define U1IIR (*(CPU_INT08U *)(U1_BASE + 0x0008))
#define U1FCR (*(CPU_INT08U *)(U1_BASE + 0x0008))
#define U1LCR (*(CPU_INT08U *)(U1_BASE + 0x000C))
#define U1LSR (*(CPU_INT08U *)(U1_BASE + 0x0014))
/* ---------- Pin Connect Block Register Defines ---------- */
#define PINSEL0 (*(CPU_INT32U *)(PINSEL_BASE + 0x0000))
#define PINSEL1 (*(CPU_INT32U *)(PINSEL_BASE + 0x0004))
#define PINSEL2 (*(CPU_INT32U *)(PINSEL_BASE + 0x0014))
/* ----------------- VIC Register Defines ----------------- */
#define VICIntSelect (*(CPU_INT32U *)(VIC_BASE + 0x000C))
#define VICIntEnable (*(CPU_INT32U *)(VIC_BASE + 0x0010))
#define VICVectAddr (*(CPU_INT32U *)(VIC_BASE + 0x0030))
#define VICVectAddr15 (*(CPU_INT32U *)(VIC_BASE + 0x013C))
#define VICVectCntl15 (*(CPU_INT32U *)(VIC_BASE + 0x023C))
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
extern CPU_INT32U BSP_CPU_PclkFreq (void);
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef PROBE_RS232_COMM_SEL
#error "PROBE_RS232_COMM_SEL not #define'd in 'probe_com_cfg.h' "
#error " [MUST be PROBE_RS232_UART_0 ] "
#error " [ || PROBE_RS232_UART_1 ] "
#elif (PROBE_RS232_COMM_SEL != PROBE_RS232_UART_0 ) && \
(PROBE_RS232_COMM_SEL != PROBE_RS232_UART_1 )
#error "PROBE_RS232_COMM_SEL illegally #define'd in 'probe_com_cfg.h' "
#error " [MUST be PROBE_RS232_UART_0 ] "
#error " [ || PROBE_RS232_UART_1 ] "
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* ProbeRS232_InitTarget()
*
* Description : Initialize the UART for uC/Probe communication.
*
* Argument(s) : baud_rate Intended baud rate of the RS-232.
*
* Return(s) : none.
*********************************************************************************************************
*/
void ProbeRS232_InitTarget (CPU_INT32U baud_rate)
{
CPU_INT16U div; /* Baud rate divisor */
CPU_INT08U divlo;
CPU_INT08U divhi;
CPU_INT32U pinsel;
CPU_INT32U pclk_freq;
/* --------------- COMPUTE DIVISOR BAUD RATE -------------- */
pclk_freq = BSP_CPU_PclkFreq(); /* Get the CPU clock frequency */
div = (CPU_INT16U)(((2 * pclk_freq / 16 / baud_rate) + 1) / 2);
divlo = div & 0x00FF; /* Split divisor into LOW and HIGH bytes */
divhi = (div >> 8) & 0x00FF;
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
/* ------------------- ENABLE UART0 I/Os ------------------ */
/* (1) P0[0] = Function 01b */
/* (2) P0[1] = Function 01b */
pinsel = PINSEL0;
pinsel &= 0xFFFFFFF0;
pinsel |= 0x00000005;
PINSEL0 = pinsel;
/* --------------------- SETUP UART0 ---------------------- */
U0LCR = DEF_BIT_07; /* Set divisor access bit */
U0DLL = divlo; /* Load divisor */
U0DLM = divhi;
U0LCR = 0x03; /* 8 Bits, 1 Stop, No Parity */
U0IER = 0x00; /* Disable both Rx and Tx interrupts */
U0FCR = DEF_BIT_00; /* Enable FIFO, flush Rx & Tx */
/* --------------- INITIALIZE VIC FOR UART0 --------------- */
VICIntSelect &= ~(1 << VIC_UART0); /* Enable interrupts */
VICVectAddr15 = (CPU_INT32U)ProbeRS232_RxTxISRHandler; /* Set the vector address */
VICVectCntl15 = 0x20 | VIC_UART0; /* Enable vectored interrupts */
VICIntEnable = (1 << VIC_UART0); /* Enable Interrupts */
#endif
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
/* ------------------- ENABLE UART1 I/Os ------------------ */
/* (1) P0[8] = Function 01b */
/* (2) P0[9] = Function 01b */
pinsel = PINSEL0;
pinsel &= 0xFFF0FFFF;
pinsel |= 0x00050000;
PINSEL0 = pinsel;
/* --------------------- SETUP UART1 ---------------------- */
U1LCR = DEF_BIT_07; /* Set divisor access bit */
U1DLL = divlo; /* Load divisor */
U1DLM = divhi;
U1LCR = 0x03; /* 8 Bits, 1 Stop, No Parity */
U1IER = 0x00; /* Disable both Rx and Tx interrupts */
U1FCR = DEF_BIT_00; /* Enable FIFO, flush Rx & Tx */
/* --------------- INITIALIZE VIC FOR UART1 --------------- */
VICIntSelect &= ~(1 << VIC_UART1); /* Enable interrupts */
VICVectAddr15 = (CPU_INT32U)ProbeRS232_RxTxISRHandler; /* Set the vector address */
VICVectCntl15 = 0x20 | VIC_UART1; /* Enable vectored interrupts */
VICIntEnable = (1 << VIC_UART1); /* Enable Interrupts */
#endif
}
/*
*********************************************************************************************************
* ProbeRS232_RxTxISRHandler()
*
* Description: Handle Rx and Tx interrupts.
*
* Argument(s): none.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -