Пример #1
0
static int subcommand_gpio_dir(int argc, const char **argv) {
	/* > gpio dir $pin $dir(0:input, 1:output) */
	uint8_t pin;
	bool dir;

	if (argc < 3) {
		return -1;
	}

	pin = (uint8_t)atoi(argv[1]);
	if (pin >= MAX_PIN_NUMBER) {
		return -1;
	}
	dir = !!atoi(argv[2]);
	gpio_set_dir(pin, dir);

	uart_put_line("gpio dir set: pin=");
	uart_put_char(ascii_num_to_char(pin/10));
	uart_put_char(ascii_num_to_char(pin%10));
	uart_put_line(" dir=");
	uart_put_char(ascii_num_to_char(gpio_get_dir(pin)));
	uart_put_char('\n');

	return 0;
}
Пример #2
0
static int subcommand_gpio_write(int argc, const char **argv) {
	/* > gpio write $pin $value(0 or 1) */
	uint8_t pin;
	bool value;

	if (argc < 3) {
		return -1;
	}

	pin = (uint8_t)atoi(argv[1]);
	if (pin >= MAX_PIN_NUMBER) {
		return -1;
	}
	value = !!atoi(argv[2]);
	gpio_write(pin, value);

	uart_put_line("gpio write: pin=");
	uart_put_char(ascii_num_to_char(pin/10));
	uart_put_char(ascii_num_to_char(pin%10));
	uart_put_line(" value=");
	uart_put_char(ascii_num_to_char(gpio_read(pin)));
	uart_put_char('\n');

	return 0;
}
Пример #3
0
static int subcommand_gpio_mode(int argc, const char **argv) {
	/* > gpio mode $pin $mode(0:hi-z 1:pulldown, 2:pullup, 3:repeater) */
	uint8_t pin;
	CHIP_PIN_MODE_T mode;

	if (argc < 3) {
		return -1;
	}

	pin = (uint8_t)atoi(argv[1]);
	if (pin >= MAX_PIN_NUMBER) {
		return -1;
	}
	mode = (CHIP_PIN_MODE_T)atoi(argv[2]);
	if (mode > PIN_MODE_REPEATER) {
		return -1;
	}
	gpio_set_mode(pin, mode);

	uart_put_line("gpio mode set: pin=");
	uart_put_char(ascii_num_to_char(pin/10));
	uart_put_char(ascii_num_to_char(pin%10));
	uart_put_line(" mode=");
	uart_put_char(ascii_num_to_char(mode));
	uart_put_char('\n');

	return 0;
}
Пример #4
0
// This function is called to process the received packet
uint8_t cc2500_rx_callback( uint8_t* buffer, uint8_t length )
{

  // The RSSI byte is AFTER the message, which is why I'm
  // going one byte more than the actual 'length'
  uart_put_char(buffer[length]);
  uart_put_char('\r');
  uart_put_char('\n');

  // Currently not used
  return 0;
}
Пример #5
0
static int subcommand_gpio_list(int argc, const char **argv) {
	/* > gpio list */
	uint8_t i;
	for (i=0; i<MAX_PIN_NUMBER; i++) {
		uart_put_char(ascii_num_to_char(i/10));
		uart_put_char(ascii_num_to_char(i%10));
		uart_put_line(": dir=");
		uart_put_line(gpio_get_dir(i) ? "out" : "in ");
		uart_put_line(" value=");
		uart_put_char(ascii_num_to_char(gpio_read(i)));
		uart_put_char('\n');
	}

	return 0;
}
Пример #6
0
int run(void) {
    uart_put("hello from ");
    uart_put(get_instance_name());
    uart_put_char('\n');
    h_handoff();
    return 0;
}
Пример #7
0
int uart_put_string(int n_uart, unsigned char *s)
{
    if (n_uart >1 ) return -1;	// only uart0 is supported for now
	while (*s !=0) { // loop through each char in the string
		uart_put_char(n_uart, *s++);  // print the char, then ptr increments
	}
	return 0;
}
Пример #8
0
/**
 * @brief write a string to UART
 */
int uart_put_string(int n_uart, unsigned char *s)
{
  if (n_uart >1 ) return -1;    /* only uart0, 1 are supported for now      */
  while (*s !=0) {              /* loop through each char in the string */
    uart_put_char(n_uart, *s++);/* print the char, then ptr increments  */
  }
  return 0;
}
Пример #9
0
void uart_put_int(int val) {
	int i;
	int temp;
	int original;
	if (val < 0) {
		val = -val;
		uart_put_char(0, '-');
	}
	original = val;
	for (i = 1000000000; i > 0; i /= 10) {
		if (i < original) {
			temp = val / i;
			uart_put_char(0, temp + '0');
		}
		val %= i;
	}
}
Пример #10
0
void uart_put_hex(int val) {

	int i;
	 for (i = 7; i >= 0; --i) {
		 char c = (0xF & (val >> (i * 4)));
		 uart_put_char(0, c + (c < 10 ? '0' : ('A' - 10)));
	}
		uart_put_string("\n\r");
	}
Пример #11
0
/*******************************************************************************
 * @fn     uart_write( uint8_t character )
 * @brief  transmit whole buffer
 * ****************************************************************************/
void uart_write( uint8_t* buffer, uint16_t length )
{
  uint16_t buffer_index;
  
  for( buffer_index = 0; buffer_index < length; buffer_index++ )
  {
    uart_put_char( buffer[buffer_index] );
  }
}
Пример #12
0
int uart_put_string(unsigned char *s)
{
  while (*s !=0) {              /* loop through each char in the string */
		while ( !(g_UART0_TX_empty & 0x01) );	
    uart_put_char(0, *s++);/* print the char, then ptr increments  */
		g_UART0_TX_empty = 0;  // not empty in the THR until it shifts out
  }
  return 0;
}
Пример #13
0
static void usage(const subcmd_t *subcmd, int num) {
	int i;
	uart_put_line("gpio sub-command is following\n");
	for (i=0; i<num; i++) {
		uart_put_line(subcmd[i].name);
		uart_put_line(": ");
		uart_put_line(subcmd[i].description);
		uart_put_char('\n');
	}
}
Пример #14
0
/*******************************************************************************
 * @fn     uart_write_escaped( uint8_t character )
 * @brief  transmit whole buffer while escaping characters
 * ****************************************************************************/
void uart_write_escaped( uint8_t* buffer, uint16_t length )
{
  uint16_t buffer_index;
    
  uart_put_char( 0x7e );
  for( buffer_index = 0; buffer_index < length; buffer_index++ )
  {
    if( (buffer[buffer_index] == 0x7e) | (buffer[buffer_index] == 0x7d) )
    {
      uart_put_char( 0x7d ); // Escape byte
      uart_put_char( buffer[buffer_index] ^ 0x20 );
    }
    else
    {
      uart_put_char( buffer[buffer_index] );
    }
  }
  uart_put_char( 0x7e );
}
Пример #15
0
static int subcommand_gpio_read(int argc, const char **argv) {
	/* > gpio read $pin */
	uint8_t pin;

	if (argc < 2) {
		return -1;
	}

	pin = (uint8_t)atoi(argv[1]);
	if (pin >= MAX_PIN_NUMBER) {
		return -1;
	}
	uart_put_line("gpio read: pin=");
	uart_put_char(ascii_num_to_char(pin/10));
	uart_put_char(ascii_num_to_char(pin%10));
	uart_put_line(" value=");
	uart_put_char(ascii_num_to_char(gpio_read(pin)));
	uart_put_char('\n');

	return 0;
}
Пример #16
0
static int uart_put_char(char c, FILE* stream) {
	uint8_t interrupts_enabled;
	
	/* Add the character to the buffer for transmission (if there 
	 * is space to do so). If not we wait until the buffer has space.
	 * If the character is \n, we output \r (carriage return)
	 * also.
	*/
	if(c == '\n') {
		uart_put_char('\r', stream);
	}
	
	/* If the buffer is full and interrupts are disabled then we
	 * abort - we don't output the character since the buffer will
	 * never be emptied if interrupts are disabled. If the buffer is full
	 * and interrupts are enabled then we loop until the buffer has 
	 * enough space. The bytes_in_buffer variable will get modified by the
	 * ISR which extracts bytes from the buffer.
	*/
	interrupts_enabled = bit_is_set(SREG, SREG_I);
	while(bytes_in_out_buffer >= OUTPUT_BUFFER_SIZE) {
		if(!interrupts_enabled) {
			return 1;
		}		
		/* else do nothing */
	}
	
	/* Add the character to the buffer for transmission if there
	 * is space to do so. We advance the insert_pos to the next
	 * character position. If this is beyond the end of the buffer
	 * we wrap around back to the beginning of the buffer 
	 * NOTE: we disable interrupts before modifying the buffer. This
	 * prevents the ISR from modifying the buffer at the same time.
	 * We reenable them if they were enabled when we entered the
	 * function.
	*/	
	cli();
	out_buffer[out_insert_pos++] = c;
	bytes_in_out_buffer++;
	if(out_insert_pos == OUTPUT_BUFFER_SIZE) {
		/* Wrap around buffer pointer if necessary */
		out_insert_pos = 0;
	}
	/* Reenable interrupts (UDR Empty interrupt may have been
	 * disabled) */
	UCSR0B |= (1 << UDRIE0);
	if(interrupts_enabled) {
		sei();
	}
	return 0;
}
Пример #17
0
static int uart_put_char(char c, FILE* stream) {
	unsigned char interrupts_enabled;
	
	/* Add the character to the buffer for transmission (if there 
	** is space to do so). If not we wait until the buffer has space.
	** If the character is \n, we output \r (carriage return)
	** also.
	*/
	if(c == '\n') {
		uart_put_char('\r', stream);
	}
	
	/* 
	** Loop until the buffer has enough space. The bytes_in_buffer
	** variable will get modified by the ISR which extracts bytes
	** from the buffer.
	*/
	while(bytes_in_out_buffer >= OUTPUT_BUFFER_SIZE) {
		/* do nothing */
	}
	
	/* Add the character to the buffer for transmission if there
	** is space to do so. We advance the insert_pos to the next
	** character position. If this is beyond the end of the buffer
	** we wrap around back to the beginning of the buffer 
	** NOTE: we disable interrupts before modifying the buffer. This
	** prevents the ISR from modifying the buffer at the same time.
	** We reenable them if they were enabled when we entered the
	** function.
	*/
	
	interrupts_enabled = bit_is_set(SREG, SREG_I);
	cli();
	out_buffer[out_insert_pos++] = c;
	bytes_in_out_buffer++;
	if(out_insert_pos == OUTPUT_BUFFER_SIZE) {
		/* Wrap around buffer pointer if necessary */
		out_insert_pos = 0;
	}
	/* Reenable interrupts (UDR Empty interrupt may have been
	** disabled */
	UCR |= (1 << UDRIE);
	if(interrupts_enabled) {
		sei();
	}
	return 0;
}
Пример #18
0
/*******************************************************************************
* Function Name  : uart_write
* Description    : Write data bytes to the USARTx TxBuffer.
* Input          : - RdPtr: Location where the first byte is to be read
*                : - Size: Number of bytes to be written
*                : - Uart: Select the USART or the UART peripheral.
* Output         : None
* Return         : -1 if ERROR, Number of char not written (0 if OK)
*******************************************************************************/
int uart_write(const void *RdPtr, u16 Size, const _Uart_Descriptor *Uart)
{
  u16 i;
  char *ptr = (char *)RdPtr;
  if(Size>(*Uart->Ctrl)->TxBufSize)
     Size=(*Uart->Ctrl)->TxBufSize;

  //
  USART_ITConfig(Uart->UARTx, USART_IT_TXE, DISABLE);
  //
  for (i = 0 ; i < Size ; i++){ 
    if (uart_put_char(*ptr++, Uart) == -1) 
      break;
  }
  //
  if ((*Uart->Ctrl)->HwCtrl & UART_HALF_DUPLEX) 
    uart_tx_enable(Uart);
  //
  USART_ITConfig(Uart->UARTx, USART_IT_TXE, ENABLE);
  //
  return((int)(i));
}
Пример #19
0
int sys_write(int fd, const void *buf, size_t count)
{
	if (fd == 1)
		return uart_put_char(buf, count);
}
Пример #20
0
/**
  * @brief  shell 输出一个字节
  * @param  ch 字节数据
  * @retval None
  */
static void shell_put_char(INT8U ch)
{
	uart_put_char(ch);
}
Пример #21
0
//*********************************************************************//
void uart_put_string(char *s){
  while(*s) uart_put_char(*s++);
}
Пример #22
0
void h_handoff(void) {
    uart_put("hello from ");
    uart_put(get_instance_name());
    uart_put_char('\n');
}
Пример #23
0
int uart_put_char_stream(char c, FILE* stream) {
    uart_put_char(c);
    return 0;
}
Пример #24
0
static int command_version(int argc, const char** argv) {
    uart_put_line(FIRMWARE_VERESION);
    uart_put_char('\n');
    return 0;
}