//-------------------------------------------------------------------- void cc_factory_reset(void) { uint8_t *t = EE_CC1100_CFG; for(uint8_t i = 0; i < sizeof(CC1100_CFG); i++) ewb(t++, __LPM(CC1100_CFG+i)); #if defined(HAS_FASTRF) || defined(HAS_RF_ROUTER) t = EE_FASTRF_CFG; for(uint8_t i = 0; i < sizeof(FASTRF_CFG); i++) ewb(t++, __LPM(FASTRF_CFG+i)); #endif #ifdef MULTI_FREQ_DEVICE // check 433MHz version marker and patch default frequency if (!bit_is_set(MARK433_PIN, MARK433_BIT)) { t = EE_CC1100_CFG + 0x0d; ewb(t++, 0x10); ewb(t++, 0xb0); ewb(t++, 0x71); #if defined(HAS_FASTRF) || defined(HAS_RF_ROUTER) t = EE_FASTRF_CFG + 0x0d; ewb(t++, 0x10); ewb(t++, 0xb0); ewb(t++, 0x71); #endif } #endif cc_set_pa(8); }
void cc_set_pa(uint8_t idx) { uint8_t *t = EE_CC1100_PA; if(idx > 9) idx = 8; #ifdef FULL_CC1100_PA const uint8_t *f = CC1100_PA+idx*8; for (uint8_t i = 0; i < 8; i++) ewb(t++, __LPM(f+i)); // Correct the FREND0 ewb(EE_CC1100_CFG+0x22, (idx > 4 && idx < 10) ? 0x11 : 0x17); #else if(idx > 4) idx -= 5; for (uint8_t i = 0; i < 8; i++) ewb(t++, i == 1 ? __LPM(CC1100_PA+idx) : 0); #endif }
static void it_tunein(void) { int8_t i; #ifdef ARM AT91C_BASE_AIC->AIC_IDCR = 1 << AT91C_ID_PIOA; // disable INT - we'll poll... AT91C_BASE_PIOA->PIO_PPUER = _BV(CC1100_CS_PIN); //Enable pullup AT91C_BASE_PIOA->PIO_OER = _BV(CC1100_CS_PIN); //Enable output AT91C_BASE_PIOA->PIO_PER = _BV(CC1100_CS_PIN); //Enable PIO control #else EIMSK &= ~_BV(CC1100_INT); SET_BIT( CC1100_CS_DDR, CC1100_CS_PIN ); // CS as output #endif CC1100_DEASSERT; // Toggle chip select signal my_delay_us(30); CC1100_ASSERT; my_delay_us(30); CC1100_DEASSERT; my_delay_us(45); ccStrobe( CC1100_SRES ); // Send SRES command my_delay_us(100); CC1100_ASSERT; // load configuration cc1100_sendbyte( 0 | CC1100_WRITE_BURST ); for(uint8_t i = 0; i < 13; i++) { cc1100_sendbyte(__LPM(CC1100_ITCFG+i)); } // Tune to standard IT-Frequency cc1100_sendbyte(it_frequency[0]); // Modify Freq. for 433.92MHZ, or whatever cc1100_sendbyte(it_frequency[1]); cc1100_sendbyte(it_frequency[2]); for (i = 16; i<EE_CC1100_CFG_SIZE; i++) { cc1100_sendbyte(__LPM(CC1100_ITCFG+i)); } CC1100_DEASSERT; uint8_t *pa = EE_CC1100_PA; CC1100_ASSERT; // setup PA table cc1100_sendbyte( CC1100_PATABLE | CC1100_WRITE_BURST ); for (uint8_t i = 0;i<8;i++) { cc1100_sendbyte(erb(pa++)); } CC1100_DEASSERT; ccStrobe( CC1100_SCAL ); my_delay_ms(1); cc_on = 1; // Set CC_ON }
void it_tunein(void) { int8_t i; #ifdef USE_HAL hal_CC_GDO_init(CC_INSTANCE,INIT_MODE_OUT_CS_IN); hal_enable_CC_GDOin_int(CC_INSTANCE,FALSE); // disable INT - we'll poll... #else EIMSK &= ~_BV(CC1100_INT); SET_BIT( CC1100_CS_DDR, CC1100_CS_PIN ); // CS as output #endif CC1100_DEASSERT; // Toggle chip select signal my_delay_us(30); CC1100_ASSERT; my_delay_us(30); CC1100_DEASSERT; my_delay_us(45); ccStrobe( CC1100_SRES ); // Send SRES command my_delay_us(100); CC1100_ASSERT; // load configuration cc1100_sendbyte( 0 | CC1100_WRITE_BURST ); for(uint8_t i = 0; i < 13; i++) { cc1100_sendbyte(__LPM(CC1100_ITCFG+i)); } // Tune to standard IT-Frequency cc1100_sendbyte(it_frequency[0]); // Modify Freq. for 433.92MHZ, or whatever cc1100_sendbyte(it_frequency[1]); cc1100_sendbyte(it_frequency[2]); for (i = 16; i<EE_CC1100_CFG_SIZE; i++) { cc1100_sendbyte(__LPM(CC1100_ITCFG+i)); } CC1100_DEASSERT; uint8_t *pa = EE_CC1100_PA; CC1100_ASSERT; // setup PA table cc1100_sendbyte( CC1100_PATABLE | CC1100_WRITE_BURST ); for (uint8_t i = 0;i<8;i++) { cc1100_sendbyte(erb(pa++)); } CC1100_DEASSERT; ccStrobe( CC1100_SCAL ); my_delay_ms(1); #ifndef USE_RF_MODE cc_on = 1; // Set CC_ON #endif }
//--------------------------------------------------------------------------- void SndStepScore(void) { for(;;) { u8 cmd = __LPM(Snd.pScoreCur++); u8 op = cmd & 0xf0; u8 ch = cmd & 0x0f; switch(op) { case SND_OP_PLAY_NOTE: SndPlayNote(ch, __LPM(Snd.pScoreCur++)); break; case SND_OP_STOP_NOTE: SndStopNote(ch); break; case SND_OP_RESTART: Snd.pScoreCur = Snd.pScoreStart; break; case SND_OP_STOP: SndStopScore(); return; default: // wait count in msec. if(op < 0x80) { u16 duration = ((u16)cmd << 8) | __LPM(Snd.pScoreCur++); Snd.scoreCnt = ((u32)Snd.scoreFreqCnt * duration + 500) / 1000; if(Snd.scoreCnt == 0) { Snd.scoreCnt = 1; } return; } SystemError("[Snd %x %x]", cmd, Snd.pScoreCur - Snd.pScoreStart); } } // for(;;) }
void display_string_P(prog_char *s) { uint8_t c; while((c = __LPM(s))) { display_char(c); s++; } }
// see CC1101 documentation, chapter 29, p. 82 void ccSetConfig(void) { CC1100_SPI_BEGIN; // upload configuration ccSpiSend(0 | CC1100_WRITE_BURST); for(uint8_t i= 0; i< CC1100_CONFIG_SIZE_W; i++) { ccSpiSend(__LPM(CC1100_CFG+i)); } CC1100_SPI_END; }
//--------------------------------------------------------------------------- void AstSetUnit(u8 num, s8 x, s8 y, u8 type, u8 step) { ST_AST_DATA* p = &Ast.d[num]; p->fx = NUM2FIX(x); p->fy = NUM2FIX(y); p->fmx = (Rnd((1 + Ast.wave + step) * 4) + (1 + Ast.wave) * 2) * (RndIsBool() == TRUE ? 1 : -1); p->fmy = (Rnd((1 + Ast.wave + step) * 4) + (1 + Ast.wave) * 2) * (RndIsBool() == TRUE ? 1 : -1); p->type = type; p->step = step; p->r = (s8)__LPM(AstRadiusTable + step); p->isUse = TRUE; Ast.cnt++; }
uint8_t callfn(char *buf) { for(uint8_t idx = 0; ; idx++) { uint8_t n = __LPM(&fntab[idx].name); void (*fn)(char *) = (void (*)(char *))__LPM_word(&fntab[idx].fn); if(!n) break; if(buf == 0) { DC(' '); DC(n); } else if(buf[0] == n) { fn(buf); return 1; } } return 0; }
void fht_hook(uint8_t *fht_in) { uint8_t fi0 = fht_in[0]; // Makes code 18 bytes smaller... uint8_t fi1 = fht_in[1]; uint8_t fi2 = fht_in[2]; // FHT Command with extension bit uint8_t fi3 = fht_in[3]; // Originator: CUL or FHT uint8_t fi4 = fht_in[4]; // Command Argument #ifdef FHTDEBUG fht_display_buf(fht_in); #endif fht80b_timeout = 95; // Wait 0.76s (second can-rcv) for reply fht80b_repeatcnt = 0; // but do not send anything per default if(fht_hc0 == 0 && fht_hc1 == 0) // FHT processing is off return; if(fht80b_out[0] != fi0 || // A different FHT is sending data fht80b_out[1] != fi1) { fht80b_reset_state(); fht80b_out[0] = fi0; fht80b_out[1] = fi1; } if(fht80b_state == FHT_FOREIGN) // This is not our FHT, forget it return; uint8_t inb, outb; fht80b_out[2] = fi2; // copy the in buffer as it cannot fht80b_out[3] = fi3; // be used for sending it out again fht80b_out[4] = fi4; ////////////////////////////// // FHT->CUL part: ack everything. if(fi2 && fht80b_state == 0) { if(fi4 != fht_hc0 && // Foreign (not our) FHT/FHZ, forget it fi4 != 100 && // not the unassigned one (fi2 == FHT_CAN_XMIT || // FHZ start seq fi2 == FHT_CAN_RCV || // FHZ start seq? fi2 == FHT_START_XMIT)) { // FHT start seq fht80b_state = FHT_FOREIGN; return; } // Setting fht80b_out[4] to our housecode for FHT_CAN_RCV & FHT_START_XMIT // won't change the FHT pairing if(fi2 == FHT_CAN_RCV) return; if((fi3 & 0xf0) == 0x60) { // Ack only 0x6? packets, else we get fht80b_out[3] = fi3|0x70; // strange "endless" loops when other fht80b_send_repeated(); // CUL's / FHT's are involved } return; } ////////////////////////////// // CUL->FHT part if(!fht_getbuf(fht80b_out) && fht80b_state == 0) return; // What is the FHT80 supposed to send? inb = (fht80b_ldata ? fht80b_ldata : __LPM(fht80b_state_tbl+fht80b_state)); // We frequently loose the FHT_CAN_XMIT msg from the FHT // so skip this state if the next msg comes in. if(inb == FHT_CAN_XMIT && fi2 == FHT_CAN_RCV) { inb = FHT_CAN_RCV; fht80b_state += 2; } // Ack-Check: correct ack from the FHT? if(inb != fi2) { fht80b_reset_state(); return; } outb = 0; // What should the CUL send back? if(fht80b_ldata) { fht80b_bufoff += 2; if(fht_getbuf(fht80b_out)) { // Search for next outb = FHT_DATA; } else { fht80b_state+=2; } } if(!outb) outb = __LPM(fht80b_state_tbl+fht80b_state+1); if(outb == FHT_DATA) { fht80b_ldata = fht80b_out[2]; if(fht80b_ldata == FHT_MINUTE) // Adjust the minute offset... fht80b_out[4] = fht80b_minute; } else { // Follow the protocol table fht80b_out[2] = outb; fht80b_out[3] = 0x77; fht80b_out[4] = fht_hc0; fht80b_state += 2; fht80b_ldata = 0; if(fht80b_state == sizeof(fht80b_state_tbl)) { // If we delete the buffer earlier, and our conversation aborts, then the // FHT will send every 10 minutes from here on a can_rcv telegram, and // will stop sending temperature messages fht_delbuf(fht80b_out); fht80b_reset_state(); } } if(outb) fht80b_send_repeated(); }
void kopp_fc_init(void) { #ifdef ARM AT91C_BASE_AIC->AIC_IDCR = 1 << CC1100_IN_PIO_ID; // disable INT - we'll poll... CC1100_CS_BASE->PIO_PPUER = _BV(CC1100_CS_PIN); //Enable pullup CC1100_CS_BASE->PIO_OER = _BV(CC1100_CS_PIN); //Enable output CC1100_CS_BASE->PIO_PER = _BV(CC1100_CS_PIN); //Enable PIO control #else EIMSK &= ~_BV(CC1100_INT); // disable INT - we'll poll... SET_BIT( CC1100_CS_DDR, CC1100_CS_PIN ); // CS as output #endif // Toggle chip select signal (why?) CC1100_DEASSERT; // Chip Select InActiv my_delay_us(30); CC1100_ASSERT; // Chip Select Activ my_delay_us(30); CC1100_DEASSERT; // Chip Select InActiv my_delay_us(45); ccStrobe( CC1100_SRES ); // Send SRES command (Reset CC110x) my_delay_us(100); // load configuration (CC1100_Kopp_CFG[EE_CC1100_CFG_SIZE]) CC1100_ASSERT; // Chip Select Activ cc1100_sendbyte( 0 | CC1100_WRITE_BURST ); for(uint8_t i = 0; i < EE_CC1100_CFG_SIZE; i++) { cc1100_sendbyte(__LPM(CC1100_Kopp_CFG+i)); } CC1100_DEASSERT; // Chip Select InActiv // If I don't missunderstand the code, in module cc1100.c the pa table is defined as // 00 and C2 what means power off and max. power. // so following code (setup PA table) is not needed ? // did a trial, but does not work // setup PA table (-> Remove as soon as transmitting ok?), table see cc1100.c // this initializes the PA table with the table defined at EE_Prom // which table will be taken depends on command "x00 .... x09" // x00 means -10dbm pa ramping // x09 means +10dBm no pa ramping (see cc1100.c) and commandref.html #ifdef PrintOn // DS_P(PSTR("PA Table values: ")); #endif uint8_t *pa = EE_CC1100_PA; // EE_CC1100_PA+32 means max power??? CC1100_ASSERT; cc1100_sendbyte( CC1100_PATABLE | CC1100_WRITE_BURST); for (uint8_t i = 0; i < 8; i++) { #ifdef PrintOn // DU(erb(pa),0); // ### Claus, mal sehen was im PA Table steht DS_P(PSTR(" ")); #endif cc1100_sendbyte(erb(pa++)); // fncollection.c "erb()"gibt einen EEPROM Wert zurück } #ifdef PrintOn DS_P(PSTR("\r\n")); #endif CC1100_DEASSERT; // Set CC_ON ccStrobe( CC1100_SCAL); // Calibrate Synthesizer and turn it of. ##Claus brauchen wir das my_delay_ms(1); cc_on = 1; kopp_fc_on = 1; //##Claus may be not needed in future (Tx Only) checkFrequency(); }
void KAUart::SendPgmData(unsigned Adress, size_t Size) { while (Size--) Send(__LPM(Adress++)); }
void KAUart::SendPgmString(unsigned Adress) { while (char c = __LPM(Adress++)) Send(c); }
void KAUart::SendPgmChar(unsigned Adress) { Send(__LPM(Adress)); }
//--------------------------------------------------------------------------- s8 MathCos(u8 deg) { return __LPM(MathSinTable + ((deg + 192) & 0xff)); }
//--------------------------------------------------------------------------- s8 MathSin(u8 deg) { return __LPM(MathSinTable + (deg & 0xff)); }