void BSP_Ser_ISR_Handler (void) { CPU_REG32 status; OSIntEnter(); while(DEF_TRUE) { status = USART2->SR; if (status & 0x20) /* RX interrupt? */ { /* move received byte and move it into the Rx buff */ BSP_SerialRxBuffer[BSP_RxBuffer_Head_ndx++] = (CPU_INT08U)USART_ReceiveData(USART2); if (BSP_RxBuffer_Head_ndx >= BSP_UART2_RX_BUFFER_SIZE) { BSP_RxBuffer_Head_ndx = 0; } if (BSP_RxBuffer_Head_ndx == BSP_RxBuffer_Tail_ndx) /* check if the Rx buffer becomes full */ { /* Rx buffer is full: drop the oldest byte */ if (++BSP_RxBuffer_Tail_ndx >= BSP_UART2_RX_BUFFER_SIZE) { BSP_RxBuffer_Tail_ndx = 0; } } else { BSP_OS_SemPost(&BSP_SerRxWait); /* Post to the sempahore */ } continue; } else if ((USART2->CR1 & 0x80) && (status & 0x80)) /* is it a TX interrupt? */ { /* Yes, is there any byte in the Tx buffer? */ if (BSP_TxBuffer_Tail_ndx != BSP_TxBuffer_Head_ndx) { /* Send the byte and adjust the buffes indexes */ USART_SendData(USART2, BSP_SerialTxBuffer[BSP_TxBuffer_Tail_ndx++]); if (BSP_TxBuffer_Tail_ndx >= BSP_UART2_RX_BUFFER_SIZE) { BSP_TxBuffer_Tail_ndx = 0; } BSP_OS_SemPost(&BSP_SerTxWait); /* Post to the semaphore */ } else { /* no more bytes to send, disable Tx interrupt */ USART_ITConfig(USART2, USART_IT_TXE, DISABLE); } continue; } else { break; /* quit the interrupt */ } } OSIntExit(); }
void BSP_Ser_RdStr (CPU_CHAR *p_str, CPU_INT16U len) { CPU_CHAR rx_data; CPU_CHAR rx_buf_ix; CPU_BOOLEAN bContinueRx; CPU_BOOLEAN err; rx_buf_ix = 0; p_str[0] = 0; bContinueRx = DEF_TRUE; if (BSP_SerialInitilizated == DEF_TRUE) { err = BSP_OS_SemWait(&BSP_SerLock, 0); /* Obtain access to the serial interface */ if (err != DEF_OK ) { return; } do { rx_data = BSP_Ser_RdByteUnlocked(); if ((rx_data == ASCII_CHAR_CARRIAGE_RETURN) || /* Is it '\r' or '\n' character ? */ (rx_data == ASCII_CHAR_LINE_FEED )) { BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_LINE_FEED); BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_CARRIAGE_RETURN); p_str[rx_buf_ix] = 0; /* set the null character at the end of the string */ bContinueRx = DEF_FALSE; /* exit the loop */ } else if (rx_data == ASCII_CHAR_BACKSPACE) { /* Is backspace character ? */ if (rx_buf_ix > 0) { BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_BACKSPACE); BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_SPACE); BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_BACKSPACE); rx_buf_ix--; /* Decrement the index */ p_str[rx_buf_ix] = 0; } } else if (ASCII_IsPrint(rx_data)) { /* Is it a printable character ... ? */ BSP_Ser_WrByteUnlocked((CPU_INT08U)rx_data); /* Echo-back */ p_str[rx_buf_ix] = rx_data; /* Save the received character in the buffer */ rx_buf_ix++; /* Increment the buffer index */ if (rx_buf_ix >= len) { rx_buf_ix = len; } } } while (bContinueRx == DEF_TRUE); BSP_OS_SemPost(&BSP_SerLock); /* Release access to the serial interface */ } }
void BSP_Ser_WrStr (CPU_CHAR *p_str) { CPU_BOOLEAN err; if (p_str == (CPU_CHAR *)0) { return; } err = BSP_OS_SemWait(&BSP_SerLock, 0); /* Obtain access to the serial interface */ if (err != DEF_OK ) { return; } while ((*p_str) != (CPU_CHAR )0) { if (*p_str == ASCII_CHAR_LINE_FEED) { BSP_Ser_WrByteUnlocked(ASCII_CHAR_CARRIAGE_RETURN); BSP_Ser_WrByteUnlocked(ASCII_CHAR_LINE_FEED); p_str++; } else { BSP_Ser_WrByteUnlocked(*p_str++); } } BSP_OS_SemPost(&BSP_SerLock); /* Release access to the serial interface */ }
void BSP_Ser_WrByte(CPU_INT08U c) { BSP_OS_SemWait(&BSP_SerLock, 0); /* Obtain access to the serial interface */ BSP_Ser_WrByteUnlocked(c); BSP_OS_SemPost(&BSP_SerLock); /* Release access to the serial interface */ }
CPU_ISR BSP_Ser_ISR_Rx_Handler (void) { OSIntEnter(); /* Notify uC/OS-III or uC/OS-II of ISR entry */ CPU_INT_GLOBAL_EN(); /* Reenable global interrupts */ BSP_SerRxData = SCI2.RDR; /* Read one byte from the receive data register. */ IR(SCI2, RXI2) = 0; /* Clear the SCI2 receive interrupt. */ BSP_OS_SemPost(&BSP_SerRxWait); /* Post to the semaphore. */ OSIntExit(); /* Notify uC/OS-III or uC/OS-II of ISR exit */ }
void BSP_Ser_ISR_Handler (void) { FlagStatus tc_status; FlagStatus rxne_status; rxne_status = USART_GetFlagStatus(USART2, USART_FLAG_RXNE); if (rxne_status == SET) { BSP_SerRxData = USART_ReceiveData(USART2) & 0xFF; /* Read one byte from the receive data register. */ USART_ClearITPendingBit(USART2, USART_IT_RXNE); /* Clear the USART2 receive interrupt. */ BSP_OS_SemPost(&BSP_SerRxWait); /* Post to the sempahore */ } tc_status = USART_GetFlagStatus(USART2, USART_FLAG_TC); if (tc_status == SET) { USART_ITConfig(USART2, USART_IT_TC, DISABLE); USART_ClearITPendingBit(USART2, USART_IT_TC); /* Clear the USART2 receive interrupt. */ BSP_OS_SemPost(&BSP_SerTxWait); /* Post to the semaphore */ } }
CPU_INT08U BSP_Ser_RdByte (void) { CPU_INT08U rx_byte = 0; if (BSP_SerialInitilizated == DEF_TRUE) { BSP_OS_SemWait(&BSP_SerLock, 0); /* Obtain access to the serial interface */ rx_byte = BSP_Ser_RdByteUnlocked(); /* Get a byte from the Rx buffer */ BSP_OS_SemPost(&BSP_SerLock); /* Release access to the serial interface */ } return (rx_byte); }
CPU_INT08U BSP_Ser_RdByte (void) { CPU_INT08U rx_byte; BSP_OS_SemWait(&BSP_SerLock, 0); /* Obtain access to the serial interface */ rx_byte = BSP_Ser_RdByteUnlocked(); BSP_OS_SemPost(&BSP_SerLock); /* Release access to the serial interface */ return (rx_byte); }
CPU_ISR BSP_Ser_ISR_Tx_Handler (void) { OSIntEnter(); /* Notify uC/OS-III or uCOS-II of ISR entry */ CPU_INT_GLOBAL_EN(); /* Reenable global interrupts */ // if (SCI2.SSR.BIT.TEND) { /* Check the Transmission Complete bit. */ SCI2.SSR.BIT.TEND; SCI2.SSR.BIT.TEND = 0; BSP_OS_SemPost(&BSP_SerTxWait); /* Post to the semaphore */ // } OSIntExit(); /* Notify uC/OS-III or uC/OS-II of ISR exit */ }
CPU_INT08U BSP_Ser_RdByteNB (CPU_INT08U* p_err) { CPU_INT08U rx_byte = 0; *p_err = BSP_SER_ERR_NO_INIT; if (BSP_SerialInitilizated == DEF_TRUE) { BSP_OS_SemWait(&BSP_SerLock, 0); /* Obtain access to the serial interface */ *p_err = BSP_SER_ERR_RXBUFFER_EMPTY; if (BSP_RxBuffer_Head_ndx != BSP_RxBuffer_Tail_ndx) { rx_byte = BSP_Ser_RdByteUnlocked(); /* Get a byte from the Rx buffer */ *p_err = BSP_SER_ERR_NONE; } BSP_OS_SemPost(&BSP_SerLock); /* Release access to the serial interface */ } return (rx_byte); }
/******************************************************************************* * 名 称: AppTaskTmr * 功 能: 控制任务 * 入口参数: p_arg - 由任务创建函数传入 * 出口参数: 无 * 作 者: wumingshen. * 创建日期: 2015-02-05 * 修 改: * 修改日期: *******************************************************************************/ osalEvt TaskTmrEvtProcess(INT8U task_id, osalEvt task_event) { OS_ERR err; /*********************************************** * 描述: 本任务看门狗标志置位 */ OSSetWdtFlag(( OS_FLAGS ) WDT_FLAG_TMR); /*************************************************************************** * 描述: 统计模块和无线发送模块通讯定时器, COMM_EVT_FLAG_DTU_TIMEOUT 标示。 */ if( task_event & OS_EVT_TMR_SEC ) { static uint8 mPlugTime = 0; static uint8 mNoPlugTime = 0; //无卡状态下,插入IC卡 //无卡状态下,插入IC卡卡,发送信号量 if(ReadIC_SWT() == 1 && Ctrl.sRunPara.plugcard == 0) { if( mPlugTime++ > 2) { Ctrl.sRunPara.plugcard = 1; //发送信号量,启动 IC卡任务 BSP_OS_SemPost(&Bsp_Card_Sem); mNoPlugTime = 0; } //有卡状态,且已经拔出IC卡 } else if ( ReadIC_SWT() == 0 && Ctrl.sRunPara.plugcard == 1) { if( mNoPlugTime++ > 2) { Ctrl.sRunPara.plugcard = 0; mPlugTime = 0; } } return ( task_event ^ OS_EVT_TMR_SEC ); } return 0; }
void BSP_Ser_RdStr (CPU_CHAR *p_str, CPU_INT16U len) { CPU_CHAR *p_char; CPU_BOOLEAN rxd_history_char0; CPU_CHAR rx_data; CPU_BOOLEAN err; rxd_history_char0 = DEF_NO; p_str[0] = (CPU_CHAR)'\0'; p_char = p_str; err = BSP_OS_SemWait(&BSP_SerLock, 0); /* Obtain access to the serial interface */ if (err != DEF_OK ) { return; } while (DEF_TRUE) { rx_data = BSP_Ser_RdByteUnlocked(); if ((rx_data == ASCII_CHAR_CARRIAGE_RETURN) || /* Is it '\r' or '\n' character ? */ (rx_data == ASCII_CHAR_LINE_FEED )) { BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_LINE_FEED); BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_CARRIAGE_RETURN); *p_char = (CPU_CHAR)'\0'; /* set the null character at the end of the string */ #if (BSP_CFG_SER_CMD_HISTORY_LEN > 0u) Str_Copy(BSP_SerCmdHistory, p_str); #endif break; /* exit the loop */ } if (rx_data == ASCII_CHAR_BACKSPACE) { /* Is backspace character */ if (p_char > p_str) { BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_BACKSPACE); p_char--; /* Decrement the index */ } } if ((ASCII_IsPrint(rx_data) ) && (rxd_history_char0 == DEF_NO)) { /* Is it a printable character ... ? */ BSP_Ser_WrByteUnlocked((CPU_INT08U)rx_data); /* Echo-back */ *p_char = rx_data; /* Save the received character in the buffer */ p_char++; /* Increment the buffer index */ if (p_char >= &p_str[len]) { p_char = &p_str[len]; } } else if ((rx_data == ASCII_CHAR_ESCAPE) && (rxd_history_char0 == DEF_NO )) { rxd_history_char0 = DEF_YES; #if (BSP_CFG_SER_CMD_HISTORY_LEN > 0u) } else if ((rx_data == ASCII_CHAR_LEFT_SQUARE_BRACKET) && (rxd_history_char0 == DEF_YES )) { while (p_char != p_str) { BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_BACKSPACE); p_char--; /* Decrement the index */ } Str_Copy(p_str, BSP_SerCmdHistory); while (*p_char != '\0') { BSP_Ser_WrByteUnlocked(*p_char++); } #endif } else { rxd_history_char0 = DEF_NO; } } BSP_OS_SemPost(&BSP_SerLock); /* Release access to the serial interface */ }