Пример #1
0
void check_timer (int icount) 
{
	
	if ( TIMER0_VALUE < icount) {
		uart0_printf("timer under count\n\r");
		init_current_time();
	}

}
Пример #2
0
/* ---- Main function ---- */
int main(void)
{
	int temp;
	init_current_time();
	// Intro
	uart0_printf("\r\n\r\nSTORM SoC Basic Configuration\r\n");
	uart0_printf("Demo program + Timer\r\n\r\n");
	uart1_print();
		while (1) {
		 //TIMER0_LOAD  = 1562;

		check_timer (50) ;
	}
}
Пример #3
0
int main(void) {
  SystemInit();

  debug_puts("Happy Face!\n");

  SystemCoreClockUpdate();
  uint32_t clock = SystemCoreClock;

  INIT_LEDS();

  /* Setup the memory */
  memory_init();

  /* Start applications */
  net_init();
  radio_init();
  init_current_time();

  /* Switch to a stable clock source from the radio */
  switch_to_stable_clock();

  /* Setup the Repetitive Interrupt Timer (RIT) */
  LPC_SC->PCONP |= (1 << 16); /* Power up the RIT, PCLK=CCLK/4 */
  LPC_RIT->RICTRL = 1; /* Disable RIT, Clear interrupt */
  NVIC_SetPriority(RIT_IRQn, 31); /* Set Lowest Priority */
  NVIC_EnableIRQ(RIT_IRQn); /* Enable the interrupt */
  LPC_RIT->RIMASK = 0; /* Compare all the bits */
  LPC_RIT->RICOMPVAL = 500*25; /* 500µS on 25MHz PCLK */
  /* Enable RIT, Halt on Debug, Clear on match */
  LPC_RIT->RICTRL = (1<<3)|(0<<2)|(1<<1);

  /* Setup sleep mode */
  LPC_SC->PCON &= ~0x3; /* Sleep or Deep Sleep mode */
  SCB->SCR &= ~(1<<2); /* Sleep mode */

  /* Sleep forever */
  while(1) {
    __WFI();
  }

  return 0;
}
Пример #4
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);
        }
    }
}