Ejemplo n.º 1
0
extern void WeightInitHardware(void)
{
    /* Set up PIOs
     * PIO11 - Button
     */
    /* Set the button PIO to user mode */
    PioSetModes(BUTTON_PIO_MASK, pio_mode_user);

    /* Set the PIO direction as input. */
    PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT);

    /* Pull up the PIO. */
    PioSetPullModes(BUTTON_PIO_MASK, pio_mode_strong_pull_up);

    /* Initialise Buzzer Hardware */
    BuzzerInitHardware();

    /* Set up button on PIO11 */
    PioSetEventMask(BUTTON_PIO_MASK, pio_event_mode_both);

    /* Save power by changing the I2C pull mode to pull down */
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);

#ifdef ENABLE_LEDBLINK
    /* PIO 4 is being used for LED glowing. */
    PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_user); /* user mode set */
    PioSetDir(LED_PIO, PIO_DIRECTION_OUTPUT);   /* output */
    PioSet(LED_PIO, FALSE);     /* set low */
#endif /* ENABLE_LEDBLINK */

}
Ejemplo n.º 2
0
void AppInit(sleep_state last_sleep_state)
{
    /* set all PIOs to inputs and pull them down */
    PioSetModes(0xFFFFFFFFUL, pio_mode_user);
    PioSetDirs(0xFFFFFFFFUL, FALSE);
    PioSetPullModes(0xFFFFFFFFUL, pio_mode_strong_pull_down);
    
    /* Set LED0 and LED1 to be controlled directly via PioSet */
    PioSetModes((1UL << PIO_LED0), pio_mode_user);

    /* Configure LED0 and LED1 to be outputs */
    PioSetDir(PIO_LED0, PIO_DIR_OUTPUT);

    /* Set the LED0 and LED1 to have strong internal pull ups */
    PioSetPullModes((1UL << PIO_LED0),
                    pio_mode_strong_pull_up);

    /* Configure button to be controlled directly */
    PioSetMode(PIR_SIGNAL, pio_mode_user);

    /* Configure button to be input */
    PioSetDir(PIR_SIGNAL, PIO_DIR_INPUT);

    /* Set weak pull up on button PIO, in order not to draw too much current
     * while button is pressed
     */
    PioSetPullModes((1UL << PIR_SIGNAL), pio_mode_weak_pull_down);

    /* Set the button to generate sys_event_pio_changed when pressed as well
     * as released
     */
    PioSetEventMask((1UL << PIR_SIGNAL), pio_event_mode_rising);


    /* disable wake up on UART RX */
    SleepWakeOnUartRX(FALSE);
    
    /* pull down the I2C lines */
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);

    /* Reset LED sequence */
    restartLedSeq();

	SleepModeChange(sleep_mode_deep);


    TimerInit(MAX_APP_TIMERS, (void*)app_timers);

    BeaconInit();

    pirStatusServiceInit();
}
Ejemplo n.º 3
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      InitAlertTagHardware  -  initialize application hardware
 *
 *  DESCRIPTION
 *      This function is called upon a power reset to initialize the PIOs
 *      and configure their initial states.
 *
 *  RETURNS
 *      Nothing.
 *
 *----------------------------------------------------------------------------*/
extern void InitAlertTagHardware(void)
{
#ifndef DEBUG_THRU_UART
    /* Don't wakeup on UART RX line */
    SleepWakeOnUartRX(FALSE);
#endif
    /* Setup PIOs
     * PIO3 - Buzzer - BUZZER_PIO
     * PIO4 - LED 1 - LED_PIO
     * PIO11 - Button - BUTTON_PIO
     */

    PioSetModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_user);
    PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT); /* input */
    PioSetPullModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_strong_pull_up); 
    /* Setup button on PIO11 */
    PioSetEventMask(PIO_BIT_MASK(BUTTON_PIO), pio_event_mode_both);


#ifdef ENABLE_LEDBLINK
    /* PWM is being used for LED glowing.*/
    PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_pwm1);

    /* Advertising parameters are being configured for PWM right now. When
     * application moves to connection state, we change PWM parameters to
     * the ones for connection
     */

    PioConfigPWM(LED_PWM_INDEX_1, pio_pwm_mode_push_pull, DULL_LED_ON_TIME_ADV,
         DULL_LED_OFF_TIME_ADV, DULL_LED_HOLD_TIME_ADV, BRIGHT_LED_OFF_TIME_ADV,
         BRIGHT_LED_ON_TIME_ADV, BRIGHT_LED_HOLD_TIME_ADV, LED_RAMP_RATE);

    PioEnablePWM(LED_PWM_INDEX_1, FALSE);
#endif /* ENABLE_LEDBLINK */


#ifdef ENABLE_BUZZER
    PioSetModes(PIO_BIT_MASK(BUZZER_PIO), pio_mode_pwm0);
    /* Configure the buzzer on PIO3 */
    PioConfigPWM(BUZZER_PWM_INDEX_0, pio_pwm_mode_push_pull, DULL_BUZZ_ON_TIME,
                 DULL_BUZZ_OFF_TIME, DULL_BUZZ_HOLD_TIME, BRIGHT_BUZZ_ON_TIME,
                 BRIGHT_BUZZ_OFF_TIME, BRIGHT_BUZZ_HOLD_TIME, BUZZ_RAMP_RATE);


    PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE);
#endif /* ENABLE_BUZZER */

    /* Set the I2C pins to pull down */
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);
}
Ejemplo n.º 4
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      I2CcommsInit
 *
 *  DESCRIPTION
 *      This function initialises the I2C
 *
 *  RETURNS
 *      Nothing
 *
 *----------------------------------------------------------------------------*/
extern void I2CcommsInit(void)
{
    /* Initialise I2C if it is not already initialised */

    if(!i2c_initialised)
    {     
        i2c_initialised = TRUE;
        PioSetModes(    ((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), 
                                                pio_mode_user);

        /* Configure the PIOs as Input */
        PioSetDirs(     ((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), 
                                                FALSE);
        PioSetPullModes(((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), 
                                                pio_mode_strong_pull_down); 
        PioSetEventMask(((0x01L << I2C_SDA_PIO) | (0x01L << I2C_SCL_PIO)), 
                                                pio_event_mode_disable);

        /* Configure the I2C controller */
        I2cInit(I2C_SDA_PIO,
                I2C_SCL_PIO,
                I2C_POWER_PIO_UNDEFINED,
                pio_i2c_pull_mode_strong_pull_up);

        /* Configure pull mode of the I2C pins */
        PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_up);

        /* Configure the I2C clock */
        I2cConfigClock(I2C_SCL_100KBPS_HIGH_PERIOD, I2C_SCL_100KBPS_LOW_PERIOD);
//        I2cConfigClock(I2C_SCL_400KBPS_HIGH_PERIOD, I2C_SCL_400KBPS_LOW_PERIOD);
        
        /* Enable the I2C controller */
        I2cEnable(TRUE);
    }
}
Ejemplo n.º 5
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      InitHardware
 *
 *  DESCRIPTION
 *      This function is called to initialise the application hardware.
 *
 *  PARAMETERS
 *      None
 *
 *  RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
extern void InitHardware(void)
{
    /* Setup PIOs
     * PIO11 - Button
     */
    /* Set the button PIO to user mode */
    PioSetModes(BUTTON_PIO_MASK, pio_mode_user);

    /* Set the PIO direction as input */
    PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT);

    /* Pull up the PIO */
    PioSetPullModes(BUTTON_PIO_MASK, pio_mode_strong_pull_up);

    /* Initialise buzzer hardware */
    BuzzerInitHardware();
    
    /* Initialise LED hardware */
    LedInitHardware();

    /* Request an event when the button PIO changes state */
    PioSetEventMask(BUTTON_PIO_MASK, pio_event_mode_both);

    /* Save power by changing the I2C pull mode to pull down.*/
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);
}
Ejemplo n.º 6
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      SetIndication
 *
 *  DESCRIPTION
 *      This function indicates the app state through LED blinking
 *
 *  RETURNS/MODIFIES
 *      Nothing.
 *
 *----------------------------------------------------------------------------*/
