Exemplo n.º 1
0
void UART_Handler(void)
{
    tUartControl *pControl;
	uint32_t ul_status;
	uint8_t c;

	pControl = uart_control[0]; 

	/* Read UART Status. */
	ul_status = uart_get_status(UART);

	if (ul_status & UART_SR_RXRDY)
	{
		uart_read(UART, &c);
		
		/* Check if buffer has more space
		 * If no space, data will be discarded
		 */
		if (str_buf_is_full (&pControl->rx_buffer))
        {
            pControl->rx_buffer.header.err_overflow = 1;
        }
        else
        {
            str_buf_putc (&pControl->rx_buffer, c);
		}
	}
	
	if (ul_status & UART_SR_TXRDY)
	{
		uart_disable_interrupt (UART, UART_IER_TXRDY);

    	while (!str_buf_is_empty (&pControl->tx_buffer))
        {
            c = str_buf_getc (&pControl->tx_buffer);
            uart_write (pControl->uart_def_p, c);
    
            if ( !uart_is_tx_ready (pControl->uart_def_p) )
                break;
        }
        
        /* If there is no more data to send, disable the transmit
            interrupt - else enable it or keep it enabled */
	    if (str_buf_is_empty (&pControl->tx_buffer)) 
        {
		    uart_disable_interrupt (UART, UART_IER_TXRDY);
            pControl->TxIntEnabled = false;
        }
        else
        {
            // Set Tx Interrupt state
            pControl->TxIntEnabled = true;
            uart_enable_interrupt (UART, UART_IER_TXRDY);
        }

	} //
	
}
Exemplo n.º 2
0
void platform_dputc(char c)
{
	if (c == '\n') {
		_dputc('\r');
	}

	while (!uart_is_tx_ready(UART))
		;
	uart_write(UART, c);
}
Exemplo n.º 3
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{	
	sysclk_init();
	irq_initialize_vectors();
	cpu_irq_enable();

	/* Initialize the sleep manager */
	sleepmgr_init();
	
	/* Initialize the SAM board */
	board_init();
	
	/* Serial line [UART] initialization */
	uart1_init(CONF_UART_BAUDRATE);
	
	#if WITH_SERIAL_LINE_INPUT
	/* If SLIP-radio is enabled, the handler is overridden. */
	uart1_set_input(serial_line_input_byte);
	#endif
	
	while(!uart_is_tx_ready(CONSOLE_UART));
	/* PRINT Contiki Entry String */
	PRINTF("Starting ");	
	PRINTF(CONTIKI_VERSION_STRING);	
	
	/* Configure sys-tick for 1 ms */
	clock_init(); 
	
	/* Initialize Contiki Process function */
	process_init();
	
	/* rtimer and ctimer should be initialized before radio duty cycling layers*/
	rtimer_init();
	
	/* etimer_process should be initialized before ctimer */
	process_start(&etimer_process, NULL);
	
	/* Initialize the ctimer process */ 
	ctimer_init();	
#ifdef WITH_LED_DEBUGGING
	configure_led_debug_pins();
#ifdef WITH_AR9170_WIFI_SUPPORT
	configure_ar9170_disconnect_pins();
#endif
#endif		
	
	/* rtimer initialization */
	rtimer_init();
	
	/* Network protocol stack initialization */
	netstack_init();
	
	/* Process init initialization */
	procinit_init();
	
	/* Initialize energy estimation routines */
	energest_init();
		
	/* Initialize watch-dog process */
	watchdog_start();  

#ifdef WITH_AR9170_WIFI_SUPPORT
#ifdef WITH_USB_SUPPORT
	/* Start network-related system processes. */
	#if WITH_UIP6	
	#ifdef WITH_SLIP
	#warning SLIP_RADIO enabled!
	process_start(&slip_radio_process, NULL);
	#endif
	#endif		
#else
#error USB support must be enabled.
#endif
#endif

#ifdef WITH_USB_SUPPORT
	/* Start ARM Cortex-M3 USB Host Stack */
	uhc_start();
	configure_ar9170_disconnect_pins();
#endif	

	/* Autostart all declared [not system] processes */
	//autostart_start(autostart_processes);

	#if UIP_CONF_IPV6
	printf("Tentative link-local IPv6 address: ");
	{
		uip_ds6_addr_t *lladdr;
		int i;
		lladdr = uip_ds6_get_link_local(-1);
		for(i = 0; i < 7; ++i) {
			printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
			lladdr->ipaddr.u8[i * 2 + 1]);
		}
		printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
	}

	if(!UIP_CONF_IPV6_RPL) {
		uip_ipaddr_t ipaddr;
		int i;
		uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
		uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
		uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
		printf("Tentative global IPv6 address ");
		for(i = 0; i < 7; ++i) {
			printf("%02x%02x:",
			ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
		}
		printf("%02x%02x\n",
		ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
	}
	#endif /* UIP_CONF_IPV6 */

	PRINTF("Starting Contiki OS main loop...\n");	

	while(true) {
		
		/* Contiki Polling System */
		process_run();
	}	
}