Exemplo n.º 1
0
/****************************************************************************
 *
 * NAME: MibNodeControl_vSecond
 *
 * DESCRIPTION:
 * Timing function
 *
 ****************************************************************************/
PUBLIC void MibNodeControl_vSecond(void)
{
	/* Counting down to factory reset ? */
	if (psMibNodeControl->sTemp.u16FactoryReset > 0)
	{
		/* Decrement */
		psMibNodeControl->sTemp.u16FactoryReset--;
		/* Time to reset ? */
		if (psMibNodeControl->sTemp.u16FactoryReset == 0)
		{
			DBG_vPrintf(CONFIG_DBG_MIB_NODE_CONTROL, "\nDevice_vReset() Y");
			/* Perform factory reset */
			Device_vReset(TRUE);
		}
	}

	/* Counting down to reset ? */
	if (psMibNodeControl->sTemp.u16Reset > 0)
	{
		/* Decrement */
		psMibNodeControl->sTemp.u16Reset--;
		/* Time to reset ? */
		if (psMibNodeControl->sTemp.u16Reset == 0)
		{
			DBG_vPrintf(CONFIG_DBG_MIB_NODE_CONTROL, "\nDevice_vReset() Z");
			/* Perform normal reset */
			Device_vReset(FALSE);
		}
	}

	/* Need to force an exception ? */
	if (psMibNodeControl->sTemp.u8RaiseException != 0)
	{
		/* Save all PDM records */
		PDM_vSave();
		/* Force an exception */
		*((uint32*)0xffffffff) = 0x12345678;
	}
}
Exemplo n.º 2
0
/****************************************************************************
 *
 * NAME: Device_vInit
 *
 * DESCRIPTION:
 * Entry point for application
 *
 * RETURNS:
 * void, never returns
 *
 ****************************************************************************/
PUBLIC void Device_vInit(bool_t bWarmStart)
{
	bool_t   				  bFactoryReset;

	/* Initialise stack and hardware interfaces */
	v6LP_InitHardware();

	/* Cold start ? */
	if (FALSE == bWarmStart)
	{
		/* Initialise exception handler */
		Exception_vInit();

		/* Initialise all DIO as outputs and drive low */
		vAHI_DioSetDirection(0, 0xFFFFFFFE);
		vAHI_DioSetOutput(0, 0xFFFFFFFE);
	}

	/* Debug ? */
	#ifdef DBG_ENABLE
	{
		/* Initialise debugging */
		DBG_vUartInit(DEBUG_UART, DEBUG_BAUD_RATE);
		/* Disable the debug port flow control lines to turn off LED2 */
		vAHI_UartSetRTSCTS(DEBUG_UART, FALSE);
	}
	#endif

	/* 6x chip family ? */
	#ifdef  JENNIC_CHIP_FAMILY_JN516x
		/* Wait for clock to stablise */
		while(bAHI_Clock32MHzStable() == FALSE);
	#endif
	/* 42J01 chip ? */
	#ifdef JENNIC_CHIP_JN5142J01
		/* Wait for clock to stablise */
		while(bAHI_Clock32MHzStable() == FALSE);
	#endif

	/* Debug */
	DBG_vPrintf(TRUE, "                ");
	DBG_vPrintf(TRUE, "\n\nDEVICE DIO");
	DBG_vPrintf(DEBUG_DEVICE_FUNC, "\nDevice_vInit(%d)", bWarmStart);

	/* Node initialisation */
	Node_vInit(bWarmStart);

	/* Cold start ? */
	if (FALSE == bWarmStart)
	{
		/* 4x chip family ? */
		#ifdef  JENNIC_CHIP_FAMILY_JN514x
		{
			/* Check for factory reset using flags from flash */
			bFactoryReset = Node_bTestFactoryResetFlash();
		}
		#else
		{
			/* Check for factory reset using flags from EEPROM */
			bFactoryReset = Node_bTestFactoryResetEeprom();
		}
		#endif
		/* Reset the tick queue */
		u8TickQueue = 0;

		/* Initialise PDM and MIB data */
		Device_vPdmInit();

		/* Apply factory reset if required */
		if (bFactoryReset) Device_vReset(TRUE);

		/* Initialise JIP */
		(void) Device_eJipInit();
	}
	#ifdef MK_BLD_NODE_TYPE_END_DEVICE
	else
	{
		/* Debug */
		DBG_vPrintf(DEBUG_DEVICE_FUNC, "\ni6LP_ResumeStack()");
		/* Resume 6LoWPAN */
		i6LP_ResumeStack();
	}
	#endif

	/* Now initialised */
	bInitialised = TRUE;

	/* Enter main loop */
	Device_vMain();

	/* Allow sleeping ? */
	#ifdef MK_BLD_NODE_TYPE_END_DEVICE
	{
		/* Go to sleep if we exit main loop */
		Device_vSleep();
	}
	#endif
}