今天的唯一成就吧,不过做完这些基本上事情也就完了。只是改动了串口的中断服务程序,也比较简单
/*
* This file is a sample test application
*
* This application is intended to test and/or illustrate some
* functionality of your system. The contents of this file may
* vary depending on the IP in your system and may use existing
* IP driver functions. These drivers will be generated in your
* XPS project when you run the "Generate Libraries" menu item
* in XPS.
*/
// Located in: ppc405_0/include/xparameters.h
#include "xparameters.h"
#include "stdio.h"
#include "xutil.h"
/* Begin user-supplied interrupt test routine */
/* This example demonstrates how to use an interrupt controller
* that responds to interrupts from two peripherals (UART and OPB_timer)
* in a PowerPC based system.
* This interrupt test routine has been added to the test application (TestApp_Memory)
* generated by the Base System Builder.
*/
#include "xgpio_l.h" /* general-purpose I/O peripheral control functions */
#include "xtmrctr_l.h" /* timer/counter peripheral control functions */
#include "xuartlite_l.h" /* uartlite peripheral control functions */
#include "xintc_l.h" /* interrupt controller peripheral control functions */
#include "xexception_l.h" /* PPC exception handler control functions */
#define LED_MSB 0x00000008 /* mask for position of left-most LED */
/* Global variables */
unsigned int led_data = 0; /* initial LED pattern when interrupt test begins */
unsigned int timer_count = 33554432; /* initial timer period in OPB cycles ~= 0.3 sec */
volatile unsigned int exit_command = 0; /* flag from UART ISR to exit InterruptTest routine */
int a[4];//保存临时数数组
int b[9];//未与默认值比较时的转换后数据
int input[9];//进行与默认值比较后转换所得所有数据
int j=0,h=0;
/* UART interrupt service routine */
void uart_int_handler(void* baseaddr_p){
char c;
int i,k,q;
while(!XUartLite_mIsReceiveEmpty(XPAR_RS232_UART_BASEADDR)){
/* read a character */
c=XUartLite_RecvByte(XPAR_RS232_UART_BASEADDR);
if((c!=13 ) && (c!=8 ))//判断是否为回车或者后退,如不是则为真
{
i=c-'0';
a[j]=i;
xil_printf("%d",i);
j=j+1;
}
else if(c==8)//如果是后退
{
j=j-1;
}
else if(c==13)//如果是回车
{print("/r/n");
k=j;j=0;
if (k==3)//判断位数并进行转换
q=a[0]*100+a[1]*10+a[2];
else if (k==2)
q=a[0]*10+a[1];
else if (k==1)
q=a[0];
else
q=0;//若没有输入则位数为0,此时将值置0
if(h<=8){
b[h]=q;
h=h+1;
switch(h){
case (1):
xil_printf("The frequency is%d/r/n",b[h-1]);
xil_printf("Please input the voltage level of the %d channel/r/n",h);break;
case(2):
xil_printf("The high voltage level of channel %d is %d/r/n",h-1,b[h-1]);
xil_printf("Please input the high voltage level of the %d channel/r/n",h);break;
case(3):
xil_printf("The high voltage level of channel %d is %d/r/n",h-1,b[h-1]);
xil_printf("Please input the high voltage level of the %d channel/r/n",h);break;
case(4):
xil_printf("The high voltage level of channel %d is %d/r/n",h-1,b[h-1]);
xil_printf("Please input the high voltage level of the %d channel/r/n",h);break;
case(5):
xil_printf("The high voltage level of channel %d is %d/r/n",h-1,b[h-1]);
xil_printf("Please input the high voltage level of the %d channel/r/n",h);break;
case(6):
xil_printf("The high voltage level of channel %d is %d/r/n",h-1,b[h-1]);
xil_printf("Please input the high voltage level of the %d channel/r/n",h);break;
case(7):
xil_printf("The high voltage level of channel %d is %d/r/n",h-1,b[h-1]);
xil_printf("Please input the high voltage level of the %d channel/r/n",h);break;
case(8):
xil_printf("The high voltage level of channel %d is %d/r/n",h-1,b[h-1]);
xil_printf("Please input the high voltage level of the %d channel/r/n",h);break;
case(9):
xil_printf("The high voltage level of channel %d is %d/r/n",h-1,b[h-1]);
print("You have finished entering/n");
for(i=0;i<9;i++)
{ if(b[i]!=0)//若没有输入则转换成默认值
input[i]=b[i];
else
input[i]=(b[0]/2);}
}
}
else
print("Erro:You have already input 8 numbers");
}
}
}
/* Timer interrupt service routine */
/* Note: This ISR is registered statically in the Software Platform Settings dialog */
void timer_int_handler(void * baseaddr_p) {
unsigned int csr;
/* Read timer 0 CSR to see if it requested the interrupt */
csr = XTmrCtr_mGetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0);
if (csr & XTC_CSR_INT_OCCURED_MASK) {
/* Increment led_count in a johnson-counter pattern */
if (led_data & LED_MSB)
led_data = led_data << 1;
else
led_data = (led_data << 1) + 1;
/* Update LED output pattern */
XGpio_mSetDataReg(XPAR_LEDS_4BIT_BASEADDR, 1, led_data);
}
/* Clear the timer interrupt */
XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0, csr);
}
/* Interrupt test routine */
void InterruptTest(void) {
print("/r/n-- Please input the Frequency --/r/n");
/* Initialize exception handling */
XExc_Init();
/* Register external interrupt handler */
XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT,
(XExceptionHandler)XIntc_DeviceInterruptHandler,
(void *)XPAR_OPB_INTC_0_DEVICE_ID);
/* Register the UART interrupt handler in the vector table */
XIntc_RegisterHandler(XPAR_OPB_INTC_0_BASEADDR,XPAR_OPB_INTC_0_RS232_UART_INTERRUPT_INTR,
(XInterruptHandler)uart_int_handler,(void *)XPAR_RS232_UART_BASEADDR);
/* Start the interrupt controller */
XIntc_mMasterEnable(XPAR_OPB_INTC_0_BASEADDR);
/* Set the gpio for LEDs as output */
XGpio_mSetDataDirection(XPAR_LEDS_4BIT_BASEADDR, 1, 0x00000000);
/* Set the number of cycles the timer counts before interrupting */
XTmrCtr_mSetLoadReg(XPAR_OPB_TIMER_1_BASEADDR, 0, timer_count);
/* Reset the timers, and clear interrupts */
XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0,
XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
/* Enable timer and uart interrupt requests in the interrupt controller */
XIntc_mEnableIntr(XPAR_OPB_INTC_0_BASEADDR,
XPAR_OPB_TIMER_1_INTERRUPT_MASK | XPAR_RS232_UART_INTERRUPT_MASK);
/* Start the timers */
XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_1_BASEADDR, 0,
XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK |
XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);
/* Enable PPC non-critical interrupts */
XExc_mEnableExceptions(XEXC_NON_CRITICAL);
/* Enable UART interrupts */
XUartLite_mEnableIntr(XPAR_RS232_UART_BASEADDR);
/* Wait for interrupts to occur until exit_command received from UART ISR */
while (!exit_command)
;
/* Disable PPC non-critical interrupts */
XExc_mDisableExceptions(XEXC_NON_CRITICAL);
print("-- Exiting InterruptTest() --/r/n");
}
/* End user-supplied interrupt test routine */
//====================================================
int main (void) {
print("-- Entering main() --/r/n");
/*
* MemoryTest routine will not be run for the memory at
* 0xffff0000 (plb_bram_if_cntlr_1)
* because it is being used to hold a part of this application program
*/
/* Testing BRAM Memory (opb_bram_if_cntlr_1)*/
{
XStatus status;
print("Starting MemoryTest for opb_bram_if_cntlr_1:/r/n");
print(" Running 32-bit test...");
status = XUtil_MemoryTest32((Xuint32*)XPAR_OPB_BRAM_IF_CNTLR_1_BASEADDR, 512, 0xAAAA5555, XUT_ALLMEMTESTS);
if (status == XST_SUCCESS) {
print("PASSED!/r/n");
}
else {
print("FAILED!/r/n");
}
print(" Running 16-bit test...");
status = XUtil_MemoryTest16((Xuint16*)XPAR_OPB_BRAM_IF_CNTLR_1_BASEADDR, 1024, 0xAA55, XUT_ALLMEMTESTS);
if (status == XST_SUCCESS) {
print("PASSED!/r/n");
}
else {
print("FAILED!/r/n");
}
print(" Running 8-bit test...");
status = XUtil_MemoryTest8((Xuint8*)XPAR_OPB_BRAM_IF_CNTLR_1_BASEADDR, 2048, 0xA5, XUT_ALLMEMTESTS);
if (status == XST_SUCCESS) {
print("PASSED!/r/n");
}
else {
print("FAILED!/r/n");
}
}
/* Run user-supplied interrupt test routine */
InterruptTest();
print("-- Exiting main() --/r/n");
return 0;
}