IS1200/IS1500 Computer Engineering

Size: px
Start display at page:

Download "IS1200/IS1500 Computer Engineering"

Transcription

1 IS1200/IS1500 Computer Engineering Laboratory Exercise nios2int Interrupts and Traps Incomplete work is only valid until Student's name in permanent ink: Latest update: Date: Demonstrations 1, 2, 3. There are no Demonstrations for these Assignments. Demonstration 4: The Key Discussion about working program, signed by teacher: First Surprise Assignment. Teacher's description of Surprise Assignment: Demonstration 5: First Surprise Assignment. Signed by teacher: Demonstration 6: Toggles. Discussion about working program, signed by teacher: Second Surprise Assignment. Teacher's description of Surprise Assignment: Demonstration 7: Second Surprise Assignment. Signed by teacher: Laboratory Exercise 100% complete. Signed by teacher: Hey, student! Please keep this page, as proof of your completed laboratory exercise. IS1500 nios2int 2014 page 1

2 This page intentionally left blank. IS1500 nios2int 2014 page 2

3 nios2int: Input and Output Contents Files used a complete list, so you can download them all and then work offline...3 Read this first our best advice comes first...4 Objectives what you will be able to do after the laboratory exercise...5 Requirements for Laboratory Exercises how to pass our laboratory exercises...5 Known issues...6 Checklist for troubleshooting...8 Exceptions and interrupts - how they work...9 Interrupts... 9 Exceptions Exceptions or interrupts in an exception handler Altera-supplied software functions Hardware information Toggle switches Red LEDs Green LEDs Push-buttons Seven-segment displays...19 The Programmable Hardware Timer Serial Port (UART,Universal Asynchronous Receiver/Transmitter) Serial Input and Output Putty...24 Assignments with Assembly-Language Interrupt Handlers Home Assignment 1 Prime Time Home Assignment 2 Exceptional Exclamation Home Assignment 3 T-Time Home Assignment 4 The Key Laboratory Assignment 5 First Surprise Assignment Home Assignment 6 Toggles Laboratory Assignment 7 Second Surprise Assignment Laboratory Assignment 8 Packing up the Board...39 Error messages...42 Version history for this document...43 Files used All files are available from the course web. You need a software installation of the Nios II Software Build Tools for Eclipse. The Nios II Software Build Tools for Eclipse is bundled with Quartus II, version 11 or later. If you install yourself, please select Quartus II version 13.0sp1, which is compatible with all laboratory exercises in this course. Later versions are not compatible. You need a configuration file for the Nios II Software Build Tools. You need the NIISim simulator. You need the Nios II Processor Reference Handbook (PDF) from Altera. We use chapters 3 and 8. Chapter 3 describes the programming model, and chapter 8 is the instruction set reference. IS1500 nios2int 2014 page 3

4 You need a configuration file for the DE2 board. The items above are the same ones you used for the Laboratory Exercises nios2time and nios2io. You will also need several source files, specific to this lab. Read this first This lab is 90% preparation. Really. You may need a full week to prepare completely for the laboratory session. Do previous labs first. You must finish the First Project, and also labs nios2time and nios2io before you begin. This lab session is more difficult. In this lab, the debugger is not as trustworthy as it used to be. An interrupt can cause the processor to execute a lot of code behind the debugger's back. The debugger can only tell you about things it knows about, so what you see in the debugger is no longer always true. You need to understand your own code really well to find out what's happening. You will need the KTH-managed computers in the computer-rooms. Go there, and check that you can log in. If you can't, fix that. Otherwise, you may have trouble at the lab session, so that you are unable to finish the laboratory exercise. Participate in our practicals (övningar). The lectures tell you the general picture, but our practicals discuss the details you need at the lab session. If you miss a practical, you will spend hours just catching up. Check the solved sample exercises (Exempelsamling), and the slides from our practicals (övningar). There are lots of solved examples and useful slides to help you get going. Explain every line of code to yourself. If you can't understand it, it shouldn't be there. And we will ask you to explain it at the lab session. When you see an error message, check the list. If we have seen that message before, the list will contain good advice about what to do. Use the debugger. When your program doesn't do what it should, step through it in the debugger. At each step, check carefully that the program really does what you want. If it does something else, you've found the error. There is a trick to set a breakpoint at the start of your interupt handler. Start the debugger, then write down the current program-counter value. Now change the program counter to 0x Step once, so that the interrupt-handler starts. Step twice again. You are now inside your own exception handler. Set a breakpoint there. Now change the program counter back to its original value, so that your initialization code gets to run correctly. This procedure ensures that the debugger will stop on every interrupt. If it doesn't stop, this means that there was no interrupt; and that can be a very useful piece of information, too. Important! When performing this procedure, please remember to change the program counter back to its original value, so that your initialization code runs correctly. Perform code review. Read through your program carefully and try to improve it. Make notes of the contents of selected registers to check that the program really does what you want. Ask us. If you get stuck, get help. Post a question on the KTH Social Course Web. We follow these questions and reply as soon as we can, and other students can post a reply even faster than that. IS1500 nios2int 2014 page 4

5 Objectives After this laboratory exercise, you will be able to: write assembly-language interrupt handlers write assembly-language trap handlers write C-language interrupt handlers write interrupt handlers combining assembly language and C Requirements for Laboratory Exercises Do all Home Assignments before the lab session. We will send you home if your Home Assignments are incomplete. All code must be easy to understand. The best way is to make it short and simple. When you must do something non-trivial, write a comment to explain. When you reach lines of assembly code, use a flow-chart to explain what happens. Complicated code means confusing code. All code must follow our specifications completely. In this laboratory exercise, you will create building blocks to be used for later lab exercises, together with code written by other people. Your building blocks will only work with the other building blocks, if all your code follows all specifications completely. "But it works anyway" is not an excuse - it means you've taken some shortcut instead of writing correct code. Sloppy code can fail miserably at the next laboratory exercise, when you've forgotten about your shortcuts. All your code must compile with no errors and no warnings. To check this, right-click the project name and select Clean Project, then right-click again and select Build Project. Look for messages in the Problems tab, and in the Nios II Build Console. Be prepared to explain. The laboratory teachers ask questions about your programs, and every student must be able to explain everything, individually. We will send you home if you cannot explain your code. It's your code you must explain it. Be prepared to change your code. You will get Surprise Assignments, which you must finish during the lab session. If you can't finish a Surprise Assignment, you must come back at a later lab session. At that later session, you will get a new Surprise Assignment, which must be finished at that session. You can never take home a Surprise Assignment. You must complete all Laboratory Assignments, demonstrate them and explain them. All Assignments are mandatory. Work in groups of two. We will have 15 DE2 boards for a group of 30 students. You can sometimes work alone, but check with the laboratory teachers first. Groups of more than two persons are not allowed. This rule is not negotiable. At the lab session, show us immediately. As soon as you have finished a Demonstration: discuss with the lab teacher, who will mark your work on the front page. Keep the front page. When you've Demonstrated everything, the teacher will make a note on our department-internal list. This list is later used for reporting into Ladok. The front page is your safeguard, in case any errors should occur in our department-internal list. IS1500 nios2int 2014 page 5

6 Known issues Wonky push-buttons On many boards, the push-buttons KEY3, KEY2, KEY1 and KEY0 are unreliable. If they don't work, press a harder. If this doesn't help, press at the edge of the button intead of in the center. All other buttons and functions on the boards work perfectly. Where's my output? During simulation, you will see all program output in the UART0 console-window of the NIISim simulator. At the laboratory session, there are three possible cases. Which one you will see depends on the internal design of your computer. 1. Most common case: Your computer has no serial-port hardware, so the Nios II IDE gives an error message. You will need a USB-to-serial converter (we supply that) and a terminal emulator (you fix that!). The error message is: nios2-terminal: can't open uart: Permission denied, and/or Terminal process failed. Just click OK, and ignore those two error messages. 2. This case can happen: Your computer has serial port hardware but no connector, so you can't use it. You will need a USB-to-serial converter (we supply that) and a terminal emulator (you fix that!). There will be no error messages, since the Nios II Software Build Tools will connect to the (unused) internal serial port. However, nothing will be displayed in the console window of the Nios II Software Build Tools. 3. Least common case: Your computer has a serial port, and you use it. Program output is displayed in the console window of the Nios II Software Build Tools. movia bug The movia pseudo-instruction produces incorrect code for negative constants, and for values larger than 0x That's 7 zeroes, so all valid DE2-board addresses are safe. Memory starts at 0x (only 5 zeroes). An important case is moving -1 to r2: please use movi r2,-1 In this case, movia will not work. The assembler translates movia incorrectly, changing the contents of another register. Nearly all negative constants can use movi without the a. All movi instructions (without the a) work correctly, but have a 16-bit size-limit. Constants for movi must be in the range through jmpi The hardware has no jmpi instruction. If you use it, your code will fail at the lab session..include You can only use.include for files containing macro definitions. Files containing subroutines may not be included. Otherwise, some code will be compiled twice (or more), and the duplicates will cause errors and endless confusion. Files containing program text and/or data must never be included using.include. IS1500 nios2int 2014 page 6

7 PUSH The definition of the PUSH macro must use subi sp,sp,4 and not addi sp,sp,-4 This is confusing, since these two instructions should be translated to the exact same bits in the binary machine-code program. Changing files outside the Nios II Software Build Tools It is possible, but not recommended, to use other programs than the Nios II Software Build Tools to edit C-code files, assembly-code files, and other source-code files. It is also possible to copy files through the Windows Explorer or other file-manager program. Remember to right-click the project directory in the Nios II Software Build Tools window, and select "Refresh" every time you have changed a file outside the Nios II Software Build Tools. This applies to all projects affected by a change, so moving a file from one project-folder to another will normally require two Refresh operations, one for each of the two projects. Only copy, edit, and move source files. Never change, copy or move configuration files. Never copy or move folders, because folders always contain configuration files. The Nios II Software Build Tools stores administrative information in hidden files. These hidden files contain path information, which becomes invalid if the file is copied or moved. If you happen to copy or move a hidden file, you will confuse the Nios II Software Build Tools. The resulting error messages are usually incomprehensible, and seemingly totally irrelevant. The Debugger may hang instead of starting normally This can be fixed, see Fixing the Debugger if it hangs. Run As Hardware produces an error, but my program is unchanged since the last run This can be fixed, see Target Connection Problem on page 43. IS1500 nios2int 2014 page 7

8 Checklist for troubleshooting There is also a (partial) list of error messages at the end of this document..data before data.text before code.align 2 before code.global is required for the name of each subroutine..end causes the assembler to stop assembling. Don't put anything after.end. No code before main: When starting your program, the Nios II processor is initialized by a startup-routine. The startup-routine calls your code with the instruction call main Therefore, any code before the label main: will never be executed. Subroutines: Must be called with call or callr and returned from with ret Parameter to subroutine: must be in r4 R31: Any subroutine that calls other subroutines must push r31 before the first call, and pop r31 after the last call. If you use any of r8 through r15 for local variables, you need to caller-save those registers by pushing them on the stack before any subroutine call, and restore them by popping from the stack afterwards. If you use any of r16 through r23 for local variables, you must save those registers before you first write them, and restore the original values before you return from your subroutine. Always save to the stack. There are no safe registers. If you think there are safe registers, your programs will fail miserably at the nios2int exercise. Always use ldwio to read from an input/output device, and use stwio to write to it. Start the terminal-emulator window with correct port-parameters. Use bits/s, 8 data bits, no parity, 1 stop bit, and no flow control. Keep the terminal-emulator running. Closing it and restarting it is a waste of time. Check the UART addresses. Address for uart0 = 0x860, address for uart1 = 0x880. If you type one character and get lots of copies of it in return: perhaps there's a problem with the check for negative return values indicating "no new data". Anything you save to the stack will disappear when your subroutine returns. If you need to remember things until the next time your subroutine is called, use a variable in the DATA area in main memory. These variables are sometimes called static, since they still exist whether your subroutine is running or not. Symbols are sometimes case sensitive, so hexasc and HEXASC may be different labels in some cases (but not always). Therefore, always write all labels and names the same way, 100% of the time. IS1500 nios2int 2014 page 8

9 Exceptions and interrupts - how they work Interrupts This is a summary of the Exception Processing sections of Chapter 3 from the Nios II Processor Reference Handbook. An interrupt happens when a hardware device changes an electrical signal from inactive (0) to active (1). As an example, the hardware device may do this when input data are available. The electrical signal passes through logic gates, allowing other inputs of those gates to block the signal. When the signal is blocked, the interrupt is disabled (and cannot happen). This figure shows a general interrupt signal in a Nios-II system. The input/output device has some kind of internal ready-signal, for example to indicate that fresh data is available. A configurable interrupt-enable bit in the device controls whether this ready-signal can be seen outside the device. If the ready-signal is available outside the device, it is connected to one of the 32 interrupt-request inputs of the Nios II processor. The inputs are numbered 0 through 31. Each input has a corresponding bit in the ienable control-register, so that interrupts can be enabled and disabled for each device separately. A global flag, the Processor Interrupt Enable bit, is used to enable or disable interrupts in general. The figure below shows a simplified logic diagram of the interrupt-logic inside a Nios II processor. Every device has a unique bit in the ipending special register (ctl4), and the interrupt-handler must check which bit is a '1'. For example, if bit 2 is a '1', there was an interrupt from device number 2. The handler must figure that out, and then jump to code that is specific for the device connected to interrupt-input number 2. While an interrupt is being processed, all further interrupts are disabled. The processor ensures this by clearing the Processor Interrupt-Enable bit (PIE) in the status register (ctl0) before starting the interrupt handler. The eret instruction restores the previous contents of the status register. When interrupts are enabled, an interrupt can happen anytime, so all registers can be expected to contain values needed by the interrupted program. Therefore, an interrupt handler (also known as an interrupt service routine) can never modify any register contents. IS1500 nios2int 2014 page 9

10 In the Nios II processor, register R24 is set aside for temporary use by interrupt handlers. Register R24 is also called et (exception temporary). Interrupt-handlers that needs to use other registers must first save their values to the stack, and restore those values before returning. In Nios II systems, interrupts always cause the processor to jump to one specific address. In the systems used in these laboratory exercises, the address is 0x Return from the interrupt must be by way of the special exception-return instruction eret Since interrupts are disabled in an interrupt handler, some functions are not available. In particular, the putchar function must never be called from an interrupt-handler, since putchar uses an interrupt-dependent device (the JTAG UART). Calling putchar from an interrupt handler fails in the following way: putchar will sometimes wait for an interrupt from the JTAG UART. Since interrupts are disabled, that interrupt will never happen, so the system hangs until you restart it. Exceptions A software exception has the same effect as an interrupt, but the cause is different. Interrupts are caused by hardware outside the processor, but a software exception is caused by some specific instruction that is executed in the processor. On many systems, the division instruction will cause a software exception if the divisor is zero (a divide-by-zero exception). There is also a trap instruction, that will always cause a software exception. Since software exceptions and interrupts are similar, they are often discussed together. In this case, an "exception" is either an interrupt or a software exception. An exception wrapper for C It is not possible to write an exception handler using only C. Some assembly-language code is necessary. In some of the Assignments in this laboratory exercise, you will use an Altera-supplied exception-wrapper. This wrapper is written in assembly language, with some parts in C. The general structure of the wrapper is as follows. For more details see the section on Altera's exception-handling wrapper. 1. Save register ra (return address, r31) plus all caller-save registers (registers r1 through r15). 2. Save control register estatus (contents of status as it was just before the exception, ctl1). 3. Call a C-language checking-routine to find the cause of the exception. If the cause was an interrupt, the C-language routine looks in the ipending special register (ctl4), to find out which one of the 32 interrupt inputs was active. Each interrupt input has its own interrupthandling subroutine. The checking-routine selects the right subroutine and calls it. 4. After the return from the C-language checking-routine, restore all previously saved register contents (registers r1 through r15, ra, and estatus). 5. The last instruction of the wrapper is eret, which returns to the interrupted program. If you write an interrupt-handling subroutine that the exception-wrapper should call, you must make your subroutine known to the C-language part of the exception-wrapper. An interrupt-handling subroutine is often mentioned as an "Interrupt Service Routine" (ISR), and making an ISR known to the exception-wrapper is desribed as "registering the Interrupt Service Routine". See below for more information. IS1500 nios2int 2014 page 10

11 The figure below shows actions that must be taken by a general interrupt wrapper. Exceptions without a wrapper You can't rely on other people to write wrappers for you at all times. To have your own, complete exception handler for Nios II, the following steps are necessary. Please note that all steps below refer to assembly-language program code. 1. As part of your initialization, copy a stub routine to the exception-handling address 0x The stub routine should contain a jmp instruction, transfering program control to your main exception handler. 2. In your main exception handler, do the following: 1. Check if EPIE == 1; if not, there was no interrupt (but perhaps a trap or other synchronous exception). EPIE is the saved value of the Processor Interrupt-Enable bit, from immediately before the interrupt (or trap or exception). EPIE can be read from the special register estatus (ctl1). 2. If EPIE == 1, check if ipending == 0. If ipending == 0, there was no interrupt (similar case as in the previous check). ipending is a special register (ctl4). 3. If EPIE == 1 and ipending 0, the exception was caused by a hardware interrupt. Subtract 4 from the saved exception-return address in register ea (r29), since the interrupted instruction was not finished and must be restarted. IS1500 nios2int 2014 page 11

12 4. Check one of the bits in the ipending special register (ctl4). If this bit is set, there is an interrupt pending corresponding to the index of that bit. In that case, control must be transfered to your Interrupt Service Routine for that interrupt index. In assembly-language code, you would normally use a branch or jump instruction for this, and not a call, so the Interrupt Service Routine should end with an eret instruction. 5. Check another bit in the ipending special register (ctl4). And so on, for all possible interrupt sources. 6. Please note that the order in which you check the bits will decide the relative priority of different interrupts. Interrupts checked first will have priority over interrupts checked later. 3. Check if the interrupted instruction was a trap. If so, jump to a trap handler. 4. Theoretically, you would want to check if the interrupted instruction was an unimplemented instruction, for which you have written a handler. This is beyond the scope of this laboratory exercise. You may ignore the case of unimplemented instructions: you don't have to check for them in this laboratory exercise. 5. Add code to handle the case that no trap, interrupt, or unimplemented instruction caused the exception. This is called a spurious interrupt. The steps above are adapted from the section Determining the Cause of Interrupt and Instruction- Related Exceptions in Chapter 3 of the Nios II Processor Reference Handbook. Exceptions or interrupts in an exception handler In rare cases, it is necessary to allow an interrupt handler to be interrupted. There are two possible cases: allowing the same type of interrupt to happen again, and allowing other interrupts to happen (but not the same type as the one we're handling). A software exception or trap inside an exception handler must be handled similarly. In the lists below, steps not applicable for traps are clearly marked. Note: the Altera-supplied exception wrapper saves (and restores) ea and estatus. Allowing all interrups, including allowing the same type of interrupt to happen again (using Assembler) This requires the following steps: 1. Acknowledge the interrupt. This step must be performed before the interrupt-enable step below. 2. Save the contents of register ea (r29 - the exception-return address register). 3. Save the contents of special register estatus (ctl1). 4. Enable interrupts for the current interrupt number (not required for traps). 5. Do whatever it is that will take such a long time (long enough for you to want interrupts enabled for the duration), or do whatever it is that may cause a software exception or trap. 6. Disable interrupts (not required for traps). 7. Restore the contents of special register estatus (ctl1). 8. Restore the contents of register ea (r29). 9. Return normally from the interrupt, using eret. IS1500 nios2int 2014 page 12

