Exemple #1
0
void emu_reset()
{
        sram_save();
        rtc_save();

        hw_reset();
        lcd_reset();
        cpu_reset();
        mbc_reset();
        sound_reset();

        init = 0;
}
Exemple #2
0
void time_set(time_s* newTimeData)
{
//	TCNT2 = 0x00;

	newTimeData->secs = 0;
	memcpy(&timeData, newTimeData, sizeof(time_s));

#if RTC_SRC != RTC_SRC_INTERNAL
	rtc_save(newTimeData);
#endif

	alarm_updateNextAlarm();
}
Exemple #3
0
bool asic_save(emu_image *s) {
    s->deviceType = asic.deviceType;

    return backlight_save(s)
           && control_save(s)
           && cpu_save(s)
           && flash_save(s)
           && intrpt_save(s)
           && keypad_save(s)
           && lcd_save(s)
           && mem_save(s)
           && watchdog_save(s)
           && protect_save(s)
           && rtc_save(s)
           && sha256_save(s)
           && gpt_save(s)
           && usb_save(s)
           && cxxx_save(s)
           && dxxx_save(s)
           && exxx_save(s)
           && sched_save(s);
}
Exemple #4
0
static void cleanup()
{
	sram_save();
	rtc_save();
	/* IDEA - if error, write emergency savestate..? */
}
Exemple #5
0
int main(void)
{
  const char* str;

  /* initialize stuff commen for both base and node */
  config_load();
  lcd_init();
  rtc_init();
  adc_init();
  uart_init();
  
  //Timer2 används för att hålla våran radio-timeslot (kanske bara behövs när vi är nod?.
  timer2_init();

  /* set portC as output and all leds off */
  DDRC = 0xFF;
  PORTC = 0xff;

  /* lets initialize modules specific for the mode */
  if(config.flags.mode == CONFIG_MODE_BASE)
  {
    suart_init();
    str = "\n00init\nSystem is now online!\n";
    while(*str)
    {
      while(suart_putc(*str) == FALSE);
      str++;
    }
  }
  else
  {
    response_wait_time = atoi(config.group) * 4;
//    response_wait_time = 16;
  }

  /* in our answer the two first byte is always the group number */
  memcpy((void*)answer, (void*)config.group, CONFIG_GRP_LEN);

  /* all is initialized, lets roll */
  sei();
  
  /* configure the mode button pin as input */
  MODE_BUTTON_DDR &= ~_BV(MODE_BUTTON_PIN);

  /* loop until the mode button pin is low */
  while(bit_is_set(MODE_BUTTON_PORT, MODE_BUTTON_PIN))
  {
    uint8_t buffer[UART_FIFO_SIZE];

    /* uart data (radio), parse it */
    if(uart.stopchars)
    {
      uart.stopchars--;

      /* copy it to our stack */
      uint8_t i = 0;
      while ((buffer[i] = uart_getc()) != PROTOCOL_STOPCHAR)
        i++;
      /* 
       * node -> parse it
       * base -> pass along to the suart (to computer)
       */
      
      if(config.flags.mode == CONFIG_MODE_BASE)
      {
        int j;
        for(j=0;j<i;j++)
          while(suart_putc(buffer[j]) == FALSE);
      }
      else {
        if (cmd_parse(buffer, i)) {
          // enable the send timer
          TCNT2 = 0;
          TIMSK |= _BV(OCIE2);
        }
      }
    }

    /*
     * suart data (from computer)
     * We only get this as base, so answer the command
     * if it's addressed to us, and send to all nodes.
     */
    if(suart.stopchars) {
      suart.stopchars--;
      uint8_t i = 0;
      while ((buffer[i] = suart_getc()) != PROTOCOL_STOPCHAR)
        i++;
      if (cmd_parse(buffer, i)) {
        i = 0;
        if (command_parsed == 1) {
          do {
            suart_putc(answer[i]);
          } while (answer[i++] != PROTOCOL_STOPCHAR);
          command_parsed = 0;
        }
      }
      //Send to radio
      i = 0;
      do {
        uart_putc(buffer[i]);
      } while (buffer[i++] != PROTOCOL_STOPCHAR);
    }
  }

  /* we are closing down, do not disturb */
  cli();

  /* this is safe because we know that the mode is just one bit */
  config.flags.mode = !config.flags.mode;
  config_save();
  rtc_save();

  /* use the watchdog to get a nice clean reset */
  wdt_enable(WDTO_15MS);
  while(1);
}