예제 #1
0
/****************************************************************************
 *
 * NAME: vModuleSetRadioFrontEnd
 *
 * DESCRIPTION:
 * Set up the module appropriately for a given radio front end
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void vModuleSetRadioFrontEnd(teRadioFrontEnd eRadioFrontEnd)
{
    if ((u8AHI_PowerStatus() & (1 << 3)) == 0)
    {
        /* Power domain is inactive - writing to the register will cause a bus exception */
        return;
    }

    switch(eRadioFrontEnd)
    {
    case (E_FRONTEND_STANDARD_POWER):
        u32AllocatedPins &= ~(3 << 2); /* DIO2 & 3 Used for Tx/Rx on High power module - mark available  */
        vLog_Printf(TRACE_BR, LOG_INFO, "\nEnable Std Power");
#if defined JENNIC_CHIP_FAMILY_JN516x
        vAppApiSetHighPowerMode(APP_API_MODULE_STD, TRUE);
#else
        vAHI_HighPowerModuleEnable(FALSE, FALSE);
#endif /* JENNIC_CHIP_FAMILY_JN516x */
        break;

    case (E_FRONTEND_HIGH_POWER):
    case (E_FRONTEND_ETSI):
        /* Pin is pulled low - High power mode selected */
        u32AllocatedPins |= 3 << 2; /* DIO2 & 3 Used for Tx/Rx on High power module - mark allocated  */
        if (u32ActivityLEDMask != ACTIVITY_LED_DISABLED)
        {
            if (u32ActivityLEDMask & (3 << 2))
            {
                /* The activity LED has already been set up as pin 2/3, disable it! */
                u32ActivityLEDMask = ACTIVITY_LED_DISABLED;
            }
        }

        vLog_Printf(TRACE_BR, LOG_INFO, "\nEnable High Power");
#if defined JENNIC_CHIP_FAMILY_JN516x
#else
        vAHI_HighPowerModuleEnable(TRUE, TRUE);
#endif /* JENNIC_CHIP_FAMILY_JN516x */

        switch(sConfig.u8Region)
        {

        case E_REGION_EUROPE:
            break;

        case E_REGION_USA:
#if defined JENNIC_CHIP_FAMILY_JN516x
#else
        	bAHI_PhyRadioSetPower(5);
#endif /* JENNIC_CHIP_FAMILY_JN516x */
            break;

        case E_REGION_JAPAN:
            break;
        }

        if (eRadioFrontEnd == E_FRONTEND_HIGH_POWER)
        {
#if defined JENNIC_CHIP_FAMILY_JN516x
        	vAppApiSetHighPowerMode(APP_API_MODULE_HPM06, TRUE);
#else
        	vAppApiSetHighPowerMode(APP_API_HPM_MODULE_M06, APP_API_HPM_MODE_FULL);
#endif /* JENNIC_CHIP_FAMILY_JN516x */

        }
        else if (eRadioFrontEnd == E_FRONTEND_ETSI)
        {
            vLog_Printf(TRACE_BR, LOG_INFO, "\nEnable ETSI");

#if defined JENNIC_CHIP_FAMILY_JN516x
            vAppApiSetHighPowerMode(APP_API_MODULE_HPM05, TRUE);
#else
            vAppApiSetHighPowerMode(APP_API_HPM_MODULE_M06, APP_API_HPM_MODE_ETSI);
#endif /* JENNIC_CHIP_FAMILY_JN516x */
        }
        {
            uint32 u32TxPower;
            /* Read then write back TX power level
             * This forces the MAC to implement the previous change.
             */
            eAppApiPlmeGet(PHY_PIB_ATTR_TX_POWER,&u32TxPower);
            eAppApiPlmeSet(PHY_PIB_ATTR_TX_POWER, u32TxPower);
        }
        break;

    default:
        break;
    }
}
예제 #2
0
파일: rxmain.c 프로젝트: ahopper/rc24
/****************************************************************************
 *
 * NAME: frameStartEvent
 *
 * DESCRIPTION: Handler for the frame start notification
 *
 * PARAMETERS:      Name            RW  Usage
 * 					buff			?	unused??
 *
 * RETURNS:
 *
 * NOTES:
 ****************************************************************************/
