Пример #1
0
/****************************************************************************
 *
 * NAME: vDongleInitDIOs
 *
 * DESCRIPTION: Initialize the DIOs pins
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
void vDongleInitDIOs(){
	DBG_vPrintf(DEBUG_DEVICE_CONFIG,"vDongleInitDIOs\n");
	vAHI_DioSetPullup(0xFFFFFFFF, 0);
	vAHI_DioSetDirection(0, DONGLE_STATUS_LED); // set DIO15 to output

	vDongleSetLED(OFF);
}
Пример #2
0
/*---------------------------------------------------------------------------*/
void
leds_arch_init(void)
{
  vAHI_DioSetDirection(0, LED_R | LED_G);
  vAHI_DioSetOutput(0, LED_R | LED_G);     /* Default off */
  leds = 0;
}
Пример #3
0
PRSEV_HANDLER_DEF(E_STATE_APP_SLEEP, tsEvent *pEv, teEvent eEvent, uint32 u32evarg) {
	if (eEvent == E_EVENT_NEW_STATE) {
		// Sleep は必ず E_EVENT_NEW_STATE 内など1回のみ呼び出される場所で呼び出す。
		V_PRINTF(LB"! Sleeping...");
		V_FLUSH();

		pEv->bKeepStateOnSetAll = FALSE; // スリープ復帰の状態を維持

		// Mininode の場合、特別な処理は無いのだが、ポーズ処理を行う
		ToCoNet_Nwk_bPause(sAppData.pContextNwk);

		// センサー用の電源制御回路を Hi に戻す
		vPortSetSns(FALSE);

#ifdef LITE2525A
		vPortSetLo(LED);
#else
		vPortSetHi(LED);
#endif
		// 周期スリープに入る
		if(sAppData.sFlash.sData.i16param == NORMAL || sAppData.sFlash.sData.i16param == NEKOTTER ){
			vSleep(sAppData.sFlash.sData.u32Slp, sAppData.u16frame_count == 1 ? FALSE : TRUE, FALSE);
		}else{
			//	割り込みの設定
			vAHI_DioSetDirection(PORT_INPUT_MASK_ADXL345, 0); // set as input
			(void)u32AHI_DioInterruptStatus(); // clear interrupt register
			vAHI_DioWakeEnable(PORT_INPUT_MASK_ADXL345, 0); // also use as DIO WAKE SOURCE
			vAHI_DioWakeEdge(PORT_INPUT_MASK_ADXL345, 0); // 割り込みエッジ(立上がりに設定)

			vSleep(0, FALSE, FALSE);
		}
	}
}
/*	スリープをする状態	*/
PRSEV_HANDLER_DEF(E_STATE_APP_SLEEP, tsEvent *pEv, teEvent eEvent, uint32 u32evarg) {
	if (eEvent == E_EVENT_NEW_STATE) {
		// Sleep は必ず E_EVENT_NEW_STATE 内など1回のみ呼び出される場所で呼び出す。
		V_PRINTF(LB"Sleeping...");
		V_FLUSH();

		// Mininode の場合、特別な処理は無いのだが、ポーズ処理を行う
		ToCoNet_Nwk_bPause(sAppData.pContextNwk);

		// print message.
		vAHI_UartDisable(UART_PORT); // UART を解除してから(このコードは入っていなくても動作は同じ)

		// set UART Rx port as interrupt source
		vAHI_DioSetDirection(PORT_INPUT_MASK, 0); // set as input

		(void)u32AHI_DioInterruptStatus(); // clear interrupt register

		vAHI_DioWakeEnable(PORT_INPUT_MASK, 0); // also use as DIO WAKE SOURCE

		// i16paramに関わらず状態の変化で起床
		if(sAppData.bDI1_Now_Opened) {
			vAHI_DioWakeEdge(0, PORT_INPUT_MASK); // 割り込みエッジ(立下りに設定)
		} else {
			vAHI_DioWakeEdge(PORT_INPUT_MASK, 0); // 割り込みエッジ(立上がりに設定)
		}

		// wake up using wakeup timer as well.
		ToCoNet_vSleep(E_AHI_WAKE_TIMER_0, sAppData.sFlash.sData.u32Slp, FALSE, FALSE ); // PERIODIC RAM OFF SLEEP USING WK0

	}
}
Пример #5
0
/****************************************************************************
 *
 * NAME:            LAMP_vInit
 *
 * DESCRIPTION:     Initialises the lamp drive system
 *
 * PARAMETERS:      Name     RW  Usage
 *
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void DriverBulb_vInit(void)
{
    bool_t bLampTimerInt = FALSE;

    static bool_t bInit = FALSE;

	if (bInit==TRUE)
    {
        /* Mimic PWM to led ? */
        #if (LAMP_LED_PIN < 21)
        {
            /* Configure as output */
            vAHI_DioSetDirection(0, (1 << LAMP_LED_PIN));
            /* Turn CFL lamp off */
            vAHI_DioSetOutput((1 << LAMP_LED_PIN), 0);
            /* Register interrupt callback */
			#if (JENNIC_CHIP == JN5148) || (JENNIC_CHIP == JN5148J01)
	            vAHI_Timer1RegisterCallback(vCbTimer1);
			#else
	            vAHI_Timer3RegisterCallback(vCbTimer1);
			#endif
            /* Note we want to generate interrupts */
            bLampTimerInt = TRUE;
        }
        #endif

        /* Indicate gateway mode on LED ? */
        #if (LAMP_GW_PIN < 21)
        {
            /* Configure as output */
            vAHI_DioSetDirection(0, (1 << LAMP_GW_PIN));
		}
		#endif

        /* Configure timer 0 to generate a PWM output on its output pin */
        vAHI_TimerEnable(LAMP_TIMER, LAMP_TIMER_PRESCALE, bLampTimerInt, bLampTimerInt, TRUE);
        vAHI_TimerConfigureOutputs(LAMP_TIMER, FALSE, TRUE);
        vAHI_TimerClockSelect(LAMP_TIMER, FALSE, TRUE);

        /********************************************/
        /* Voltage Monitoring System Initialisation */
        /********************************************/

         gu32BusVoltage = 0;
    }
    bInit=TRUE; /* 2nd late call will be used for initialisation */
}
Пример #6
0
/*---------------------------------------------------------------------------*/
void
leds_arch_init(void)
{
  vAHI_DioSetDirection(0, E_AHI_DIO8_INT|
                          E_AHI_DIO9_INT|
                          E_AHI_DIO10_INT|
                          E_AHI_DIO16_INT);
  leds_arch_set(0);
}
Пример #7
0
void initLcdEADog(uint8 cs,int reset,int a0,int angle,lcdEADog* lcd)
{
    lcd->spicspin=cs;
    lcd->resetpin=reset;
    lcd->a0pin=a0;
    lcd->angle=angle;

    uint8 config0deg[14]={0x40,0xa1,0xc0,0xa6,0xa2,0x2f,0xf8,0x00,0x27,0x81,0x16,0xac,0x00,0xaf};
    uint8 config180deg[14]={0x40,0xa0,0xc8,0xa6,0xa2,0x2f,0xf8,0x00,0x27,0x81,0x16,0xac,0x00,0xaf};

    vAHI_SpiConfigure( 2, /* number of slave select lines in use */
        E_AHI_SPIM_MSB_FIRST, /* send data MSB first */
        FALSE,
        FALSE,
        1,//8MHz
        E_AHI_SPIM_INT_DISABLE, /* Disable SPI interrupt */
        E_AHI_SPIM_AUTOSLAVE_DSABL); /* Disable auto slave select        */


    vAHI_DioSetDirection(0,lcd->resetpin);
    vAHI_DioSetDirection(0,lcd->a0pin);


    vAHI_DioSetOutput(0,lcd->resetpin);

    cycleDelay(16*4000);
    vAHI_DioSetOutput(lcd->resetpin,0);

    vAHI_DioSetOutput(0,lcd->a0pin);


    int i;

    vAHI_SpiSelect(lcd->spicspin);

    for(i=0;i<sizeof(config0deg);i++)
    {
        if(angle==180)vAHI_SpiStartTransfer8(config180deg[i]);
        else vAHI_SpiStartTransfer8(config0deg[i]);
        vAHI_SpiWaitBusy();
    }
    vAHI_SpiStop();
}
Пример #8
0
/****************************************************************************
 * NAME: bButtonInitialize
 *
 * DESCRIPTION:
 * Button Initialization function, enables interrupts only on DK4
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
bool bButtonInitialize(void)
{

#ifdef DK4
	 /* Set DIO lines to inputs with buttons connected */
	 vAHI_DioSetDirection(APP_BUTTONS_DIO_MASK, 0);

    vAHI_SysCtrlRegisterCallback(&vEH_ButtonCallback);

    /* Turn on pull-ups for DIO lines with buttons connected */
    vAHI_DioSetPullup(APP_BUTTONS_DIO_MASK, 0);

    /* Set the edge detection for falling edges */
    vAHI_DioInterruptEdge(0, APP_BUTTONS_DIO_MASK);

    /* Enable interrupts to occur on selected edge */
    vAHI_DioInterruptEnable(APP_BUTTONS_DIO_MASK, 0);
    uint32 u32ButtonStatus = u32AHI_DioReadInput() ;
   if ((u32ButtonStatus & 0x100) == 0x00)
   {
	   u32Button = APP_BUTTONS_BUTTON_1;
	   bButtonPressed = TRUE;
		/* disable edge detection until handling of button press complete */
		vAHI_DioInterruptEnable(0, APP_BUTTONS_DIO_MASK);
	   return TRUE;
   }
   return FALSE;

