OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [UartSC.cpp] - Diff between revs 6 and 42

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 6 Rev 42
Line 26... Line 26...
#include <iomanip>
#include <iomanip>
#include <cmath>
#include <cmath>
 
 
#include "UartSC.h"
#include "UartSC.h"
 
 
 
//#define UART_SC_DEBUG
 
 
 
 
SC_HAS_PROCESS( UartSC );
SC_HAS_PROCESS( UartSC );
 
 
//! Constructor for the Uart system C model
//! Constructor for the Uart system C model
 
 
Line 52... Line 54...
                  int uart_baud
                  int uart_baud
                  )
                  )
{
{
  // Calculate number of clocks per UART bit
  // Calculate number of clocks per UART bit
  clocks_per_bit = (int)(clk_freq_hz/uart_baud);
  clocks_per_bit = (int)(clk_freq_hz/uart_baud);
 
  bits_received=0;
 
#ifdef UART_SC_DEBUG
 
  printf("UartSC Initialised: Sys. clk. freq.: %d Hz, Baud: %d, cpb: %d\n", clk_freq_hz, uart_baud, clocks_per_bit);
 
#endif
}
}
 
 
 
 
// Maybe do this with threads instead?!
// Maybe do this with threads instead?!
void
void
UartSC::checkTx () {
UartSC::checkTx () {
 
 
 
#ifdef UART_SC_DEBUG
  //printf("Uart TX activity: level is : 0x%x\n", uarttx.read()&1);
  //printf("Uart TX activity: level is : 0x%x\n", uarttx.read()&1);
 
#endif
 
 
  // Check the number of bits received
  // Check the number of bits received
  if (bits_received==0)
  if (bits_received==0)
    {
    {
      // Check if tx is low
      // Check if tx is low
Line 72... Line 80...
          // Line pulled low, begin receive of new char
          // Line pulled low, begin receive of new char
          current_char = 0;
          current_char = 0;
          // Start 
          // Start 
          counter = 1;
          counter = 1;
          bits_received++; // We got the start bit
          bits_received++; // We got the start bit
          //cout << "UartSC checkTx: got start bit at time " << sc_time_stamp() << endl;
#ifdef UART_SC_DEBUG
 
          cout << "UartSC checkTx: got start bit at time " << sc_time_stamp() << endl;
 
#endif
        }
        }
    }
    }
  else if (bits_received > 0 && bits_received < 9)
  else if (bits_received > 0 && bits_received < 9)
    {
    {
      // Check the counter - see if it's time to sample the line
      // Check the counter - see if it's time to sample the line
Line 114... Line 124...
              counter = 0;
              counter = 0;
            }
            }
          else
          else
            {
            {
              // Print the char
              // Print the char
              //printf("Char received: 0x%2x time: ", current_char);
#ifdef UART_SC_DEBUG
              //cout << sc_time_stamp() << endl;
              printf("Char received: 0x%2x time: ", current_char);
              cout << current_char;
              cout << sc_time_stamp() << endl;
 
#endif
 
              // cout'ing the char didn't work for some systems - jb 090613ol
 
              //cout << current_char;
 
              printf("%c",current_char);
 
 
              bits_received = 0;
              bits_received = 0;
              counter = 0;
              counter = 0;
            }
            }
        }
        }
      else
      else

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.