13 Allowing other interrupts, but not the same type again (using Assembler) This requires the following steps: 1. Save the contents of register ea (r29 - the exception-return address register). 2. Save the contents of special register estatus (ctl1). 3. Disable interrupts for the current interrupt number (not required for traps). 4. Enable interrupts for all other interrupt numbers (not required for traps). 5. Do whatever it is that will take such a long time (long enough for you to want interrupts enabled for the duration), or do whatever it is that may cause a software exception or trap. 6. Disable interrupts (not required for traps). 7. Acknowledge the interrupt. This step may be performed earlier in the sequence. 8. Restore the contents of special register estatus (ctl1). 9. Restore the contents of register ea (r29). 10.Re-enable interrupts for the current interrupt number (not required for traps). 11.Return normally from the interrupt, using eret. Executing a trap instruction from within an exception handler (using Assembler) This requires the following steps: 1. Save the contents of register ea (r29 - the exception-return address register). 2. Save the contents of special register estatus (ctl1). 3. Save all caller-saved registers (r1 through r15). 4. Execute the trap instruction. 5. Restore the contents of special register estatus (ctl1). 6. Restore the contents of register ea (r29). 7. Return normally from the interrupt, using eret. Altera-supplied software functions This section contains more information on the Altera-supplied exception wrapper, and on some relevant functions/subroutines. The Altera-supplied exception wrapper can handle all sorts of interrupts, but only some types of software exceptions. In this Laboratory Exercise, we will only use the wrapper for interrupts, and not for any software exceptions. Registers saved and restored by the exception wrapper The following registers are saved and restored by the exception wrapper: Register r31 (the subroutine-return address register, ra). Register r1 (the assembler's temporary, at). Registers r2 through r15 (the caller-saved registers). Control register estatus, also known as ctl1. Saving this register is strictly necessary only in interruptible handlers, but always saving it simplifies the code. Registers r16 through r23 are not in this list; they are the callee-saved registers. Since callee-saved registers must be saved and restored by any function/subroutine using them, they need not be saved by the wrapper. IS1500 nios2int 2014 page 13

14 Registering an interrupt handler Let's recall how interrupts are handled by the Altera-supplied software. The Altera-supplied assembly-language wrapper calls a C-language checking-routine. This checking-routine examines the cause of the exception. If it was an interrupt, it checks the ipending special register (ctl4) to determine which device caused the interrupt. Every device has a unique bit in the ipending special register (ctl4). For example, if bit 2 is a '1', there was an interrupt from device number 2. The checking-routine uses a table, mapping device numbers to interrupt-handling subroutines. If you write an interrupt-handling subroutine (Interrupt Service Routine, ISR), the starting address of your subroutine must be put into the correct cell of the table. This is called registering the Interrupt Service Routine. The Altera-supplied function for registering an Interrupt Service Routine is alt_ic_isr_register. A call to this function has five (5) input parameters, like this: check_val = alt_ic_isr_register( ic_id, irq_number, function, context, flags ); irq_number is the interrupt index (device number), and function is the starting address of your Interrupt Service Routine. For ic_id use the numerical constant 0 (zero); for context and flags use a null-pointer (a pointer with the value zero). There's a detailed example below. Upon return from alt_ic_isr_register, the interrupt with index irq_number is enabled. The return value (check_val) is zero for success and non-zero in case of failure. All other interrupts are unchanged by alt_ic_isr_register. Interrupts which were previously enabled are still enabled, and interrupts which were previously disabled are still disabled. Type declarations In order for your program to be type-correct, you must make sure that variables and functions have declarations conforming to the Altera-supplied definitions. Here's a summary: void irq_handler( void * context ); /* You write this handler! */ int alt_ic_isr_register( alt_u32 ic_id, alt_u32 irq_number, void (*function) (void *, alt_u32), void * context, void * flags ); /* Written by Altera */ The declaration for irq_handler is simple and has only one (1) input parameter. This is good, as you must write that handler and use exactly that declaration. You can change the names (irq_handler and context), but not the types (void, and pointer to void). The declaration for alt_ic_isr_register is not-so-simple. But Altera has already written the declaration - it's in the include-file alt_irq.h. All you have to do is call alt_ic_isr_register and supply the right five parameters. Let's go through them one by one. 1. The ic_id parameter must be 0 (the integer constant zero). In more complex Nios II systems there can be more than one interrupt-controller, and this parameter selects which one to use. 2. The irq_number parameter must be an integer constant equal to the interrupt-index of the hardware device causing the interrupt. So if you're writing a handler for interrupts from uart_1, irq_number must be 5. No other number will work, since the hardware was designed with uart_1 connected to the processor's interrupt input number The function parameter is simply the name of your interrupt handler. Altera's interrupt-handling wrapper-code will save this parameter, and call your handler when there is an interrupt on the input you specified with the irq_number parameter (described previously). This kind of mechanism is called a call-back. IS1500 nios2int 2014 page 14

15 4. The context parameter should be a null-pointer: ((void *) 0). The pointer value will be a parameter to your handler, when Altera's wrapper-code calls it. This is useful in more complex setups, but not in this laboratory exercise. 5. The flags parameter is reserved for future use by Altera, and must be a null-pointer: ((void *) 0). Example Some sample code will give an even clearer picture. This sample code initializes a device called somedevice with interrupt index 7: #include <alt_irq.h> const int somedevice_irq_index = 7; /* IRQ number for somedevice */ void * null_pointer = (void *) 0; /* Null pointer for calls to alt_ic_isr_register */ void irq_handler_for_somedevice( void * context ) { /* Insert real handler code here. This is just an example. */ } void initialize_somedevice( void ) { int check_value; /* Insert real initialization code here. This is just an example. */ check_value = alt_ic_isr_register( 0, somedevice_irq_index, irq_handler_for_somedevice, null_pointer, null_pointer ); if( check_value!= 0 ) my_initialization_failed_with_an_error(); /* Change this to code for handling the error. */ } The header file alt_irq.h must be included, so that the compiler can recognize alt_ic_isr_register and other relevant functions. The code in the handler may ignore its argument; but the argument must be present, or your program will not compile. In our example, we don't use the context parameter, so we set it to a null-pointer in the call to alt_ic_isr_register. On an interrupt, your handler (irq_handler_for_somedevice) is called by Altera's wrapper. The argument, context, is the pointer (null_pointer) you used when you registered the handler. IS1500 nios2int 2014 page 15

16 Hardware information Toggle switches Example: reading address 0x850 will return 14 unspecified most-significant bits, and 18 leastsignificant bits indicating the current positions of switcher SW17-SW0. The interrupt-mask must be written during initialization. For every toggle-switch, there is a bit in the interrupt-mask. Setting a bit to '1' enables interrupts when that switch is moved from one position to the other. With interrupts enabled, both possible position-changes will interrupt the processor. Moving the switch lever towards the center of the board will produce an interrupt, as well as moving the switch lever towards the edge of the board. There's a bit for every toggle-switch In the edge-capture device-register, too. When a switch position was changed, the corresponding bit in the edge-capture device-register is set to 1. It is not possible to clear individual bits of the edge-capture device-register. Any write operation to address 0x85c will clear all bits of the edge-capture device-register, regardless of the value written. To enable interrupts for one or more toggle switches: 1. Setup an interrupt handler for the interrupt-requests from device number 3 (de2_pio_toggles18). How to do this depends on your software configuration. 2. Set (to a logic "1") those bits in the interrupt-mask (0x858) which correspond to toggle switches that should be able to interrupt the processor. 3. Set (to a logic "1") the bit with index 3 in the processor's ienable register (ctl3). A bitmask with this bit set is: 0x Set (to a logic "1") the processor's PIE bit (Processor Interrupt Enable) - bit 0 in the status register (ctl0). The interrupt output from de2_pio_toggles is active if and only if: there is a '1' in some position in the edge capture register, and also a '1' in the same position in the interrupt-mask register. When this condition is true, other bits in the edge-capture and interrupt-mask registers do not matter. To acknowledge the interrupt, write any value to the edge-capture register. This will always clear all bits of the edge-capture register. IS1500 nios2int 2014 page 16

17 Red LEDs Example: writing the value 0x17 to address 0x810 will light LEDs LEDR4, LEDR2, LEDR1, and LEDR0. This device cannot be a source of interrupts. Green LEDs Please note that LEDG8 is located between the blocks of seven-segment display-digits. Example: writing the value 0x117 to address 0xA10 will light LEDs LEDG8, LEDG4, LEDG2, LEDG1, and LEDG0. This device cannot be a source of interrupts. IS1500 nios2int 2014 page 17

18 Push-buttons The key-output is inverted, so when no-one touches your board, you will read 1's from the PIO. Example: reading address 0x840 when no-one touches the board will return 1's in the 4 leastsignificant digits (and unspecified values in the 28 most-significant digits). The interrupt-mask must be written during initialization. For every button, there is a bit in the interrupt-mask. Setting a bit to '1' enables interrupts when that button is pushed, or released. With interrupts enabled, both possible position-changes will interrupt the processor. Pushing the button will produce an interrupt, as well as releasing the button. There's a bit for every button In the edge-capture device-register, too. When a button was pressed or released, the corresponding bit in the edge-capture device-register is set to 1. It is not possible to clear individual bits of the edge capture device-register. Any write operation to address 0x84c will clear all bits of the edge capture device-register, regardless of the value written. To enable interrupts for one or more push-button switches: 1. Setup an interrupt handler for the interrupt-requests from device number 2 (de2_pio_keys4). How to do this depends on your software configuration. 2. Set (to a logic "1") those bits in the interrupt-mask device-register (0x848) which correspond to toggle switches that should be able to interrupt the processor. 3. Set (to a logic "1") the bit with index 2 in the processor's ienable register (ctl3). A bitmask with this bit set is: 0x Set (to a logic "1") the processor's PIE bit (Processor Interrupt Enable) - bit 0 in the status register (ctl0). The interrupt output from de2_pio_keys is active if and only if: there is a '1' in some position in the edge capture register, and also a '1' in the same position in the interrupt-mask register. When this condition is true, other bits in the edge-capture and interrupt-mask registers do not matter. To acknowledge the interrupt, write any value to the edge-capture register. This will always clear all bits of the edge-capture register. IS1500 nios2int 2014 page 18

19 Seven-segment displays The seven-segment display modules need two I/O ports for all their bits. Each display digit uses 7 bits. The decimal points are not connected. Bits cleared (logic "0") light up their corresponding segments; bits set (logic "1") shut off their corresponding segments. This device cannot be a source of interrupts. The Programmable Hardware Timer All device registers in the Timer have 32 bits (4 bytes) and must be read with an ldwio instruction (and written with a stwio instruction). However, no more than 16 bits (2 bytes) are connected. So the 32-bit period must be split into two 16-bit halves. To initialize the timer, first write the 2 low bytes of the period to periodl, and then write the 2 high bytes to periodh. Finally, write once to the control register, setting the Start bit, (if appropriate) the Continuous-Mode bit, and (if appropriate) the Interrupt-on-Time-Out (ITO) bit. Note: the timer counts down in one clock cycle, and sets the Time-Out flag in the next cycle if the counter reached zero. For example, if you want a 1000-cycle timeout, set the period value to 999. IS1500 nios2int 2014 page 19

20 Timer device-register summary Status, 0x920 - read status bits, write any value to clear Time-Out bit. Control, 0x924 - write to start and/or control the timer. All bits are important, every time you write. PeriodL, 0x928 - write low bits of period here. Writing may stop the timer. PeriodH, 0x92c - write high bits of period here. Writing may stop the timer. SnapL, 0x930 - read low bits of latest snapshot, write to take a snapshot. SnapH, 0x934 - read high bits of latest snapshot. Bit by bit, explained Time Out (TO) - bit 0 at address 0x920 - set to one by the Timer when the counter reaches zero. To reset the Time Out bit to zero, the program must write to address 0x920. Whatever value is written is ignored. The write transaction causes the Timer to reset the Time Out bit. Run - bit 1 at address 0x920 - indicates whether the Timer is running or not. This bit is set to one by the Timer when counting starts and reset to zero by the Timer when counting is finished. Continuous Mode - bit 1 at address 0x924 - this bit can be set and reset by the programmer. If this bit is set to one, the Timer will restart itself immediately after counting reaches zero. The Time Out bit will be set to one each time the counter reaches zero. The Run bit will always be 1. Start - bit 2 at address 0x924. When a value, where bit 2 is equal to "1", is written to address 0x924, the Timer starts counting. Writing values where bit 2 is equal to "0" has no effect. Stop - bit 3 at address 0x924. When a value, where bit 3 is equal to "1", is written to address 0x924, the Timer stops counting immediately. Writing values where bit 3 is equal to "0" has no effect. Snapshot - to read the current counter value, write any value to address 0x930 (SnapL). The counter value at the time of the write transaction will be copied from the counter to a Snapshot register inside the timer. The Snapshot register can then be read at addresses 0x930 (lowermost 16 bits at this address equals lower 16 bits of counter snapshot value) and 0x934 (lowermost 16 bits at this address equals upper 16 bits of counter snapshot value). Enabling periodic timer interrupts 1. Setup an interrupt handler for the interrupt-requests from device number 10 (timer_1). How to do this depends on your software configuration. 2. Initialize the periodl and periodh device-registers of the timer. 3. Set the Start, Continuous-Mode, and Interrupt-on-TimeOut bits in the control deviceregister. These bits have indices 2, 1 and 0, respectively. A bit-mask with these three bits set is: 0x Set (to a logic "1") the bit with index 10 in the processor's ienable register (ctl3). A mask with this bit set is: 0x Set (to a logic "1") the processor's PIE bit (Processor Interrupt Enable) - bit 0 in the status register (ctl0). To acknowledge a timer interrupt, write any value to address 0x920. IS1500 nios2int 2014 page 20

21 Serial Port (UART,Universal Asynchronous Receiver/Transmitter) uart_0 uart_1 ReceiveData (RxD) Register Address 0x860 0x880 TrasmitData (TxD) Register Address 0x864 0x884 Status Register Address 0x868 0x888 Control Register Address 0x86C 0x88C Bit by bit, explained Receiver Ready: when bit 7 in the Status Register is a "1", a new byte has been received; this byte can be read from the RxD Register. Transmitter Ready: when bit 6 in the Status Register is a "1", a new byte may be written to the TxD Register; this byte will then be sent out by the serial port. The serial port registers must be read and written as 32-bit words (with the ldwio/stwio instructions), but only the 8 least significant bits are of interest. IS1500 nios2int 2014 page 21

22 Notes and hints The RxRdy status bit is cleared when a byte is read from RxDATA. The least significant bit is called bit 0. If you need a bit mask with bit number x set to 1, and all other bits zero, write a binary 1 followed by exactly x binary 0's. The assembler understands binary constants. Start them with 0b, for example 0b101 (that's 5 decimal). You will most likely want interrupts only from RxRdy, and not from TxRdy. Enabling interrupts from uart_0 1. Setup an interrupt handler for the interrupt-requests from device number 4 (uart_0). How to do this depends on your software configuration. 2. Set the enable bit (or bits) for interrupts from RxRdy and/or TxRdy in the control deviceregisters of the UART. 3. Set (to a logic "1") the bit with index 4 in the processor's ienable register (ctl3). A mask with this bit set is: 0x Set (to a logic "1") the processor's PIE bit (Processor Interrupt Enable) - bit 0 in the status register (ctl0). To acknowledge interrupts for received data, read input data from RxDATA. To acknowledge interrupts for transmitter-ready, write output data to TxDATA. Enabling interrupts from uart_1 1. Setup an interrupt handler for the interrupt-requests from device number 5 (uart_1). How to do this depends on your software configuration. 2. Set the enable bit (or bits) for interrupts from RxRdy and/or TxRdy in the control deviceregisters of the UART. 3. Set (to a logic "1") the bit with index 5 in the processor's ienable register (ctl3). A mask with this bit set is: 0x Set (to a logic "1") the processor's PIE bit (Processor Interrupt Enable) - bit 0 in the status register (ctl0). To acknowledge interrupts for received data, read input data from RxDATA. To acknowledge interrupts for transmitter-ready, write output data to TxDATA. Serial Input and Output Your program will produce output using the out_char subroutine. This routine sends one character to the serial port uart_0 on the DE2 board. A serial cable connects this serial port to a similar port on your laptop, or on the stationary computer in the managed computer room. You will have a related subroutine for reading input arriving at the same serial port. Serial ports uart_0 and uart_1 are described above, in the hardware section. A serial-port connector looks is shown in the photo to the right. IS1500 nios2int 2014 page 22

