Ejemplo n.º 1
0
/******************************************************************************
 * @fn          halTimer32kMcuSleepTicks
 *
 * @brief       This function uses Timer B to sleep for a specfied number of
 *              ACLK ticks, that is less than 2^15 tics(1s).
 *              Assumes that the only interrupt source is
 *              generated by Timer B.
 *
 *              NOTE: When called, this function will assign NO ISR to the
 *              TIMERB0_VECTOR interrupt(NULL pointer). When interrupt triggers
 *              it will just wake up the MCU. Conflicts are possible if not
 *              used carefully since other parts of a program might use the
 *              TIMER B.
 *
 * input parameters
 *
 * @param       ticks  - Number of ACLK(32768Hz) ticks that the MCU will sleep
 *
 * output parameters
 *
 * @return      void
 */
void halTimer32kMcuSleepTicks(uint16 ticks)
{
  halTimer32kIntConnect(NULL);
  halTimer32kInit(ticks);
  halTimer32kIntEnable();
  __low_power_mode_3();
  halTimer32kAbort();
}
Ejemplo n.º 2
0
/***********************************************************************************
* @fn          appConfigTimer
*
* @brief       Configure timer interrupts for application. Uses 32 KHz timer
*
* @param       uint16 period - Frequency of timer interrupt. This value must be
*              between 1 and 32768 Hz
*
* @return      none
*/
static void appConfigTimer(uint16 rate)
{
    halTimer32kInit(TIMER_32K_CLK_FREQ/rate);
    halTimer32kIntConnect(&appTimerISR);
}
Ejemplo n.º 3
0
int main(void)
{

#error "Hi, Currently not working, still to be tested! - I didn't find time to debug it! "

	//halIntOn();
	unsigned long pktsSent = 0;
	perConfig.mode = PER_MODE_TX;
	    perConfig.state = PER_IDLE;
	    perConfig.channel = 26;
	    perConfig.txPower = 0;          // Index 0. Max output
	    perConfig.burstSize = 1000000;  // Max value
	    perConfig.pktRate   = 20;       // 20 pkts per second
	    perConfig.gainMode = PER_GAIN_MODE_NONE; // No PA/LNA

	    //
	        // Config basicRF
	        //
	        basicRfConfig.panId = PAN_ID;
	        basicRfConfig.ackRequest = false;



	    if(basicRfInit(&basicRfConfig) == FAILED)
	    {
	    while(1);
	    }

	    basicRfReceiveOff();
	    halRfSetTxPower(0);
	   // appTimerConfig(20);
	    halTimer32kInit(32768/20);
	    halTimer32kIntConnect(&appTimerIsr);    // Connect ISR
	    halTimer32kIntEnable();                 // Enable interrupts

	    while(1)
	       {
	    	if(perConfig.state == PER_TRANSMIT)
	    	        {
	    	            if(pktsSent < perConfig.burstSize) {
	    	                //
	    	                // Make sure sequence number has network byte order
	    	                //
	    	                UINT32_HTON(tTxPacket.seqNumber);

	    	                basicRfSendPacket(RX_ADDR, (unsigned char*)&tTxPacket, PACKET_SIZE);

	    	                //
	    	                // Change byte order back to host order before increment
	    	                //
	    	                UINT32_NTOH(tTxPacket.seqNumber);

	    	                //
	    	                // Update variables
	    	                //
	    	                tTxPacket.seqNumber++;
	    	                pktsSent++;
	    	                perConfig.state = PER_PACKET_RECEIVED;

	    	                //
	    	                // Update LED
	    	                //
	    	           //     bspLedToggle(BSP_LED_1);

	    	   }
	    	            else {
	    	                //
	    	                // Done sending packets, exit TX loop
	    	                //
	    	                break;
	    	            }
	    	        }
	       }
}
/******************************************************************************   
 * @fn          trxDetectCC112xCrystal()                                     
 *                                                                                
 * @brief       This function estimates the crystal frequency if a CC112x 
 *              is detected.
 *              SPI init must be applied before this function   
 *              can be called.
 *
 * @param       none
 *          
 * @return      none
 */
