int main() { __disable_interrupt(); //InitQueue(&uart_rx_cirqueue); //InitQueue(&uart_tx_cirqueue); CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1); //GPIO_Init(GPIOD, GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_SLOW); GPIO_INIT();//led GPIO_Init(GPIOD, GPIO_PIN_2,GPIO_MODE_OUT_PP_HIGH_FAST);//开启U10的控制引脚 pir_RI_io_init();//pir中断 T4_Init(); //Uart_Init(); CommInit(); /*AWU configuration --------------------------------------------*/ AWU_Config(); OSInit(); CommBufInit();//创建信号量的操作不能再OSInit();之前,也就是不能在OS_InitEventList();之前 OSTaskCreate( task0, (void *)OS_TASK_0_STK_SIZE, &Task0Stack[OS_TASK_0_STK_SIZE-1], OS_TASK_0_PRIO ); OSTaskCreate( task1, (void *)OS_TASK_1_STK_SIZE, &Task1Stack[OS_TASK_1_STK_SIZE-1], OS_TASK_1_PRIO ); //OSTaskCreate( task2, (void *)OS_TASK_2_STK_SIZE, &Task2Stack[OS_TASK_2_STK_SIZE-1], OS_TASK_2_PRIO ); OSStart(); return 0; }
int main(int argc, char *argv[]) { void* client; int err; test_Title("NETDB.H Functionality"); err=CommInit(0); /* ensure a workable comms environment */ test(err==0); testArpa(); /* doesn't use the MSystemInterface so only tested once */ if (argc==1) { /* Run the test(s) without a CPosixServer first */ testNetDB(); } test_Next("Do it all using the CPosixServer (for them, not me)"); close_console=1; start_posix_server(); /* calls SpawnPosixServer from C++ code */ client=create_thread(testNetDB, "TNETDB NetDB"); test(client!=0); start_thread(client); err=wait_for_thread(client); test(err==0); test_Close(); exit(0); return 0; }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; if (!_GameMode(hInstance, nCmdShow, 1280, 720, 32, false)) return FALSE; CommInit(NULL, NULL); //±×·¡ÇÈ ÃʱâÈ ResourceImage[0] = DDLoadBitmap(DirectOBJ, "DATA//end1.BMP", 0, 0, SYSTEM); ResourceImage[1] = DDLoadBitmap(DirectOBJ, "DATA//win.BMP", 0, 0, SYSTEM); ResourceImage[2] = DDLoadBitmap(DirectOBJ, "DATA//Choice.BMP", 0, 0, SYSTEM); ResourceImage[3] = DDLoadBitmap(DirectOBJ, "DATA//Money.BMP", 0, 0,SYSTEM); ResourceImage[4] = DDLoadBitmap(DirectOBJ, "DATA//Sonmogazi.BMP", 0, 0, SYSTEM); ResourceImage[5] = DDLoadBitmap(DirectOBJ, "DATA//Button.BMP", 0, 0, SYSTEM); ResourceImage[6] = DDLoadBitmap(DirectOBJ, "DATA//ZokBo.BMP", 0, 0, SYSTEM); ResourceImage[7] = DDLoadBitmap(DirectOBJ, "DATA//Texts.BMP", 0, 0, SYSTEM); ResourceImage[8] = DDLoadBitmap(DirectOBJ, "DATA//Stop.BMP", 0, 0, SYSTEM); ResourceImage[9] = DDLoadBitmap(DirectOBJ, "DATA//Back.BMP", 0, 0, SYSTEM); ResourceImage[10] = DDLoadBitmap(DirectOBJ, "DATA//main.bmp", 0, 0, SYSTEM); DDSetColorKey(ResourceImage[0], BLACK); DDSetColorKey(ResourceImage[1], BLACK); DDSetColorKey(ResourceImage[2], BLACK); DDSetColorKey(ResourceImage[3], BLACK); DDSetColorKey(ResourceImage[4], BLACK); DDSetColorKey(ResourceImage[5], BLACK); DDSetColorKey(ResourceImage[6], BLACK); DDSetColorKey(ResourceImage[7], BLACK); DDSetColorKey(ResourceImage[8], BLACK); DDSetColorKey(ResourceImage[9], BLACK); DDSetColorKey(ResourceImage[10], BLACK); //À½Çâ ÃʱâÈ if (SoundCard) { Sound[0] = SndObjCreate(SoundOBJ, "Sound//OST.WAV", 1); Sound[1] = SndObjCreate(SoundOBJ, "Sound//¹ØÀ廩±â.WAV", 1); Sound[2] = SndObjCreate(SoundOBJ, "Sound//Select3.WAV", 1); //Sound[3] = SndObjCreate(SoundOBJ, "Sound//Check.WAV", 1); //Sound[4] = SndObjCreate(SoundOBJ, "Sound//Start.WAV", 1); //3,4¹ø Àç»ýÀÌ ¾ÈµÊ. ÀÌÀ¯´Â ¸ð¸§.. } turn = 0; randomize(); Pae(); CommSend(); PlaySound("Sound//OST.WAV", NULL, SND_ASYNC); SetTimer(MainHwnd, 1, 10, NULL); // Main message loop while (GetMessage(&msg, NULL, 0, 0)){ TranslateMessage(&msg); DispatchMessage(&msg); } DestroyWindow(MainHwnd); return TRUE; }
int main() { int err; test_Title("AF_INET Streams"); err=CommInit(0); /* ensure a workable comms environment */ test(err==0); IN_SET_LOOPBACK_ADDR(&testaddr); testSimple(); test_Close(); return 0; }
//发送串口通讯数据包 static inline void CommSend(BYTE size) { WORD sum; BYTE i; UartSend(0x46); UartSend(0xb9); UartSend(0x6a); UartSend(0x00); sum = size + 6 + 0x6a; UartSend(size + 6); serialport_write(handle_download_port,TxBuffer,size); for (i=0; i<size; i++) { sum += TxBuffer[i]; } UartSend(HIBYTE(sum)); UartSend(LOBYTE(sum)); UartSend(0x16); CommInit(); }
TInt E32Main() /** * @test Main program tsmsmsg */ { CTrapCleanup* cleanup = CTrapCleanup::New(); CActiveScheduler* theActiveScheduler = new CActiveScheduler(); CActiveScheduler::Install(theActiveScheduler); __UHEAP_MARK; gTest.SetLogged(EFalse); // to avoid garbage on Com port gTest.Title(); TInt ret = CommInit(); if(ret != KErrNone) { gTest.Printf(_L("ERROR: Leave %d\n"), ret); } else { gTest.Start(_L("Starting tests...")); TRAPD(err,RunTestsL()); if (err!=KErrNone) gTest.Printf(_L("ERROR: Leave %d\n"),err); } gTest.End(); gTest.Close(); __UHEAP_MARKEND; delete cleanup; delete theActiveScheduler; return KErrNone; }
/** * @brief 程序入口 * @param 无 * @return 返回 */ int main(void) { int nOperRole = 0xff; char szOper[OPERCODELEN + 1]; PubInitUiParam(); ASSERT_QUIT(Ums_CheckMcVer()); /*重要:判断主控版本*/ PubLuaOpen(); PubLuaDisplay("LuaSetUIStyle"); /*设置系统风格*/ RecordVersion(); /*记录版本信息*/ PubKbHit(); /*清除按键缓*/ /** * 版本校验(首次运行检测) */ FirstRunChk(); /** * 模块初始化,重要!!! */ AppInit(); #if defined(USE_TMS) /**<检查是否有应用或者参数的更新*/ DoTmsTask(TMS_POS_CHKUPDATA); GetTmsParamDown(); #endif Cup_InitScrLed(); SetControlChkPinpad(YES); /* * 运行任务 */ while(1) { /** * 设备检查 */ ChkPdAndRF(); /** * 通讯初始化 */ CommInit(); memset(szOper, 0, sizeof(szOper)); GetWaterOper(szOper);/**<取做过交易的(有流水)操作员号码*/ SetOperLimit(szOper); GetVarLastOperInfo(szOper, &nOperRole);/**<取最后登陆的操作员信息(保存的)*/ SetCurrentOper(szOper, NULL, nOperRole);/**<将最后登陆的操作员信息设置给操作员模块*/ if (ChkIsMCReturn() == APP_SUCC || nOperRole != NORMALOPER || YES != GetVarIsLogin()) { if (OperLogon() != APP_SUCC) { /*取消已设置的系统风格*/ PubLuaDisplay("LuaUnSetUIStyle"); PubLuaClose(); CommDump(); Cup_ExitScrLed(); return APP_QUIT; } } GetCurrentOper(szOper, NULL, &nOperRole);/**<从操作员模块获取当前的操作员信息*/ SetVarLastOperInfo(szOper, (char)nOperRole);/**<保存最后登陆的操作员信息*/ /** * 系统管理员 */ if (nOperRole == ADMINOPER) { Manage(); ParamSave(); PubClearAll(); } else if(nOperRole == HIDEMENUOPER) { HideManage(); } else if(nOperRole == MANAGEROPER) { Operate(); } else { if (APP_SUCC != AppTrans()) { PubLuaDisplay("LuaUnSetUIStyle"); PubLuaClose(); CommDump(); Cup_ExitScrLed(); return APP_QUIT; } } } }
int main() { CYBLE_API_RESULT_T apiResult; CYBLE_LP_MODE_T lpMode; CyGlobalIntEnable; CommInit(); /* Start communication component */ printf("BLE Uart Transmission Collector Example Project \r\n"); Scanning_LED_Write(LED_OFF); apiResult = CyBle_Start(AppCallBack); if(apiResult != CYBLE_ERROR_OK) { printf("CyBle_Start API Error: %xd \r\n", apiResult); } else { printf("CyBle_Start API ok \r\n"); } /* Enable the Interrupt component connected to interrupt */ TC_CC_ISR_StartEx(InterruptHandler); /* Start the components */ Timer_Start(); while(1) { if(CyBle_GetState() != CYBLE_STATE_INITIALIZING) { /* Enter DeepSleep mode between connection intervals */ lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); if(lpMode == CYBLE_BLESS_DEEPSLEEP) { /* Put the device into the Deep Sleep mode only when all debug information has been sent if(UART_DEB_SpiUartGetTxBufferSize() == 0u) { CySysPmDeepSleep(); } else { CySysPmSleep(); }*/ CySysPmSleep(); /* Handle scanning led blinking */ HandleLEDs(ble_state); } HandleLEDs(ble_state); } /*********************************************************************** * Wait for connection established with Central device ***********************************************************************/ if(CyBle_GetState() == CYBLE_STATE_CONNECTED) { /******************************************************************* * Periodically measure a battery level and temperature and send * results to the Client *******************************************************************/ CommMonitorUart(); CommMonitorBLE(); #if 0 if(mainTimer != 0u) { mainTimer = 0u; if(storeBondingData == ENABLED) { cystatus retValue; retValue = CyBle_StoreBondingData(0u); printf("Store bonding data, status: %lx \r\n", retValue); storeBondingData = DISABLED; } } #endif } /******************************************************************* * Processes all pending BLE events in the stack *******************************************************************/ CyBle_ProcessEvents(); } }
void* download_recv_thread(void* thread_arg){ static WORD RecvSum; static BYTE RecvIndex; static BYTE RecvCount; int exitthread=0; int ret; int readlength,consumed; BYTE dat; while(!exitthread){ // platform_usleep(1000); readlength = serialport_read(handle_download_port,&dat,1,0); if(readlength>0) { //printf("got uart bytes dat=0x%x UartRecvStep=0x%x\n",dat,UartRecvStep); switch (UartRecvStep) { case 1: if (dat != 0xb9) goto L_CheckFirst; UartRecvStep++; break; case 2: if (dat != 0x68) goto L_CheckFirst; UartRecvStep++; break; case 3: if (dat != 0x00) goto L_CheckFirst; UartRecvStep++; break; case 4: RecvSum = 0x68 + dat; RecvCount = dat - 6; RecvIndex = 0; UartRecvStep++; break; case 5: RecvSum += dat; RxBuffer[RecvIndex++] = dat; if (RecvIndex == RecvCount) UartRecvStep++; break; case 6: if (dat != HIBYTE(RecvSum)) goto L_CheckFirst; UartRecvStep++; break; case 7: if (dat != LOBYTE(RecvSum)) goto L_CheckFirst; UartRecvStep++; break; case 8: if (dat != 0x16) goto L_CheckFirst; UartReceived = TRUE; UartRecvStep++; break; L_CheckFirst: case 0: default: CommInit(); UartRecvStep = (dat == 0x46 ? 1 : 0); break; } } } return NULL; }
//对STC15系列的芯片进行数据下载程序 static int Firmware_Download(BYTE *pdat, long size) { BYTE arg; BYTE cnt; WORD addr; Initial(); //握手 CommInit(); while (1) { if (UartRecvStep == 0) { UartSend(0x7f); DelayXms(10); } if (UartReceived) { arg = RxBuffer[4]; if (RxBuffer[0] == 0x50) break; return eDownloadErrCodeHandshake; } if (TimeOut == 0) { printf("waiting for mcu isp timeout\n"); return eDownloadErrCodeTimeout; } } printf("set comm param\n"); //设置参数 TxBuffer[0] = 0x01; TxBuffer[1] = arg; TxBuffer[2] = 0x40; TxBuffer[3] = HIBYTE(RL(MAXBAUD)); TxBuffer[4] = LOBYTE(RL(MAXBAUD)); TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0xc3; CommSend(8); while (1) { if (TimeOut == 0) return eDownloadErrCodeTimeout; if (UartReceived) { if (RxBuffer[0] == 0x01) break; return eDownloadErrCodeSetCommParam; } } printf("download prepare \n"); //准备 serialport_config(handle_download_port,MAXBAUD,8,1,'e'); DelayXms(10); TxBuffer[0] = 0x05; CommSend(1); while (1) { if (TimeOut == 0) return eDownloadErrCodeTimeout; if (UartReceived) { if (RxBuffer[0] == 0x05) break; return eDownloadErrCodeSetCommParam; } } printf("erase flash ...\n"); //擦除 DelayXms(10); TxBuffer[0] = 0x03; TxBuffer[1] = 0x00; CommSend(2); TimeOut = 100; while (1) { if (TimeOut == 0) return eDownloadErrCodeTimeout; if (UartReceived) { if (RxBuffer[0] == 0x03) break; return eDownloadErrCodeEraseFlash; } } printf("program flash size[0x%lx]...\n",size); //写用户代码 DelayXms(10); addr = 0; TxBuffer[0] = 0x22; while (addr < size) { TxBuffer[1] = HIBYTE(addr); TxBuffer[2] = LOBYTE(addr); cnt = 0; while (addr < size) { TxBuffer[cnt+3] = pdat[addr]; addr++; cnt++; if (cnt >= 128) break; } CommSend(cnt + 3); while (1) { if (TimeOut == 0) return eDownloadErrCodeTimeout; if (UartReceived) { if ((RxBuffer[0] == 0x02) && (RxBuffer[1] == 'T')) break; return eDownloadErrCodeProgramFlash; } } TxBuffer[0] = 0x02; } printf("program hardware option ... skipped\n"); #if 0 //写硬件选项(如果不需要修改硬件选项,此步骤可直接跳过) DelayXms(10); for (cnt=0; cnt<128; cnt++) { TxBuffer[cnt] = 0xff; } //Do we know details of hardware options??? TxBuffer[0] = 0x04; TxBuffer[1] = 0x00; TxBuffer[2] = 0x00; TxBuffer[34] = 0xfd; TxBuffer[62] = arg; TxBuffer[63] = 0x7f; TxBuffer[64] = 0xf7; TxBuffer[65] = 0x7b; TxBuffer[66] = 0x1f; CommSend(67); while (1) { if (TimeOut == 0) return eDownloadErrCodeTimeout; if (UartReceived) { if ((RxBuffer[0] == 0x04) && (RxBuffer[1] == 'T')) break; return eDownloadErrCodeProgramOption; } } #endif //下载完成 return eDownloadErrCodeSuccess; }