void init(void) { LED_INIT(); SW_INIT(); SENS_INIT(); // SPI // MOSI, SCK, als Output / MISO als Input SPI_DDR |= _BV( SPI_MOSI ) | _BV( SPI_SCLK ); // mosi, sck output SPI_DDR &= ~_BV( SPI_MISO ); // miso input // test pin change interrupt GIMSK |= _BV(PCIE0); /* PCIE0 pin change interrupt auf pcint 7 bis 0 aktiviert */ PCMSK0 |= _BV(PCINT0) | _BV(PCINT1); /* pcint0 + 1 aktivieren */ // read housecode/button from eprom readConfig(); // init devices ccInitChip(); fs20_init(); // init watchdog timer as long timer (8s). Timeout will lead to an interrupt and not a reset // do not set WDE (as if so we need to set WDIE after every interrupt) WDTCSR |= _BV(WDIE) | _BV(WDP3) | _BV(WDP0); }
//-------------------------------------------------------------------- void ccsetpa(char *in) { uint8_t hb = 2; fromhex(in+1, &hb, 1); cc_set_pa(hb); ccInitChip(EE_CC1100_CFG); }
static void rf_router_send(uint8_t addAddr) { #ifdef RFR_DEBUG if(RFR_Buffer.buf[5] == 'T') nr_t++; else if(RFR_Buffer.buf[5] == 'F') nr_f++; else if(RFR_Buffer.buf[5] == 'E') nr_e++; else if(RFR_Buffer.buf[5] == 'K') nr_k++; else if(RFR_Buffer.buf[5] == 'H') nr_h++; else nr_r++; #endif uint8_t buf[7], l = 1; buf[0] = RF_ROUTER_PROTO_ID; if(addAddr) { tohex(rf_router_target, buf+1); tohex(rf_router_myid, buf+3), buf[5] = 'U'; l = 6; } rf_router_ping(); // 15ms ccInitChip(EE_FASTRF_CFG); // 1.6ms my_delay_ms(3); // 3ms: Found by trial and error CC1100_ASSERT; cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO); #ifdef RFR_USBECHO uint8_t nbuf = RFR_Buffer.nbytes; #endif cc1100_sendbyte(RFR_Buffer.nbytes+l); for(uint8_t i = 0; i < l; i++) cc1100_sendbyte(buf[i]); while(RFR_Buffer.nbytes) cc1100_sendbyte(rb_get(&RFR_Buffer)); CC1100_DEASSERT; ccTX(); rb_reset(&RFR_Buffer); // needed by FHT_compress // Wait for the data to be sent uint8_t maxwait = 20; // max 20ms while((cc1100_readReg(CC1100_TXBYTES) & 0x7f) && maxwait--) my_delay_ms(1); set_txrestore(); #ifdef RFR_USBECHO #warning RFR USB DEBUGGING IS ACTIVE uint8_t odc = display_channel; display_channel = DISPLAY_USB; DC('.'); DU(nbuf, 2); DNL(); display_channel = odc; #endif }
/* * remote configuration facility */ void fs20_configuration(void) { ccInitChip(); fs20_resetbuffer(); fs20_rxon(); fstelegram_t t; t.type = 'U'; // undefined uint16_t rxtimeout = 300; // wait 300*100ms= 30s for reception // wait for next telegram // exit if button pressed or timeout occured while(!fs20_readFS20Telegram(&t) && (rxtimeout--)>0) { _delay_ms(100); if(LED_PIN!=PA3) LED_TOGGLE(); // do not touch pin for CC1100 communication } fs20_idle(); // evaluate the result if(t.type=='F') { if((t.housecode==HOUSECODE) && (t.button==BUTTON_COMMAND)) { led_blink(3); // blink for confirmation switch(t.cmd) { case COMMAND_HCALIB1: xcalib1= get_voltage(); hcalib1= t.data[0]/100.0; recalibrate(); break; case COMMAND_HCALIB2: xcalib2= get_voltage(); hcalib2= t.data[0]/100.0; recalibrate(); break; case COMMAND_USFOFFSET: // we receive ufsoffset in centimeters set_usfconfig(t.data[0]/100.0, usfheight); break; case COMMAND_USFHEIGHT: // we receive usfheight in centimenters set_usfconfig(usfoffset, t.data[0]/100.0); break; } } } }
void set_ccon(void) { ccInitChip(EE_CC1100_CFG); cc_on = 1; #ifdef HAS_ASKSIN #ifndef CC1100_ASKSIN asksin_on = 0; #endif #endif #ifdef HAS_MORITZ #ifndef CC1100_MORITZ moritz_on = 0; #endif #endif }
void set_ccon (void) { ccInitChip (); cc_on = 1; }
void rf_router_task(void) { if(rf_router_status == RF_ROUTER_INACTIVE) return; uint8_t hsec = (uint8_t)ticks; if(rf_router_status == RF_ROUTER_GOT_DATA) { uint8_t len = cc1100_readReg(CC1100_RXFIFO); uint8_t proto = 0; if(len > 5) { rb_reset(&TTY_Rx_Buffer); CC1100_ASSERT; cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO ); proto = cc1100_sendbyte(0); while(--len) rb_put(&TTY_Rx_Buffer, cc1100_sendbyte(0)); CC1100_DEASSERT; } set_txrestore(); rf_router_status = RF_ROUTER_INACTIVE; if(proto == RF_ROUTER_PROTO_ID) { uint8_t id; if(fromhex(TTY_Rx_Buffer.buf, &id, 1) == 1 && // it is for us id == rf_router_myid) { if(TTY_Rx_Buffer.buf[4] == 'U') { // "Display" the data while(TTY_Rx_Buffer.nbytes) // downlink: RFR->CUL DC(rb_get(&TTY_Rx_Buffer)); DNL(); } else { // uplink: CUL->RFR TTY_Rx_Buffer.nbytes -= 4; // Skip dest/src bytes TTY_Rx_Buffer.getoff = 4; rb_put(&TTY_Rx_Buffer, '\n'); input_handle_func(DISPLAY_RFROUTER); // execute the command } } else { rb_reset(&TTY_Rx_Buffer); } } } else if(rf_router_status == RF_ROUTER_DATA_WAIT) { uint8_t diff = hsec - rf_router_hsec; if(diff > 7) { // 3 (delay above) + 3 ( ((4+64)*8)/250kBaud ) set_txrestore(); rf_router_status = RF_ROUTER_INACTIVE; } } else if(rf_router_status == RF_ROUTER_SYNC_RCVD) { ccInitChip(EE_FASTRF_CFG); ccRX(); rf_router_status = RF_ROUTER_DATA_WAIT; rf_router_hsec = hsec; } }
void it_func(char *in) { if (in[1] == 't') { fromdec (in+2, (uint8_t *)&it_interval); DU(it_interval,0); DNL(); } else if (in[1] == 's') { if (in[2] == 'r') { // Modify Repetition-counter fromdec (in+3, (uint8_t *)&it_repetition); DU(it_repetition,0); DNL(); #ifdef HAS_HOMEEASY } else if (in[2] == 'h') { // HomeEasy it_send (in, DATATYPE_HE); } else if (in[2] == 'e') { // HomeEasy EU it_send (in, DATATYPE_HEEU); #endif } else { it_send (in, DATATYPE_IT); // Sending real data } //sending real data } else if (in[1] == 'r') { // Start of "Set Frequency" (f) #ifdef HAS_ASKSIN if (asksin_on) { restore_asksin = 1; asksin_on = 0; } #endif #ifdef HAS_MORITZ if (moritz_on) { restore_moritz = 1; moritz_on = 0; } #endif it_tunein (); intertechno_on = 1; } else if (in[1] == 'f') { // Set Frequency if (in[2] == '0' ) { it_frequency[0] = 0x10; it_frequency[1] = 0xb0; it_frequency[2] = 0x71; } else { fromhex (in+2, it_frequency, 3); } DC('i');DC('f');DC(':'); DH2(it_frequency[0]); DH2(it_frequency[1]); DH2(it_frequency[2]); DNL(); } else if (in[1] == 'x') { // Reset Frequency back to Eeprom value if(0) { ; #ifdef HAS_ASKSIN } else if (restore_asksin) { restore_asksin = 0; rf_asksin_init(); asksin_on = 1; ccRX(); #endif #ifdef HAS_MORITZ } else if (restore_moritz) { restore_moritz = 0; rf_moritz_init(); #endif } else { ccInitChip(EE_CC1100_CFG); // Set back to Eeprom Values if(tx_report) { // Enable RX ccRX(); } else { ccStrobe(CC1100_SIDLE); } } intertechno_on = 0; } }