/* $Id$ */ /* Example for use of the HIF functions */ #include "board.h" #include "hif.h" #include "xmpl.h" #define PROMPT() PRINTF("\n\ruracoli[%02d]> ",lc++) int main(void) { uint16_t inchar; uint16_t br = 9600; uint8_t lc = 0; uint8_t msg[] = { 0x57, 0x65, 0x6c, 0x63, 0x6f, 0x6d, 0x65, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x20, 0xb5, 0x72, 0x61, 0x63, 0x6f, 0x6c, 0x69, 0x21, '\n','\r',0x00}; /* setting up UART and adjusting the baudrate */ hif_init(br); LED_INIT(); sei(); #if HIF_TYPE == HIF_AT90USB /* * Wait for terminal user pressing a key so there is time to * attach a terminal emulator after the virtual serial port has * been established within the host OS. */ do { inchar = hif_getc(); } while (inchar >= 0x100); #endif /* using the basic hif_xxx functions */ hif_printf(FLASH_STRING("\n\rHIF Example : %s : %d bit/s\n\r"),BOARD_NAME,br); hif_echo(FLASH_STRING("$Revision$\n\r")); /* this macro is equivalent to hif_printf(FLASH_STRING(...),...) */ PRINTF("File: %s:%d\n\r",__FILE__,__LINE__); /* this function outputs an array transparently */ hif_put_blk (msg, sizeof(msg)); /* there is also an optimized hexdump function for byte arrays */ DUMP(sizeof(msg),msg); /* starting the main loop, prompting and counting the line numbers */ PROMPT(); while(1) { inchar = hif_getc(); if (inchar < 0x100) { if (inchar == '\r' || inchar == '\n') { PROMPT(); } else { hif_putc(inchar); } } } } /* EOF */
The programm dumps at first a view text lines to the host interface, then waiting for input data. All characters received are echoed, except for '\n' and '\r' which where treated as line break, printing out a prompt with the current line number in square brackets.
This is an example screenshot of the terminal window, with the output of tree command, redirected to the HIF.
Screenshot of terminal window.