Esempio n. 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;
}
Esempio n. 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 */
}
Esempio n. 3
0
/*-----------------------------------------------------------------------------
*  init bus communication
*/
static void InitComm(void) {
    
   SioInit();
   SioRandSeed(sMyAddr);
   sSioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, 
                       eSioStopBits1, eSioModeHalfDuplex);
   SioSetIdleFunc(sSioHandle, IdleSio);
   SioSetTransceiverPowerDownFunc(sSioHandle, BusTransceiverPowerDown);

   BusTransceiverPowerDown(true);
   
   BusInit(sSioHandle);
   spRxBusMsg = BusMsgBufGet();
}
Esempio n. 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];
        }
    }
Esempio n. 5
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 */
}