Lab 1 Introduction
When learning about an embedded system, you might begin by learning how to program the system, how to supply input, and how to produce system output. On the Blackfin, you might wonder how a language you know (like C) behaves on the system and what simple I/O is available. This lab demonstrates basic I/O on the BF561 by use of its push buttons and LEDs.
On the BF561 EZ-KIT Lite evaluation board there are a number of primitive I/O peripherals. They are described in the EZ-KIT Lite manual from ADI. There are 4 push buttons and 16 LEDs - all available through the programmable flags register. These buttons and LEDs are visible in Figure 1 on the lower right hand side of the board.
As a quick thought experiment, let's consider the act of pushing a button on the BF561. Does the board immediately notice the button is pressed (i.e., what happens when the circuit is closed)? Is the signal that changes active high or low? Does the CPU core notice the pressed button because of a routine check of the state of the push buttons (i.e., every clock cycle it checks)? Or does it rather get interrupted by the push button? Which seems more efficient: checking every clock cycle for the push button status or interrupting the core when the status changes?
For simplicity's sake, let usassume the CPU core checks the status of the push buttons every clock cycle. So we'll need to set the board up so our assumptions are correct -- for instance, that LEDs represent output, push buttons are input, etc. Even without writing any code, we know an initialization block is needed (to set everything) and a while loop that will check the status of our push buttons. We can summarize our assumptions in a table such as Table 1 and a generic code listing such as Listing 1.
LED represent | Output |
Push Buttons represent | Input |
Edge | PGT? NGT? |
Input | Clocked? not clocked? |
main ( ... )
{
Initialize(); /* Function or block of code to initialize the board */
/* esp. wrt. our configuration assumptions */
while ( 1 ) {
Get_Input_State(); /* check input state */
Change_System_State(); /* respond to input, by changing state */
Set_Output_State(); /* change output lines, if needed */
}
}
In VDSP++, open up the file
C:\Program Files\Analog Devices\VisualDSP 4.0\Blackfin\include
.
Here you can see the actual System MMR Register Map. Scroll down to line number
184, where the Programmable Flag x registers
sections begin. Refer to
the Hardware Reference guide Ch. 14, pages 14-9 to 14-44.
LEDs as Output
If we are to use the LEDs, their direction register (FIOn_DIR) should be set to outputs. Read page 14-9. What value should bits 15 to 0 be? What is the equivalent value in hexadecimal? What is n? (Check the Systems manual, page 1-9.)
In order to write a value to be displayed using the 16 LEDs we first have to be able to clear the LEDs (for an initial value that we can return to if needed). Read page 14-26 and 14-27. What values of bits 15 to 0 clear the register? What is that in hex?
For setting values, read 14-25 and 14-26. What would be displayed if the value of the register was 43605 in decimal?
Problem Write a program that prints the output of a count from 0 to 65535. Figure 2 shows a short movie of the BF561 performing a count. What is the decimal equivalent of the count (assume a non-lit LED is a logical 0 and a lit LED is 1) - from what initial value to what final value? (Possible solution)
Push Buttons as Input
If we are to use the Push Buttons, their direction register (FIOn_DIR) should be set to inputs. Read page 14-9. What value should bits 15 to 0 be? What is the equivalent value in hexadecimal? What is n? (Check the Systems manual, page 1-9.)
Also the input enable register (FIOn_INEN) should be set to enable input buffers. Read page 14-43. But which PFx bits correspond to the Push Buttons on the BF-561 EZ-KIT LITE eval board? We will need to check with the BF561 systems manual (page 1-9). Which programmable flags control the sixteen LEDs? According to the hardware manual, what should their values be? What's that in hex?
Finally the Push Buttons must be active when pressed or active on a clock edge (i.e., is the input clocked or not?). Which clock edge (positive-going or negative-going) should be used? Read 14-38 to 14-42.
Problem Write a program that prints to std out which push button was pressed.