Ejemplo n.º 1
0
/*! Setup debugging output.
 *  This function initializes stderr stream to output on USART specified at baud rate specified.
 *  \param u Pointer to USART used for debug output
 *  \param baudctrlA Baud rate control register A
 *  \param baudctrlB Baud rate control register B
 */
void debugInit(struct USART_struct *u,
               enum debugUsartBlock_e block,
               uint8_t baudctrlA,
               uint8_t baudctrlB) {
    
    debugUsart = u;
    // initialize USART
    usartInitAsyncTx(u, baudctrlA, baudctrlB);
    // select appropriate putchar function
    if (block == DEBUG_USART_BLOCK) {
        fdev_setup_stream(debug, putchar_block, NULL,  _FDEV_SETUP_WRITE);
    } else {
        fdev_setup_stream(debug, putchar_noblock, NULL,  _FDEV_SETUP_WRITE);
    }
}
Ejemplo n.º 2
0
// Initialize uart and direct standard out and standard error to uart
void Debug::Initialize()
{
    uart_init(UART_BAUD_SELECT(UART_BAUD_RATE, F_CPU));
    fdev_setup_stream(&uartStream, UARTPutChar, NULL, _FDEV_SETUP_WRITE);
    stdout = &uartStream;
    stderr = &uartStream;
}
Ejemplo n.º 3
0
void
Serial_init()
{
    fdev_setup_stream( &g_uartFile, uart_putchar, NULL, _FDEV_SETUP_WRITE );
    Serial.begin( 9600, SERIAL_8N1 );
    stdout = &g_uartFile;
}
Ejemplo n.º 4
0
int main(void)
{
	init();

#if defined(USBCON)
	USBDevice.attach();
#endif

#if defined(USE_STDOUT)
    // fill in the UART file descriptor with pointer to writer.
    fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);

    // The uart is the standard output device STDOUT.
    stdout = &uartout ;
#endif

	setup();

	for (;;) {
		loop();
		if (serialEventRun) serialEventRun();
	}

	return 0;
}
Ejemplo n.º 5
0
void setup_debug() {
	fdev_setup_stream(&_stderr,
		simulavr_fputc,
		simulavr_fgetc,
		_FDEV_SETUP_WRITE | _FDEV_SETUP_READ);
	stderr = &_stderr;
}
Ejemplo n.º 6
0
// -----------------------------------------------------------------
int main() {
    // Initialize the lcd
    lcd_init();
    fdev_setup_stream(&lcd_stream, lcd_putchar, 0, _FDEV_SETUP_WRITE); 
    lcd_clear_and_home();
 
    // initialize eeprom and TWI/I2C
    eeprom_init();
 
    // specify 7 bit device address of eeprom chip
    #define EEPROM_DEVICE_ID 0b1010000
    fprintf_P(&lcd_stream, PSTR("24LC256 ADDR: %02X"), EEPROM_DEVICE_ID);
 
    // specify eeprom memory address for data storage
    #define EEPROM_DATA_ADDRESS 0x0000
 
    // create local copy of eeprom data
    EEPROM_DATA e_data;
 
    // read eeprom contents at location 0000
    e_data = read_eeprom(0);
 
    // show what we read from the eeprom -
    // note: the very first read on a new eeprom
    // will show uninitalized data
    show_eeprom_data(&e_data);
 
    // process data
    if(e_data.need_initalization){
        // set all data item values if first time
        e_data.need_initalization = false;
        strcpy_P(e_data.author, PSTR("Noter"));
        e_data.read_count = 1;
        e_data.brightness = 0x33;
        e_data.version = 1.01;
    } else {
        // check contents against the values written when initializing
        if((e_data.version != 1.01)||
            (strcmp_P(e_data.author, PSTR("Noter")) !=0)||
            (e_data.brightness != 0x33)){
                    lcd_line_four();
                    fprintf_P(&lcd_stream, PSTR("DATA ERROR - ")); 
                    while(true);    // and freeze
                } else {
                    // increment read_count 
                    e_data.read_count += 1;
                }
    }
 
    // write data to eeprom memory at location 0000
    write_eeprom(0, &e_data);
 
    // and show the read count
    lcd_line_two();
    fprintf_P(&lcd_stream, PSTR("READ COUNT = %d"), e_data.read_count);
 
    // done
    while(true);
}
Ejemplo n.º 7
0
void comms_setup()
{
	// set up stdio write redirect to comms_putchar
	fdev_setup_stream(&comms_putchar_file, &comms_putchar, NULL, _FDEV_SETUP_WRITE);
	stdout = &comms_putchar_file;

	// set up comms stream
  comms_stream_setup(&payload_stream, payload_tx_fifo_buffer, PAYLOAD_TX_FIFO_LENGTH, payload_rx_fifo_buffer, PAYLOAD_RX_FIFO_LENGTH, payload_command_bytes, PAYLOAD_COMMAND_BYTES_MAX_LENGTH);
}
Ejemplo n.º 8
0
int16_t Print::printf(const __FlashStringHelper *format, ...)
{
	FILE f;
	va_list ap;

	fdev_setup_stream(&f, printf_putchar, NULL, _FDEV_SETUP_WRITE);
	fdev_set_udata(&f, this);
	va_start(ap, format);
	return vfprintf_P(&f, (const char *)format, ap);
}
Ejemplo n.º 9
0
/**
 * sets up the necessary pointers
 *
 * \warning Must be called before all printf statements!
 *
 * \param baud Baudrate for the communication (see Serial.begin())
 */
extern "C" void uartInit(long baud) {
	// Start the UART
	Serial.begin(baud);

	// fill in the UART file descriptor with pointer to writer.
	fdev_setup_stream(&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);

	// The uart is the standard output device STDOUT.
	stdout = &uartout;
}
Ejemplo n.º 10
0
void hal_printf_init() {
    // create a FILE structure to reference our UART output function
    static FILE uartout;
    memset(&uartout, 0, sizeof(uartout));

    // fill in the UART file descriptor with pointer to writer.
    fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);

    // The uart is the standard output device STDOUT.
    stdout = &uartout ;
}
Ejemplo n.º 11
0
void init_stdout()
{
    /* Create a persistent FILE object. */
    static FILE myStdout;
    
    /* By default stdout, the pointer to the FILE object to use, is null, i.e. no standard
       out is available. We let it point to our persistent FILE object. */
    stdout = &myStdout;
    
    /* Initialize our FILE object ans associate it (and thus stdout) with the charater
       write function, which will write the character into Serial. */
    fdev_setup_stream (&myStdout, serial_putchar, NULL, _FDEV_SETUP_WRITE);

} /* End of init_stdout */
Ejemplo n.º 12
0
template<> OS_PROCESS void TDebugProc::exec()
{
    const timeout_t sleep_time = 200;
    const uint8_t   report_period = 1000 / sleep_time;
    const uint32_t baud = 115200UL;
    const uint32_t divider = (F_CPU + 8 * baud) / (16 * baud) - 1;

    UCSR0B = 0;
    UCSR0A = 0;
    UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
    UBRR0H = divider >> 8;
    UBRR0L = divider;
    UCSR0B = (1 << RXEN0) | (1 << TXEN0);    

    FILE uart_file;
    fdev_setup_stream( &uart_file, uart_putc, NULL, _FDEV_SETUP_WRITE);

    stdout = &uart_file;

    // Reset VT100 properties, clear screen and go home, print sample header
    printf_P(PSTR("\x1B" "c" "\x1B[2J" "\tscmRTOS: 4-Debug sample\n" "Prio "));
    for(uint8_t i = 0; i < OS::PROCESS_COUNT; i++) {
        printf_P(PSTR("%7s"), get_prio_name(i));
    }

    for (;;) {
        uint8_t report_div = report_period;
        do {
            sleep(sleep_time);
        } while(--report_div);

        profiler.process_data();

        // Go to 3'd line, clear to end of screen and print statistics
        printf_P(PSTR("\x1B[3;1H" "\x1B[J" "Stack"));
        for(uint8_t i = 0; i < OS::PROCESS_COUNT; i++) {
            unsigned stack = OS::get_proc(i)->stack_slack() * sizeof(stack_item_t);
            printf_P(PSTR("%7u"), stack);
        }

        printf_P(PSTR("\nCPU %%"));
        for(uint8_t i = 0; i < OS::PROCESS_COUNT; i++) {
            unsigned cpu = profiler.get_result(i);
            printf_P(PSTR("%4u.%02u"), cpu/100, cpu%100);
        }
    }

} // TProc4::exec()
Ejemplo n.º 13
0
void init(void) {
    clock_prescale_set(clock_div_2); // we run at 3.3v
    fdev_setup_stream(&mystdout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
    stdout = &mystdout;
    usb_init();
    MRF_RESET_CONFIG;
    MRF_CS_CONFIG;
    SPI_MasterInit();

    // interrupt pin from mrf
    EIMSK |= (1<<INT0);

    while (!usb_configured()) {
    }
    // Advised to wait a bit longer by pjrc.com
    // as not all drivers will be ready even after host is up
    _delay_ms(500);
}
Ejemplo n.º 14
0
/* === functions =========================================================== */
int buffer_stream_init( buffer_stream_t *pbs,
                        void (*incb)(buffer_t *pbuf),
                        void (*outcb)(buffer_t *pbuf))
{
FILE *f;
    f = &(pbs->bstream);
    pbs->pbufin = NULL;
    pbs->pbufout = NULL;
    pbs->incb = incb;
    pbs->outcb = outcb;
    fdev_setup_stream ( f,
                        buffer_stream_putchar,
                        buffer_stream_getchar,
                        _FDEV_SETUP_RW);
    fdev_set_udata(f, pbs);

    return 0;
}
Ejemplo n.º 15
0
void serial_stdout_init (long speed) {
/* Set baud rate */
uint16_t factor = (F_CPU / 16 + speed / 2) / speed – 1;
UBRR0H = factor >> 8;
UBRR0L = factor;

/* Set format (8N1) */
UCSR0C = 3 << UCSZ00;

/* Enable transmitter */

UCSR0B = _BV(TXEN0);

/* Set up stdout to write to the serial port */
/* stdout = fdevopen (serial_write, NULL);  replaced with the following care of DH */

fdev_setup_stream(&sio_stdout, serial_write, NULL,_FDEV_SETUP_WRITE);
stdout = &sio_stdout ;

}
Ejemplo n.º 16
0
void *
ttyopen(struct devsw *devptr)
{
	struct tty *iptr = &tty[devptr->dvminor];
	FILE *streamPtr;
	
	if ( (streamPtr = (FILE *)calloc(1,sizeof(FILE)) ) == (FILE *)NULL )
		return 0;
	fdev_setup_stream(streamPtr, stdPut, stdGet, _FDEV_SETUP_RW);
	fdev_set_udata(streamPtr, (void *)iptr);	/* Set user defined and accessible pointer */
	
	stdout = streamPtr;
	
//	if (strcmp(name, "stdout") == 0)
//		stdout = streamPtr;				/* stdout is a macro */
//	else if (strcmp(name, "stdin") == 0)
//		stdin = streamPtr;
//	else if (strcmp(name, "stderr") == 0)
//		stderr = streamPtr;
	
	return (void *)streamPtr;
}
Ejemplo n.º 17
0
void Lcd::init(void)
{
	font = 0;
	fdev_setup_stream(&lcdf, (int (*)(char, FILE*)) &lcd.lcdPut, NULL, _FDEV_SETUP_WRITE);

	spiMasterInit();

	CLR_SCE;
	CLR_RST;
	_delay_ms(100);
	SET_RST;
	SET_SCE;

	command(0x21);	// Switch to extended instruction set.
	command(0xbf);	// Set VOP.
	command(0x04);	// Set temperature coefficient.
	command(0x14);	// Set bias.
	command(0x20);	// Switch to basic instruction set.
	command(0x0c);	// Set normal display mode.

	clear();
	sync();
}
Ejemplo n.º 18
0
void term_redirect_putchar(terminal_t* term) {
  term_redirected = term;
  fdev_setup_stream(stdout, term_putchar_wrapper, NULL, _FDEV_SETUP_WRITE);
  //stdout = &mystdout;
}
Ejemplo n.º 19
0
void web::ProcessWebClients()
{
	// listen for incoming clients
	EthernetClient client = m_server->available();
	if (client)
	{
		bool bReset = false;
#ifdef ARDUINO
		FILE stream_file;
		FILE * pFile = &stream_file;
		setup_sendbuf();
		fdev_setup_stream(pFile, stream_putchar, NULL, _FDEV_SETUP_WRITE);
		stream_file.udata = &client;
#else
		FILE * pFile = fdopen(client.GetSocket(), "w");
#endif
		freeMemory();
		trace(F("Got a client\n"));
		//ShowSockStatus();
		KVPairs key_value_pairs;
		char sPage[35];

		if (!ParseHTTPHeader(client, &key_value_pairs, sPage, sizeof(sPage)))
		{
			trace(F("ERROR!\n"));
			ServeError(pFile);
		}
		else
		{

			trace(F("Page:%s\n"), sPage);
			//ShowSockStatus();

			if (strcmp(sPage, "bin/setSched") == 0)
			{
				if (SetSchedule(key_value_pairs))
				{
					if (GetRunSchedules())
						ReloadEvents();
					ServeHeader(pFile, 200, "OK", false);
				}
				else
					ServeError(pFile);
			}
			else if (strcmp(sPage, "bin/setZones") == 0)
			{
				if (SetZones(key_value_pairs))
				{
					ReloadEvents();
					ServeHeader(pFile, 200, "OK", false);
				}
				else
					ServeError(pFile);
			}
			else if (strcmp(sPage, "bin/delSched") == 0)
			{
				if (DeleteSchedule(key_value_pairs))
				{
					if (GetRunSchedules())
						ReloadEvents();
					ServeHeader(pFile, 200, "OK", false);
				}
				else
					ServeError(pFile);
			}
			else if (strcmp(sPage, "bin/setQSched") == 0)
			{
				if (SetQSched(key_value_pairs))
				{
					ServeHeader(pFile, 200, "OK", false);
				}
				else
					ServeError(pFile);
			}
			else if (strcmp(sPage, "bin/settings") == 0)
			{
				if (SetSettings(key_value_pairs))
				{
					ReloadEvents();
					ServeHeader(pFile, 200, "OK", false);
				}
				else
					ServeError(pFile);
			}
			else if (strcmp(sPage, "bin/manual") == 0)
			{
				if (ManualZone(key_value_pairs))
				{
					ServeHeader(pFile, 200, "OK", false);
				}
				else
					ServeError(pFile);
			}
			else if (strcmp(sPage, "bin/run") == 0)
			{
				if (RunSchedules(key_value_pairs))
				{
					ReloadEvents();
					ServeHeader(pFile, 200, "OK", false);
				}
				else
					ServeError(pFile);
			}
			else if (strcmp(sPage, "bin/factory") == 0)
			{
				ResetEEPROM();
				ReloadEvents();
				ServeHeader(pFile, 200, "OK", false);
			}
			else if (strcmp(sPage, "bin/reset") == 0)
			{
				ServeHeader(pFile, 200, "OK", false);
				bReset = true;
			}
			else if (strcmp(sPage, "json/schedules") == 0)
			{
				JSONSchedules(key_value_pairs, pFile);
			}
			else if (strcmp(sPage, "json/zones") == 0)
			{
				JSONZones(key_value_pairs, pFile);
			}
			else if (strcmp(sPage, "json/settings") == 0)
			{
				JSONSettings(key_value_pairs, pFile);
			}
			else if (strcmp(sPage, "json/state") == 0)
			{
				JSONState(key_value_pairs, pFile);
			}
			else if (strcmp(sPage, "json/schedule") == 0)
			{
				JSONSchedule(key_value_pairs, pFile);
			}
			else if (strcmp(sPage, "json/wcheck") == 0)
			{
				JSONwCheck(key_value_pairs, pFile);
			}
#ifdef LOGGING
			else if (strcmp(sPage, "json/logs") == 0)
			{
				JSONLogs(key_value_pairs, pFile);
			}
			else if (strcmp(sPage, "json/tlogs") == 0)
			{
				JSONtLogs(key_value_pairs, pFile);
			}
#endif
			else if (strcmp(sPage, "ShowSched") == 0)
			{
				freeMemory();
				ServeSchedPage(pFile);
			}
			else if (strcmp(sPage, "ShowZones") == 0)
			{
				freeMemory();
				ServeZonesPage(pFile);
			}
			else if (strcmp(sPage, "ShowEvent") == 0)
			{
				ServeEventPage(pFile);
			}
			else if (strcmp(sPage, "ReloadEvent") == 0)
			{
				ReloadEvents(true);
				ServeEventPage(pFile);
			}
			else
			{
				if (strlen(sPage) == 0)
					strcpy(sPage, "index.htm");
				// prepend path
				memmove(sPage + 5, sPage, sizeof(sPage) - 5);
				memcpy(sPage, "/web/", 5);
				sPage[sizeof(sPage)-1] = 0;
				trace(F("Serving Page: %s\n"), sPage);
				SdFile theFile;
				if (!theFile.open(sPage, O_READ))
					Serve404(pFile);
				else
				{
					if (theFile.isFile())
						ServeFile(pFile, sPage, theFile, client);
					else
						Serve404(pFile);
					theFile.close();
				}
			}
		}

#ifdef ARDUINO
		flush_sendbuf(client);
		// give the web browser time to receive the data
		delay(1);
#else
		fflush(pFile);
		fclose(pFile);
#endif
		// close the connection:
		client.stop();

		if (bReset)
			sysreset();
	}
}
Ejemplo n.º 20
0
FILE *uart0FOpen(uint32_t baud) {
	uart0Open(baud);
	fdev_setup_stream(&ttyUART0, uart0PutCharStd, uart0GetCharStd, _FDEV_SETUP_RW);
	return &ttyUART0;
}
Ejemplo n.º 21
0
/* ------------------------------------------------------------------------- */
bool usart_init(uint8_t device_num, baud_rate_t baudrate, usart_parity_t parity, uint8_t xbuf_size, uint8_t rbuf_size) {
	bool		rtcode = false;
	usart_t		*pusart;
	uint16_t	ubbr;
	uint8_t		u2xn;

	assert ((parity==PARITY_NONE) || (parity==PARITY_EVEN) || (parity==PARITY_ODD));
	assert ((baudrate==BAUD_115200) || (baudrate==BAUD_57600) || (baudrate==BAUD_38400) || (baudrate==BAUD_19200) || (baudrate==BAUD_9600));
	assert (device_num <= USARTS_NUM - 1);
	
	switch (baudrate) {
		case BAUD_9600:	// intentional fall through
		case BAUD_19200:	// intentional fall through
		case BAUD_38400:
			u2xn = 0;
			ubbr = (uint16_t) ((F_CPU * 10)/(baudrate * 16));
			if ((ubbr % 10) >= 5) ubbr += 10;	// rounding
			ubbr = (ubbr/10) - 1;
			rtcode = true;
			break;
		case BAUD_57600:
#if F_CPU==8000000
			u2xn = 0x02;
			ubbr = 16;
			rtcode = true;
#elif F_CPU==16000000
			u2xn = 0x02;
			ubbr = 34;
			rtcode = true;
#endif
			break;
		case BAUD_115200:
#if F_CPU==16000000
			u2xn = 0x02;
			ubbr = 16;
			rtcode = true;
#endif
			break;
	}

	if (rtcode == true) {
		uart_xmt_interrupt_disable(device_num);
		uart_rcv_interrupt_disable(device_num);	

		pusart = &usarts[device_num];

		pusart->device_num = device_num;
		pusart->baudrate = baudrate;
		pusart->pxbuf = &(pusart->xmt_buf);
		pusart->prbuf = &(pusart->rcv_buf);
		circbuf_create(pusart->pxbuf,xbuf_size);	// add space in circular buffer
		circbuf_create(pusart->prbuf,rbuf_size);
		pusart->stream = &(pusart->file);
		pusart->read_blocking = true;
		pusart->read_echo = false;
		fdev_setup_stream(pusart->stream, uart_putchar, uart_getchar, _FDEV_SETUP_RW);

		// need an entry for each device for macro expansion
		switch (device_num) {
#if DEV_CLASS_1 || DEV_CLASS_2
			case 0:
				SET_UCSRA(0, u2xn);
				SET_UCSRB(0, (1<<RXEN0) | (1<<TXEN0));
				SET_UCSRC(0, (1<<UCSZ00) | (1<<UCSZ01) | parity);	// 8 bit, 1 stop bit
				SET_UBRRH(0, (ubbr >> 8)); 							// baud rate upper byte
				SET_UBRRL(0, (ubbr)); 								// baud rate lower byte
				break;
#endif
#if DEV_CLASS_1
			case 1:
				SET_UCSRA(1, u2xn);
				SET_UCSRB(1, (1<<RXEN1) | (1<<TXEN1));
				SET_UCSRC(1, (1<<UCSZ10) | (1<<UCSZ11) | parity);	// 8 bit, 1 stop bit
				SET_UBRRH(1, (ubbr >> 8)); 							// baud rate upper byte
				SET_UBRRL(1, (ubbr)); 								// baud rate lower byte
				break;
			case 2:
				SET_UCSRA(2, u2xn);
				SET_UCSRB(2, (1<<RXEN2) | (1<<TXEN2));
				SET_UCSRC(2, (1<<UCSZ20) | (1<<UCSZ21) | parity);	// 8 bit, 1 stop bit
				SET_UBRRH(2, (ubbr >> 8)); 							// baud rate upper byte
				SET_UBRRL(2, (ubbr)); 								// baud rate lower byte
				break;
			case 3:
				SET_UCSRA(3, u2xn);
				SET_UCSRB(3, (1<<RXEN3) | (1<<TXEN3));
				SET_UCSRC(3, (1<<UCSZ30) | (1<<UCSZ31) | parity);	// 8 bit, 1 stop bit
				SET_UBRRH(3, (ubbr >> 8)); 							// baud rate upper byte
				SET_UBRRL(3, (ubbr)); 								// baud rate lower byte
				break;
#endif
		}

		uart_xmt_interrupt_enable(device_num);
		uart_rcv_interrupt_enable(device_num);
	}