int main( void ) { uint8_t i; uint8_t numArgs; char argStr[ 20 ]; InitHardware(); // The first handle opened for read goes to stdin, and the first handle // opened for write goes to stdout. So u0 is stdin, stdout, and stderr #if defined( __AVR_LIBC_VERSION__ ) fdevopen( UART0_PutCharStdio, UART0_GetCharStdio ); #else fdevopen( UART0_PutCharStdio, UART0_GetCharStdio, 0 ); #endif printf( "*****\n" ); printf( "***** ArgTest program\n" ); printf( "*****\n" ); numArgs = NumArgs(); LED_OFF( RED ); LED_OFF( BLUE ); LED_OFF( YELLOW ); while ( 1 ) { printf( "Number of arguments: %d\n", numArgs ); printf( "\n" ); for ( i = 0; i < numArgs; i++ ) { GetArg( i, argStr, sizeof( argStr )); printf( "arg[ %d ] = '%s'\n", i, argStr ); } for ( i = 0; i < 5; i++ ) { putchar( '.' ); LED_ON( RED ); Delay100mSec( 2 ); LED_OFF( RED ); LED_ON( BLUE ); Delay100mSec( 2 ); LED_OFF( BLUE ); Delay100mSec( 6 ); } putchar( '\n' ); } } // main
int main(void) { FILE * slow; uint8_t i; wait_ms(100); lcd_init(LCD_DISP_ON); lcd_putc('j'); // ne doit pas etre visible lcd_putc('\f'); // effacement lcd_gotoxy(5,0); lcd_putc('h'); wait_ms(DELAY); lcd_putc('e'); wait_ms(DELAY); lcd_putc('l'); wait_ms(DELAY); lcd_putc('l'); wait_ms(DELAY); lcd_putc('o'); wait_ms(DELAY); lcd_putc('\n'); for(i=0;i<5;i++) lcd_putc(' '); lcd_putc('w'); wait_ms(DELAY); lcd_putc('o'); wait_ms(DELAY); lcd_putc('r'); wait_ms(DELAY); lcd_putc('l'); wait_ms(DELAY); lcd_putc('d'); wait_ms(DELAY); wait_ms(20*DELAY); // with printf :) fdevopen(lcd_dev_putc,NULL); lcd_putc('\f'); // effacement printf_P(PSTR("big brother")); wait_ms(20*DELAY); slow = fdevopen(lcd_dev_putc_delay,NULL); fprintf_P(slow, PSTR("\fl' AVR c'est top\nl' AVR c'est tof")); while(1); return 0; }
void stdio_usb_init(void) { stdio_base = NULL; ptr_put = stdio_usb_putchar; ptr_get = stdio_usb_getchar; /* * Start and attach USB CDC device interface for devices with * integrated USB interfaces. Assume the VBUS is present if * VBUS monitoring is not available. */ udc_start (); #if defined(__GNUC__) # if XMEGA // For AVR GCC libc print redirection uses fdevopen. fdevopen((int (*)(char, FILE*))(_write),(int (*)(FILE*))(_read)); # endif # if UC3 || SAM // For AVR32 and SAM GCC // Specify that stdout and stdin should not be buffered. setbuf(stdout, NULL); setbuf(stdin, NULL); // Note: Already the case in IAR's Normal DLIB default configuration // and AVR GCC library: // - printf() emits one character at a time. // - getchar() requests only 1 byte to exit. # endif #endif }
FILE* HTTPClient::openClientFile() { FILE* result = fdevopen(clientWrite, clientRead); if (result == NULL) { return NULL; } http_stream_udata* udata = (http_stream_udata*) malloc( sizeof(http_stream_udata)); fdev_set_udata(result,udata); udata->client = this; udata->encode = 0; if (connected()) { stop(); } if (connect()) { return result; } else { closeStream(result); return NULL; } }
void sms_uart_init() { uint8_t i; usart_init(); /* open stream to mobil */ ausgabe = fdevopen(my_uart_put, NULL); SMS_DEBUG("sms\r\n"); /* disable command echo from mobil */ fprintf(ausgabe, "ate0\r\n"); SMS_DEBUG("mobil echo off\r\n"); global_mobil_access = 1; i = 255; while (global_mobil_access == 1 && i--) _delay_ms(4); if (!i) return; /* select mobil mem */ fprintf(ausgabe, "AT+CPMS=MT\r\n"); SMS_DEBUG("mobil memory selected\r\n"); global_mobil_access = 1; i = 255; while (global_mobil_access == 1 && i--) _delay_ms(4); if (!i) return; for (i = 0; i < SMS_BUFFER; i++) sms_buffer[i] = NULL; }
int main(void) { /* LEDS */ DDRB=0xFF; /* uart*/ uart_init(); // kbd_init(); scheduler_init(); /* ajoute la scrutation du clavier */ // scheduler_add_periodical_event(kbd_get_pressed, 100); /* envoie les caracteres du clavier vers l'uart */ // kbd_register_event(menu_control); /* creation du device */ fdevopen( (int (*)(char)) uart0_send, (int (*)(void))uart0_recv, 0); // se place sur le 1er fils menu_goto(menu_down(menu_current())); menu_print(); sei(); while(1); return 0; }
void main_init(void) { uint8_t itmp; serial_init(); PORTD |= 7<<PD5; DDRD |= 15<<PD4; fdevopen((void*)serial_putc, (void*)serial_get); serial_set_echo(SERIAL_ECHO_OFF); for(itmp=0; itmp<20; itmp++) printf("\r\n"); printf("Initialization\r\n"); printf("Initializing delay timer (2)...\r\n"); timer2_init(); adc_init(); timer2_wait(STD_DELAY); printf("Disable JTAG...\r\n"); cli(); MCUCSR |= (1<<JTD); MCUCSR |= (1<<JTD); // 2 mal in Folge ,vgl. Datenblatt fuer mehr Information sei(); timer2_wait(STD_DELAY); initial_power_check(); printf("EEPROM Check:"); if(eeprom_is_config_valid()==1) printf(COLOR_GREEN" Valid!"COLOR_OFF); else printf(COLOR_RED" Invalid!"COLOR_OFF); printf("\r\n"); }
int main (void) { uint16_t heading; int16_t pitch, roll; uint16_t headingIntegerPart, headingFractionPart; int16_t pitchIntegerPart, pitchFractionPart; int16_t rollIntegerPart, rollFractionPart; // initialize the hardware stuff we use InitTimer (); InitUART (); i2c_init (); fdevopen (UART0_PutCharStdio, UART0_GetCharStdio); // set the LED port for output LED_DDR |= LED_MASK; printf ("\nHoneywell HMC6343 I2C Compass Test\n\n"); // Flash the LED for 1/2 a second... turnOnLED (); ms_spin (500); turnOffLED (); while (1) // outer loop is once every 250 ms (more or less) { // send the HEADING command to the compass i2c_start_wait (COMPASS_ADDRESS_WRITE); i2c_write (COMPASS_HEADING_COMMAND); // now read the response i2c_rep_start (COMPASS_ADDRESS_READ); heading = (i2c_readAck () * 256) + i2c_readAck (); pitch = (i2c_readAck () * 256) + i2c_readAck (); roll = (i2c_readAck () * 256) + i2c_readNak (); i2c_stop (); headingIntegerPart = heading / 10; headingFractionPart = heading - (headingIntegerPart * 10); pitchIntegerPart = pitch / 10; pitchFractionPart = pitch - (pitchIntegerPart * 10); if (pitchFractionPart < 0) pitchFractionPart *= -1; rollIntegerPart = roll / 10; rollFractionPart = roll - (rollIntegerPart * 10); if (rollFractionPart < 0) rollFractionPart *= -1; printf ("Heading: %3d.%1d Pitch: %3d.%1d Roll: %3d.%1d\n", headingIntegerPart, headingFractionPart, pitchIntegerPart, pitchFractionPart, rollIntegerPart, rollFractionPart); turnOnLED (); ms_spin (100); turnOffLED (); ms_spin (150); } // we'll never get here... return 0; }
int main(void) { uint32_t data; uint32_t data_try; uint8_t error; int i; #ifndef HOST_VERSION /* UART */ uart_init(); fdevopen(uart0_dev_send, uart0_dev_recv); sei(); #endif for (i=0; i<(sizeof(tab)/sizeof(uint32_t)) ; i++) { data=tab[i]; for(error=0; error<29 ; error++) { data_try = data; hamming_do(&data_try); data_try ^= (1L << error); // block if pb hamming_undo(&data_try); if (data != data_try) { printf("Hamming fail %d %d\n", i, error); } } } printf("Hamming success\n"); return 0; }
void my_uart_usb_init(void){ circ_buffer_init(&my_uart_usb_rx_buffer); circ_buffer_init(&my_uart_usb_tx_buffer); #ifdef __GNUC__ fdevopen((int (*)(char, FILE*))(my_uart_usb_putchar),(int (*)(FILE*))my_uart_usb_getchar); //for printf redirection #endif }
void setup() { // put your setup code here, to run once: fdevopen( &my_putc, 0); sensors[S0] = &read_0_sonic_real; sensors[S90] = &read_90_sonic_real; sensors[S180] = &read_180_sonic_real; sensors[S270] = &read_270_sonic_real; sensors[OR0] = &read_orientation_is_0; Serial.begin(115200); randomSeed(analogRead(0)); digitalWrite(SS, HIGH); // ensure SS stays high for now // Put SCK, MOSI, SS pins into output mode // also put SCK, MOSI into LOW state, and SS into HIGH state. // Then put SPI hardware into Master mode and turn SPI on SPI.begin(); }
FILE *tftout(tft_t *hw) { static FILE *out = NULL; tft = hw; if (out == NULL) out = fdevopen(tftputch, NULL); return out; }
static void init(void) { usart0__rate__set(BAUD_RATE); usart0__tx__enabled__set(1); usart0__rx__enabled__set(1); usart_out = fdevopen(usart_putchar, NULL); stdout = stdin = usart_out; }
static void ReadLoggingFlag ( void ) { loggingFlag = eeprom_read_byte((uint16_t*)(CALIBRATION_EEPROM_BASE + LOGGING_FLAG_LOCATION)); if (loggingFlag) { InitUART (); fdevopen (UART1_PutCharStdio, UART1_GetCharStdio); turnOnAsyncCapture(); } }
int main(void) { USART_init(TX_COMPLETION_INTERRUPT | RX_COMPLETION_INTERRUPT, 51); USART_setRxCompletionInterruptListener(*rxEventListener); fdevopen(*USART_sendData, NULL); sei(); printf("Initialized>>\n"); while (1) { } }
void uart_init(void) { // set baud rate UBRR1H = 0x01; UBRR1L = 0xa0; UCSR1B = (1<<RXEN1)|(1<<TXEN1); // set 8N1 frame format UCSR1C = (1<<UCSZ11)|(1<<UCSZ10); fdevopen(&uart_putchar, &uart_getchar); }
int main(void) { init(); fdevopen(&serial_console_putc, NULL); pinIsrSetup(); taskLoop(NULL); return 0; }
/* redirect the standard input/output stream to the uart. the uart must be * constructed and opened successfully before call this function. */ void stdc_redirect( TiUartAdapter * uart ) { m_uart = uart; /* @todo * fdevopen is declared in <stdio.h> but you may need to link with some library * to enable it. i don't know why there's always a warning when calling fdevopen */ fdevopen( _usart_putchar, _usart_getchar, 0 ); }
void serial_init( void ) { uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) ); fdevopen(&uart_putchar,NULL); // printf_P( PSTR("S0 V%d.%d up\r\n"), SWVERSIONMAJOR, SWVERSIONMINOR ); buffer[0] = 0; buf_cnt = 0; }
void setup() { Serial.begin(115200); fdevopen(&serial_putc, 0); fb_init(fb_default()); init_task(); vTaskStartScheduler(); }
void hd44780_init(void) { /* init io pins */ CTRL_OUTPUT(); PIN_CLEAR(HD44780_RS); PIN_CLEAR(HD44780_EN); #ifdef HAVE_HD44780_RW PIN_CLEAR(HD44780_RW); #endif PIN_CLEAR(HD44780_D4); PIN_CLEAR(HD44780_D5); PIN_CLEAR(HD44780_D6); PIN_CLEAR(HD44780_D7); DATA_OUTPUT(); _delay_ms(40); PIN_SET(HD44780_D4); PIN_SET(HD44780_D5); clock_write(); _delay_ms(4); clock_write(); _delay_ms(1); clock_write(); /* init done */ _delay_ms(1); PIN_CLEAR(HD44780_D4); clock_write(); _delay_ms(1); /* configure for 4 bit, 2 lines, 5x9 font (datasheet, page 24) */ output_byte(0, CMD_FUNCTIONSET(0, 1, 0)); /* turn on display, cursor and blinking */ hd44780_config(0,0); /* clear display */ hd44780_clear(); /* set shift and increment */ output_byte(0, CMD_ENTRY_MODE(1, 0)); /* set ddram address */ output_byte(0, CMD_SETDRAMADR(0)); /* open file descriptor */ lcd = fdevopen(hd44780_put, NULL); /* set current virtual postion */ current_pos = 0; }
int main(void) { // Global init sei(); uart_init(); fdevopen(uart1_dev_send, uart1_dev_recv); // Error configuration error_register_emerg(log_event); error_register_error(log_event); error_register_warning(log_event); error_register_notice(log_event); error_register_debug(log_event); log_level = ERROR_SEVERITY_DEBUG; // Clear screen printf("%c[2J",0x1B); printf("%c[0;0H",0x1B); // Test fpga_init(); wait_ms(100); _SFR_MEM8(0x1800) = 1; wait_ms(100); _SFR_MEM8(0x1800) = 0; NOTICE(0, "ADNS9500 init"); adns9500_init(); NOTICE(0, "ADNS9500 boot"); adns9500_boot(); NOTICE(0,"ADNS9500 > AUTO"); adns9500_set_mode(ADNS9500_BHVR_MODE_AUTOMATIC); adns9500_encoders_t e; while(1) { adns9500_encoders_get_value(&e); printf("%ld %ld %ld %ld %ld %ld | %2.2X %2.2X %2.2X | %2.2X\n", e.vectors[0], e.vectors[1], e.vectors[2], e.vectors[3], e.vectors[4], e.vectors[5], e.squals[0], e.squals[1], e.squals[2], e.fault); wait_ms(100); } NOTICE(0, "DONE"); while(1) nop(); return 0; }
int main() { PCMSK0 |= 1 << SCL_PCINT | 1 << SDA_PCINT; PCICR |= 1 << PCINT_GROUP; uart_init(); fdevopen(&uart_putchar, &uart_getchar); if (MAKE_TWI_TRAFFIC_FOR_SELF_TEST) i2c_init(); sei(); printf("I2C Sniffer by dongfang\r\n"); processLoop2(); }
void usartInitialize() { /*UBRR (USART Baud Register) variable to hold calculated serial port config values (16 bits) - Default Operating Mode: Asynchronous Normal Mode (U2X=0): * set USART_OPERATING_MODE_U2X=0; - Secondary Operating Mode: Asynchronous Double Speed Mode (U2X=1): * set USART_OPERATING_MODE_U2X=1; */ #if USART_OPERATING_MODE_U2X unsigned int UBRR=(F_CPU / (8UL * USART_BAUDRATE)) - 1; //if integer trunctuation is noticed (...not getting the expected baudrate) due to integer devision, USE: ((F_CPU + USART_BAUD_RATE * 8L) / (USART_BAUD_RATE * 16L) - 1) instead. When doing integer division it is usually better to round to the nearest integer, rather than to the lowest. UCSR0A |= (1<<U2X0);//---------------------------//U2x=1 #else unsigned int UBRR=(F_CPU / (16UL * USART_BAUDRATE)) - 1; UCSR0A &= ~(1<<U2X0);//---------------------------//U2X=0 #endif //Set up the baud rate for USART0 UBRR0L=UBRR;//---------------------------// load lower 8 bits of baud rate value UBRR0H=(UBRR>>8);//---------------------------// load upper 8 bits of baud rate value //Enable Tx & Rx UCSR0B=(1<<TXEN0)|(1<<RXEN0); /*Configure Data Format: - Data Bits = 8; - Stop Bits = 2; - Parity = EVEN; */ UCSR0C = (1<<URSEL0)|(1<<USBS0)|(3<<UCSZ00)|(1<<UPM01); /* * If "USART_ENABLE_printf" is set we can bind printf to "usartSendByte(..)" function by calling fdevopen(..). * About fdevopen(): * - First parameter: address to a function which outputs a single character. * - Second parameter: optional; used for get functions, ie. receiving a character from the USART. * - BEAWARE that this function uses malloc() */ if(USART_ENABLE_printf) { fdevopen(&usartSendByte,NULL); // Create printf Stream structure //FILE printf_stream = FDEV_SETUP_STREAM(usartSendByte, NULL, _FDEV_SETUP_WRITE); !!!TODO; FOR implementing automatic CR (/r) send for endl(/n) } if(USART_INTERRUPT_RX) { UCSR0B |= (1<<RXCIE0); // Enable the USART Receive Complete interrupt (USART_RXCIE0) //Enable the interrupts globally. sei(); } }
//############################################################################ //INstallation der Seriellen Schnittstelle void UART_Init (void) //############################################################################ { //Enable TXEN im Register UCR TX-Data Enable UCR=(1 << TXEN); //Teiler wird gesetzt UBRR=(SYSCLK / (BAUD_RATE * 16L) - 1); //UBRR = 33; //öffnet einen Kanal für printf (STDOUT) fdevopen (uart_putchar, NULL, 0); sbi(PORTD,4); }
void MAIN_init(void) { USART_Init(MYUBRR); fdevopen(USART_Transmit, USART_Receive); //EXTMEM_init(); //OLED_init(); SPI_Init(); CAN_init(); sei(); }
void debug_init_uart(void) { #ifndef SOFT_UART_SUPPORT usart_init(); /* disable the receiver we just enabled */ usart(UCSR, B) &= ~(_BV(usart(RXCIE)) | _BV(usart(RXEN))); #endif /* open stdout/stderr */ fdevopen(debug_uart_put, NULL); }
//! @brief This function initializes the hardware ressources required for CDC demo. //! //! //! @param none //! //! @return none //! //!/ void cdc_task_init(void) { DDRF = 0; //Port F is an input port PORTF = 0; //Disable pullups uart_init(); Leds_init(); Hwb_button_init(); Usb_enable_sof_interrupt(); #ifdef AVRGCC fdevopen(uart_usb_putchar,uart_usb_getchar); //for printf redirection #endif }
void uart0_init(void) { unsigned char baudrateDiv = MYUBRR; UBRR0H = baudrateDiv >> 8; UBRR0L = baudrateDiv; UCSR0B = (1 << RXEN0) | (1 << TXEN0); UCSR0C = 0x2f;//(1<<USBS0)|(1<<UCSZ00); fdevopen(uart_putchar, NULL); }
void sio2host_init(void) { /* Set HIGH before switching to output to prevent RD cycle */ USB_CTRL_PORT |= USB_RD; USB_CTRL_DDR |= USB_RD; /* Set HIGH before switching to output to prevent WR cycle */ USB_CTRL_PORT |= USB_WR; USB_CTRL_DDR |= USB_WR; USB_CTRL_DDR &= ~USB_RXF; USB_CTRL_DDR &= ~USB_TXE; /* * If the board features an address latch, trigger it to activate * the address decoder. */ #if defined(USB_ALE_PORT) && defined(USB_ALE_PIN) && defined(USB_FIFO_AD) USB_ALE_DDR |= USB_ALE_PIN; USB_ALE_PORT |= USB_ALE_PIN; USB_DATA_SETOUTP(); USB_DATA_PORT = USB_FIFO_AD >> 8; /* high byte of FIFO address */ nop(); nop(); USB_ALE_PORT &= ~USB_ALE_PIN; #endif /* defined(USB_ALE_PORT) && defined(USB_ALE_PIN) && defined(USB_FIFO_AD) */ /* Flush all input data from FIFO. */ USB_DATA_SETINP(); while ((USB_CTRL_PIN & USB_RXF) == 0) { USB_CTRL_RD_LO(); USB_CTRL_RD_HI(); } /* * Some boards require a non-generic (board specific) initialization. * If this is required, the following macro is filled with the proper * implementation (see board specific file pal_config.h). * If this is not required, the macro will be empty. */ USB_INIT_NON_GENERIC(); #if (XMEGA || MEGA_RF) && defined(__GNUC__) // For AVR GCC libc print redirection uses fdevopen. fdevopen((int (*)(char, FILE*))(_write),(int (*)(FILE*))(_read)); # endif }