Res BufferCreate(Buffer *bufferReturn, BufferClass klass, Pool pool, Bool isMutator, ArgList args) { Res res; Buffer buffer; Arena arena; void *p; AVER(bufferReturn != NULL); AVERT(BufferClass, klass); AVERT(Pool, pool); arena = PoolArena(pool); /* Allocate memory for the buffer descriptor structure. */ res = ControlAlloc(&p, arena, klass->size); if (res != ResOK) goto failAlloc; buffer = p; /* Initialize the buffer descriptor structure. */ res = BufferInit(buffer, klass, pool, isMutator, args); if (res != ResOK) goto failInit; *bufferReturn = buffer; return ResOK; failInit: ControlFree(arena, buffer, klass->size); failAlloc: return res; }
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 //Procedure SetPlayer //Author Robert Slater //Date Wed 27 Jan 1999 // //Description // //Inputs // //Returns // //------------------------------------------------------------------------------ void MessageBuffer::SetPlayer(AirStrucPtr ac1,AirStrucPtr ac2) { BufferInit(); //RJS 01Apr99 thePlayer = ac1; theOtherOne = ac2; //DEADCODE RDH 17/05/00 _Radio.Enter3D(); //RJS 28Apr99 }
MessageBuffer::MessageBuffer() { oldbuffer = NULL; newbuffer = NULL; //FIXA lateststring = new CString; BufferInit(); }
unsigned char *GProfile::GetBinary(const char *szSectionName, const char *szKey, GString &strDest) { GString strEncoded(GProfile::GetString(szSectionName, szKey, 0)); BUFFER b2; BufferInit(&b2); unsigned int nDecoded; uudecode((char *)(const char *)strEncoded, &b2, &nDecoded, false); strDest.WriteOn(b2.pBuf,nDecoded); BufferTerminate(&b2); return (unsigned char *)strDest.Buf(); }
void GProfile::SetConfigBinary(const char *szSection, const char *szEntry, unsigned char *lValue, int nValueLength) { // UUencode the binary BUFFER b; BufferInit(&b); uuencode(lValue, nValueLength, &b); GString strEncoded((char *)b.pBuf, b.cLen); BufferTerminate(&b); SetConfig(szSection, szEntry, strEncoded, 0 ); }
/***************************************************************************** * Create: allocates adjust video thread output method ***************************************************************************** * This function allocates and initializes a adjust vout method. *****************************************************************************/ static int Create( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; filter_sys_t *p_sys; /* Allocate structure */ p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) return VLC_ENOMEM; p_sys = p_filter->p_sys; BufferInit( &p_sys->input ); BufferInit( &p_sys->output ); QueueInit( &p_sys->atomic ); QueueInit( &p_sys->pending ); QueueInit( &p_sys->processed ); do_ListInit( &p_sys->overlays ); p_sys->i_inputfd = -1; p_sys->i_outputfd = -1; p_sys->b_updated = true; p_sys->b_atomic = false; vlc_mutex_init( &p_sys->lock ); p_filter->pf_sub_source = Filter; config_ChainParse( p_filter, "overlay-", ppsz_filter_options, p_filter->p_cfg ); p_sys->psz_inputfile = var_CreateGetStringCommand( p_filter, "overlay-input" ); p_sys->psz_outputfile = var_CreateGetStringCommand( p_filter, "overlay-output" ); var_AddCallback( p_filter, "overlay-input", AdjustCallback, p_sys ); var_AddCallback( p_filter, "overlay-output", AdjustCallback, p_sys ); RegisterCommand( p_filter ); return VLC_SUCCESS; }
MessageBuffer::MessageBuffer() { oldbuffer = NULL; newbuffer = NULL; lateststring = new CString; BufferInit(); #ifdef _PRINTSTRING_ debfp = fopen("radtest.txt","wt"); #endif }
void CommunicationInit(CommunicationState *com) { RingBufferInit(&com->uart_in_ringbuffer, com->uart_in_data, COMMUNICATION_UART_IN_BUFF_SIZE); BufferInit(&com->deframed_buffer, com->deframed_data, COMMUNICATION_UART_IN_BUFF_SIZE); RingBufferInit(&com->uart_out_ringbuffer, com->uart_out_data, COMMUNICATION_UART_OUT_BUFF_SIZE); _communicationState = com; CommunicationIntRegisterHandler(CommunicationISR); LogCString(LOG_LEVEL_DEBUG, "Initializing communication"); // Initialize UART peripheral CommunicationHwInit(); // Enable UART read interrupts CommunicationIntEnableRead(); LogCString(LOG_LEVEL_DEBUG, "Communication initialized"); }
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstExePrev, LPSTR pszCmdLine, int nCmdShow) { // ***** To debug this application **** // set fDebug to 1, then recompile (in debug mode) // and run the program in a debugger like any windows .exe // The exact same code executes as if the user clicked the // 'start' button in the NT services manager. int fDebug = 0; int nArgc = __argc; #ifdef UNICODE LPCTSTR *ppArgv = (LPCTSTR*) CommandLineToArgvW(GetCommandLine(), &nArgc); #else LPCTSTR *ppArgv = (LPCTSTR*) __argv; #endif BOOL fStartService = (nArgc < 2); int i; int bInstall = 0; int bRemove = 0; int bChange = 0; GString strPort("10888"); GString strBoot; GString strRoot("NotUsed"); for (i = 1; i < nArgc; i++) { if ((ppArgv[i][0] == __TEXT('-')) || (ppArgv[i][0] == __TEXT('/'))) { // Command line switch if (lstrcmpi(&ppArgv[i][1], __TEXT("install")) == 0) bInstall = 1; if (lstrcmpi(&ppArgv[i][1], __TEXT("remove")) == 0) bRemove = 1; if (lstrcmpi(&ppArgv[i][1], __TEXT("change")) == 0) bChange = 1; GString strTemp(&ppArgv[i][1],strlen("desc:")); if (strTemp.CompareNoCase("desc:") == 0) { strServerDescription = &ppArgv[i][1+strlen("desc:")]; } GString strTemp2(&ppArgv[i][1],strlen("name:")); if (strTemp2.CompareNoCase("name:") == 0) { strServerName = &ppArgv[i][1+strlen("name:")]; } GString strTemp3(&ppArgv[i][1],strlen("pass:"******"pass:"******"pass:"******"boot:")); if (strTemp4.CompareNoCase("boot:") == 0) { strBoot = &ppArgv[i][1+strlen("boot:")]; } GString strTemp5(&ppArgv[i][1],strlen("port:")); if (strTemp5.CompareNoCase("port:") == 0) { strPort = &ppArgv[i][1+strlen("port:")]; } GString strTemp6(&ppArgv[i][1],strlen("root:")); if (strTemp6.CompareNoCase("root:") == 0) { strRoot = &ppArgv[i][1+strlen("root:")]; } } } if (bChange) { ModifyStartupFile(strBoot,strServerPassword,strRoot,strPort); } if (bInstall) { GString strThisEXEName(GetThisEXEName()); // uuencode strBoot BUFFER b; BufferInit(&b); uuencode((unsigned char *)(const char *)strBoot, (int)strBoot.Length(), &b); GString strEncodedBoot((char *)b.pBuf, b.cLen); BufferTerminate(&b); // open the registry, save the coded boot key, close the registry HKEY hk; if (RegCreateKey(HKEY_CLASSES_ROOT,(const char *)strThisEXEName,&hk) == ERROR_SUCCESS) { RegSetValue(hk,NULL,REG_SZ,(const char *)strEncodedBoot,0); RegCloseKey(hk); } // use root of file system to store the startup file // unless specified otherwise by environment setting GString strOutFile("c:\\"); strOutFile += strThisEXEName; if (getenv(strThisEXEName)) { strOutFile += getenv(strThisEXEName); } // create the startup file GString strTempFile; strTempFile << strServerPassword << "&&" << strRoot << "&&" << strPort; strTempFile.ToFile("tempfile"); GString strErrorOut; FileEncrypt(strBoot, "tempfile", strOutFile, strErrorOut); unlink("tempfile"); InstallService(); } if (bRemove) { RemoveService(); GString strThisEXEName(GetThisEXEName()); // remove the registry entry RegDeleteKey(HKEY_CLASSES_ROOT,(const char *)strThisEXEName); // remove the startup file GString strOutFile("c:\\"); strOutFile += strThisEXEName; if (getenv(strThisEXEName)) { strOutFile += getenv(strThisEXEName); } unlink(strOutFile); } strcpy(pzServer,strServerName); if (fDebug) { // Running as EXE not as service, just run the service for debugging TimeServiceMain(0, NULL); } if (fStartService) { SERVICE_TABLE_ENTRY ServiceTable[] = { { pzServer, TimeServiceMain }, { NULL, NULL } // End of list }; StartServiceCtrlDispatcher(ServiceTable); } return(0); }
void WINAPI TimeServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) { #ifdef _WIN64 unsigned __int64 dwCompKey = CK_SERVICECONTROL; #else DWORD dwCompKey = CK_SERVICECONTROL; #endif DWORD fdwControl = SERVICE_CONTROL_RUN; DWORD dwBytesTransferred; OVERLAPPED *po; SERVICE_STATUS ss; SERVICE_STATUS_HANDLE hSS; BOOL bPasswordCompileEmbedded = 0; // We must get the private password for connecting to this machine. // The password can be compiled into the server any of the following ways...... // 1 way - the easiest way, just uncomment and put any value between the quotes // then remove the code between --Load External Password Begin & End-- below // ***** example of very simple integrated password ******** // GString strPassword("Password"); // GString strPort("80"); // GString strRoot; // bPasswordCompileEmbedded = 1; // Another way - a most secure way to embed the password. // ***** example of integrated password ******** // GString strPassword; // MakePassword(strPassword); // Go read the MakePassword() routine above. // GString strPort("80"); // GString strRoot; // bPasswordCompileEmbedded = 1; // OR // The password can be retrieved from an external disk location. // Passwords can be obtained from disk in two different ways. // Either in a registry key matching the (probably renamed) // executable file that is this server, OR by loading a // predefined file name at a predefined location. // This file must be present while starting the server, but can be // removed once this process has fully started. // --Load External Password Begin-- GString strPassword; GString strPort; GString strRoot; if (!bPasswordCompileEmbedded) { GString strThisEXEName(GetThisEXEName()); GString strStartupKey; // use our runtime image name as the registry key char buf[512]; long lSize = sizeof(buf); if (RegQueryValue(HKEY_CLASSES_ROOT,(const char *)strThisEXEName,buf,&lSize) == ERROR_SUCCESS) { // uudecode the startup key BUFFER b; BufferInit(&b); unsigned int nDecoded; uudecode(buf, &b, &nDecoded, false); strStartupKey.write((const char *)b.pBuf,nDecoded); BufferTerminate(&b); } GString strStartupData; if (strStartupKey.Length()) { // look for a file in the root of the file system (c:\) // with the same name as this .exe GString strFile("c:\\"); strFile += strThisEXEName; // load the crypted disk file into clear text memory char *pDest; int nDestLen; GString strErrorOut; if (FileDecryptToMemory(strStartupKey, strFile, &pDest, &nDestLen, strErrorOut)) { // parse into the profile data structures pDest[7 + nDestLen] = 0; // null terminate it strStartupData.write(&pDest[7], nDestLen + 1); // and cap the GString } else { // if the file was not in the root of the file system // see if there is an environment setting directing // this server to look for the file in another location // The variable name is dynamic, matching this .exe name // and the environment variable value must be a fully // qualified path and file name to the startup file. if (getenv(strThisEXEName)) { if (FileDecryptToMemory(strStartupKey, getenv(strThisEXEName), &pDest, &nDestLen, strErrorOut)) { // parse into the profile data structures strStartupData.write(&pDest[7], nDestLen-7); } } } // parse stored settings in startup file to startup variables if (strStartupData.Length()) { GStringList lstOptions("&&",strStartupData); GStringIterator it(&lstOptions); if (it()) strPassword = it++; if (it()) strRoot = it++; // currently not used if (it()) strPort = it++; } } } // --Load External Password End-- GString strFile; GString strConfigFileDefault; GString strErrorOut; int bSetStartupFile = 0; #ifdef _WIN32 SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS); // = 1 point above normal #endif // Create the completion port and save its handle in a global // variable so that the Handler function can access it. g_hIOCP = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, CK_PIPE, 0); // Give SCM the address of this service's Handler // NOTE: hSS does not have to be closed. hSS = RegisterServiceCtrlHandler((const char *)strServerName, TimeServiceHandler); // Do what the service should do. // Initialize the members that never change ss.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; do { switch (dwCompKey) { case CK_SERVICECONTROL: // We got a new control code ss.dwWin32ExitCode = NO_ERROR; ss.dwServiceSpecificExitCode = 0; ss.dwCheckPoint = 0; ss.dwWaitHint = 0; if (fdwControl == SERVICE_CONTROL_INTERROGATE) { SetServiceStatus(hSS, &ss); break; } // Determine which PENDING state to return if (dwSrvCtrlToPend[fdwControl] != 0) { ss.dwCurrentState = dwSrvCtrlToPend[fdwControl]; ss.dwCheckPoint = 0; ss.dwWaitHint = 500; // half a second SetServiceStatus(hSS, &ss); } switch (fdwControl) { case SERVICE_CONTROL_RUN: case SERVICE_CONTROL_CONTINUE: try { if (strRoot.Length() && strPort.Length()) { GString strCfgData; strCfgData.Format(pzBoundStartupConfig,(const char *)strRoot,(const char *)strPort); SetProfile(new GProfile((const char *)strCfgData, (int)strCfgData.Length(), 0)); if (!server_start()) { ss.dwCurrentState = SERVICE_STOPPED; ss.dwCheckPoint = ss.dwWaitHint = 0; SetServiceStatus(hSS, &ss); break; } } else { // No password compiled in - and no valid startup file found for(int i=0; i<3;i++) { // three beeps MessageBeep(0); Sleep(1000); } ss.dwCurrentState = SERVICE_STOPPED; ss.dwCheckPoint = ss.dwWaitHint = 0; SetServiceStatus(hSS, &ss); break; } } catch ( GException &) { ss.dwCurrentState = SERVICE_STOPPED; ss.dwCheckPoint = ss.dwWaitHint = 0; SetServiceStatus(hSS, &ss); break; } if (dwSrvPendToState[ss.dwCurrentState] != 0) { ss.dwCurrentState = dwSrvPendToState[ss.dwCurrentState]; ss.dwCheckPoint = ss.dwWaitHint = 0; SetServiceStatus(hSS, &ss); } break; case SERVICE_CONTROL_PAUSE: case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: server_stop(); if (dwSrvPendToState[ss.dwCurrentState] != 0) { ss.dwCurrentState = dwSrvPendToState[ss.dwCurrentState]; ss.dwCheckPoint = ss.dwWaitHint = 0; SetServiceStatus(hSS, &ss); } break; } // Determine which complete state to return break; } if (ss.dwCurrentState != SERVICE_STOPPED) { // Sleep until a control code comes in or a client connects GetQueuedCompletionStatus(g_hIOCP, &dwBytesTransferred, &dwCompKey, &po, INFINITE); fdwControl = dwBytesTransferred; } } while (ss.dwCurrentState != SERVICE_STOPPED); // Cleanup and stop this service CloseHandle(g_hIOCP); }
void USARTInit(uint16_t tx_pin, uint16_t rx_pin, uint32_t usart) { #ifdef BUFFERED //initialise buffers BufferInit(&U1Rx); BufferInit(&U1Tx); #endif GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure; g_usart = usart; // keep track of which USART we are using //enable bus clocks RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); if (usart == USART1) RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1, ENABLE ); else RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2, ENABLE); //Configure USART1 Tx (PA.09) as alternate function push-pull GPIO_InitStructure.GPIO_Pin = tx_pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure USART1 Rx (PA.10) as input floating GPIO_InitStructure.GPIO_Pin = rx_pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART1 and USART2 configuration ------------------------------------------------------*/ /* USART and USART2 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl =USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure USART1 */ USART_Init(g_usart, &USART_InitStructure); /* Enable the USART1 */ USART_Cmd(g_usart, ENABLE); #ifdef BUFFERED //configure NVIC NVIC_InitTypeDef NVIC_InitStructure; //select NVIC channel to configure NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //set priority to lowest NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; //set sub-priority to lowest NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; //enable IRQ channel NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //update NVIC registers NVIC_Init(&NVIC_InitStructure); //disable Transmit Data Register empty interrupt USART_ITConfig(USART1, USART_IT_TXE, DISABLE); //enable Receive Data register not empty interrupt USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); vSemaphoreCreateBinary(xSerialHandlerSemaphore); #endif // comm_puts("TEST\0\r\n"); }
/** * @brief Main program * @param None * @retval None */ int main(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; BufferInit(&TxRingBuf); BufferInit(&RxRingBuf); /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f401xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* TIM Configuration */ //TIM_Config(); /* ----------------------------------------------------------------------- TIM3 Configuration: generate 4 PWM signals with 4 different duty cycles. In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1. TIM3CLK = 2 * PCLK1 PCLK1 = HCLK / 4 => TIM3CLK = HCLK / 2 = SystemCoreClock /2 To get TIM3 counter clock at 14 MHz, the prescaler is computed as follows: Prescaler = (TIM3CLK / TIM3 counter clock) - 1 Prescaler = ((SystemCoreClock /2) /14 MHz) - 1 To get TIM3 output clock at 21 KHz, the period (ARR)) is computed as follows: ARR = (TIM3 counter clock / TIM3 output clock) - 1 = 665 TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR)* 100 = 50% TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR)* 100 = 37.5% TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR)* 100 = 25% TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR)* 100 = 12.5% Note: SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate() function to update SystemCoreClock variable value. Otherwise, any configuration based on this variable will be incorrect. ----------------------------------------------------------------------- */ //=========================================================== //UART config //=========================================================== USART_InitTypeDef UartHandle; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; USART_ClockInitTypeDef USART_ClockInitStruct; RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); USART_StructInit(&UartHandle); USART_ClockStructInit(&USART_ClockInitStruct); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2); GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOD, &GPIO_InitStructure); USART_Init(USART2,&UartHandle); USART_ClockInit(USART2,&USART_ClockInitStruct); USART_ITConfig(USART2,USART_IT_RXNE,ENABLE); USART_ITConfig(USART2, USART_IT_TC,ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_Cmd(USART2, ENABLE); Delay(40); Sevenseg_Setup(); Delay(40); USART_SendData(USART2,0xaaaa); //GPIO_SetBits(GPIOB,GPIO_Pin_0 | GPIO_Pin_1); GPIO_SetBits(GPIOD,GPIO_Pin_0); //====================================================== //---------------------------------------------------- //======================================================== // /* Compute the prescaler value */ // PrescalerValue = (uint16_t) (SystemCoreClock / 1000000) - 1; // // /* Time base configuration */ // TIM_TimeBaseStructure.TIM_Period = 5000; // TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; // TIM_TimeBaseStructure.TIM_ClockDivision = 0; // TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // // TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); // // /* PWM1 Mode configuration: Channel1 */ // TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; // TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; // TIM_OCInitStructure.TIM_Pulse = CCR1_Val; // TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; // // TIM_OC1Init(TIM3, &TIM_OCInitStructure); // // TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); // // // /* PWM1 Mode configuration: Channel2 */ // TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; // TIM_OCInitStructure.TIM_Pulse = CCR2_Val; // // TIM_OC2Init(TIM3, &TIM_OCInitStructure); // // TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); // // /* PWM1 Mode configuration: Channel3 */ // TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; // TIM_OCInitStructure.TIM_Pulse = CCR3_Val; // // TIM_OC3Init(TIM3, &TIM_OCInitStructure); // // TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); // // /* PWM1 Mode configuration: Channel4 */ // TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; // TIM_OCInitStructure.TIM_Pulse = CCR4_Val; // // TIM_OC4Init(TIM3, &TIM_OCInitStructure); // // TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable); // // TIM_ARRPreloadConfig(TIM3, ENABLE); // // /* TIM3 enable counter */ // TIM_Cmd(TIM3, ENABLE); int bts = 0; Sevenseg_Send(0x33); while (1) { if(RxRingBuf.length > 10) { int i; int ntosend = RxRingBuf.length; for(i = 0; i < ntosend;i++) { bts = BufferRead(&RxRingBuf); //if(bts == -1) break; USART2_SendByte(bts); } /* while(TxRingBuf.length > 0) { if((TxRingBuf.length > 0) && (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == SET)) { BufferSend(&TxRingBuf); } } */ } /* GPIO_ResetBits(GPIOB,GPIO_Pin_0 | GPIO_Pin_1); GPIO_ResetBits(GPIOA,GPIO_Pin_0); //GPIO_ToggleBits(GPIOB, GPIO_Pin_0); GPIO_SetBits(GPIOB,GPIO_Pin_0 | GPIO_Pin_1); GPIO_SetBits(GPIOA,GPIO_Pin_0); */ //USART_SendData(USART2,0x0051); //USART_SendData(USART2,0x003b); } }
void UART_Init(uint8_t channel) { // use flag so init calls to Timing_Init and Task_Init get called only once static uint8_t init_flag = 0; rx_flags = 0; switch(channel){ #ifdef USE_UART0 case 0: hal_UART_Init(channel, UART0_BAUD); BufferInit(&rx0, &rx_buffer_array0[0], UART0_RX_BUFFER_LENGTH); BufferInit(&tx0, &tx_buffer_array0[0], UART0_TX_BUFFER_LENGTH); CharReceiverList_Init(&receiverList0, &receiver_array0[0], NUM_UART0_RECEIVERS); uart[0].rx = &rx0; uart[0].tx = &tx0; uart[0].receiverList = &receiverList0; break; #endif #ifdef USE_UART1 case 1: hal_UART_Init(channel, UART1_BAUD); BufferInit(&rx1, &rx_buffer_array1[0], UART1_RX_BUFFER_LENGTH); BufferInit(&tx1, &tx_buffer_array1[0], UART1_TX_BUFFER_LENGTH); CharReceiverList_Init(&receiverList1, &receiver_array1[0], NUM_UART1_RECEIVERS); uart[1].rx = &rx1; uart[1].tx = &tx1; uart[1].receiverList = &receiverList1; break; #endif #ifdef USE_UART2 case 2: hal_UART_Init(channel, UART2_BAUD); BufferInit(&rx2, &rx_buffer_array2[0], UART2_RX_BUFFER_LENGTH); BufferInit(&tx2, &tx_buffer_array2[0], UART2_TX_BUFFER_LENGTH); CharReceiverList_Init(&receiverList2, &receiver_array2[0], NUM_UART2_RECEIVERS); uart[2].rx = &rx2; uart[2].tx = &tx2; uart[2].receiverList = &receiverList2; break; #endif #ifdef USE_UART3 case 3: hal_UART_Init(channel, UART3_BAUD); BufferInit(&rx3, &rx_buffer_array3[0], UART3_RX_BUFFER_LENGTH); BufferInit(&tx3, &tx_buffer_array3[0], UART3_TX_BUFFER_LENGTH); CharReceiverList_Init(&receiverList3, &receiver_array3[0], NUM_UART3_RECEIVERS); uart[3].rx = &rx3; uart[3].tx = &tx3; uart[3].receiverList = &receiverList3; break; #endif #ifdef USE_UART4 case 4: hal_UART_Init(channel, UART4_BAUD); BufferInit(&rx4, &rx_buffer_array4[0], UART4_RX_BUFFER_LENGTH); BufferInit(&tx4, &tx_buffer_array4[0], UART4_TX_BUFFER_LENGTH); CharReceiverList_Init(&receiverList4, &receiver_array4[0], NUM_UART4_RECEIVERS); uart[4].rx = &rx4; uart[4].tx = &tx4; uart[4].receiverList = &receiverList4; break; #endif #ifdef USE_UART5 case 5: hal_UART_Init(channel, UART5_BAUD); BufferInit(&rx5, &rx_buffer_array5[0], UART5_RX_BUFFER_LENGTH); BufferInit(&tx5, &tx_buffer_array5[0], UART5_TX_BUFFER_LENGTH); CharReceiverList_Init(&receiverList5, &receiver_array5[0], NUM_UART5_RECEIVERS); uart[5].rx = &rx5; uart[5].tx = &tx5; uart[5].receiverList = &receiverList5; break; #endif #ifdef USE_UART6 case 6: hal_UART_Init(channel, UART6_BAUD); BufferInit(&rx6, &rx_buffer_array6[0], UART6_RX_BUFFER_LENGTH); BufferInit(&tx6, &tx_buffer_array6[0], UART6_TX_BUFFER_LENGTH); CharReceiverList_Init(&receiverList6, &receiver_array6[0], NUM_UART6_RECEIVERS); uart[6].rx = &rx6; uart[6].tx = &tx6; uart[6].receiverList = &receiverList6; break; #endif #ifdef USE_UART7 case 7: hal_UART_Init(channel, UART7_BAUD); BufferInit(&rx7, &rx_buffer_array7[0], UART7_RX_BUFFER_LENGTH); BufferInit(&tx7, &tx_buffer_array7[0], UART7_TX_BUFFER_LENGTH); CharReceiverList_Init(&receiverList7, &receiver_array7[0], NUM_UART7_RECEIVERS); uart[7].rx = &rx7; uart[7].tx = &tx7; uart[7].receiverList = &receiverList7; break; #endif } #ifdef _TASK_H_ #ifndef UART_TICK_OVERRIDE // if the Task Management Module is being used then schedule // the UART_Tick to happen every ms if(init_flag == 0) { // make sure the task manager is initialized Task_Init(); Task_Schedule(UART_Tick,0,1,1); } #endif #endif init_flag = 1; }