示例#1
0
void console_put_char(uint8_t ch)
{
  if ( m_console == CONSOLE_AVAILABLE )
  {
    hal_uart_putchar(ch);
  }
}  
示例#2
0
void console_put_hexnybble(uint8_t n)
{
  if ( m_console == CONSOLE_AVAILABLE )
  {
    hal_uart_putchar((uint8_t)hex_tab[n & 0x0f]);
  }
}
示例#3
0
文件: durga.c 项目: mutex023/dhARMa
void rtc_intr_hdlr (void *data)
{
	static u8 c = 33;
	static u8 hr = 0, min = 0, sec = 0;

	/* disable RTC interrupts till you process current interrupt
	 * for this, set the interrupt mask bit for the RTC interrupt
	 * - i.e, the 11th bit in MIR2, bits0-63 are in MIR0-1 -- TRM 6.3 & 6.5.1.31
	*/
	WRITEREG32(INTC_MIR2_SET, 0x01 << 11);

	/* process the interrupt - print to uart an ascii chart 
	 * and system up time 
	*/
	++sec;
	if (sec >= 60) {
		sec = 0;
		++min;
		if (min >= 60) {
			min = 0;
			++hr;
			if (hr >= 24) {
				hr = 0;
			}
		}
	} 
	hal_uart_putstr("RTC - ");
	hal_uart_putchar(hr/10 + '0');
	hal_uart_putchar(hr%10 + '0');
	hal_uart_putchar(':');
	hal_uart_putchar(min/10 + '0');
	hal_uart_putchar(min%10 + '0');
	hal_uart_putchar(':');
	hal_uart_putchar(sec/10 + '0');
	hal_uart_putchar(sec%10 + '0');
	hal_uart_putstr(" - ");
	hal_uart_putchar(c++);
	hal_uart_putchar('\n');
	if (c > 126)
		c = 33;

	/* re-enable RTC interrupts */
	WRITEREG32(INTC_MIR2_CLEAR, 0x01 << 11);
}
示例#4
0
void console_put_chars(uint8_t const * chars, uint8_t num_chars)
{
  if ( m_console == CONSOLE_AVAILABLE )
  {
    for( ; num_chars > 0; num_chars--)
    {
      hal_uart_putchar(*chars++);
    }
  }
}
示例#5
0
void console_put_string(uint8_t const * string)
{
  if ( m_console == CONSOLE_AVAILABLE )
  {
    while(*string != 0)
    {
      hal_uart_putchar(*string++);
    }
  }
}
示例#6
0
void console_put_line(uint8_t const * string)
{
  if ( m_console == CONSOLE_AVAILABLE )
  {
    while(*string != 0)
    {
      hal_uart_putchar(*string++);
    }
    console_put_string((uint8_t *)CONSOLE_NEWLINE_OUTPUT);
  }
}
示例#7
0
void console_put_decbyte(uint8_t b) // b is in the range [0 255]
{
  uint8_t b0;
  uint8_t b1;

  if ( m_console == CONSOLE_AVAILABLE )
  {
    b0 = (b % 10); //Remainder of b when divided by 10 
    b /= 10;       // forces w into the range [0 25]
  
    b1 = (b % 10); //Remainder of b when divided by 10
    b /= 10;       // forces w into the range [0 2]
  
    if(b != 0)
    {
      hal_uart_putchar(b + '0');
      hal_uart_putchar(b1 + '0');
      hal_uart_putchar(b0 + '0');
    }
    else if (b1 != 0)
    {
      hal_uart_putchar(b1 + '0');
      hal_uart_putchar(b0 + '0');    
    }
    else
    {
      hal_uart_putchar(b0 + '0');
    }
  }
}
示例#8
0
uint8_t console_get_char(void)
{
  uint8_t ch = '\0';

  if ( m_console == CONSOLE_AVAILABLE )
  {
    ch = hal_uart_getchar();
  #ifdef CONSOLE_ENABLE_ECHO
      hal_uart_putchar(ch);
  #endif
  }
  return ch;
}  
示例#9
0
void console_get_chars(uint8_t * chars, uint8_t num_chars)
{
  if ( m_console == CONSOLE_AVAILABLE )
  {
    for( ; num_chars > 0; num_chars--)
    {
      *chars++ = hal_uart_getchar();
  #ifdef CONSOLE_ENABLE_ECHO
      hal_uart_putchar(*(chars-1));
  #endif
    }    
  }
}
示例#10
0
void console_get_string(uint8_t * string, uint8_t num_chars)
{
  if ( m_console == CONSOLE_AVAILABLE )
  {
    for( ; num_chars > 0; num_chars--)
    {
      *string++ = hal_uart_getchar();
  #ifdef CONSOLE_ENABLE_ECHO
      hal_uart_putchar(*(string-1));
  #endif
    }    
    *string = 0;   /* Add zero terminator */
  }
}
示例#11
0
void console_get_line(uint8_t * string, uint8_t max_len)
{
  uint8_t c, k, m;

  if ( m_console == CONSOLE_AVAILABLE )
  {
    c = '\0';
    for( k = 0; k < max_len - 1 ; k++ )
    {
      c = hal_uart_getchar();
      if (c == newline_input[0])
      {
        break;
      }
      string[k] = c;
  #ifdef CONSOLE_ENABLE_ECHO
      hal_uart_putchar(c);
  #endif
    }
    string[k] = 0;
    /* Read (and discard) also rest of newline sequence if we found the start of if */
    /* This is were we may discard characters we should not, se the comments in the header file. */
    /* NOTE: We really should check what we read, and notify the caller if it is not really the newline sequence. */
    if( c == newline_input[0] )
    {
      for( m = 0; m < NEWLINE_INPUT_LEN - 1; m++)   /* We have already read the first character */
      {
          c = hal_uart_getchar();
      }
  #ifdef CONSOLE_ENABLE_ECHO
      /* We have read a newline, and since echo is enabled, we should also echo back a newline. */
      /* But this should be the output newline, which may differ from the input newline we read. */
      console_put_string((uint8_t *)CONSOLE_NEWLINE_OUTPUT);    
  #endif
    }
  }
} //lint !e438 Last value assigned to 'c' not used
示例#12
0
void console_put_dec32bit(uint32_t ww)  // ww is in the range [0 4294967295]
{
  uint8_t ww0;
  uint8_t ww1;
  uint8_t ww2;
  uint8_t ww3;
  uint8_t ww4;
  uint8_t ww5;
  uint8_t ww6;
  uint8_t ww7;
  uint8_t ww8;

  if ( m_console == CONSOLE_AVAILABLE )
  {
    ww0 = (ww % 10); //Remainder of ww when divided by 10 
    ww /= 10;       // forces ww into the range [0 429496729]
  
    ww1 = (ww % 10); //Remainder of ww when divided by 10
    ww /= 10;       // forces ww into the range [0 42949672]
  
    ww2 = (ww % 10); //Remainder of ww when divided by 10
    ww /= 10;       // forces ww into the range [0 4294967]
  
    ww3 = (ww % 10); //Remainder of ww when divided by 10
    ww /= 10;       // forces ww into the range [0 429496]
  
    ww4 = (ww % 10); //Remainder of ww when divided by 10
    ww /= 10;       // forces ww into the range [0 42949]
  
    ww5 = (ww % 10); //Remainder of ww when divided by 10
    ww /= 10;       // forces ww into the range [0 4294]
  
    ww6 = (ww % 10); //Remainder of ww when divided by 10
    ww /= 10;       // forces ww into the range [0 429]
  
    ww7 = (ww % 10); //Remainder of ww when divided by 10
    ww /= 10;       // forces ww into the range [0 42]
  
    ww8 = (ww % 10); //Remainder of ww when divided by 10
    ww /= 10;       // forces ww into the range [0 4]
  
  
    if(ww != 0)
    {
      hal_uart_putchar((uint8_t)ww  + '0');   /* We may safely cast ww to the smaller type, as we have */
                                              /* made sure (above) that its value will fit. */
      hal_uart_putchar(ww8 + '0');
      hal_uart_putchar(ww7 + '0');
      hal_uart_putchar(ww6 + '0');
      hal_uart_putchar(ww5 + '0');
      hal_uart_putchar(ww4 + '0');
      hal_uart_putchar(ww3 + '0');
      hal_uart_putchar(ww2 + '0');
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');
    }
    else if (ww8 != 0)
    {
      hal_uart_putchar(ww8 + '0');
      hal_uart_putchar(ww7 + '0');
      hal_uart_putchar(ww6 + '0');
      hal_uart_putchar(ww5 + '0');
      hal_uart_putchar(ww4 + '0');
      hal_uart_putchar(ww3 + '0');
      hal_uart_putchar(ww2 + '0');
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');
    }
    else if (ww7 != 0)
    {
      hal_uart_putchar(ww7 + '0');
      hal_uart_putchar(ww6 + '0');
      hal_uart_putchar(ww5 + '0');
      hal_uart_putchar(ww4 + '0');
      hal_uart_putchar(ww3 + '0');
      hal_uart_putchar(ww2 + '0');
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');    
    }
    else if (ww6 != 0)
    {
      hal_uart_putchar(ww6 + '0');
      hal_uart_putchar(ww5 + '0');
      hal_uart_putchar(ww4 + '0');
      hal_uart_putchar(ww3 + '0');
      hal_uart_putchar(ww2 + '0');
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');    
    }
    else if (ww5 != 0)
    {
      hal_uart_putchar(ww5 + '0');
      hal_uart_putchar(ww4 + '0');
      hal_uart_putchar(ww3 + '0');
      hal_uart_putchar(ww2 + '0');
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');    
    }
    else if (ww4 != 0)
    {
      hal_uart_putchar(ww4 + '0');
      hal_uart_putchar(ww3 + '0');
      hal_uart_putchar(ww2 + '0');
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');    
    }
    else if (ww3 != 0)
    {
      hal_uart_putchar(ww3 + '0');
      hal_uart_putchar(ww2 + '0');
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');    
    }
    else if (ww2 != 0)
    {
      hal_uart_putchar(ww2 + '0');
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');    
    }
    else if (ww1 != 0)
    {
      hal_uart_putchar(ww1 + '0');
      hal_uart_putchar(ww0 + '0');    
    }
    else
    {
      hal_uart_putchar(ww0 + '0');
    }
  }
}
示例#13
0
void console_put_decword(uint16_t w)  // w is in the range [0 65535]
{
  uint8_t w0;
  uint8_t w1;
  uint8_t w2;
  uint8_t w3;

  if ( m_console == CONSOLE_AVAILABLE )
  {
    w0 = (w % 10); //Remainder of w when divided by 10 
    w /= 10;       // forces w into the range [0 6553]
  
    w1 = (w % 10); //Remainder of w when divided by 10
    w /= 10;       // forces w into the range [0 655]
  
    w2 = (w % 10); //Remainder of w when divided by 10
    w /= 10;       // forces w into the range [0 65]
  
    w3 = (w % 10); //Remainder of w when divided by 10
    w /= 10;       // forces w into the range [0 6]
  
    if(w != 0)
    {
      hal_uart_putchar((uint8_t)w  + '0');   /* We may safely cast w to the smaller type, as we have */
                                             /* made sure (above) that its value will fit. */
      hal_uart_putchar(w3 + '0');
      hal_uart_putchar(w2 + '0');
      hal_uart_putchar(w1 + '0');
      hal_uart_putchar(w0 + '0');
    }
    else if (w3 != 0)
    {
      hal_uart_putchar(w3 + '0');
      hal_uart_putchar(w2 + '0');
      hal_uart_putchar(w1 + '0');
      hal_uart_putchar(w0 + '0');
    }
    else if (w2 != 0)
    {
      hal_uart_putchar(w2 + '0');
      hal_uart_putchar(w1 + '0');
      hal_uart_putchar(w0 + '0');    
    }
    else if (w1 != 0)
    {
      hal_uart_putchar(w1 + '0');
      hal_uart_putchar(w0 + '0');    
    }
    else
    {
      hal_uart_putchar(w0 + '0');
    }
  }
}
示例#14
0
文件: main.c 项目: amurlynx/rf-nordic
/** @file
 * @brief UART example
 * @defgroup uart_example UART "Hello World" example
 * @{
 * @ingroup nrf_examples
 *
 * @brief This example writes the string "Hello World" on start-up. After this all
 * characters received on the RXD input are echoed to the TXD output.
 *
 * The example implements the low level stdio functions putchar() and getchar() so that standard
 * IO functions such as printf() and gets() can be used by the application.
 *
*/

//lint -e732
//lint -e713
//lint -e640

#include <stdio.h>
#include "nrf24le1.h"
#include "hal_uart.h"
#include "hal_clk.h"

// Cusomization of low level stdio function. Used by for example printf().
#ifdef __ICC8051__
int putchar(int c)
#else /*presume C51 or other accepting compilator*/
char putchar(char c)
#endif
{
  hal_uart_putchar(c);
  return c;
}