/*******************************************************************************//** * configures CC2420 **********************************************************************************/ void CC2420_Configure(void) { uint16_t Val; // disable hardware MAC operations Val = CC2420_ReadRegister(CC2420_MDMCTRL0); #ifdef PHY_LAYER_HANDLE_CHECKSUM Val &= ~((1<<CC2420_MDMCTRL0_PAN_COORDINATOR)|(1<<CC2420_MDMCTRL0_ADR_DECODE)|(1<<CC2420_MDMCTRL0_AUTOACK)); Val |= (1<<CC2420_MDMCTRL0_AUTOCRC); #else Val &= ~((1<<CC2420_MDMCTRL0_PAN_COORDINATOR)|(1<<CC2420_MDMCTRL0_ADR_DECODE)|(1<<CC2420_MDMCTRL0_AUTOCRC)|(1<<CC2420_MDMCTRL0_AUTOACK)); #endif CC2420_WriteRegister(CC2420_MDMCTRL0,Val); // disable hardware security operations Val = CC2420_ReadRegister(CC2420_SECCTRL0); Val &= ~((1<<CC2420_SECCTRL0_RXFIFO_PROTECTION)|(1<<CC2420_SECCTRL0_SEC_MODE_1)|(1<<CC2420_SECCTRL0_SEC_MODE_0)); CC2420_WriteRegister(CC2420_SECCTRL0,Val); // set FIFOP THR value to 127 Val = CC2420_ReadRegister(CC2420_IOCFG0); Val |= 0x007F; CC2420_WriteRegister(CC2420_IOCFG0,Val); }
void CC2420_SetPANId(uint8 *panid) { uint16 temp; if ((panid[0] == 0xff) && (panid[1] == 0xff)) { temp = CC2420_ReadRegister(CC2420_IOCFG0); CC2420_WriteRegister(CC2420_IOCFG0, (temp | 0x0800)); } else{ temp = CC2420_ReadRegister(CC2420_IOCFG0); CC2420_WriteRegister(CC2420_IOCFG0, (temp & 0xf7ff)); } temp = CC2420_ReadRegister(CC2420_IOCFG0); CC2420_WriteRam(CC2420_RAM_PANID, 2, panid); }
/************************************************ * set the physical communication channel. * the value wrotten to FSCTRL.FREQ[9:0] is: * FSCTRL.FREQ = 357 + 5 (k-11) * * input: channel number in [11,26] * return: described in PHY layer. depends ************************************************/ void CC2420_SetChannel(uint8 channel) { uint16 temp; temp = CC2420_ReadRegister(CC2420_FSCTRL); temp = ((temp & 0xfc00) | (357+5*(channel - 11))); CC2420_WriteRegister(CC2420_FSCTRL, temp); }
void CC2420_SetAddressRecognition(BOOL flag) { uint16 temp; temp = CC2420_ReadRegister(CC2420_MDMCTRL0); if (flag) CC2420_WriteRegister(CC2420_MDMCTRL0, (temp | 0x0800)); else CC2420_WriteRegister(CC2420_MDMCTRL0, (temp & 0xf7ff)); }
void CC2420_SetCoordinator(BOOL flag) { uint16 temp; temp = CC2420_ReadRegister(CC2420_MDMCTRL0); if (flag)//Coordinator and Auto Ack CC2420_WriteRegister(CC2420_MDMCTRL0, (temp | 0x1010)); else //other device type and Auto Ack CC2420_WriteRegister(CC2420_MDMCTRL0, (temp | 0x0010)); }
uint8 CC2420_GetCCAMode() { return (CC2420_ReadRegister(CC2420_MDMCTRL0) & 0x00c0)>>6; }
void CC2420_SetCCAMode(uint8 mode) { uint16 temp; temp = CC2420_ReadRegister(CC2420_MDMCTRL0); CC2420_WriteRegister(CC2420_MDMCTRL0, ((temp & 0xff3f) | (mode<<6))); }
uint8 CC2420_GetTxPower() { return (CC2420_ReadRegister(CC2420_TXCTRL) & 0x1f); }
void CC2420_SetTxPower(uint8 power) { uint16 temp; temp = CC2420_ReadRegister(CC2420_TXCTRL); CC2420_WriteRegister(CC2420_TXCTRL, ((temp & 0xffe0) | power)); }
uint8 CC2420_GetChannel() { uint8 temp; temp = ((CC2420_ReadRegister(CC2420_FSCTRL) & 0x03ff) - 357)/5 + 11; return temp; }