Пример #1
0
/* @fn      LoacationApp_Sleep
 * @brief   Sample Application set allow/disallow sleep mode.
 * @return  none*/
void LoacationApp_Sleep( uint8 allow ) {
#if defined( POWER_SAVING )
  if ( allow ) {
    osal_pwrmgr_task_state( NWK_TaskID, PWRMGR_CONSERVE );
    NLME_SetPollRate( 0 );
  } else {
    osal_pwrmgr_task_state( NWK_TaskID, PWRMGR_HOLD );
    NLME_SetPollRate( 1000 );
  }
#endif
}
Пример #2
0
void ther_wake_lock(void)
{
	struct ther_info *ti = &ther_info;

	if (ti->lock_users == 0) {
		osal_pwrmgr_task_state(ti->task_id, PWRMGR_HOLD);
	}
	ti->lock_users++;
}
Пример #3
0
void ther_wake_unlock(void)
{
	struct ther_info *ti = &ther_info;

	ti->lock_users--;
	if (ti->lock_users == 0) {
		osal_pwrmgr_task_state(ti->task_id, PWRMGR_CONSERVE);
	}
}
Пример #4
0
HAL_ISR_FUNCTION(port1Isr, P1INT_VECTOR)
#endif
{
	HAL_ENTER_ISR();
	
	PxIFG = 0;
	PxIF = 0;
	
	dmaRdyIsr = 1;

#ifdef POWER_SAVING
	CLEAR_SLEEP_MODE();
	osal_pwrmgr_task_state(Hal_TaskID, PWRMGR_HOLD);

#if HAL_UART_TX_BY_ISR 
	if (dmaCfg.txHead == dmaCfg.txTail) {
		HAL_UART_DMA_CLR_RDY_OUT();
	}
#endif
#endif
	HAL_EXIT_ISR();
}
Пример #5
0
HAL_ISR_FUNCTION(port0Isr, P0INT_VECTOR)
{
  unsigned char status;
  unsigned char i;

  HAL_ENTER_ISR();

  status = P0IFG;
  status &= P0IEN;
  if (status)
  {
    P0IFG = ~status;
    P0IF = 0;
    
#if HAL_UART_DMA == 1
    extern uint8 Hal_TaskID;
    extern volatile uint8 dmaRdyIsr;
    dmaRdyIsr = 1;
    CLEAR_SLEEP_MODE();
    osal_pwrmgr_task_state(Hal_TaskID, PWRMGR_HOLD);
#if HAL_UART_TX_BY_ISR
    if (dmaCfg.txHead == dmaCfg.txTail)
    {
      HAL_UART_DMA_CLR_RDY_OUT();
    }
#endif
#endif // HAL_UART_DMA

    for (i = 0; i < OS_MAX_INTERRUPT; i++)
    {
      if (PIN_MAJOR(blueBasic_interrupts[i].pin) == 0 && (status & (1 << PIN_MINOR(blueBasic_interrupts[i].pin))))
      {
        osal_set_event(blueBasic_TaskID, BLUEBASIC_EVENT_INTERRUPT << i);
      }
    }
  }

  HAL_EXIT_ISR();
}
Пример #6
0
/**************************************************************************************************
 * @fn      Hal_ProcessEvent
 *
 * @brief   Hal Process Event
 *
 * @param   task_id - Hal TaskId
 *          events - events
 *
 * @return  None
 **************************************************************************************************/