#else

    /* Disable internal pull-up */
	vAHI_DioSetPullup    ((uint32) 0x0, APP_BUTTONS_DIO_MASK);
	/* Make button DIO an input */
	vAHI_DioSetDirection ((uint32) APP_BUTTONS_DIO_MASK, 0x0);

	  return TRUE;

#endif

}
/****************************************************************************
 *
 * NAME: vSetUpWakeUpConditions
 *
 * DESCRIPTION:
 *
 * Set up the wake up inputs while going to sleep.
 *
 * PARAMETERS:      Name            RW  Usage
 *
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vSetUpWakeUpConditions(void)
{
   /*
    * Set the DIO with the right edges for wake up
    * */
	/*Set the LED to inputs to reduce power consumption */
	/*the following pins are connected to LEDs hence drive them low*/
	vGenericLEDSetOutput(2, 0);
	vGenericLEDSetOutput(4, 0);

    vAHI_DioSetDirection(APP_BUTTONS_DIO_MASK,0);   /* Set as Power Button(DIO0) as Input */
    vSaveDioStateBeforeDeepSleep();
}
Пример #10
0
PUBLIC void vWatchdog_init(){

	#if defined WATCHDOG_INTERNAL

	    vAHI_WatchdogStart(12);// Prescaler is equal 12 -> 16392 ms timeout period

	#elif defined WATCHDOG_EXTERNAL

	    vAHI_WatchdogStop();

	    // ”становить вывод через который передаЄтс¤ импульс на внешний Watchdog
		vAHI_DioSetDirection(0, WATCHDOG_IMPULSE);
		vAHI_DioSetPullup(0, WATCHDOG_IMPULSE);

	#elif

	    vAHI_WatchdogStop();

	#endif
}
Пример #11
0
/****************************************************************************
 *
 * NAME: APP_vButtonsInitialise
 *
 * DESCRIPTION:
 * Initialises buttons
 *
 * RETURNS:
 * bool_t   Returns TRUE if any button was pressed
 *
 ****************************************************************************/