extern void SetIndication(app_indication state)
{

#ifdef ENABLE_LEDBLINK
    if(state == app_ind_stop)
    {
        /*Stop LED glowing */
        PioEnablePWM(LED_PWM_INDEX_1, FALSE);

        /* Reconfigure LED to pio_mode_user. This reconfiguration has been done
         * because When PWM is disabled, LED pio value remains same as it was at
         * the exact time of disabling. So if LED was on, it may remain ON even
         * after PWM disabling. So it is better to reconfigure it to user mode.
         * It will reconfigured to PWM mode while enabling.
         */
        PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_user);
        PioSet(LED_PIO, FALSE);
    }
    else
    {
        if(state == app_ind_adv)
        {
            /* Fast Blinking for advertising */
            PioConfigPWM(LED_PWM_INDEX_1, pio_pwm_mode_push_pull, 
                DULL_LED_ON_TIME_ADV, DULL_LED_OFF_TIME_ADV,
                DULL_LED_HOLD_TIME_ADV, BRIGHT_LED_ON_TIME_ADV,
                BRIGHT_LED_OFF_TIME_ADV, BRIGHT_LED_HOLD_TIME_ADV, 
                LED_RAMP_RATE);
        }
        else if(state == app_ind_conn)
        {
            /* slow blinking for connected state */
            PioConfigPWM(LED_PWM_INDEX_1, pio_pwm_mode_push_pull, 
                DULL_LED_ON_TIME_CONN, DULL_LED_OFF_TIME_CONN, 
                DULL_LED_HOLD_TIME_CONN, BRIGHT_LED_ON_TIME_CONN,
                BRIGHT_LED_OFF_TIME_CONN, BRIGHT_LED_HOLD_TIME_CONN, 
                LED_RAMP_RATE);
        }

        PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_pwm1);
        /*Start LED glowing */
        PioEnablePWM(LED_PWM_INDEX_1, TRUE);
        PioSet(LED_PIO, TRUE);
    }
#endif /* ENABLE_LEDBLINK */
}
Ejemplo n.º 7
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      BuzzerInitHardware
 *
 *  DESCRIPTION
 *      This function initialises the buzzer hardware.
 *
 *  PARAMETERS
 *      None
 *
 *  RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
extern void BuzzerInitHardware(void)
{
    /* Configure the buzzer PIO to use PWM. */
    PioSetModes(BUZZER_PIO_MASK, pio_mode_pwm0);

    /* Configure the PWM for buzzer ON OFF values */
    PioConfigPWM(BUZZER_PWM_INDEX_0, pio_pwm_mode_push_pull, DULL_BUZZ_ON_TIME,
                 DULL_BUZZ_OFF_TIME, DULL_BUZZ_HOLD_TIME, BRIGHT_BUZZ_ON_TIME,
                 BRIGHT_BUZZ_OFF_TIME, BRIGHT_BUZZ_HOLD_TIME, BUZZ_RAMP_RATE);

    /* Disable buzzer for the time being. */
    PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE);

}
Ejemplo n.º 8
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      InitTimeClientHardware-initialize application hardware
 *
 *  DESCRIPTION
 *      This function is called upon a power reset to initialize the PIOs
 *      and configure their initial states.
 *
 *  RETURNS
 *      Nothing.
 *
 *----------------------------------------------------------------------------*/
extern void InitTimeClientHardware(void)
{
    /* Setup PIOs
     * PIO3 - Buzzer - BUZZER_PIO
     * PIO4 - LED 1 - LED_PIO
     * PIO11 - Button - BUTTON_PIO
     */

    PioSetModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_user);
    PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT); /* input */
    PioSetPullModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_strong_pull_up); 
    /* Setup button on PIO11 */
    PioSetEventMask(PIO_BIT_MASK(BUTTON_PIO), pio_event_mode_both);

    /* Initialize Buzzer Hardware */
    BuzzerInitHardware();

#ifdef ENABLE_LEDBLINK
    /* PWM is being used for LED glowing.*/
    PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_pwm1);

    /* Advertising parameters are being configured for PWM right now. When
     * application moves to connection state, we change PWM parameters to
     * the ones for connection
     */

    PioConfigPWM(LED_PWM_INDEX_1, pio_pwm_mode_push_pull, DULL_LED_ON_TIME_ADV,
         DULL_LED_OFF_TIME_ADV, DULL_LED_HOLD_TIME_ADV, BRIGHT_LED_OFF_TIME_ADV,
         BRIGHT_LED_ON_TIME_ADV, BRIGHT_LED_HOLD_TIME_ADV, LED_RAMP_RATE);

    PioEnablePWM(LED_PWM_INDEX_1, FALSE);
#endif /* ENABLE_LEDBLINK */

    /* Set the I2C pins to pull down */
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);
}
Ejemplo n.º 9
0
void AppInit(sleep_state last_sleep_state)
{
    /* set all PIOs to inputs and pull them down */
    PioSetModes(0xFFFFFFFFUL, pio_mode_user);
    PioSetDirs(0xFFFFFFFFUL, FALSE);
    PioSetPullModes(0xFFFFFFFFUL, pio_mode_strong_pull_down);
    
    /* disable wake up on UART RX */
    SleepWakeOnUartRX(FALSE);
    
    /* pull down the I2C lines */
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);
       
    /* Start advertising */
    startAdvertising();
}