uint16 Hal_ProcessEvent( uint8 task_id, uint16 events )
{
    uint8 *msgPtr;

    (void)task_id;  // Intentionally unreferenced parameter

    if ( events & SYS_EVENT_MSG )
    {
        msgPtr = osal_msg_receive(Hal_TaskID);

        while (msgPtr)
        {
            /* Do something here - for now, just deallocate the msg and move on */

            /* De-allocate */
            osal_msg_deallocate( msgPtr );
            /* Next */
            msgPtr = osal_msg_receive( Hal_TaskID );
        }
        return events ^ SYS_EVENT_MSG;
    }

#if (defined HAL_BUZZER) && (HAL_BUZZER == TRUE)
    if (events & HAL_BUZZER_EVENT)
    {
        HalBuzzerStop();
        return events ^ HAL_BUZZER_EVENT;
    }
#endif

#ifdef CC2591_COMPRESSION_WORKAROUND
    if ( events & PERIOD_RSSI_RESET_EVT )
    {
        macRxResetRssi();
        return (events ^ PERIOD_RSSI_RESET_EVT);
    }
#endif

    if ( events & HAL_LED_BLINK_EVENT )
    {
#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
        HalLedUpdate();
#endif /* BLINK_LEDS && HAL_LED */
        return events ^ HAL_LED_BLINK_EVENT;
    }

    if (events & HAL_KEY_EVENT)
    {
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
        /* Check for keys */
        HalKeyPoll();

        /* if interrupt disabled, do next polling */
        if (!Hal_KeyIntEnable)
        {
            osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);
        }
#endif
        return events ^ HAL_KEY_EVENT;
    }

#if defined POWER_SAVING
    if ( events & HAL_SLEEP_TIMER_EVENT )
    {
        halRestoreSleepLevel();
        return events ^ HAL_SLEEP_TIMER_EVENT;
    }

    if ( events & HAL_PWRMGR_HOLD_EVENT )
    {
        (void)osal_pwrmgr_task_state(Hal_TaskID, PWRMGR_HOLD);

        (void)osal_stop_timerEx(Hal_TaskID, HAL_PWRMGR_CONSERVE_EVENT);
        (void)osal_clear_event(Hal_TaskID, HAL_PWRMGR_CONSERVE_EVENT);

        return (events & ~(HAL_PWRMGR_HOLD_EVENT | HAL_PWRMGR_CONSERVE_EVENT));
    }

    if ( events & HAL_PWRMGR_CONSERVE_EVENT )
    {
        (void)osal_pwrmgr_task_state(Hal_TaskID, PWRMGR_CONSERVE);
        return events ^ HAL_PWRMGR_CONSERVE_EVENT;
    }
#endif

    return 0;
}
Пример #7
0
/*********************************************************************
 * @fn      ParkingApp_Init
 *
 * @brief   Initialization function for the Generic App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void ParkingApp_Init( uint8 task_id )
{
  //开始应用初始化,闪灯
  //HalLedSet(HAL_LED_1,HAL_LED_MODE_FLASH);
  HalLedBlink( HAL_LED_1, 10, 50, 1000 );

  ParkingApp_TaskID = task_id;
  ParkingApp_NwkState = DEV_INIT;
  ParkingApp_TransID = 0;

  // Device hardware initialization can be added here or in main() (Zmain.c).
  // If the hardware is application specific - add it here.
  // If the hardware is other parts of the device add it in main().

 #if defined ( BUILD_ALL_DEVICES )
  // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START
  // We are looking at a jumper (defined in ParkingAppHw.c) to be jumpered
  // together - if they are - we will start up a coordinator. Otherwise,
  // the device will start as a router.
  if ( readCoordinatorJumper() )
    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
  else
    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif // BUILD_ALL_DEVICES

#if defined ( HOLD_AUTO_START )
  // HOLD_AUTO_START is a compile option that will surpress ZDApp
  //  from starting the device and wait for the application to
  //  start the device.
  ZDOInitDevice(0);
#endif

  // Setup for the periodic message's destination address
  // Broadcast to everyone
#if (defined DATABROADCAST && DATABROADCAST == TRUE)
  ParkingApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; //afAddr16Bit;
  ParkingApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // 0x0000;
#else
  ParkingApp_Periodic_DstAddr.addrMode = (afAddrMode_t)afAddr16Bit;
  ParkingApp_Periodic_DstAddr.addr.shortAddr = 0x0000;
#endif
  ParkingApp_Periodic_DstAddr.endPoint = PARKINGAPP_ENDPOINT;
  
  // Fill out the endpoint description.
  ParkingApp_epDesc.endPoint = PARKINGAPP_ENDPOINT;
  ParkingApp_epDesc.task_id = &ParkingApp_TaskID;
  ParkingApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&ParkingApp_SimpleDesc;
  ParkingApp_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint description with the AF
  afRegister( &ParkingApp_epDesc );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( ParkingApp_TaskID );
  
  osal_pwrmgr_task_state( ParkingApp_TaskID, PWRMGR_CONSERVE );

  // Set TXPOWER
//  MAC_MlmeSetReq( ZMacPhyTransmitPower, &txPower );
  
  // By default, all devices start out in Group 1
  ParkingApp_Group.ID = 0x0005;
  osal_memcpy( ParkingApp_Group.name, "Group 1", 7  );
  aps_AddGroup( PARKINGAPP_ENDPOINT, &ParkingApp_Group );
}
Пример #8
0
void ECGSensor_Init( uint8 task_id )
{
  ECGSensor_TaskID = task_id;

  #ifdef POWER_SAVING
    (void)osal_pwrmgr_task_state( task_id, PWRMGR_CONSERVE );
  #endif
    
    
  uart_open();
    
  // Setup the GAP Peripheral Role Profile

  // 对于CC2540_ECG, 设备初始化时,进行广播
  uint8 initial_advertising_enable = TRUE;

  // By setting this to zero, the device will go into the waiting state after
  // being discoverable for 30.72 second, and will not being advertising again
  // until the enabler is set back to TRUE
  uint16 gapRole_AdvertOffTime = 0;
    
  uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;
  uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
  uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
  uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY;
  uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT;

  // Set the GAP Role Parameters
  GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
  GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime );
  
  GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData );
  GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );
  
  GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );
  GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );
  GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );
  GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency );
  GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout );

  // Set the GAP Characteristics
  GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );

// Set advertising interval

  uint16 advInt = DEFAULT_ADVERTISING_INTERVAL;
  GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
  GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
  GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
  GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );


// Setup the GAP Bond Manager

  uint32 passkey = 0; // passkey "000000"
  uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
  uint8 mitm = TRUE;
  uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
  uint8 bonding = TRUE;
  GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey );
  GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode );
  GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm );
  GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap );
  GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding ); 
   
  // Initialize GATT attributes
  GGS_AddService( GATT_ALL_SERVICES );            // GAP
  GATTServApp_AddService( GATT_ALL_SERVICES );    // GATT attributes
  DevInfo_AddService();                           // Device Information Service
  SimpleProfile_AddService( GATT_ALL_SERVICES );  // Simple GATT Profile
  
  // 设置Battery Characteristic Values
  uint8 critical = DEFAULT_BATT_CRITICAL_LEVEL;
  Batt_SetParameter( BATT_PARAM_CRITICAL_LEVEL, sizeof (uint8 ), &critical ); 
  Batt_AddService( );                             // 电池电量服务
  //Register for Battery service callback;
  Batt_Register ( ECGSensorBattCB );


// Setup the SimpleProfile Characteristic Values
  uint8 charValue1 = 1;
  uint8 charValue2 = 2;
  uint8 charValue3 = 3;
  uint8 charValue4 = 4; 
  uint8 charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 };
  SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR1, sizeof ( uint8 ), &charValue1 );
  SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR2, sizeof ( uint8 ), &charValue2 );
  SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR3, sizeof ( uint8 ), &charValue3 );
  SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof ( uint8 ), &charValue4 );
  SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5 );
 
  // Simple Keys Profile
  SK_AddService( GATT_ALL_SERVICES );
  // Register for all key events - This app will handle all key events
  RegisterForKeys( ECGSensor_TaskID );  


  // Register callback with SimpleGATTprofile
  VOID SimpleProfile_RegisterAppCBs( &ECGSensor_SimpleProfileCBs );

  // Enable clock divide on halt
  // This reduces active current while radio is active and CC254x MCU
  // is halted
  HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_ENABLE_CLK_DIVIDE_ON_HALT );

  // makes sure LEDs are off
  HalLedSet( (HAL_LED_1), HAL_LED_MODE_OFF ); 
  HalLedSet( (HAL_LED_2), HAL_LED_MODE_ON ); 
  
  // Setup a delayed profile startup
  osal_set_event( ECGSensor_TaskID, START_DEVICE_EVT ); 
  
  // 初始化ADS1194
  ADS1194_Init(ECGRate,ECGGain);
}