PUBLIC bool_t APP_bButtonInitialise(void)
{
    /* Set DIO lines to inputs with buttons connected */
    vAHI_DioSetDirection(APP_BUTTONS_DIO_MASK, 0);

    /* Turn on pull-ups for DIO lines with buttons connected */
    vAHI_DioSetPullup(APP_BUTTONS_DIO_MASK, 0);

    /* Set the edge detection for falling edges */
    vAHI_DioInterruptEdge(0, APP_BUTTONS_DIO_MASK);

    /* Enable interrupts to occur on selected edge */
    vAHI_DioInterruptEnable(APP_BUTTONS_DIO_MASK, 0);

    uint32 u32Buttons = u32AHI_DioReadInput() & APP_BUTTONS_DIO_MASK;
    if (u32Buttons != APP_BUTTONS_DIO_MASK)
    {
        return TRUE;
    }
    return FALSE;
}
/****************************************************************************
 *
 * NAME: APP_bButtonInitialise
 *
 * DESCRIPTION:
 * Button Initialization
 *
 * PARAMETER: void
 *
 * RETURNS: bool
 *
 ****************************************************************************/
PUBLIC void APP_bButtonInitialise(void)
{
    /* Set DIO lines to inputs with buttons connected */
    vAHI_DioSetDirection(APP_BUTTONS_DIO_MASK, 0);

    /* Turn on pull-ups for DIO lines with buttons connected */
    vAHI_DioSetPullup(APP_BUTTONS_DIO_MASK, 0);

    if (FALSE == (u16AHI_PowerStatus() & WAKE_FROM_DEEP_SLEEP))
	{
		/* Set the edge detection for falling edges */
		vAHI_DioWakeEdge(0, APP_BUTTONS_DIO_MASK);
	}
    else
    {
    	u32PreviousDioState = u32AHI_ReadNVData(DIO_STATE_NVM_LOCATION);
    	DBG_vPrintf(TRACE_APP_BUTTON, "\nAPP Button: Previous Dio State = %d", u32PreviousDioState);
    }

	/* Enable interrupts to occur on selected edge */
	vAHI_DioWakeEnable(APP_BUTTONS_DIO_MASK, 0);
}
Пример #13
0
/*
 * set IO direction
 * - pio: IO device pointer
 * - dir: INPUT or OUTPUT
 */
void suli_pin_dir(IO_T *pio, DIR_T dir)
{
    if(*pio >= DO0)
    {
        if(dir == HAL_PIN_INPUT)
        {
            DBG_vPrintf(TRACE_SULI, "DO pins can not be configured as input.\r\n");
        }
    } else
    {
        uint32 u32Inputs = 0;
        uint32 u32Outputs = 0;

        if(dir == HAL_PIN_INPUT)
        {
            u32Inputs = (1 << (*pio));
        } else
        {
            u32Outputs = (1 << (*pio));
        }
        vAHI_DioSetDirection(u32Inputs, u32Outputs);
    }
}
Пример #14
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
  if(type == SENSORS_HW_INIT) {
    /* Called from sensor thread when started.
       Configure DIO lines with buttons connected as input */
    vAHI_DioSetDirection(APP_BUTTONS_DIO_MASK, 0);
    /* Turn on pull-ups for DIO lines with buttons connected */
    vAHI_DioSetPullup(APP_BUTTONS_DIO_MASK, 0);
    PRINTF("HW_INIT BUTTONS (0x%x)\n", APP_BUTTONS_DIO_MASK);
    /* Configure debounce timer. Do not run it yet. */
    buttons_status = BUTTONS_STATUS_INIT;
    process_start(&key_sampling, NULL);
    return 1;
  } else if(type == SENSORS_ACTIVE) {
    if(buttons_status != BUTTONS_STATUS_NOT_INIT) {
      if(value) {
        /* Button sensor activated */
        PRINTF("BUTTONS ACTIVATED\n");
        buttons_status = BUTTONS_STATUS_ACTIVE;
      } else {
        /* Button sensor de-activated */
        PRINTF("BUTTONS DE-ACTIVATED\n");
        buttons_status = BUTTONS_STATUS_NOT_ACTIVE;
      }
      process_post(&key_sampling, PROCESS_EVENT_MSG, (void *)&buttons_status);
      return 1;
    } else {
      /* Buttons must be intialised before being (de)-activated */
      PRINTF("ERROR: NO HW_INIT BUTTONS\n");
      return 0;
    }
  } else {
    /* Non valid type */
    return 0;
  }
}
Пример #15
0
void
AppColdStart(void)
{
    /* initialize unaligned access handler */
    UNALIGNED_ACCESS = UNALIGNED_ACCESS_HANDLER;

    /* initialize uart to 8N1 at 115200 baud, that gives a throughput og
     * ~14.4 kb/s, maxmimum packet rate on Ieee802.15.4 is 248 packets/sec at
     * 127 bytes payload + header, which allows to return about 50bytes on the
     * uart per packet. */
    vAHI_UartEnable(UART);
    vAHI_UartReset(UART, true, true);
    vAHI_UartReset(UART, false, false);
    vAHI_UartSetControl(UART, E_AHI_UART_EVEN_PARITY,
                        E_AHI_UART_PARITY_DISABLE,
                        E_AHI_UART_WORD_LEN_8,
                        E_AHI_UART_1_STOP_BIT,
                        E_AHI_UART_RTS_HIGH);
    vAHI_UartSetBaudrate(UART, BAUD);
    vAHI_UartSetRTSCTS(UART, false);
    vAHI_DioSetDirection(CTS, RTS);
    vAHI_DioSetOutput(0x00, RTS);

    /* run the main loop, wait for channel number, then start reception
     * and packet delivery. Ack by sending "okay\n". */
    while (1) {
        static int     started = MAC_ENUM_NO_DATA;
        static char    input[10];
        static uint8_t i=0;

        /* write one rxd packet to uart */
        if (started==MAC_ENUM_SUCCESS) {
            MAC_DcfmIndHdr_s *ind;

            if (rxq_peektype() == MCPS) {
                ind = rxq_peek();

                if (ind->u8Type == MAC_MCPS_IND_DATA) {
                    MAC_McpsDcfmInd_s *s = ind;
                    uart_write(UART, (char*) &s->uParam.sIndData, sizeof(s->uParam.sIndData));
                }
            }

            rxq_dequeue();
        }

        /* read from uart into buf */
        while (i<sizeof(input) && DATAREADY(UART)) {
            input[i] = u8AHI_UartReadData(UART);

            if ((i+1)==sizeof(input)) { /* buffer overrun, discard input */
                memset(input, '\0', i);
                i = 0;
            } else if (input[i]=='\n' || input[i]=='\r') {  /* read as channel number */
                int channel;

                input[9] = '\0';            /* terminate string */
                channel  = atoi(input);     /* convert string to num */
                started  = start_sniffer(channel);

                if (started != MAC_ENUM_SUCCESS)
                    printf("not started, error code: 0x%x, see MAC_Enum_e\r\n", started);
                else
                    printf("started on channel %d\r\n", channel);

                memset(input, '\0', i);
                i = 0;
            } else
                i++;
        }
    }
}
Пример #16
0
/****************************************************************************
 *
 * NAME:       		LAMP_vInit
 *
 * DESCRIPTION:		Initialises the lamp drive system
 *
 * PARAMETERS:      Name     RW  Usage
 *
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void DriverBulb_vInit(void)
{
	bool_t bLampTimerInt = FALSE;

	static bool_t bInit = FALSE;

	if (bInit == FALSE)
	{

		/* Configure DIO pins */
		vAHI_DioSetDirection(0, (LAMP_ON_OFF_MASK | (1 <<LAMP_BLEEDER_PIN)));

		/* Turn CFL lamp off */
		vAHI_DioSetOutput(0, LAMP_ON_OFF_MASK);

		/* Mimic PWM to led ? */
		#if (LAMP_LED_PIN < 21)
		{
			/* Configure as output */
			vAHI_DioSetDirection(0, (1 << LAMP_LED_PIN));
			/* Turn CFL lamp off */
			vAHI_DioSetOutput(0, (1 << LAMP_LED_PIN)/*, 0*/);
			/* Register interrupt callback */
			vAHI_Timer0RegisterCallback(vCbTimer0);
			/* Note we want to generate interrupts */
			bLampTimerInt = TRUE;
		}
		#endif

		/* Configure timer 0 to generate a PWM output on its output pin */
		vAHI_TimerEnable(LAMP_TIMER, LAMP_TIMER_PRESCALE, bLampTimerInt, bLampTimerInt, TRUE);
		vAHI_TimerConfigureOutputs(LAMP_TIMER, FALSE, TRUE);
		vAHI_TimerClockSelect(LAMP_TIMER, FALSE, TRUE);

		/* turn on lamp - this is the default state */

		vAHI_DioSetOutput((1 << LAMP_BLEEDER_PIN),0);
		vAHI_DioSetOutput(LAMP_ON_OFF_MASK,0);


		vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE,
							 E_AHI_AP_INT_DISABLE,
							 E_AHI_AP_SAMPLE_8,
							 E_AHI_AP_CLOCKDIV_500KHZ,
							 E_AHI_AP_INTREF);

		while (!bAHI_APRegulatorEnabled());   /* spin on reg not enabled */

		vAHI_AdcEnable(E_AHI_ADC_SINGLE_SHOT, E_AHI_AP_INPUT_RANGE_2, ADC_USED);

		do
		{
			vAHI_AdcStartSample();
			while(bAHI_AdcPoll());
			gu32BusVoltage = ((uint32)u16AHI_AdcRead()*VBUS_MAXIMUM) >> ADC_BITS;
		} while (gu32BusVoltage< VBUS_TRIP_LO);

		vAHI_AdcDisable();

		vAHI_ApConfigure(E_AHI_AP_REGULATOR_DISABLE,
						 E_AHI_AP_INT_DISABLE,
					     E_AHI_AP_SAMPLE_8,
						 E_AHI_AP_CLOCKDIV_500KHZ,
						 E_AHI_AP_INTREF);

		vAHI_TimerStartRepeat(LAMP_TIMER, PWM_COUNT, PWM_COUNT );

		bInit = TRUE;
		bIsOn = TRUE;

	}
