Exemplo n.º 1
0
Arquivo: avr.c Projeto: olcai/sommar
void suart_puts(const char* str)
{
  while(*str)
  {
    while(suart_putc(*str) == FALSE);
    str++;
  }
  while(suart_putc('\n') == FALSE);
}
Exemplo n.º 2
0
/**
 * Send a byte via software uart
 * Doesn't care about running transmissions!
 */
void debug_send_c(char c, uint8_t endLine){
	suart_putc(c);
	if( endLine ){
		suart_puts("\n");
	}
}
Exemplo n.º 3
0
Arquivo: avr.c Projeto: olcai/sommar
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);
}