📄 main.c
字号:
/**********************************************************************************
;
; 2002 Altera Corporation. All rights reserved. Altera products are protected
; under numerous U.S. and foreign patents, maskwork rights, copyrights and other
; intellectual property laws. This reference design file, and your use thereof,
; is subject to and governed by the terms and conditions of the applicable
; Altera Reference Design License Agreement (found at www.altera.com). By using
; this reference design file, you indicate your acceptance of such terms and
; conditions between you and Altera Corporation. In the event that you do not
; agree with such terms and conditions, you may not use the reference design file
; and please promptly destroy any copies you have made. This reference design
; file being provided on an "as-is" basis and as an accommodation and therefore
; all warranties, representations or guarantees of any kind (whether express,
; implied or statutory) including, without limitation, warranties of
; merchantability, non-infringement, or fitness for a particular purpose, are
; specifically disclaimed. By making this reference design file available, Altera
; expressly does not recommend, suggest or require that this reference design file
; be used in combination with any other product not provided by Altera.
;
;**********************************************************************************
;
; Filename: alu_demo.c
;
; This code writes values to a simple ALU in the PLD which is then read back and
; display on LEDs
;
;**********************************************************************************/
#include <stdio.h>
#include "uartcomm.h"
#include "stripe.h"
#include "flash.h"
int INPUT_OPERAND,OPERAND1,OPERAND2;
volatile unsigned int* ALU_Op1_Addr;
volatile unsigned int* ALU_Op2_Addr;
volatile unsigned int* ALU_Operation_Addr;
volatile unsigned int* ALU_Result_Addr;
volatile unsigned int* DPRAM_Addr;
char OP[2];
volatile unsigned int OPERATION;
int get_input(void);
void get_operand(void);
void EnableIRQ(void);
int main(void)
{
volatile unsigned int RESULT;
ALU_Op1_Addr = (volatile unsigned int*) (EXC_PLD_BLOCK0_BASE + 4);
ALU_Op2_Addr = (volatile unsigned int*) (EXC_PLD_BLOCK0_BASE + 8);
ALU_Operation_Addr = (volatile unsigned int*) (EXC_PLD_BLOCK0_BASE + 12);
ALU_Result_Addr = (volatile unsigned int*) (EXC_PLD_BLOCK0_BASE + 16);
DPRAM_Addr = (volatile unsigned int*) (EXC_DPSRAM_BLOCK0_BASE);
uart_init();
EnableIRQ(); // Enable processor interrupts
write_flash_value((unsigned short*)EXC_EBI_BLOCK0_BASE, 0xFFFF);//Writes to flash to reset the boot parameters.
//The websever will run after the board is reset
printf ("\rStarting ALU Demo.........................................\r\n");
printf ("\rThis is an implemenation of a simple ALU in the PLD array.\r\n");
printf ("\rThe ALU is driven by the processor writing operand and operation values.\r\n");
printf ("\rThe a portion of the result is displayed on four of the LEDs.\r\n");
printf ("\rIn addition to the ALU in the PLD, there is a PWM that is attached\r\n");
printf ("\rto LEDs on the board independent of the processors interaction with the ALU.\r\n");
while (1)
{
printf ("Enter first operand.\r\n");
OPERAND1 = get_input();
printf ("\r\nEnter second operand.\r\n");
OPERAND2 = get_input();
printf ("\r\nEnter operation : + , - , or * .\r\n");
get_operand();
*ALU_Op1_Addr = OPERAND1;
*ALU_Op2_Addr = OPERAND2;
*ALU_Operation_Addr = OPERATION;
RESULT = *ALU_Result_Addr;
*DPRAM_Addr = ~RESULT; //inverting output to display on LEDs
printf ("\r\nThe result of %u %s %u is %u.\r\n",OPERAND1, OP, OPERAND2, RESULT);
}
}
int get_input(void)
{
char c;
char input[9];
int i, n;
i =0;
while ((c = fgetc(0x0))!= '\r')
{
input[i++] = (char)c;
fputc(c,0x0);
if(c == 0x1b)
break;
if(i >=9)
break;
}
input[i] = 0x00; /* place a string termination */
sscanf(input, "%u", &n);
return n;
}
void get_operand(void)
{
char c;
while ((c = fgetc(0x0))!= '\r')
{
OP[0] = c;
OP[1]= 0x0;
fputc(c,0x0);
if(c == 0x1b)
break;
switch(c)
{
case '+':
OPERATION = 0x00000005;
break;
case '-':
OPERATION = 0x00000006;
break;
case '*':
OPERATION = 0x00000007;
break;
default:
printf("\r\nInvalid operation, please enter +,-, or * .\r\n");
OPERATION = 0x000000005;
c = '+';
}
}
}
void CAbtHandler(void)
{
printf("Data abort\r\n");
}
void CPabtHandler(void)
{
printf("Error prefetch abort\r\n");
}
void CDabtHandler(void)
{
printf("Error data abort\r\n");
}
void CSwiHandler(void)
{
printf("Error swi\r\n");
}
void CUdefHandler(void)
{
printf("Error undefined instruction\r\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -