Пример #1
0
//______________________________________________________________________
int main() {
	WDTCTL = WDTPW + WDTHOLD;
	__use_cal_clk(MHZ);

	P1SEL = 0;
	P1DIR = 0;
	P1OUT = 0;
	P2SEL = 0;
	P2DIR = 0;
	P2OUT = 0;

	_BIC_SR(GIE);

	led_init();
	led_off();

	uart_init();

	_BIS_SR(GIE);

	char buf[64], *at=buf;
	uint8_t c = 0;

	while (1) {
		if (c || uart_getc(&c)) {
			switch (c) {
				case '.': led_flip(); break;
				case '1': uart_puts(quick); uart_putc('\n'); say(quick); break;
				case '2': uart_puts(dave); uart_putc('\n'); say(dave); break;
				case '3': uart_puts(luke); uart_putc('\n'); say(luke); break;
				case '4': uart_puts(time); uart_putc('\n'); say(time); break;
				case '5': uart_puts(temp); uart_putc('\n'); say(temp); break;
				case '\r':	// end of command
					uart_putc('\n');
					*at = '\0';
					at = buf;
					if (*at == '*') {
						speak(at+1);
					}//if
					else {
						if (*at == '!')
							setPitch(*(at+1)-'A');
						else
							say(at);
					}//else
					uart_puts("\ndone\n");
					break;
				default:
					*at++ = c;
					uart_putc(c);
					break;
			}//switch
		}//if
		c = 0;
	}//while

}
Пример #2
0
static void rtc_example_callback()
{
	/* Log the interrupt event. */
	SOC_WATCH_LOG_EVENT(SOCW_EVENT_INTERRUPT, QM_IRQ_RTC_0_INT_VECTOR);

	/* Invert On-board LED. */
	led_flip(BOARD_LED_PIN);
	++rtc_tick;

	/* Reschedule next tick. */
	qm_rtc_set_alarm(QM_RTC_0, (QM_RTC[QM_RTC_0]->rtc_ccvr +
				    (QM_RTC_ALARM_SECOND(CLK_RTC_DIV_1) / 2)));
}
Пример #3
0
int main ( void ) {
    char* line;
    time_t* led_flash_timer;
    time_t* reboot_timer;
    socket_t* socket = socket0_g;
    int reboot_stage = 0;
    
    /* Turn off all LEDs as a starting point */
    led_clear();

    /* this must be first, because all the other init functions call malloc */
    init_malloc();
        
    /* Initialize current time and some timers */
    init_current_time();
    led_flash_timer = init_timer();
    set_timer(led_flash_timer, 500);    
    reboot_timer = init_timer();
    
        
    /* receive packet buffer */
    rx_packet_g = malloc(sizeof(packet_t));
    
    /* socket init */
    socket0_g = init_socket(0);
    socket1_g = init_socket(1);
        
    /* open ethernet port and wait for connection requests 
       keep trying forever */
    while (!open_link());
        
    /* infinite loop. Everything is timer, interrupt and queue driven from here on down */
    while (1) {
        
        /* Flash a heartbeat LED */
        if (timer_expired(led_flash_timer)) {
            led_flip(0);
            set_timer(led_flash_timer, 500);
            }
            
            
        /* Check for newly downloaded tftp file. Add to all tx buffers */
        /* Has a file been uploaded via tftp ? */
        if (udp_file_g != NULL) {
            /* Notify telnet clients that file has been received */
            if (udp_file_g->ready) {
                udp_file_g->ready = 0;
                telnet_broadcast("Received file %s, %d bytes, linux %d\r\n",
                    udp_file_g->filename, udp_file_g->total_bytes, udp_file_g->linux_boot);
                if (process_file(socket0_g) == 0)
                    /* Disconnect in 1 second */
                    set_timer(reboot_timer, 1000);
                else
                    telnet_broadcast("Not an elf file\r\n");
                }
            }
            
            
        /* reboot timer expired */
        if (timer_expired(reboot_timer)) {
            /* First stage of reboot sequence is to nicely disconnect */
            if (reboot_stage == 0) {
                set_timer(reboot_timer, 1000);
                reboot_stage = 1;
                socket0_g->tcp_disconnect = 1;
                socket1_g->tcp_disconnect = 1;
                } 
            else {
            /* Second stage of reboot sequence is to turn off ethmac and then jump to restart vector */
                close_link();
                reboot();
                }
            }


        /* Poll both sockets in turn for activity */
        if (socket == socket0_g)
            socket = socket1_g;
        else
            socket = socket0_g;
            
            
        /* Check if any tcp packets need to be re-transmitted */
        tcp_retransmit(socket);


        /* Handle exit command */
        if (socket->tcp_disconnect && socket->tcp_connection_state == TCP_OPEN) {
            tcp_disconnect(socket);
            }
            

        /* Reset connection */
        if (socket->tcp_reset) {
            socket->tcp_connection_state = TCP_CLOSED;
            socket->telnet_connection_state = TELNET_CLOSED;
            socket->telnet_options_sent = 0;
            tcp_reply(socket, NULL, 0);
            socket->tcp_reset = 0;
            }
                     
        
        /* Send telnet options */             
        if (socket->tcp_connection_state == TCP_OPEN && !socket->telnet_options_sent){
            telnet_options(socket);
            socket->telnet_options_sent = 1;
            }
            
        /* telnet connection open 
           Communicate with client */
        else if (socket->telnet_connection_state == TELNET_OPEN) {
            /* Send telnet greeting */
            if (!socket->telnet_sent_opening_message){
                put_line (socket->telnet_txbuf, "Amber Processor Boot Loader\r\n> ");
                socket->telnet_sent_opening_message = 1;
                }
                
            /* Parse telnet rx buffer */
            if (get_line(socket->telnet_rxbuf, &line)) 
                parse_command (socket, line);

            /* Transmit text from telnet tx buffer */
            telnet_tx(socket, socket->telnet_txbuf);
        }
    }
}