Example #1
0
/*-----------------------------------------------------------------------------
*  main
*/
int main(void) {

   uint8_t ret;
   int   sioHdl;

   /* set clock prescaler to 2 (set clock to 7.3928 MHz) */
   CLKPR = 1 << CLKPCE;
   CLKPR = 1;

   /* get module address from EEPROM */
   sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);
   GetClientListFromEeprom();
    
   PortInit();
   TimerInit();
   ButtonInit();
   PwmInit();
   ApplicationInit();

   SioInit();
   SioRandSeed(sMyAddr);

   /* sio for bus interface */
   sioHdl = SioOpen("USART1", eSioBaud9600, eSioDataBits8, eSioParityNo,
                    eSioStopBits1, eSioModeHalfDuplex);

   SioSetIdleFunc(sioHdl, IdleSio1);
   SioSetTransceiverPowerDownFunc(sioHdl, BusTransceiverPowerDown);
   BusTransceiverPowerDown(true);

   BusInit(sioHdl);
   spBusMsg = BusMsgBufGet();

   /* warten for full operation voltage */
   while (!POWER_GOOD);

   /* enable ints before RestorePwm() */
   ENABLE_INT;
   TimerStart();
   RestorePwm();

   /* ext int for power fail: INT0 low level sensitive */
   EICRA &= ~((1 << ISC01) | (1 << ISC00));
   EIMSK |= (1 << INT0);

   ApplicationStart();
   
   /* Hauptschleife */
   while (1) {
      Idle();
      ret = BusCheck();
      ProcessBus(ret);
      CheckButton();
      PwmCheck();
      ApplicationCheck();
      CheckEvent();
   }
   return 0;
}
Example #2
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

    int     sioHandle;
    uint8_t windThreshold1;
    uint8_t windThreshold2;

    MCUSR = 0;
    wdt_disable();

    /* get module address from EEPROM */
    sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);
    windThreshold1 = eeprom_read_byte((const uint8_t *)WIND_THRESHOLD1);
    windThreshold2 = eeprom_read_byte((const uint8_t *)WIND_THRESHOLD2);
    GetClientListFromEeprom();

    PortInit();
    TimerInit();
    SioInit();
    sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                        eSioStopBits1, eSioModeHalfDuplex);
    SioSetIdleFunc(sioHandle, IdleSio);
    SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

    BusTransceiverPowerDown(true);
   
    BusInit(sioHandle);
    spRxBusMsg = BusMsgBufGet();

    /* enable global interrupts */
    ENABLE_INT;  

    SendStartupMsg();

    /* wait for controller startup delay for sending first state telegram */
    DELAY_S(STARTUP_DELAY);

    while (1) { 
        Idle();
        ProcessSwitch();
        ProcessBus();
      
        if (sWind >= windThreshold1) {
            sWindSwitch |= 0x01;
        } else {
            sWindSwitch &= ~0x01;    
        }
        if (sWind >= windThreshold2) {
            sWindSwitch |= 0x02;
        } else {
            sWindSwitch &= ~0x02;    
        }    
    }
    return 0;  /* never reached */
}
Example #3
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

   MCUSR = 0;
   wdt_disable();

   /* get module address from EEPROM */
   sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);

   PortInit();
   TimerInit();

   InitComm();

   /* enable global interrupts */
   ENABLE_INT;  

   SendStartupMsg();

   while (1) { 
      Idle();
      ProcessBus();
   }
   return 0;  /* never reached */
}
Example #4
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

    int     sioHandle;
    uint8_t i;
    uint8_t u8;

    MCUSR = 0;
    wdt_disable();

    /* get module address from EEPROM */
    sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);
    for (i = 0; i < NUM_BUTTON_EVENT_ADDRESSES; i++) {
        sMySwitchAddr[i] = eeprom_read_byte((const uint8_t *)(BUTTON_EVENT_ADRESS_BASE + i));
    }
   
    PortInit();
    TimerInit();
    SioInit();
    SioRandSeed(MY_ADDR);
    sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                        eSioStopBits1, eSioModeHalfDuplex);
    SioSetIdleFunc(sioHandle, IdleSio);
    SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

    BusTransceiverPowerDown(true);
   
    BusInit(sioHandle);
    spRxBusMsg = BusMsgBufGet();

    /* enable global interrupts */
    ENABLE_INT;  
    i2c_slave(SLAVE_ADRESSE);

    button_register = 0;

    init_BJ(SLAVE_ADRESSE);

    for (i = 0; i < NR_OF_LEDS; i++) {
        u8 = eeprom_read_byte((const uint8_t *)(COLOR_LED_BASE + i));
        set_LED(i, u8);
        sNewLedData[i / 2] |= (u8 & 0x0f) << ((i % 2) ? 4 : 0);
    }

    i2c_slave(SLAVE_ADRESSE);

    SendStartupMsg();
   
    while (1) { 
        Idle();
        if (send_startup == 1) {
            init_BJ(SLAVE_ADRESSE);
            for (i = 0; i < NR_OF_LEDS; i++) {
                set_LED(i, eeprom_read_byte((const uint8_t *)(COLOR_LED_BASE + i)));
            }
        }
        sInputState = button_register; 
        ProcessButton(sInputState);

        ProcessBus();

        for (i = 0; i < BUS_SW16_LED_SIZE_SET_VALUE; i++) {
            if ((sNewLedData[i] & 0x0f) != (sLedData[i] & 0x0f) ) { // linke LED
                set_LED(i * 2, sNewLedData[i] & 0x0f);
                i2c_slave(SLAVE_ADRESSE);
            }
            if ((sNewLedData[i] & 0xf0) != (sLedData[i] & 0xf0) ) { // rechte LED
                set_LED(i * 2 + 1, (sNewLedData[i] & 0xf0) >> 4);
                i2c_slave(SLAVE_ADRESSE);
            }
            sLedData[i] = sNewLedData[i];
        }
    }
Example #5
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {

   UINT8   ret;  
   UINT16  flashWordAddr;    
   UINT16  sum;

   cli();
   MCUSR = 0;
   wdt_disable();

   /* get oscillator correction value from EEPROM */
   EEAR = OSCCAL_CORR;
   /* Start eeprom read by writing EERE */
   EECR |= (1 << EERE);
   /* read data */
   OSCCAL += EEDR;

   /* get modul adress from EEPROM */
   EEAR = MODUL_ADDRESS;
   /* Start eeprom read by writing EERE */
   EECR |= (1 << EERE);
   /* read data */
   sMyAddr = EEDR;

   /* configure pins to input with pull up */
   PORTB = 0b11111111;
   DDRB =  0b00000000;

   PORTC = 0b11111111;
   DDRC =  0b00000000;

   PORTD = 0b11111111;
   DDRD =  0b00100010;

   /* configure Timer 0 */
   /* prescaler clk/64 -> Interrupt period 256/1000000 * 64 = 16.384 ms */
   TCCR0B = 3 << CS00; 
   TIMSK0 = 1 << TOIE0;

   SioInit();
   spRxBusMsg = BusMsgBufGet();

   /* Enable change of Interrupt Vectors */
   MCUCR = (1 << IVCE);
   /* Move interrupts to Boot Flash section */
   MCUCR = (1 << IVSEL);

   /* Prüfsumme der Applikation berechnen */
   sum = 0;
   for (flashWordAddr = 0; flashWordAddr < (MAX_FIRMWARE_SIZE / 2); flashWordAddr += CHECKSUM_BLOCK_SIZE) {
      sum += FlashSum(flashWordAddr, (UINT8)CHECKSUM_BLOCK_SIZE);
   }

   if (sum != FLASH_CHECKSUM) {
      /* Fehler */
      sFwuState = WAIT_FOR_UPD_ENTER;      
   }
   sei();
      
   /* Startup-Msg senden */
   sTxBusMsg.type = eBusDevStartup;  
   sTxBusMsg.senderAddr = MY_ADDR; 
   BusSend(&sTxBusMsg);  
   SioReadFlush();
 
   /* Hauptschleife */
   while (1) {   
      ret = BusCheck();
      ProcessBus(ret);
      /* Mit timeout auf Request zum Firmwareupdate warten  */
      if (sFwuState == WAIT_FOR_UPD_ENTER_TIMEOUT) {
         if (gTimeS8 >= 4) {
            /* Application starten */
            break;
         }
      } 
   } 
            
   cli();
   
   /* Enable change of Interrupt Vectors */
   MCUCR = (1 << IVCE);
   /* Move interrupts to application section */
   MCUCR = (0 << IVSEL);

   /* jump to application */
   ApplicationEntry();
   
   /* never reach this */
   return 0;
} 
Example #6
0
/*-----------------------------------------------------------------------------
*  program start
*/
int main(void) {                      

   int     sioHandle;
   uint8_t inputState;

   MCUSR = 0;
   wdt_disable();

   /* get module address from EEPROM */
   sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS);

   sInputType = eeprom_read_byte((const uint8_t *)INPUT_TYPE);
   if (sInputType > INPUT_TYPE_MOTION_DETECTOR) {
      sInputType = INPUT_TYPE_DUAL_BUTTON;
   }
   PortInit();
   TimerInit();
   SioInit();
   SioRandSeed(sMyAddr);
   sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                       eSioStopBits1, eSioModeHalfDuplex);
   SioSetIdleFunc(sioHandle, IdleSio);
   SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown);

   BusTransceiverPowerDown(true);
   
   BusInit(sioHandle);
   spRxBusMsg = BusMsgBufGet();

   /* enable global interrupts */
   ENABLE_INT;  

   SendStartupMsg();
   
   if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
       (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
      /* wait for controller startup delay for sending first state telegram */
      DELAY_S(STARTUP_DELAY);
   }

   if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
       (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
      inputState = GetInputState();
      sSwitchStateOld = ~inputState;
      ProcessSwitch(inputState);
   }

   while (1) { 
      Idle();
   
      inputState = GetInputState(); 
      if ((sInputType == INPUT_TYPE_DUAL_SWITCH) ||
          (sInputType == INPUT_TYPE_MOTION_DETECTOR)) {
         ProcessSwitch(inputState);
      } else if (sInputType == INPUT_TYPE_DUAL_BUTTON) {
         ProcessButton(inputState);
      }

      ProcessBus();
   }
   return 0;  /* never reached */
}
Example #7
0
/*-----------------------------------------------------------------------------
*  Programstart
*/
int main(void) {

   UINT8   ret;  
   UINT16  flashWordAddr;    
   UINT16  sum;

   /* get oscillator correction value from EEPROM */
   EEAR = OSCCAL_CORR;
   /* Start eeprom read by writing EERE */
   EECR |= (1 << EERE);
   /* read data */
   OSCCAL += EEDR;

   /* get modul adress from EEPROM */
   EEAR = MODUL_ADDRESS;
   /* Start eeprom read by writing EERE */
   EECR |= (1 << EERE);
   /* read data */
   sMyAddr = EEDR;

   /* Portpins für Schaltereingänge mit Pullup konfigurieren */
   /* nicht benutzte Pin aus Ausgang Low*/
   PORTC = 0x03;
   DDRC = 0x3C;             
   
   PORTB = 0x38;
   DDRB = 0xC7;
   
   PORTD = 0x01;
   DDRD = 0xFE;

   /* configure Timer 0 */
   /* prescaler clk/64 -> Interrupt period 256/1000000 * 64 = 16.384 ms */
   TCCR0 = 3 << CS00; 
   TIMSK = 1 << TOIE0;

   SioInit();
   spRxBusMsg = BusMsgBufGet();

   /* Umschaltung der Interruptvektor-Tabelle */
   GICR = (1 << IVCE);
   /* In Bootbereich verschieben */
   GICR = (1 << IVSEL);

   /* Prüfsumme der Applikation berechnen */
   sum = 0;
   for (flashWordAddr = 0; flashWordAddr < (MAX_FIRMWARE_SIZE / 2); flashWordAddr += CHECKSUM_BLOCK_SIZE) {
      sum += FlashSum(flashWordAddr, (UINT8)CHECKSUM_BLOCK_SIZE);
   }

   if (sum != FLASH_CHECKSUM) {
      /* Fehler */
      sFwuState = WAIT_FOR_UPD_ENTER;      
   }

   sei();
                          
   /* Startup-Msg senden */
   sTxBusMsg.type = eBusDevStartup;  
   sTxBusMsg.senderAddr = MY_ADDR; 
   BusSend(&sTxBusMsg);  
   SioReadFlush();
   
   /* Hauptschleife */
   while (1) {   
      ret = BusCheck();
      ProcessBus(ret);
      /* Mit timeout auf Request zum Firmwareupdate warten  */
      if (sFwuState == WAIT_FOR_UPD_ENTER_TIMEOUT) {
         if (gTimeS8 >= 4) {
            /* Application starten */
            break;
         }
      } 
   } 
            
   cli();
   /* Umschaltung der Interruptvektor-Tabelle */
   GICR = (1 << IVCE);
   /* In Applikationsbereich verschieben */
   GICR = (0 << IVSEL);
   
   /* zur Applikation springen */       
   ApplicationEntry();
   /* hier kommen wir nicht her!!*/
   return 0;
}