Ejemplo n.º 1
0
void wakeup()
{
   blip();
   
   // serial interrupt detected a char
   if (wakeup_mode == WAKEON_COM_A) {
      // while an RTC wakeup has not occured
      while (wakeup_mode != WAKEON_RTC){
         // flash LED
         blip();
         // if serial wake-up is good
         if (serial_wakeup()){
            sleep_mode = FALSE;
            start_heartbeat();
            init_hardware();
            init_rtc();                      // This is the FAT RTC
            sd_status = init_sdcard();
            bit_set(INTCON,PEIE);            // Set Peripheral Interrupt Enable bit
            sprintf(event_str, ",serial wake-up,SD initialized\r\n");
            record_event();
            if(sd_status>0) msg_card_fail();
            return;
         }
         else {
            // if serial_wakeup() == FALSE, then false alarm
            wakeup_mode = WAKEON_BAD;
            blip();
            blip();
            shutdown();
            go_to_sleep();
         }
      }
   }
}
Ejemplo n.º 2
0
void setup()
{
  board->register_sensor(new Paralax28015REVC_Sensor(1, 5));  
  // board->register_sensor(new DHT_V12_Sensor(6));  
  chibiCmdInit(57600);
  init_sdcard();
  board->set_datetime(15, 5, 1, 15, 20, 0);
  char msg[100];
  memset(msg, 0, 100);
  sprintf(msg, "Clock set to: %s", (char*)board->timestamp());
  writeData((unsigned char*)msg);
  

}
Ejemplo n.º 3
0
int main(void) {
	// Start the timestamp -- will be used for seeding the random number generator.

	alt_timestamp_start();
	sdcard_handle *sd_dev = init_sdcard();
	initAudio();

	loadMusic("Title2.wav", 1, 0.25);

	// Set latch and clock to 0.
	IOWR_8DIRECT(controller_out, 0, 0x00);

	init_display();

	clear_display();

	if (sd_dev == NULL)
		return 1;

	printf("Card connected.\n");

	ticks_per_sec = alt_ticks_per_second();

	seed(alt_timestamp());

	alt_u32 tickCount = alt_nticks();
	num_ticks = ticks_per_sec / 60;
	//alt_alarm *update_alarm = malloc(sizeof(alt_alarm));
	//alt_alarm_start(update_alarm, num_ticks, update, (void*)0);

	while (true)
	{
		if (alt_nticks() - tickCount >= num_ticks)
		{
			tickCount = alt_nticks();
			update(0);
		}
	}

	return 0;
}
Ejemplo n.º 4
0
void main()
{
   disable_interrupts(GLOBAL);
   
   setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 );
   setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 );
   
   setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);

   // TIMER 0 is being used to service the WTD
   setup_timer_0(T0_INTERNAL|T0_DIV_256);
   /* sets the internal clock as source and prescale 256. 
      At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every
      6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used.
      Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec
      Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec
      .. pre-load with 3036 to get exact 1.0000 sec value
   */
   
   // TIMER 1 is used to extinguish the LED
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   /* sets the internal clock as source and prescale 4. 
      At 10Mhz timer0 will increment every 0.4us in this setup and overflows every
      104.8 ms. Timer1 is 16-bit.
      Fosc = 10 Mhz ... 2.5 MHz / div 4  = 0.00000160 s * 65536 = 0.104858 sec
      Fosc = 64 Mhz ... 16 MHz /  div 4  = 0.00000025 s * 65536 = 0.016384 sec
      Fosc = 64 Mhz ... 16 MHz /  div 8  = 0.00000200 s * 65536 = 0.032768 sec
   */   
   
   setup_stepper_pwm();  // Uses TIMER 2
   
   // TIMER 3 is used for stepper motor intervals
   setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);   // 16 bit timer
   
   // TIMER 4 is use for serial time-outs. 8-bit timer.
   setup_timer_4(T4_DIV_BY_4, 127, 1);           
   
   setup_comparator(NC_NC_NC_NC);
   
   setup_oscillator(OSC_16MHZ | OSC_PLL_ON);  // Fosc = 64 MHz
          
   ext_int_edge(0, H_TO_L);         // Set up PIC18 EXT0
   enable_interrupts(INT_EXT);
   
   start_heartbeat();
   
   enable_interrupts(GLOBAL);

   init_hardware();
   motor_sleep_rdy();
   
   sleep_mode = FALSE;   
   busy_set();
   
   init_nv_vars();
   get_step_vars();
   init_aws();
   
   blink();
   
   //Add for TCP/IP interface
   //delay_ms(15000);
   
   signon();
   
   RTC_read();
   RTC_last_power();
   RTC_reset_HT();  
   RTC_read();    
   RTC_read_flags();
   
   if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status);
   init_rtc(); // This is the FAT RTC
   sd_status = init_sdcard();
   if(sd_status>0) msg_card_fail();
   
   reset_event();
   
   if(m_error[0] > 0 || m_error[1] > 0) msg_mer();  
   
   if (m_comp[0]==FALSE) {
      e_port[0]=0;
      write16(ADDR_E1_PORT,0);
      fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]);
   }
   if (m_comp[1]==FALSE) {
      m_lin_pos[1]=-1;
      write16(ADDR_M2_LIN_POS, -1);
      fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]);
   }
   
   if (nv_cmd_mode == FALSE){
      for(dt=0; dt<100; ++dt){
         blip();
         if (nv_cmd_mode == TRUE) {
            busy_clear();
            fputs("@OK!", COM_A);
            command_prompt();
            dt = 100;
         }
      }
   }
   else command_prompt();
   
   user_quit = auto_sample_ready();
   
   reset_cpu();
}