void Chip8EOSLogicN::initRegs(void) { regAccess->writeReg(0x1101, 0xA0A0, false); os_dly_wait(10); regAccess->writeReg(0x1101, 0xA1A1, false); os_dly_wait(10); }
/** * [InitTask description] */ __task void InitTask(void) { int msg_len = 0; int clockRate = Chip_Clock_GetMainClockRate(); /* Enabled Clock To GPPIO */ Chip_GPIO_Init(LPC_GPIO); // Set the pin direction, set high for an output LED2 Chip_GPIO_SetPinDIR(LPC_GPIO, 0, 2, 1); /* Serial Driver Enable */ SER_Init(); msg_len = snprintf(message, sizeof(message), "Main clock is: %d\r\n", clockRate); Chip_UART0_SendRB(LPC_USART0, &txring, message, msg_len); for(;;) { os_dly_wait(50); Chip_UART0_SendRB(LPC_USART0, &txring, "Sveiki\r\n", strlen("Sveiki\r\n")); Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 2, 0); os_dly_wait(100); Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 2, 1); } }
//Blink with 50ms interval static void blinkLED(){ gpio_set_dap_led(1); os_dly_wait(5); gpio_set_dap_led(0); os_dly_wait(5); gpio_set_dap_led(1); }
void target_before_init_debug(void) { swd_set_target_reset(1); os_dly_wait(2); swd_set_target_reset(0); os_dly_wait(2); return; }
void GUI_X_Delay(int ms) { while (ms > 0xFFFE) { ms -= 0xFFFE; os_dly_wait(0xFFFE); } os_dly_wait(ms); }
__task void CMDHandler(void) { uint8_t write_buf[128]={0}; uint8_t read_buf[128]={0}; uint8_t i=0; uint32_t err_count=0; uint32_t ok_count=0; unsigned short tmp=0; os_dly_wait(300); // // 10MS * 10 = 100 mS Serial_PutString("AT\r\n"); os_dly_wait(50); // // 10MS * 10 = 100 mS Serial_PutString("ATE1\r\n"); os_dly_wait(50); // // 10MS * 10 = 100 mS Serial_PutString("AT+CPIN?\r\n"); os_dly_wait(100); // // 10MS * 10 = 100 mS ds18b20_start(); while (1) { Serial_PutString("AT+CSQ\r\n"); ShowTime(); printf("ACC:%5.2f %5.2f %5.2f GYRO: %5.2f %5.2f %5.2f\r\n\r\n",Acc_Buffer[0],Acc_Buffer[1],Acc_Buffer[2], Gyro_Buffer[0],Gyro_Buffer[1],Gyro_Buffer[2]); printf("SLOAR: %d, CHARGE: %d, BAT: %d (ADC Value)\r\n",Adc1Result.Channel_8, Adc1Result.Channel_9, Adc1Result.Channel_15); for(i=0;i<128;i++) write_buf[i]=rand(); at25_write_page(0x00,128,write_buf); at25_read_page(0x00,128,read_buf); if(memcmp(read_buf,write_buf,128) == 0) { printf("> FRAM Write successed : %d\r\n" ,++ok_count); } else { printf("> FRAM Write failed: %d\r\n",++err_count); } tmp=ds18b20_read(); printf("> Tmp: %.1f (%d)\r\n",(tmp*0.0039),tmp); if(flag_usart3_rx==1) { flag_usart3_rx=0; printf("%s",UART3RecvBuf); printf("\r\n"); } printf("---------------------------------------------------------------------------\r\n\r\n"); os_dly_wait(100); // // 10MS * 10 = 100 mS } }
/*---------------------------------------------------------------------------- * Function 'signal_func' called from multiple tasks *---------------------------------------------------------------------------*/ void signal_func (OS_TID task) { os_evt_set (0x0100, t_clock); /* send event signal to clock task */ os_dly_wait (50); /* delay 50 clock ticks */ os_evt_set (0x0100, t_clock); /* send event signal to clock task */ os_dly_wait (50); /* delay 50 clock ticks */ os_evt_set (0x0001, task); /* send event to task 'task' */ os_dly_wait (50); /* delay 50 clock ticks */ }
int main(void){ //---------------------------------------------------------------- // Low Level Peripheral INIT [must be done before RTOS Init] //---------------------------------------------------------------- Init_USARTS(); os_dly_wait(1); Acc_Init(); os_dly_wait(1); //---------------------------------------------------------------- // //---------------------------------------------------------------- os_sys_init(Init_System); //---------------------------------------------------------------- }
//clock task __task void clock_task(void){ uint32_t ticks; uint32_t last_keys = 0; uint32_t last_joy = 0; uint32_t value = 0; static unsigned char sec; for(;;){ os_dly_wait(10); ticks++; if(ticks >= 10) { ticks = 0; os_sem_send(&semIncSec); } value = KBD_GetKeys(); os_evt_set((uint16_t)((value ^ last_keys) & ~value),keyTaskId); last_keys = value; value = JOY_GetKeys(); os_evt_set((uint16_t)((value ^ last_joy) & ~value),joyTaskId); last_joy = value; } }
/* * 1.����豸���� * 2.���IP���Զ��MCU��ֻ��Workingʱ���ã� * 2.��ʼ��Э��������ָ����λ��Ϣ * 3.����IDLE״̬ * 4.��ʼ״̬������ */ void ProtectAssistCell::start() { GeneralLogic::instance().assignSlot( CardCPU::itsSlot() ); if( CardCPU::itsSlot() == 1 ) { os_dly_wait(300); } SoftWDT::instance().init(); //首先建立软狗,否则其它任务无法注册 GeneralLogic::instance().FSMStart(); DeviceComponent::initDeviceComponentCommon(); CommunicationModule::initCommon(); // SoftWDT::instance().startSoftWDT(); //开启软狗 if( getOMUWorkingStateByHardware() == OMU_Working ) { omu = new OMUWorking(); #ifdef EZ_DEBUG std::cout << "OMUWorking" << std::endl; #endif } else { omu = new OMUStandby(); // #ifdef EZ_DEBUG std::cout << "OMUStandby" << std::endl; #endif } working_state_check = os_tsk_create_ex(check_working, P_Protect, this); }
/*** tcp_connect is actually associated with following syassl_tcp_connect. ***/ int Cyassl_connect(int sd, const struct sockaddr* sa, int sz) { int ret = 0 ; #if defined(CYASSL_KEIL_TCP_NET) SOCKADDR_IN addr ; addr = *(SOCKADDR_IN *)sa ; do { #undef connect /* Go to KEIL TCPnet connect */ ret = connect(sd, (SOCKADDR *)&addr, sizeof(addr)) ; os_dly_wait(50); } while(ret == SCK_EWOULDBLOCK) ; #ifdef DEBUG_CYASSL { char msg[50] ; sprintf(msg, "BSD Connect return code: %d\n", ret) ; CYASSL_MSG(msg) ; } #endif #endif /* CYASSL_KEIL_TCP_NET */ return(ret ) ; }
void lcd_cmd_shift(void){ lcd_write_command(0x01); lcd_write_command(0x0c); lcd_write_command(0x01); lcd_write_command(0x07); os_dly_wait(1); // 38us=>минимальная задержка 1ms=>1ms }
TASK void check_working(void* pc) { ProtectAssistCell* pac = reinterpret_cast<ProtectAssistCell*>(pc); if( pac == 0 ) { #ifdef EZ_DEBUG printf("\n!!!task check_working error!!!\n"); #endif os_tsk_delete_self(); } static int count = 0; while( 1 ) { os_dly_wait(100); if( pac->protectPause ) { continue; } Working_STATE_E currentState = pac->getOMUWorkingStateByHardware(); if( pac->getOMUCurrentWorkingState() != currentState ) { if( ++count > 3 ) { count = 0; pac->switchTo(currentState); } } else { count = 0; //保证必须连续三次采集到不同才会切换 } } }
__task void LED_TOGGLE (void) { //---------------------------------------------------------------- uint8_t led_timer = 0; //---------------------------------------------------------------- put_log("[LED]: LED Task Started...\r\n"); //---------------------------------------------------------------- for (;;) { //---------------------------------------------------------------- os_dly_wait(20); //---------------------------------------------------------------- led_timer++; //---------------------------------------------------------------- if(led_timer==3 || led_timer==4){ //---------------------------------------------------------------- tmr1 = os_tmr_create (5, MAIN_LED_OFF_TMO); if (tmr1 != NULL) { GPIOD->BSRRL = GPIO_Pin_12; } //---------------------------------------------------------------- if(led_timer==4){ led_timer = 0; } //---------------------------------------------------------------- } //---------------------------------------------------------------- } //---------------------------------------------------------------- }
void lcd_debug_display (void) { unsigned char j; //Unlock Count lcd_clear(); //lcd_write_string_XY(0, 0, "Unlock Count:"); lcd_write_int_XY(0, 1, local_ee_data.unlock_count); os_dly_wait(300); //Box ID lcd_clear(); //lcd_write_string_XY(0, 0, "Box_ID:"); lcd_write_int(local_ee_data.box_id); os_dly_wait(300); //Full Unlock lcd_clear(); if (local_ee_data.full_unlock == EE_FULL_UNLOCK_CODE) { lcd_write_string("Full Unlock"); } else { lcd_write_string("Not Full Unlock"); } os_dly_wait(300); /* lcd_clear(); lcd_write_int(get_unlock_days ()); os_dly_wait(300); */ //RTC Test for (j = 0; j < 50; j++) { char str[16]; lcd_clear(); get_time_str(&str[0]); lcd_write_string_XY(0,0, str); str[0] = '\0'; get_date_str(&str[0]); lcd_write_string_XY(0,1, str); //200ms delay os_dly_wait(20); } lcd_clear(); }
__task void task2() { while(1) { printf("Task2: HelloWorld!\n"); os_dly_wait(3); } }
__task void task4() { while(1) { printf("Task4: Printing Task 4!\n"); os_dly_wait(3); } }
/*---------------------------------------------------------------------------- * Task 5 'clock': Signal Clock *---------------------------------------------------------------------------*/ __task void clock (void) { for (;;) { os_evt_wait_and (0x0100, 0xffff); /* wait for an event flag 0x0100 */ LED_On (LED_CLK); os_dly_wait (8); /* delay 8 clock ticks */ LED_Off(LED_CLK); } }
/** * open sim18 */ BOOL blSIM18_Open(void) { vGPS_PowerSupplyOn(); w_indx = 0; r_indx = 0; /* wait for Vgps stable */ os_dly_wait(DELAY_2S/OS_TICK_RATE_MS); // turn on module gps. vGPS_GenPulse(); os_dly_wait(500/OS_TICK_RATE_MS); return 1; }
__task void LedTask1(void) { for(;;) { GPIOD->ODR^=1<<15; os_dly_wait(300); } }
TASK void tsk_trap(void) //�������� { while( 1 ) { if( TrapList::instance().ifTrapDestExist() ) { os_dly_wait(100); while( TrapList::instance().isHasTrapItem() ) { TrapList::instance().sendaTrapItem(); } } else { //#ifdef EZ_DEBUG // printf("\n!!!Trap destination unreanchable!!!\n"); //#endif os_dly_wait(6000); } } }
uint16_t get_adc(void) { uint16_t adc = 0; BAT_MEASURE_SET; os_dly_wait(1); adc=adc_value[0]; BAT_MEASURE_RESET; return adc; }
void ADC_StartConver(void) { BAT_MEASURE_SET; os_dly_wait(1); // DMA_Configuration(); //ADC_DMACmd(ADC1, ENABLE); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConv(ADC1); }
/*---------------------------------------------------------------------*/ __task void task3(void){ void *pointer; pointer = os_mem_alloc(box_mem); if (pointer == NULL) printf("Not enough memory\n"); else printf("malloc'd(): %d \n", pointer); os_dly_wait(50); if(os_mem_free(box_mem, pointer) == OS_R_OK){ printf("dealloc'd(): OS_R_OK \n"); }else{ printf("dealloc'd(): OS_R_NOK \n"); } os_dly_wait(50); os_tsk_delete_self(); }
void lcd_splash_screen (int seconds) { lcd_write_string_XY(0, 0, " e.quinox "); lcd_write_string_XY(0, 1, " izuba.box "); os_dly_wait(100*seconds); lcd_clear(); }
__task void LedTask2(void) { for(;;) { GPIOD->ODR^=1<<14; // Usart2SendString("HELLO"); os_dly_wait(2000); } }
__task void task1() { unsigned int i = 0; for (;; i++) { printf("Task1: %d\n", i); os_dly_wait(10); } }
/*---------------------------------------------------------------------------- * Task 2: RTX Kernel starts this task with os_tsk_create (task2, 1) *---------------------------------------------------------------------------*/ __task void task2 (void) { for (;;) { /* Wait for completion of do-this (0xffff means no time-out) */ os_evt_wait_or (0x0004, 0xffff); /* do-that */ /* Pause for 20 ms until signaling event to task1 */ os_dly_wait (2); /* Indicate to task1 completion of do-that */ os_evt_set (0x0004, id1); } }
/***关机服务***/ void power_down(u8 time) { u8 f=2; time=time*f; while(time) { time--; sound_control(1); os_dly_wait(1000/f); } }
//----------------------------------------- // Task2: KEYHandle // 线程监控任务 // 查看软件狗状态,喂硬件狗 //----------------------------------------- __task void KEYHandler(void) { while (1) { User_Feed_IWDG(); // 硬件喂狗 Get_Car_Gesture(); os_dly_wait(50); // 10MS * 10=100 mS } }