Bryan and Naved Debub monitor

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Monitor.cpp Source File

Monitor.cpp

Go to the documentation of this file.
00001 /**----------------------------------------------------------------------------
00002              \file Monitor.cpp
00003 --                                                                           --
00004 --              ECEN 5003 Mastering Embedded System Architecture             --
00005 --                  Project 1 Module 3                                       --
00006 --                Microcontroller Firmware                                   --
00007 --                      Monitor.cpp                                            --
00008 --                                                                           --
00009 -------------------------------------------------------------------------------
00010 --
00011 --  Designed for:  University of Colorado at Boulder
00012 --               
00013 --                
00014 --  Designed by:  Tim Scherr
00015 --  Revised by:  Student's name 
00016 -- 
00017 -- Version: 2.0
00018 -- Date of current revision:  2016-09-29   
00019 -- Target Microcontroller: Freescale MKL25ZVMT4 
00020 -- Tools used:  ARM mbed compiler
00021 --              ARM mbed SDK
00022 --              Freescale FRDM-KL25Z Freedom Board
00023 --               
00024 -- 
00025    Functional Description: See below 
00026 --
00027 --      Copyright (c) 2015 Tim Scherr All rights reserved.
00028 --
00029 */              
00030 
00031 #include <stdio.h>
00032 #include "shared.h"
00033 
00034 /*******************************************************************************
00035 * Set Display Mode Function
00036 * Function determines the correct display mode.  The 3 display modes operate as 
00037 *   follows:
00038 *
00039 *  NORMAL MODE       Outputs only mode and state information changes   
00040 *                     and calculated outputs
00041 *
00042 *  QUIET MODE        No Outputs
00043 *
00044 *  DEBUG MODE        Outputs mode and state information, error counts,
00045 *                    register displays, sensor states, and calculated output
00046 *
00047 *
00048 * There is deliberate delay in switching between modes to allow the RS-232 cable 
00049 * to be plugged into the header without causing problems. 
00050 *******************************************************************************/
00051 
00052 
00053 
00054 __asm uint32_t getregister(uint32_t x){
00055    
00056     CMP r0,#0;
00057     BEQ return_from_function_r0
00058     CMP r0,#1;
00059     BEQ return_from_function_r1
00060     CMP r0,#2;
00061     BEQ return_from_function_r2 
00062     CMP r0,#3;
00063     BEQ return_from_function_r3 
00064     CMP r0,#4;
00065     BEQ return_from_function_r4
00066     CMP r0,#5;
00067     BEQ return_from_function_r5
00068     CMP r0,#6;
00069     BEQ return_from_function_r6
00070     CMP r0,#7;
00071     BEQ return_from_function_r7
00072     CMP r0,#8;
00073     BEQ return_from_function_r8
00074     CMP r0,#9;
00075     BEQ return_from_function_r9 
00076     CMP r0,#10;
00077     BEQ return_from_function_r10
00078     CMP r0,#11;
00079     BEQ return_from_function_r11
00080     CMP r0,#12;
00081     BEQ return_from_function_r12
00082     CMP r0,#13;
00083     BEQ return_from_function_r13
00084     CMP r0,#14;
00085     BEQ return_from_function_r14
00086    // CMP r0,#15;
00087    // BEQ return_from_function_r15
00088     
00089 return_from_function_r0
00090     MOV r0,r0 ; store the return value in r0
00091     BLX  lr            ; Else return from subroutine with link and returning the value of register
00092 return_from_function_r1
00093     MOV r0,r1 ; store the return value in r0
00094     BLX  lr            ; Else return from subroutine with link and returning the value of register
00095 return_from_function_r2
00096     MOV r0,r2 ; store the return value in r0
00097     BLX  lr            ; Else return from subroutine with link and returning the value of register
00098 return_from_function_r3
00099     MOV r0,r3 ; store the return value in r0
00100     BLX  lr            ; Else return from subroutine with link and returning the value of register
00101 return_from_function_r4
00102     MOV r0,r4 ; store the return value in r0
00103     BLX  lr            ; Else return from subroutine with link and returning the value of register
00104 return_from_function_r5
00105     MOV r0,r5 ; store the return value in r0
00106     BLX  lr            ; Else return from subroutine with link and returning the value of register
00107 return_from_function_r6
00108     MOV r0,r6 ; store the return value in r0
00109     BLX  lr            ; Else return from subroutine with link and returning the value of register
00110 return_from_function_r7
00111     MOV r0,r7 ; store the return value in r0
00112     BLX  lr            ; Else return from subroutine with link and returning the value of register
00113 return_from_function_r8
00114     MOV r0,r8 ; store the return value in r0
00115     BLX  lr            ; Else return from subroutine with link and returning the value of register
00116 return_from_function_r9
00117     MOV r0,r9 ; store the return value in r0
00118     BLX  lr            ; Else return from subroutine with link and returning the value of register
00119 return_from_function_r10
00120     MOV r0,r10 ; store the return value in r0
00121     BLX  lr            ; Else return from subroutine with link and returning the value of register
00122 return_from_function_r11
00123     MOV r0,r11 ; store the return value in r0
00124     BLX  lr            ; Else return from subroutine with link and returning the value of register
00125 return_from_function_r12
00126     MOV r0,r12 ; store the return value in r0
00127     BLX  lr            ; Else return from subroutine with link and returning the value of register
00128 return_from_function_r13
00129     MOV r0,r13 ; store the return value in r0
00130     BLX  lr            ; Else return from subroutine with link and returning the value of register
00131 return_from_function_r14
00132     MOV r0,r14 ; store the return value in r0
00133     BLX  lr            ; Else return from subroutine with link and returning the value of register
00134 //return_from_function_r15
00135     
00136     //  MOV r0,15 ; store the return value in r0
00137    // BLX  lr            ; Else return from subroutine with link and returning the value of register
00138 }
00139 
00140 __asm uint32_t getregister0(void){
00141       MOV r0,r0 ; store the return value in r0
00142     BLX  lr            ; Else return from subroutine with link and returning the value of register
00143     
00144 }
00145 void set_display_mode(void)   
00146 {
00147   UART_direct_msg_put("\r\nSelect Mode");
00148   UART_direct_msg_put("\r\n Hit NOR - Normal");
00149   UART_direct_msg_put("\r\n Hit QUI - Quiet");
00150   UART_direct_msg_put("\r\n Hit DEB - Debug" );
00151   UART_direct_msg_put("\r\n Hit V - Version#\r\n");
00152   UART_direct_msg_put("\r\nSelect:  ");
00153   
00154 }
00155 //*****************************************************************************/
00156 /// \fn void chk_UART_msg(void) 
00157 ///
00158 //*****************************************************************************/
00159 void chk_UART_msg(void)    
00160 {
00161    UCHAR j;
00162    while( UART_input() )      // becomes true only when a byte has been received
00163    { //j = *rx_out_ptr++; 
00164          //*tx_out_ptr++ = j;
00165          //UART0->D  = *tx_out_ptr++;     /* send next char */
00166          // skip if no characters pending
00167       j = UART_get();                 // get next character
00168       //UART0->D = *tx_out_ptr++;     /* send next char */            // echo the character   
00169 
00170       if( j == '\r' )          // on a enter (return) key press
00171       {                // complete message (all messages end in carriage return)
00172          UART_msg_put("->");
00173          UART_msg_process();
00174       }
00175       else 
00176       {
00177          if ((j != 0x02) )         // if not ^B
00178          {                             // if not command, then   
00179             UART_put(j);              // echo the character, modified code for UART_put   
00180          }
00181          else
00182          {
00183           ;            
00184          }
00185          if( j == '\b' ) 
00186          {                             // backspace editor
00187             if( msg_buf_idx != 0) 
00188             {                       // if not 1st character then destructive 
00189                UART_msg_put(" \b");// backspace
00190                msg_buf_idx--;
00191             }
00192          }
00193          else if( msg_buf_idx >= MSG_BUF_SIZE )  
00194          {                                // check message length too large
00195             UART_msg_put("\r\nToo Long!");
00196             msg_buf_idx = 0;
00197          }
00198          else if ((display_mode == QUIET) && (msg_buf[0] != 0x02) && 
00199                   (msg_buf[0] != 'D') && (msg_buf[0] != 'N') && 
00200                   (msg_buf[0] != 'V') &&
00201                   (msg_buf_idx != 0))
00202          {                          // if first character is bad in Quiet mode
00203             msg_buf_idx = 0;        // then start over
00204          }
00205          else {                        // not complete message, store character
00206               
00207             msg_buf[msg_buf_idx] = j;
00208             msg_buf_idx++;
00209             if (msg_buf_idx > 2)
00210             {
00211                UART_msg_process();
00212             }
00213          }
00214       }
00215    }
00216 }
00217 
00218 //*****************************************************************************/
00219 ///  \fn void UART_msg_process(void) 
00220 ///UART Input Message Processing
00221 //*****************************************************************************/
00222 void UART_msg_process(void)
00223 {
00224    UCHAR chr,err=0;
00225 //   unsigned char  data;
00226 
00227 
00228    if( (chr = msg_buf[0]) <= 0x60 ) 
00229    {      // Upper Case
00230       switch( chr ) 
00231       {
00232          case 'D':
00233             if((msg_buf[1] == 'E') && (msg_buf[2] == 'B') && (msg_buf_idx == 3)) 
00234             {
00235                display_mode = DEBUG;
00236                UART_direct_msg_put("\r\nMode=DEBUG");
00237                UART_direct_msg_put("\n");
00238                             display_timer = 0;
00239             }
00240             else
00241                err = 1;
00242             break;
00243 
00244          case 'N':
00245             if((msg_buf[1] == 'O') && (msg_buf[2] == 'R') && (msg_buf_idx == 3)) 
00246             {
00247                display_mode = NORMAL;
00248                UART_msg_put("\r\nMode=NORMAL\n");
00249                //display_timer = 0;
00250             }
00251             else
00252                err = 1;
00253             break;
00254 
00255          case 'Q':
00256             if((msg_buf[1] == 'U') && (msg_buf[2] == 'I') && (msg_buf_idx == 3)) 
00257             {
00258                display_mode = QUIET;
00259                UART_msg_put("\r\nMode=QUIET\n");
00260                display_timer = 0;
00261             }
00262             else
00263                err = 1;
00264             break;
00265 
00266          case 'V':
00267             display_mode = VERSION;
00268             UART_msg_put("\r\n");
00269             UART_msg_put( CODE_VERSION ); 
00270             UART_msg_put("\r\nSelect  ");
00271             display_timer = 0;
00272             break;
00273                 
00274          default:
00275             err = 1;
00276       }
00277    }
00278 
00279    else 
00280    {                                 // Lower Case
00281       switch( chr ) 
00282       {
00283         default:
00284          err = 1;
00285       }
00286    }
00287 
00288    if( err == 1 )
00289    {
00290       UART_msg_put("\n\rError!");
00291    }   
00292    else if( err == 2 )
00293    {
00294       UART_msg_put("\n\rNot in DEBUG Mode!");
00295    }   
00296    else
00297    {
00298     msg_buf_idx = 0;          // put index to start of buffer for next message
00299       ;
00300    }
00301     msg_buf_idx = 0;          // put index to start of buffer for next message
00302 
00303 
00304 }
00305 
00306 
00307 //*****************************************************************************
00308 ///   \fn   is_hex
00309 /// Function takes 
00310 ///  @param a single ASCII character and returns 
00311 ///  @return 1 if hex digit, 0 otherwise.
00312 ///    
00313 //*****************************************************************************
00314 UCHAR is_hex(UCHAR c)
00315 {
00316    if( (((c |= 0x20) >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f'))  )
00317       return 1;
00318    return 0;
00319 }
00320 
00321 /*******************************************************************************
00322 *   \fn  DEBUG and DIAGNOSTIC Mode UART Operation
00323 *******************************************************************************/
00324 
00325 void monitor(void)
00326 {
00327 /**********************************/
00328 /*     Spew outputs               */
00329 /**********************************/
00330 
00331    switch(display_mode)
00332    {
00333       case(QUIET):
00334          {
00335              UART_msg_put("\r\n ");
00336              display_flag = 0;
00337          }  
00338          break;
00339       case(VERSION):
00340          {
00341              display_flag = 0;
00342          }  
00343          break;         
00344       case(NORMAL):
00345          {
00346             if (display_flag == 1)
00347             {                       // resets and sets continous receive enable bit
00348                UART_msg_put("\r\nNORMAL ");
00349                UART_direct_msg_put(" Flow: ");
00350                // ECEN 5803 add code as indicated               
00351                 UART_direct_hex_put(flow);
00352                UART_direct_msg_put(" Temp: ");
00353                // ECEN 5803 add code as indicated                           
00354                UART_direct_hex_put(temperature);
00355                UART_direct_msg_put(" Freq: ");
00356                // ECEN 5803 add code as indicated                           
00357                 UART_direct_hex_put(freq_value);
00358                display_flag = 0;
00359             }
00360          }  
00361          break;
00362       case(DEBUG):
00363          {
00364             if (display_flag == 1)
00365             {
00366                UART_direct_msg_put("\r\nDEBUG ");
00367                UART_direct_msg_put(" Flow: ");
00368                // ECEN 5803 add code as indicated               
00369                 UART_direct_hex_put(flow);
00370                UART_direct_msg_put(" Temp: ");
00371                // ECEN 5803 add code as indicated                           
00372               UART_direct_hex_put(temperature);
00373                UART_direct_msg_put(" Freq: ");
00374                // ECEN 5803 add code as indicated                           
00375                 UART_direct_hex_put(freq_value);
00376                
00377                
00378  /****************      ECEN 5803 add code as indicated   ***************/             
00379                //  Create a display of  error counts, sensor states, and
00380                //  ARM Registers R0-R15 - Completed displaying register, not error counts or sensor states
00381                             /**********************************/
00382               /*     Define varables to store registers*/
00383               /**********************************/
00384                             //Assembly language call to function to get ARM registers (R0-R15)
00385 
00386              uint32_t register0 = getregister0();
00387                          uint32_t register1 = getregister(1);
00388                          uint32_t register2 = getregister(2);
00389                          uint32_t register3 = getregister(3);
00390                          uint32_t register4 = getregister(4);
00391                          uint32_t register5 = getregister(5);
00392                          uint32_t register6 = getregister(6);
00393                          uint32_t register7 = getregister(7);
00394                          uint32_t register8 = getregister(8);
00395                          uint32_t register9 = getregister(9);
00396                          uint32_t register10 = getregister(10);
00397                          uint32_t register11 = getregister(11);
00398                          uint32_t register12 = getregister(12);
00399                          uint32_t register13 = getregister(13);
00400                          uint32_t register14 = getregister(14);
00401                          //uint32_t register15 = getregister(15); // Write code to get register 15
00402                          // Display registers
00403                          UART_direct_msg_put("\r\nARM REGISTERS[R0-R15]:");
00404                          UART_direct_msg_put("\r\nREGISTER0:");
00405                          UART_direct_hex_put_word(register0); 
00406                          UART_direct_msg_put("\r\nREGISTER1:");
00407                        UART_direct_hex_put_word(register1);             
00408                          UART_direct_msg_put("\r\nREGISTER2:");
00409                        UART_direct_hex_put_word(register2);                          
00410                          UART_direct_msg_put("\r\nREGISTER3:");
00411                        UART_direct_hex_put_word(register3);                                 
00412                          UART_direct_msg_put("\r\nREGISTER4:");
00413                        UART_direct_hex_put_word(register4);
00414                          UART_direct_msg_put("\r\nREGISTER5:");
00415                        UART_direct_hex_put_word(register5);                         
00416                          UART_direct_msg_put("\r\nREGISTER6:");
00417                        UART_direct_hex_put_word(register6);                              
00418                          UART_direct_msg_put("\r\nREGISTER7:");
00419                        UART_direct_hex_put_word(register7);                                 
00420                          UART_direct_msg_put("\r\nREGISTER8:");
00421                        UART_direct_hex_put_word(register8);
00422                          UART_direct_msg_put("\r\nREGISTER9:");
00423                        UART_direct_hex_put_word(register9);                 
00424                          UART_direct_msg_put("\r\nREGISTER10:");
00425                        UART_direct_hex_put_word(register10);                    
00426                          UART_direct_msg_put("\r\nREGISTER11:");
00427                        UART_direct_hex_put_word(register11);    
00428                          UART_direct_msg_put("\r\nREGISTER12:");
00429                        UART_direct_hex_put_word(register12);    
00430                          UART_direct_msg_put("\r\nREGISTER13:");
00431                        UART_direct_hex_put_word(register13);
00432                          UART_direct_msg_put("\r\nREGISTER14:");
00433                        UART_direct_hex_put_word(register14);    
00434                          //UART_direct_msg_put("\r\nREGISTER15:");
00435                        //UART_hex_put(register15);                           
00436 
00437                             
00438               //  Create a command to read a section of Memory and display it
00439                
00440                                 //int32_t *memory_ptr; /* pointer store the address in memory to display */
00441                              
00442                             
00443                //  Create a command to read 16 words from the current stack 
00444                // and display it in reverse chronological order.
00445               
00446               
00447                // clear flag to ISR      
00448                display_flag = 0;
00449              }   
00450          }  
00451          break;
00452 
00453       default:
00454       {
00455          UART_msg_put("Mode Error");
00456       }  
00457    }
00458 }  
00459