示例#1
0
}

void uart_putchar(char c, FILE *stream) {
    if (c == '\n') {
        uart_putchar('\r', stream);
    }
    loop_until_bit_is_set(UCSR0A, UDRE0);
    UDR0 = c;
}

char uart_getchar(FILE *stream) {
    loop_until_bit_is_set(UCSR0A, RXC0);
    return UDR0;
}

FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);

int main(void) {

    uart_init();
    stdout = &uart_output;

    while(1) {
      int i = 0;
      for (i = 0; i < 100; i++) {
        printf("%d\n", i);
      }
    }

    return 0;
}
示例#2
0

#ifdef AVR_DEFAULT_TIMER_SOURCE

/* Hint: 1,000,000 µs/s * 256 T/C0 clock cycles per tick * 64 CPU clocks per
 * T/C0 clock cycle / x,000,000 CPU clock cycles per second -> µs per tick
 */
#define PLAT_TIME_PER_TICK_USEC (1000000ULL*256ULL*64ULL/F_CPU)

#endif /* AVR_DEFAULT_TIMER_SOURCE */


/* Configure stdin, stdout, stderr */
static int uart_putc(char c, FILE *stream);
static int uart_getc(FILE *stream);
FILE avr_uart = FDEV_SETUP_STREAM(uart_putc, uart_getc, _FDEV_SETUP_RW);


/*
 * AVR target shall use stdio for I/O routines.
 * The UART or USART must be configured for the interactive interface to work.
 */
PmReturn_t
plat_init(void)
{
    CPU_PRESCALE(0);
    usb_init();
    while(!usb_configured()) _delay_ms(1);

    stdin = stdout = stderr = &avr_uart;
 */


/* Local data */

/* Application threads' TCBs */
static ATOM_TCB main_tcb;

/* Main thread's stack area */
static uint8_t main_thread_stack[MAIN_STACK_SIZE_BYTES];

/* Idle thread's stack area */
static uint8_t idle_thread_stack[IDLE_STACK_SIZE_BYTES];

/* STDIO stream */
static FILE uart_stdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);


/* Forward declarations */
static void main_thread_func (uint32_t data);


/**
 * \b main
 *
 * Program entry point.
 *
 * Sets up the AVR hardware resources (system tick timer interrupt) necessary
 * for the OS to be started. Creates an application thread and starts the OS.
 */
示例#4
0
文件: CDC.c 项目: 12019/mooltipass
void CDC_Device_CreateBlockingStream(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
                                     FILE* const Stream)
{
	*Stream = (FILE)FDEV_SETUP_STREAM(CDC_Device_putchar, CDC_Device_getchar_Blocking, _FDEV_SETUP_RW);
	fdev_set_udata(Stream, CDCInterfaceInfo);
}
示例#5
0
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <avr/io.h>
#include <avr/power.h>
#include <avr/pgmspace.h>

#include "avrdbg.h"
#include "hw_setup.h"

#define BAUD 115200
#include <util/setbaud.h>

static int serial_putchar(char c, FILE *stream);
static FILE mystdout = FDEV_SETUP_STREAM(serial_putchar, NULL, _FDEV_SETUP_WRITE);

static int serial_putchar(char c, FILE *stream)
{
    if (c == '\n')
		serial_putchar('\r', stream);

    loop_until_bit_is_set(UCSR0A, UDRE0);
    UDR0 = c;
    return 0;
}

/*
uint8_t serial_getchar(void)
{
	loop_until_bit_is_set(UCSR0A, RXC0);
示例#6
0
#define LED_B_PWM	OCR1C

#define BTN			(1<<PD7)
#define BTN_PORT	PORTD
#define BTN_PIN		PIND
#define BTN_DDR		DDRD

char hexchar2hex(char);
int uart_tx (unsigned char);
unsigned char uart_rx (void);
int i;

unsigned char hexcolors[8] = "NULL", charcount = 0;
unsigned int val_r, val_g, val_b;

FILE uart_str = FDEV_SETUP_STREAM(uart_tx, uart_rx, _FDEV_SETUP_RW);

void init_hw( void )
{
	//Set full speed (disables CKDIV8 by registers)
	CLKPR = (1<<CLKPCE);
	CLKPR = 0;

	//setup LEDs
	LED_R_DDR |= LED_R;
	LED_G_DDR |= LED_G;
	LED_B_DDR |= LED_B;
	
	TCCR1A = (1<<COM1A1)|(1<<COM1A0)|(1<<COM1B1)|(1<<COM1B0)|(1<<COM1C1)|(1<<COM1C0)|(1<<WGM11);
	TCCR1B = (1<<WGM12)|(1<<WGM13)|(1<<CS10);
	
示例#7
0
*	\author		Pat Satyshur
*	\version	1.0
*	\date		1/21/2013
*	\copyright	Copyright 2013, Pat Satyshur
*	\ingroup 	common
*
*	@{
*/

#include <avr/interrupt.h>
#include <stdio.h>
#include <string.h>
#include <avr/io.h>
#include "UART.h"

FILE UART_stdout = FDEV_SETUP_STREAM(UARTPutChar, NULL, _FDEV_SETUP_WRITE);

void UARTinit (void)
{
	#if defined (__AVR_ATmega328P__) || defined (__AVR_ATmega328__)
		PRR &= ~(1<<PRUSART0);			//Turn on UART power
		DDRD |= (1<<1);					//PD1 as output (TxD)
		DDRB &= ~(1<<0);				//PD0 as input (RxD)
		
		//Set USART Baud Rate
		UBRR0H = MYUBRR >> 8;
		UBRR0L = MYUBRR;
		UCSR0B = (1<<RXEN0)|(1<<TXEN0);		//Activate RX, TX
		
		
		
示例#8
0
文件: code.c 项目: shanesoh/pulso
// at start of device turn on, point the front sensor vertically to the ground for calibration
// in the code, sonar0 refers to left sonar, 1 = right, 2 = front

#include "trtSettings.h"
#include "trtkernel_1284.c"
#include <util/delay.h>
#include <stdio.h>

// serial communication library
#define SEM_RX_ISR_SIGNAL 1
#define SEM_STRING_DONE 2 
#include "trtUart.h"
#include "trtUart.c"

// UART file descriptor 
FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);

// semaphore to protect reading (only one active transceiver/ at a time)
#define SEM_RANGE 3

// ----- Sonar and navigation definitions ------
#define sonarFreq 0.25 			// Freq at which sonar ranges (in seconds)
#define navFreq 0.3 			// Freq at which navigation logic refreshes (in seconds)
#define sonar3FeedbackFreq 0.25  // Freq at which sensor 3's motor refreshes (in seconds)
#define windowSize 3 			// Window size of median filter (odd numbers only)
#define nCalibCycles 3 			// Number of front sonar calibration cycles

float F_calibrated = 0; 		// calibrated vertical distance from front sensor to ground
int firstRun = 1;				// flag for first cycle through tasks (for inits)

// Sonar ranges in meters
示例#9
0
//Copyright 2011 Charles Lohr under the MIT/X11 License.

#include "SPIPrinting.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>

volatile char SPIBuffer[PRINTF_BUFFER_SIZE];
volatile unsigned char SPIHead = 0;
volatile unsigned char SPITail = 0;

static int SPIPutCharInternal(char c, FILE *stream);

static FILE mystdout = FDEV_SETUP_STREAM( SPIPutCharInternal, NULL, _FDEV_SETUP_WRITE );

void SetupPrintf()
{
	SPCR = (1<<SPIE)|(1<<SPE);
	DDRB |= _BV(3);
	DDRB &= ~(_BV(0)|_BV(1)|_BV(2));
	stdout = &mystdout;
}

static int SPIPutCharInternal(char c, FILE *stream)
{
	if( ( SPIHead + 1 ) == SPITail ) return -1;//Overflow.
	SPIBuffer[SPIHead] = c;
	SPIHead++;
	if( SPIHead == PRINTF_BUFFER_SIZE ) SPIHead = 0;
	return 0;
}