void frameStartEvent(void* context,void* buff)
{
	// Called every frame, currently 20ms
	frameCounter++;


	#ifdef JN5168
/*
		MAC_McpsReqRsp_s sMcpsReqRsp;
		MAC_McpsSyncCfm_s sMcpsSyncCfm;
		// Send request to remove a data frame from transaction queue
		sMcpsReqRsp.u8Type = MAC_MCPS_REQ_PURGE;
		sMcpsReqRsp.u8ParamLength = sizeof(MAC_McpsReqPurge_s);
		sMcpsReqRsp.uParam.sReqPurge.u8Handle = 1;
		vAppApiMcpsRequest(&sMcpsReqRsp, &sMcpsSyncCfm);
*/
		//reset MAC
		MAC_MlmeReqRsp_s sMlmeReqRsp;
		MAC_MlmeSyncCfm_s sMlmeSyncCfm;
		sMlmeReqRsp.u8Type = MAC_MLME_REQ_RESET;
		sMlmeReqRsp.u8ParamLength = sizeof(MAC_MlmeReqReset_s);
		sMlmeReqRsp.uParam.sReqReset.u8SetDefaultPib = FALSE;
		vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);


		uint32 newchannel = getHopChannel(getSeqClock());


		eAppApiPlmeSet(PHY_PIB_ATTR_CURRENT_CHANNEL, newchannel);
	#endif

	if(frameReceived==FALSE)
	{
		RX.missedFrames++;
	}
	else
	{
		RX.missedFrames=0;
	}

	//used instead of sequence number to prevent handling the same frame twice
	frameReceived=FALSE;

	// Binding check
	// Only do automatic bind request after 10secs incase this
	// was an unintended reboot in flight.
	// Only do if not already communicating with a tx
	if ((frameCounter > 500 && frameCounter < 5000) &&
		getHopMode() == hoppingRxStartup)
	{
		// TODO - add binding button check and an option to disable auto binding
		uint32 channel = 0;
		eAppApiPlmeGet(PHY_PIB_ATTR_CURRENT_CHANNEL, &channel);
		if (channel == 11)
		{
			// TODO - Get rid of magic numbers
			uint8 packet[14];
			packet[0] = 0; //no high priority data
			packet[1] = 0; //seq no
			packet[2] = 0; //chunk no
			packet[3] = 10; //length of message
			packet[4] = 0; //no route
			packet[5] = 16; //bind request

			module_MAC_ExtAddr_s* macptr = (module_MAC_ExtAddr_s*)pvAppApiGetMacAddrLocation();

			// TODO - can't we just memcpy the whole thing in one call?
			memcpy(&packet[6], &macptr->u32L, sizeof(macptr->u32L));
			memcpy(&packet[10], &macptr->u32H, sizeof(macptr->u32H));

			vTransmitDataPacket(packet, sizeof(packet), TRUE);
		}

		// Set the flash rate to fast to indicate binding attempts
		rxLEDFlashLimit = LED_FLASH_FAST;
	}

	// LED Flasher to indicate binding state.
	if ((getHopMode() == hoppingContinuous) && !rxLEDState)
	{
		// We have bound, set the LED on
		rxLEDState = TRUE;
		vAHI_DioSetOutput(rxHardware.ledBit, 0);
	}
	else
	{
		if (frameCounter > 5000)
			// We have timed out
			rxLEDFlashLimit = LED_FLASH_SLOW;

		// If the count exceeds the current limit, toggle the LED state
		if (++rxLEDFlashCount > rxLEDFlashLimit)
		{
			// Toggle the state flag
			rxLEDState = !rxLEDState;

			// Set the output accordingly
			if (rxLEDState)
				vAHI_DioSetOutput(rxHardware.ledBit, 0);
			else
				vAHI_DioSetOutput(0, rxHardware.ledBit);

			// Reset the counter for the next cycle
			rxLEDFlashCount = 0;
		}
	}

}