예제 #1
0
파일: node.c 프로젝트: azman/my1jendemo
PUBLIC void vJenie_CbInit(bool_t bWarmStart)
{

    vUtils_Init();

    if(bWarmStart==FALSE)
    {
        (void)u32AHI_Init();
        sHomeData.bStackReady=FALSE;
        /* Initialise buttons, LEDs and program variables */
        vInitEndpoint();
        /* Set DIO for buttons and LEDs */
        vLedControl(LED1, FALSE);
        vLedControl(LED2, FALSE);
        vLedInitRfd();
        vButtonInitRfd();

        #ifdef NO_SLEEP
            vAHI_WakeTimerEnable(E_AHI_WAKE_TIMER_1, TRUE);
        #endif

        /* Set SW1(dio9) to input */
        vAHI_DioSetDirection(E_AHI_DIO9_INT, 0);
        /* set interrupt for DIO9 to occur on button release - rising edge */
        vAHI_DioInterruptEdge(E_AHI_DIO9_INT, 0);
        /* enable interrupt for DIO9 */
        vAHI_DioInterruptEnable(E_AHI_DIO9_INT, 0);

        /* Set SW2(dio10) to input */
        vAHI_DioSetDirection(E_AHI_DIO10_INT, 0);
        /* set interrupt for DIO9 to occur on button release - rising edge */
        vAHI_DioInterruptEdge(E_AHI_DIO10_INT, 0);
        /* enable interrupt for DIO9 */
        vAHI_DioInterruptEnable(E_AHI_DIO10_INT, 0);

        /* Set up peripheral hardware */
        vALSreset();
        vHTSreset();

        /* Start ALS now: it automatically keeps re-sampling after this */
        vALSstartReadChannel(0);

        sHomeData.eAppState = E_STATE_REGISTER;
        switch(eJenie_Start(E_JENIE_END_DEVICE))        /* Start network as end device */
        {
        case E_JENIE_SUCCESS:
            #ifdef DEBUG
                vUtils_Debug("Jenie Started");
            #endif
            #ifdef HIGH_POWER
                /* Set high power mode */
                eJenie_RadioPower(18, TRUE);
            #endif
            break;

        case E_JENIE_ERR_UNKNOWN:
        case E_JENIE_ERR_INVLD_PARAM:
        case E_JENIE_ERR_STACK_RSRC:
        case E_JENIE_ERR_STACK_BUSY:

        default:
            /* Do something on failure?? */
            break;
        }
    }else{

        /* Set up peripheral hardware */
        vALSreset();
        vHTSreset();

        /* Start ALS now: it automatically keeps re-sampling after this */
        vALSstartReadChannel(0);

        switch(eJenie_Start(E_JENIE_END_DEVICE))        /* Start network as end device */
        {
        case E_JENIE_SUCCESS:
            #ifdef HIGH_POWER
                /* Set high power mode */
                eJenie_RadioPower(18, TRUE);
            #endif
            break;

        case E_JENIE_ERR_UNKNOWN:
        case E_JENIE_ERR_INVLD_PARAM:
        case E_JENIE_ERR_STACK_RSRC:
        case E_JENIE_ERR_STACK_BUSY:

        default:
            /* Do something on failure?? */
            break;
        }

    }
    /* set watchdog to long timeout - override setting in JenNet startup */
    #ifdef WATCHDOG_ENABLED
       vAHI_WatchdogStart(254);
    #endif

}
예제 #2
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();
    }
}