Example #1
0
/****************************************************************************
 *
 * NAME: vInitSystem
 *
 * DESCRIPTION: Initialise the radio system
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vInitSystem(void)
{
	// Setup interface to MAC
	(void) u32AHI_Init();
	(void) u32AppQApiInit(NULL,mcpsCallback , NULL);


	loadSettings();


	if (useHighPowerModule == TRUE)
	{
		//max power for europe including antenna gain is 10dBm
		// TODO see if we can use more power as rx antenna is lower gain
		//??? boost is +2.5 ant is 1 and power set to 4 = 7.5 ????
		vAHI_HighPowerModuleEnable(TRUE, TRUE);
#ifdef JN5168
		eAppApiPlmeSet(PHY_PIB_ATTR_TX_POWER, 34+10*2);
#else
		bAHI_PhyRadioSetPower(2);
#endif
	}
	// Initialise end device state
	sEndDeviceData.eState = E_STATE_IDLE;
	sEndDeviceData.u8TxPacketSeqNb = 0;
	sEndDeviceData.u8RxPacketSeqNb = 0;
	sEndDeviceData.u8ChannelSeqNo = 0;

	// Set up the MAC handles. Must be called AFTER u32AppQApiInit()
	s_pvMac = pvAppApiGetMacHandle();
	s_psMacPib = MAC_psPibGetHandle(s_pvMac);

	// Set Pan ID in PIB (also sets match register in hardware)
	MAC_vPibSetPanId(s_pvMac, PAN_ID);

	// Enable receiver to be on when idle
	MAC_vPibSetRxOnWhenIdle(s_pvMac, TRUE, FALSE);

	// sometimes useful during development
	// all messages are passed up from lower levels
	// MAC_vPibSetPromiscuousMode(s_pvMac, TRUE, FALSE);


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

	//moved to after u32AHI_Init() for jn5148
	randomizeHopSequence(((uint32) macptr->u32H) ^ ((uint32) macptr->u32L));

#if (defined JN5148 || defined JN5168)
	/* Enable TOF ranging. */
//	vAppApiTofInit(TRUE);
#endif

}
Example #2
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;
    }
}
/****************************************************************************
 *
 * NAME: vAppMain
 *
 * DESCRIPTION:
 * Entry point for application from a cold start.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void vAppMain(void)
{
    #if JENNIC_CHIP_FAMILY == JN516x
        /* Wait until FALSE i.e. on XTAL  - otherwise uart data will be at wrong speed */
         while (bAHI_GetClkSource() == TRUE);
         /* Now we are running on the XTAL, optimise the flash memory wait states */
         vAHI_OptimiseWaitStates();
    #endif

    /*
     * Don't use RTS/CTS pins on UART0 as they are used for buttons
     * */
    vAHI_UartSetRTSCTS(E_AHI_UART_0, FALSE);

    /*
     * Initialize the debug diagnostics module to use UART0 at 115K Baud;
     * Do not use UART 1 if LEDs are used, as it shares DIO with the LEDS
     * */
    DBG_vUartInit(DBG_E_UART_0, DBG_E_UART_BAUD_RATE_115200);
    DBG_vPrintf(TRACE_START, "\nAPP Start: Switch Power Up");


    /*
     * Initialise the stack overflow exception to trigger if the end of the
     * stack is reached. See the linker command file to adjust the allocated
     * stack size.
     */
    vAHI_SetStackOverflow(TRUE, (uint32)&_stack_low_water_mark);


    /*
     * Catch resets due to watchdog timer expiry. Comment out to harden code.
     */
    if (bAHI_WatchdogResetEvent())
    {
        DBG_vPrintf(TRACE_START, "\nAPP Start: Watchdog timer has reset device!");
        DBG_vDumpStack();
        #if HALT_ON_EXCEPTION
            vAHI_WatchdogStop();
            while (1);
        #endif
    }

    /* initialise ROM based software modules */
    #ifndef JENNIC_MAC_MiniMacShim
    u32AppApiInit(NULL, NULL, NULL, NULL, NULL, NULL);
    #endif

    /* Define HIGH_POWER_ENABLE to enable high power module */
    #ifdef HIGH_POWER_ENABLE
        vAHI_HighPowerModuleEnable(TRUE, TRUE);
    #endif

    /* start the RTOS */
    OS_vStart(vInitialiseApp, vUnclaimedInterrupt, vOSError);
    DBG_vPrintf(TRACE_START, "OS started\n");

    /* idle task commences here */
    while (TRUE)
    {
        /* Re-load the watch-dog timer. Execution must return through the idle
         * task before the CPU is suspended by the power manager. This ensures
         * that at least one task / ISR has executed with in the watchdog period
         * otherwise the system will be reset.
         */
    	DBG_vPrintf(TRACE_START, "#");
        vAHI_WatchdogRestart();

        /*
         * suspends CPU operation when the system is idle or puts the device to
         * sleep if there are no activities in progress
         */
        PWRM_vManagePower();
        DBG_vPrintf(TRACE_START, "?");
    }
}