23 At the lab session, use the serial port of the KTH-managed computer at your seat. If you have your own computer, run the Nios II Software Build Tools on your computer, as usual. The DE2 board will have three cables connected: 1. Power cable (of course), 2. USB cable, connected to the computer running the Nios II Software Build Tools (such as, your portable computer), and 3. serial cable, connected to the KTH-managed desktop computer. Log in to the KTH-managed computer using your usual KTH login, also known as the KTH-ID. Use the Putty program for input and output through the serial port. Connect the serial cable to a serial-port on the KTH-managed computer. Do not connect the serial cable to the DE2 board yet. The serial-port will be on the back of the computer. If there is no serial-port, the laboratory teacher will lend you a USB-to-serial adapter. Connect the USB-to-serial adapter to a USB port on the KTH-managed computer before you continue. USB-to-serial adapter (only when no serial port is present) Before starting your terminal-emulator, you need to check the name of your serial port. Windows systems: open the Device Manager to check the port number. To open the Device Manager in Windows 7, click Start, then type "device manager" (or "enhetshanteraren" on a Swedish-language system). Click the Device Manager icon when it appears. In the Device Manager window, open the section Ports (COM & LPT) by clicking the appropriate plus-sign. Check the COM port number of the USB to Serial Bridge. Important: If you unplug the USB-to-serial adapter and connect it to a different USB port, the COM-port number will be different. Nothing will break if you use the wrong COM port. But the lab won't work, of course. Linux systems: insert the USB plug into a free USB jack on the computer. Do not connect the DE2 board yet. The adapter is nearly always called: /dev/ttyusb0 If you really must run putty on your own computer We recommend that you run putty on a computer owned by KTH. If you really want to run putty on your own computer, you can. If you have Windows 8, ask the laboratory teacher for a USB-to-serial converter converter suitable for use with Windows 8. To get the driver, please visit aten.com, mouse over "Support" and click "Software and Driver". Then select "UC232A" in the drop-down list. Scroll down a little to see the driver downloads for Windows 7 and Windows 8. IS1500 nios2int 2014 page 23

24 Putty Start Putty, and leave it running. Don't close and restart Putty, unless you have a USB-to-serial adapter and must disconnect and reconnect the adapter. Stopping the terminal-emulator will not stop your program, which is running all by itself on the DE2 board. Stopping the terminal-emulator just means that Windows (or Linux) will have to buffer up your program-output, possibly making your system slow and unresponsive. Windows systems: to start Putty, click Start, then type "putty". Click the icon when it appears. If this doesn't work, download Putty from Linux systems: to start Putty, open a Terminal and type: putty You will see the Putty Basic Options Configuration screen: Start by setting the Connection Type to Serial. Then click the Serial category in the left-hand pane. IS1500 nios2int 2014 page 24

25 You will see the Putty Serial Configuration screen: Set Serial line to connect to to the correct serial port. If the KTH-managed computer has a serial port, it's called COM1 or COM2. If you use a USB-toserial adapter, you know the COM-port number from your check with the Device Manager. Use speed baud and no flow control. Click Open. Note 1: If you unplug the USB-to-serial adapter and connect it to a different USB port, the COMport number is often different afterwards. Nothing will break if you use the wrong COM port. But the lab won't work, of course. Note 2: if you forgot to set the Connection Type to Serial, Putty will not respond when you click Open. Go back to the Session category and follow our instructions carefully. Assignments with Assembly-Language Interrupt Handlers Assembly-Language Assignments Assignments 1 through 5 will not use the Altera-supplied wrapper. You will have to write your own code for most of the interrupt-handling functions. To get you started, we provide you with files for Assignments 1 through 5, available in a zipped archive called nios2int2014asm.zip. In previous Laboratory Exercises, we used the putchar function. However, the putchar function uses the complex JTAG UART, which we will avoid in this lab exercise. Instead, we use uart_0.therefore, you must create a new System Library. The procedure to do this is described below. IS1500 nios2int 2014 page 25

26 Home Assignment 1 Prime Time You can use the NiiSim simulator to test your programs for this Home Assignment. At the laboratory session, you will use a DE2 board to run your programs on Nios2 hardware. Note: Instruction-set simulation carries a performance penalty. Simulated execution may be times slower than hardware. If interrupts are setup to occur 10 times per second, you can expect simulated interrupts to occur about every minute or so. Performance may vary considerably from time to time, from program to program, and of course from host computer to host computer. Task preliminaries HA1.1. Create a new Nios II Application and BSP from Template in the Nios II Software Build Tools. Call the project nios2int1. HA1.2. Copy the files nios2int1main.s and nios2intasmhelpers.c) to the project folder. HA1.3. Copy the files puttime_uart_0.c and tick.c into the project folder. HA1.4. Right-click the project name and select Refresh, so that the Nios II IDE re-checks the contents of the project directory. IS1500 nios2int 2014 page 26

27 HA1.5. Test the program using the NIISim simulator. Open the UART0 console (not the JTAG UART) - this applies to all assignments in this laboratory exercise. Typical output from a short run can look like this: HA1.6. Study the file nios2int1main.s until you understand the contents. Edit the file as specified below. Use the existing comments to guide your placement of the various code sections you write. Add comments detailing how your own code works. Add code to initialize timer_1 for continuous interrupts every 100 ms (10 interrupts per second); the clock frequency is 50 MHz. Add code to initialize the CPU for interrupts with index 10. Add code to allow interrupts in general. Interrupt code is the most difficult kind of code to debug, so make sure that all your code is easy to read. For every section of code you add or change, write detailed comments describing what you want to do, and how your code does it. HA1.7. Test the program using the NIISim simulator. Remember to open the UART0 console window. Typical output from a short run can look like this: IS1500 nios2int 2014 page 27

28 The NIISim simulator can simulate the board hardware. Click View I/O Board to open this view. The seven-segment LEDs will update and look something like this (when showing ): Demonstration for Assignment 1 - Prime Time There is no demonstration for Home Assignment 1 specifically. Home Assignments 1 through 5 are demonstrated together. IS1500 nios2int 2014 page 28

29 Home Assignment 2 Exceptional Exclamation Task HA2.1. Create a new project in the Nios II IDE, and call the new project nios2int2. Re-use your Board Support Package from Home Assignment 1: Re-using the Board Support Package will save you some disk space, and some compile time. HA2.2. Use the Nios II IDE to copy all files from your Home Assignment 1 to the new project folder. HA2.3. In the new project, change the filename of nios2int1main.s to nios2int2main.s. Using the nios2int2 project, edit nios2int2main.s as follows. Use existing comments to guide your placement of the code sections you write. Add comments detailing how your own code works. HA2.4. Modify the exception handler exchand. Add code to distinguish between interrupts and traps. For every piece of code you add or change, write detailed comments describing what you want to do, and how your code does it. IS1500 nios2int 2014 page 29

30 HA2.5. Modify the main program in nios2int2main.s, by inserting code near the label mainloop as specified below. Original code: mainloop: call primesearch # Add code here for Assignment 2 mov r4,r2 # # This is the end of the main loop. # We jump back to the beginning. br mainloop Changed code, new instructions in red: mainloop: call primesearch PUSH r4 movi r4,33 # 33 = '!' trap POP r4 mov r4,r2 # # This is the end of the main loop. # We jump back to the beginning. br mainloop The new program uses a trap instruction to print an extra character to the console (or terminalemulator). You MUST follow the specification. HA2.6. Test the program using the NIISim simulator. Typical output from a five-minute run can look like this: Note the exclamation sign ("!") after each prime-number printout. Demonstration for Assignment 2 Exceptional Exclamation There is no demonstration for Home Assignment 3 specifically. Home Assignments 1 through 5 are demonstrated together. IS1500 nios2int 2014 page 30

31 Home Assignment 3 T-Time Task HA3.1. Create a new project in the Nios II IDE, and call the new project nios2int3. Re-use the Board Support Package you created for Home Assignment 1. HA3.2. Copy all source files from your Home Assignment 2 to the new project folder. Change the filename of nios2int2main.s to nios2int3main.s. HA3.3. Edit nios2int3main.s as follows. Modify the exception handler exchand, by inserting code near the label timer1int as specified below. Original code: # Before calling a subroutine, push r1 through r15, and r31. PUSHMOST movia r4,mytime call puttime movia r4,mytime call tick # Add code here for Assignment 3 POPMOST # Afterwards, restore saved register values. Changed code, new instructions in red: # Before calling a subroutine, push r1 through r15, and r31. PUSHMOST movia r4,mytime call puttime movia r4,mytime call tick (you will need to add some code of your own here) movi r4,'t' trap (you will need to add some code of your own here) POPMOST # Afterwards, restore saved register values. You MUST follow the specification. The result should be that a T is printed after each time-display. However, since the trap instruction is now used from within an interrupt handler, that interrupt handler will need some additional modifications for this to work. This situation is similar to the case when an interrupt handler can be interrupted. However, there is no need to re-enable interrupts, as the trap instruction is not affected by the Processor Interrupt- Enable (PIE) flag. HA3.4. Edit nios2int3main.s, and perform the additional modifications necessary to allow the trap instruction to be used from within an interrupt handler. For every piece of code you add or change, write detailed comments describing what you want to do, and how your code does it. You MUST follow the specification. IS1500 nios2int 2014 page 31

32 HA3.5. Test the program using the NIISim simulator. Typical output may look like this: Note the "T" after each time-printout. Demonstration for Assignment 3 T-Time There is no demonstration for Home Assignment 4 specifically. Home Assignments 1 through 5 are demonstrated together. Home Assignment 4 The Key For this Home Assignment, you can use the NIISim simulator. to test your program. Task HA4.1. Create a new project in the Nios II IDE, and call the new project nios2int4. Re-use the Board Support Package you created for Home Assignment 1. HA4.2. Copy all source files from your Home Assignment 3 to the new project folder. Change the filename of nios2int3main.s to nios2int4main.s. HA4.3. Edit nios2int4main.s. Use the existing comments to guide your placement of the various code sections you write. For every piece of code you add or change, write detailed comments describing what you want to do, and how your code does it. The following modifications are required: Add code below the label main: (see the comments in the file) to initialize de2_pio_keys4 for interrupts when button KEY0 is pushed or released. Also add code to initialize the processor for interrupts with index 2, in addition to the previously initialized index 10. Add code in the exception handler exchand, to check if the interrupt came from timer_1 or from de2_pio_keys4. Also add code in the interrupt handler to perform the actions described in the table below, when an interrupt comes from de2_pio_keys4. IS1500 nios2int 2014 page 32

33 Action table for Assignment 4: Input Key KEY0 is pressed. (Down) Key KEY0 is released. (Up) Action An upper-case 'D' is sent using the subroutine out_char_uart_0. An upper-case 'U' is sent using the subroutine out_char_uart_0. Hint: you can check the status of the actual button in the interrupt handler. The interrupt will be processed immediately after the button is pushed or released, so the button will not have time to move. Therefore, if the button is up, the interrupt must have happened because the button was released and not pushed, and vice versa. HA4.4. Run your program in the NIISim simulator. Typical output will be identical to that of the previous Assignment. Test your program by clicking on the keys. Laboratory Assignment 4 The Key LA4.1. Change the initialization value for Timer 1, so that the time-out period becomes exactly 1 second. LA4.2. Follow our tutorial for connecting the DE2 board. Since you have finished lab 1 (nios2time), the driver is already installed. LA4.3. Connect a serial cable between the DE2 board and a computer. We recommend that you use the computer supplied by KTH for this, even if you have your own computer with programs and Nios II Software. Use our USB-to-serial adapter if necessary. If you use the USB-to-serial adapter, start the terminal emulator putty according to the instructions for lab nios2io. If you use a USB-to-serial converter, output will be visible only in the terminal emulator. The Nios II IDE may show a blank console window, or an error message. See the section on Known issues (above). If your computer has a serial port, the Nios II IDE will detect the port and connect it to the console window. This is different from lab nios2io. The reason is that you selected uart_0 rather than the JTAG UART in the System Library settings for the current lab (nios2int). LA4.4. Test your program using the DE2 board. Verify the following properties. Prime numbers must be printed several times per minute. The time must be printed exactly once per second. The time will also be shown on the seven-segment display. A 'D' (for "down") must be printed when KEY0 is pressed, and an 'U' (for "up") must be printed when the key is released. Demonstration for Assignment 4 The Key Call the laboratory teacher, restart your program, and let him/her test it. Answer all questions he/she may ask. IS1500 nios2int 2014 page 33

34 Laboratory Assignment 5 First Surprise Assignment LA5.1. Use the Nios II IDE to create a new project, called nios2surprise1. If this is not your first surprise assignment, use the next available higher number: nios2surprise2, etcetera. LA5.2. Use the Nios II IDE to copy all files from your nios2int4 project to the new project. LA5.3. Contact the laboratory teacher; he/she will decide on an individual surprise assignment for you. The laboratory teacher's decision is not negotiable. You must complete your individual surprise assignment during the session, in order to pass this laboratory exercise. Before making the decision, the laboratory teacher will welcome suggestions from you, for surprise projects that you find interesting. You can discuss projects of any difficulty, since projects which are too difficult (or too easy) will be rejected by the laboratory teacher. Surprise Assignments cannot be taken home to be shown later, but must be finished during the current session. Should you be unable to finish the Surprise Assignment, you will have to return for a later lab session. In that later session, you will get a new Surprise Assignment, to be finished during that session. Demonstration for Assignment 5 First Surprise Assignment Show your completed surprise-project to the laboratory teacher. Answer all questions that he/she asks. C-code Assignments For assignment 6 and on, please use the files in the zipped archive called nios2int2014c.zip. Assignments 6 and on use the Altera-supplied exception-wrapper. There's a short description on page 13. For more information on alt_ic_isr_register and other useful functions, please check Altera's literature. Each function is described in detail in the Nios II Software Developer's Handbook, Chapter 14 (HAL API Reference). For these assignments, you will need our initialization fixup subroutine. The subroutine is called intfix and is available in file intfix.c. The intfix subroutine must be called before any other code in your program, and only once. The intfix subroutine removes all unused handlers (which have been added by Altera-supplied initialization code). After running intfix, interrupts are enabled only from the JTAG UART, and also from the system timer (timer_0). These devices are used by the Altera-supplied system software for communication between the DE2 board and the Nios II IDE. Detailed information: The Altera-supplied initialization code initializes all devices present in the system-design configuration file, and sets up standardized Interrups Service Routines for those devices. In our programs, we need to initialize some devices using our own code. Such devices include timer_1 and de2_pio_keys4. We also want to leave many devices uninitialized, and with interrupts turned off; those devices include timer_2 and others which are not used in this course. Calling alt_ic_isr_register, with a null-pointer argument for the interrupt-handling function, will remove the interrupt handler. The intfix subroutine calls alt_ic_isr_register in this way, once for each unwanted interrupt handler. IS1500 nios2int 2014 page 34

35 Home Assignment 6 Toggles For this Home Assignment, you can use the NIISim Simulator to test some parts of your program. The parallel input-port de2_pio_keys4, and the buttons that provide input through that port, are not simulated. At the laboratory session, you will be able to test the complete program by running it on a DE2 board. To get you started, we provide the file nios2intc.c (also available in a zipped archive). You will also need an initialization fixup subroutine, intfix.c), for Home Assignment 6 and on. The intfix subroutine must be called before any other code in your main program, and only once. The intfix subroutine disables the Altera-supplied interrupt handlers for most devices. Task preliminaries - do this first! HA6.1. Create a new project in the Nios II IDE, and call the new project nios2int6. Re-use the Board Support Package you created for Home Assignment 1. HA6.2. Copy files intfix.c, nios2intc.c and puttime_uart_0.c to the project folder. Also copy the source file for the tick.c subroutine to the new project folder. If necessary, right-click the project name and select Refresh, so that the Nios II IDE re-checks the contents of the project directory. The supplied file nios2intc.c initializes interrupts from the push-button KEY0, connected to the de2_pio_keys4 device. The interrupt handler is called irq_handler_keys, and performs the actions specified in the table below. Make sure you understand how the interrupts from the de2_pio_keys4 device works, and how they are initialized. Action table for interrupts from de2_pio_keys4 Input Action An upper-case 'D' is printed using out_char_uart_0. Green LED LEDG0 lights up (and continues shining). Key KEY0 is pressed. The handler waits about 2 seconds, after which time a lower-case 'd' is printed using out_char_uart_0. Key KEY0 is released. An upper-case 'U' is printed using out_char_uart_0. Green LED LEDG0 turns off (and continues being dark). One or several out of KEY1 through KEY3 are pressed Nothing happens. and/or released. The supplied file nios2intc.c contains a C-language interrupt-handler for de2_pio_keys4. This handler implements actions very similar to those of your assembly-language interrupt handler from Assignment 5. Differences: The C-language handler turns on green LED LEDG0 for the button-down interrupt, and turns off the same LED for the button-up interrupt. The assembly-language handler does not affect the green LEDs. The C-language handler delays for about 2 seconds before returning. There is no such delay in the assembly-language handler. The C-language handler prints a lower-case 'd' after the delay but immediately before returning. The assembly-language handler only prints uppercase letters 'D' and 'U' (see action tables for details). IS1500 nios2int 2014 page 35

36 Task - the real tasks are here! HA6.3. Write new subroutines toggles_init and irq_handler_toggles; toggles_init initializes the parallel input-port de2_pio_toggles18 for interrupts, while irq_handler_toggles examines which switch (or switches) has (or have) been toggled, and performs actions detailed below. Modify your main program to contain calls to these functions. Test the subroutines using the main program. We recommend that you add the subroutines toggles_init and irq_handler_toggles to the main program file (nios2intc.c). Note: Having one large file with most of the code is not the best practice in general, but can be accepted for small programs. The best practice is to have separate files for separate functions. This, however, would require you to add correct C function headers (type definitions) to all files, or to write a separate header file. The added complexity would be beyond the scope of this laboratory exercise. Specification: toggles_init Name: The subroutine must be called toggles_init. Input parameters: None. Return value: None. Side effects: The subroutine must initialize the parallel input-port de2_pio_toggles18, controlled by reading and writing addresses in the range 0x850-0x85F, so that its interrupt output is activated when switch SW0 changes position ("toggles"). The subroutine must also "register the ISR" by calling the alt_ic_isr_register function with correct input parameters.. The values in registers r1 through r15 may be altered. All other registers must have unchanged values when the subroutine returns. Language: You must use the C language for this subroutine. C language: The C-language function prototype is: void toggles_init( void ); Specification: irq_handler_toggles Name: The subroutine must be called irq_handler_toggles. Input parameter: Only one: a pointer to a context (first parameter, in register r4). The subroutine is allowed to ignore both parameters. Return value: None. Side effects: In all cases, the interrupt must be acknowledged. Furthermore, actions should be taken according to the table below. The values in registers r1 through r15 may be altered. All other registers must have unchanged values when the subroutine returns. Language: You must use the C language for this subroutine. C language: The C-language function prototype is: void irq_handler_toggles( void * ); IS1500 nios2int 2014 page 36

37 Action table for interrupts from de2_pio_toggles18 Input Action Switch SW0 changes position. One of SW1 through Nothing happens. SW17 changes position. You MUST follow the specifications. Red LED LEDR0 lights up, and an upper-case 'S' is printed using out_char_uart_0. The interrupt handler then waits for a predefined time by calling bigdelay(); After the wait, red LED LEDR0 turns off (and continues being dark), and a lower-case 's' i printed using out_char_uart_0. HA6.5. Compile the project, and test the program using the NIISim simulator. Typical output may look like this: HA6.6. Test button KEY0 with the NIISim simulator and check the LEDs, and the changes in the UART0 console output. When pressing and holding KEY0, you should see a D, then a pause, then a d. When releasing KEY0, you should see an U. IS1500 nios2int 2014 page 37

38 Laboratory Assignment 6 Toggles LA6.1. Modify the definition of TIMER_1_TIMEOUT in the file nios2intc.c, so that the larger value is used ( ). Otherwise, your display will be cluttered with time values, and hard to read. Rebuild the project. Note: When using the DE2 hardware, all output from the DE2 board will use uart_0. Remember to connect the serial cable. If you use a USB-to-serial converter, output will be visible only in the putty terminal-emulator. LA6.2. Test your program using the DE2 board. Verify that keypresses and switch-toggling cause actions according to the action tables. Also check that underscores are still printed several times per second, and that the time is printed correctly once per second. Examine specifically what happens in the following cases. Make sure you can explain the behavior. LA6.3.Press button KEY0 and hold it down. Move switch SW0 from one position from the other. Immediately after this, while the handler irq_handler_toggles is still waiting, release KEY0. Explain the printouts on the console, and the behavior observed on the red and green LEDs. LA6.4. Toggle switch SW0. Immediately after this, while the handler irq_handler_toggles is still waiting, press button KEY0 and release it again immediately. Explain the printouts on the console, and the behavior observed on the red and green LEDs. Demonstration for Assignment 6 Toggles Call the laboratory teacher, restart your program, and let him/her test it. Answer all questions he/she may ask. Explain the behaviors in Laboratory Assignments LA6.3 and LA6.4. Laboratory Assignment 7 Second Surprise Assignment Note: there is no Home Assignment 7. LA7.1. Use the Nios II IDE to create a new project, called nios2surprise1. If this is not your first surprise assignment, use the next available higher number: nios2surprise2, etcetera. LA7.2. Use the Nios II IDE to copy all files from your nios2int7 project to the new project. LA7.3. Contact the laboratory teacher; he/she will decide on an individual surprise assignment for you. The laboratory teacher's decision is not negotiable. You must complete your individual surprise assignment during the session, in order to pass this laboratory exercise. Before making the decision, the laboratory teacher will welcome suggestions from you, for surprise projects that you find interesting. You can discuss projects of any difficulty, since projects which are too difficult (or too easy) will be rejected by the laboratory teacher. Surprise Assignments cannot be taken home to be shown later, but must be finished during the current session. Should you be unable to finish the Surprise Assignment, you will have to return for a later lab session. In that later session, you will get a new Surprise Assignment, to be finished during that session. Demonstration for Assignment 7 Second Surprise Assignment Show your completed surprise-project to the laboratory teacher. Answer all questions that he/she asks. IS1500 nios2int 2014 page 38

39 Laboratory Assignment 8 Packing up the Board Please make sure that box and board matches The number on the board should match the number on the box. If the numbers don't match, please find the right box. In case you fail to find the correct box, talk to the laboratory teacher, so that he/she can make a note (and match up the boards and boxes later). Power supply and USB cable, nothing else The USB cable and power supply should be at the bottom of the box. Let the cables lie loosely - they may not fit otherwise. At some laboratory sessions, you will use extra cables. Any extra cables should not be in the box. Please give them to the laboratory teacher, who will pack them separately. IS1500 nios2int 2014 page 39

40 Cardboard divider Now fold in the cardboard divider. Plastic-foam protector and the DE2 board After you have folded in the divider, put in the plastic-foam protector and place the board in the foam. One edge of the plastic foam has a cut-out for the connectors that extend slightly from the back of the board. Please orient the board so that the connectors face this cut-out area. Otherwise, the board will not fit well into the plastic foam. IS1500 nios2int 2014 page 40

41 Foam sheet on top Now add the thin sheet of foam, to protect the top of the board. Note: Some boxes do not have a foam-sheet. Close the box and return it Finally, close the box, and return it to the laboratory teacher. Taking good care of our laboratory boards make them last longer. Thank you for your help! IS1500 nios2int 2014 page 41

I expect you to understand everything discussed prior to this page. In particular:

I expect you to understand everything discussed prior to this page. In particular: A NOTE TO 259 STUDENTS: Interrupts involve a lot of details. The details presented after this page provide further background on exactly what happens at the CPU logic and assembly code levels. This may

More information

Detailed Nios II Exception Process

Detailed Nios II Exception Process Detailed Nios II Exception Process When an exception is triggered, the CPU does the following steps automatically: 1. Copy the contents of status to estatus to save pre-exception state 2. Clear (0) PIE

More information

Debugging of Application Programs on Altera s DE-Series Boards. 1 Introduction

Debugging of Application Programs on Altera s DE-Series Boards. 1 Introduction Debugging of Application Programs on Altera s DE-Series Boards 1 Introduction This tutorial presents some basic concepts that can be helpful in debugging of application programs written in the Nios II

More information

Laboratory Exercise 7

Laboratory Exercise 7 Laboratory Exercise 7 Using Interrupts with C code The purpose of this exercise is to investigate the use of interrupts for the Nios II processor, using C code. To do this exercise you need to have a good

More information

Computer Hardware Engineering

Computer Hardware Engineering 2 Course Structure Computer Hardware ngineering IS1200, spring 2015 Lecture 3: Languages Module 4: I/O Systems Module 1: Logic Design L DCÖ1 L DCÖ2 Lab:dicom L7 Module 2: C and Assembly Programming Associate

More information

University of Massachusetts Amherst Computer Systems Lab 1 (ECE 354) LAB 1 Reference Manual

University of Massachusetts Amherst Computer Systems Lab 1 (ECE 354) LAB 1 Reference Manual University of Massachusetts Amherst Computer Systems Lab 1 (ECE 354) LAB 1 Reference Manual Lab 1: Using NIOS II processor for code execution on FPGA Objectives: 1. Understand the typical design flow in

More information

NIOS CPU Based Embedded Computer System on Programmable Chip

NIOS CPU Based Embedded Computer System on Programmable Chip 1 Objectives NIOS CPU Based Embedded Computer System on Programmable Chip EE8205: Embedded Computer Systems This lab has been constructed to introduce the development of dedicated embedded system based

More information

CS 11 C track: lecture 8

CS 11 C track: lecture 8 CS 11 C track: lecture 8 n Last week: hash tables, C preprocessor n This week: n Other integral types: short, long, unsigned n bitwise operators n switch n "fun" assignment: virtual machine Integral types

More information

1. Number Conversions [8 marks]

1. Number Conversions [8 marks] 1. Number Conversions [8 marks] a. convert the decimal number 42 to a 16-bit signed integer in binary 0b0000 0000 0010 1010 b. convert the 8-bit number 0x42 to a 16-bit signed integer in binary 0b0000

More information

Getting Started with the HCS12 IDE

Getting Started with the HCS12 IDE Getting Started with the HCS12 IDE B. Ackland June 2015 This document provides basic instructions for installing and using the MiniIDE Integrated Development Environment and the Java based HCS12 simulator.

More information

University of Massachusetts Amherst Computer Systems Lab 2 (ECE 354) Spring Lab 1: Using Nios 2 processor for code execution on FPGA

University of Massachusetts Amherst Computer Systems Lab 2 (ECE 354) Spring Lab 1: Using Nios 2 processor for code execution on FPGA University of Massachusetts Amherst Computer Systems Lab 2 (ECE 354) Spring 2007 Lab 1: Using Nios 2 processor for code execution on FPGA Objectives: After the completion of this lab: 1. You will understand

More information

University of Toronto Faculty of Applied Science and Engineering Department of Electrical and Computer Engineering Final Examination

University of Toronto Faculty of Applied Science and Engineering Department of Electrical and Computer Engineering Final Examination University of Toronto Faculty of Applied Science and Engineering Department of Electrical and Computer Engineering Final Examination ECE 253F - Digital and Computer Systems Friday December 10, 2010 Duration:

More information

SISTEMI EMBEDDED. (Software) Exceptions and (Hardware) Interrupts. Federico Baronti Last version:

SISTEMI EMBEDDED. (Software) Exceptions and (Hardware) Interrupts. Federico Baronti Last version: SISTEMI EMBEDDED (Software) Exceptions and (Hardware) Interrupts Federico Baronti Last version: 20160410 Exceptions and Interrupts Exception: a transfer of control away from a program s normal flow of

More information

Interrupts L33-1. Interrupts

Interrupts L33-1. Interrupts L33-1 Interrupts Interrupts Interrupts are like receiving a telephone call while you are in a face-to-face meeting: The phone rings (ie, an interrupt is sent) Tell the person you are meeting with to please

More information

Basic Computer System for the Altera DE0-Nano Board. 1 Introduction. 2 DE0-Nano Basic Computer Contents. 2.1 Nios II Processor. For Quartus II 13.

Basic Computer System for the Altera DE0-Nano Board. 1 Introduction. 2 DE0-Nano Basic Computer Contents. 2.1 Nios II Processor. For Quartus II 13. Basic Computer System for the Altera DE0-Nano Board For Quartus II 13.0 1 Introduction This document describes a simple computer system that can be implemented on the Altera DE0-Nano development and education

More information

NIOS CPU Based Embedded Computer System on Programmable Chip

NIOS CPU Based Embedded Computer System on Programmable Chip NIOS CPU Based Embedded Computer System on Programmable Chip EE8205: Embedded Computer Systems NIOS-II SoPC: PART-II 1 Introduction This lab has been constructed to introduce the development of dedicated

More information

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465 Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465 Keywords: MAXQ, MAXQ610, UART, USART, serial, serial port APPLICATION NOTE 4465 Using the Serial Port on the

More information

So, you want to run interp on a MIPS target through a E-JTAG emulator?

So, you want to run interp on a MIPS target through a E-JTAG emulator? Porting Monograph 2 - MIPS EPI/MAJIC So, you want to run interp on a MIPS target through a E-JTAG emulator? Even if your target --isn't-- MIPS, this porting example will address common problems you should

More information

YOU WILL NOT BE ALLOWED INTO YOUR LAB SECTION WITHOUT THE REQUIRED PRE-LAB.

YOU WILL NOT BE ALLOWED INTO YOUR LAB SECTION WITHOUT THE REQUIRED PRE-LAB. Page 1/5 Revision 3 OBJECTIVES Explore and understand microprocessor interrupts. In part A of this lab, you will use XMEGA external interrupt system. Learn how to utilize asynchronous serial communication.

More information

Process Context & Interrupts. New process can mess up information in old process. (i.e. what if they both use the same register?)

Process Context & Interrupts. New process can mess up information in old process. (i.e. what if they both use the same register?) 1 Process Context 1.1 What is context? A process is sometimes called a task, subroutine or program. Process context is all the information that the process needs to keep track of its state. Registers Temporary

More information

Boot Camp. Dave Eckhardt Bruce Maggs

Boot Camp. Dave Eckhardt Bruce Maggs Boot Camp Dave Eckhardt de0u@andrew.cmu.edu Bruce Maggs bmm@cs.cmu.edu 1 This Is a Hard Class Traditional hazards 410 letter grade one lower than other classes All other classes this semester: one grade

More information

EE 361 University of Hawaii Fall

EE 361 University of Hawaii Fall C functions Road Map Computation flow Implementation using MIPS instructions Useful new instructions Addressing modes Stack data structure 1 EE 361 University of Hawaii Implementation of C functions and

More information

Basic Computer System for the Altera DE1 Board. 1 Introduction. 2 DE1 Basic Computer Contents. 2.1 Nios II Processor.

Basic Computer System for the Altera DE1 Board. 1 Introduction. 2 DE1 Basic Computer Contents. 2.1 Nios II Processor. Basic Computer System for the Altera DE1 Board For Quartus II 8 1 Introduction This document describes a simple computer system that can be implemented on the Altera DE1 development and education board.

More information

Introduction to Embedded Systems. Lab Logistics

Introduction to Embedded Systems. Lab Logistics Introduction to Embedded Systems CS/ECE 6780/5780 Al Davis Today s topics: lab logistics interrupt synchronization reentrant code 1 CS 5780 Lab Logistics Lab2 Status Wed: 3/11 teams have completed their

More information

Everything You Wanted To Know About USB Embossers* *but were afraid to ask

Everything You Wanted To Know About USB Embossers* *but were afraid to ask Braille2000, LLC 6801 Southfork Cir, Lincoln, NE 68516 Phone: (402) 423-4782, Fax: (402) 423-5154 http://www.braille2000.com Everything You Wanted To Know About USB Embossers* *but were afraid to ask This

More information

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives: ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives: This lab will introduce basic embedded systems programming concepts by familiarizing the user with an embedded programming

More information

MIPS Functions and Instruction Formats

MIPS Functions and Instruction Formats MIPS Functions and Instruction Formats 1 The Contract: The MIPS Calling Convention You write functions, your compiler writes functions, other compilers write functions And all your functions call other

More information

Laboratory Exercise 3 Comparative Analysis of Hardware and Emulation Forms of Signed 32-Bit Multiplication

Laboratory Exercise 3 Comparative Analysis of Hardware and Emulation Forms of Signed 32-Bit Multiplication Laboratory Exercise 3 Comparative Analysis of Hardware and Emulation Forms of Signed 32-Bit Multiplication Introduction All processors offer some form of instructions to add, subtract, and manipulate data.

More information

Last Name (in case pages get detached): UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING FINAL EXAMINATION, APRIL 2011

Last Name (in case pages get detached): UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING FINAL EXAMINATION, APRIL 2011 Page 1 of 17 UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING FINAL EXAMINATION, APRIL 2011 ECE243H1 S COMPUTER ORGANIZATION Exam Type: D Duration: 2.5 Hours Prof.s Anderson, Enright Jerger,

More information

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Laboratory Assignment #4 Debugging in Eclipse CDT 1 Lab 4 (10 points) November 20, 2013 CS-2301, System Programming for Non-majors, B-term 2013 Objective Laboratory Assignment #4 Debugging in Eclipse CDT 1 Due: at 11:59 pm on the day of your lab session

More information

DKAN0011A Setting Up a Nios II System with SDRAM on the DE2

DKAN0011A Setting Up a Nios II System with SDRAM on the DE2 DKAN0011A Setting Up a Nios II System with SDRAM on the DE2 04 November 2009 Introduction This tutorial details how to set up and instantiate a Nios II system on Terasic Technologies, Inc. s DE2 Altera

More information

LAB C Translating Utility Classes

LAB C Translating Utility Classes LAB C Translating Utility Classes Perform the following groups of tasks: LabC1.s 1. Create a directory to hold the files for this lab. 2. Create and run the following two Java classes: public class IntegerMath

More information

BASICS OF THE RENESAS SYNERGY PLATFORM

BASICS OF THE RENESAS SYNERGY PLATFORM BASICS OF THE RENESAS SYNERGY PLATFORM TM Richard Oed 2017.12 02 CHAPTER 9 INCLUDING A REAL-TIME OPERATING SYSTEM CONTENTS 9 INCLUDING A REAL-TIME OPERATING SYSTEM 03 9.1 Threads, Semaphores and Queues

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Last Name (in case pages get detached): UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING MIDTERM EXAMINATION, MARCH 2011

Last Name (in case pages get detached): UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING MIDTERM EXAMINATION, MARCH 2011 Page 1 of 13 UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING MIDTERM EXAMINATION, MARCH 2011 ECE243H1 S COMPUTER ORGANIZATION Exam Type: D Duration: 2 Hours Prof.s Anderson, Enright Jerger,

More information

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment Com S 227 Spring 2018 Assignment 1 100 points Due Date: Friday, September 14, 11:59 pm (midnight) Late deadline (25% penalty): Monday, September 17, 11:59 pm General information This assignment is to be

More information

University of Toronto Faculty of Applied Science and Engineering

University of Toronto Faculty of Applied Science and Engineering Print: First Name:............................. Last Name:............................. Student Number:............................................... University of Toronto Faculty of Applied Science and

More information

Part 1: Start up. Part 2: Add Instruction. Part 3: Another way to get data into a register

Part 1: Start up. Part 2: Add Instruction. Part 3: Another way to get data into a register Part 1: Start up Power on the DE2 (Lab 0 showed you how), and begin the project by doing the following: Create new project directory Copy lab1sof and lab1ptf to the new directory Copy code provided (lab01?s)

More information

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;} Subroutines Also called procedures or functions Example C code: int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;} // subroutine converts Celsius to kelvin int celtokel(int i) { return (i

More information

The K Project. Interrupt and Exception Handling. LSE Team. May 14, 2018 EPITA. The K Project. LSE Team. Introduction. Interrupt Descriptor Table

The K Project. Interrupt and Exception Handling. LSE Team. May 14, 2018 EPITA. The K Project. LSE Team. Introduction. Interrupt Descriptor Table and Exception Handling EPITA May 14, 2018 (EPITA) May 14, 2018 1 / 37 and Exception Handling Exception : Synchronous with program execution (e.g. division by zero, accessing an invalid address) : Asynchronous

More information

Handout Objectives: a. b. c. d. 3. a. b. c. d. e a. b. 6. a. b. c. d. Overview:

Handout Objectives: a. b. c. d. 3. a. b. c. d. e a. b. 6. a. b. c. d. Overview: Computer Basics I Handout Objectives: 1. Control program windows and menus. 2. Graphical user interface (GUI) a. Desktop b. Manage Windows c. Recycle Bin d. Creating a New Folder 3. Control Panel. a. Appearance

More information

18-349: Introduction to Embedded Real-Time Systems

18-349: Introduction to Embedded Real-Time Systems 18-349: Introduction to Embedded Real-Time Systems Embedded Real-Time Systems Lecture 6: Timers and Interrupts Anthony Rowe Electrical and Computer Engineering Carnegie Mellon University Embedded Real-Time

More information

BASICS OF THE RENESAS SYNERGY TM

BASICS OF THE RENESAS SYNERGY TM BASICS OF THE RENESAS SYNERGY TM PLATFORM Richard Oed 2018.11 02 CHAPTER 9 INCLUDING A REAL-TIME OPERATING SYSTEM CONTENTS 9 INCLUDING A REAL-TIME OPERATING SYSTEM 03 9.1 Threads, Semaphores and Queues

More information

Project 3: RPN Calculator

Project 3: RPN Calculator ECE267 @ UIC, Spring 2012, Wenjing Rao Project 3: RPN Calculator What to do: Ask the user to input a string of expression in RPN form (+ - * / ), use a stack to evaluate the result and display the result

More information

Codewarrior for ColdFire (Eclipse) 10.0 Setup

Codewarrior for ColdFire (Eclipse) 10.0 Setup Codewarrior for ColdFire (Eclipse) 10.0 Setup 1. Goal This document is designed to ensure that your Codewarrior for Coldfire v10.0 environment is correctly setup and to orient you to it basic functionality

More information

IRIX is moving in the n32 direction, and n32 is now the default, but the toolchain still supports o32. When we started supporting native mode o32 was

IRIX is moving in the n32 direction, and n32 is now the default, but the toolchain still supports o32. When we started supporting native mode o32 was Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2002 Handout 23 Running Under IRIX Thursday, October 3 IRIX sucks. This handout describes what

More information

Introduction to the Altera SOPC Builder Using Verilog Design

Introduction to the Altera SOPC Builder Using Verilog Design Introduction to the Altera SOPC Builder Using Verilog Design This tutorial presents an introduction to Altera s SOPC Builder software, which is used to implement a system that uses the Nios II processor

More information

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission.

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission. INTRODUCTION This manual will guide you through the first steps of getting the SE-8051ICD running with the Crossware 8051 Development Suite and the Atmel Flexible In-System Programming system (FLIP). The

More information

DE2-115 Computer System. 1 Introduction. 2 DE2-115 Computer Contents. 2.1 Nios II Processor. For Quartus Prime 16.1

DE2-115 Computer System. 1 Introduction. 2 DE2-115 Computer Contents. 2.1 Nios II Processor. For Quartus Prime 16.1 DE2-115 Computer System For Quartus Prime 16.1 1 Introduction This document describes a computer system that can be implemented on the Intel DE2-115 development and education board. This system, called

More information

IS1200/IS1500. Lab 5 Processor Design v1.0

IS1200/IS1500. Lab 5 Processor Design v1.0 IS1200/IS1500 Lab 5 Processor Design 2015-10-20 v1.0 Introduction Welcome to the fifth lab! In this laboratory exercise, you will learn the fundamentals of processor design. After finishing this lab, you

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

ECE2049 Embedded Computing in Engineering Design. Lab #0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

ECE2049 Embedded Computing in Engineering Design. Lab #0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio ECE2049 Embedded Computing in Engineering Design Lab #0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio In this lab you will be introduced to the Code Composer Studio

More information

NIOS CPU Based Embedded Computer System on Programmable Chip

NIOS CPU Based Embedded Computer System on Programmable Chip NIOS CPU Based Embedded Computer System on Programmable Chip 1 Lab Objectives EE8205: Embedded Computer Systems NIOS-II SoPC: PART-I This lab has been constructed to introduce the development of dedicated

More information

Code::Blocks Student Manual

Code::Blocks Student Manual Code::Blocks Student Manual Lawrence Goetz, Network Administrator Yedidyah Langsam, Professor and Theodore Raphan, Distinguished Professor Dept. of Computer and Information Science Brooklyn College of

More information

In examining performance Interested in several things Exact times if computable Bounded times if exact not computable Can be measured

In examining performance Interested in several things Exact times if computable Bounded times if exact not computable Can be measured System Performance Analysis Introduction Performance Means many things to many people Important in any design Critical in real time systems 1 ns can mean the difference between system Doing job expected

More information

Lesson 3 Transcript: Part 1 of 2 - Tools & Scripting

Lesson 3 Transcript: Part 1 of 2 - Tools & Scripting Lesson 3 Transcript: Part 1 of 2 - Tools & Scripting Slide 1: Cover Welcome to lesson 3 of the db2 on Campus lecture series. Today we're going to talk about tools and scripting, and this is part 1 of 2

More information

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

QUIZ How do we implement run-time constants and. compile-time constants inside classes? QUIZ How do we implement run-time constants and compile-time constants inside classes? Compile-time constants in classes The static keyword inside a class means there s only one instance, regardless of

More information

Hardware OS & OS- Application interface

Hardware OS & OS- Application interface CS 4410 Operating Systems Hardware OS & OS- Application interface Summer 2013 Cornell University 1 Today How my device becomes useful for the user? HW-OS interface Device controller Device driver Interrupts

More information

Computer Basics: Step-by-Step Guide (Session 2)

Computer Basics: Step-by-Step Guide (Session 2) Table of Contents Computer Basics: Step-by-Step Guide (Session 2) ABOUT PROGRAMS AND OPERATING SYSTEMS... 2 THE WINDOWS 7 DESKTOP... 3 TWO WAYS TO OPEN A PROGRAM... 4 DESKTOP ICON... 4 START MENU... 5

More information

Programming Model 2 A. Introduction

Programming Model 2 A. Introduction Programming Model 2 A. Introduction Objectives At the end of this lab you should be able to: Use direct and indirect addressing modes of accessing data in memory Create an iterative loop of instructions

More information

TDT 1.2 Release Notes and FAQ March 2002

TDT 1.2 Release Notes and FAQ March 2002 TDT 1.2 Release Notes and FAQ March 2002 This document gives additional information about the use of the ARM Trace Debug Tools TDT 1.2 (build 1031) For more information, please see the Trace Debug Tools

More information

Arduino IDE Friday, 26 October 2018

Arduino IDE Friday, 26 October 2018 Arduino IDE Friday, 26 October 2018 12:38 PM Looking Under The Hood Of The Arduino IDE FIND THE ARDUINO IDE DOWNLOAD First, jump on the internet with your favorite browser, and navigate to www.arduino.cc.

More information

ENCM 369 Winter 2017 Lab 3 for the Week of January 30

ENCM 369 Winter 2017 Lab 3 for the Week of January 30 page 1 of 11 ENCM 369 Winter 2017 Lab 3 for the Week of January 30 Steve Norman Department of Electrical & Computer Engineering University of Calgary January 2017 Lab instructions and other documents for

More information

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python Programming Languages Streams Wrapup, Memoization, Type Systems, and Some Monty Python Quick Review of Constructing Streams Usually two ways to construct a stream. Method 1: Use a function that takes a(n)

More information

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text 1. Interrupt An interrupt is the occurrence of a condition--an event --

More information

Prerequisites for Eclipse

Prerequisites for Eclipse Prerequisites for Eclipse 1 To use Eclipse you must have an installed version of the Java Runtime Environment (JRE). The latest version is available from java.com/en/download/manual.jsp Since Eclipse includes

More information

Real Time Embedded Systems. Lecture 10 January 31, 2012 Interrupts

Real Time Embedded Systems.  Lecture 10 January 31, 2012 Interrupts Interrupts Real Time Embedded Systems www.atomicrhubarb.com/embedded Lecture 10 January 31, 2012 Interrupts Section Topic Where in the books Catsoulis chapter 1 (pg 10-12) Simon chapter4 Zilog UM197 (ZNEO

More information

EE 109 Unit 17 - Exceptions

EE 109 Unit 17 - Exceptions EE 109 Unit 17 - Exceptions 1 2 What are Exceptions? Any event that causes a break in normal execution Error Conditions Invalid address, Arithmetic/FP overflow/error Hardware Interrupts / Events Handling

More information

CS 2505 Computer Organization I

CS 2505 Computer Organization I Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

Lab 9: On-Board Time Generation and Interrupts

Lab 9: On-Board Time Generation and Interrupts Lab 9: On-Board Time Generation and Interrupts Summary: Develop a program and hardware interface that will utilize externally triggered interrupts and the onboard timer functions of the 68HC12. Learning

More information

Using Visual Studio.NET: IntelliSense and Debugging

Using Visual Studio.NET: IntelliSense and Debugging DRAFT Simon St.Laurent 3/1/2005 2 Using Visual Studio.NET: IntelliSense and Debugging Since you're going to be stuck using Visual Studio.NET anyway, at least for this edition of the.net Compact Framework,

More information

GOBENCH IQ Release v

GOBENCH IQ Release v GOBENCH IQ Release v1.2.3.3 2018-06-11 New Add-Ons / Features / Enhancements in GOBENCH IQ v1.2.3.3 GOBENCH IQ v1.2.3.3 contains several new features and enhancements ** New version of the comparison Excel

More information

INTERRUPTS in microprocessor systems

INTERRUPTS in microprocessor systems INTERRUPTS in microprocessor systems Microcontroller Power Supply clock fx (Central Proccesor Unit) CPU Reset Hardware Interrupts system IRQ Internal address bus Internal data bus Internal control bus

More information

In further discussion, the books make other kinds of distinction between high level languages:

In further discussion, the books make other kinds of distinction between high level languages: Max and Programming This essay looks at Max from the point of view of someone with a bit of experience in traditional computer programming. There are several questions that come up from time to time on

More information

EE 109 Unit 15 Subroutines and Stacks

EE 109 Unit 15 Subroutines and Stacks 1 EE 109 Unit 15 Subroutines and Stacks 2 Program Counter and GPRs (especially $sp, $ra, and $fp) REVIEW OF RELEVANT CONCEPTS 3 Review of Program Counter PC is used to fetch an instruction PC contains

More information

AT&T Voice DNA Receptionist User Guide

AT&T Voice DNA Receptionist User Guide AT&T Voice DNA Receptionist User Guide Page 2 of 28 Table of Contents About Receptionist... 3 Start Receptionist... 4 Use Receptionist the First Time... 4 Use Receptionist After the First Time... 7 The

More information

CHAPTER 11 INTERRUPTS PROGRAMMING

CHAPTER 11 INTERRUPTS PROGRAMMING CHAPTER 11 INTERRUPTS PROGRAMMING Interrupts vs. Polling An interrupt is an external or internal event that interrupts the microcontroller To inform it that a device needs its service A single microcontroller

More information

Microprocessors B (17.384) Spring Lecture Outline

Microprocessors B (17.384) Spring Lecture Outline Microprocessors B (17.384) Spring 2013 Lecture Outline Class # 04 February 12, 2013 Dohn Bowden 1 Today s Lecture Administrative Microcontroller Hardware and/or Interface Programming/Software Lab Homework

More information

An Introduction to Komodo

An Introduction to Komodo An Introduction to Komodo The Komodo debugger and simulator is the low-level debugger used in the Digital Systems Laboratory. Like all debuggers, Komodo allows you to run your programs under controlled

More information

(Refer Slide Time: 00:51)

(Refer Slide Time: 00:51) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute Technology, Madras Module 10 E Lecture 24 Content Example: factorial

More information

PhotoKeeper User s Manual

PhotoKeeper User s Manual PhotoKeeper User s Manual 20071226 20080404 Table of Contents CONGRATULATIONS on your purchase of a Polaroid PhotoKeeper. Please read carefully and follow all instructions in the manual and those marked

More information

The Definitive Guide to Fractal Awesomeness with J-WildFire!

The Definitive Guide to Fractal Awesomeness with J-WildFire! Installing Java and J-WildFire - by Martin Flink Copyright 2013 Martin Flink All Rights Reserved. No part of this document may be reproduced in any form without permission in writing from the author. Contact:

More information

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be tricky) when you translate high-level code into assembler code. MIPS Programming This is your crash course in assembler programming; you will teach yourself how to program in assembler for the MIPS processor. You will learn how to use the instruction set summary to

More information

Using Devices with Microsoft HealthVault

Using Devices with Microsoft HealthVault Using Devices with Microsoft HealthVault A Microsoft HealthVault Step-by-Step Guide This guide will help you get started using Microsoft HealthVault Connection Center to send information from your health

More information

oxigen system Installation of the bootloader application 1/ 22 oxigen bootloader

oxigen system Installation of the bootloader application 1/ 22 oxigen bootloader 1/ 22 The oxigen Bootloader application is the software program which allows the user to: 1. check and update the firmware of the oxigen devices; 2. check and update the ID number of the car chip, of the

More information

EE475 Lab #3 Fall Memory Placement and Interrupts

EE475 Lab #3 Fall Memory Placement and Interrupts EE475 Lab #3 Fall 2005 Memory Placement and Interrupts In this lab you will investigate the way in which the CodeWarrior compiler and linker interact to place your compiled code and data in the memory

More information

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Debugging Nios II Systems with the SignalTap II Logic Analyzer Debugging Nios II Systems with the SignalTap II Logic Analyzer May 2007, ver. 1.0 Application Note 446 Introduction As FPGA system designs become more sophisticated and system focused, with increasing

More information

Using Virtual EEPROM and Flash API for Renesas MCUs RX600 Series

Using Virtual EEPROM and Flash API for Renesas MCUs RX600 Series Using Virtual EEPROM and Flash API for Renesas MCUs RX600 Series Description: This lab will take the user through using the Virtual EEPROM (VEE) project for RX. The user will learn to use the Virtual EEPROM

More information

Interrupts and Low Power Features

Interrupts and Low Power Features ARM University Program 1 Copyright ARM Ltd 2013 Interrupts and Low Power Features Module Syllabus Interrupts What are interrupts? Why use interrupts? Interrupts Entering an Exception Handler Exiting an

More information

Chapter Operation Pinout Operation 35

Chapter Operation Pinout Operation 35 68000 Operation 35 Chapter 6 68000 Operation 6-1. 68000 Pinout We will do no construction in this chapter; instead, we will take a detailed look at the individual pins of the 68000 and what they do. Fig.

More information

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1 EEL 4744C: Microprocessor Applications Lecture 7 Part 1 Interrupt Dr. Tao Li 1 M&M: Chapter 8 Or Reading Assignment Software and Hardware Engineering (new version): Chapter 12 Dr. Tao Li 2 Interrupt An

More information

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1 Reading Assignment EEL 4744C: Microprocessor Applications Lecture 7 M&M: Chapter 8 Or Software and Hardware Engineering (new version): Chapter 12 Part 1 Interrupt Dr. Tao Li 1 Dr. Tao Li 2 Interrupt An

More information

Installing and Configuring the Voice UPB Bridge updated 22-Jan-2018

Installing and Configuring the Voice UPB Bridge updated 22-Jan-2018 Installing and Configuring the Voice UPB Bridge updated 22-Jan-2018 Before starting these instructions, you should already have your Voice assistant installed and working. These instructions can be used

More information

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs Slide Set 2 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

FPGA4U HowTo. 1 Introduction. 2 Minimum requirements. Recommended system. Operating systems

FPGA4U HowTo. 1 Introduction. 2 Minimum requirements. Recommended system. Operating systems FPGA4U HowTo 1 Introduction This document briefly describes how to install Altera s Softwares on your own personal computer, for use with our mini project. At the end of this tutorial, we expect that you

More information

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3). CIT Intro to Computer Systems Lecture # (//) Functions As you probably know from your other programming courses, a key part of any modern programming language is the ability to create separate functions

More information

Barchard Introduction to SPSS Marks

Barchard Introduction to SPSS Marks Barchard Introduction to SPSS 22.0 3 Marks Purpose The purpose of this assignment is to introduce you to SPSS, the most commonly used statistical package in the social sciences. You will create a new data

More information

Troubleshooting Maple Worksheets: Common Problems

Troubleshooting Maple Worksheets: Common Problems Troubleshooting Maple Worksheets: Common Problems So you've seen plenty of worksheets that work just fine, but that doesn't always help you much when your worksheet isn't doing what you want it to. This

More information

Taking Control of Your . Terry Stewart Lowell Williamson AHS Computing Monday, March 20, 2006

Taking Control of Your  . Terry Stewart Lowell Williamson AHS Computing Monday, March 20, 2006 Taking Control of Your E-Mail Terry Stewart Lowell Williamson AHS Computing Monday, March 20, 2006 Overview Setting up a system that works for you Types of e-mail Creating appointments, contacts and tasks

More information

Contents. Last updated: 18 th August 2017

Contents. Last updated: 18 th August 2017 DRM Lite in Firefox DRM Lite is the new way for British Library to deliver electronic documents securely. When a document is requested via this service the document is locked so that only one user can

More information