uint32_t IEEE802154::init(uint16_t panid)
{
	IEEE802154_DBG_FUNC_ENTER();

	void *pvMac;
	uint32_t version;

	version = u32AppApiInit(MlmeDcfmIndGetBuf, MlmeDcfmIndPost, this,
			        McpsDcfmIndGetBuf, McpsDcfmIndPost, this);
	IEEE802154_DBG_PRINTLN("pvAppApiGetMacHandle");
	pvMac = pvAppApiGetMacHandle();

	IEEE802154_DBG_PRINTLN("MAC_psPibGetHandle");
	(void)MAC_psPibGetHandle(pvMac);

	IEEE802154_DBG_PRINTF("MAC_vPibSetPanId: 0x%x", panid);
	IEEE802154_DBG_PRINTLN("");
	
	MAC_vPibSetPanId(pvMac, panid);
	
	/* Enable receiver to be on when idle */
	IEEE802154_DBG_PRINTLN("MAC_vPibSetRxOnWhenIdle");
	MAC_vPibSetRxOnWhenIdle(pvMac, 1, FALSE);

	return version;
}
示例#2
0
/****************************************************************************
 *
 * NAME: vAppMain
 *
 * DESCRIPTION:
 * Entry point for application from a cold start.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void vAppMain(void)
{

    /* Initialise the debug diagnostics module to use UART0 at 115K Baud;
     * UART 1 cannot be used as it shares DIO with the LEDS */
    DBG_vUartInit(DBG_E_UART_0, DBG_E_UART_BAUD_RATE_115200);

    /*
     * 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.
     */
    if (bAHI_WatchdogResetEvent())
    {
        DBG_vPrintf(TRACE_APP, "APP: Watchdog timer has reset device!\n");
        /* un-comment to trap watchdog resets here */
        //vAHI_WatchdogStop();
        //while (1);
    }

    /* initialise ROM based software modules */
    u32AppApiInit(NULL, NULL, NULL, NULL, NULL, NULL);

    /* Un-comment this line in order to enable high power module */
    //vAHI_HighPowerModuleEnable(TRUE, TRUE);

    /* start the RTOS */
    OS_vStart(vInitialiseApp, vUnclaimedInterrupt);

    /* 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. APP_bAppHealthy is a belt-and-braces check
         * on correct application functionality and is a flag set by the main sensor task.
         */
        if (APP_bAppHealthy)
        {
            vAHI_WatchdogRestart();
            APP_bAppHealthy = FALSE;
        }

        /*
         * suspends CPU operation when the system is idle or puts the device to
         * sleep if there are no activities in progress
         */
        PWRM_vManagePower();
    }
}
示例#3
0
/****************************************************************************
 *
 * NAME:       bAppQApiInit
 *
 * DESCRIPTION:
 * Initialised the Application Queue API, Application API and stack. Creates
 * the queues used for passing information up to the application and fills
 * the 'spare buffers' queues with the spare buffer entries. Also registers
 * the callback handlers with the Application API layer so all upward
 * information comes through this module.
 *
 * PARAMETERS: Name            RW  Usage
 *             prMlmeCallback  R   Optional callback when MLME received
 *             prMcpsCallback  R   Optional callback when MCPS received
 *             prHwCallback    R   Optional callback when HW int received
 *
 * RETURNS:
 * TRUE if initialisation was successful
 *
 ****************************************************************************/
