4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-18 14:43:31 +08:00

[serial] 优化dma接收处理流程,解耦驱动调用串口框架的API接口

This commit is contained in:
chenjh 2021-06-07 22:46:02 +08:00
parent d94be14df5
commit fac3c5cda1
6 changed files with 269 additions and 402 deletions

View File

@ -342,37 +342,42 @@ static void dma_recv_isr(struct rt_serial_device *serial, rt_uint8_t isr_flag)
{ {
struct stm32_uart *uart; struct stm32_uart *uart;
rt_base_t level; rt_base_t level;
rt_uint16_t recv_len = 0; rt_size_t recv_len, counter;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct stm32_uart, serial); uart = rt_container_of(serial, struct stm32_uart, serial);
struct rt_serial_rx_fifo *rx_fifo;
rx_fifo = (struct rt_serial_rx_fifo *) serial->serial_rx;
RT_ASSERT(rx_fifo != RT_NULL);
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
rt_uint16_t index = __HAL_DMA_GET_COUNTER(&(uart->dma_rx.handle)); recv_len = 0;
counter = __HAL_DMA_GET_COUNTER(&(uart->dma_rx.handle));
switch (isr_flag) switch (isr_flag)
{ {
case UART_RX_DMA_IT_IDLE_FLAG:
case UART_RX_DMA_IT_TC_FLAG: if (counter <= uart->dma_rx.remaining_cnt)
if(index >= uart->dma_rx.remaining_cnt) recv_len = uart->dma_rx.remaining_cnt - counter;
recv_len = serial->config.rx_bufsz + uart->dma_rx.remaining_cnt - index; else
recv_len = serial->config.rx_bufsz + uart->dma_rx.remaining_cnt - counter;
break; break;
case UART_RX_DMA_IT_HT_FLAG: case UART_RX_DMA_IT_HT_FLAG:
case UART_RX_DMA_IT_IDLE_FLAG: if (counter < uart->dma_rx.remaining_cnt)
if(index < uart->dma_rx.remaining_cnt) recv_len = uart->dma_rx.remaining_cnt - counter;
recv_len = uart->dma_rx.remaining_cnt - index;
break; break;
case UART_RX_DMA_IT_TC_FLAG:
if(counter >= uart->dma_rx.remaining_cnt)
recv_len = serial->config.rx_bufsz + uart->dma_rx.remaining_cnt - counter;
default: default:
break; break;
} }
uart->dma_rx.remaining_cnt = index; if (recv_len)
rt_serial_update_write_index(&(rx_fifo->rb), recv_len); {
uart->dma_rx.remaining_cnt = counter;
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8));
}
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
} }
@ -444,7 +449,6 @@ static void uart_isr(struct rt_serial_device *serial)
&& (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_IDLE) != RESET)) && (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_IDLE) != RESET))
{ {
dma_recv_isr(serial, UART_RX_DMA_IT_IDLE_FLAG); dma_recv_isr(serial, UART_RX_DMA_IT_IDLE_FLAG);
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
__HAL_UART_CLEAR_IDLEFLAG(&uart->handle); __HAL_UART_CLEAR_IDLEFLAG(&uart->handle);
} }
#endif #endif
@ -1051,9 +1055,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
struct stm32_uart *uart; struct stm32_uart *uart;
RT_ASSERT(huart != NULL); RT_ASSERT(huart != NULL);
uart = (struct stm32_uart *)huart; uart = (struct stm32_uart *)huart;
dma_recv_isr(&uart->serial, UART_RX_DMA_IT_TC_FLAG); dma_recv_isr(&uart->serial, UART_RX_DMA_IT_TC_FLAG);
rt_hw_serial_isr(&uart->serial, RT_SERIAL_EVENT_RX_DMADONE);
} }
/** /**
@ -1068,15 +1070,13 @@ void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
struct stm32_uart *uart; struct stm32_uart *uart;
RT_ASSERT(huart != NULL); RT_ASSERT(huart != NULL);
uart = (struct stm32_uart *)huart; uart = (struct stm32_uart *)huart;
dma_recv_isr(&uart->serial, UART_RX_DMA_IT_HT_FLAG); dma_recv_isr(&uart->serial, UART_RX_DMA_IT_HT_FLAG);
rt_hw_serial_isr(&uart->serial, RT_SERIAL_EVENT_RX_DMADONE);
} }
/** /**
* @brief HAL_UART_TxCpltCallback * @brief HAL_UART_TxCpltCallback
* @param huart: UART handle * @param huart: UART handle
* @note This callback can be called by two functions, first in UART_EndTransmit_IT when * @note This callback can be called by two functions, first in UART_EndTransmit_IT when
* UART Tx complete and second in UART_DMATransmitCplt function in DMA Circular mode. * UART Tx complete and second in UART_DMATransmitCplt function in DMA Circular mode.
* @retval None * @retval None
*/ */