static uint8 trxDetectCC112xCrystal()
{  
  // Write EXT CLOCK to IOCFG3 and IOCFG2
  uint8 writeBytes1[2] = {0x31, 0x31};
  trx8BitRegAccess(CC112X_WRITE_BURST, CC112X_IOCFG3, writeBytes1, 2);
  // set external clock divider to 32
  writeBytes1[0] = 0x00;
  trx16BitRegAccess(CC112X_WRITE_BURST,CC112X_EXT_MEM_ACCESS,CC112X_ECG_CFG,writeBytes1,1);
  
  //wait for crystal to be stable (CHIP_RDYn)
  while((trxSpiCmdStrobe(CC112X_SNOP)& 0xF0) != 0x00);
  
  //get system clock frequency
  uint32_t systemClockBak = bspSysClockSpeedGet();
  
  //set system clock frequency up to 25 MHz for accurate sampling
  bspSysClockSpeedSet(BSP_SYS_CLK_25MHZ);
  
  // initialize timerA to capture rising and falling edges on EXT CLOCK
  cc112xInitTimerA();
  
  // Setting up time out in case we hang wating for capture interrupt
  halTimer32kIntConnect(&timeOutISR);
  halTimer32kSetIntFrequency(1); // 1 sec timeout
  halTimer32kIntEnable();
  
  // wait for interrupt on timer capture or timeout
  while((!timerSemaphore) && (!timeoutSemaphore));
  
  // stop timeuot timer
  halTimer32kIntDisable();
  
  // stop timer
  disableTimerA();
 
  if(timerSemaphore)
  {
    // assuming 50% duty cycle. Period time = time between rising and
    // falling edge x 2
    capturePeriod = (captureTable[1]  - captureTable[0])*2;
  
    //check for negative number and set absolute value
    capturePeriod= (capturePeriod<0)?(0-capturePeriod):capturePeriod;
  
    // Claculate XOSC frequency in  MHz: 
    // system clock frequency / capturePeriod
    // times external clock divider (32)
    // times digital clock divider (2)
    floatingEstimate = (((25.0*32.0*2.0)/capturePeriod));
  
    //Round up/down estimated frequency and truncate to int
    xoscFreqEstimate = (uint8) (floatingEstimate + 0.5);
  }
  else
  {
    xoscFreqEstimate =  XOSC_FREQ_NONE;
  }
  
  //set system clock frequency back to standard
  bspSysClockSpeedSet(systemClockBak);
  
  //reset radio
  trxSpiCmdStrobe(CC112X_SRES);
  
  return xoscFreqEstimate;
}
/******************************************************************************   
 * @fn          trxDetectCC1101Crystal()                                    
 *                                                                                
 * @brief       This function estimates the crystal frequency if a NextGen 
 *              radio is detected.
 *              SPI init must be applied before this function   
 *              can be called.
 *
 * @param       none
 *          
 * @return      none
 */
static uint8 trxDetectCC1101Crystal()
{
  
 // Write CLOCK_XOSC/192 to GDO2
  uint8 writeByte = 0x3F;
  trx8BitRegAccess(CC1101_WRITE_BURST, CC1101_IOCFG2, &writeByte, 1);
  
  //Wait for crystal to be stable (CHIP_RDYn)
  while((trxSpiCmdStrobe(CC1101_SNOP)& 0xF0) != 0x00);
  
  //Get current system clock frequency
  uint32_t systemClockBak = bspSysClockSpeedGet();
  
  //set system clock frequency up to 25 MHz for accurate sampling
  bspSysClockSpeedSet(BSP_SYS_CLK_25MHZ);
  
  // initialize timerA to capture rising edges on CLOCK XOSC
  cc1101InitTimerA();
  
  // Setting up time out in case we hang wating for capture interrupt
  halTimer32kIntConnect(&timeOutISR);
  halTimer32kSetIntFrequency(1);  // 1 sec timeout
  halTimer32kIntEnable();
  
  // wait for interrupt on timer capture or timeout
  while((!timerSemaphore) && (!timeoutSemaphore));
  
  // stop timeuot timer
  halTimer32kIntDisable();
    
  // stop timer
  disableTimerA();
 
  if(timerSemaphore)
  {
     // assuming 50% duty cycle. Period time = time between rising and
    // falling edge x 2
    capturePeriod = (captureTable[1]  - captureTable[0])*2;
  
    //check for negative number and set absolute value
    capturePeriod= (capturePeriod<0)?(0-capturePeriod):capturePeriod;
  
    // Claculate XOSC frequency in  MHz:
    // system clock frequency / capturePeriod
    // times clock xosc divider (192)
    floatingEstimate = (((25.0*192.0)/capturePeriod));
  
    //Round up/down estimated frequency and truncate to int
    xoscFreqEstimate = (uint8) (floatingEstimate + 0.5);
  }
  else
  {
    xoscFreqEstimate =  XOSC_FREQ_NONE;
  }
  
  //set system clock frequency back to standard
  bspSysClockSpeedSet(systemClockBak);
    
  //reset radio
  trxSpiCmdStrobe(CC1101_SRES);
  
  return xoscFreqEstimate;
}