⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c

📁 LPC22xx peripheral initialization
💻 C
字号:
//!  The peripheral initialisation starts here. 
/*!
  This is the init.c file where the init_peripheral() function is for initialisation of 
  other peripherals used for sniffing 
*/
#include <LPC22xx.h>      // Keil: Register definition file for LPC2294
#include "timer.h"
#include "SPI.h"
#include "UART.h"
#include "chip_sel.h"

//! The forward declartions.
/*! All the functions used in the init function block are declared in this block */
extern void InitialiseBuffers();
extern void init_peripheral_data(void);
extern char Local_Buffer[];
/**
******************************************************************************
  Module Name:	init_peripheral
  Module ID:
  Purpose:		initiliza the peripherals used for sniffing  
  Author:		Saud
  Date Written:	25-9-07
********************************************************************************/
//! The init_peripheral() function will initialise the peripherals for sniffing 
/*!
\function name init_peripheral()
\param void.
\return void.
*/
void init_peripheral(void)
{
	/*********************System Clock Initialisation to 60 MHz******************/
    VPBDIV =0x1; //  As PCLK = CPUCLK , CPU Clock = P CLK = 60 MHz 
	/*************************ADC*********************************************/
	ADCR   = 0x00210601;                   /* Setup A/D: 10-bit AIN0 @ 3MHz  */ 
	ADCR  |= 0x01000000;                   /* Start A/D Conversion for channel 0*/    
	/*************************Timer 1******************************************/
	PINSEL0     |=	 ((0x01<<21)|(0x01<<23));	// Enable CAP1.0 on P0.10 & CAP1.1 on P0.11   
	T1PR 		 = 0x59; 	
	T1TCR 		 = 0x00000002;			
    T1MCR 		 = 0x00000003;			
	T1MR0		 = 0x39386FF;			
	T1TCR 		 = 0x00000001;			 
	VICVectAddr0 = (unsigned int)timer1handler;
	VICVectCntl0 = 0x20 | 5; // Channel0 on Source#14 ... enabled
	VICIntEnable|= 0x00000020; // start timer for time stamping ***********
	/*************************SPI 0 Init *************************************/
	PINSEL0 |= (1<<8|1<<10|1<<12|1<<14); // configure SPI1 pins
    //  S0SPCR   = 0x08;                
	/************************SPI 1 init ************************************/
	PINSEL1 |= (1<<3|1<<5|1<<7|1<<9); // configure SPI1 pins
    //	S1SPCR  |=     0x08;       
	VICVectAddr2 = (unsigned long) SPI_ISR;
	VICVectCntl2 = 0x2B; // Channel0 on Source#11 ... enabled
	/************************Init UART ****************************************/
	PINSEL0 	   |= (1<<16|1<<18);//0x00050000;       /* Enable RxD1 and TxD1*/ 
//	U1LCR 	        = 0x00000083;       /* 8 bits, no Parity, 1 Stop bit */
//	U1DLL 	        = 0x00000020;       /* 115200 Baud Rate @ 60MHz VPB Clock  */
	U1LCR 	        = 0x00000003;       /* DLAB = 0             */
	U1FCR           = 0x07;			    /*Enable FIFOs & reset them	*/
	VICVectAddr4 	= (unsigned long)UART_ISR;		//pass the address of the IRQ into the VIC slot
	VICVectCntl4    =   0x20 | 7 ;  				//select priority slot 3 for UART1 int 
	U1IER           =   0x01;		 	 			//Enable only RDA interrupt for UART1                      
	/************************Timer 0 Capture init*************************/
	PINSEL0 	|=(1<<5);					//Enable pin 0.2 as capture 
	/***********************Chip select Falling edge*****************************/
	PINSEL0       |= ((1<<6)|(1<<7)); // P0.3 as EINT1 pin on 43B 
	VPBDIV         = 0;
	EXTMODE 	   = 0x02; // EINT0 is (falling) edge-sensitive
	VPBDIV         = 1; // additional step see errata
	VPBDIV         = 0;
	EXTPOLAR       = 0x00; // EINT0 is (falling) edge-sensitive
	VPBDIV         = 0;// additional step see errata
	VPBDIV         = 1;   // VPB clock = CPU clock
	VICVectAddr5 = (unsigned int)SPI_SOF_ISR;
	VICVectCntl5 = 0x2F; // Channel0 on Source#14 ... enabled
//	EXTINT |= 0x02; // Clear the peripheral interrupt flag		  
    /***********************Chip select Rising Edge*****************************/
	PINSEL0  |= (1<<31); // P0.15 as EINT2 pin on 28F
	VPBDIV = 0;
	EXTMODE |= (1<<2); // EINT2 is  edge-sensitive
	VPBDIV = 1; // additional step see errata
	VPBDIV = 0;
	EXTPOLAR |= (1<<2); // EINT2 is rising edge triggered
	VPBDIV = 0;	  // additional step see errata
	VPBDIV = 1;   // VPB clock = CPU clock
	VICVectAddr6 = (unsigned int)SPI_EOF_ISR;
	VICVectCntl6 = 0x30; // Channel0 on Source#16 ... enabled
//	EXTINT |= (1<<2); // Clear the peripheral interrupt flag		*/
	/**********************UART0 for Debugging************************************/
	PINSEL0 |= (1<<2|1<<0);                /* Enable RxD1 and TxD1              */
	U0LCR = 0x83;                          /* 8 bits, no Parity, 1 Stop bit     */
	U0DLL =135;//                          /* 9600 Baud Rate @ 15MHz VPB Clock  */
	U0DLM=1;
	U0LCR = 0x03;                          /* DLAB = 0                          */
	InitialiseBuffers();
}


/**
******************************************************************************
  Module Name:	Config_peripherals
  Module ID:
  Purpose:		Configure the peripherals as per user settings   
  Author:		Saud
  Date Written:	25-9-07
********************************************************************************/
//! The Config_peripherals() function will Configure the peripherals as per user settings 
/*!
\function name Config_peripherals()
\param void.
\return void.
*/

void Config_peripherals(void)
{
    S1SPCR  |=  Local_Buffer[0];  //0x88;     
    S0SPCR   =  Local_Buffer[0];  ///0x08;   
   	U1LCR 	 = 0x00000083;       /* 8 bits, no Parity, 1 Stop bit */
	U1DLL 	 = 0x00000020;       /* 115200 Baud Rate @ 60MHz VPB Clock  */

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -