Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. #include "address_map_nios2.h"
  2. #include <stdio.h>
  3.  
  4. /* function prototypes */
  5. void put_jtag(volatile int *, char);
  6. int change(volatile int *, char);
  7.  
  8. /********************************************************************************
  9.  * This program demonstrates use of the JTAG UART port
  10.  *
  11.  * It performs the following:
  12.  *      1. sends a text string to the JTAG UART
  13.  *  2. reads character data from the JTAG UART
  14.  *  3. echos the character data back to the JTAG UART
  15. ********************************************************************************/
  16. int main(void)
  17. {
  18.     /* Declare volatile pointers to I/O registers (volatile means that IO load
  19.        and store instructions will be used to access these pointer locations,
  20.        instead of regular memory loads and stores) */
  21.     volatile int * JTAG_UART_ptr    = (int *) JTAG_UART_BASE;   // JTAG UART address
  22.    
  23.     int data, i;
  24.     char text_string[] = "\nJTAG UART example code\n> \0";
  25.  
  26.     /* print a text string */
  27.     for (i = 0; text_string[i] != 0; ++i)
  28.         //put_jtag (JTAG_UART_ptr, text_string[i]);
  29.  
  30.     /* read and echo characters */
  31.     while(1)
  32.     {
  33.         data = *(JTAG_UART_ptr);                // read the JTAG_UART data register
  34.         if (data & 0x00008000)                  // check RVALID to see if there is new data
  35.         {
  36.             data = data & 0x000000FF;           // the data is in the least significant byte
  37.             change (JTAG_UART_ptr, (char) data & 0xFF);
  38.             /* echo the character */
  39.             put_jtag (JTAG_UART_ptr, (char) data & 0xFF );
  40.         }
  41.     }
  42. }
  43.  
  44. /********************************************************************************
  45.  * Subroutine to send a character to the JTAG UART
  46. ********************************************************************************/
  47. int change(volatile int  * JTAG_UART_ptr, char c)
  48. {
  49.     int control;
  50.     int counter = 0;
  51.     control = *(JTAG_UART_ptr + 1);         // read the JTAG_UART control register
  52.     if (control & 0xFFFF0000)                   // if space, then echo character, else ignore
  53.          
  54.     if (c == 0x30 /*&& control <= 0x39*/)
  55.     {
  56.         c = c & 0x09;
  57.         //c =
  58.         *(JTAG_UART_ptr) = c;
  59.     }
  60.    
  61.     else {
  62.     put_jtag( volatile int * JTAG_UART_ptr, char c );
  63.     {
  64.         int control;
  65.         control = *(JTAG_UART_ptr + 1);         // read the JTAG_UART control register
  66.         if (control & 0xFFFF0000)                   // if space, then echo character, else ignore
  67.             *(JTAG_UART_ptr) = c;
  68.     }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement