static void ledConnTimerExpiry(timer_id id) { if(g_weight_hw_data.led_off_conn_tid == id) { /* The application starts LED on timer for LED_ON_CONN_PERIOD after the * expiry of LED off timer in connected state. */ TimerDelete(g_weight_hw_data.led_off_conn_tid); g_weight_hw_data.led_off_conn_tid=TIMER_INVALID; PioSet(LED_PIO, TRUE); g_weight_hw_data.led_on_conn_tid = TimerCreate(LED_ON_CONN_PERIOD,TRUE, ledConnTimerExpiry); } else if(g_weight_hw_data.led_on_conn_tid == id) { /* The application starts LED off timer for LED_OFF_CONN_PERIOD after * the expiry of LED on timer in connected state. */ TimerDelete(g_weight_hw_data.led_on_conn_tid); g_weight_hw_data.led_on_conn_tid=TIMER_INVALID; PioSet(LED_PIO,FALSE); g_weight_hw_data.led_off_conn_tid = TimerCreate(LED_OFF_CONN_PERIOD, TRUE, ledConnTimerExpiry); } }
static void ledAdTimerExpiry(timer_id id) { if(g_weight_hw_data.led_off_ad_tid == id) { /* The application starts LED on timer for LED_ON_AD_PERIOD after the * expiry of LED off timer in advertising state. */ TimerDelete(g_weight_hw_data.led_off_ad_tid); g_weight_hw_data.led_off_ad_tid=TIMER_INVALID; PioSet(LED_PIO, TRUE); g_weight_hw_data.led_on_ad_tid = TimerCreate(LED_ON_AD_PERIOD,TRUE, ledAdTimerExpiry); } else if(g_weight_hw_data.led_on_ad_tid == id) { /* The application starts LED off timer for LED_OFF_AD_PERIOD after the * expiry of LED on timer in advertising state. */ TimerDelete(g_weight_hw_data.led_on_ad_tid); g_weight_hw_data.led_on_ad_tid=TIMER_INVALID; PioSet(LED_PIO,FALSE); g_weight_hw_data.led_off_ad_tid = TimerCreate(LED_OFF_AD_PERIOD,TRUE, ledAdTimerExpiry); } }
void WebcamCapture::run() { Mat orig; // макрос для создания таймера TimerCreate(); while (isRunning()) { TimerUpdate(); vector<unsigned char> m_status; vector<float> m_error; vector<Point2f> trackedPts; // если камера инициализирована и можно считать // изображение, то добавляем в очередь на обработку if (mVideoCapture->isOpened()) { if (mVideoCapture->read(orig)) mDataHandler_out->Write(orig); } else { this->exit(-1); } TimerElapsed(); } // освобождение ресурсов камеры mVideoCapture->release(); this->exit(0); }
TriStatus freettcn::PA::CPlatformAdaptor::TimerStart(const TriTimerId *timerId, TriTimerDuration timerDuration) { if (!timerId) return TRI_ERROR; freettcn::PA::CTimer *timer = 0; // check if timer running already for(CTimerList::const_iterator it=_timerList.begin(); it!=_timerList.end(); ++it) { if (timerId == &(*it)->Id()) { timer = *it; break; } } if (!timer) { // create new timer timer = TimerCreate(*timerId); _timerList.push_back(timer); } timer->Start(timerDuration); if (Logging() && LogMask().Get(freettcn::CLogMask::CMD_PA_T_START)) { TriComponentId comp = { { 0 } }; tliTStart(0, TimeStampMgr().Get(), 0, 0, comp, *timerId, timerDuration); } return TRI_OK; }
/*----------------------------------------------------------------------------* * NAME * dutyCycleTask * * DESCRIPTION * This is the function called when the timer expires. * * Creates a timer for updating the duty cycle on the PWM1. The ramping * effect is produced on the PWM1 by updating its duty cycle periodically * while maintaining constant frequency. * * The PWM1 is configured for its duty cycle from this timer call-back. The * duty cycle is updated from 0% to 100% and then down to 0% and so on. * * PARAMETERS * tid Id of the timer that has just expired. It is not used. * * RETURNS/MODIFIES * None *----------------------------------------------------------------------------*/ static void dutyCycleTask( timer_id const tid ) { static uint8 on_ticks = 0U; static int8 increment_value = 1U; /* Hold the value by which ON time is incremented. When duty cycle is increasing it holds possitive value. When duty cycle is decreasing it holds negative value */ /* Configure the PWM1 to produce a fixed frequency signal, with the same * duty cycle for both the dullest and brightest parts. */ setPwmDutyCycle(on_ticks); if ( on_ticks >= NUMBER_OF_STEPS ) /* When ON time reaches its maximum (i.e. 100% duty cycle) * it should be decremented until it reaches minimum (i.e. 0%) */ { increment_value = -1; } else if ( on_ticks <= 0U ) /* When ON time reaches its minimum (i.e. 0% duty cycle) * it should be incremented until it reaches maximum (i.e. 100%) */ { increment_value = 1; } /* Update ON time for the next update */ on_ticks += increment_value; /* Re-start the timer */ TimerCreate(DUTY_CYCLE_STEP_TIME, TRUE, dutyCycleTask); }
/*----------------------------------------------------------------------------* * NAME * HandleLongButtonPressTimerExpiry * * DESCRIPTION * This function is for handling the long Button press timer expiry * * RETURNS * Nothing. * *----------------------------------------------------------------------------*/ extern void HandleLongButtonPressTimerExpiry(timer_id tid) { if(tid == g_app_hw_data.button_press_tid) { /* Set the long button pressed flag. */ g_app_hw_data.long_button_pressed = TRUE; g_app_hw_data.button_press_tid = TIMER_INVALID; /* long button press timer has expired. Now Start a timer of value * (EXTRA_LONG_BUTTON_PRESS_TIMER - LONG_BUTTON_PRESS_TIMER). * * If application receives the button release event between this time * (EXTRA_LONG_BUTTON_PRESS_TIMER - LONG_BUTTON_PRESS_TIMER), it means * that user has performed an long button press which will handled * accordingly. * * else if this timer expires before button release event then it will * mean that user had performed extra long button press. */ g_app_hw_data.button_press_tid = TimerCreate( EXTRA_LONG_BUTTON_PRESS_TIMER -LONG_BUTTON_PRESS_TIMER, TRUE, HandleExtraLongButtonPressTimerExpiry); } /* else it may be because of some race condition, ignore it */ }
void WebcamCapture::run() { Mat orig; TimerCreate(); while (isRunning()) { TimerUpdate(); vector<unsigned char> m_status; vector<float> m_error; vector<Point2f> trackedPts; if (vc->isOpened()) { if (vc->read(orig)) dh_out->WriteFrame(orig); } else { this->exit(-1); } TimerElapsed(); } vc->release(); this->exit(0); }
extern void timerCallback(timer_id const id) { uint8 hacksplack = 0; uint8 minimap = (g_eeg_serv_data.channel_map & 0x00FF); if ((minimap & 0x01) == 1) hacksplack += 1; if ((minimap & 0x02) == 2) hacksplack += 2; if ((minimap & 0x04) == 4) hacksplack += 4; if ((minimap & 0x08) == 8) hacksplack += 8; if ((minimap & 0x10) == 16) hacksplack += 16; if ((minimap & 0x20) == 32) hacksplack += 32; if ((minimap & 0x40) == 64) hacksplack += 64; if ((minimap & 0x80) == 128) hacksplack += 128; if (hacksplack == 0) hacksplack = 1; readChannels((hacksplack) , &meas_report[0]); #ifdef DEBUG /* writeASCIICodedNumber(minimap); DebugWriteString("\r\n"); writeASCIICodedNumber(hacksplack); DebugWriteString("\r\n"); writeASCIICodedNumber(meas_report[0]); DebugWriteString(" "); writeASCIICodedNumber(meas_report[1]); DebugWriteString("\r\n"); writeASCIICodedNumber(meas_report[2]); DebugWriteString(" "); writeASCIICodedNumber(meas_report[3]); DebugWriteString("\r\n"); writeASCIICodedNumber(meas_report[4]); DebugWriteString(" "); writeASCIICodedNumber(meas_report[5]); DebugWriteString("\r\n"); */ #endif if ((g_eeg_serv_data.acquisition_rate < 1) || (g_eeg_serv_data.acquisition_rate > 900)) g_eeg_serv_data.acquisition_rate = 10000; TimerCreate((TIME) (((uint32) g_eeg_serv_data.acquisition_rate) * 100UL), TRUE, timerCallback); #ifdef DEBUG writeASCIICodedNumber(g_eeg_serv_data.acquisition_rate * 100UL); #endif }
extern void HandlePIOChangedEvent(uint32 pio_changed) { if(pio_changed & PIO_BIT_MASK(BUTTON_PIO)) { /* PIO changed */ uint32 pios = PioGets(); if(!(pios & PIO_BIT_MASK(BUTTON_PIO))) { /* This is for the case when pio changed event has come for button * press. */ /* Delete any button press timer if already running */ TimerDelete(g_app_hw_data.button_press_tid); g_app_hw_data.button_press_tid = TIMER_INVALID; /* Create a button press timer */ g_app_hw_data.button_press_tid = TimerCreate(LONG_BUTTON_PRESS_TIMER, TRUE, handleShortOrLongButtonPressTimerExpiry); /* Initialize the short (or) long button pressed flag with FALSE.*/ g_app_hw_data.long_or_short_button_pressed = FALSE; } else { /* This is for the case when pio changed event comes for * the button release */ if(g_app_hw_data.button_press_tid != TIMER_INVALID) { /* Button press timer is running.This means that either * 1.timer EXTRA_LONG_BUTTON_PRESS_TIMER has not expired yet * OR * 2.Timer EXTRA_LONG_BUTTON_PRESS_TIMER has expired but a 2nd * timer of length (EXTRA_LONG_BUTTON_PRESS_TIMER - * LONG_BUTTON_PRESS_TIMER) which we start on 1st timer * expiry, is still running. */ /* case when timer LONG_BUTTON_PRESS_TIMER is still running */ if(g_app_hw_data.long_or_short_button_pressed == FALSE) { HandleShortButtonPress(); } /* Delete the already running button press timer */ TimerDelete(g_app_hw_data.button_press_tid); g_app_hw_data.button_press_tid = TIMER_INVALID; g_app_hw_data.long_or_short_button_pressed = FALSE; } } } }
extern void GattStartAdverts(bool fast_connection) { /* Variable 'connect_flags' needs to be updated to have peer address type * if Directed advertisements are supported as peer address type will * only be used in that case. We don't support directed advertisements for * this application. */ #ifdef USE_STATIC_RANDOM_ADDRESS uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | L2CAP_OWN_ADDR_TYPE_RANDOM; #else uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | L2CAP_OWN_ADDR_TYPE_PUBLIC; #endif /* USE_STATIC_RANDOM_ADDRESS */ /* Set UCID to INVALID_UCID */ g_hr_data.st_ucid = GATT_INVALID_UCID; /* Set advertisement parameters */ gattSetAdvertParams(fast_connection); /* If white list is enabled, set the controller's advertising filter policy * to "process scan and connection requests only from devices in the White * List" */ if((g_hr_data.enable_white_list == TRUE) && (!GattIsAddressResolvableRandom(&(g_hr_data.bonded_bd_addr)))) { #ifdef USE_STATIC_RANDOM_ADDRESS connect_flags = L2CAP_CONNECTION_SLAVE_WHITELIST | L2CAP_OWN_ADDR_TYPE_RANDOM; #else connect_flags = L2CAP_CONNECTION_SLAVE_WHITELIST | L2CAP_OWN_ADDR_TYPE_PUBLIC; #endif /* USE_STATIC_RANDOM_ADDRESS */ } /* Start GATT connection in Slave role */ GattConnectReq(NULL, connect_flags); /* Start advertisement timer */ if(g_hr_data.advert_timer_value) { TimerDelete(g_hr_data.app_tid); /* Start advertisement timer */ g_hr_data.app_tid = TimerCreate(g_hr_data.advert_timer_value, TRUE, gattAdvertTimerHandler); } }
extern void SetIndication(app_indication state) { #ifdef ENABLE_LEDBLINK if(state == stop_ind) { /* Stop LED glowing */ PioSet(LED_PIO, FALSE); /* Delete LED timers */ TimerDelete(g_weight_hw_data.led_on_ad_tid); g_weight_hw_data.led_on_ad_tid = TIMER_INVALID; TimerDelete(g_weight_hw_data.led_off_ad_tid); g_weight_hw_data.led_off_ad_tid = TIMER_INVALID; TimerDelete(g_weight_hw_data.led_on_conn_tid); g_weight_hw_data.led_on_conn_tid = TIMER_INVALID; TimerDelete(g_weight_hw_data.led_off_conn_tid); g_weight_hw_data.led_off_conn_tid = TIMER_INVALID; } else { if(state == advertising_ind) { /* Create a timer for LED_ON_AD_PERIOD for advertising state */ PioSet(LED_PIO, TRUE); g_weight_hw_data.led_on_ad_tid = TimerCreate(LED_ON_AD_PERIOD,TRUE, ledAdTimerExpiry); } else if(state == connected_ind) { /* Create a timer for LED_ON_CONN_PERIOD for connected state */ PioSet(LED_PIO, TRUE); g_weight_hw_data.led_on_conn_tid = TimerCreate(LED_ON_CONN_PERIOD, TRUE, ledConnTimerExpiry); } } #endif /* ENABLE_LEDBLINK */ }
Log::Log() : timer(nullptr) , mutex(nullptr) { Allocator* alloc = AllocatorGetThis(); timer = TimerCreate(alloc); mutex = MutexCreate(alloc); LogAddHandler(this, LogConsoleHandler); if( !gs_Log ) LogSetDefault(this); }
extern void GattHandleAccessInd(GATT_ACCESS_IND_T *p_ind) { if(p_ind->flags == (ATT_ACCESS_WRITE | ATT_ACCESS_PERMISSION | ATT_ACCESS_WRITE_COMPLETE)) { bool old_hid_notify_status; old_hid_notify_status = AppCheckNotificationStatus(); handleAccessWrite(p_ind); #ifdef PENDING_REPORT_WAIT if(g_kbd_data.pending_report_tid != TIMER_INVALID) { /* Delete the pending timer */ TimerDelete(g_kbd_data.pending_report_tid); g_kbd_data.pending_report_tid = TIMER_INVALID; /* Recreate the timer */ g_kbd_data.pending_report_tid = TimerCreate(PENDING_REPORT_WAIT_TIMEOUT, TRUE, HandlePendingReportsTimerExpiry); } #else /* PENDING_REPORT_WAIT */ /* If notifications are just enabled and Key press is pending/buffered * notify all buffered key presses to the remote host */ bool new_hid_notify_status; new_hid_notify_status = AppCheckNotificationStatus(); if(!old_hid_notify_status && new_hid_notify_status && g_kbd_data.data_pending && g_kbd_data.encrypt_enabled && !g_kbd_data.data_tx_in_progress && !g_kbd_data.waiting_for_fw_buffer) { /* Scanning already on-going, send key-press data stored in queue */ SendKeyStrokesFromQueue(); } #endif } else if(p_ind->flags == (ATT_ACCESS_READ | ATT_ACCESS_PERMISSION)) { handleAccessRead(p_ind); } }
extern void acquireData(timer_id tid) { uint8 channelsActive = count(g_eeg_serv_data.channel_map); TimerDelete(g_eeg_serv_data.acq_tmr); g_eeg_serv_data.acq_tmr = TimerCreate((uint32) (1000000/g_eeg_serv_data.acquisition_rate), TRUE, acquireData); meas_report[3] = channelsActive; uint8 i = 0; for(i = 0; i < channelsActive; i++) { } }
/*----------------------------------------------------------------------------* * NAME * HandlePIOChangedEvent * * DESCRIPTION * This function handles the PIO Changed event. * * PARAMETERS * pio_data [in] State of the PIOs when the event occurred * * RETURNS * Nothing *----------------------------------------------------------------------------*/ extern void HandlePIOChangedEvent(pio_changed_data *pio_data) { if(pio_data->pio_cause & BUTTON_PIO_MASK) { /* PIO changed */ uint32 pios = PioGets(); if(!(pios & BUTTON_PIO_MASK)) { /* This event is triggered when a button is pressed. */ /* Start a timer for EXTRA_LONG_BUTTON_PRESS_TIMER seconds. If the * timer expires before the button is released an extra long button * press is detected. If the button is released before the timer * expires a short button press is detected. */ TimerDelete(g_app_hw_data.button_press_tid); g_app_hw_data.button_press_tid = TimerCreate(EXTRA_LONG_BUTTON_PRESS_TIMER, TRUE, handleExtraLongButtonPress); } else { /* This event comes when a button is released. */ if(g_app_hw_data.button_press_tid != TIMER_INVALID) { /* Timer was already running. This means it was a short button * press. */ TimerDelete(g_app_hw_data.button_press_tid); g_app_hw_data.button_press_tid = TIMER_INVALID; /* Indicate short button press using short beep */ SoundBuzzer(buzzer_beep_short); HandleShortButtonPress(); } } } }
/*----------------------------------------------------------------------------* * NAME * GattTriggerFastAdverts * * DESCRIPTION * This function is used to trigger fast advertisements * * RETURNS * Nothing * *---------------------------------------------------------------------------*/ extern void GattTriggerFastAdverts(void) { CSR_MESH_USER_ADV_PARAMS_T adv_params; /* Reset existing advertising data */ CsrMeshStoreUserAdvData(0, NULL, ad_src_advertise); CsrMeshStoreUserAdvData(0, NULL, ad_src_scan_rsp); #ifdef USE_STATIC_RANDOM_ADDRESS /* Restore the Random Address of the Bluetooth Device */ MemCopy(&adv_params.bd_addr.addr, &g_lightapp_data.random_bd_addr, sizeof(BD_ADDR_T)); adv_params.bd_addr.type = L2CA_RANDOM_ADDR_TYPE; #else adv_params.bd_addr.type = L2CA_PUBLIC_ADDR_TYPE; #endif /* USE_STATIC_RANDOM_ADDRESS */ /* Set GAP peripheral params */ adv_params.role = gap_role_peripheral; adv_params.bond = gap_mode_bond_no; adv_params.connect_mode = gap_mode_connect_undirected; adv_params.discover_mode = gap_mode_discover_general; adv_params.security_mode = gap_mode_security_unauthenticate; g_lightapp_data.gatt_data.advert_timer_value = ADVERT_INTERVAL + appRandomDelay(); /* If GATT bearer is enabled send connectable advert */ if(g_lightapp_data.bearer_data.bearerEnabled & BLE_GATT_SERVER_BEARER_MASK) { /* Set advertisement parameters */ gattSetAdvertParams(TRUE); /* Send a connectable advertisement */ CsrMeshSendUserAdvert(&adv_params); /* Restart the advertising timer */ TimerDelete(g_lightapp_data.gatt_data.app_tid); g_lightapp_data.gatt_data.app_tid = TimerCreate( g_lightapp_data.gatt_data.advert_timer_value, TRUE, gattAdvertTimerHandler); } }
extern void HandlePIOChangedEvent(pio_changed_data *pio_data) { if(pio_data->pio_cause & BUTTON_PIO_MASK) { /* PIO changed */ uint32 pios = PioGets(); if(!(pios & BUTTON_PIO_MASK)) { /* This event comes when a button is pressed */ /* Start a timer for EXTRA_LONG_BUTTON_PRESS_TIMER seconds. * If timer expires before we receive a button release event then * it was a long press and if we receive a button release PIO * changed event, it means it was a short press. */ TimerDelete(g_weight_hw_data.button_press_tid); g_weight_hw_data.button_press_tid = TIMER_INVALID; g_weight_hw_data.button_press_tid = TimerCreate( EXTRA_LONG_BUTTON_PRESS_TIMER, TRUE, HandleExtraLongButtonPress); } else { if(g_weight_hw_data.button_press_tid != TIMER_INVALID) { /* Timer was already running. This means it was a short button * press. */ TimerDelete(g_weight_hw_data.button_press_tid); g_weight_hw_data.button_press_tid = TIMER_INVALID; AppHandleShortButtonPress(); } } } }
void ProcessingThread::run() { Mat orig, previmg, output, mask; vector<Point2f> prev_pts, orig_pts; vector<uchar> m_status; Mat m_error; TimerCreate(); while (isRunning()) { while (dh_in->ReadFrame(orig)) { TimerUpdate(); OpticalFlowHandle(previmg, orig, prev_pts, orig_pts); TimerElapsed(); } yieldCurrentThread(); } }
void udelay(int us) { u8 heap[0x10]; u32 msg; s32 mqueue = -1; s32 timer = -1; mqueue = mqueue_create(heap, 1); if(mqueue < 0) goto out; timer = TimerCreate(us, 0, mqueue, 0xbabababa); if(timer < 0) goto out; mqueue_recv(mqueue, &msg, 0); out: if(timer > 0) TimerDestroy(timer); if(mqueue > 0) mqueue_destroy(mqueue); }
extern void GattStartAdverts(bool fast_connection, gap_mode_connect connect_mode) { uint16 connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | L2CAP_OWN_ADDR_TYPE_PUBLIC; /* Set UCID to INVALID_UCID */ g_btcar_data.st_ucid = GATT_INVALID_UCID; /* Set advertisement parameters */ gattSetAdvertParams(fast_connection, connect_mode); if(g_btcar_data.bonded && !IsAddressResolvableRandom(&g_btcar_data.bonded_bd_addr) && !IsAddressNonResolvableRandom(&g_btcar_data.bonded_bd_addr)) { if(connect_mode == gap_mode_connect_directed) { connect_flags = L2CAP_CONNECTION_SLAVE_DIRECTED | L2CAP_OWN_ADDR_TYPE_PUBLIC | L2CAP_PEER_ADDR_TYPE_PUBLIC; } else { /* When the device is bonded, set the advertising filter policy to * "process scan and connection requests only from devices in white * list" */ connect_flags = L2CAP_CONNECTION_SLAVE_WHITELIST | L2CAP_OWN_ADDR_TYPE_PUBLIC; } } #ifdef __GAP_PRIVACY_SUPPORT__ /*Check if privacy enabled */ if(IsGapPeripheralPrivacyEnabled()) { if(connect_mode == gap_mode_connect_directed) { /* Set advAddress to reconnection address. */ GapSetRandomAddress(GapGetReconnectionAddress()); connect_flags = L2CAP_CONNECTION_SLAVE_DIRECTED | L2CAP_OWN_ADDR_TYPE_RANDOM | L2CAP_PEER_ADDR_TYPE_RANDOM; } else { /* Generate Resolvable random address and use it as advAddress. */ SMPrivacyRegenerateAddress(NULL); if(g_btcar_data.bonded_bd_addr.type == L2CA_RANDOM_ADDR_TYPE) { /* Change to random address */ connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | L2CAP_OWN_ADDR_TYPE_RANDOM | L2CAP_PEER_ADDR_TYPE_RANDOM; } else { /* Change to random address */ connect_flags = L2CAP_CONNECTION_SLAVE_UNDIRECTED | L2CAP_OWN_ADDR_TYPE_RANDOM | L2CAP_PEER_ADDR_TYPE_PUBLIC; } } } #endif /* __GAP_PRIVACY_SUPPORT__ */ /* Start GATT connection in Slave role */ GattConnectReq(NULL, connect_flags); /* Start advertisement timer */ if(g_btcar_data.advert_timer_value) { TimerDelete(g_btcar_data.app_tid); /* Start advertisement timer */ g_btcar_data.app_tid = TimerCreate(g_btcar_data.advert_timer_value, TRUE, gattAdvertTimerHandler); } }
extern void HeartRateHandleAccessWrite(GATT_ACCESS_IND_T *p_ind) { uint8 *p_value = p_ind->value; gatt_client_config client_config; sys_status rc = sys_status_success; switch(p_ind->handle) { /* Heart Rate measurement characteristic client configuration is being * written */ case HANDLE_EEG_MEASUREMENT_C_CFG: { client_config = BufReadUint16(&p_value); /* Client Configuration is bit field value so ideally bitwise * comparison should be used but since the application supports only * notifications, direct comparison is being used. */ if((client_config == gatt_client_config_notification) || (client_config == gatt_client_config_none)) { /* Store the new client configuration */ g_eeg_serv_data.hr_meas_client_config = client_config; /* Write Heart Rate Measurement Client configuration to NVM if * the device is bonded. */ if(AppIsDeviceBonded()) { Nvm_Write((uint16*)&client_config, sizeof(client_config), g_eeg_serv_data.nvm_offset + HR_NVM_HR_MEAS_CLIENT_CONFIG_OFFSET); } /* Start sending the HR measurement notifications if they are * not being sent currently. */ StartSendingHRMeasurements(); } else { /* INDICATION or RESERVED */ /* Return Error as only Notifications are supported */ rc = gatt_status_desc_improper_config; } break; } /* EEG channels Control point is being written */ case HANDLE_EEG_CHANNELS: { /* Extract the written value */ g_eeg_serv_data.channel_map = BufReadUint16(&p_value); DebugWriteString("\n\rChannel map updated"); break; } case HANDLE_EEG_ACQUISITION_RATE: { g_eeg_serv_data.acquisition_rate = BufReadUint16(&p_value); TimerDelete(g_eeg_serv_data.acq_tmr); g_eeg_serv_data.acq_tmr = TimerCreate((uint32) (1000000/g_eeg_serv_data.acquisition_rate), TRUE, acquireData); DebugWriteString("\n\rAcq Rate changed"); break; } default: { /* Write is not permitted on any other characteristic/attribute */ rc = gatt_status_write_not_permitted; break; } } /* Send ACCESS RESPONSE */ GattAccessRsp(p_ind->cid, p_ind->handle, rc, 0, NULL); }
/*----------------------------------------------------------------------------* * NAME * SoundBuzzer * * DESCRIPTION * This function is called to trigger beeps of different types, enumerated * by 'buzzer_beep_type'. * * PARAMETERS * beep_type [in] Type of beep required * * RETURNS * Nothing *----------------------------------------------------------------------------*/ extern void SoundBuzzer(buzzer_beep_type beep_type) { /* Duration of beep */ uint32 beep_timer = SHORT_BEEP_TIMER_VALUE; /* Disable the buzzer and stop the buzzer timer. */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); if (g_buzz_data.buzzer_tid != TIMER_INVALID) { TimerDelete(g_buzz_data.buzzer_tid); g_buzz_data.buzzer_tid = TIMER_INVALID; } /* Reset the beeper state */ g_buzz_data.beep_count = 0; /* Store the beep type. It will be used on timer expiry to check the type of * beep being sounded. */ g_buzz_data.beep_type = beep_type; switch(g_buzz_data.beep_type) { case buzzer_beep_off: { /* Don't do anything */ } break; case buzzer_beep_short: /* One short beep will be sounded */ /* FALLTHROUGH */ case buzzer_beep_twice: /* Two short beeps will be sounded */ /* FALLTHROUGH */ case buzzer_beep_thrice: /* Three short beeps will be sounded */ { beep_timer = SHORT_BEEP_TIMER_VALUE; } break; case buzzer_beep_long: { /* One long beep will be sounded */ beep_timer = LONG_BEEP_TIMER_VALUE; } break; default: { /* No such beep type defined */ ReportPanic(app_panic_unexpected_beep_type); } break; } if(g_buzz_data.beep_type != buzzer_beep_off) { /* Enable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, TRUE); /* Start the buzzer timer */ g_buzz_data.buzzer_tid = TimerCreate(beep_timer, TRUE, appBuzzerTimerHandler); } }
/*----------------------------------------------------------------------------* * NAME * appBuzzerTimerHandler * * DESCRIPTION * This function is used to stop the Buzzer at the expiry of * timer. * * RETURNS * Nothing. * *----------------------------------------------------------------------------*/ static void appBuzzerTimerHandler(timer_id tid) { uint32 beep_timer = SHORT_BEEP_TIMER_VALUE; g_app_hw_data.buzzer_tid = TIMER_INVALID; switch(g_app_hw_data.beep_type) { case beep_short: /* FALLTHROUGH */ case beep_long: { g_app_hw_data.beep_type = beep_off; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); } break; case beep_twice: { if(g_app_hw_data.beep_count == 0) { /* First beep sounded. Start the silent gap*/ g_app_hw_data.beep_count = 1; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); /* Time gap between two beeps */ beep_timer = BEEP_GAP_TIMER_VALUE; } else if(g_app_hw_data.beep_count == 1) { g_app_hw_data.beep_count = 2; /* Enable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, TRUE); /* Start beep */ beep_timer = SHORT_BEEP_TIMER_VALUE; } else { /* Two beeps have been sounded. Stop buzzer now*/ g_app_hw_data.beep_count = 0; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); g_app_hw_data.beep_type = beep_off; } } break; case beep_thrice: { if(g_app_hw_data.beep_count == 0 || g_app_hw_data.beep_count == 2) { /* First beep sounded. Start the silent gap*/ g_app_hw_data.beep_count++; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); /* Time gap between two beeps */ beep_timer = BEEP_GAP_TIMER_VALUE; } else if(g_app_hw_data.beep_count == 1 || g_app_hw_data.beep_count == 3) { g_app_hw_data.beep_count++; /* Enable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, TRUE); beep_timer = SHORT_BEEP_TIMER_VALUE; } else { /* Two beeps have been sounded. Stop buzzer now*/ g_app_hw_data.beep_count = 0; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); g_app_hw_data.beep_type = beep_off; } } break; default: { /* No such beep type */ ReportPanic(app_panic_unexpected_beep_type); /* Though break statement will not be executed after panic but this * has been kept to avoid any confusion for default case. */ } break; } if(g_app_hw_data.beep_type != beep_off) { /* start the timer */ g_app_hw_data.buzzer_tid = TimerCreate(beep_timer, TRUE, appBuzzerTimerHandler); } }
/*----------------------------------------------------------------------------* * NAME * SoundBuzzer * * DESCRIPTION * Function for sounding beeps. * * RETURNS * Nothing. * *----------------------------------------------------------------------------*/ extern void SoundBuzzer(buzzer_beep_type beep_type) { #ifdef ENABLE_BUZZER uint32 beep_timer = SHORT_BEEP_TIMER_VALUE; PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); TimerDelete(g_app_hw_data.buzzer_tid); g_app_hw_data.buzzer_tid = TIMER_INVALID; g_app_hw_data.beep_count = 0; /* Store the beep type in some global variable. It will used on timer expiry * to check the type of beeps being sounded. */ g_app_hw_data.beep_type = beep_type; switch(g_app_hw_data.beep_type) { case beep_off: { /* Don't do anything */ } break; case beep_short: /* FALLTHROUGH */ case beep_twice: /* Two short beeps will be sounded */ /* FALLTHROUGH */ case beep_thrice: /* Three short beeps will be sounded */ { /* One short beep will be sounded */ beep_timer = SHORT_BEEP_TIMER_VALUE; } break; case beep_long: { /* One long beep will be sounded */ beep_timer = LONG_BEEP_TIMER_VALUE; } break; break; default: { /* No such beep type defined */ ReportPanic(app_panic_unexpected_beep_type); /* Though break statement will not be executed after panic but this * has been kept to avoid any confusion for default case. */ } break; } if(g_app_hw_data.beep_type != beep_off) { /* Initialize beep count to zero */ g_app_hw_data.beep_count = 0; /* Enable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, TRUE); TimerDelete(g_app_hw_data.buzzer_tid); g_app_hw_data.buzzer_tid = TimerCreate(beep_timer, TRUE, appBuzzerTimerHandler); } #endif /* ENABLE_BUZZER */ }
/*----------------------------------------------------------------------------* * NAME * appBuzzerTimerHandler * * DESCRIPTION * This function is used to stop the Buzzer at the expiry of timer. * * PARAMETERS * tid [in] ID of expired timer (unused) * * RETURNS * Nothing *----------------------------------------------------------------------------*/ static void appBuzzerTimerHandler(timer_id tid) { /* Duration of next timer */ uint32 beep_timer = SHORT_BEEP_TIMER_VALUE; /* The buzzer timer has just expired, so reset the timer ID */ g_buzz_data.buzzer_tid = TIMER_INVALID; switch(g_buzz_data.beep_type) { case buzzer_beep_short: /* FALLTHROUGH */ case buzzer_beep_long: { g_buzz_data.beep_type = buzzer_beep_off; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); } break; case buzzer_beep_twice: { if(g_buzz_data.beep_count == 0) { /* First beep sounded. Increment the beep count and start the * silent gap. */ g_buzz_data.beep_count = 1; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); /* Time gap between two beeps */ beep_timer = BEEP_GAP_TIMER_VALUE; } else if(g_buzz_data.beep_count == 1) { /* Sound the second beep and increment the beep count. */ g_buzz_data.beep_count = 2; /* Enable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, TRUE); /* Start another short beep */ beep_timer = SHORT_BEEP_TIMER_VALUE; } else { /* Two beeps have been sounded. Stop buzzer now and reset the * beep count. */ g_buzz_data.beep_count = 0; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); g_buzz_data.beep_type = buzzer_beep_off; } } break; case buzzer_beep_thrice: { if(g_buzz_data.beep_count == 0 || g_buzz_data.beep_count == 2) { /* Start the silent gap*/ ++g_buzz_data.beep_count; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); /* Time gap between two beeps */ beep_timer = BEEP_GAP_TIMER_VALUE; } else if(g_buzz_data.beep_count == 1 || g_buzz_data.beep_count == 3) { /* Start the beep sounding part. */ ++g_buzz_data.beep_count; /* Enable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, TRUE); beep_timer = SHORT_BEEP_TIMER_VALUE; } else { /* Three beeps have been sounded. Stop the buzzer. */ g_buzz_data.beep_count = 0; /* Disable buzzer */ PioEnablePWM(BUZZER_PWM_INDEX_0, FALSE); g_buzz_data.beep_type = buzzer_beep_off; } } break; default: { /* No such beep type */ ReportPanic(app_panic_unexpected_beep_type); } break; } if(g_buzz_data.beep_type != buzzer_beep_off) { /* Start the timer */ g_buzz_data.buzzer_tid = TimerCreate(beep_timer, TRUE, appBuzzerTimerHandler); } }
int asyncmsg_connect_attach(uint32_t nd, pid_t pid, int chid, unsigned index, unsigned flags, const struct _asyncmsg_connection_attr *attr) { struct _asyncmsg_connect_context *acc; struct _asyncmsg_connection_descriptor *acd; int id, size; static pthread_mutex_t _async_init_mutex = PTHREAD_MUTEX_INITIALIZER; _mutex_lock(&_async_init_mutex); if (!_async_ev) { int chid; if ((_async_ev = malloc(sizeof(*_async_ev))) == NULL) { _mutex_unlock(&_async_init_mutex); return -1; } if ((chid = ChannelCreate(0)) == -1) { free(_async_ev); _async_ev = NULL; _mutex_unlock(&_async_init_mutex); return -1; } if ((_async_ev->sigev_coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0)) == -1) { ChannelDestroy(chid); free(_async_ev); _async_ev = NULL; _mutex_unlock(&_async_init_mutex); return -1; } _async_ev->sigev_notify = SIGEV_PULSE; _async_ev->sigev_priority = SIGEV_PULSE_PRIO_INHERIT; if ((errno = pthread_create(&_async_ev_tid, NULL, _async_event_thread, (void *)chid)) != EOK) { ConnectDetach(_async_ev->sigev_coid); ChannelDestroy(chid); free(_async_ev); _async_ev = NULL; _mutex_unlock(&_async_init_mutex); return -1; } } _mutex_unlock(&_async_init_mutex); size = sizeof(*acc) + sizeof(struct _asyncmsg_put_header) * attr->max_num_buffer; acc = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_PHYS, NOFD, 0); if (acc == (struct _asyncmsg_connect_context *)MAP_FAILED) { return -1; } memset(acc, 0, sizeof(*acc)); acd = &acc->acd; flags |= _NTO_COF_NOSHARE; acd->attr = *attr; acd->flags = flags; acd->sendq_size = attr->max_num_buffer; acd->sendq = (struct _asyncmsg_put_header *)((char *)acc + sizeof(*acc)); if ((id = ConnectAttachExt(nd, pid, chid, index, flags, acd)) == -1) { return -1; } acd->sendq_head = acd->sendq_tail = acd->sendq_free = 0; acd->ev = *_async_ev; acd->ev.sigev_value.sival_int = id; acd->ev.sigev_code = 'T'; if ((acd->ttimer = TimerCreate(CLOCK_REALTIME, &acd->ev)) == (timer_t)-1) { asyncmsg_connect_detach(id); return -1; } acc->flags = _ASYNCMSG_CONNECT_TIMEROFF; acd->ev.sigev_code = 'P'; if ((errno = pthread_mutex_init(&acd->mu, 0)) != EOK) { asyncmsg_connect_detach(id); return -1; } if ((errno = pthread_cond_init(&acd->block_con, 0)) != EOK) { asyncmsg_connect_detach(id); return -1; } if (_asyncmsg_handle(id, _ASYNCMSG_HANDLE_ADD, acc) == NULL) { asyncmsg_connect_detach(id); return -1; } return id; }
/*----------------------------------------------------------------------------* * NAME * processRxData * * DESCRIPTION * This function peeks the data from the queue and sends it to the remote * device. * * RETURNS * Nothing * *----------------------------------------------------------------------------*/ extern void processRxData(void) { uint8 data[SERIAL_RX_DATA_LENGTH]; /* Data to be sent */ uint16 size_val; /* Length of the data to be sent */ /* Length of data available in the queue */ uint16 length = BQGetDataSize(SEND_QUEUE_ID); /* Proceed only if byte queue is not empty */ if(length > 0) { /* Make sure that the maximum data length is not exceeded */ size_val = length > SERIAL_RX_DATA_LENGTH ? SERIAL_RX_DATA_LENGTH : length; if(length < SERIAL_RX_DATA_LENGTH) { /* Length of the data is less than serial data length. */ if(g_is_current_baud_rate_high) { if (g_partial_buffer_timer_tid == TIMER_INVALID) { /* Create partial buffer timer */ g_partial_buffer_timer_tid = TimerCreate( PARTIAL_BUFFER_WAIT_TIME_HIGH, TRUE, sendPartialBuffer); } } else { if (g_partial_buffer_timer_tid == TIMER_INVALID) { /* Create partial buffer timer */ g_partial_buffer_timer_tid = TimerCreate( PARTIAL_BUFFER_WAIT_TIME_LOW, TRUE, sendPartialBuffer); } } } else { if (g_partial_buffer_timer_tid != TIMER_INVALID) { /* Kill the partial buffer timer. */ TimerDelete(g_partial_buffer_timer_tid); g_partial_buffer_timer_tid = TIMER_INVALID; } if (BQPeekBytes(data, size_val,SEND_QUEUE_ID) > 0) { /* Make a note of the data length which is being sent. */ length_data_peeked = size_val; if(ExecuteWriteCommandOnSerialDataTransferCharacteristic( GetConnectionIdentifier(), data, size_val) != gatt_status_busy) { /* Pop the data out from the send queue */ BQPopBytes(data, size_val,SEND_QUEUE_ID); /* Reset the peeked variable */ length_data_peeked = 0; } else { /* Transmission failed. Just reset the peeked variable */ length_data_peeked = 0; /* Configure for Radio Tx Event */ ConfigureRadioTxEvent(); } } } } }