PUBLIC uint32 u32AppQApiInit(PR_QIND_CALLBACK prMlmeCallback,
                             PR_QMCPS_CALLBACK prMcpsCallback,
                             PR_HWQINT_CALLBACK prHwCallback)
{
    int i;

    /* Initialise 'spare buffers' queues and fill with spare buffers */
    vFifoInit(&sMlmeIndBufferQueue, apvMlmeIndBufferData, APP_MAX_MLME_IND);
    for (i = 0; i < APP_MAX_MLME_IND; i++)
    {
        bFifoPush(&sMlmeIndBufferQueue, (void *)&asMlmeIndBuffer[i]);
    }

    vFifoInit(&sMcpsIndBufferQueue, apvMcpsIndBufferData, APP_MAX_MCPS_IND);
    for (i = 0; i < APP_MAX_MCPS_IND; i++)
    {
        bFifoPush(&sMcpsIndBufferQueue, (void *)&asMcpsIndBuffer[i]);
    }

    vFifoInit(&sHwIndBufferQueue, apvHwIndBufferData, APP_MAX_HW_IND);
    for (i = 0; i < APP_MAX_HW_IND; i++)
    {
        bFifoPush(&sHwIndBufferQueue, (void *)&asHwIndBuffer[i]);
    }

    /* Initialise 'used buffers' queues */
    vFifoInit(&sMlmeIndQueue, apvMlmeIndData, APP_MAX_MLME_IND);
    vFifoInit(&sMcpsIndQueue, apvMcpsIndData, APP_MAX_MCPS_IND);
    vFifoInit(&sHwIndQueue,   apvHwIndData,   APP_MAX_HW_IND);

    /* Store callbacks */
    prAppMlmeCallback = prMlmeCallback;
    prAppMcpsCallback = prMcpsCallback;
    prAppHwCallback = prHwCallback;

    /* Register peripheral callbacks */
    vAHI_SysCtrlRegisterCallback(vAppQApiPostHwInt);
    vAHI_APRegisterCallback(vAppQApiPostHwInt);
#ifndef GDB
    vAHI_Uart0RegisterCallback(vAppQApiPostHwInt);
#endif
    vAHI_Uart1RegisterCallback(vAppQApiPostHwInt);
    vAHI_TickTimerInit(vAppQApiPostHwInt);
    vAHI_SpiRegisterCallback(vAppQApiPostHwInt);
    vAHI_SiRegisterCallback(vAppQApiPostHwInt);
    vAHI_Timer0RegisterCallback(vAppQApiPostHwInt);
    vAHI_Timer1RegisterCallback(vAppQApiPostHwInt);

    /* Register this layer with AppApi layer */
    return u32AppApiInit(psAppQApiGetMlmeBuffer, vAppQApiPostMlme, NULL,
                         psAppQApiGetMcpsBuffer, vAppQApiPostMcps, NULL);
}
示例#4
0
void
ieee_init()
{
  void *mac;
  MAC_Pib_s *pib;

  if (process_is_running(&ieee_process))
    return;

  /* initialize ieee_eventhandler and event queue*/
  rxq_init();

  /* setup mac <-> app interface */
  u32AppApiInit((PR_GET_BUFFER) rxq_mlme_alloc, (PR_POST_CALLBACK) ieee_process_poll, NULL,
                (PR_GET_BUFFER) rxq_mcps_alloc, (PR_POST_CALLBACK) ieee_process_poll, NULL);

  /* get mac and pib handles */
  mac   = pvAppApiGetMacHandle();
  pib   = MAC_psPibGetHandle(mac);

  /* do a full reset */
  req_reset(true);

  /* set panid and default parameters */
  MAC_vPibSetPanId(mac, IEEE802154_PANDID);
  MAC_vPibSetRxOnWhenIdle(mac, true, false);

  /* allocate an event for this process */
  ieee_event = process_alloc_event();
  pib->bAutoRequest = true;

  /* bandwidth control, smaller interframe gap and higher data rate,
   * this is not standard conform! */
#if defined(__BA2__) && defined(JENNIC_CONF_JN5148_FASTDATARATE)
  vAHI_BbcSetHigherDataRate(E_AHI_BBC_CTRL_DATA_RATE_1_MBPS);
  vAHI_BbcSetInterFrameGap(48);
#endif

  process_start(&ieee_process, NULL);
}
示例#5
0
int
start_sniffer(int channel) {
    void      *mac;
    MAC_Pib_s *pib;
    int res;

    rxq_init();

    /* setup mac <-> app interface */
    u32AppApiInit((PR_GET_BUFFER) rxq_mlme_alloc, (PR_POST_CALLBACK) dummy, NULL,
                  (PR_GET_BUFFER) rxq_mcps_alloc, (PR_POST_CALLBACK) dummy, NULL);

    /* get mac and pib handles */
    mac   = pvAppApiGetMacHandle();
    pib   = MAC_psPibGetHandle(mac);

    /* do a full reset */
    req_reset(true);
    MAC_vPibSetShortAddr(mac, 0x0001);
    MAC_vPibSetPromiscuousMode(mac, true, true);
    res = req_start(channel, true);
    MAC_vPibSetPromiscuousMode(mac, true, false);
    return res;
}
/****************************************************************************
 *
 * 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, "?");
    }
}
示例#7
0
/****************************************************************************
 *
 * NAME: vAppMain
 *
 * DESCRIPTION:
 * Entry point for application from a cold start.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void vAppMain(void)
{
	#ifdef DBG_ENABLE
		dbg_vPatchInit();
	#endif
    os_vPatchInit();

	/* Debug */
	DBG_vUartInit(DBG_E_UART_1, DBG_E_UART_BAUD_RATE_115200);
	vAHI_UartSetRTSCTS(DBG_E_UART_1, FALSE);
	DBG_vPrintf(RTR_TRACE, "\n%d RTR  < vAppMain()", NODE_sData.u32Timer);

	/* Initialise and turn on LEDs */
	vLedInitRfd();
	vLedControl(0, TRUE);
	vLedControl(1, TRUE);

	/* Initialise buttons */
	vButtonInitRfd();

	/* Watchdog ? */
	#if NODE_FUNC_WATCHDOG
	{
		DBG_vPrintf(RTR_TRACE, " Stack low water mark = %08x", &stack_low_water_mark);
		*(volatile uint32 *)0x020010e0 = ((uint32)&stack_low_water_mark) | 0x8000000;

		if ((*(volatile uint32 *)0x02000004) & 0x80 )
		{
			DBG_vPrintf(RTR_TRACE, " Watchdog timer has reset device!");
			vAHI_WatchdogStop();
			while(1);
		}
   	}
   	#else
   	{
	    /* Don't use watchdog */
    	vAHI_WatchdogStop();
   	}
   	#endif

	/* Initialise application API */
	u32AppApiInit(NULL, NULL, NULL, NULL, NULL, NULL);

	/* Start OS */
    OS_vStart(RTR_vInit, RTR_vUncInt);

	/* Turn off LEDs */
	vLedControl(0, FALSE);
	vLedControl(1, FALSE);

	/* Idle task commences on exit from OS start call */
    while (TRUE)
    {
		/* Watchdog ? */
		#if NODE_FUNC_WATCHDOG
		{
			/* Restart watchdog */
        	vAHI_WatchdogRestart();
        }
        #endif

        /* Manage power */
        PWRM_vManagePower();
    }
}