In this exercise we will look at tailoring the GNU Printf function to work with the LPC2100 UART. We will look at the registers of the UARTs in more detail later.
Open the project in EX4 printf\work
In main.c add a message for transmission to the printf statement while(1)
{
printf("Your Message Here \n"); //Call the prinfF function }
Add the file syscalls.c in the work directory to the project.
In syscalls.c add modify the write function as follows:
Complete the for loop statement so it runs for the length of the printf string (len )
Inside the for loop add the putchar statement to write a single character to the stdio channel ( putchar (*ptr)) Increment the pointer to the character string ptr++
int write (int file, char * ptr, int len) {
int i;
for (i = 0; i < len; i++) putchar (*ptr++); return len;
}
Compile the code and download it to the development board Run the code and observe the output within hyper terminal
If you are using the simulator, select view/serial window #1. This opens a terminal window within the simulator which displays the UART0 output.
6.11 Exercise 5: Simple Interrupt
In this exercise we will setup a basic FIQ interrupt and see it serviced. Open the project in EX5-Interrupt\work
In main.c complete the definition of the EXTintFIQ function prototype to define it as the FIQ interrupt service routine
void EXTintFIQ (void) __attribute__ ((interrupt("FIQ"))); In startup.s complete the vector constants table to define EXTintFIQ as the FIQ ISR.
.global EXTintFIQ Declare the name of the C ISR function as a global .global _startup .func _startup _startup: Vectors: LDR PC, Reset_Addr LDR PC, Undef_Addr LDR PC, SWI_Addr
LDR PC, PAbt_Addr Vector Table LDR PC, DAbt_Addr
.long 0xB8A06F58
LDR PC, [PC, #-0xFF0] LDR PC, FIQ_Addr
Reset_Addr: .word Reset_Handler Undef_Addr: .word Undef_Handler
SWI_Addr: .word SWI_Handler Constants table PAbt_Addr: .word PAbt_Handler
DAbt_Addr: .word DAbt_Handler .word 0
IRQ_Addr: .word IRQ_Handler FIQ_Addr: .word EXTintFIQ
Insert the name of the C ISR function in the constants table Compile the code and download it onto the board.
Step through the code and observe the following using the disassembly window and the registers window. Step through the code until you reach the while loop
Set a breakpoint in the EXTintFIQ function Press F5 to set the program running
To control the interrupt in the simulator, open the peripherals/GPIO port 0 window. Pin 0.14 is set high by the map.ini startup script. If you set the program running unchecking, the Pin1.4 box will generate the interrupt. You must raise the pin high again to stop interrupts.
Alternatively in the toolbox there is a “Generate EINT1” button. This button will generate a simulated pulse on to the interrupt pin.
Toolbox button Toolbox with user
configurable scripts
Within uVision there is a full scripting language which allows you to simulate external events. These scripts are based on the C language and are stored in text files. The script used to simulate the pulse is shown below: signal void Toggle(void)
{ PORT0 = (PORT0 ^ 0x4000); twatch (200); PORT0 = (PORT0 ^ 0x4000); } KILL BUTTON *
DEFINE BUTTON "GenerateEINT1","Toggle()"
This script is stored in the file signal.ini and is added to the project in the debug window. For more details on the scripting language see the uVision documentation.
6.12 Exercise 6: Software Interrupt
In this exercise we will define an inline Assembler function to call a software interrupt and place the value 0x02 in the calling instruction. In the software interrupt SWI we will decode the instruction to see which SWI function has been called and then use a case statement to run the appropriate code.
Open the project in EX6 SWI\work In main.c add the following code
As the first instruction in main add the assembler define which calls the swi instruction #define SoftwareInterrupt2 asm (" swi #02")
In the SWI ISR complete the register definition to access R14 register unsigned * link_ptr asm ("r14");
Complete the code to pass value of the SWI ordinal into the temp variable temp = *(link_ptr-1) & 0x00FFFFFF;
Compile and download the code into the debugger Step the code and observe the SWI being serviced
In the disassembly window the first SWI instruction has been encoded with the value 1 at location 0x0000015C
On entry to the ISR the supervisor link register contains the value 0x00000160
The calculation for temp is temp = *(link_ptr-1) & 0x00FFFFFF or 0x164 – 4 ( word-wide pointer, remember) which is 0x15C which points to the instruction which generated the SWI. The top 8 bits are masked off which yields a value of 1. This is used in the case statement to run the required code.
7 Chapter 7: Hitex Tutorial (With Keil Or GNU Compiler)
This chapter describes, how to use the Hitex tools with the Keil or GNU compiler for the tutorial examples. The debugging can be done with the HiSIMARM instruction set simulator, as long as no peripherals of the LPC2000 microcontroller are used. For examining the peripherals, a starter kit from Hitex or the full Tantino or Tanto system is recommended.
7.1
Installation
All the necessary software for the practical examples is on the Hitex CD that comes with this book.
1. First it is necessary to install the HiTOP IDE. Please install the options “HiSIM for ARM” and if you are using a starter kit, the “Tantino7/9 for ARM” option also. For high-end system users, please install the option “Tanto for ARM” as well.
2. Depending which compiler is to be used, please install the Keil or the GNU compíler for ARM 3. Finally install the StartEasy for ARM software. This is a CASE tool for the LPC2000 which will allow
you to easily configure the LPC2000 devices.