Пример #17
0
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

}
Пример #18
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
}
Пример #19
0
void LED_INIT() { vAHI_DioSetDirection(0, 1 << 2); vAHI_DioSetDirection(0, 1 << 3); vAHI_DioSetDirection(0, 1 << 16); vAHI_DioSetDirection(0, 1 << 17); CLEAR_PIN(16); CLEAR_PIN(17); }
Пример #20
0
/****************************************************************************
 *
 * NAME: AppColdStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Initialises system and runs
 * main loop.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void AppColdStart(void)
{
#if (defined JN5148 || defined JN5168 )
	// TODO - use watch dog and probably disable brownout reset
	vAHI_WatchdogStop();
#endif
#ifdef JN5139
	vAppApiSetBoostMode(TRUE);
#endif

	// Initialise the hopping mode status
	// TODO - move to settings?
	setHopMode(hoppingRxStartup);

	connectObjects();
	RX.ro.version=2;

	// Initialise the system
	vInitSystem();

	// set up the exception handlers
	setExceptionHandlers();


	if(!radioDebug)debugRoute=&pcViaComPort;
	else debugRoute=&pcViaTx;

	if (debugRoute->routeNodes[0] == CONPC)
	{
		// Don't use uart pins for servo op
		initPcComs(&pccoms, CONPC, 0, rxHandleRoutedMessage);
		rxHardware.uart0InUse=TRUE;
	}


	// Initialise the clock
	// TODO - fix this
	/* the jn5148 defaults to 16MHz for the processor,
	   it can be switched to 32Mhz however the servo driving
	   code would need tweaking
	   */
	//bAHI_SetClockRate(3);


	resetType rt=getResetReason();
	if(rt!=NOEXCEPTION)
	{
		dbgPrintf("EXCEPTION %d \r\n",rt);
	}


	// Set handler for incoming data
	setRadioDataCallback(rxHandleRoutedMessage, CONTX);

	// Retrieve the MAC address and log it to the PC
	module_MAC_ExtAddr_s* macptr = (module_MAC_ExtAddr_s*)pvAppApiGetMacAddrLocation();


	// Send init string to PC log rx mac and bound tx mac to pc
	dbgPrintf("rx24 2.10 rx %x %x tx %x %x",macptr->u32H, macptr->u32L,txMACh ,txMACl );


	// Use dio 16 for test sync pulse
	vAHI_DioSetDirection(0, 1 << 16);


	// Set demands to impossible values
	// TODO - fix magic numbers grrr
	int i;
	for (i = 0; i < 20; i++)
	{
		RX.rxDemands[i] = 4096;
		RX.rxMixedDemands[i] = 4096;
	}
	rxHardware.i2cInUse=imu.enabled;
	startIMU(&imu);


	// Set up digital inputs and outputs
	initInputs(&rxHardware);
	initOutputs(&rxHardware);



	if(rxHardware.oneWireEnabled==TRUE)
	{
		// enable onewire sensor bus
		initOneWireBus(&sensorBus1,CONONEWIRE,rxHardware.oneWirePort,rxHandleRoutedMessage);

	}
	if(rxHardware.gpsEnabled==TRUE)
	{
		initNmeaGps(rxHardware.gpsPort, E_AHI_UART_RATE_38400);
	}

	// Setup DIO  for the LED
	vAHI_DioSetDirection(0, rxHardware.ledBit);

	// Initialise Analogue peripherals
	vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE, E_AHI_AP_INT_DISABLE,
			E_AHI_AP_SAMPLE_8, E_AHI_AP_CLOCKDIV_500KHZ, E_AHI_AP_INTREF);

	while (bAHI_APRegulatorEnabled() == 0)
		;


	// Start the servo pwm generator
	setFrameCallback(frameStartEvent);
	setMixCallback(mixEvent);



	startServoPwm(RX.servoUpdateRate);


	// Enter the never ending main handler
	while (1)
	{
		// Process any events
		vProcessEventQueues();
	}
}