View File

@ -197,21 +197,7 @@ CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_RYM is not set # CONFIG_RT_USING_RYM is not set
# CONFIG_RT_USING_ULOG is not set # CONFIG_RT_USING_ULOG is not set
# CONFIG_RT_USING_UTEST is not set # CONFIG_RT_USING_UTEST is not set
CONFIG_RT_USING_RT_LINK=y # CONFIG_RT_USING_RT_LINK is not set
CONFIG_RT_LINK_USING_SF_CRC=y
# CONFIG_RT_LINK_USING_HW_CRC is not set
#
# rt-link hardware device configuration
#
CONFIG_RT_LINK_HW_DEVICE_NAME="uart2"
CONFIG_RT_LINK_USING_UART=y
#
# rt link debug option
#
# CONFIG_USING_RT_LINK_DEBUG is not set
# CONFIG_USING_RT_LINK_HW_DEBUG is not set
# CONFIG_RT_USING_LWP is not set # CONFIG_RT_USING_LWP is not set
# #

View File

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd"> <Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
<SchemaVersion>2.1</SchemaVersion> <SchemaVersion>2.1</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header> <Header>### uVision Project, (C) Keil Software</Header>
<Targets> <Targets>
<Target> <Target>
<TargetName>rt-thread</TargetName> <TargetName>rt-thread</TargetName>
@ -13,31 +16,31 @@
<TargetCommonOption> <TargetCommonOption>
<Device>STM32L475VETx</Device> <Device>STM32L475VETx</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32L4xx_DFP.2.0.0</PackID> <PackID>Keil.STM32L4xx_DFP.2.2.0</PackID>
<PackURL>http://www.keil.com/pack</PackURL> <PackURL>http://www.keil.com/pack</PackURL>
<Cpu>IRAM(0x20000000,0x00018000) IRAM2(0x10000000,0x00008000) IROM(0x08000000,0x00080000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu> <Cpu>IRAM(0x20000000,0x00018000) IRAM2(0x10000000,0x00008000) IROM(0x08000000,0x00080000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec /> <FlashUtilSpec></FlashUtilSpec>
<StartupFile /> <StartupFile></StartupFile>
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L4xx_512 -FS08000000 -FL080000 -FP0($$Device:STM32L475VETx$CMSIS\Flash\STM32L4xx_512.FLM))</FlashDriverDll> <FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32L4xx_512 -FS08000000 -FL080000 -FP0($$Device:STM32L475VETx$CMSIS\Flash\STM32L4xx_512.FLM))</FlashDriverDll>
<DeviceId>0</DeviceId> <DeviceId>0</DeviceId>
<RegisterFile>$$Device:STM32L475VETx$Drivers\CMSIS\Device\ST\STM32L4xx\Include\stm32l4xx.h</RegisterFile> <RegisterFile>$$Device:STM32L475VETx$Drivers\CMSIS\Device\ST\STM32L4xx\Include\stm32l4xx.h</RegisterFile>
<MemoryEnv /> <MemoryEnv></MemoryEnv>
<Cmp /> <Cmp></Cmp>
<Asm /> <Asm></Asm>
<Linker /> <Linker></Linker>
<OHString /> <OHString></OHString>
<InfinionOptionDll /> <InfinionOptionDll></InfinionOptionDll>
<SLE66CMisc /> <SLE66CMisc></SLE66CMisc>
<SLE66AMisc /> <SLE66AMisc></SLE66AMisc>
<SLE66LinkerMisc /> <SLE66LinkerMisc></SLE66LinkerMisc>
<SFDFile>$$Device:STM32L475VETx$CMSIS\SVD\STM32L4x5.svd</SFDFile> <SFDFile>$$Device:STM32L475VETx$CMSIS\SVD\STM32L4x5.svd</SFDFile>
<bCustSvd>0</bCustSvd> <bCustSvd>0</bCustSvd>
<UseEnv>0</UseEnv> <UseEnv>0</UseEnv>
<BinPath /> <BinPath></BinPath>
<IncludePath /> <IncludePath></IncludePath>
<LibPath /> <LibPath></LibPath>
<RegisterFilePath /> <RegisterFilePath></RegisterFilePath>
<DBRegisterFilePath /> <DBRegisterFilePath></DBRegisterFilePath>
<TargetStatus> <TargetStatus>
<Error>0</Error> <Error>0</Error>
<ExitCodeStop>0</ExitCodeStop> <ExitCodeStop>0</ExitCodeStop>
@ -59,8 +62,8 @@
<BeforeCompile> <BeforeCompile>
<RunUserProg1>0</RunUserProg1> <RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2> <RunUserProg2>0</RunUserProg2>
<UserProg1Name /> <UserProg1Name></UserProg1Name>
<UserProg2Name /> <UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopU1X>0</nStopU1X> <nStopU1X>0</nStopU1X>
@ -69,8 +72,8 @@
<BeforeMake> <BeforeMake>
<RunUserProg1>0</RunUserProg1> <RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2> <RunUserProg2>0</RunUserProg2>
<UserProg1Name /> <UserProg1Name></UserProg1Name>
<UserProg2Name /> <UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopB1X>0</nStopB1X> <nStopB1X>0</nStopB1X>
@ -80,14 +83,14 @@
<RunUserProg1>1</RunUserProg1> <RunUserProg1>1</RunUserProg1>
<RunUserProg2>0</RunUserProg2> <RunUserProg2>0</RunUserProg2>
<UserProg1Name>fromelf --bin !L --output rtthread.bin</UserProg1Name> <UserProg1Name>fromelf --bin !L --output rtthread.bin</UserProg1Name>
<UserProg2Name /> <UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode> <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode> <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopA1X>0</nStopA1X> <nStopA1X>0</nStopA1X>
<nStopA2X>0</nStopA2X> <nStopA2X>0</nStopA2X>
</AfterMake> </AfterMake>
<SelectedForBatchBuild>0</SelectedForBatchBuild> <SelectedForBatchBuild>0</SelectedForBatchBuild>
<SVCSIdString /> <SVCSIdString></SVCSIdString>
</TargetCommonOption> </TargetCommonOption>
<CommonProperty> <CommonProperty>
<UseCPPCompiler>0</UseCPPCompiler> <UseCPPCompiler>0</UseCPPCompiler>
@ -101,8 +104,8 @@
<AssembleAssemblyFile>0</AssembleAssemblyFile> <AssembleAssemblyFile>0</AssembleAssemblyFile>
<PublicsOnly>0</PublicsOnly> <PublicsOnly>0</PublicsOnly>
<StopOnExitCode>3</StopOnExitCode> <StopOnExitCode>3</StopOnExitCode>
<CustomArgument /> <CustomArgument></CustomArgument>
<IncludeLibraryModules /> <IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg> <ComprImg>1</ComprImg>
</CommonProperty> </CommonProperty>
<DllOption> <DllOption>
@ -136,10 +139,10 @@
<bUseTDR>1</bUseTDR> <bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2> <Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3>"" ()</Flash3> <Flash3>"" ()</Flash3>
<Flash4 /> <Flash4></Flash4>
<pFcarmOut /> <pFcarmOut></pFcarmOut>
<pFcarmGrp /> <pFcarmGrp></pFcarmGrp>
<pFcArmRoot /> <pFcArmRoot></pFcArmRoot>
<FcArmLst>0</FcArmLst> <FcArmLst>0</FcArmLst>
</Utilities> </Utilities>
<TargetArmAds> <TargetArmAds>
@ -172,7 +175,7 @@
<RvctClst>0</RvctClst> <RvctClst>0</RvctClst>
<GenPPlst>0</GenPPlst> <GenPPlst>0</GenPPlst>
<AdsCpuType>"Cortex-M4"</AdsCpuType> <AdsCpuType>"Cortex-M4"</AdsCpuType>
<RvctDeviceName /> <RvctDeviceName></RvctDeviceName>
<mOS>0</mOS> <mOS>0</mOS>
<uocRom>0</uocRom> <uocRom>0</uocRom>
<uocRam>0</uocRam> <uocRam>0</uocRam>
@ -181,6 +184,7 @@
<hadXRAM>0</hadXRAM> <hadXRAM>0</hadXRAM>
<uocXRam>0</uocXRam> <uocXRam>0</uocXRam>
<RvdsVP>2</RvdsVP> <RvdsVP>2</RvdsVP>
<RvdsMve>0</RvdsMve>
<hadIRAM2>1</hadIRAM2> <hadIRAM2>1</hadIRAM2>
<hadIROM2>0</hadIROM2> <hadIROM2>0</hadIROM2>
<StupSel>8</StupSel> <StupSel>8</StupSel>
@ -304,7 +308,7 @@
<Size>0x8000</Size> <Size>0x8000</Size>
</OCR_RVCT10> </OCR_RVCT10>
</OnChipMemories> </OnChipMemories>
<RvctStartVector /> <RvctStartVector></RvctStartVector>
</ArmAdsMisc> </ArmAdsMisc>
<Cads> <Cads>
<interw>1</interw> <interw>1</interw>
@ -331,10 +335,10 @@
<v6WtE>0</v6WtE> <v6WtE>0</v6WtE>
<v6Rtti>0</v6Rtti> <v6Rtti>0</v6Rtti>
<VariousControls> <VariousControls>
<MiscControls /> <MiscControls></MiscControls>
<Define>USE_HAL_DRIVER, __RTTHREAD__, STM32L475xx</Define> <Define>USE_HAL_DRIVER, __RTTHREAD__, STM32L475xx</Define>
<Undefine /> <Undefine></Undefine>
<IncludePath>.;applications;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\components\finsh;.;..\..\..\include;..\..\..\components\libc\compilers\common;..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Inc;..\libraries\STM32L4xx_HAL\CMSIS\Device\ST\STM32L4xx\Include;..\libraries\STM32L4xx_HAL\CMSIS\Include</IncludePath> <IncludePath>.;applications;..\..\..\libcpu\arm\common;..\..\..\libcpu\arm\cortex-m4;..\..\..\components\drivers\include;..\..\..\components\drivers\include;..\..\..\components\drivers\include;board;board\CubeMX_Config\Inc;board\ports;..\libraries\HAL_Drivers;..\libraries\HAL_Drivers\config;..\..\..\components\finsh;.;..\..\..\include;..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Inc;..\libraries\STM32L4xx_HAL\CMSIS\Device\ST\STM32L4xx\Include;..\libraries\STM32L4xx_HAL\CMSIS\Include</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
@ -349,10 +353,10 @@
<useXO>0</useXO> <useXO>0</useXO>
<uClangAs>0</uClangAs> <uClangAs>0</uClangAs>
<VariousControls> <VariousControls>
<MiscControls /> <MiscControls></MiscControls>
<Define /> <Define></Define>
<Undefine /> <Undefine></Undefine>
<IncludePath /> <IncludePath></IncludePath>
</VariousControls> </VariousControls>
</Aads> </Aads>
<LDads> <LDads>
@ -364,13 +368,13 @@
<useFile>0</useFile> <useFile>0</useFile>
<TextAddressRange>0x08000000</TextAddressRange> <TextAddressRange>0x08000000</TextAddressRange>
<DataAddressRange>0x20000000</DataAddressRange> <DataAddressRange>0x20000000</DataAddressRange>
<pXoBase /> <pXoBase></pXoBase>
<ScatterFile>.\board\linker_scripts\link.sct</ScatterFile> <ScatterFile>.\board\linker_scripts\link.sct</ScatterFile>
<IncludeLibs /> <IncludeLibs></IncludeLibs>
<IncludeLibsPath /> <IncludeLibsPath></IncludeLibsPath>
<Misc /> <Misc></Misc>
<LinkerInputFile /> <LinkerInputFile></LinkerInputFile>
<DisabledWarnings /> <DisabledWarnings></DisabledWarnings>
</LDads> </LDads>
</TargetArmAds> </TargetArmAds>
</TargetOption> </TargetOption>
@ -383,39 +387,36 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>applications\main.c</FilePath> <FilePath>applications\main.c</FilePath>
</File> </File>
<File>
<FileName>uart_sample.c</FileName>
<FileType>1</FileType>
<FilePath>.\applications\uart_sample.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
<GroupName>CPU</GroupName> <GroupName>CPU</GroupName>
<Files> <Files>
<File> <File>
<FileName>backtrace.c</FileName> <FileName>showmem.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\libcpu\arm\common\backtrace.c</FilePath> <FilePath>..\..\..\libcpu\arm\common\showmem.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>div0.c</FileName> <FileName>div0.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\libcpu\arm\common\div0.c</FilePath> <FilePath>..\..\..\libcpu\arm\common\div0.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>showmem.c</FileName> <FileName>backtrace.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\libcpu\arm\common\showmem.c</FilePath> <FilePath>..\..\..\libcpu\arm\common\backtrace.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>cpuport.c</FileName> <FileName>cpuport.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\libcpu\arm\cortex-m4\cpuport.c</FilePath> <FilePath>..\..\..\libcpu\arm\cortex-m4\cpuport.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>context_rvds.S</FileName> <FileName>context_rvds.S</FileName>
<FileType>2</FileType> <FileType>2</FileType>
@ -431,57 +432,41 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\components\drivers\misc\pin.c</FilePath> <FilePath>..\..\..\components\drivers\misc\pin.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>serial.c</FileName> <FileName>serial_v2.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\components\drivers\serial\serial.c</FilePath> <FilePath>..\..\..\components\drivers\serial\serial_v2.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>completion.c</FileName> <FileName>completion.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\completion.c</FilePath> <FilePath>..\..\..\components\drivers\src\completion.c</FilePath>
</File> </File>
</Files>
<Files>
<File>
<FileName>dataqueue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\dataqueue.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>pipe.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\pipe.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>ringblk_buf.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\ringblk_buf.c</FilePath>
</File>
</Files>
<Files>
<File> <File>
<FileName>ringbuffer.c</FileName> <FileName>ringbuffer.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\ringbuffer.c</FilePath> <FilePath>..\..\..\components\drivers\src\ringbuffer.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>waitqueue.c</FileName> <FileName>waitqueue.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\waitqueue.c</FilePath> <FilePath>..\..\..\components\drivers\src\waitqueue.c</FilePath>
</File> </File>
</Files> <File>
<Files> <FileName>ringblk_buf.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\ringblk_buf.c</FilePath>
</File>
<File>
<FileName>dataqueue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\dataqueue.c</FilePath>
</File>
<File>
<FileName>pipe.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\drivers\src\pipe.c</FilePath>
</File>
<File> <File>
<FileName>workqueue.c</FileName> <FileName>workqueue.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@ -491,42 +476,32 @@
</Group> </Group>
<Group> <Group>
<GroupName>Drivers</GroupName> <GroupName>Drivers</GroupName>
<Files>
<File>
<FileName>board.c</FileName>
<FileType>1</FileType>
<FilePath>board\board.c</FilePath>
</File>
</Files>
<Files> <Files>
<File> <File>
<FileName>stm32l4xx_hal_msp.c</FileName> <FileName>stm32l4xx_hal_msp.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>board\CubeMX_Config\Src\stm32l4xx_hal_msp.c</FilePath> <FilePath>board\CubeMX_Config\Src\stm32l4xx_hal_msp.c</FilePath>
</File> </File>
</Files> <File>
<Files> <FileName>board.c</FileName>
<FileType>1</FileType>
<FilePath>board\board.c</FilePath>
</File>
<File> <File>
<FileName>startup_stm32l475xx.s</FileName> <FileName>startup_stm32l475xx.s</FileName>
<FileType>2</FileType> <FileType>2</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\CMSIS\Device\ST\STM32L4xx\Source\Templates\arm\startup_stm32l475xx.s</FilePath> <FilePath>..\libraries\STM32L4xx_HAL\CMSIS\Device\ST\STM32L4xx\Source\Templates\arm\startup_stm32l475xx.s</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>drv_gpio.c</FileName> <FileName>drv_gpio.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\libraries\HAL_Drivers\drv_gpio.c</FilePath> <FilePath>..\libraries\HAL_Drivers\drv_gpio.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>drv_usart.c</FileName> <FileName>drv_usart_v2.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\libraries\HAL_Drivers\drv_usart.c</FilePath> <FilePath>..\libraries\HAL_Drivers\drv_usart_v2.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>drv_common.c</FileName> <FileName>drv_common.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@ -542,116 +517,81 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\components\finsh\shell.c</FilePath> <FilePath>..\..\..\components\finsh\shell.c</FilePath>
</File> </File>
</Files>
<Files>
<File>
<FileName>cmd.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\finsh\cmd.c</FilePath>
</File>
</Files>
<Files>
<File> <File>
<FileName>msh.c</FileName> <FileName>msh.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\components\finsh\msh.c</FilePath> <FilePath>..\..\..\components\finsh\msh.c</FilePath>
</File> </File>
<File>
<FileName>cmd.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\finsh\cmd.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
<GroupName>Kernel</GroupName> <GroupName>Kernel</GroupName>
<Files>
<File>
<FileName>clock.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\clock.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>components.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\components.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>device.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\device.c</FilePath>
</File>
</Files>
<Files> <Files>
<File> <File>
<FileName>idle.c</FileName> <FileName>idle.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\src\idle.c</FilePath> <FilePath>..\..\..\src\idle.c</FilePath>
</File> </File>
</Files>
<Files>
<File>
<FileName>ipc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\ipc.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>irq.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\irq.c</FilePath>
</File>
</Files>
<Files>
<File> <File>
<FileName>kservice.c</FileName> <FileName>kservice.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\src\kservice.c</FilePath> <FilePath>..\..\..\src\kservice.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>mem.c</FileName> <FileName>device.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\src\mem.c</FilePath> <FilePath>..\..\..\src\device.c</FilePath>
</File>
<File>
<FileName>clock.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\clock.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>mempool.c</FileName> <FileName>mempool.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\src\mempool.c</FilePath> <FilePath>..\..\..\src\mempool.c</FilePath>
</File> </File>
</Files>
<Files>
<File>
<FileName>object.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\object.c</FilePath>
</File>
</Files>
<Files>
<File> <File>
<FileName>scheduler.c</FileName> <FileName>scheduler.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\src\scheduler.c</FilePath> <FilePath>..\..\..\src\scheduler.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>signal.c</FileName> <FileName>mem.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\src\signal.c</FilePath> <FilePath>..\..\..\src\mem.c</FilePath>
</File>
<File>
<FileName>components.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\components.c</FilePath>
</File>
<File>
<FileName>ipc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\ipc.c</FilePath>
</File>
<File>
<FileName>irq.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\irq.c</FilePath>
</File>
<File>
<FileName>object.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\src\object.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>thread.c</FileName> <FileName>thread.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\src\thread.c</FilePath> <FilePath>..\..\..\src\thread.c</FilePath>
</File> </File>
</Files>
<Files>
<File> <File>
<FileName>timer.c</FileName> <FileName>timer.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@ -659,172 +599,124 @@
</File> </File>
</Files> </Files>
</Group> </Group>
<Group>
<GroupName>libc</GroupName>
<Files>
<File>
<FileName>time.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\components\libc\compilers\common\time.c</FilePath>
</File>
</Files>
</Group>
<Group> <Group>
<GroupName>Libraries</GroupName> <GroupName>Libraries</GroupName>
<Files>
<File>
<FileName>system_stm32l4xx.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\CMSIS\Device\ST\STM32L4xx\Source\Templates\system_stm32l4xx.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_comp.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_comp.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_cortex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cortex.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_crc.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_crc.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_crc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_crc_ex.c</FilePath>
</File>
</Files>
<Files> <Files>
<File> <File>
<FileName>stm32l4xx_hal_cryp.c</FileName> <FileName>stm32l4xx_hal_cryp.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cryp.c</FilePath> <FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cryp.c</FilePath>
</File> </File>
</Files> <File>
<Files> <FileName>stm32l4xx_hal_uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_usart.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_usart.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_cortex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cortex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_gpio.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_dma.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dma.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_pwr.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_pwr.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_rcc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rcc_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_rcc.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rcc.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_dma_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dma_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_exti.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_exti.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_crc.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_crc.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_usart_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_usart_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_uart_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_crc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_crc_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_comp.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_comp.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_pwr_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_pwr_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_rng.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rng.c</FilePath>
</File>
<File>
<FileName>system_stm32l4xx.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\CMSIS\Device\ST\STM32L4xx\Source\Templates\system_stm32l4xx.c</FilePath>
</File>
<File> <File>
<FileName>stm32l4xx_hal_cryp_ex.c</FileName> <FileName>stm32l4xx_hal_cryp_ex.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cryp_ex.c</FilePath> <FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cryp_ex.c</FilePath>
</File> </File>
</Files> </Files>
<Files>
<File>
<FileName>stm32l4xx_hal_dma.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dma.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_dma_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dma_ex.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_exti.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_exti.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_pwr.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_pwr.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_pwr_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_pwr_ex.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_rcc.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rcc.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_rcc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rcc_ex.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_rng.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rng.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_gpio.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_uart_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart_ex.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_usart.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_usart.c</FilePath>
</File>
</Files>
<Files>
<File>
<FileName>stm32l4xx_hal_usart_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\libraries\STM32L4xx_HAL\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_usart_ex.c</FilePath>
</File>
</Files>
</Group> </Group>
</Groups> </Groups>
</Target> </Target>
</Targets> </Targets>
<RTE> <RTE>
<apis /> <apis/>
<components /> <components/>
<files /> <files/>
</RTE> </RTE>
</Project> </Project>

