int main(void) { char incoming; OT_init(); EthernetInit(); UART0_Init(9600); TimerInit(0, 1000); TimerInit(3, 120000000); //delayMs(0,1000); //enable_timer(3); while(1) { EthernetHandle(); //UARTHandle(); if(UART0_Available()) { UARTLED_ON; incoming = UART0_Getchar(); gw_char(incoming); UARTLED_OFF; } } }
uint8 InitDevice()//TODO:异常处理 { uint8 r=0,t=0; //GPIO PinInit(); IO0DIR=1<<29|1<<30;//P0.29,P0.30必须同为输出才能输出(SSP0的片选). //GpioSpeedHigh();//全局高速模式,因为P0.29问题无法使用。 //指示系统启动 LED1ON(); //UART0-GCS r+=UARTInit(FCUARTPORT,FCUARTBPS);//UART0-PC UARTSendChar(FCUARTPORT,0x40); UARTSendChar(FCUARTPORT,0x40); //UART2-INS r+=UARTInit(INSUARTPORT,INSUARTBPS); //UARTSendChar(2,0x40); //UARTSendChar(2,0x40); //SSP0-FPGA r+=SSP0FPGAMode(); //r+=SPIInit(); //while(1) //{ t=FPGACheck(); //} if(t==TRUE) { FCEventSend(OKFPGA); } else { FCEventSend(ErrFPGA); } r+=t; //SSP1-FLASH r+=FlashInit(FlashQueueSize); //Timer0-MainLoop r+=TimerInit(0,1000/MainLoopHz); TimerDisable(0); //TimerEnable(0); //Timer1-Time+LED1 r+=TimerInit(1,1000); TimerEnable(1); //Timer2-Working-LED2 r+=TimerInit(2,100); TimerDisable(2); //启动中断 IRQEnable(); return r; }
bool MQTTClientInit(MQTTClient *c, Network *network, unsigned int command_timeout_ms, unsigned char *sendbuf, size_t sendbuf_size, unsigned char *readbuf, size_t readbuf_size) { int i; c->ipstack = network; for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i) { c->messageHandlers[i].topicFilter = 0; } if (command_timeout_ms != 0) { c->command_timeout_ms = command_timeout_ms; } else { c->command_timeout_ms = CONFIG_MQTT_SEND_CYCLE; } if (sendbuf) { c->buf = sendbuf; c->buf_size = sendbuf_size; } else { c->buf = (unsigned char *)malloc(CONFIG_MQTT_SEND_BUFFER); if (c->buf) { c->buf_size = CONFIG_MQTT_SEND_BUFFER; } else { return false; } } if (readbuf) { c->readbuf = readbuf; c->readbuf_size = readbuf_size; } else { c->readbuf = (unsigned char *)malloc(CONFIG_MQTT_RECV_BUFFER); if (c->readbuf) { c->readbuf_size = CONFIG_MQTT_RECV_BUFFER; } else { return false; } } c->isconnected = 0; c->cleansession = 0; c->ping_outstanding = 0; c->defaultMessageHandler = NULL; c->next_packetid = 1; TimerInit(&c->last_sent); TimerInit(&c->last_received); TimerInit(&c->ping_wait); #if defined(MQTT_TASK) MutexInit(&c->mutex); #endif return true; }
// @brief : To initialise port pin for user switch input. // @param : none // @retval void SwitchInit() { EXTI_InitTypeDef EXTI_InitStruct; NVIC_InitTypeDef NVIC_InitStruct; // USER_SW_PORT is defined as PA14 GPIO_Init_Mode(USER_SW_PORT, USER_SW_PIN, GPIO_Mode_IN_FLOATING); EXTI_InitStruct.EXTI_Line = EXTI_Line14; EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStruct.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStruct); NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = SWITCH_PRIORITY; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); bSWFlag = FALSE; SWstate = SW_LOW; SW_PRESS_TIME = 0; TimerInit(TIM_SWITCH); }
int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter) { int rc = FAILURE; Timer timer; MQTTString topic = MQTTString_initializer; topic.cstring = (char *)topicFilter; int len = 0; #if defined(MQTT_TASK) FreeRTOS_MutexLock(&c->mutex); #endif if (!c->isconnected) goto exit; TimerInit(&timer); TimerCountdownMS(&timer, c->command_timeout_ms); if ((len = MQTTSerialize_unsubscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic)) <= 0) goto exit; if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet goto exit; // there was a problem if (waitfor(c, UNSUBACK, &timer) == UNSUBACK) { unsigned short mypacketid; // should be the same as the packetid above if (MQTTDeserialize_unsuback(&mypacketid, c->readbuf, c->readbuf_size) == 1) rc = 0; } else rc = FAILURE; exit: #if defined(MQTT_TASK) FreeRTOS_MutexUnlock(&c->mutex); #endif return rc; }
/****************************************************************************** * * Name: smeMain_Init * * Description: * This routine is called to initialize the the SME Task and related * components. * * Conditions For Use: * None. * * Arguments: * None. * * Return Value: * Status indicating success or failure * * Notes: * None. * * PDL: * Call smeQ_Init() * If the queue was successfully initialized Then * Create the SME Task by calling os_TaskCreate() * If creating the SME Task succeeded Then * Return OS_SUCCESS * End If * End If * * Return OS_FAIL * END PDL * *****************************************************************************/ extern WL_STATUS smeMain_Init( vmacApInfo_t *vmacSta_p ) { // WL_STATUS status; #ifdef IEEE80211H { UINT8 ChannelList[IEEE_80211_MAX_NUMBER_OF_CHANNELS]; /* the assumption of NULL-terminated is made */ memset(ChannelList, 0, IEEE_80211_MAX_NUMBER_OF_CHANNELS); /* get regulatory maximum tx power */ domainGetInfo(ChannelList); /* init channel utilization information database */ semChannelUtilizationInit(ChannelList); } TimerInit(&vmacSta_p->reqMeasurementTimer); #endif /* IEEE80211H */ #ifdef AP_MAC_LINUX #ifdef IEEE80211H_NOTWIFI /* Start MREQUEST periodic timer (10 mins interval) */ TimerFireEvery(&vmacSta_p->reqMeasurementTimer, 1, &StartSendMREQUESTCmd, vmacSta_p, 50); #endif /* IEEE80211H */ #endif // SendStartCmd(); return(OS_SUCCESS); }
void PapStart(Link l, int which) { PapInfo pap = &l->lcp.auth.pap; switch (which) { case AUTH_PEER_TO_SELF: /* Just wait for peer's request */ break; case AUTH_SELF_TO_PEER: /* Initialize retry counter and timer */ pap->next_id = 1; pap->retry = AUTH_RETRIES; TimerInit(&pap->timer, "PapTimer", l->conf.retry_timeout * SECONDS, PapTimeout, l); TimerStart(&pap->timer); /* Send first request */ PapSendRequest(l); break; default: assert(0); } }
/****************************************************************************** * * @name TimerQInitialize * * @brief Initializes RTC, Timer Object Queue and System Clock Counter * * @param controller_ID : Controller ID * * @return None ***************************************************************************** * This function initializes System Clock Counter, Timer Queue and Initializes * System Timer *****************************************************************************/ uint_8 TimerQInitialize(uint_8 controller_ID) { UNUSED (controller_ID) (void)memset(g_TimerObjectArray, (int)NULL, sizeof(g_TimerObjectArray)); return TimerInit(); }
FSTATUS MulticastInitialize(void) { FSTATUS Status; _DBG_ENTER_LVL(_DBG_LVL_FUNC_TRACE, InitializeMulticast); McSdHandle = NULL; QListInit(&MasterMcGroupList); QListInit(&MasterMcClientList); SpinLockInitState(&MulticastLock); SpinLockInit(&MulticastLock); TimerInitState(&MaintenanceTimer); TimerInit(&MaintenanceTimer, McMaintenance, NULL); MaintenanceTimerActivated = FALSE; Status = iba_sd_register(&McSdHandle, NULL); if (Status != FSUCCESS) { McSdHandle = NULL; _DBG_ERROR(("Multicast Module Not Able To Register With Subnet Driver " "Status = %d.\n", Status)); } _DBG_LEAVE_LVL( _DBG_LVL_FUNC_TRACE ); return Status; }
//主程序 int main() { INT8U remember; DISABLE_INTERRUPTS; //禁止总中断 //1. 芯片初始化 MCUInit(); //2. 模块初始化 SCIInit(); //(1) 串口初始化 TimerInit(); //(2) 定时器1初始化 //3. 内存初始化 //(1) "时分秒"缓存初始化(00:00:00) time[0] = 0; time[1] = 0; time[2] = 0; //(2) 临时变量remember初始化 remember = time[2]; //(3) 全局变量TimInterCount初始化 TimInterCount = 0; //4. 开放各模块中断 EnableSCIReInt; //(1) 开放SCI0接收中断 EnableT1OVInt; //(2) 开放定时器1溢出中断 //5. 开放总中断 ENABLE_INTERRUPTS; //开总中断 while (1) { if (time[2] != remember) { SCISendN(3, time); //发送当前"时分秒" remember = time[2]; //remember中存放当前秒值 } } }
void MQTTRun(void *parm) { Timer timer; MQTTClient *c = (MQTTClient *)parm; TimerInit(&timer); while (1) { TimerCountdownMS(&timer, CONFIG_MQTT_RECV_CYCLE); /* Don't wait too long if no traffic is incoming */ #if CONFIG_MQTT_RECV_CYCLE == 0 /* The smaller cycle, the greater throughput */ esp_task_wdt_reset(); #endif #if defined(MQTT_TASK) MutexLock(&c->mutex); #endif int rc = cycle(c, &timer); if (rc == FAILURE) { ESP_LOGE(TAG, "MQTTRun cycle failed"); #if defined(MQTT_TASK) MutexUnlock(&c->mutex); #endif vTaskDelete(NULL); } #if defined(MQTT_TASK) MutexUnlock(&c->mutex); #endif } }
void F4Timer::set_period(uint32_t period) { if(TIM1==TIMx) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); if(TIM2==TIMx) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); if(TIM3==TIMx) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); if(TIM4==TIMx) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE); if(TIM5==TIMx) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE); if(TIM6==TIMx) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE); TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_DeInit(TIMx); TIM_InternalClockConfig(TIMx); TIM_TimeBaseStructure.TIM_Prescaler=167;//1Mhz 1us 65536 TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period=period; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0; TIM_TimeBaseInit(TIMx,&TIM_TimeBaseStructure); TIM_ClearFlag(TIMx,TIM_FLAG_Update); TIM_ARRPreloadConfig(TIMx,DISABLE); TIM_ITConfig(TIMx,TIM_IT_Update,ENABLE); TIM_Cmd(TIMx,ENABLE); TimerInit(this->TIMx); }
void _CRTAPI1 Zqsort (void * Arg1, size_t Arg2, size_t Arg3, int (_CRTAPI1 * Arg4)(const void *, const void *)) { SHORT sTimerHandle; ULONG ulElapsedTime; if (fInitDone == FALSE) { ApfInitDll(); } TimerOpen(&sTimerHandle, MICROSECONDS); TimerInit(sTimerHandle); // // Call the api // qsort(Arg1,Arg2,Arg3,Arg4); // // Get the elapsed time // ulElapsedTime = TimerRead(sTimerHandle); ApfRecordInfo(I_qsort, ulElapsedTime); TimerClose(sTimerHandle); return; }
void test2_click_to_measure_btnclicked(GtkWidget *widget, gpointer user_data) { long int Delay = 0xFFFFFFFF; start_timer = 1; wait_for_5sec = 1; GtkWidget *feed_back; feed_back = GTK_WIDGET (gtk_builder_get_object (Test2Builder, "label9")); gtk_label_set_label (feed_back, "Please hold the handles"); /* while(BLITestEn==1){ while(Delay>0){ Delay--; } GetBliOutput(); Delay = 0xFFFFFFFF; } */ BLITestEn=1; test2_button_set_state(FALSE); Minutes = 0; Seconds = 0; test_timeout = BODYFAT_TIMEOUT; StartTimer = 1; TimerInit(); return; }
int _CRTAPI1 Z_execl (const char* Arg1,const char* Arg2, DWORD64ARGS) { int RetVal; SHORT sTimerHandle; ULONG ulElapsedTime; if (fInitDone == FALSE) { ApfInitDll(); } TimerOpen(&sTimerHandle, MICROSECONDS); TimerInit(sTimerHandle); // // Call the api // RetVal = _execl(Arg1,Arg2, ARGS64); // // Get the elapsed time // ulElapsedTime = TimerRead(sTimerHandle); ApfRecordInfo(I__execl, ulElapsedTime - ApfData[I_CALIBRATE].ulFirstTime); TimerClose(sTimerHandle); return(RetVal); }
void INIT NORETURN kMain(unsigned int mBootCode, multiboot_info_t * mBootInfo) { //Kernel C Entry Point // Check boot code if(mBootCode != MULTIBOOT_BOOTLOADER_MAGIC) { Panic("kMain: OS must be loaded by a multiboot bootloader"); } // Wipe screen MemSet((void *) 0xC00B8000, 0, 0xFA0); // Core Initialization (most other stuff depends on this) IntrInit(); CpuInit(); MemManagerInit(mBootInfo); MemSlabInit(); // Other Initializations CpuInitLate(); TimerInit(); ProcInit(); IoBlockCacheInit(); IoDevFsInit(); // Exit boot mode MemFreeInitPages(); ProcIntSelfExit(); }
int MQTTDisconnect(MQTTClient *c) { int rc = FAILURE; Timer timer; // we might wait for incomplete incoming publishes to complete int len = 0; #if defined(MQTT_TASK) MutexLock(&c->mutex); #endif TimerInit(&timer); TimerCountdownMS(&timer, c->command_timeout_ms); len = MQTTSerialize_disconnect(c->buf, c->buf_size); if (len > 0) { rc = sendPacket(c, len, &timer); // send the disconnect packet } MQTTCloseSession(c); #if defined(MQTT_TASK) MutexUnlock(&c->mutex); #endif return rc; }
//Code blocks in the preamble are labelled with the names //of the libraries in which the used functions are defined. //Look in these to discover fundamental definitions. void main(void) { EALLOW;//an assembly language thing required to allow access to system control registers SysCtrlRegs.WDCR = 0x68;//disable watchdog //clock SysClkInit(FIFTY);//set the system clock to 50MHz //gpio Uint8 out[3] = {31, 34};//0 is !shdn on wifi GpioOutputsInit(out, 2); //34 is a pin that goes high/low each second //interrupts //31 is ld2: lights when wifi is sending IsrInit(TINT0, &timerISR); IsrInit(ADCINT2, &adcISR); //adc AdcInit(); AdcSetClock(FOURTH); AdcSetupSOC(SOC3, ADCB6, SOFTWARE); AdcEnableIsr(SOC3, ADCINT2); //clock TimerInit(1.0);//set the timer to 1kHz and start. Relies on SysClkInit, so call that first. EDIS;//disallow access to system control registers while(1) { loopcnt++; } }
int keepalive(MQTTClient *c) { int rc = SUCCESS; if (c->keepAliveInterval == 0) { goto exit; } if (TimerIsExpired(&c->last_sent) || TimerIsExpired(&c->last_received)) { if (c->ping_outstanding && TimerIsExpired(&c->ping_wait)) { rc = FAILURE; /* PINGRESP not received in keepalive interval */ } else { Timer timer; TimerInit(&timer); TimerCountdownMS(&timer, 1000); int len = MQTTSerialize_pingreq(c->buf, c->buf_size); if (len > 0 && (rc = sendPacket(c, len, &timer)) == SUCCESS) { // send the ping packet c->ping_outstanding = 1; TimerCountdownMS(&c->ping_wait, CONFIG_MQTT_PING_TIMEOUT); } } } exit: return rc; }
int _CRTAPI1 Zatexit (void (_CRTAPI1 * Arg1)(void)) { int RetVal; SHORT sTimerHandle; ULONG ulElapsedTime; if (fInitDone == FALSE) { ApfInitDll(); } TimerOpen(&sTimerHandle, MICROSECONDS); TimerInit(sTimerHandle); // // Call the api // RetVal = atexit(Arg1); // // Get the elapsed time // ulElapsedTime = TimerRead(sTimerHandle); ApfRecordInfo(I_atexit, ulElapsedTime); TimerClose(sTimerHandle); return(RetVal); }
void* _CRTAPI1 Z_lsearch (const void * Arg1, void * Arg2,unsigned int * Arg3, unsigned int Arg4, int (_CRTAPI1 * Arg5)(const void *, const void *)) { void* RetVal; SHORT sTimerHandle; ULONG ulElapsedTime; if (fInitDone == FALSE) { ApfInitDll(); } TimerOpen(&sTimerHandle, MICROSECONDS); TimerInit(sTimerHandle); // // Call the api // RetVal = _lsearch(Arg1,Arg2,Arg3,Arg4,Arg5); // // Get the elapsed time // ulElapsedTime = TimerRead(sTimerHandle); ApfRecordInfo(I__lsearch, ulElapsedTime); TimerClose(sTimerHandle); return(RetVal); }
/*----------------------------------------------------------------------------- * main */ int main(void) { uint8_t ret; int sioHdl; /* set clock prescaler to 2 (set clock to 7.3928 MHz) */ CLKPR = 1 << CLKPCE; CLKPR = 1; /* get module address from EEPROM */ sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS); GetClientListFromEeprom(); PortInit(); TimerInit(); ButtonInit(); PwmInit(); ApplicationInit(); SioInit(); SioRandSeed(sMyAddr); /* sio for bus interface */ sioHdl = SioOpen("USART1", eSioBaud9600, eSioDataBits8, eSioParityNo, eSioStopBits1, eSioModeHalfDuplex); SioSetIdleFunc(sioHdl, IdleSio1); SioSetTransceiverPowerDownFunc(sioHdl, BusTransceiverPowerDown); BusTransceiverPowerDown(true); BusInit(sioHdl); spBusMsg = BusMsgBufGet(); /* warten for full operation voltage */ while (!POWER_GOOD); /* enable ints before RestorePwm() */ ENABLE_INT; TimerStart(); RestorePwm(); /* ext int for power fail: INT0 low level sensitive */ EICRA &= ~((1 << ISC01) | (1 << ISC00)); EIMSK |= (1 << INT0); ApplicationStart(); /* Hauptschleife */ while (1) { Idle(); ret = BusCheck(); ProcessBus(ret); CheckButton(); PwmCheck(); ApplicationCheck(); CheckEvent(); } return 0; }
/***************************************************************************** Function: void TickInit(void) Summary: Initializes the Tick manager module. Description: Configures the Tick module and any necessary hardware resources. Precondition: None Parameters: None Returns: None Remarks: This function is called only one during lifetime of the application. ***************************************************************************/ void TickInit(void) { #if defined(__18CXX) // Use Timer0 for 8 bit processors // Initialize the time TMR0H = 0; TMR0L = 0; // Set up the timer interrupt INTCON2bits.TMR0IP = 1; // High priority INTCONbits.TMR0IF = 0; INTCONbits.TMR0IE = 1; // Enable interrupt // Timer0 on, 16-bit, internal timer, 1:256 prescalar T0CON = 0x87; #else /* // Use Timer 1 for 16-bit and 32-bit processors // 1:1 prescale T1CONbits.TCKPS = 0; T1CONbits.TCS = 1; //T1CON = 0x0002; // Base PR1 = 0xFFFF; // Clear counter TMR1 = 0; // Enable timer interrupt #if defined(__C30__) IPC0bits.T1IP = 2; // Interrupt priority 2 (low) IFS0bits.T1IF = 0; IEC0bits.T1IE = 1; #else IPC1bits.T1IP = 2; // Interrupt priority 2 (low) IFS0CLR = _IFS0_T1IF_MASK; IEC0SET = _IEC0_T1IE_MASK; #endif // Start timer T1CONbits.TON = 1; */ TimerInit(TIMER1, CLOCK_SOURCE_EXTERNAL, GATED_DISABLE, PRE_1_1, IDLE_ENABLE, BIT_16, SYNC_ENABLE); TimerSetValue(TIMER1, 0x0000, 0xFFFF); TimerSetCallback(TIMER1, Timer1Callback); TimerSetInt(TIMER1, 7, TRUE); TimerSetState(TIMER1, TRUE); { DWORD RTCSec = GetTimeFromRTC(); dwInternalTicks = RTCSec / 2; if(RTCSec & 1){ TimerSetValue(TIMER1, TICKS_PER_SECOND, 0xFFFF); } } #endif }
int MotorDelay(unsigned int ms) { TimerInit(TimerStop, 0, ms); wait_for_completion(&comp); TimerExit(); return 0; }
void OC_Start (void){ DisableInterrupts; TimerInit(); TIOS |= 0x01; // activate TC0 as output compare TIE |= 0x01; // arm OC0 TC0 = TCNT + 50; //First interrupt = immediate EnableInterrupts; }
void main(void) { USB_STATUS status = USB_OK; /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */ _bsp_platform_init(); sci1_init(); sci2_init(); IIC_ModuleInit(); TimerInit(); DisableInterrupts; /* enable interrupt OTG module */ Int_Ctl_int_init(IRQ3_INT_CNTL, IRQ3_ISR_SRC, 2,2, TRUE); MCF_EPORT_EPPAR |= MCF_EPORT_EPPAR_EPPA3_FALLING; /* falling edge */ MCF_EPORT_EPDDR &= ~MCF_EPORT_EPDDR_EPDD3; /* set input*/ MCF_EPORT_EPIER |= MCF_EPORT_EPIER_EPIE3; /* enable interrupts IRQ 3 */ /* set VHost pin ( PUC3) */ MCF_GPIO_DDRUC |= MCF_GPIO_DDRUC_DDRUC3; /* set output */ MCF_GPIO_PUCPAR |= MCF_GPIO_PUCPAR_UCTS2_GPIO; /* set as GPIO */ ENABLE_USB_5V; status = _usb_otg_init(0, (OTG_INIT_STRUCT*)&otg_init, &otg_handle); if(status == USB_OK) { status = _usb_otg_register_callback(otg_handle, App_OtgCallback); } EnableInterrupts; #if (defined _MCF51MM256_H) || (defined _MCF51JE256_H) usb_int_en(); #endif printf("\n\rInitialization passed. Plug-in MSD device to USB port"); printf("\n\rPress P to print the menu:"); for(;;) { _usb_otg_task(); if(dev_stack_active) { App_PeripheralTask(); } if(host_stack_active) { App_Host_Task(); } App_HandleUserInput(); __RESET_WATCHDOG(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave main */ }
void CANUi::CANopenStart(){ if(!m_CANopenState){ m_CANopenState = true; TimerInit(); StartTimerLoop(&InitNodes); } }
void SystemInit (void) { TimerInit(); DirInit(); VideoInit(); // Must be before sound/input because of window InputInit(); SoundInit(); //LuaStart(); }
/*! * task to blink led rtos between 1 seconds. */ void task_led_rtos( task_param_t param ) { TimerInit(&Led1Timer, "Led1Timer", 250, OnLed1TimerEvent, false); TimerInit(&Led2Timer, "Led2Timer", 250, OnLed2TimerEvent, false); TimerInit(&Led3Timer, "Led3Timer", 250, OnLed3TimerEvent, false); // Switch LED 1 ON GpioWrite(&Led1, 0); TimerStart(&Led1Timer); while (1) { if ( Led1TimerEvent == true ) { Led1TimerEvent = false; // Switch LED 1 OFF GpioWrite(&Led1, 1); // Switch LED 2 ON GpioWrite(&Led2, 0); TimerStart(&Led2Timer); } if ( Led2TimerEvent == true ) { Led2TimerEvent = false; // Switch LED 2 OFF GpioWrite(&Led2, 1); // Switch LED 3 ON GpioWrite(&Led3, 0); TimerStart(&Led3Timer); } if ( Led3TimerEvent == true ) { Led3TimerEvent = false; // Switch LED 3 OFF GpioWrite(&Led3, 1); // Switch LED 1 ON GpioWrite(&Led1, 0); TimerStart(&Led1Timer); } OSA_TimeDelay(50); } }
int MQTTSubscribeWithResults(MQTTClient *c, const char *topicFilter, enum QoS qos, messageHandler messageHandler, MQTTSubackData *data) { int rc = FAILURE; Timer timer; int len = 0; MQTTString topic = MQTTString_initializer; topic.cstring = (char *)topicFilter; #if defined(MQTT_TASK) MutexLock(&c->mutex); #endif if (!c->isconnected) { goto exit; } TimerInit(&timer); TimerCountdownMS(&timer, c->command_timeout_ms); len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, (int *)&qos); if (len <= 0) { goto exit; } if ((rc = sendPacket(c, len, &timer)) != SUCCESS) { // send the subscribe packet goto exit; // there was a problem } if (waitfor(c, SUBACK, &timer) == SUBACK) { // wait for suback int count = 0; unsigned short mypacketid; data->grantedQoS = QOS0; if (MQTTDeserialize_suback(&mypacketid, 1, &count, (int *)&data->grantedQoS, c->readbuf, c->readbuf_size) == 1) { if (data->grantedQoS != 0x80) { rc = MQTTSetMessageHandler(c, topicFilter, messageHandler); } } } else { rc = FAILURE; } exit: if (rc == FAILURE) { MQTTCloseSession(c); } #if defined(MQTT_TASK) MutexUnlock(&c->mutex); #endif return rc; }