| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- /*
- *
- *
- *
- *
- */
- #include "string.h"
- #include "main.h"
- #include "usart.h"
- UART_HandleTypeDef huart3;
- extern uint8_t esp8266_rxdata;
- #define RX_BUF_MAX_LEN 1536
- /*typedef struct _frame_state_{
- __IO uint16_t FrameHeadIndex;
- __IO uint16_t FrameTailIndex;
- __IO uint16_t FrameLength;
- __IO uint8_t FrameStateFlag;//0,idle; 1: working; 2:done;
- __IO uint8_t FrameOverrunFlag;
- }stBufferState, *pBufferState;
- typedef struct _frame_timeout_{
- __IO uint16_t starttime;
- __IO uint16_t timeoutConst;//ms
- __IO uint16_t timeoutFrame;
- __IO uint16_t byteTransTime;//us: 113us@115200, 10us@1382400, 3us@4608000; 13bits/byte=1+9+2+1
- }stFrameTimeout, *pFrameTimeout;
- typedef struct _struct_frame_
- {
- char Data_RX_BUF[RX_BUF_MAX_LEN];
- stBufferState RX_State;
- stFrameTimeout RX_timeout;
- char Data_TX_BUF[RX_BUF_MAX_LEN];
- stBufferState TX_State;
- stFrameTimeout TX_timeout;
- }stBufferFrame, *pBufferFrame;*/
- #pragma pack(4)
- typedef struct _frame_state_{
- uint8_t FrameStateFlag;//0,idle; 1: working; 2:done;
- uint8_t FrameOverrunFlag;
- uint16_t FrameHeadIndex;
- uint16_t FrameTailIndex;
- uint16_t FrameLength;
- }stBufferState, *pBufferState;
- #pragma pack()
- #pragma pack(4)
- typedef struct _frame_timeout_{
- uint32_t starttime;
- uint16_t timeoutConst;//ms
- uint16_t byteTransTime;//us: 113us@115200, 10us@1382400, 3us@4608000; 13bits/byte=1+9+2+1
- uint32_t timeoutFrame;
- }stFrameTimeout, *pFrameTimeout;
- #pragma pack()
- #pragma pack(4)
- typedef struct _struct_frame_
- {
- char Data_RX_BUF[RX_BUF_MAX_LEN];
- __IO stBufferState RX_State;
- stFrameTimeout RX_timeout;
- char Data_TX_BUF[RX_BUF_MAX_LEN];
- __IO stBufferState TX_State;
- stFrameTimeout TX_timeout;
- }stBufferFrame, *pBufferFrame;
- #pragma pack()
- //extern stBufferFrame stWifiFrameRecord;
- stBufferFrame stWifiFrameRecord={0};
- //__IO uint8_t UartReady = RESET;
- UART_HandleTypeDef wifi_UartHandle;
- UART_HandleTypeDef huart3;
- #if 0
- void Delay_ms( unsigned int time_ms )
- {
- unsigned int temp=0;
- unsigned int start = HAL_GetTick();
- do
- {
- temp = HAL_GetTick();
- }
- while(time_ms > temp - start);
- }
- #endif
- /*
- * Init Usart with given baudrate.
- * Note:
- * Lowest baudrate is 57600!
- */
- void Wifi_USART_Init(uint32_t baud)
- {
- uint32_t temp=0;
- GPIO_InitTypeDef GPIO_InitStruct;
- if(baud < WIFI_LOWEST_BAUDRATE)
- {
- baud = WIFI_LOWEST_BAUDRATE;
- }
- else if( baud > WIFI_HIGHEST_BAUDRATE)
- {
- baud = WIFI_HIGHEST_BAUDRATE;
- }
-
- wifi_UartHandle.Instance = WIFI_UART;
- wifi_UartHandle.Init.BaudRate = (baud==WIFI_LOWEST_BAUDRATE) ? WIFI_LOWEST_BAUDRATE : WIFI_HIGH_BAUDRATE;
- wifi_UartHandle.Init.WordLength = WIFI_UART_WORDLENGTH;
- wifi_UartHandle.Init.StopBits = WIFI_UART_STOPBITS;
- wifi_UartHandle.Init.Parity = WIFI_UART_PARITY;
- wifi_UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- wifi_UartHandle.Init.Mode = UART_MODE_TX_RX;
- wifi_UartHandle.Init.OverSampling = UART_OVERSAMPLING_8;
- HAL_NVIC_SetPriority(UART5_IRQn, 1, 0);
- HAL_NVIC_EnableIRQ(UART5_IRQn);
- if(HAL_UART_Init(&wifi_UartHandle) != HAL_OK)
- {
- //Error_Handler();
- }
-
- /*##-2- Configure peripheral GPIO ##########################################*/
- WIFI_RST_GPIO_CLK_ENABLE();
- GPIO_InitStruct.Pin = WIFI_RST_PIN;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = WIFI_RST_PIN_PULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(WIFI_RST_GPIO_PORT, &GPIO_InitStruct);
- WIFI_ENABLE_GPIO_CLK_ENABLE();
- GPIO_InitStruct.Pin = WIFI_ENABLE_PIN;
- GPIO_InitStruct.Pull = WIFI_ENABLE_PIN_PULL;
- HAL_GPIO_Init(WIFI_ENABLE_GPIO_PORT, &GPIO_InitStruct);
- WIFI_CS_GPIO_CLK_ENABLE();
- GPIO_InitStruct.Pin = WIFI_CS_PIN;
- GPIO_InitStruct.Pull = WIFI_CS_PIN_PULL;
- HAL_GPIO_Init(WIFI_CS_GPIO_PORT, &GPIO_InitStruct);
- //HAL_UART_Transmit_IT(&wifi_UartHandle,"0123456789\r\n",12);
- /*HAL_StatusTypeDef status= HAL_UART_Transmit(&wifi_UartHandle,"0123456789\r\n",12,1000);
- status++;*/
- //
- temp = (uint16_t)(13 * 1000000.0 / wifi_UartHandle.Init.BaudRate + 0.55);
- stWifiFrameRecord.RX_timeout.byteTransTime = temp;//us
- //stWifiFrameRecord.RX_timeout.timeoutConst = 1500;//1000ms
- stWifiFrameRecord.TX_timeout.byteTransTime = temp;//us
- //stWifiFrameRecord.TX_timeout.timeoutConst = 200;//200ms
- Wifi_Start();
- }
- void Wifi_Start(void)
- {
- HAL_GPIO_WritePin(WIFI_RST_GPIO_PORT, WIFI_RST_PIN, GPIO_PIN_SET);
- HAL_GPIO_WritePin(WIFI_CS_GPIO_PORT, WIFI_CS_PIN, GPIO_PIN_RESET);
- HAL_GPIO_WritePin(WIFI_ENABLE_GPIO_PORT, WIFI_ENABLE_PIN, GPIO_PIN_SET);
- }
- int Wifi_reset(void)
- {
- static int rststate=0;
- static uint32_t starttime=0;
- switch(rststate)
- {
- case 0:
- HAL_GPIO_WritePin(WIFI_RST_GPIO_PORT, WIFI_RST_PIN, GPIO_PIN_RESET);
- HAL_GPIO_WritePin(WIFI_CS_GPIO_PORT, WIFI_CS_PIN, GPIO_PIN_SET);
- HAL_GPIO_WritePin(WIFI_ENABLE_GPIO_PORT, WIFI_ENABLE_PIN, GPIO_PIN_RESET);
- rststate=1;
- starttime=HAL_GetTick();
- break;
- case 1:
- if(HAL_GetTick()-starttime<500)
- {
- break;
- }
- rststate=2;
- case 2:
- HAL_GPIO_WritePin(WIFI_CS_GPIO_PORT, WIFI_CS_PIN, GPIO_PIN_RESET);
- HAL_GPIO_WritePin(WIFI_ENABLE_GPIO_PORT, WIFI_ENABLE_PIN, GPIO_PIN_SET);
- HAL_GPIO_WritePin(WIFI_RST_GPIO_PORT, WIFI_RST_PIN, GPIO_PIN_SET);
- starttime=HAL_GetTick();
- rststate=3;
- break;
- case 3:
- if(HAL_GetTick()-starttime < 1000)
- {
- break;
- }
- default:
- rststate=0;
- break;
- }
- return rststate;
- }
- /*
- Tail is the newest byte!!
- */
- unsigned int Wifi_Uart_DataLen(void)
- {
- if(!stWifiFrameRecord.RX_State.FrameOverrunFlag)
- {
- if(stWifiFrameRecord.RX_State.FrameTailIndex<=stWifiFrameRecord.RX_State.FrameHeadIndex)
- return (stWifiFrameRecord.RX_State.FrameHeadIndex-stWifiFrameRecord.RX_State.FrameTailIndex);
- else
- return (RX_BUF_MAX_LEN - stWifiFrameRecord.RX_State.FrameTailIndex
- + stWifiFrameRecord.RX_State.FrameHeadIndex);
- }
- return RX_BUF_MAX_LEN;
- }
- /*
- */
- unsigned int Wifi_Uart_ReadData(uint8_t* buf, uint32_t len)
- {
- uint16_t len1,len2;
- uint16_t idxHead = stWifiFrameRecord.RX_State.FrameHeadIndex;
- uint16_t idxTail = stWifiFrameRecord.RX_State.FrameTailIndex;
- if(idxTail <= idxHead)
- {
- len1 = idxHead - idxTail;
- if(len1 > len)
- {
- len1 = len;
- }
- memcpy((void*)buf, (void*)&stWifiFrameRecord.Data_RX_BUF[idxTail], len1);
- stWifiFrameRecord.RX_State.FrameTailIndex += len1;
- }
- else
- {
- len1 = RX_BUF_MAX_LEN - idxTail;
- if(len1 > len)
- {
- len1 = len;
- }
- memcpy((void*)buf, (void*)&stWifiFrameRecord.Data_RX_BUF[idxTail], len1);
- stWifiFrameRecord.RX_State.FrameTailIndex += len1;
- if(stWifiFrameRecord.RX_State.FrameTailIndex >= RX_BUF_MAX_LEN)
- {
- stWifiFrameRecord.RX_State.FrameTailIndex = 0;
- }
- len -= len1;
- if(len > 0)
- {
- len2 = idxHead - len;
- if(len2 > len)
- {
- len2 = len;
- }
- memcpy((void*)(buf+len1), (void*)&stWifiFrameRecord.Data_RX_BUF[idxTail], len2);
- stWifiFrameRecord.RX_State.FrameTailIndex += len2;
- if(stWifiFrameRecord.RX_State.FrameTailIndex >= RX_BUF_MAX_LEN)
- {
- stWifiFrameRecord.RX_State.FrameTailIndex = 0;
- }
- len1 += len2;
- }
- }
- if(len1 > 0)
- {
- stWifiFrameRecord.RX_State.FrameOverrunFlag = 0;
- }
- return len1;
- }
- /**/
- void Wifi_Uart_ClearRxBuf(void)
- {
- memset((void*)&stWifiFrameRecord.RX_State, 0, sizeof(stBufferState));
- memset((void*)&stWifiFrameRecord.RX_timeout, 0, sizeof(stFrameTimeout));
- }
- void Wifi_Uart_ClearTxBuf(void)
- {
- memset((void*)&stWifiFrameRecord.TX_State, 0, sizeof(stBufferState));
- memset((void*)&stWifiFrameRecord.TX_timeout, 0, sizeof(stFrameTimeout));
- }
- int Wifi_Uart_Send(uint8_t *buf, uint32_t len,uint32_t timeout)
- {
- #if UART_INF_REG==1
- int ret=0;
- uint32_t time=0;
- pBufferState pstate = (pBufferState)&stWifiFrameRecord.TX_State;
- pFrameTimeout ptimeout = &stWifiFrameRecord.TX_timeout;
- if(stWifiFrameRecord.TX_State.FrameStateFlag == 0)//idle
- {
- /*stWifiFrameRecord.TX_State.FrameStateFlag = 1;
- stWifiFrameRecord.TX_State.FrameHeadIndex = 0;
- stWifiFrameRecord.TX_State.FrameTailIndex = 0;
- stWifiFrameRecord.TX_State.FrameLength = len;
- memcpy(stWifiFrameRecord.Data_TX_BUF,buf,len);
- ret = (stWifiFrameRecord.TX_timeout.byteTransTime * len + 599) / 1000 + 1;
- if(timeout < ret) timeout = ret;
- stWifiFrameRecord.TX_timeout.timeoutConst = timeout;
- ret += stWifiFrameRecord.TX_timeout.timeoutConst;
- stWifiFrameRecord.TX_timeout.timeoutFrame = ret;
- time = HAL_GetTick();
- stWifiFrameRecord.TX_timeout.starttime = time;*/
- pstate->FrameStateFlag = 1;
- pstate->FrameHeadIndex = 0;
- pstate->FrameTailIndex = 0;
- pstate->FrameLength = len;
- memcpy(stWifiFrameRecord.Data_TX_BUF,buf,len);
- ret = (ptimeout->byteTransTime * len + 599) / 1000 + 1;
- if(timeout < ret) timeout = ret;
- ptimeout->timeoutConst = timeout;
- ret += ptimeout->timeoutConst;
- ptimeout->timeoutFrame = ret;
- time = HAL_GetTick();
- ptimeout->starttime = time;
- time++;
- SET_BIT(WIFI_UART->CR1, USART_CR1_TE);
- //CLEAR_BIT(WIFI_UART->CR1, USART_CR1_TCIE);
- /* Enable the UART Transmit data register empty Interrupt */
- SET_BIT(WIFI_UART->CR1, USART_CR1_TXEIE);
- SET_BIT(WIFI_UART->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
- return 0;
- }
- else if(stWifiFrameRecord.TX_State.FrameStateFlag == 2)
- {
- CLEAR_BIT(WIFI_UART->CR1, USART_CR1_TCIE);
- CLEAR_BIT(WIFI_UART->CR1, USART_CR1_TXEIE);
- stWifiFrameRecord.TX_State.FrameStateFlag = 0;
- return stWifiFrameRecord.TX_State.FrameTailIndex;
- }
- else
- {
- time = HAL_GetTick();
- if(stWifiFrameRecord.TX_timeout.timeoutFrame <=
- time - stWifiFrameRecord.TX_timeout.starttime)
- {
- stWifiFrameRecord.TX_State.FrameStateFlag = 0;
- return -1;
- }
- return 0;
- }
- #else
- UartReady = RESET;
- HAL_UART_Transmit_IT(&wifi_UartHandle,buf,len);
- while(UartReady == RESET)
- {
- ;
- }
- return 0;
- #endif
- }
- int Wifi_Uart_Receive(uint8_t *buf, uint32_t len,uint32_t timeout)
- {
- #if UART_INF_REG==1
- int ret=0;
- uint32_t time=0;
- if(stWifiFrameRecord.RX_State.FrameStateFlag == 0)//idle
- {
- if(buf==NULL || len==0)
- {
- return -1;
- }
- stWifiFrameRecord.RX_State.FrameStateFlag = 1;
- stWifiFrameRecord.RX_State.FrameLength = len;
- ret = (stWifiFrameRecord.RX_timeout.byteTransTime * len + 599) / 1000 + 1;
- if(timeout < ret) timeout = ret;
- stWifiFrameRecord.RX_timeout.timeoutConst = timeout;
- ret += stWifiFrameRecord.RX_timeout.timeoutConst;
- stWifiFrameRecord.RX_timeout.timeoutFrame = ret;
- time = HAL_GetTick();
- stWifiFrameRecord.RX_timeout.starttime = time;
- SET_BIT(WIFI_UART->CR1, USART_CR1_RE);
- // Enable the UART Error Interrupt: (Frame error, noise error, overrun error)
- SET_BIT(WIFI_UART->CR3, USART_CR3_EIE);
- // Enable the UART Parity Error and Data Register not empty Interrupts
- SET_BIT(WIFI_UART->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
- return 0;
- }
- else
- {
- ret = Wifi_Uart_DataLen();
- //if(stWifiFrameRecord.RX_State.FrameStateFlag == 3 || ret >= len)
- if(ret >= len)
- {
- stWifiFrameRecord.RX_State.FrameStateFlag = 0;//over
- if(len < ret) len = ret;
- ret = Wifi_Uart_ReadData(buf,len);
- }
- else
- {
- time = HAL_GetTick();
- if(stWifiFrameRecord.RX_timeout.timeoutFrame <=
- (time - stWifiFrameRecord.RX_timeout.starttime))
- {
- stWifiFrameRecord.RX_State.FrameStateFlag = 0;//over
- //ret = Wifi_Uart_DataLen();
- ret = Wifi_Uart_ReadData(buf, ret);
- if(ret <= 0)
- return -2;
- return ret;
- }
- ret = 0;//wait again
- }
- return ret;
- }
- /*if(stWifiFrameRecord.RX_State.FrameStateFlag == 0)//idle
- {
- stWifiFrameRecord.RX_State.FrameStateFlag = 1;
- stWifiFrameRecord.RX_State.FrameHeadIndex = 0;
- stWifiFrameRecord.RX_State.FrameTailIndex = 0;
- stWifiFrameRecord.RX_State.FrameLength = len;
- memset(stWifiFrameRecord.Data_RX_BUF,0,RX_BUF_MAX_LEN);
- stWifiFrameRecord.RX_State.FrameOverrunFlag = 0;
- stWifiFrameRecord.RX_timeout.timeoutFrame = stWifiFrameRecord.RX_timeout.byteTransTime * len;
- stWifiFrameRecord.RX_timeout.timeoutFrame += stWifiFrameRecord.RX_timeout.timeoutConst + 1;
- stWifiFrameRecord.RX_timeout.starttime = HAL_GetTick();
- SET_BIT(WIFI_UART->CR1, USART_CR1_RE);
- // Enable the UART Error Interrupt: (Frame error, noise error, overrun error)
- SET_BIT(WIFI_UART->CR3, USART_CR3_EIE);
- // Enable the UART Parity Error and Data Register not empty Interrupts
- SET_BIT(WIFI_UART->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
- return 0;
- }
- else if(stWifiFrameRecord.RX_State.FrameStateFlag >= 2)
- {
- CLEAR_BIT(WIFI_UART->CR3, USART_CR3_EIE);
- CLEAR_BIT(WIFI_UART->CR1, USART_CR1_PEIE);
- CLEAR_BIT(WIFI_UART->CR1, USART_CR1_RXNEIE);
- memcpy(buf,stWifiFrameRecord.Data_RX_BUF,stWifiFrameRecord.RX_State.FrameLength);
- stWifiFrameRecord.RX_State.FrameStateFlag = 0;
- return stWifiFrameRecord.RX_State.FrameLength;
- }
- else
- {
- if(stWifiFrameRecord.RX_timeout.timeoutFrame <=
- (HAL_GetTick() - stWifiFrameRecord.RX_timeout.starttime))
- {
- stWifiFrameRecord.RX_State.FrameStateFlag = 0;
- return -1;
- }
- if((stWifiFrameRecord.RX_State.FrameTailIndex - stWifiFrameRecord.RX_State.FrameHeadIndex)
- >= stWifiFrameRecord.RX_State.FrameLength)
- {
- memcpy(buf,stWifiFrameRecord.Data_RX_BUF,stWifiFrameRecord.RX_State.FrameLength);
- stWifiFrameRecord.RX_State.FrameStateFlag = 0;
- return stWifiFrameRecord.RX_State.FrameLength;
- }
- return 0;
- }*/
- #else
- return HAL_UART_Receive(&wifi_UartHandle,buf,len,3000);
- #endif
- }
- #if UART_INF_REG==1
- #define __UART_GET_FLAG(__UART__, __FLAG__) (((__UART__)->SR & (__FLAG__)) == (__FLAG__))
- #define __UART_CLEAR_FLAG(__UART__, __FLAG__) ((__UART__)->SR = ~(__FLAG__))
- void Wifi_Uart_IRQ_Handler(void)
- {
- uint32_t sr = WIFI_UART->SR;//1
- uint16_t ucCh = (uint16_t)(WIFI_UART->DR);//2
- //uint16_t temp = 0;
- uint32_t cr1 = WIFI_UART->CR1;
- //uint32_t cr3 = WIFI_UART->CR3;
- //if( __UART_GET_FLAG(WIFI_UART, UART_FLAG_RXNE))
- if((sr&UART_FLAG_RXNE)>0)
- {
- __UART_CLEAR_FLAG( WIFI_UART, UART_FLAG_RXNE );
- /*
- #if WIFI_UART_WORDLENGTH==UART_WORDLENGTH_8B
- #if (WIFI_UART_PARITY == UART_PARITY_NONE)
- ucCh = (uint8_t)(WIFI_UART->DR & 0x00FF);
- #else
- ucCh = (uint8_t)(WIFI_UART->DR & 0x007F);
- #endif
- #else //(WIFI_UART_WORDLENGTH == UART_WORDLENGTH_9B)
- #if (WIFI_UART_PARITY == UART_PARITY_NONE)
- ucCh = (uint16_t)(WIFI_UART->DR & 0x01FF);
- len=2;
- #else
- ucCh = (uint16_t)(WIFI_UART->DR & 0x00FF);
- #endif
- #endif
- if(stWifiFrameRecord.RX_State.FrameStateFlag == 1)
- {
- if(stWifiFrameRecord.RX_State.FrameTailIndex < ( stWifiFrameRecord.RX_State.FrameLength - 1 ) )
- {
- stWifiFrameRecord.Data_RX_BUF[stWifiFrameRecord.RX_State.FrameTailIndex++] = ucCh;
- }
- else
- {
- stWifiFrameRecord.RX_State.FrameStateFlag = 2;
- }
- }*/
- #if WIFI_UART_WORDLENGTH==UART_WORDLENGTH_8B
- #if (WIFI_UART_PARITY == UART_PARITY_NONE)
- ucCh = (uint8_t)(ucCh & 0x00FF);
- #else
- ucCh = (uint8_t)(ucCh & 0x007F);
- #endif
- #else //(WIFI_UART_WORDLENGTH == UART_WORDLENGTH_9B)
- #if (WIFI_UART_PARITY == UART_PARITY_NONE)
- ucCh = (uint16_t)(ucCh & 0x01FF);
- len=2;
- #else
- ucCh = (uint16_t)(ucCh & 0x00FF);
- #endif
- #endif
- stWifiFrameRecord.Data_RX_BUF[stWifiFrameRecord.RX_State.FrameHeadIndex++] = ucCh;
- if(stWifiFrameRecord.RX_State.FrameHeadIndex >= RX_BUF_MAX_LEN)
- {
- stWifiFrameRecord.RX_State.FrameHeadIndex = 0;
- }
- if(stWifiFrameRecord.RX_State.FrameHeadIndex <= stWifiFrameRecord.RX_State.FrameTailIndex)
- {
- stWifiFrameRecord.RX_State.FrameOverrunFlag = 1;
- }
- }
- //if( __UART_GET_FLAG( WIFI_UART, UART_FLAG_IDLE ))
- if((sr&UART_FLAG_IDLE)>0)
- {
- __UART_CLEAR_FLAG( WIFI_UART, UART_FLAG_IDLE );
- /*
- if(stWifiFrameRecord.RX_State.FrameStateFlag > 0)//In receiving
- {
- stWifiFrameRecord.RX_State.FrameStateFlag = 3;
- }
- #if (WIFI_UART_PARITY == UART_PARITY_NONE)
- ucCh = (uint8_t)(WIFI_UART->DR & 0xFF);
- #else
- ucCh = (uint8_t)(WIFI_UART->DR & 0x7F);
- #endif
- */
- }
- /*if((sr&UART_FLAG_ORE)>0)//
- {
- cr3 = WIFI_UART->SR;
- }*/
- //if( __UART_GET_FLAG( WIFI_UART, UART_FLAG_TXE )&& 0<(WIFI_UART->CR1& USART_CR1_TXEIE))
- if( (sr & UART_FLAG_TXE)>0 && (cr1 & USART_CR1_TXEIE)>0)
- {
- if(stWifiFrameRecord.TX_State.FrameTailIndex < stWifiFrameRecord.TX_State.FrameLength)
- {
- #if (WIFI_UART_PARITY == UART_PARITY_NONE)
- ucCh = 0xFF & stWifiFrameRecord.Data_TX_BUF[stWifiFrameRecord.TX_State.FrameTailIndex];
- #else
- ucCh = 0x7F & stWifiFrameRecord.Data_TX_BUF[stWifiFrameRecord.TX_State.FrameTailIndex];
- #endif
- WIFI_UART->DR = (uint8_t)ucCh;
- stWifiFrameRecord.TX_State.FrameTailIndex++;
- if(stWifiFrameRecord.TX_State.FrameTailIndex>=RX_BUF_MAX_LEN)
- {
- stWifiFrameRecord.TX_State.FrameTailIndex = 0;
- }
- }
- if(stWifiFrameRecord.TX_State.FrameTailIndex >= stWifiFrameRecord.TX_State.FrameLength)
- {
- /* Disable the UART Transmit Complete Interrupt */
- CLEAR_BIT(WIFI_UART->CR1, USART_CR1_TXEIE);
- /* Enable the UART Transmit Complete Interrupt */
- SET_BIT(WIFI_UART->CR1, USART_CR1_TCIE);
- }
- else
- {
- /* Enable the UART Transmit Complete Interrupt */
- CLEAR_BIT(WIFI_UART->CR1, USART_CR1_TCIE);
- /* Disable the UART Transmit Complete Interrupt */
- SET_BIT(WIFI_UART->CR1, USART_CR1_TXEIE);
- }
- sr = WIFI_UART->SR;
- cr1 = WIFI_UART->CR1;
- }
- //if( __UART_GET_FLAG( WIFI_UART, UART_FLAG_TC ) && 0<(WIFI_UART->CR1& USART_CR1_TCIE))
- if( (sr & UART_FLAG_TC) > 0 && (cr1 & USART_CR1_TCIE) > 0)
- {
- __UART_CLEAR_FLAG( WIFI_UART, UART_FLAG_TC );
- /* Disable the UART Transmit Complete Interrupt */
- CLEAR_BIT(WIFI_UART->CR1, USART_CR1_TCIE);
- stWifiFrameRecord.TX_State.FrameStateFlag = 2;
- }
- }
- #else
- /**
- * @brief Tx Transfer completed callback
- * @param UartHandle: UART handle.
- * @note This example shows a simple way to report end of IT Tx transfer, and
- * you can add your own implementation.
- * @retval None
- */
- void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
- {
- UartReady = SET;
- }
- /**
- * @brief Rx Transfer completed callback
- * @param UartHandle: UART handle
- * @note This example shows a simple way to report end of IT Rx transfer, and
- * you can add your own implementation.
- * @retval None
- */
- void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
- {
- ;
- }
- /**
- * @brief UART error callbacks
- * @param UartHandle: UART handle
- * @note This example shows a simple way to report transfer error, and you can
- * add your own implementation.
- * @retval None
- */
- void HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle)
- {
- ;
- }
- #endif
|