View File

@ -111,16 +111,6 @@
/* Utilities */ /* Utilities */
#define RT_USING_RT_LINK
#define RT_LINK_USING_SF_CRC
/* rt-link hardware device configuration */
#define RT_LINK_HW_DEVICE_NAME "uart2"
#define RT_LINK_USING_UART
/* rt link debug option */
/* RT-Thread Utestcases */ /* RT-Thread Utestcases */

View File

@ -112,7 +112,7 @@ struct serial_configure
}; };
/* /*
* Serial FIFO mode * Serial Receive FIFO mode
*/ */
struct rt_serial_rx_fifo struct rt_serial_rx_fifo
{ {
@ -128,6 +128,9 @@ struct rt_serial_rx_fifo
rt_uint8_t buffer[]; rt_uint8_t buffer[];
}; };
/*
* Serial Transmit FIFO mode
*/
struct rt_serial_tx_fifo struct rt_serial_tx_fifo
{ {
struct rt_ringbuffer rb; struct rt_ringbuffer rb;
@ -174,15 +177,6 @@ struct rt_uart_ops
rt_uint32_t tx_flag); rt_uint32_t tx_flag);
}; };
rt_size_t rt_serial_get_linear_buffer(struct rt_ringbuffer *rb,
rt_uint8_t **ptr);
rt_size_t rt_serial_update_read_index(struct rt_ringbuffer *rb,
rt_uint16_t read_index);
rt_size_t rt_serial_update_write_index(struct rt_ringbuffer *rb,
rt_uint16_t write_index);
void rt_hw_serial_isr(struct rt_serial_device *serial, int event); void rt_hw_serial_isr(struct rt_serial_device *serial, int event);
rt_err_t rt_hw_serial_register(struct rt_serial_device *serial, rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,

View File

@ -157,7 +157,7 @@ static int serial_fops_poll(struct dfs_fd *fd, struct rt_pollreq *req)
rx_fifo = (struct rt_serial_rx_fifo*) serial->serial_rx; rx_fifo = (struct rt_serial_rx_fifo*) serial->serial_rx;
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
if (rt_ringbuffer_data_len(&rx_fifo->rb)) if (rt_ringbuffer_data_len(&rx_fifo->rb))
mask |= POLLIN; mask |= POLLIN;
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
@ -180,8 +180,8 @@ const static struct dfs_file_ops _serial_fops =
}; };
#endif #endif
rt_size_t rt_serial_get_linear_buffer(struct rt_ringbuffer *rb, static rt_size_t rt_serial_get_linear_buffer(struct rt_ringbuffer *rb,
rt_uint8_t **ptr) rt_uint8_t **ptr)
{ {
rt_size_t size; rt_size_t size;
@ -206,8 +206,8 @@ rt_size_t rt_serial_get_linear_buffer(struct rt_ringbuffer *rb,
return rb->buffer_size - rb->read_index; return rb->buffer_size - rb->read_index;
} }
rt_size_t rt_serial_update_read_index(struct rt_ringbuffer *rb, static rt_size_t rt_serial_update_read_index(struct rt_ringbuffer *rb,
rt_uint16_t read_index) rt_uint16_t read_index)
{ {
rt_size_t size; rt_size_t size;
@ -219,7 +219,7 @@ rt_size_t rt_serial_update_read_index(struct rt_ringbuffer *rb,
/* no data */ /* no data */
if (size == 0) if (size == 0)
return 0; return 0;
/* less data */ /* less data */
if(size < read_index) if(size < read_index)
read_index = size; read_index = size;
@ -239,8 +239,8 @@ rt_size_t rt_serial_update_read_index(struct rt_ringbuffer *rb,
return read_index; return read_index;
} }
rt_size_t rt_serial_update_write_index(struct rt_ringbuffer *rb, static rt_size_t rt_serial_update_write_index(struct rt_ringbuffer *rb,
rt_uint16_t write_index) rt_uint16_t write_index)
{ {
rt_uint16_t size; rt_uint16_t size;
RT_ASSERT(rb != RT_NULL); RT_ASSERT(rb != RT_NULL);
@ -499,7 +499,7 @@ static rt_size_t _serial_fifo_tx_blocking_buf(struct rt_device *dev,
while (size) while (size)
{ {
/* Copy one piece of data into the ringbuffer at a time /* Copy one piece of data into the ringbuffer at a time
* until the length of the data is equal to size */ * until the length of the data is equal to size */
tx_fifo->put_size = rt_ringbuffer_put(&(tx_fifo->rb), tx_fifo->put_size = rt_ringbuffer_put(&(tx_fifo->rb),
(rt_uint8_t *)buffer + offset, (rt_uint8_t *)buffer + offset,
@ -629,7 +629,7 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
if (optmode == RT_SERIAL_TX_BLOCKING_BUFFER) if (optmode == RT_SERIAL_TX_BLOCKING_BUFFER)
{ {
/* If use RT_SERIAL_TX_BLOCKING_BUFFER, the ringbuffer is initialized */ /* If use RT_SERIAL_TX_BLOCKING_BUFFER, the ringbuffer is initialized */
tx_fifo = (struct rt_serial_tx_fifo *) rt_malloc tx_fifo = (struct rt_serial_tx_fifo *) rt_malloc
(sizeof(struct rt_serial_tx_fifo) + serial->config.tx_bufsz); (sizeof(struct rt_serial_tx_fifo) + serial->config.tx_bufsz);
RT_ASSERT(tx_fifo != RT_NULL); RT_ASSERT(tx_fifo != RT_NULL);
@ -641,9 +641,9 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
} }
else else
{ {
/* If not use RT_SERIAL_TX_BLOCKING_BUFFER, /* If not use RT_SERIAL_TX_BLOCKING_BUFFER,
* the control() API is called to configure the serial device */ * the control() API is called to configure the serial device */
tx_fifo = (struct rt_serial_tx_fifo*) rt_malloc tx_fifo = (struct rt_serial_tx_fifo*) rt_malloc
(sizeof(struct rt_serial_tx_fifo)); (sizeof(struct rt_serial_tx_fifo));
RT_ASSERT(tx_fifo != RT_NULL); RT_ASSERT(tx_fifo != RT_NULL);
@ -665,14 +665,14 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
/* When using RT_SERIAL_TX_NON_BLOCKING, ringbuffer needs to be initialized, /* When using RT_SERIAL_TX_NON_BLOCKING, ringbuffer needs to be initialized,
* and initialize the tx_fifo->activated value is RT_FALSE. * and initialize the tx_fifo->activated value is RT_FALSE.
*/ */
tx_fifo = (struct rt_serial_tx_fifo *) rt_malloc tx_fifo = (struct rt_serial_tx_fifo *) rt_malloc
(sizeof(struct rt_serial_tx_fifo) + serial->config.tx_bufsz); (sizeof(struct rt_serial_tx_fifo) + serial->config.tx_bufsz);
RT_ASSERT(tx_fifo != RT_NULL); RT_ASSERT(tx_fifo != RT_NULL);
tx_fifo->activated = RT_FALSE; tx_fifo->activated = RT_FALSE;
tx_fifo->put_size = 0; tx_fifo->put_size = 0;
rt_ringbuffer_init(&(tx_fifo->rb), rt_ringbuffer_init(&(tx_fifo->rb),
tx_fifo->buffer, tx_fifo->buffer,
serial->config.tx_bufsz); serial->config.tx_bufsz);
serial->serial_tx = tx_fifo; serial->serial_tx = tx_fifo;
@ -712,7 +712,7 @@ static rt_err_t rt_serial_rx_enable(struct rt_device *dev,
return -RT_EINVAL; return -RT_EINVAL;
} }
dev->read = _serial_poll_rx; dev->read = _serial_poll_rx;
dev->open_flag |= RT_SERIAL_RX_BLOCKING; dev->open_flag |= RT_SERIAL_RX_BLOCKING;
return RT_EOK; return RT_EOK;
} }
@ -892,7 +892,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
dev->open_flag |= RT_SERIAL_TX_BLOCKING; dev->open_flag |= RT_SERIAL_TX_BLOCKING;
/* set steam flag */ /* set steam flag */
if ((oflag & RT_DEVICE_FLAG_STREAM) || if ((oflag & RT_DEVICE_FLAG_STREAM) ||
(dev->open_flag & RT_DEVICE_FLAG_STREAM)) (dev->open_flag & RT_DEVICE_FLAG_STREAM))
dev->open_flag |= RT_DEVICE_FLAG_STREAM; dev->open_flag |= RT_DEVICE_FLAG_STREAM;
@ -903,7 +903,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
/* initialize the Tx structure according to open flag */ /* initialize the Tx structure according to open flag */
if (serial->serial_tx == RT_NULL) if (serial->serial_tx == RT_NULL)
rt_serial_tx_enable(dev, dev->open_flag & rt_serial_tx_enable(dev, dev->open_flag &
(RT_SERIAL_TX_BLOCKING | RT_SERIAL_TX_NON_BLOCKING)); (RT_SERIAL_TX_BLOCKING | RT_SERIAL_TX_NON_BLOCKING));
return RT_EOK; return RT_EOK;
@ -925,10 +925,10 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
/* this device has more reference count */ /* this device has more reference count */
if (dev->ref_count > 1) return -RT_ERROR; if (dev->ref_count > 1) return -RT_ERROR;
/* Disable serial receive mode. */ /* Disable serial receive mode. */
rt_serial_rx_disable(dev, dev->open_flag & rt_serial_rx_disable(dev, dev->open_flag &
(RT_SERIAL_RX_BLOCKING | RT_SERIAL_RX_NON_BLOCKING)); (RT_SERIAL_RX_BLOCKING | RT_SERIAL_RX_NON_BLOCKING));
/* Disable serial tranmit mode. */ /* Disable serial tranmit mode. */
rt_serial_tx_disable(dev, dev->open_flag & rt_serial_tx_disable(dev, dev->open_flag &
(RT_SERIAL_TX_BLOCKING | RT_SERIAL_TX_NON_BLOCKING)); (RT_SERIAL_TX_BLOCKING | RT_SERIAL_TX_NON_BLOCKING));
/* Call the control() API to close the serial device */ /* Call the control() API to close the serial device */
@ -978,7 +978,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
} }
/* set serial configure */ /* set serial configure */
serial->config = *pconfig; serial->config = *pconfig;
serial->ops->configure(serial, serial->ops->configure(serial,
(struct serial_configure *) args); (struct serial_configure *) args);
} }
@ -994,7 +994,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
} }
#ifdef RT_USING_DEVICE_OPS #ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops serial_ops = const static struct rt_device_ops serial_ops =
{ {
rt_serial_init, rt_serial_init,
rt_serial_open, rt_serial_open,
@ -1070,9 +1070,14 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
RT_ASSERT(rx_fifo != RT_NULL); RT_ASSERT(rx_fifo != RT_NULL);
/* If the event is RT_SERIAL_EVENT_RX_IND, rx_length is equal to 0 */
rx_length = (event & (~0xff)) >> 8;
if (rx_length)
rt_serial_update_write_index(&(rx_fifo->rb), rx_length);
/* Get the length of the data from the ringbuffer */ /* Get the length of the data from the ringbuffer */
rx_length = rt_ringbuffer_data_len(&rx_fifo->rb); rx_length = rt_ringbuffer_data_len(&rx_fifo->rb);
if (rx_length == 0) break; if (rx_length == 0) break;
if (serial->parent.open_flag & RT_SERIAL_RX_BLOCKING) if (serial->parent.open_flag & RT_SERIAL_RX_BLOCKING)