support posix

1. posix pthread.h: pthread, pthread_barrier, pthread_cond, pthread_mutex, , pthread_rwlock, pthread_spin, etc
2. posix semaphore.h: sem_*
3. posix mqueue.h: mq_*
4. posix time.h: timer_*
5. to support posix, add tos_barrier, tos_bitmap, tos_rwlock, tos_stopwatch, change name of k_task_t from a char * pointer to a char array.
6. sample, see examples\posix
7. project, see board\TencentOS_tiny_EVB_MX_Plus\KEIL\posix
This commit is contained in:
daishengdong
2020-02-28 00:11:28 +08:00
parent 7bfc998494
commit 40f55ec57b
84 changed files with 11704 additions and 158 deletions

View File

@@ -0,0 +1,97 @@
// File: STM32L43x_44x_45x_46x.dbgconf
// Version: 1.0.0
// Note: refer to STM32L43xxx STM32L44xxx STM32L45xxx STM32L46xxx Reference manual (RM0394)
// refer to STM32L431xx, STM32L432xx, STM32L433xx, STM32L442xx, STM32L443xx, STM32L451xx, STM32L452xx, STM32L462xx datasheets
// <<< Use Configuration Wizard in Context Menu >>>
// <h> Debug MCU configuration register (DBGMCU_CR)
// <o0.2> DBG_STANDBY
// <i> Debug Standby mode
// <i> 0: (FCLK=Off, HCLK=Off) The whole digital part is unpowered.
// <i> 1: (FCLK=On, HCLK=On) The digital part is not unpowered and FCLK and HCLK are provided by the internal RC oscillator which remains active
// <o0.1> DBG_STOP
// <i> Debug Stop mode
// <i> 0: (FCLK=Off, HCLK=Off) In STOP mode, the clock controller disables all clocks (including HCLK and FCLK).
// <i> 1: (FCLK=On, HCLK=On) When entering STOP mode, FCLK and HCLK are provided by the internal RC oscillator which remains active in STOP mode.
// <o0.0> DBG_SLEEP
// <i> Debug Sleep mode
// <i> 0: (FCLK=On, HCLK=Off) In Sleep mode, FCLK is clocked by the system clock as previously configured by the software while HCLK is disabled.
// <i> 1: (FCLK=On, HCLK=On) When entering Sleep mode, HCLK is fed by the same clock that is provided to FCLK (system clock as previously configured by the software).
// </h>
DbgMCU_CR = 0x00000007;
// <h> Debug MCU APB1 freeze register1 (DBGMCU_APB1FZR1)
// <o0.31> DBG_LPTIM1_STOP
// <i> LPTIM1 counter stopped when core is halted
// <i> 0: The counter clock of LPTIM1 is fed even if the core is halted
// <i> 1: The counter clock of LPTIM1 is stopped when the core is halted
// <o0.25> DBG_CAN_STOP
// <i> bxCAN1 stopped when core is halted
// <i> 0: Same behavior as in normal mode
// <i> 1: The bxCAN1 receive registers are frozen
// <o0.23> DBG_I2C3_STOP
// <i> I2C3 SMBUS timeout counter stopped when core is halted
// <i> 0: Same behavior as in normal mode
// <i> 1: The I2C3 SMBus timeout is frozen
// <o0.22> DBG_I2C2_STOP
// <i> I2C2 SMBUS timeout counter stopped when core is halted
// <i> 0: Same behavior as in normal mode
// <i> 1: The I2C2 SMBus timeout is frozen
// <o0.21> DBG_I2C1_STOP
// <i> I2C1 SMBUS timeout counter stopped when core is halted
// <i> 0: Same behavior as in normal mode
// <i> 1: The I2C1 SMBus timeout is frozen
// <o0.12> DBG_IWDG_STOP
// <i> Independent watchdog counter stopped when core is halted
// <i> 0: The independent watchdog counter clock continues even if the core is halted
// <i> 1: The independent watchdog counter clock is stopped when the core is halted
// <o0.11> DBG_WWDG_STOP
// <i> Window watchdog counter stopped when core is halted
// <i> 0: The window watchdog counter clock continues even if the core is halted
// <i> 1: The window watchdog counter clock is stopped when the core is halted
// <o0.10> DBG_RTC_STOP
// <i> RTC counter stopped when core is halted
// <i> 0: The clock of the RTC counter is fed even if the core is halted
// <i> 1: The clock of the RTC counter is stopped when the core is halted
// <o0.5> DBG_TIM7_STOP
// <i> TIM7 counter stopped when core is halted
// <i> 0: The counter clock of TIM7 is fed even if the core is halted
// <i> 1: The counter clock of TIM7 is stopped when the core is halted
// <o0.4> DBG_TIM6_STOP
// <i> TIM6 counter stopped when core is halted
// <i> 0: The counter clock of TIM6 is fed even if the core is halted
// <i> 1: The counter clock of TIM6 is stopped when the core is halted
// <o0.0> DBG_TIM2_STOP
// <i> TIM2 counter stopped when core is halted
// <i> 0: The counter clock of TIM2 is fed even if the core is halted
// <i> 1: The counter clock of TIM2 is stopped when the core is halted
// </h>
DbgMCU_APB1_Fz1 = 0x00000000;
// <h> Debug MCU APB1 freeze register 2 (DBGMCU_APB1FZR2)
// <o0.5> DBG_LPTIM2_STOP
// <i> LPTIM2 counter stopped when core is halted
// <i> 0: The counter clock of LPTIM2 is fed even if the core is halted
// <i> 1: The counter clock of LPTIM2 is stopped when the core is halted
// </h>
DbgMCU_APB1_Fz2 = 0x00000000;
// <h> Debug MCU APB2 freeze register (DBGMCU_APB2FZR)
// <o0.17> DBG_TIM16_STOP
// <i> TIM16 counter stopped when core is halted
// <i> 0: The clock of the TIM16 counter is fed even if the core is halted
// <i> 1: The clock of the TIM16 counter is stopped when the core is halted
// <o0.16> DBG_TIM15_STOP
// <i> TIM15 counter stopped when core is halted
// <i> 0: The clock of the TIM15 counter is fed even if the core is halted
// <i> 1: The clock of the TIM15 counter is stopped when the core is halted
// <o0.11> DBG_TIM1_STOP
// <i> TIM1 counter stopped when core is halted
// <i> 0: The clock of the TIM1 counter is fed even if the core is halted
// <i> 1: The clock of the TIM1 counter is stopped when the core is halted
// </h>
DbgMCU_APB2_Fz = 0x00000000;
// </h>
// <<< end of configuration section >>>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
<component name="EventRecorderStub" version="1.0.0"/> <!--name and version of the component-->
<events>
</events>
</component_viewer>

View File

@@ -0,0 +1,20 @@
/*
* Auto generated Run-Time-Environment Component Configuration File
* *** Do not modify ! ***
*
* Project: 'TencentOS_tiny'
* Target: 'TencentOS_tiny'
*/
#ifndef RTE_COMPONENTS_H
#define RTE_COMPONENTS_H
/*
* Define the Device Header File:
*/
#define CMSIS_device_header "stm32l4xx.h"
#endif /* RTE_COMPONENTS_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,867 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
<SchemaVersion>2.1</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header>
<Targets>
<Target>
<TargetName>TencentOS_tiny</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
<Device>STM32L431RCTx</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32L4xx_DFP.2.2.0</PackID>
<PackURL>http://www.keil.com/pack</PackURL>
<Cpu>IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")</Cpu>
<FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile>
<FlashDriverDll></FlashDriverDll>
<DeviceId></DeviceId>
<RegisterFile></RegisterFile>
<MemoryEnv></MemoryEnv>
<Cmp></Cmp>
<Asm></Asm>
<Linker></Linker>
<OHString></OHString>
<InfinionOptionDll></InfinionOptionDll>
<SLE66CMisc></SLE66CMisc>
<SLE66AMisc></SLE66AMisc>
<SLE66LinkerMisc></SLE66LinkerMisc>
<SFDFile>$$Device:STM32L431RCTx$CMSIS\SVD\STM32L4x1.svd</SFDFile>
<bCustSvd>0</bCustSvd>
<UseEnv>0</UseEnv>
<BinPath></BinPath>
<IncludePath></IncludePath>
<LibPath></LibPath>
<RegisterFilePath></RegisterFilePath>
<DBRegisterFilePath></DBRegisterFilePath>
<TargetStatus>
<Error>0</Error>
<ExitCodeStop>0</ExitCodeStop>
<ButtonStop>0</ButtonStop>
<NotGenerated>0</NotGenerated>
<InvalidFlash>1</InvalidFlash>
</TargetStatus>
<OutputDirectory>.\obj\</OutputDirectory>
<OutputName>TencentOS_tiny</OutputName>
<CreateExecutable>1</CreateExecutable>
<CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile>
<DebugInformation>1</DebugInformation>
<BrowseInformation>0</BrowseInformation>
<ListingPath>.\list\</ListingPath>
<HexFormatSelection>1</HexFormatSelection>
<Merge32K>0</Merge32K>
<CreateBatchFile>0</CreateBatchFile>
<BeforeCompile>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopU1X>0</nStopU1X>
<nStopU2X>0</nStopU2X>
</BeforeCompile>
<BeforeMake>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopB1X>0</nStopB1X>
<nStopB2X>0</nStopB2X>
</BeforeMake>
<AfterMake>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopA1X>0</nStopA1X>
<nStopA2X>0</nStopA2X>
</AfterMake>
<SelectedForBatchBuild>0</SelectedForBatchBuild>
<SVCSIdString></SVCSIdString>
</TargetCommonOption>
<CommonProperty>
<UseCPPCompiler>0</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>0</AlwaysBuild>
<GenerateAssemblyFile>0</GenerateAssemblyFile>
<AssembleAssemblyFile>0</AssembleAssemblyFile>
<PublicsOnly>0</PublicsOnly>
<StopOnExitCode>3</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>0</ComprImg>
</CommonProperty>
<DllOption>
<SimDllName>SARMCM3.DLL</SimDllName>
<SimDllArguments>-REMAP -MPU</SimDllArguments>
<SimDlgDll>DCM.DLL</SimDlgDll>
<SimDlgDllArguments>-pCM4</SimDlgDllArguments>
<TargetDllName>SARMCM3.DLL</TargetDllName>
<TargetDllArguments>-MPU</TargetDllArguments>
<TargetDlgDll>TCM.DLL</TargetDlgDll>
<TargetDlgDllArguments>-pCM4</TargetDlgDllArguments>
</DllOption>
<DebugOption>
<OPTHX>
<HexSelection>1</HexSelection>
<HexRangeLowAddress>0</HexRangeLowAddress>
<HexRangeHighAddress>0</HexRangeHighAddress>
<HexOffset>0</HexOffset>
<Oh166RecLen>16</Oh166RecLen>
</OPTHX>
</DebugOption>
<Utilities>
<Flash1>
<UseTargetDll>1</UseTargetDll>
<UseExternalTool>0</UseExternalTool>
<RunIndependent>0</RunIndependent>
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
<Capability>1</Capability>
<DriverSelection>4107</DriverSelection>
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>STLink\ST-LINKIII-KEIL_SWO.dll</Flash2>
<Flash3></Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp>
<pFcArmRoot></pFcArmRoot>
<FcArmLst>0</FcArmLst>
</Utilities>
<TargetArmAds>
<ArmAdsMisc>
<GenerateListings>0</GenerateListings>
<asHll>1</asHll>
<asAsm>1</asAsm>
<asMacX>1</asMacX>
<asSyms>1</asSyms>
<asFals>1</asFals>
<asDbgD>1</asDbgD>
<asForm>1</asForm>
<ldLst>0</ldLst>
<ldmm>1</ldmm>
<ldXref>1</ldXref>
<BigEnd>0</BigEnd>
<AdsALst>1</AdsALst>
<AdsACrf>1</AdsACrf>
<AdsANop>0</AdsANop>
<AdsANot>0</AdsANot>
<AdsLLst>1</AdsLLst>
<AdsLmap>1</AdsLmap>
<AdsLcgr>1</AdsLcgr>
<AdsLsym>1</AdsLsym>
<AdsLszi>1</AdsLszi>
<AdsLtoi>1</AdsLtoi>
<AdsLsun>1</AdsLsun>
<AdsLven>1</AdsLven>
<AdsLsxf>1</AdsLsxf>
<RvctClst>0</RvctClst>
<GenPPlst>0</GenPPlst>
<AdsCpuType>"Cortex-M4"</AdsCpuType>
<RvctDeviceName></RvctDeviceName>
<mOS>0</mOS>
<uocRom>0</uocRom>
<uocRam>0</uocRam>
<hadIROM>1</hadIROM>
<hadIRAM>1</hadIRAM>
<hadXRAM>0</hadXRAM>
<uocXRam>0</uocXRam>
<RvdsVP>2</RvdsVP>
<RvdsMve>0</RvdsMve>
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
<useUlib>1</useUlib>
<EndSel>0</EndSel>
<uLtcg>0</uLtcg>
<nSecure>0</nSecure>
<RoSelD>3</RoSelD>
<RwSelD>3</RwSelD>
<CodeSel>0</CodeSel>
<OptFeed>0</OptFeed>
<NoZi1>0</NoZi1>
<NoZi2>0</NoZi2>
<NoZi3>0</NoZi3>
<NoZi4>0</NoZi4>
<NoZi5>0</NoZi5>
<Ro1Chk>0</Ro1Chk>
<Ro2Chk>0</Ro2Chk>
<Ro3Chk>0</Ro3Chk>
<Ir1Chk>1</Ir1Chk>
<Ir2Chk>0</Ir2Chk>
<Ra1Chk>0</Ra1Chk>
<Ra2Chk>0</Ra2Chk>
<Ra3Chk>0</Ra3Chk>
<Im1Chk>1</Im1Chk>
<Im2Chk>0</Im2Chk>
<OnChipMemories>
<Ocm1>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm1>
<Ocm2>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm2>
<Ocm3>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm3>
<Ocm4>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm4>
<Ocm5>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm5>
<Ocm6>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm6>
<IRAM>
<Type>0</Type>
<StartAddress>0x20000000</StartAddress>
<Size>0x10000</Size>
</IRAM>
<IROM>
<Type>1</Type>
<StartAddress>0x8000000</StartAddress>
<Size>0x40000</Size>
</IROM>
<XRAM>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</XRAM>
<OCR_RVCT1>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT1>
<OCR_RVCT2>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT2>
<OCR_RVCT3>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT3>
<OCR_RVCT4>
<Type>1</Type>
<StartAddress>0x8000000</StartAddress>
<Size>0x40000</Size>
</OCR_RVCT4>
<OCR_RVCT5>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT5>
<OCR_RVCT6>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT6>
<OCR_RVCT7>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT7>
<OCR_RVCT8>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT8>
<OCR_RVCT9>
<Type>0</Type>
<StartAddress>0x20000000</StartAddress>
<Size>0x10000</Size>
</OCR_RVCT9>
<OCR_RVCT10>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT10>
</OnChipMemories>
<RvctStartVector></RvctStartVector>
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>1</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>1</OneElfS>
<Strict>0</Strict>
<EnumInt>0</EnumInt>
<PlainCh>0</PlainCh>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<wLevel>2</wLevel>
<uThumb>0</uThumb>
<uSurpInc>0</uSurpInc>
<uC99>1</uC99>
<uGnu>0</uGnu>
<useXO>0</useXO>
<v6Lang>1</v6Lang>
<v6LangP>1</v6LangP>
<vShortEn>1</vShortEn>
<vShortWch>1</vShortWch>
<v6Lto>0</v6Lto>
<v6WtE>0</v6WtE>
<v6Rtti>0</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define>USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER,USE_ESP8266</Define>
<Undefine></Undefine>
<IncludePath>..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\OLED;..\..\BSP\Hardware\BH1750;..\..\..\..\examples\helloworld;..\..\..\..\osal\posix\include</IncludePath>
</VariousControls>
</Cads>
<Aads>
<interw>1</interw>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<thumb>0</thumb>
<SplitLS>0</SplitLS>
<SwStkChk>0</SwStkChk>
<NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc>
<useXO>0</useXO>
<uClangAs>0</uClangAs>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Aads>
<LDads>
<umfTarg>1</umfTarg>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<noStLib>0</noStLib>
<RepFail>1</RepFail>
<useFile>0</useFile>
<TextAddressRange>0x08000000</TextAddressRange>
<DataAddressRange>0x20000000</DataAddressRange>
<pXoBase></pXoBase>
<ScatterFile></ScatterFile>
<IncludeLibs></IncludeLibs>
<IncludeLibsPath></IncludeLibsPath>
<Misc></Misc>
<LinkerInputFile></LinkerInputFile>
<DisabledWarnings></DisabledWarnings>
</LDads>
</TargetArmAds>
</TargetOption>
<Groups>
<Group>
<GroupName>Application/MDK-ARM</GroupName>
<Files>
<File>
<FileName>startup_stm32l431xx.s</FileName>
<FileType>2</FileType>
<FilePath>startup_stm32l431xx.s</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Application/User</GroupName>
<Files>
<File>
<FileName>gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\gpio.c</FilePath>
</File>
<File>
<FileName>main.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\main.c</FilePath>
</File>
<File>
<FileName>mcu_init.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\mcu_init.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_msp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\stm32l4xx_hal_msp.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_it.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\stm32l4xx_it.c</FilePath>
</File>
<File>
<FileName>usart.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\usart.c</FilePath>
</File>
<File>
<FileName>adc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\adc.c</FilePath>
</File>
<File>
<FileName>dac.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\dac.c</FilePath>
</File>
<File>
<FileName>i2c.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\i2c.c</FilePath>
</File>
<File>
<FileName>spi.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\spi.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>examples</GroupName>
<Files>
<File>
<FileName>posix_sample.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\examples\posix\posix_sample.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Drivers/STM32L4xx_HAL_Driver</GroupName>
<Files>
<File>
<FileName>stm32l4xx_hal_tim.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_tim.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_tim_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_tim_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_uart_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_i2c.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_i2c.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_i2c_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_i2c_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_rcc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rcc.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_rcc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rcc_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_flash.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_flash.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_flash_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_flash_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_flash_ramfunc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_flash_ramfunc.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_gpio.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_dma.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dma.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_dma_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dma_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_pwr.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_pwr.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_pwr_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_pwr_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_cortex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cortex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_adc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_adc_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_adc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_adc.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_dac.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dac.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_dac_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dac_ex.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_spi.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_spi.c</FilePath>
</File>
<File>
<FileName>stm32l4xx_hal_spi_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_spi_ex.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Drivers/CMSIS</GroupName>
<Files>
<File>
<FileName>system_stm32l4xx.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Src\system_stm32l4xx.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Hardware</GroupName>
<Files>
<File>
<FileName>DHT11_BUS.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Hardware\DHT11\DHT11_BUS.c</FilePath>
</File>
<File>
<FileName>oled.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\BSP\Hardware\OLED\oled.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>kernel</GroupName>
<Files>
<File>
<FileName>tos_binary_heap.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_binary_heap.c</FilePath>
</File>
<File>
<FileName>tos_char_fifo.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_char_fifo.c</FilePath>
</File>
<File>
<FileName>tos_completion.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_completion.c</FilePath>
</File>
<File>
<FileName>tos_countdownlatch.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_countdownlatch.c</FilePath>
</File>
<File>
<FileName>tos_event.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_event.c</FilePath>
</File>
<File>
<FileName>tos_global.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_global.c</FilePath>
</File>
<File>
<FileName>tos_mail_queue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_mail_queue.c</FilePath>
</File>
<File>
<FileName>tos_message_queue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_message_queue.c</FilePath>
</File>
<File>
<FileName>tos_mmblk.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_mmblk.c</FilePath>
</File>
<File>
<FileName>tos_mmheap.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_mmheap.c</FilePath>
</File>
<File>
<FileName>tos_mutex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_mutex.c</FilePath>
</File>
<File>
<FileName>tos_pend.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_pend.c</FilePath>
</File>
<File>
<FileName>tos_priority_mail_queue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_priority_mail_queue.c</FilePath>
</File>
<File>
<FileName>tos_priority_message_queue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_priority_message_queue.c</FilePath>
</File>
<File>
<FileName>tos_priority_queue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_priority_queue.c</FilePath>
</File>
<File>
<FileName>tos_ring_queue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_ring_queue.c</FilePath>
</File>
<File>
<FileName>tos_robin.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_robin.c</FilePath>
</File>
<File>
<FileName>tos_sched.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_sched.c</FilePath>
</File>
<File>
<FileName>tos_sem.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_sem.c</FilePath>
</File>
<File>
<FileName>tos_sys.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_sys.c</FilePath>
</File>
<File>
<FileName>tos_task.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_task.c</FilePath>
</File>
<File>
<FileName>tos_tick.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_tick.c</FilePath>
</File>
<File>
<FileName>tos_time.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_time.c</FilePath>
</File>
<File>
<FileName>tos_timer.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_timer.c</FilePath>
</File>
<File>
<FileName>tos_barrier.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_barrier.c</FilePath>
</File>
<File>
<FileName>tos_bitmap.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_bitmap.c</FilePath>
</File>
<File>
<FileName>tos_rwlock.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_rwlock.c</FilePath>
</File>
<File>
<FileName>tos_stopwatch.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\kernel\core\tos_stopwatch.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>cpu</GroupName>
<Files>
<File>
<FileName>port_s.S</FileName>
<FileType>2</FileType>
<FilePath>..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc\port_s.S</FilePath>
</File>
<File>
<FileName>tos_cpu.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\arch\arm\arm-v7m\common\tos_cpu.c</FilePath>
</File>
<File>
<FileName>port_c.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc\port_c.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>cmsis</GroupName>
<Files>
<File>
<FileName>cmsis_os.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\cmsis_os\cmsis_os.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>config</GroupName>
<Files>
<File>
<FileName>tos_config.h</FileName>
<FileType>5</FileType>
<FilePath>..\..\TOS-CONFIG\tos_config.h</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>posix</GroupName>
<Files>
<File>
<FileName>pthread.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\pthread.c</FilePath>
</File>
<File>
<FileName>pthread_prv.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\pthread_prv.c</FilePath>
</File>
<File>
<FileName>time.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\time.c</FilePath>
</File>
<File>
<FileName>time_prv.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\time_prv.c</FilePath>
</File>
<File>
<FileName>semaphore.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\semaphore.c</FilePath>
</File>
<File>
<FileName>mqueue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\mqueue.c</FilePath>
</File>
<File>
<FileName>timer_prv.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\timer_prv.c</FilePath>
</File>
<File>
<FileName>mqueue_prv.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\mqueue_prv.c</FilePath>
</File>
<File>
<FileName>sched.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\sched.c</FilePath>
</File>
<File>
<FileName>tos_posix.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\osal\posix\tos_posix.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>::CMSIS</GroupName>
</Group>
</Groups>
</Target>
</Targets>
<RTE>
<apis/>
<components>
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="4.3.0" condition="CMSIS Core">
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="4.5.0"/>
<targetInfos>
<targetInfo name="TencentOS_tiny"/>
</targetInfos>
</component>
</components>
<files/>
</RTE>
</Project>

View File

@@ -0,0 +1,140 @@
<html>
<body>
<pre>
<h1><EFBFBD>Vision Build Log</h1>
<h2>Tool Versions:</h2>
IDE-Version: <20>Vision V5.26.2.0
Copyright (C) 2018 ARM Ltd and ARM Germany GmbH. All rights reserved.
License Information: arthur Microsoft, Microsoft, LIC=2TTQ1-CJN11-8Y7VV-PZWYN-PU1X8-9S4FH
Tool Versions:
Toolchain: MDK-ARM Professional Version: 5.26.2.0
Toolchain Path: d:\Keil_v5\ARM\ARMCC\Bin
C Compiler: Armcc.exe V5.06 update 6 (build 750)
Assembler: Armasm.exe V5.06 update 6 (build 750)
Linker/Locator: ArmLink.exe V5.06 update 6 (build 750)
Library Manager: ArmAr.exe V5.06 update 6 (build 750)
Hex Converter: FromElf.exe V5.06 update 6 (build 750)
CPU DLL: SARMCM3.DLL V5.26.2.0
Dialog DLL: DCM.DLL V1.17.2.0
Target DLL: STLink\ST-LINKIII-KEIL_SWO.dll V3.0.5.0
Dialog DLL: TCM.DLL V1.36.1.0
<h2>Project:</h2>
D:\TOS\TencentOS-tiny\board\TencentOS_tiny_EVB_MX_Plus\KEIL\posix\TencentOS_tiny.uvprojx
Project File Date: 02/27/2020
<h2>Output:</h2>
*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'd:\Keil_v5\ARM\ARMCC\Bin'
Rebuild target 'TencentOS_tiny'
assembling startup_stm32l431xx.s...
compiling gpio.c...
compiling stm32l4xx_it.c...
compiling stm32l4xx_hal_msp.c...
compiling main.c...
compiling mcu_init.c...
compiling usart.c...
compiling adc.c...
compiling dac.c...
compiling stm32l4xx_hal_tim_ex.c...
compiling i2c.c...
compiling posix_sample.c...
compiling spi.c...
compiling stm32l4xx_hal_tim.c...
compiling stm32l4xx_hal_uart.c...
compiling stm32l4xx_hal_uart_ex.c...
compiling stm32l4xx_hal_i2c_ex.c...
compiling stm32l4xx_hal_i2c.c...
compiling stm32l4xx_hal_rcc.c...
compiling stm32l4xx_hal.c...
compiling stm32l4xx_hal_flash.c...
compiling stm32l4xx_hal_rcc_ex.c...
compiling stm32l4xx_hal_flash_ex.c...
compiling stm32l4xx_hal_flash_ramfunc.c...
compiling stm32l4xx_hal_dma.c...
compiling stm32l4xx_hal_gpio.c...
compiling stm32l4xx_hal_dma_ex.c...
compiling stm32l4xx_hal_pwr_ex.c...
compiling stm32l4xx_hal_pwr.c...
compiling stm32l4xx_hal_cortex.c...
compiling stm32l4xx_hal_dac_ex.c...
compiling stm32l4xx_hal_adc_ex.c...
compiling stm32l4xx_hal_dac.c...
compiling stm32l4xx_hal_adc.c...
compiling stm32l4xx_hal_spi_ex.c...
compiling stm32l4xx_hal_spi.c...
compiling system_stm32l4xx.c...
compiling tos_binary_heap.c...
compiling oled.c...
compiling DHT11_BUS.c...
compiling tos_char_fifo.c...
compiling tos_completion.c...
compiling tos_countdownlatch.c...
compiling tos_event.c...
compiling tos_mail_queue.c...
compiling tos_global.c...
compiling tos_message_queue.c...
compiling tos_mmblk.c...
compiling tos_mutex.c...
compiling tos_mmheap.c...
compiling tos_pend.c...
compiling tos_priority_message_queue.c...
compiling tos_ring_queue.c...
compiling tos_priority_queue.c...
compiling tos_priority_mail_queue.c...
compiling tos_sched.c...
compiling tos_robin.c...
compiling tos_sem.c...
compiling tos_tick.c...
compiling tos_sys.c...
compiling tos_task.c...
compiling tos_time.c...
compiling tos_timer.c...
compiling tos_barrier.c...
assembling port_s.S...
compiling tos_bitmap.c...
compiling tos_cpu.c...
compiling tos_stopwatch.c...
compiling tos_rwlock.c...
compiling cmsis_os.c...
compiling pthread.c...
compiling port_c.c...
compiling pthread_prv.c...
compiling time_prv.c...
compiling semaphore.c...
compiling time.c...
compiling timer_prv.c...
compiling mqueue_prv.c...
compiling mqueue.c...
compiling sched.c...
compiling tos_posix.c...
linking...
Program Size: Code=23380 RO-data=2664 RW-data=312 ZI-data=42888
FromELF: creating hex file...
".\obj\TencentOS_tiny.axf" - 0 Error(s), 0 Warning(s).
<h2>Software Packages used:</h2>
Package Vendor: ARM
http://www.keil.com/pack/ARM.CMSIS.5.4.0.pack
ARM.CMSIS.5.4.0
CMSIS (Cortex Microcontroller Software Interface Standard)
* Component: CORE Version: 5.1.2
Package Vendor: Keil
http://www.keil.com/pack/Keil.STM32L4xx_DFP.2.2.0.pack
Keil.STM32L4xx_DFP.2.2.0
STMicroelectronics STM32L4 Series Device Support, Drivers and Examples
<h2>Collection of Component include folders:</h2>
.\RTE\_TencentOS_tiny
d:\Keil_v5\ARM\PACK\ARM\CMSIS\5.4.0\CMSIS\Core\Include
d:\Keil_v5\ARM\PACK\Keil\STM32L4xx_DFP\2.2.0\Drivers\CMSIS\Device\ST\STM32L4xx\Include
<h2>Collection of Component Files used:</h2>
* Component: ARM::CMSIS:CORE:5.1.2
Build Time Elapsed: 00:00:22
</pre>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x00040000 { ; load region size_region
ER_IROM1 0x08000000 0x00040000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
RW_IRAM1 0x20000000 0x00010000 { ; RW data
.ANY (+RW +ZI)
}
}

View File

@@ -0,0 +1,404 @@
;********************** COPYRIGHT(c) 2017 STMicroelectronics ******************
;* File Name : startup_stm32l431xx.s
;* Author : MCD Application Team
;* Description : STM32L431xx Ultra Low Power devices vector table for MDK-ARM toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the Cortex-M4 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
;*
;* Redistribution and use in source and binary forms, with or without modification,
;* are permitted provided that the following conditions are met:
;* 1. Redistributions of source code must retain the above copyright notice,
;* this list of conditions and the following disclaimer.
;* 2. Redistributions in binary form must reproduce the above copyright notice,
;* this list of conditions and the following disclaimer in the documentation
;* and/or other materials provided with the distribution.
;* 3. Neither the name of STMicroelectronics nor the names of its contributors
;* may be used to endorse or promote products derived from this software
;* without specific prior written permission.
;*
;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
;* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;*
;*******************************************************************************
;
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x100
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x100
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window WatchDog
DCD PVD_PVM_IRQHandler ; PVD/PVM1/PVM2/PVM3/PVM4 through EXTI Line detection
DCD TAMP_STAMP_IRQHandler ; Tamper and TimeStamps through the EXTI line
DCD RTC_WKUP_IRQHandler ; RTC Wakeup through the EXTI line
DCD FLASH_IRQHandler ; FLASH
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line0
DCD EXTI1_IRQHandler ; EXTI Line1
DCD EXTI2_IRQHandler ; EXTI Line2
DCD EXTI3_IRQHandler ; EXTI Line3
DCD EXTI4_IRQHandler ; EXTI Line4
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_IRQHandler ; ADC1
DCD CAN1_TX_IRQHandler ; CAN1 TX
DCD CAN1_RX0_IRQHandler ; CAN1 RX0
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
DCD EXTI9_5_IRQHandler ; External Line[9:5]s
DCD TIM1_BRK_TIM15_IRQHandler ; TIM1 Break and TIM15
DCD TIM1_UP_TIM16_IRQHandler ; TIM1 Update and TIM16
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; External Line[15:10]
DCD RTC_Alarm_IRQHandler ; RTC Alarm (A and B) through EXTI Line
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SDMMC1_IRQHandler ; SDMMC1
DCD 0 ; Reserved
DCD SPI3_IRQHandler ; SPI3
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD TIM6_DAC_IRQHandler ; TIM6 and DAC1&2 underrun errors
DCD TIM7_IRQHandler ; TIM7
DCD DMA2_Channel1_IRQHandler ; DMA2 Channel 1
DCD DMA2_Channel2_IRQHandler ; DMA2 Channel 2
DCD DMA2_Channel3_IRQHandler ; DMA2 Channel 3
DCD DMA2_Channel4_IRQHandler ; DMA2 Channel 4
DCD DMA2_Channel5_IRQHandler ; DMA2 Channel 5
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD COMP_IRQHandler ; COMP Interrupt
DCD LPTIM1_IRQHandler ; LP TIM1 interrupt
DCD LPTIM2_IRQHandler ; LP TIM2 interrupt
DCD 0 ; Reserved
DCD DMA2_Channel6_IRQHandler ; DMA2 Channel 6
DCD DMA2_Channel7_IRQHandler ; DMA2 Channel 7
DCD LPUART1_IRQHandler ; LP UART1 interrupt
DCD QUADSPI_IRQHandler ; Quad SPI global interrupt
DCD I2C3_EV_IRQHandler ; I2C3 event
DCD I2C3_ER_IRQHandler ; I2C3 error
DCD SAI1_IRQHandler ; Serial Audio Interface 1 global interrupt
DCD 0 ; Reserved
DCD SWPMI1_IRQHandler ; Serial Wire Interface 1 global interrupt
DCD TSC_IRQHandler ; Touch Sense Controller global interrupt
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD RNG_IRQHandler ; RNG global interrupt
DCD FPU_IRQHandler ; FPU
DCD CRS_IRQHandler ; CRS interrupt
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT SystemInit
IMPORT __main
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_PVM_IRQHandler [WEAK]
EXPORT TAMP_STAMP_IRQHandler [WEAK]
EXPORT RTC_WKUP_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMA1_Channel1_IRQHandler [WEAK]
EXPORT DMA1_Channel2_IRQHandler [WEAK]
EXPORT DMA1_Channel3_IRQHandler [WEAK]
EXPORT DMA1_Channel4_IRQHandler [WEAK]
EXPORT DMA1_Channel5_IRQHandler [WEAK]
EXPORT DMA1_Channel6_IRQHandler [WEAK]
EXPORT DMA1_Channel7_IRQHandler [WEAK]
EXPORT ADC1_IRQHandler [WEAK]
EXPORT CAN1_TX_IRQHandler [WEAK]
EXPORT CAN1_RX0_IRQHandler [WEAK]
EXPORT CAN1_RX1_IRQHandler [WEAK]
EXPORT CAN1_SCE_IRQHandler [WEAK]
EXPORT EXTI9_5_IRQHandler [WEAK]
EXPORT TIM1_BRK_TIM15_IRQHandler [WEAK]
EXPORT TIM1_UP_TIM16_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI15_10_IRQHandler [WEAK]
EXPORT RTC_Alarm_IRQHandler [WEAK]
EXPORT SDMMC1_IRQHandler [WEAK]
EXPORT SPI3_IRQHandler [WEAK]
EXPORT TIM6_DAC_IRQHandler [WEAK]
EXPORT TIM7_IRQHandler [WEAK]
EXPORT DMA2_Channel1_IRQHandler [WEAK]
EXPORT DMA2_Channel2_IRQHandler [WEAK]
EXPORT DMA2_Channel3_IRQHandler [WEAK]
EXPORT DMA2_Channel4_IRQHandler [WEAK]
EXPORT DMA2_Channel5_IRQHandler [WEAK]
EXPORT COMP_IRQHandler [WEAK]
EXPORT LPTIM1_IRQHandler [WEAK]
EXPORT LPTIM2_IRQHandler [WEAK]
EXPORT DMA2_Channel6_IRQHandler [WEAK]
EXPORT DMA2_Channel7_IRQHandler [WEAK]
EXPORT LPUART1_IRQHandler [WEAK]
EXPORT QUADSPI_IRQHandler [WEAK]
EXPORT I2C3_EV_IRQHandler [WEAK]
EXPORT I2C3_ER_IRQHandler [WEAK]
EXPORT SAI1_IRQHandler [WEAK]
EXPORT SWPMI1_IRQHandler [WEAK]
EXPORT TSC_IRQHandler [WEAK]
EXPORT RNG_IRQHandler [WEAK]
EXPORT FPU_IRQHandler [WEAK]
EXPORT CRS_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_PVM_IRQHandler
TAMP_STAMP_IRQHandler
RTC_WKUP_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_IRQHandler
CAN1_TX_IRQHandler
CAN1_RX0_IRQHandler
CAN1_RX1_IRQHandler
CAN1_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_TIM15_IRQHandler
TIM1_UP_TIM16_IRQHandler
TIM1_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTC_Alarm_IRQHandler
SDMMC1_IRQHandler
SPI3_IRQHandler
TIM6_DAC_IRQHandler
TIM7_IRQHandler
DMA2_Channel1_IRQHandler
DMA2_Channel2_IRQHandler
DMA2_Channel3_IRQHandler
DMA2_Channel4_IRQHandler
DMA2_Channel5_IRQHandler
COMP_IRQHandler
LPTIM1_IRQHandler
LPTIM2_IRQHandler
DMA2_Channel6_IRQHandler
DMA2_Channel7_IRQHandler
LPUART1_IRQHandler
QUADSPI_IRQHandler
I2C3_EV_IRQHandler
I2C3_ER_IRQHandler
SAI1_IRQHandler
SWPMI1_IRQHandler
TSC_IRQHandler
RNG_IRQHandler
FPU_IRQHandler
CRS_IRQHandler
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE*****

View File

@@ -0,0 +1,136 @@
#include "tos_posix.h"
#include "pthread.h"
#include "mqueue.h"
#include "semaphore.h"
#include "time.h"
typedef struct pthread_arg_st {
char *msg;
uint32_t payload;
} pthread_arg_t;
#define FIRSTBORN_PTHREAD_STACK_SIZE 1024
uint8_t firstborn_pthread_stack[FIRSTBORN_PTHREAD_STACK_SIZE];
pthread_t firstborn_pthread;
pthread_arg_t the_arg;
pthread_t secondborn_pthread;
char *secondborn_last_words = "2nd, dead now";
pthread_t thirdborn_pthread;
pthread_t fourthborn_pthread;
char *fourthborn_last_words = "4th, dead now";
void *fourthborn_routine(void *arg)
{
int i = 0;
while (1) {
printf("I am the 4th-born\n");
tos_task_delay(2000);
if (++i == 4) {
printf("4th-born: I kill myself!\n");
pthread_exit(fourthborn_last_words);
}
}
}
void *thirdborn_routine(void *arg)
{
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
while (1) {
printf("I am the 3rd-born\n");
tos_task_delay(2000);
}
}
void *secondborn_routine(void *arg)
{
printf("I am the 2nd-born, hello!\n");
tos_task_delay(2000);
printf("I am the 2nd-born, goodbye!\n");
return (void *)secondborn_last_words;
}
void *firstborn_routine(void *arg)
{
int i = 0;
int rc = 0;
pthread_arg_t *the_arg;
pthread_attr_t attr;
void *value;
the_arg = (pthread_arg_t *)arg;
printf("msg: %s\n", the_arg->msg);
printf("payload:0x%x\n", the_arg->payload);
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
rc = pthread_create(&secondborn_pthread, &attr, secondborn_routine, NULL);
if (rc != 0) {
printf("2nd-born create failed!\n");
}
pthread_join(secondborn_pthread, &value);
printf("2nd-born is dead now\n");
printf("his last words: %s\n", (char *)value);
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
rc = pthread_create(&thirdborn_pthread, &attr, thirdborn_routine, NULL);
if (rc != 0) {
printf("3rd-born pthread create failed!\n");
}
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
rc = pthread_create(&fourthborn_pthread, &attr, fourthborn_routine, NULL);
if (rc != 0) {
printf("4th-born create failed!\n");
}
while (1) {
++i;
printf("I am the 1st-born\n");
if (i == 3) {
printf("do the canceling to 3rd-born!\n");
pthread_cancel(thirdborn_pthread);
} else if (i == 4) {
/* the fourththread must be dead already, check his last words */
pthread_join(fourthborn_pthread, &value);
printf("4th-born's last words: %s\n", (char *)value);
}
tos_task_delay(3000);
}
}
void application_entry(void *arg)
{
int rc = 0;
pthread_attr_t attr;
struct sched_param param;
/* if use posix, must have this function invoked first */
rc = tos_posix_init();
if (rc != 0) {
return;
}
the_arg.msg = "hello, 1st-born posix thread!";
the_arg.payload = 0xDEADBEEF;
pthread_attr_init(&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
param.sched_priority = 4;
pthread_attr_setschedparam(&attr, &param);
pthread_attr_setstack(&attr, firstborn_pthread_stack, sizeof(firstborn_pthread_stack));
rc = pthread_create(&firstborn_pthread, &attr, firstborn_routine, &the_arg);
if (rc != 0) {
return;
}
}

View File

@@ -0,0 +1,89 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _TOS_BARRIER_H_
#define _TOS_BARRIER_H_
__CDECLS_BEGIN
typedef struct k_barrier_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
pend_obj_t pend_obj;
k_barrier_cnt_t count;
} k_barrier_t;
/**
* @brief Create a thread barrier.
*
* @attention the count must be greater then zero.
*
* @param[in] barrier the barrier.
* @param[in] count the number of threads(task) must call tos_barrier_pend before any of them successfully return from the call.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_BARRIER_COUNT_INVALID the count is equals to zero.
*/
__API__ k_err_t tos_barrier_create(k_barrier_t *barrier, k_barrier_cnt_t count);
/**
* @brief Create a thread barrier.
*
* @attention the count must be greater then zero.
*
* @param[in] barrier the barrier.
* @param[in] count the number of threads(task) must call tos_barrier_pend before any of them successfully return from the call.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_BARRIER_COUNT_INVALID the count is equals to zero.
*/
__API__ k_err_t tos_barrier_destroy(k_barrier_t *barrier);
/**
* @brief Pend on a barrier.
*
* @attention until (countdownlatch->count) of tasks have called the pend, the pender would wake up.
*
* @param[in] barrier the barrier.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_BARRIER_OVERFLOW the barrier is pended too many times.
*/
__API__ k_err_t tos_barrier_pend(k_barrier_t *barrier);
/**
* @brief Reset a barrier.
*
* @attention
*
* @param[in] barrier the barrier.
* @param[in] count the count of the barrier to be reset.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_barrier_reset(k_barrier_t *barrier, k_barrier_cnt_t count);
__CDECLS_END
#endif /* _TOS_BARRIER_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_BINARY_HEAP_H_
#define _TOS_BINARY_HEAP_H_
__CDECLS_BEGIN
typedef int (*k_bin_heap_cmp)(void *first, void *second);
typedef struct k_binary_heap_st {
@@ -176,5 +178,7 @@ __API__ int tos_bin_heap_is_empty(k_bin_heap_t *bin_heap);
*/
__API__ int tos_bin_heap_is_full(k_bin_heap_t *bin_heap);
__CDECLS_END
#endif /* _TOS_BINARY_HEAP_H_ */

View File

@@ -0,0 +1,155 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _TOS_BITMAP_H_
#define _TOS_BITMAP_H_
typedef uint32_t k_bmtbl_t;
typedef struct k_bitmap_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
uint32_t bit_ndx_max;
uint32_t bit_max;
k_bmtbl_t *bitmap_tbl;
} k_bitmap_t;
#define K_BITMAP_SLOT_SIZE (sizeof(k_bmtbl_t) * 8) /* in bits */
#define K_BITMAP_TBL_SIZE(bit_max) ((bit_max + K_BITMAP_SLOT_SIZE - 1) / K_BITMAP_SLOT_SIZE)
#define K_BITMAP_NDX(bit) ((bit) >> 5u) /* bit / K_BITMAP_SLOT_SIZE */
#define K_BITMAP_BIT(bit) ((uint32_t)1u << (K_BITMAP_SLOT_SIZE - 1u - ((bit) & (K_BITMAP_SLOT_SIZE - 1u))))
#define TOS_BITMAP_SIZE(bit_max) (K_BITMAP_TBL_SIZE(bit_max))
/**
* @brief Create a bitmap with all bit are set to 0.
*
* @attention the size of bitmap_tabl can be caculated by the macro TOS_BITMAP_SIZE
*
* @param[in] bitmap pointer to the handler of the bitmap.
* @param[in] bitmap_tbl bitmap table buffer.
* @param[in] bit_max maximal bit.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_OBJ_PTR_NULL bitmap is NULL.
*/
__API__ k_err_t tos_bitmap_create_empty(k_bitmap_t *bitmap, k_bmtbl_t *bitmap_tbl, uint32_t bit_max);
/**
* @brief Create a bitmap with all bit are set to 1.
*
* @attention the size of bitmap_tabl can be caculated by the macro TOS_BITMAP_SIZE
*
* @param[in] bitmap pointer to the handler of the bitmap.
* @param[in] bitmap_tbl bitmap table buffer.
* @param[in] bit_max maximal bit.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_OBJ_PTR_NULL bitmap is NULL.
*/
__API__ k_err_t tos_bitmap_create_full(k_bitmap_t *bitmap, k_bmtbl_t *bitmap_tbl, uint32_t bit_max);
/**
* @brief Destroy the bitmap.
*
* @attention
*
* @param[in] bitmap pointer to the handler of the bitmap.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_OBJ_PTR_NULL bitmap is NULL.
*/
__API__ k_err_t tos_bitmap_destroy(k_bitmap_t *bitmap);
/**
* @brief Set a certain bit of the bitmap to 1.
*
* @attention
*
* @param[in] bitmap pointer to the handler of the bitmap.
* @param[in] bit the bit to set.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_BITMAP_EXCEED bit is larger than the bit_max passed to tos_bitmap_create_*.
*/
__API__ k_err_t tos_bitmap_set(k_bitmap_t *bitmap, uint32_t bit);
/**
* @brief Set a certain bit of the bitmap to 0.
*
* @attention
*
* @param[in] bitmap pointer to the handler of the bitmap.
* @param[in] bit the bit to set.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_BITMAP_EXCEED bit is larger than the bit_max passed to tos_bitmap_create_*.
*/
__API__ k_err_t tos_bitmap_reset(k_bitmap_t *bitmap, uint32_t bit);
/**
* @brief Test whether a certain bit of the bitmap is 1.
*
* @attention
*
* @param[in] bitmap pointer to the handler of the bitmap.
* @param[in] bit the bit to set.
*
* @return whether the bit is 1
* @retval #K_TRUE the certain bit is 1.
* @retval #K_FALSE the certain bit is not 1(that means is 0).
*/
__API__ int tos_bitmap_is_set(k_bitmap_t *bitmap, uint32_t bit);
/**
* @brief Test whether a certain bit of the bitmap is 0.
*
* @attention
*
* @param[in] bitmap pointer to the handler of the bitmap.
* @param[in] bit the bit to set.
*
* @return whether the bit is 0
* @retval #K_TRUE the certain bit is 0.
* @retval #K_FALSE the certain bit is not 0(that means is 1).
*/
__API__ int tos_bitmap_is_reset(k_bitmap_t *bitmap, uint32_t bit);
/**
* @brief Get the lowest significant bit of the bitmap.
*
* @attention The very first bit which is set to 1.
*
* @param[in] bitmap pointer to the handler of the bitmap.
* @param[in] bit the bit to set.
*
* @return the lowest significant bit of the bitmap.
*/
__API__ int tos_bitmap_lsb(k_bitmap_t *bitmap);
#endif /* _TOS_BITMAP_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_CHAR_FIFO_H_
#define _TOS_CHAR_FIFO_H_
__CDECLS_BEGIN
typedef struct k_char_fifo_st {
knl_obj_t knl_obj;
@@ -187,5 +189,7 @@ __API__ int tos_chr_fifo_is_empty(k_chr_fifo_t *chr_fifo);
*/
__API__ int tos_chr_fifo_is_full(k_chr_fifo_t *chr_fifo);
#endif // _TOS_CHAR_FIFO_H_
__CDECLS_END
#endif /* _TOS_CHAR_FIFO_H_ */

View File

@@ -18,21 +18,30 @@
#ifndef _TOS_COMPILER_H_
#define _TOS_COMPILER_H_
// function with __API__ prefix, api for user
/* function with __API__ prefix, api for user */
#define __API__
// function with __KNL__ prefix, only for kernel
/* function with __KNL__ prefix, only for kernel */
#define __KNL__
// function with __HOOK__ prefix, should be implemented by user
/* function with __HOOK__ prefix, should be implemented by user */
#define __HOOK__
// function with __DEBUG__ prefix, only for debug
/* function with __DEBUG__ prefix, only for debug */
#define __DEBUG__
// function with __PORT__ is architecture depended
/* function with __PORT__ is architecture depended */
#define __PORT__
/* CPP header guards */
#ifdef __cplusplus
#define __CDECLS_BEGIN extern "C" {
#define __CDECLS_END }
#else
#define __CDECLS_BEGIN
#define __CDECLS_END
#endif
/*------------------ RealView Compiler -----------------*/
#if defined(__CC_ARM)

View File

@@ -18,7 +18,7 @@
#ifndef _TOS_COMPLETION_H_
#define _TOS_COMPLETION_H_
#if TOS_CFG_COMPLETION_EN > 0u
__CDECLS_BEGIN
typedef uint16_t completion_done_t;
@@ -147,7 +147,7 @@ __API__ k_err_t tos_completion_reset(k_completion_t *completion);
*/
__API__ int tos_completion_is_done(k_completion_t *completion);
#endif
__CDECLS_END
#endif
#endif /* _TOS_COMPLETION_H_ */

View File

@@ -69,24 +69,6 @@
/////////////////////////////////////////
/////////////////////////////////////////
// disable countdownlatch
#ifdef TOS_CFG_COUNTDOWNLATCH_EN
#undef TOS_CFG_COUNTDOWNLATCH_EN
#endif
#define TOS_CFG_COUNTDOWNLATCH_EN 0u
/////////////////////////////////////////
/////////////////////////////////////////
// disable completion
#ifdef TOS_CFG_COMPLETION_EN
#undef TOS_CFG_COMPLETION_EN
#endif
#define TOS_CFG_COMPLETION_EN 0u
/////////////////////////////////////////
/////////////////////////////////////////
// disable the "traditional" timer
#ifdef TOS_CFG_TIMER_EN
@@ -206,14 +188,6 @@
#define TOS_CFG_SEM_EN 0u
#endif
#ifndef TOS_CFG_COUNTDOWNLATCH_EN
#define TOS_CFG_COUNTDOWNLATCH_EN 0u
#endif
#ifndef TOS_CFG_COMPLETION_EN
#define TOS_CFG_COMPLETION_EN 0u
#endif
#ifndef TOS_CFG_TIMER_EN
#define TOS_CFG_TIMER_EN 0u
#endif

View File

@@ -18,7 +18,7 @@
#ifndef _TOS_COUNTDOWNLATCH_H_
#define _TOS_COUNTDOWNLATCH_H_
#if TOS_CFG_COUNTDOWNLATCH_EN > 0u
__CDECLS_BEGIN
typedef struct k_countdownlatch_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
@@ -114,7 +114,7 @@ __API__ k_err_t tos_countdownlatch_post(k_countdownlatch_t *countdownlatch);
*/
__API__ k_err_t tos_countdownlatch_reset(k_countdownlatch_t *countdownlatch, k_countdownlatch_cnt_t count);
#endif
__CDECLS_END
#endif
#endif /* _TOS_COUNTDOWNLATCH_H_ */

View File

@@ -21,7 +21,12 @@
typedef enum k_err_en {
K_ERR_NONE = 0u,
K_ERR_BIN_HEAP_FULL = 10u,
K_ERR_BARRIER_COUNT_INVALID = 5u,
K_ERR_BARRIER_OVERFLOW,
K_ERR_BITMAP_EXCEED = 10u,
K_ERR_BIN_HEAP_FULL = 15u,
K_ERR_BIN_HEAP_EMPTY,
K_ERR_BIN_HEAP_ITEM_SIZE_NOT_MATCH,
@@ -64,7 +69,6 @@ typedef enum k_err_en {
K_ERR_PEND_NOWAIT = 1200u,
K_ERR_PEND_SCHED_LOCKED,
K_ERR_PEND_IN_IRQ,
K_ERR_PEND_ABNORMAL,
K_ERR_PEND_TIMEOUT,
K_ERR_PEND_DESTROY,
@@ -79,16 +83,25 @@ typedef enum k_err_en {
K_ERR_PRIO_Q_SLOT_NOT_TAKEN,
K_ERR_PRIO_Q_ITEM_SIZE_NOT_MATCH,
K_ERR_RING_Q_FULL = 1600u,
K_ERR_RING_Q_FULL = 1500u,
K_ERR_RING_Q_EMPTY,
K_ERR_RING_Q_ITEM_SIZE_NOT_MATCH,
K_ERR_RWLOCK_READERS_TO_MANY = 1600u,
K_ERR_RWLOCK_IS_READING,
K_ERR_RWLOCK_IS_WRITTING,
K_ERR_RWLOCK_NOT_READING,
K_ERR_RWLOCK_NOT_WRITTING,
K_ERR_RWLOCK_NOT_TAKEN,
K_ERR_RWLOCK_WAITING_WRITERS_TO_MANY,
K_ERR_SCHED_LOCKED = 1700u,
K_ERR_SCHED_NOT_LOCKED,
K_ERR_SEM_OVERFLOW = 1800u,
K_ERR_TASK_DESTROY_IDLE = 1900u,
K_ERR_TASK_ALREADY_CREATED = 1900u,
K_ERR_TASK_DESTROY_IDLE,
K_ERR_TASK_NOT_DELAY,
K_ERR_TASK_PRIO_INVALID,
K_ERR_TASK_RESUME_SELF,

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_EVENT_H_
#define _TOS_EVENT_H_
__CDECLS_BEGIN
#if TOS_CFG_EVENT_EN > 0
// if we are pending an event, for any flag we expect is set is ok, this flag should be passed to tos_event_pend
@@ -133,5 +135,7 @@ __API__ k_err_t tos_event_post_keep(k_event_t *event, k_event_flag_t flag);
#endif
__CDECLS_END
#endif /* _TOS_EVENT_H_ */

View File

@@ -35,6 +35,7 @@
#include <tos_slist.h>
#include <tos_pend.h>
#include <tos_sys.h>
#include <tos_bitmap.h>
#include <tos_ring_queue.h>
#include <tos_char_fifo.h>
#include <tos_mail_queue.h>
@@ -48,10 +49,13 @@
#include <tos_mutex.h>
#include <tos_sem.h>
#include <tos_event.h>
#include <tos_countdownlatch.h>
#include <tos_barrier.h>
#include <tos_completion.h>
#include <tos_countdownlatch.h>
#include <tos_rwlock.h>
#include <tos_timer.h>
#include <tos_time.h>
#include <tos_stopwatch.h>
#include <tos_mmblk.h>
#include <tos_mmheap.h>
#include <tos_tick.h>

View File

@@ -23,32 +23,37 @@
#include <stdlib.h>
#include <string.h>
#define TOS_MACRO_BEGIN do {
#define TOS_MACRO_END } while (0)
#define TOS_OFFSET_OF_FIELD(type, field) \
((uint32_t)&(((type *)0)->field))
#define TOS_CONTAINER_OF_FIELD(ptr, type, field) \
((type *)((uint8_t *)(ptr) - TOS_OFFSET_OF_FIELD(type, field)))
#define TOS_COUNT_OF(array) (sizeof(array) / sizeof(array[0]))
#define TOS_PTR_SANITY_CHECK(ptr) \
do { \
TOS_MACRO_BEGIN \
if (unlikely(!(ptr))) { \
return K_ERR_OBJ_PTR_NULL; \
} \
} while(0)
TOS_MACRO_END
#define TOS_PTR_SANITY_CHECK_RC(ptr, return_code) \
do { \
TOS_MACRO_BEGIN \
if (unlikely(!(ptr))) { \
return return_code; \
} \
} while(0)
TOS_MACRO_END
#define TOS_IN_IRQ_CHECK() \
do { \
TOS_MACRO_BEGIN \
if (unlikely(knl_is_inirq())) { \
return K_ERR_IN_IRQ; \
} \
} while(0)
TOS_MACRO_END
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
@@ -56,18 +61,19 @@
#define TOS_OBJ_DEINIT(obj) knl_object_deinit(&obj->knl_obj)
#define TOS_OBJ_VERIFY(obj, obj_type) \
do { \
TOS_MACRO_BEGIN \
if (!knl_object_verify(&obj->knl_obj, obj_type)) { \
return K_ERR_OBJ_INVALID; \
} \
} while (0)
TOS_MACRO_END
#define TOS_OBJ_VERIFY_RC(obj, obj_type, return_code) \
do { \
TOS_MACRO_BEGIN \
if (!knl_object_verify(&obj->knl_obj, obj_type)) { \
return return_code; \
} \
} while (0)
TOS_MACRO_END
#else

View File

@@ -30,6 +30,7 @@ typedef uint8_t k_nesting_t;
typedef uint16_t k_opt_t;
typedef uint16_t k_sem_cnt_t;
typedef uint32_t k_event_flag_t;
typedef uint16_t k_barrier_cnt_t;
typedef uint16_t k_countdownlatch_cnt_t;
typedef uint32_t k_time_t;

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_LIST_H_
#define _TOS_LIST_H_
__CDECLS_BEGIN
typedef struct k_list_node_st {
struct k_list_node_st *next;
struct k_list_node_st *prev;
@@ -138,5 +140,7 @@ __API__ __STATIC_INLINE__ int tos_list_empty(const k_list_t *list)
return list->next == list;
}
__CDECLS_END
#endif /* _TOS_LIST_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_MAIL_QUEUE_H_
#define _TOS_MAIL_QUEUE_H_
__CDECLS_BEGIN
#if TOS_CFG_MAIL_QUEUE_EN > 0u
typedef struct k_mail_queue_st {
@@ -155,5 +157,7 @@ __API__ k_err_t tos_mail_q_post_all(k_mail_q_t *mail_q, void *mail_buf, size_t m
#endif
__CDECLS_END
#endif /* _TOS_MAIL_QUEUE_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_MESSAGE_QUEUE_H_
#define _TOS_MESSAGE_QUEUE_H_
__CDECLS_BEGIN
#if TOS_CFG_MESSAGE_QUEUE_EN > 0u
typedef struct k_message_queue_st {
@@ -150,5 +152,7 @@ __API__ k_err_t tos_msg_q_post_all(k_msg_q_t *msg_q, void *msg_ptr);
#endif
__CDECLS_END
#endif /* _TOS_MESSAGE_QUEUE_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_MMBLK_H_
#define _TOS_MMBLK_H_
__CDECLS_BEGIN
#if TOS_CFG_MMBLK_EN > 0u
#define K_MMBLK_NEXT_BLK(blk_curr, blk_size) ((void *)((cpu_addr_t)blk_curr + blk_size))
@@ -103,5 +105,7 @@ __API__ k_err_t tos_mmblk_free(k_mmblk_pool_t *mbp, void *blk);
#endif
__CDECLS_END
#endif /* _TOS_MMBLK_H_ */

View File

@@ -55,6 +55,8 @@
#ifndef _TOS_MMHEAP_H_
#define _TOS_MMHEAP_H_
__CDECLS_BEGIN
#if TOS_CFG_MMHEAP_EN > 0u
/**
@@ -262,5 +264,7 @@ __KNL__ k_err_t mmheap_init_with_pool(void *pool_start, size_t pool_size);
#endif
__CDECLS_END
#endif /* _TOS_MMHEAP_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_MUTEX_H_
#define _TOS_MUTEX_H_
__CDECLS_BEGIN
#if TOS_CFG_MUTEX_EN > 0u
typedef struct k_mutex_st {
@@ -114,5 +116,7 @@ __KNL__ void mutex_release(k_mutex_t *mutex);
#endif
__CDECLS_END
#endif /* _TOS_MUTEX_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_PEND_H_
#define _TOS_PEND_H_
__CDECLS_BEGIN
typedef struct k_task_st k_task_t;
/**
@@ -67,5 +69,7 @@ __KNL__ void pend_wakeup_all(pend_obj_t *object, pend_state_t state);
__KNL__ void pend_wakeup(pend_obj_t *object, pend_state_t state, opt_post_t opt);
__CDECLS_END
#endif /* _TOS_PEND_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_PRIORITY_MAIL_QUEUE_H_
#define _TOS_PRIORITY_MAIL_QUEUE_H_
__CDECLS_BEGIN
#if TOS_CFG_PRIORITY_MAIL_QUEUE_EN > 0u
typedef struct k_priority_mail_queue_st {
@@ -160,5 +162,7 @@ __API__ k_err_t tos_prio_mail_q_post_all(k_prio_mail_q_t *prio_mail_q, void *mai
#endif
__CDECLS_END
#endif /* TOS_CFG_PRIORITY_MAIL_QUEUE_EN */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_PRIORITY_MESSAGE_QUEUE_H_
#define _TOS_PRIORITY_MESSAGE_QUEUE_H_
__CDECLS_BEGIN
#if TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN > 0u
typedef struct k_priority_message_queue_st {
@@ -155,5 +157,7 @@ __API__ k_err_t tos_prio_msg_q_post_all(k_prio_msg_q_t *prio_msg_q, void *msg_pt
#endif
__CDECLS_END
#endif /* _TOS_PRIORITY_MESSAGE_QUEUE_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_PRIORITY_QUEUE_H_
#define _TOS_PRIORITY_QUEUE_H_
__CDECLS_BEGIN
typedef uint16_t prio_q_slot_t;
typedef struct prio_q_pool_manager_entry_st {
@@ -207,5 +209,7 @@ __API__ int tos_prio_q_is_empty(k_prio_q_t *prio_q);
*/
__API__ int tos_prio_q_is_full(k_prio_q_t *prio_q);
__CDECLS_END
#endif /* _TOS_PRIORITY_QUEUE_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_ROBIN_H_
#define _TOS_ROBIN_H_
__CDECLS_BEGIN
#if TOS_CFG_ROUND_ROBIN_EN > 0u
/**
@@ -50,5 +52,7 @@ __KNL__ void robin_sched(k_prio_t prio);
#endif
__CDECLS_END
#endif /* _TOS_ROBIN_H_ */

View File

@@ -0,0 +1,192 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _TOS_RWLOCK_H_
#define _TOS_RWLOCK_H_
__CDECLS_BEGIN
#if (TOS_CFG_SEM_EN > 0u) && (TOS_CFG_MUTEX_EN > 0u)
typedef uint16_t rw_cnt_t;
typedef struct k_rwlock_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
k_mutex_t lock;
k_sem_t signal;
rw_cnt_t n_readers; /* how many readers are reading? */
rw_cnt_t n_writers; /* how many writers are waiting to obtain the wlock? */
int is_writting;
} k_rwlock_t;
/**
* @brief Create a read-write lock.
*
* @attention a read-write lock can be hold by multi-readers, that means simultaneously reading is allowed;
* but a read-write lock can only be hold by one writes, that means simultaneously writting or read while writting is not allowed.
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_rwlock_create(k_rwlock_t *rwlock);
/**
* @brief Destroy a read-write lock.
*
* @attention
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_rwlock_destroy(k_rwlock_t *rwlock);
/**
* @brief Pend on the read-lock of a read-write lock.
*
* @attention if one reader already hold the read-lock, other reader can hold the read-lock simultaneously.
* and no writers can hold the write-lock.
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_READERS_TO_MANY too many reader are holding the read-lock
*/
__API__ k_err_t tos_rwlock_rpend_timed(k_rwlock_t *rwlock, k_tick_t timeout);
/**
* @brief Pend on the read-lock of a read-write lock.
*
* @attention if one reader already hold the read-lock, other reader can hold the read-lock simultaneously.
* and no writers can hold the write-lock.
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_READERS_TO_MANY too many reader are holding the read-lock
*/
__API__ k_err_t tos_rwlock_rpend(k_rwlock_t *rwlock);
/**
* @brief Try pend on the read-lock of a read-write lock.
*
* @attention Try means just take a look, if can obtain the read-lock, then we obtain it; otherwise, just return with no-waiting.
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_IS_WRITTING the read-write lock is hold by a writter(is writting).
*/
__API__ k_err_t tos_rwlock_rpend_try(k_rwlock_t *rwlock);
/**
* @brief Pend on the write-lock of a read-write lock.
*
* @attention if one writer already hold the write-lock, other writer CANNOT hold the write-lock any more.
* and no readers can hold the read-lock.
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_WAITING_WRITERS_TO_MANY too many writers are waiting for the write-lock
*/
__API__ k_err_t tos_rwlock_wpend_timed(k_rwlock_t *rwlock, k_tick_t timeout);
/**
* @brief Pend on the write-lock of a read-write lock.
*
* @attention if one writer already hold the write-lock, other writer CANNOT hold the write-lock any more.
* and no readers can hold the read-lock.
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_WAITING_WRITERS_TO_MANY too many writers are waiting for the write-lock
*/
__API__ k_err_t tos_rwlock_wpend(k_rwlock_t *rwlock);
/**
* @brief Pend on the write-lock of a read-write lock.
*
* @attention Try means just take a look, if can obtain the write-lock, then we obtain it; otherwise, just return with no-waiting.
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_IS_READING the read-write lock is hold by other reader[s](is reading).
* @retval #K_ERR_RWLOCK_IS_WRITTING the read-write lock is hold by another writter(is writting).
*/
__API__ k_err_t tos_rwlock_wpend_try(k_rwlock_t *rwlock);
/**
* @brief Post the read-lock of a read-write lock.
*
* @attention
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_NOT_READING the read-lock is not held by reader[s].
*/
__API__ k_err_t tos_rwlock_rpost(k_rwlock_t *rwlock);
/**
* @brief Post the write-lock of a read-write lock.
*
* @attention
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_NOT_WRITTING the write-lock is not held by a writter.
*/
__API__ k_err_t tos_rwlock_wpost(k_rwlock_t *rwlock);
/**
* @brief Post the read&write-lock of a read-write lock.
*
* @attention
*
* @param[in] rwlock the read-write lock.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RWLOCK_NOT_TAKEN the read-write lock is neither held by reader[s] nor held by a writter.
*/
__API__ k_err_t tos_rwlock_post(k_rwlock_t *rwlock);
#endif
__CDECLS_END
#endif /* _TOS_RWLOCK_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_SCHED_H_
#define _TOS_SCHED_H_
__CDECLS_BEGIN
#define K_PRIO_TBL_SIZE ((TOS_CFG_TASK_PRIO_MAX + 31) / 32)
#define K_PRIO_TBL_SLOT_SIZE (32u)
@@ -48,5 +50,7 @@ __KNL__ void readyqueue_remove(k_task_t *task);
__KNL__ void readyqueue_move_head_to_tail(k_prio_t prio);
__CDECLS_END
#endif /* _TOS_SCHED_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_SEM_H_
#define _TOS_SEM_H_
__CDECLS_BEGIN
#if TOS_CFG_SEM_EN > 0u
typedef struct k_sem_st {
@@ -120,5 +122,7 @@ __API__ k_err_t tos_sem_post_all(k_sem_t *sem);
#endif
__CDECLS_END
#endif /* _TOS_SEM_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_SLIST_H_
#define _TOS_SLIST_H_
__CDECLS_BEGIN
typedef struct k_slist_node_st {
struct k_slist_node_st *next;
} k_slist_t;
@@ -181,5 +183,7 @@ __API__ __STATIC_INLINE__ int tos_slist_empty(k_slist_t *slist)
return !slist->next;
}
__CDECLS_END
#endif /* _TOS_SLIST_H_ */

View File

@@ -0,0 +1,141 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _TOS_STOPWATCH_H_
#define _TOS_STOPWATCH_H_
__CDECLS_BEGIN
typedef struct k_stopwatch_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
k_tick_t until;
} k_stopwatch_t;
/**
* @brief Create a stopwatch.
*
* @attention
*
* @param[in] stopwatch the stopwatch.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_stopwatch_create(k_stopwatch_t *stopwatch);
/**
* @brief Destroy a stopwatch.
*
* @attention
*
* @param[in] stopwatch the stopwatch.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_stopwatch_destroy(k_stopwatch_t *stopwatch);
/**
* @brief Count down for a certain tick.
*
* @attention
*
* @param[in] stopwatch the stopwatch.
* @param[in] tick tick to count down.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_stopwatch_countdown(k_stopwatch_t *stopwatch, k_tick_t tick);
/**
* @brief Count down for a certain time(in millisecond).
*
* @attention
*
* @param[in] stopwatch the stopwatch.
* @param[in] millisec time(in millisecond) to count down.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_stopwatch_countdown_ms(k_stopwatch_t *stopwatch, k_time_t millisec);
/**
* @brief Delay for a certain tick.
*
* @attention the stopwatch delay is a "busy" delay without give up of CPU(compared to tos_task_delay)
*
* @param[in] tick tick to delay.
*
* @return None
*/
__API__ void tos_stopwatch_delay(k_tick_t tick);
/**
* @brief Delay for a certain time(in millisecond).
*
* @attention the stopwatch delay is a "busy" delay without give up of CPU(compared to tos_task_delay)
*
* @param[in] millisec time(in millisecond) to delay.
*
* @return None
*/
__API__ void tos_stopwatch_delay_ms(k_time_t millisec);
/**
* @brief How much time remain of the stopwatch(in tick).
*
* @attention
*
* @param[in] stopwatch ticks remain.
*
* @return ticks remain
*/
__API__ k_tick_t tos_stopwatch_remain(k_stopwatch_t *stopwatch);
/**
* @brief How much time remain of the stopwatch(in millisecond).
*
* @attention
*
* @param[in] stopwatch milliseconds remain.
*
* @return milliseconds remain
*/
__API__ k_time_t tos_stopwatch_remain_ms(k_stopwatch_t *stopwatch);
/**
* @brief Whether the stopwatch is expired.
*
* @attention
*
* @param[in] stopwatch milliseconds remain.
*
* @return whether the stopwatch is expired
* @retval #K_TRUE the stopwatch is expired.
* @retval #K_FALSE the stopwatch is no expired.
*/
__API__ int tos_stopwatch_is_expired(k_stopwatch_t *stopwatch);
__CDECLS_END
#endif /* _TOS_STOPWATCH_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_SYS_H_
#define _TOS_SYS_H_
__CDECLS_BEGIN
#define K_NESTING_LIMIT_IRQ (k_nesting_t)250u
#define K_NESTING_LIMIT_SCHED_LOCK (k_nesting_t)250u
@@ -29,25 +31,30 @@ typedef enum knl_state_en {
// some kind of magic number, mainly for identifing whether the object is initialized, or whether user pass the correct parameter.
typedef enum knl_obj_type_en {
KNL_OBJ_TYPE_NONE = 0x0000,
KNL_OBJ_TYPE_TASK = 0xDAD1,
KNL_OBJ_TYPE_TIMER = 0xDAD2,
KNL_OBJ_TYPE_MSG_QUEUE = 0xDAD3,
KNL_OBJ_TYPE_MMBLK_POOL = 0xDAD4,
KNL_OBJ_TYPE_RING_QUEUE = 0xDAD5,
KNL_OBJ_TYPE_BINARY_HEAP = 0xDAD6,
KNL_OBJ_TYPE_PRIORITY_QUEUE = 0xDAD7,
KNL_OBJ_TYPE_CHAR_FIFO = 0xDAD8,
KNL_OBJ_TYPE_BINARY_HEAP = 0xDAD0,
KNL_OBJ_TYPE_BITMAP = 0xDAD1,
KNL_OBJ_TYPE_CHAR_FIFO = 0xDAD2,
KNL_OBJ_TYPE_MMBLK_POOL = 0xDAD3,
KNL_OBJ_TYPE_MSG_QUEUE = 0xDAD4,
KNL_OBJ_TYPE_PRIORITY_QUEUE = 0xDAD5,
KNL_OBJ_TYPE_RING_QUEUE = 0xDAD6,
KNL_OBJ_TYPE_STOPWATCH = 0xDAD7,
KNL_OBJ_TYPE_TASK = 0xDAD8,
KNL_OBJ_TYPE_TIMER = 0xDAD9,
// ipc object
KNL_OBJ_TYPE_SEMAPHORE = 0x1BEE,
KNL_OBJ_TYPE_MUTEX = 0x2BEE,
KNL_OBJ_TYPE_BARRIER = 0x0BEE,
KNL_OBJ_TYPE_COMPLETION = 0x1BEE,
KNL_OBJ_TYPE_COUNTDOWNLATCH = 0x2BEE,
KNL_OBJ_TYPE_EVENT = 0x3BEE,
KNL_OBJ_TYPE_MAIL_QUEUE = 0x4BEE,
KNL_OBJ_TYPE_MESSAGE_QUEUE = 0x5BEE,
KNL_OBJ_TYPE_PRIORITY_MAIL_QUEUE = 0x6BEE,
KNL_OBJ_TYPE_PRIORITY_MESSAGE_QUEUE = 0x7BEE,
KNL_OBJ_TYPE_COUNTDOWNLATCH = 0x8BEE,
KNL_OBJ_TYPE_COMPLETION = 0x9BEE,
KNL_OBJ_TYPE_MUTEX = 0x6BEE,
KNL_OBJ_TYPE_PRIORITY_MAIL_QUEUE = 0x7BEE,
KNL_OBJ_TYPE_PRIORITY_MESSAGE_QUEUE = 0x8BEE,
KNL_OBJ_TYPE_RWLOCK = 0x9BEE,
KNL_OBJ_TYPE_SEMAPHORE = 0xABEE,
} knl_obj_type_t;
typedef enum knl_obj_alloc_type_en {
@@ -218,5 +225,7 @@ __KNL__ __STATIC_INLINE__ int knl_object_alloc_is_static(knl_obj_t *knl_obj)
#endif
__CDECLS_END
#endif /* _TOS_SYS_H_ */

View File

@@ -18,6 +18,11 @@
#ifndef _TOS_TASK_H_
#define _TOS_TASK_H_
__CDECLS_BEGIN
#define K_TASK_NAME_MAX (16u)
#define K_TASK_STK_SIZE_MIN (sizeof(cpu_context_t))
// task state is just a flag, indicating which manager list we are in.
// ready to schedule
@@ -71,7 +76,7 @@ typedef struct k_task_st {
knl_obj_t knl_obj; /**< just for verification, test whether current object is really a task. */
char *name; /**< task name */
char name[K_TASK_NAME_MAX]; /**< task name */
k_task_entry_t entry; /**< task entry */
void *arg; /**< argument for task entry */
k_task_state_t state; /**< just state */
@@ -406,7 +411,9 @@ __DEBUG__ __STATIC_INLINE__ void task_default_walker(k_task_t *task)
state_str = state_str;
tos_kprintln("tsk name: %s", task->name);
if (task->state == K_TASK_STATE_PENDTIMEOUT_SUSPENDED) {
if (tos_task_curr_task_get() == task) {
state_str = "RUNNING";
} else if (task->state == K_TASK_STATE_PENDTIMEOUT_SUSPENDED) {
state_str = "PENDTIMEOUT_SUSPENDED";
} else if (task->state == K_TASK_STATE_PEND_SUSPENDED) {
state_str = "PEND_SUSPENDED";
@@ -431,5 +438,7 @@ __DEBUG__ __STATIC_INLINE__ void task_default_walker(k_task_t *task)
tos_kprintf("\n");
}
__CDECLS_END
#endif /* _TOS_TASK_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_TICK_H_
#define _TOS_TICK_H_
__CDECLS_BEGIN
/**
* @brief Systick interrupt handler.
* systick interrupt handler.
@@ -40,5 +42,7 @@ __KNL__ void tick_list_remove(k_task_t *task);
__KNL__ k_tick_t tick_next_expires_get(void);
#endif
__CDECLS_END
#endif /* _TOS_TICK_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_TIME_H_
#define _TOS_TIME_H_
__CDECLS_BEGIN
// if you wanna pend for something forever, use TOS_TIME_FOREVER
#define TOS_TIME_FOREVER (k_tick_t)(-1)
// if you don't wanna wait when you pend nothing, use TOS_TIME_NOWAIT
@@ -106,5 +108,7 @@ __API__ k_err_t tos_sleep_ms(k_time_t millisec);
*/
__API__ k_err_t tos_sleep_hmsm(k_time_t hour, k_time_t minute, k_time_t second, k_time_t millisec);
__CDECLS_END
#endif /* _TOS_TIME_H_ */

View File

@@ -18,6 +18,8 @@
#ifndef _TOS_TIMER_H_
#define _TOS_TIMER_H_
__CDECLS_BEGIN
#if TOS_CFG_TIMER_EN > 0u
// if we just want the timer to run only once, this option should be passed to tos_timer_create.
@@ -185,5 +187,7 @@ __KNL__ k_tick_t timer_next_expires_get(void);
#endif
__CDECLS_END
#endif /* _TOS_TIMER_H_ */

111
kernel/core/tos_barrier.c Normal file
View File

@@ -0,0 +1,111 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
__API__ k_err_t tos_barrier_create(k_barrier_t *barrier, k_barrier_cnt_t count)
{
TOS_PTR_SANITY_CHECK(barrier);
if (count == 0u) {
return K_ERR_BARRIER_COUNT_INVALID;
}
barrier->count = count;
pend_object_init(&barrier->pend_obj);
TOS_OBJ_INIT(barrier, KNL_OBJ_TYPE_BARRIER);
return K_ERR_NONE;
}
__API__ k_err_t tos_barrier_destroy(k_barrier_t *barrier)
{
TOS_CPU_CPSR_ALLOC();
TOS_PTR_SANITY_CHECK(barrier);
TOS_OBJ_VERIFY(barrier, KNL_OBJ_TYPE_BARRIER);
TOS_CPU_INT_DISABLE();
if (!pend_is_nopending(&barrier->pend_obj)) {
pend_wakeup_all(&barrier->pend_obj, PEND_STATE_DESTROY);
}
pend_object_deinit(&barrier->pend_obj);
TOS_OBJ_DEINIT(barrier);
TOS_CPU_INT_ENABLE();
knl_sched();
return K_ERR_NONE;
}
__API__ k_err_t tos_barrier_pend(k_barrier_t *barrier)
{
TOS_CPU_CPSR_ALLOC();
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(barrier);
TOS_OBJ_VERIFY(barrier, KNL_OBJ_TYPE_BARRIER);
TOS_CPU_INT_DISABLE();
if (barrier->count == 0u) {
TOS_CPU_INT_ENABLE();
return K_ERR_BARRIER_OVERFLOW;
}
if (barrier->count == (k_barrier_cnt_t)1u) {
barrier->count = (k_barrier_cnt_t)0u;
if (!pend_is_nopending(&barrier->pend_obj)) {
pend_wakeup_all(&barrier->pend_obj, PEND_STATE_POST);
}
TOS_CPU_INT_ENABLE();
return K_ERR_NONE;
}
if (knl_is_sched_locked()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_SCHED_LOCKED;
}
--barrier->count;
pend_task_block(k_curr_task, &barrier->pend_obj, TOS_TIME_FOREVER);
TOS_CPU_INT_ENABLE();
knl_sched();
return pend_state2errno(k_curr_task->pend_state);
}
__API__ k_err_t tos_barrier_reset(k_barrier_t *barrier, k_barrier_cnt_t count)
{
TOS_CPU_CPSR_ALLOC();
TOS_PTR_SANITY_CHECK(barrier);
TOS_OBJ_VERIFY(barrier, KNL_OBJ_TYPE_BARRIER);
TOS_CPU_INT_DISABLE();
barrier->count = count;
TOS_CPU_INT_ENABLE();
return K_ERR_NONE;
}

143
kernel/core/tos_bitmap.c Normal file
View File

@@ -0,0 +1,143 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
__API__ k_err_t tos_bitmap_create_empty(k_bitmap_t *bitmap, k_bmtbl_t *bitmap_tbl, uint32_t bit_max)
{
int i = 0;
TOS_PTR_SANITY_CHECK(bitmap);
bitmap->bitmap_tbl = bitmap_tbl;
bitmap->bit_max = bit_max;
bitmap->bit_ndx_max = K_BITMAP_TBL_SIZE(bit_max);
for (i = 0; i < bitmap->bit_ndx_max; ++i) {
/* all bits are 0 */
bitmap_tbl[i] = 0;
}
TOS_OBJ_INIT(bitmap, KNL_OBJ_TYPE_BITMAP);
return K_ERR_NONE;
}
__API__ k_err_t tos_bitmap_create_full(k_bitmap_t *bitmap, k_bmtbl_t *bitmap_tbl, uint32_t bit_max)
{
int i = 0;
TOS_PTR_SANITY_CHECK(bitmap);
bitmap->bitmap_tbl = bitmap_tbl;
bitmap->bit_max = bit_max;
bitmap->bit_ndx_max = K_BITMAP_TBL_SIZE(bit_max);
for (i = 0; i < bitmap->bit_ndx_max; ++i) {
/* all bits are 1 */
bitmap_tbl[i] = ~0;
}
TOS_OBJ_INIT(bitmap, KNL_OBJ_TYPE_BITMAP);
return K_ERR_NONE;
}
__API__ k_err_t tos_bitmap_destroy(k_bitmap_t *bitmap)
{
TOS_PTR_SANITY_CHECK(bitmap);
TOS_OBJ_VERIFY(bitmap, KNL_OBJ_TYPE_BITMAP);
TOS_OBJ_DEINIT(bitmap);
return K_ERR_NONE;
}
__API__ k_err_t tos_bitmap_set(k_bitmap_t *bitmap, uint32_t bit)
{
TOS_PTR_SANITY_CHECK(bitmap);
TOS_OBJ_VERIFY(bitmap, KNL_OBJ_TYPE_BITMAP);
if (bit > bitmap->bit_max) {
return K_ERR_BITMAP_EXCEED;
}
bitmap->bitmap_tbl[K_BITMAP_NDX(bit)] |= K_BITMAP_BIT(bit);
return K_ERR_NONE;
}
__API__ k_err_t tos_bitmap_reset(k_bitmap_t *bitmap, uint32_t bit)
{
TOS_PTR_SANITY_CHECK(bitmap);
TOS_OBJ_VERIFY(bitmap, KNL_OBJ_TYPE_BITMAP);
if (bit > bitmap->bit_max) {
return K_ERR_BITMAP_EXCEED;
}
bitmap->bitmap_tbl[K_BITMAP_NDX(bit)] &= ~K_BITMAP_BIT(bit);
return K_ERR_NONE;
}
__API__ int tos_bitmap_is_set(k_bitmap_t *bitmap, uint32_t bit)
{
TOS_PTR_SANITY_CHECK_RC(bitmap, K_FALSE);
TOS_OBJ_VERIFY_RC(bitmap, KNL_OBJ_TYPE_BITMAP, K_FALSE);
if (bit > bitmap->bit_max) {
return K_FALSE;
}
return (bitmap->bitmap_tbl[K_BITMAP_NDX(bit)] & K_BITMAP_BIT(bit)) ? K_TRUE : K_FALSE;
}
__API__ int tos_bitmap_is_reset(k_bitmap_t *bitmap, uint32_t bit)
{
TOS_PTR_SANITY_CHECK_RC(bitmap, K_FALSE);
TOS_OBJ_VERIFY_RC(bitmap, KNL_OBJ_TYPE_BITMAP, K_FALSE);
if (bit > bitmap->bit_max) {
return K_FALSE;
}
return tos_bitmap_is_set(bitmap, bit) ? K_FALSE : K_TRUE;
}
__API__ int tos_bitmap_lsb(k_bitmap_t *bitmap)
{
int lsb = 0, i = 0;
k_bmtbl_t *bitmap_tbl;
TOS_PTR_SANITY_CHECK_RC(bitmap, -1);
TOS_OBJ_VERIFY_RC(bitmap, KNL_OBJ_TYPE_BITMAP, -1);
bitmap_tbl = bitmap->bitmap_tbl;
for (i = 0; i < bitmap->bit_ndx_max - 1; ++i) {
if (*bitmap_tbl == 0) {
lsb += K_BITMAP_SLOT_SIZE;
++bitmap_tbl;
}
}
lsb += tos_cpu_clz(*bitmap_tbl);
if (lsb > bitmap->bit_max) {
return bitmap->bit_max + 1;
}
return lsb;
}

View File

@@ -17,8 +17,6 @@
#include "tos_k.h"
#if TOS_CFG_COMPLETION_EN > 0u
__API__ k_err_t tos_completion_create(k_completion_t *completion)
{
TOS_PTR_SANITY_CHECK(completion);
@@ -57,6 +55,7 @@ __API__ k_err_t tos_completion_pend_timed(k_completion_t *completion, k_tick_t t
{
TOS_CPU_CPSR_ALLOC();
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(completion);
TOS_OBJ_VERIFY(completion, KNL_OBJ_TYPE_COMPLETION);
@@ -72,11 +71,6 @@ __API__ k_err_t tos_completion_pend_timed(k_completion_t *completion, k_tick_t t
return K_ERR_PEND_NOWAIT;
}
if (knl_is_inirq()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_IN_IRQ;
}
if (knl_is_sched_locked()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_SCHED_LOCKED;
@@ -163,5 +157,3 @@ __API__ int tos_completion_is_done(k_completion_t *completion)
return is_done;
}
#endif

View File

@@ -17,8 +17,6 @@
#include "tos_k.h"
#if TOS_CFG_COUNTDOWNLATCH_EN > 0u
__API__ k_err_t tos_countdownlatch_create(k_countdownlatch_t *countdownlatch, k_countdownlatch_cnt_t count)
{
TOS_PTR_SANITY_CHECK(countdownlatch);
@@ -57,6 +55,7 @@ __API__ k_err_t tos_countdownlatch_pend_timed(k_countdownlatch_t *countdownlatch
{
TOS_CPU_CPSR_ALLOC();
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(countdownlatch);
TOS_OBJ_VERIFY(countdownlatch, KNL_OBJ_TYPE_COUNTDOWNLATCH);
@@ -72,11 +71,6 @@ __API__ k_err_t tos_countdownlatch_pend_timed(k_countdownlatch_t *countdownlatch
return K_ERR_PEND_NOWAIT;
}
if (knl_is_inirq()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_IN_IRQ;
}
if (knl_is_sched_locked()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_SCHED_LOCKED;
@@ -138,5 +132,3 @@ __API__ k_err_t tos_countdownlatch_reset(k_countdownlatch_t *countdownlatch, k_c
return K_ERR_NONE;
}
#endif

View File

@@ -75,6 +75,7 @@ __API__ k_err_t tos_event_pend(k_event_t *event, k_event_flag_t flag_expect, k_e
{
TOS_CPU_CPSR_ALLOC();
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(event);
TOS_PTR_SANITY_CHECK(flag_match);
TOS_OBJ_VERIFY(event, KNL_OBJ_TYPE_EVENT);
@@ -102,11 +103,6 @@ __API__ k_err_t tos_event_pend(k_event_t *event, k_event_flag_t flag_expect, k_e
return K_ERR_PEND_NOWAIT;
}
if (knl_is_inirq()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_IN_IRQ;
}
if (knl_is_sched_locked()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_SCHED_LOCKED;

View File

@@ -150,6 +150,7 @@ __API__ k_err_t tos_mail_q_pend(k_mail_q_t *mail_q, void *mail_buf, size_t *mail
TOS_CPU_CPSR_ALLOC();
k_err_t err;
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(mail_q);
TOS_PTR_SANITY_CHECK(mail_buf);
TOS_OBJ_VERIFY(mail_q, KNL_OBJ_TYPE_MAIL_QUEUE);

View File

@@ -151,6 +151,7 @@ __API__ k_err_t tos_msg_q_pend(k_msg_q_t *msg_q, void **msg_ptr, k_tick_t timeou
TOS_CPU_CPSR_ALLOC();
k_err_t err;
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(msg_q);
TOS_PTR_SANITY_CHECK(msg_ptr);
TOS_OBJ_VERIFY(msg_q, KNL_OBJ_TYPE_MESSAGE_QUEUE);

View File

@@ -151,6 +151,7 @@ __API__ k_err_t tos_prio_mail_q_pend(k_prio_mail_q_t *prio_mail_q, void *mail_bu
TOS_CPU_CPSR_ALLOC();
k_err_t err;
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(prio_mail_q);
TOS_PTR_SANITY_CHECK(mail_buf);
TOS_OBJ_VERIFY(prio_mail_q, KNL_OBJ_TYPE_PRIORITY_MAIL_QUEUE);

View File

@@ -154,6 +154,7 @@ __API__ k_err_t tos_prio_msg_q_pend(k_prio_msg_q_t *prio_msg_q, void **msg_ptr,
TOS_CPU_CPSR_ALLOC();
k_err_t err;
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(prio_msg_q);
TOS_PTR_SANITY_CHECK(msg_ptr);
TOS_OBJ_VERIFY(prio_msg_q, KNL_OBJ_TYPE_PRIORITY_MESSAGE_QUEUE);

326
kernel/core/tos_rwlock.c Normal file
View File

@@ -0,0 +1,326 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
#if (TOS_CFG_SEM_EN > 0u) && (TOS_CFG_MUTEX_EN > 0u)
__API__ k_err_t tos_rwlock_create(k_rwlock_t *rwlock)
{
k_err_t err;
TOS_PTR_SANITY_CHECK(rwlock);
err = tos_sem_create(&rwlock->signal, 0u);
if (err != K_ERR_NONE) {
return err;
}
err = tos_mutex_create(&rwlock->lock);
if (err != K_ERR_NONE) {
tos_sem_destroy(&rwlock->signal);
return err;
}
rwlock->n_readers = (rw_cnt_t)0u;
rwlock->n_writers = (rw_cnt_t)0u;
rwlock->is_writting = K_FALSE;
TOS_OBJ_INIT(rwlock, KNL_OBJ_TYPE_RWLOCK);
return K_ERR_NONE;
}
__API__ k_err_t tos_rwlock_destroy(k_rwlock_t *rwlock)
{
k_err_t err0, err1;
TOS_PTR_SANITY_CHECK(rwlock);
TOS_OBJ_VERIFY(rwlock, KNL_OBJ_TYPE_RWLOCK);
err0 = tos_sem_destroy(&rwlock->signal);
err1 = tos_mutex_destroy(&rwlock->lock);
rwlock->n_readers = (rw_cnt_t)0u;
rwlock->n_writers = (rw_cnt_t)0u;
rwlock->is_writting = K_FALSE;
TOS_OBJ_DEINIT(rwlock);
if (err0 != K_ERR_NONE) {
return err0;
}
return err1;
}
__API__ k_err_t tos_rwlock_rpend_timed(k_rwlock_t *rwlock, k_tick_t timeout)
{
k_err_t err;
k_stopwatch_t stopwatch;
TOS_PTR_SANITY_CHECK(rwlock);
TOS_OBJ_VERIFY(rwlock, KNL_OBJ_TYPE_RWLOCK);
if (timeout != TOS_TIME_FOREVER) {
tos_stopwatch_create(&stopwatch);
tos_stopwatch_countdown(&stopwatch, timeout);
}
err = tos_mutex_pend_timed(&rwlock->lock, timeout);
if (err != K_ERR_NONE) {
return err;
}
if (rwlock->n_readers == (rw_cnt_t)-1) {
/* number of reader reachs limit */
return K_ERR_RWLOCK_READERS_TO_MANY;
}
if (rwlock->n_writers == 0u && !rwlock->is_writting) {
/* no writer is now holding or waiting to hold the lock */
++rwlock->n_readers;
tos_mutex_post(&rwlock->lock);
return K_ERR_NONE;
}
if (timeout != TOS_TIME_FOREVER) {
timeout = tos_stopwatch_remain(&stopwatch);
if (timeout == 0u) {
timeout = 1u;
}
}
while (rwlock->n_writers > 0u || rwlock->is_writting) {
/* util no one is writting or waiting to hold the lock */
err = tos_sem_pend(&rwlock->signal, timeout);
if (err != K_ERR_NONE) {
break;
}
if (timeout != TOS_TIME_FOREVER) {
timeout = tos_stopwatch_remain(&stopwatch);
if (timeout == 0u) {
err = K_ERR_PEND_TIMEOUT;
break;
}
}
}
tos_mutex_post(&rwlock->lock);
return err;
}
__API__ k_err_t tos_rwlock_rpend(k_rwlock_t *rwlock)
{
return tos_rwlock_rpend_timed(rwlock, TOS_TIME_FOREVER);
}
__API__ k_err_t tos_rwlock_rpend_try(k_rwlock_t *rwlock)
{
k_err_t err;
TOS_PTR_SANITY_CHECK(rwlock);
TOS_OBJ_VERIFY(rwlock, KNL_OBJ_TYPE_RWLOCK);
err = tos_mutex_pend(&rwlock->lock);
if (err != K_ERR_NONE) {
return err;
}
if (rwlock->n_readers == (rw_cnt_t)-1) {
/* number of reader reachs limit */
return K_ERR_RWLOCK_READERS_TO_MANY;
}
if (rwlock->n_writers == 0u && !rwlock->is_writting) {
/* no writer is holding or waiting to hold the lock */
++rwlock->n_readers;
tos_mutex_post(&rwlock->lock);
return K_ERR_NONE;
}
/* the rwlock is held by other writters */
tos_mutex_post(&rwlock->lock);
return K_ERR_RWLOCK_IS_WRITTING;
}
__API__ k_err_t tos_rwlock_wpend_timed(k_rwlock_t *rwlock, k_tick_t timeout)
{
k_err_t err;
k_stopwatch_t stopwatch;
TOS_PTR_SANITY_CHECK(rwlock);
TOS_OBJ_VERIFY(rwlock, KNL_OBJ_TYPE_RWLOCK);
if (timeout != TOS_TIME_FOREVER) {
tos_stopwatch_create(&stopwatch);
tos_stopwatch_countdown(&stopwatch, timeout);
}
err = tos_mutex_pend_timed(&rwlock->lock, timeout);
if (err != K_ERR_NONE) {
return err;
}
if (rwlock->n_writers == (rw_cnt_t)-1) {
/* number of waitting writer reachs limit */
return K_ERR_RWLOCK_WAITING_WRITERS_TO_MANY;
}
++rwlock->n_writers;
if (timeout != TOS_TIME_FOREVER) {
timeout = tos_stopwatch_remain(&stopwatch);
if (timeout == 0u) {
timeout = 1u;
}
}
while (rwlock->n_readers > 0u || rwlock->is_writting) {
/* util no one is writting or reading */
err = tos_sem_pend(&rwlock->signal, timeout);
if (err != K_ERR_NONE) {
break;
}
if (timeout != TOS_TIME_FOREVER) {
timeout = tos_stopwatch_remain(&stopwatch);
if (timeout == 0u) {
err = K_ERR_PEND_TIMEOUT;
break;
}
}
}
if (err == K_ERR_NONE) {
/* we hold the wlock now */
rwlock->is_writting = K_TRUE;
} else {
tos_sem_post_all(&rwlock->signal);
}
--rwlock->n_writers;
tos_mutex_post(&rwlock->lock);
return err;
}
__API__ k_err_t tos_rwlock_wpend(k_rwlock_t *rwlock)
{
return tos_rwlock_wpend_timed(rwlock, TOS_TIME_FOREVER);
}
__API__ k_err_t tos_rwlock_wpend_try(k_rwlock_t *rwlock)
{
k_err_t err;
TOS_PTR_SANITY_CHECK(rwlock);
TOS_OBJ_VERIFY(rwlock, KNL_OBJ_TYPE_RWLOCK);
err = tos_mutex_pend(&rwlock->lock);
if (err != K_ERR_NONE) {
return err;
}
if (rwlock->n_readers > 0u) {
err = K_ERR_RWLOCK_IS_READING;
} else if (rwlock->is_writting) {
err = K_ERR_RWLOCK_IS_WRITTING;
} else {
rwlock->is_writting = K_TRUE;
}
tos_mutex_post(&rwlock->lock);
return err;
}
__API__ k_err_t tos_rwlock_rpost(k_rwlock_t *rwlock)
{
k_err_t err;
TOS_PTR_SANITY_CHECK(rwlock);
TOS_OBJ_VERIFY(rwlock, KNL_OBJ_TYPE_RWLOCK);
err = tos_mutex_pend(&rwlock->lock);
if (err != K_ERR_NONE) {
return err;
}
if (rwlock->n_readers == 0u) {
err = K_ERR_RWLOCK_NOT_READING;
} else {
--rwlock->n_readers;
if (rwlock->n_readers == 0u) {
err = tos_sem_post_all(&rwlock->signal);
}
}
tos_mutex_post(&rwlock->lock);
return err;
}
__API__ k_err_t tos_rwlock_wpost(k_rwlock_t *rwlock)
{
k_err_t err;
TOS_PTR_SANITY_CHECK(rwlock);
TOS_OBJ_VERIFY(rwlock, KNL_OBJ_TYPE_RWLOCK);
err = tos_mutex_pend(&rwlock->lock);
if (err != K_ERR_NONE) {
return err;
}
if (!rwlock->is_writting) {
err = K_ERR_RWLOCK_NOT_WRITTING;
} else {
rwlock->is_writting = K_FALSE;
err = tos_sem_post_all(&rwlock->signal);
}
tos_mutex_post(&rwlock->lock);
return err;
}
__API__ k_err_t tos_rwlock_post(k_rwlock_t *rwlock)
{
k_err_t err;
TOS_PTR_SANITY_CHECK(rwlock);
TOS_OBJ_VERIFY(rwlock, KNL_OBJ_TYPE_RWLOCK);
err = tos_mutex_pend(&rwlock->lock);
if (err != K_ERR_NONE) {
return err;
}
if (rwlock->n_readers > 0u) {
--rwlock->n_readers;
if (rwlock->n_readers == 0u) {
err = tos_sem_post_all(&rwlock->signal);
}
} else if (rwlock->is_writting) {
rwlock->is_writting = K_FALSE;
err = tos_sem_post_all(&rwlock->signal);
} else {
err = K_ERR_RWLOCK_NOT_TAKEN;
}
tos_mutex_post(&rwlock->lock);
return err;
}
#endif

View File

@@ -101,6 +101,7 @@ __API__ k_err_t tos_sem_pend(k_sem_t *sem, k_tick_t timeout)
{
TOS_CPU_CPSR_ALLOC();
TOS_IN_IRQ_CHECK();
TOS_PTR_SANITY_CHECK(sem);
TOS_OBJ_VERIFY(sem, KNL_OBJ_TYPE_SEMAPHORE);
@@ -117,11 +118,6 @@ __API__ k_err_t tos_sem_pend(k_sem_t *sem, k_tick_t timeout)
return K_ERR_PEND_NOWAIT;
}
if (knl_is_inirq()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_IN_IRQ;
}
if (knl_is_sched_locked()) {
TOS_CPU_INT_ENABLE();
return K_ERR_PEND_SCHED_LOCKED;

123
kernel/core/tos_stopwatch.c Normal file
View File

@@ -0,0 +1,123 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
__API__ k_err_t tos_stopwatch_create(k_stopwatch_t *stopwatch)
{
TOS_PTR_SANITY_CHECK(stopwatch);
stopwatch->until = 0u;
TOS_OBJ_INIT(stopwatch, KNL_OBJ_TYPE_STOPWATCH);
return K_ERR_NONE;
}
__API__ k_err_t tos_stopwatch_destroy(k_stopwatch_t *stopwatch)
{
TOS_PTR_SANITY_CHECK(stopwatch);
TOS_OBJ_VERIFY(stopwatch, KNL_OBJ_TYPE_STOPWATCH);
stopwatch->until = 0u;
TOS_OBJ_DEINIT(stopwatch);
return K_ERR_NONE;
}
__API__ k_err_t tos_stopwatch_countdown(k_stopwatch_t *stopwatch, k_tick_t tick)
{
k_tick_t now;
TOS_PTR_SANITY_CHECK(stopwatch);
TOS_OBJ_VERIFY(stopwatch, KNL_OBJ_TYPE_STOPWATCH);
now = tos_systick_get();
stopwatch->until = now + tick;
return K_ERR_NONE;
}
__API__ k_err_t tos_stopwatch_countdown_ms(k_stopwatch_t *stopwatch, k_time_t millisec)
{
k_tick_t tick;
TOS_PTR_SANITY_CHECK(stopwatch);
TOS_OBJ_VERIFY(stopwatch, KNL_OBJ_TYPE_STOPWATCH);
tick = tos_millisec2tick(millisec);
return tos_stopwatch_countdown(stopwatch, tick);
}
__API__ void tos_stopwatch_delay(k_tick_t tick)
{
k_tick_t now;
now = tos_systick_get();
while ((tos_systick_get() - now) < tick) {
;
}
}
__API__ void tos_stopwatch_delay_ms(k_time_t millisec)
{
k_tick_t tick;
tick = tos_millisec2tick(millisec);
tos_stopwatch_delay(tick);
}
__API__ k_tick_t tos_stopwatch_remain(k_stopwatch_t *stopwatch)
{
k_tick_t now;
TOS_PTR_SANITY_CHECK_RC(stopwatch, (k_tick_t)-1);
TOS_OBJ_VERIFY_RC(stopwatch, KNL_OBJ_TYPE_STOPWATCH, (k_tick_t)-1);
if (tos_stopwatch_is_expired(stopwatch)) {
return (k_tick_t)0u;
}
now = tos_systick_get();
return stopwatch->until - now;
}
__API__ k_time_t tos_stopwatch_remain_ms(k_stopwatch_t *stopwatch)
{
k_tick_t now;
TOS_PTR_SANITY_CHECK_RC(stopwatch, (k_time_t)-1);
TOS_OBJ_VERIFY_RC(stopwatch, KNL_OBJ_TYPE_STOPWATCH, (k_time_t)-1);
if (tos_stopwatch_is_expired(stopwatch)) {
return (k_tick_t)0u;
}
now = tos_systick_get();
return (k_time_t)(((stopwatch->until) - now + TOS_CFG_CPU_TICK_PER_SECOND - 1) / TOS_CFG_CPU_TICK_PER_SECOND);
}
__API__ int tos_stopwatch_is_expired(k_stopwatch_t *stopwatch)
{
k_tick_t now;
TOS_PTR_SANITY_CHECK_RC(stopwatch, K_FALSE);
TOS_OBJ_VERIFY_RC(stopwatch, KNL_OBJ_TYPE_STOPWATCH, K_FALSE);
now = tos_systick_get();
return now >= stopwatch->until ? K_TRUE : K_FALSE;
}

View File

@@ -96,7 +96,12 @@ __API__ k_err_t tos_task_create(k_task_t *task,
TOS_PTR_SANITY_CHECK(entry);
TOS_PTR_SANITY_CHECK(stk_base);
if (unlikely(stk_size < sizeof(cpu_context_t))) {
if (task->knl_obj.type == KNL_OBJ_TYPE_TASK) {
/* try to re-create a task, kind of dangerous action */
return K_ERR_TASK_ALREADY_CREATED;
}
if (unlikely(stk_size < K_TASK_STK_SIZE_MIN)) {
return K_ERR_TASK_STK_SIZE_INVALID;
}
@@ -119,10 +124,10 @@ __API__ k_err_t tos_task_create(k_task_t *task,
task->sp = cpu_task_stk_init((void *)entry, arg, (void *)task_exit, stk_base, stk_size);
task->entry = entry;
task->arg = arg;
task->name = name;
task->prio = prio;
task->stk_base = stk_base;
task->stk_size = stk_size;
strncpy(task->name, name, K_TASK_NAME_MAX);
#if TOS_CFG_ROUND_ROBIN_EN > 0u
task->timeslice_reload = timeslice;
@@ -186,18 +191,6 @@ __STATIC__ k_err_t task_do_destroy(k_task_t *task)
__STATIC__ k_err_t task_destroy_static(k_task_t *task)
{
TOS_IN_IRQ_CHECK();
if (unlikely(!task)) {
task = k_curr_task;
}
TOS_OBJ_VERIFY(task, KNL_OBJ_TYPE_TASK);
if (knl_is_self(task) && knl_is_sched_locked()) {
return K_ERR_SCHED_LOCKED;
}
#if TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u
if (!knl_object_alloc_is_static(&task->knl_obj)) {
return K_ERR_OBJ_INVALID_ALLOC_TYPE;

267
osal/posix/include/errno.h Normal file
View File

@@ -0,0 +1,267 @@
/*---------------------------------------------------------------------------- * Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_ERRNO_H_
#define _POSIX_ERRNO_H_
#define ENOERR 0
#define ENOERR_STR "No error."
#define E2BIG 1
#define E2BIG_STR "Argument list too long."
#define EACCES 2
#define EACCES_STR "Permission denied."
#define EADDRINUSE 3
#define EADDRINUSE_STR "Address in use."
#define EADDRNOTAVAIL 4
#define EADDRNOTAVAIL_STR "Address not available."
#define EAFNOSUPPORT 5
#define EAFNOSUPPORT_STR "Address family not supported."
#define EAGAIN 6
#define EAGAIN_STR "Resource unavailable, try again (may be the same value as [EWOULDBLOCK])."
#define EALREADY 7
#define EALREADY_STR "Connection already in progress."
#define EBADF 8
#define EBADF_STR "Bad file descriptor."
#define EBADMSG 9
#define EBADMSG_STR "Bad message."
#define EBUSY 10
#define EBUSY_STR "Device or resource busy."
#define ECANCELED 11
#define ECANCELED_STR "Operation canceled."
#define ECHILD 12
#define ECHILD_STR "No child processes."
#define ECONNABORTED 13
#define ECONNABORTED_STR "Connection aborted."
#define ECONNREFUSED 14
#define ECONNREFUSED_STR "Connection refused."
#define ECONNRESET 15
#define ECONNRESET_STR "Connection reset."
#define EDEADLK 16
#define EDEADLK_STR "Resource deadlock would occur."
#define EDESTADDRREQ 17
#define EDESTADDRREQ_STR "Destination address required."
#define EDOM 18
#define EDOM_STR "Mathematics argument out of domain of function."
#define EDQUOT 19
#define EDQUOT_STR "Reserved."
#define EEXIST 20
#define EEXIST_STR "File exists."
#define EFAULT 21
#define EFAULT_STR "Bad address."
#define EFBIG 22
#define EFBIG_STR "File too large."
#define EHOSTUNREACH 23
#define EHOSTUNREACH_STR "Host is unreachable."
#define EIDRM 24
#define EIDRM_STR "Identifier removed."
#define EILSEQ 25
#define EILSEQ_STR "Illegal byte sequence."
#define EINPROGRESS 26
#define EINPROGRESS_STR "Operation in progress."
#define EINTR 27
#define EINTR_STR "Interrupted function."
#define EINVAL 28
#define EINVAL_STR "Invalid argument."
#define EIO 29
#define EIO_STR "I/O error."
#define EISCONN 30
#define EISCONN_STR "Socket is connected."
#define EISDIR 31
#define EISDIR_STR "Is a directory."
#define ELOOP 32
#define ELOOP_STR "Too many levels of symbolic links."
#define EMFILE 33
#define EMFILE_STR "File descriptor value too large."
#define EMLINK 34
#define EMLINK_STR "Too many links."
#define EMSGSIZE 35
#define EMSGSIZE_STR "Message too large."
#define EMULTIHOP 36
#define EMULTIHOP_STR "Reserved."
#define ENAMETOOLONG 37
#define ENAMETOOLONG_STR "Filename too long."
#define ENETDOWN 38
#define ENETDOWN_STR "Network is down."
#define ENETRESET 39
#define ENETRESET_STR "Connection aborted by network."
#define ENETUNREACH 40
#define ENETUNREACH_STR "Network unreachable."
#define ENFILE 41
#define ENFILE_STR "Too many files open in system."
#define ENOBUFS 42
#define ENOBUFS_STR "No buffer space available."
#define ENODATA 43
#define ENODATA_STR "No message is available on the STREAM head read queue. "
#define ENODEV 44
#define ENODEV_STR "No such device."
#define ENOENT 45
#define ENOENT_STR "No such file or directory."
#define ENOEXEC 46
#define ENOEXEC_STR "Executable file format error."
#define ENOLCK 47
#define ENOLCK_STR "No locks available."
#define ENOLINK 48
#define ENOLINK_STR "Reserved."
#define ENOMEM 49
#define ENOMEM_STR "Not enough space."
#define ENOMSG 50
#define ENOMSG_STR "No message of the desired type."
#define ENOPROTOOPT 51
#define ENOPROTOOPT_STR "Protocol not available."
#define ENOSPC 52
#define ENOSPC_STR "No space left on device."
#define ENOSR 53
#define ENOSR_STR "No STREAM resources."
#define ENOSTR 54
#define ENOSTR_STR "Not a STREAM."
#define ENOSYS 55
#define ENOSYS_STR "Functionality not supported."
#define ENOTCONN 56
#define ENOTCONN_STR "The socket is not connected."
#define ENOTDIR 57
#define ENOTDIR_STR "Not a directory or a symbolic link to a directory."
#define ENOTEMPTY 58
#define ENOTEMPTY_STR "Directory not empty."
#define ENOTRECOVERABLE 59
#define ENOTRECOVERABLE_STR "State not recoverable."
#define ENOTSOCK 60
#define ENOTSOCK_STR "Not a socket."
#define ENOTSUP 61
#define ENOTSUP_STR "Not supported (may be the same value as [EOPNOTSUPP]). "
#define ENOTTY 62
#define ENOTTY_STR "Inappropriate I/O control operation."
#define ENXIO 63
#define ENXIO_STR "No such device or address."
#define EOPNOTSUPP 64
#define EOPNOTSUPP_STR "Operation not supported on socket (may be the same value as [ENOTSUP])."
#define EOVERFLOW 65
#define EOVERFLOW_STR "Value too large to be stored in data type."
#define EOWNERDEAD 66
#define EOWNERDEAD_STR "Previous owner died."
#define EPERM 67
#define EPERM_STR "Operation not permitted."
#define EPIPE 68
#define EPIPE_STR "Broken pipe."
#define EPROTO 69
#define EPROTO_STR "Protocol error."
#define EPROTONOSUPPORT 70
#define EPROTONOSUPPORT_STR "Protocol not supported."
#define EPROTOTYPE 71
#define EPROTOTYPE_STR "Protocol wrong type for socket."
#define ERANGE 72
#define ERANGE_STR "Result too large."
#define EROFS 73
#define EROFS_STR "Read-only file system."
#define ESPIPE 74
#define ESPIPE_STR "Invalid seek."
#define ESRCH 75
#define ESRCH_STR "No such process."
#define ESTALE 76
#define ESTALE_STR "Reserved."
#define ETIME 77
#define ETIME_STR "Stream ioctl() timeout."
#define ETIMEDOUT 78
#define ETIMEDOUT_STR "Connection timed out."
#define ETXTBSY 79
#define ETXTBSY_STR "Text file busy."
#define EWOULDBLOCK 80
#define EWOULDBLOCK_STR "Operation would block (may be the same value as [EAGAIN])."
#define EXDEV 81
#define EXDEV_STR "Cross-device link."
#endif /* _POSIX_ERRNO_H_ */

View File

@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_MQUEUE_H_
#define _POSIX_MQUEUE_H_
#include "tos_k.h"
#include "signal.h"
#include "time.h"
__CDECLS_BEGIN
typedef int mqd_t;
struct mq_attr {
long mq_flags; /* message queue flags */
long mq_maxmsg; /* maximum number of messages */
long mq_msgsize; /* maximum message size */
long mq_curmsgs; /* number of messages currently queued */
};
#define __NOTSUPP__
__API__ int mq_close(mqd_t mqdes);
__NOTSUPP__ int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat);
__NOTSUPP__ int mq_notify(mqd_t mqdes, const struct sigevent *notification);
__API__ mqd_t mq_open(const char *name, int oflag, ...);
__API__ ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
__API__ int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
__NOTSUPP__ int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat, struct mq_attr *omqstat);
__API__ ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio, const struct timespec *abstime);
__NOTSUPP__ int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec *abstime);
__NOTSUPP__ int mq_unlink(const char *name);
__CDECLS_END
#endif /* _POSIX_MQUEUE_H_ */

View File

@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PRIVATE_MQUEUE_H_
#define _POSIX_PRIVATE_MQUEUE_H_
#include "tos_k.h"
#include "private/posix_config.h"
__CDECLS_BEGIN
#define MQUEUE_MAX (POSIX_CFG_MQUEUE_MAX)
#define MQUEUE_MSG_MAX 20
#define MQUEUE_MSG_SIZE_MAX 50
typedef struct mqueue_control_st {
mqd_t id;
k_prio_mail_q_t kprio_mail_q;
} mqueue_ctl_t;
__KNL__ int mqueue_id_add(mqd_t id, mqueue_ctl_t *mqueue_ctl);
__KNL__ mqd_t mqueue_id_alloc(void);
__KNL__ int mqueue_id_free(mqd_t id);
__KNL__ mqueue_ctl_t *mqueue_by_id(mqd_t id);
__CDECLS_END
#endif /* _POSIX_PRIVATE_TIMER_H_*/

View File

@@ -0,0 +1,48 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_CONFIG_H_
#define _POSIX_CONFIG_H_
#define POSIX_CFG_PTHREAD_THREADS_MAX 32
#define POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS 4
#define POSIX_CFG_PTHREAD_KEYS_MAX 8
#define POSIX_CFG_TIMERS_MAX 8
#define POSIX_CFG_MQUEUE_MAX 8
#define POSIX_CFG_PTHREAD_BARRIER_EN 1u
#define POSIX_CFG_PTHREAD_COND_EN 1u
#define POSIX_CFG_PTHREAD_MUTEX_EN 1u
#define POSIX_CFG_PTHREAD_RWLOCK_EN 1u
#define POSIX_CFG_PTHREAD_SPIN_EN 1u
#define POSIX_CFG_SEM_EN 1u
#define POSIX_CFG_MQUEUE_EN 1u
#define POSIX_CFG_TIMER_EN 1u
#include "private/posix_config_check.h"
#endif /* _POSIX_CONFIG_H_ */

View File

@@ -0,0 +1,61 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_CONFIG_CHECK_H_
#define _POSIX_CONFIG_CHECK_H_
#include "tos_config.h"
#include "private/posix_config_default.h"
#if (TOS_CFG_MMHEAP_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_MMHEAP_EN to use posix stuff"
#endif
#if (POSIX_CFG_PTHREAD_COND_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use pthread_cond"
#endif
#if (POSIX_CFG_PTHREAD_COND_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_cond"
#endif
#if (POSIX_CFG_PTHREAD_MUTEX_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_mutex"
#endif
#if (POSIX_CFG_PTHREAD_RWLOCK_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use pthread_rwlock"
#endif
#if (POSIX_CFG_PTHREAD_RWLOCK_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_rwlock"
#endif
#if (POSIX_CFG_SEM_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use posix sem"
#endif
#if (POSIX_CFG_MQUEUE_EN > 0u) && (TOS_CFG_PRIORITY_MAIL_QUEUE_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_PRIORITY_MAIL_QUEUE_EN to use posix mqueue"
#endif
#if (POSIX_CFG_TIMER_EN > 0u) && (TOS_CFG_TIMER_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_TIMER_EN to use posix timer"
#endif
#endif /* _POSIX_CONFIG_CHECK_H_ */

View File

@@ -0,0 +1,74 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_CONFIG_DEFAULT_H_
#define _POSIX_CONFIG_DEFAULT_H_
#ifndef POSIX_CFG_PTHREAD_THREADS_MAX
#define POSIX_CFG_PTHREAD_THREADS_MAX 32
#endif
#ifndef POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS
#define POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS 4
#endif
#ifndef POSIX_CFG_PTHREAD_KEYS_MAX
#define POSIX_CFG_PTHREAD_KEYS_MAX 8
#endif
#ifndef POSIX_CFG_TIMERS_MAX
#define POSIX_CFG_TIMERS_MAX 8
#endif
#ifndef POSIX_CFG_MQUEUE_MAX
#define POSIX_CFG_MQUEUE_MAX 8
#endif
#ifndef POSIX_CFG_PTHREAD_BARRIER_EN
#define POSIX_CFG_PTHREAD_BARRIER_EN 1u
#endif
#ifndef POSIX_CFG_PTHREAD_COND_EN
#define POSIX_CFG_PTHREAD_COND_EN 1u
#endif
#ifndef POSIX_CFG_PTHREAD_MUTEX_EN
#define POSIX_CFG_PTHREAD_MUTEX_EN 1u
#endif
#ifndef POSIX_CFG_PTHREAD_RWLOCK_EN
#define POSIX_CFG_PTHREAD_RWLOCK_EN 1u
#endif
#ifndef POSIX_CFG_PTHREAD_SPIN_EN
#define POSIX_CFG_PTHREAD_SPIN_EN 1u
#endif
#ifndef POSIX_CFG_SEM_EN
#define POSIX_CFG_SEM_EN 1u
#endif
#ifndef POSIX_CFG_MQUEUE_EN
#define POSIX_CFG_MQUEUE_EN 1u
#endif
#ifndef POSIX_CFG_TIMER_EN
#define POSIX_CFG_TIMER_EN 1u
#endif
#endif /* _POSIX_CONFIG_DEFAULT_H_ */

View File

@@ -0,0 +1,119 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PRIVATE_PTHREAD_H_
#define _POSIX_PRIVATE_PTHREAD_H_
#include "tos_k.h"
#include "private/posix_config.h"
#include "sys/types.h"
__CDECLS_BEGIN
typedef struct pthread_control_st {
uint16_t threadstate : 4;
uint16_t cancelstate : 2;
uint16_t canceltype : 2;
uint16_t cancelpending : 1;
pthread_t id;
pthread_attr_t attr;
k_task_t ktask;
k_task_t *the_ktask;
k_sem_t joinner_sem;
void *(*start_routine)(void *); /* start routine of the pthread */
void *arg; /* argument to start routine */
void *retval; /* return value of start routine */
void *stackaddr; /* memory of address */
k_slist_t cleanup_ctl_list;
void **thread_data;
} pthread_ctl_t;
typedef struct pthread_cleanup_control_st {
void (*routine)(void *); /* function to be called */
void *arg; /* argument for the routine */
k_slist_t list;
} pthread_cleanup_ctl_t;
#define PTHREAD_KEYS_MAX (POSIX_CFG_PTHREAD_KEYS_MAX)
typedef void (*key_destructor_t)(void*);
typedef struct pthread_key_control_st {
k_bmtbl_t key_bitmap_tbl[TOS_BITMAP_SIZE(PTHREAD_KEYS_MAX)];
k_bitmap_t key_bitmap;
key_destructor_t destructors[PTHREAD_KEYS_MAX];
} pthread_key_ctl_t;
#define PTHREAD_INFO_SIZE (sizeof(pthread_ctl_t))
#define PTHREAD_STK_SIZE_MIN (K_TASK_STK_SIZE_MIN + PTHREAD_INFO_SIZE)
#define PTHREAD_DEFAULT_TIMESLICE 20
#define PTHREAD_DEFAULT_STACKSIZE (2048 + PTHREAD_INFO_SIZE)
#define PTHREAD_DEFAULT_INHERIT_SCHED PTHREAD_INHERIT_SCHED
#define PTHREAD_DEFAULT_SCHEDPOLICY SCHED_OTHER
#define PTHREAD_DEFAULT_PRIORITY (TOS_CFG_TASK_PRIO_MAX / 2)
#define PTHREAD_DEFAULT_DETACH_STATE PTHREAD_CREATE_JOINABLE
#define PTHREAD_DESTRUCTOR_ITERATIONS (POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS)
#define PTHREAD_THREADS_MAX (POSIX_CFG_PTHREAD_THREADS_MAX)
__KNL__
pthread_ctl_t *pthread_ctl_self(void);
__KNL__ pthread_ctl_t *pthread_ctl_by_id(pthread_t id);
__KNL__ int pthread_id_add(pthread_t id, pthread_ctl_t *info);
__KNL__ pthread_t pthread_id_alloc(void);
__KNL__ int pthread_id_free(pthread_t id);
__KNL__ void pthread_data_clear(pthread_key_t key);
__KNL__ int pthread_key_ctl_init(void);
__KNL__ pthread_key_t pthread_key_alloc(void);
__KNL__ int pthread_key_is_alloc(pthread_key_t key);
__KNL__ int pthread_key_free(pthread_key_t key);
__KNL__ int pthread_key_destructor_register(pthread_key_t key, key_destructor_t destructor);
__KNL__ key_destructor_t pthread_key_destructor_get(pthread_key_t key);
__KNL__ int pthread_ctl_reap(int pthreads_ready2reap);
__KNL__ void pthread_lock(void);
__KNL__ void pthread_unlock(void);
__KNL__ int pthread_lock_init(void);
__KNL__ int pthread_init(void);
__CDECLS_END
#endif /* _POSIX_PRIVATE_PTHREAD_PRV_H_ */

View File

@@ -0,0 +1,36 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PRIVATE_TIME_H_
#define _POSIX_PRIVATE_TIME_H_
#include "tos_k.h"
__CDECLS_BEGIN
#define MILLISECOND_PER_SECOND 1000UL
#define MICROSECOND_PER_SECOND 1000000UL
#define NANOSECOND_PER_SECOND 1000000000UL
__KNL__ k_tick_t timespec_to_ktick(const struct timespec *tp);
__KNL__ void ktick_to_timespec(k_tick_t ktick, struct timespec *tp);
__CDECLS_END
#endif /* _POSIX_PRIVATE_TIME_H_ */

View File

@@ -0,0 +1,50 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PRIVATE_TIMER_H_
#define _POSIX_PRIVATE_TIMER_H_
#include "tos_k.h"
#include "private/posix_config.h"
#include "signal.h"
__CDECLS_BEGIN
#define TIMERS_MAX (POSIX_CFG_TIMERS_MAX)
typedef struct ptimer_control_st {
timer_t id;
k_timer_t ktimer;
void (*sigev_notify_function)(union sigval);
union sigval sigev_value;
} ptimer_ctl_t;
__KNL__ int timer_id_add(timer_t id, ptimer_ctl_t *ptimer_ctl);
__KNL__ timer_t timer_id_alloc(void);
__KNL__ int timer_id_free(timer_t id);
__KNL__ ptimer_ctl_t *timer_by_id(timer_t id);
__CDECLS_END
#endif /* _POSIX_PRIVATE_TIMER_H_*/

View File

@@ -0,0 +1,189 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PTHREAD_H_
#define _POSIX_PTHREAD_H_
#include "tos_k.h"
#include "stddef.h"
#include "limits.h"
#include "sys/types.h"
#include "sched.h"
#include "time.h"
__CDECLS_BEGIN
extern int __pthread_canceled;
#define PTHREAD_CANCELD ((void *)(&__pthread_canceled))
/* type of mutex */
#define PTHREAD_MUTEX_NORMAL 0
#define PTHREAD_MUTEX_ERRORCHECK 1
#define PTHREAD_MUTEX_RECURSIVE 2
#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
/* state of the thread */
#define PTHREAD_STATE_DETACHED 1 /* The thread is running but detached */
#define PTHREAD_STATE_RUNNING 2 /* The thread is running and will wait to join when it exits */
#define PTHREAD_STATE_JOIN 3 /* The thread has exited and is waiting to be joined */
#define PTHREAD_STATE_EXITED 4 /* The thread has exited and is ready to be reaped */
/* cancelability state */
#define PTHREAD_CANCEL_ENABLE 1
#define PTHREAD_CANCEL_DISABLE 2
/* cancelability type */
#define PTHREAD_CANCEL_ASYNCHRONOUS 1
#define PTHREAD_CANCEL_DEFERRED 2
/* values for detachstate*/
#define PTHREAD_CREATE_JOINABLE 1
#define PTHREAD_CREATE_DETACHED 2
/* values for inheritsched */
#define PTHREAD_INHERIT_SCHED 1
#define PTHREAD_EXPLICIT_SCHED 2
#define PTHREAD_ONCE_INIT 0
#define PTHREAD_COND_INITIALIZER
#define PTHREAD_MUTEX_INITIALIZER
#define PTHREAD_RWLOCK_INITIALIZER
#define __NOTSUPP__
__NOTSUPP__ int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void));
__API__ int pthread_attr_destroy(pthread_attr_t *attr);
__API__ int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
__NOTSUPP__ int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize);
__API__ int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);
__API__ int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param);
__API__ int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);
__NOTSUPP__ int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope);
__API__ int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize);
__API__ int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
__API__ int pthread_attr_init(pthread_attr_t *attr);
__API__ int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
__NOTSUPP__ int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
__API__ int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
__API__ int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param);
__API__ int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
__NOTSUPP__ int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);
__API__ int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize);
__API__ int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
__API__ int pthread_barrier_destroy(pthread_barrier_t *barrier);
__API__ int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count);
__API__ int pthread_barrier_wait(pthread_barrier_t *barrier);
__NOTSUPP__ int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);
__NOTSUPP__ int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared);
__NOTSUPP__ int pthread_barrierattr_init(pthread_barrierattr_t *attr);
__NOTSUPP__ int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int pshared);
__API__ int pthread_cancel(pthread_t thread);
__API__ int pthread_cond_broadcast(pthread_cond_t *cond);
__API__ int pthread_cond_destroy(pthread_cond_t *cond);
__API__ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
__API__ int pthread_cond_signal(pthread_cond_t *cond);
__API__ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime);
__API__ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
__NOTSUPP__ int pthread_condattr_destroy(pthread_condattr_t *attr);
__NOTSUPP__ int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id);
__NOTSUPP__ int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
__NOTSUPP__ int pthread_condattr_init(pthread_condattr_t *attr);
__NOTSUPP__ int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id);
__NOTSUPP__ int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
__API__ int pthread_create(pthread_t *pthread, const pthread_attr_t *attr, void *(*entry)(void*), void *arg);
__API__ int pthread_detach(pthread_t thread);
__API__ int pthread_equal(pthread_t t1, pthread_t t2);
__API__ void pthread_exit(void *value_ptr);
__NOTSUPP__ int pthread_getconcurrency(void);
__NOTSUPP__ int pthread_getcpuclockid(pthread_t thread_id, clockid_t *clock_id);
__API__ int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param);
__API__ void *pthread_getspecific(pthread_key_t key);
__API__ int pthread_join(pthread_t thread, void **value_ptr);
__API__ int pthread_key_create(pthread_key_t *, void (*)(void*));
__API__ int pthread_key_delete(pthread_key_t);
__NOTSUPP__ int pthread_mutex_consistent(pthread_mutex_t *mutex);
__API__ int pthread_mutex_destroy(pthread_mutex_t *mutex);
__NOTSUPP__ int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, int *prioceiling);
__API__ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
__API__ int pthread_mutex_lock(pthread_mutex_t *mutex);
__NOTSUPP__ int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling);
__API__ int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime);
__API__ int pthread_mutex_trylock(pthread_mutex_t *mutex);
__API__ int pthread_mutex_unlock(pthread_mutex_t *mutex);
__API__ int pthread_mutexattr_destroy(pthread_mutexattr_t *);
__NOTSUPP__ int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *mutex, int *prioceiling);
__NOTSUPP__ int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *mutex, int *protocol);
__NOTSUPP__ int pthread_mutexattr_getpshared(const pthread_mutexattr_t *mutex, int *pshared);
__NOTSUPP__ int pthread_mutexattr_getrobust(const pthread_mutexattr_t *mutex, int *robust);
__API__ int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
__API__ int pthread_mutexattr_init(pthread_mutexattr_t *attr);
__NOTSUPP__ int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mutex, int prioceiling);
__NOTSUPP__ int pthread_mutexattr_setprotocol(pthread_mutexattr_t *mutex, int protocol);
__NOTSUPP__ int pthread_mutexattr_setpshared(pthread_mutexattr_t *mutex, int pshared);
__NOTSUPP__ int pthread_mutexattr_setrobust(pthread_mutexattr_t *mutex, int robust);
__API__ int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
__API__ int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
__API__ int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr);
__API__ int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
__API__ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
__API__ int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
__NOTSUPP__ int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
__NOTSUPP__ int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared);
__NOTSUPP__ int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
__NOTSUPP__ int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared);
__API__ pthread_t pthread_self(void);
__API__ int pthread_setcancelstate(int state, int *oldstate);
__API__ int pthread_setcanceltype(int type, int *oldtype);
__NOTSUPP__ int pthread_setconcurrency(int new_level);
__API__ int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param);
__API__ int pthread_setschedprio(pthread_t, int);
__API__ int pthread_setspecific(pthread_key_t key, const void *value);
__API__ int pthread_spin_destroy(pthread_spinlock_t *lock);
__API__ int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
__API__ int pthread_spin_lock(pthread_spinlock_t *lock);
__API__ int pthread_spin_trylock(pthread_spinlock_t *lock);
__API__ int pthread_spin_unlock(pthread_spinlock_t *lock);
__API__ void pthread_testcancel(void);
__API__ void pthread_cleanup_pop(int execute);
__API__ void pthread_cleanup_push(void (*routine)(void*), void *arg);
__CDECLS_END
#endif /* _POSIX_PTHREAD_H_ */

View File

@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SCHED_H_
#define _POSIX_SCHED_H_
#include "tos_k.h"
#include "sys/types.h"
#include "time.h"
__CDECLS_BEGIN
/* Scheduling Psolicies, values for schedpolicy */
#define SCHED_FIFO 0 /* First in-first out (FIFO) scheduling policy. */
#define SCHED_RR 1 /* Round robin scheduling policy. */
#define SCHED_OTHER 2 /* Another scheduling policy. */
#define __NOTSUPP__
__API__ int sched_get_priority_max(int policy);
__API__ int sched_get_priority_min(int policy);
__API__ int sched_getparam(pid_t pid, struct sched_param *param);
__NOTSUPP__ int sched_getscheduler(pid_t pid);
__API__ int sched_rr_get_interval(pid_t pid, struct timespec *interval);
__API__ int sched_setparam(pid_t pid, const struct sched_param *param);
__NOTSUPP__ int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param);
__API__ int sched_yield(void);
__CDECLS_END
#endif /* _POSIX_SCHED_H_ */

View File

@@ -0,0 +1,45 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SEMAPHORE_H_
#define _POSIX_SEMAPHORE_H_
#include "tos_k.h"
#include "time.h"
__CDECLS_BEGIN
typedef k_sem_t sem_t;
#define __NOTSUPP__
__NOTSUPP__ int sem_close(sem_t *sem);
__API__ int sem_destroy(sem_t *sem);
__API__ int sem_getvalue(sem_t *sem, int *sval);
__API__ int sem_init(sem_t *sem, int pshared, unsigned value);
__NOTSUPP__ sem_t *sem_open(const char *name, int oflag, ...);
__API__ int sem_post(sem_t *sem);
__API__ int sem_timedwait(sem_t *sem, const struct timespec *abstime);
__API__ int sem_trywait(sem_t *sem);
__NOTSUPP__ int sem_unlink(const char *name);
__API__ int sem_wait(sem_t *sem);
__CDECLS_END
#endif /* _POSIX_SEMAPHORE_H_ */

View File

@@ -0,0 +1,37 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SIGNAL_H_
#define _POSIX_SIGNAL_H_
#include "sys/types.h"
union sigval {
int sival_int; /* integer signal value */
void *sival_ptr; /* pointer signal value */
};
struct sigevent {
int sigev_notify; /* notification type */
int sigev_signo; /* signal number */
union sigval sigev_value; /* signal value */
void (*sigev_notify_function)(union sigval); /* notification function */
pthread_attr_t *sigev_notify_attributes; /* notification attributes */
};
#endif /* _POSIX_SIGNAL_H_ */

View File

@@ -0,0 +1,62 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SYS_TIME_H_
#define _POSIX_SYS_TIME_H_
#include "sys/types.h"
#include "time.h"
__CDECLS_BEGIN
struct timeval {
long tv_sec;
long tv_usec;
};
struct itimerval {
struct timeval it_interval; /* timer interval */
struct timeval it_value; /* current value */
};
#define TIMEVAL_TO_TIMESPEC(tv, ts) { \
(ts)->tv_sec = (tv)->tv_sec; \
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
}
#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
(tv)->tv_sec = (ts)->tv_sec; \
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
}
struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};
__API__ int getitimer(int which, struct itimerval *value);
__API__ int gettimeofday(struct timeval *tp, void *tzp);
__API__ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
#if 0
int select(int, fd_set *restrict, fd_set *restrict, fd_set *restrict, struct timeval *restrict);
#endif
__API__ int utimes(const char *path, const struct timeval [2]);
__CDECLS_END
#endif /* _POSIX_SYS_TIME_H_ */

View File

@@ -0,0 +1,131 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SYS_TYPES_H_
#define _POSIX_SYS_TYPES_H_
#include "stddef.h"
#include "stdint.h"
typedef uint32_t blkcnt_t; /* Used for file block counts. */
typedef size_t blksize_t; /* Used for block sizes. */
typedef uint64_t clock_t; /* Used for system times in clock ticks or CLOCKS_PER_SEC; see <time.h>. */
typedef uint32_t clockid_t; /* Used for clock ID type in the clock and timer functions. */
typedef uint32_t dev_t; /* Used for device IDs. */
typedef uint32_t fsblkcnt_t; /* Used for file system block counts. */
typedef uint32_t fsfilcnt_t; /* Used for file system file counts. */
typedef uint32_t gid_t; /* Used for group IDs. */
typedef uint32_t id_t; /* Used as a general identifier; can be used to contain at least a pid_t, uid_t, or gid_t. */
typedef uint32_t ino_t; /* Used for file serial numbers. */
typedef uint32_t key_t; /* Used for XSI interprocess communication. */
typedef uint32_t mode_t; /* Used for some file attributes. */
typedef uint32_t nlink_t; /* Used for link counts. */
typedef uint32_t off_t; /* Used for file sizes. */
typedef int pid_t; /* Used for process IDs and process group IDs. */
typedef uint32_t uid_t; /* Used for user IDs. */
#if 0 /* we donnot typedef a size_t or ssize_t here, use what is supplied by stddef.h */
size_t /* Used for sizes of objects. */
ssize_t /* Used for a count of bytes or an error indication. */
#endif
typedef int ssize_t;
typedef uint32_t suseconds_t; /* Used for time in microseconds. */
typedef uint32_t time_t; /* Used for time in seconds. */
struct sched_param {
int sched_priority; /* Process or thread execution scheduling priority. */
};
/* Used to identify a thread attribute object. */
typedef struct pthread_attr_st {
uint32_t detachstate : 2;
uint32_t inheritsched : 2; /* inherit parent priority/policy? */
uint32_t schedpolicy : 2; /* pthread scheduler policy */
uint32_t stackaddr_valid : 1;
uint32_t stacksize_valid : 1;
struct sched_param schedparam;
void *stackaddr; /* address of memory to be used as stack */
size_t stacksize; /* size of the stack allocated for the pthread */
} pthread_attr_t;
/* Used to identify a barrier. */
typedef k_barrier_t pthread_barrier_t;
/* Used to define a barrier attributes object. */
typedef uint32_t pthread_barrierattr_t;
/* Used for condition variables. */
typedef k_sem_t pthread_cond_t;
/* Used to identify a condition attribute object. */
typedef int pthread_condattr_t;
/* Used for thread-specific data keys. */
typedef int pthread_key_t;
/* Used to identify a mutex attribute object. */
typedef struct pthread_mutexattr_st {
uint8_t type : 4;
uint8_t reserved : 4;
} pthread_mutexattr_t;
/* Used for mutexes. */
typedef struct pthread_mutex_st {
k_mutex_t kmutex;
pthread_mutexattr_t attr;
} pthread_mutex_t;
/* Used for dynamic package initialization. */
typedef int pthread_once_t;
/* Used for read-write locks. */
typedef k_rwlock_t pthread_rwlock_t;
/* Used for read-write lock attributes. */
typedef int pthread_rwlockattr_t;
/* Used to identify a spin lock. */
typedef struct pthread_spinlock_st {
uint8_t is_destroyed : 1;
uint8_t is_locked : 1;
} pthread_spinlock_t;
/* Used to identify a thread. */
typedef pid_t pthread_t;
/* Used for timer ID returned by timer_create(). */
typedef int timer_t;
/* Used to identify a trace stream attributes object */
typedef int trace_attr_t;
/* Used to identify a trace event type. */
typedef int trace_event_id_t;
/* Used to identify a trace event type set. */
typedef int trace_event_set_t;
/* Used to identify a trace stream. */
typedef int trace_id_t;
#endif /* _POSIX_SYS_TYPES_H_ */

87
osal/posix/include/time.h Normal file
View File

@@ -0,0 +1,87 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_TIME_H_
#define _POSIX_TIME_H_
#include "tos_k.h"
#include "sys/types.h"
#include "signal.h"
__CDECLS_BEGIN
struct tm {
int tm_sec; /* Seconds [0,60] */
int tm_min; /* Minutes [0,59] */
int tm_hour; /* Hour [0,23] */
int tm_mday; /* Day of month [1,31] */
int tm_mon; /* Month of year [0,11] */
int tm_year; /* Years since 1900 */
int tm_wday; /* Day of week [0,6] (Sunday =0) */
int tm_yday; /* Day of year [0,365] */
};
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
struct itimerspec {
struct timespec it_interval; /* timer period */
struct timespec it_value; /* timer expiration */
};
#define CLOCK_REALTIME 0
#define __NOTSUPP__
__API__ char *asctime(const struct tm *timeptr);
__API__ char *asctime_r(const struct tm *asctime_r, char *buf);
__API__ clock_t clock(void);
__API__ int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
__API__ int clock_getres(clockid_t clock_id, struct timespec *res);
__API__ int clock_gettime(clockid_t clock_id, struct timespec *tp);
__API__ int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp);
__API__ int clock_settime(clockid_t clock_id, const struct timespec *tp);
__API__ char *ctime(const time_t *clock);
__API__ char *ctime_r(const time_t *clock, char *buf);
__API__ double difftime(time_t time1, time_t time0);
__API__ struct tm *getdate(const char *string);
__API__ struct tm *gmtime(const time_t *timer);
__API__ struct tm *gmtime_r(const time_t *timer, struct tm *result);
__API__ struct tm *localtime(const time_t *timer);
__API__ struct tm *localtime_r(const time_t *timer, struct tm *result);
__API__ time_t mktime(struct tm *timeptr);
__API__ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
__API__ size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr);
#if 0
__API__ size_t strftime_l(char *s, size_t maxsize, const char *format, const struct tm *timeptr, locale_t locale);
#endif
__API__ char *strptime(const char *buf, const char *format, struct tm *tm);
__API__ time_t time(time_t *tloc);
__API__ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid);
__API__ int timer_delete(timer_t timerid);
__NOTSUPP__ int timer_getoverrun(timer_t timerid);
__API__ int timer_gettime(timer_t timerid, struct itimerspec *value);
__API__ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue);
__API__ void tzset(void);
__CDECLS_END
#endif /* _POSIX_TIME_H_ */

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _TOS_POSIX_H_
#define _TOS_POSIX_H_
#include "tos_k.h"
__CDECLS_BEGIN
__API__ int tos_posix_init(void);
__CDECLS_END
#endif /* _TOS_POSIX_H_ */

173
osal/posix/mqueue.c Normal file
View File

@@ -0,0 +1,173 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "private/posix_config.h"
#include "errno.h"
#include "mqueue.h"
#include "private/time.h"
#include "private/mqueue.h"
#if POSIX_CFG_MQUEUE_EN > 0u
__API__ int mq_close(mqd_t mqdes)
{
k_err_t kerr;
mqueue_ctl_t *the_ctl;
the_ctl = mqueue_by_id(mqdes);
if (!the_ctl) {
return EINVAL;
}
kerr = tos_prio_mail_q_destroy_dyn((k_prio_mail_q_t *)&the_ctl->kprio_mail_q);
mqueue_id_free(mqdes);
tos_mmheap_free(the_ctl);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
__NOTSUPP__ int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat)
{
return EOPNOTSUPP;
}
__NOTSUPP__ int mq_notify(mqd_t mqdes, const struct sigevent *notification)
{
return EOPNOTSUPP;
}
__API__ mqd_t mq_open(const char *name, int oflag, ...)
{
mqd_t id;
k_err_t kerr;
mode_t mode;
va_list arg;
mqueue_ctl_t *the_ctl;
struct mq_attr *attr;
id = mqueue_id_alloc();
if (id == -1) {
return -1;
}
va_start(arg, oflag);
mode = va_arg(arg, mode_t);
mode = mode; /* make compiler happy */
attr = va_arg(arg, struct mq_attr *);
va_end(arg);
if (attr->mq_maxmsg > MQUEUE_MSG_MAX ||
attr->mq_msgsize > MQUEUE_MSG_SIZE_MAX) {
return EINVAL;
}
the_ctl = (mqueue_ctl_t *)tos_mmheap_alloc(sizeof(mqueue_ctl_t));
if (!the_ctl) {
return -1;
}
kerr = tos_prio_mail_q_create_dyn((k_prio_mail_q_t *)&the_ctl->kprio_mail_q,
attr->mq_maxmsg, attr->mq_msgsize);
if (kerr != K_ERR_NONE) {
tos_mmheap_free(the_ctl);
return -1;
}
the_ctl->id = id;
mqueue_id_add(id, the_ctl);
return id;
}
__API__ ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio)
{
k_err_t kerr;
mqueue_ctl_t *the_ctl;
the_ctl = mqueue_by_id(mqdes);
if (!the_ctl) {
return EINVAL;
}
kerr = tos_prio_mail_q_pend((k_prio_mail_q_t *)&the_ctl->kprio_mail_q, msg_ptr, &msg_len, TOS_TIME_FOREVER);
if (kerr == K_ERR_NONE) {
return 0;
}
return msg_len;
}
__API__ int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
{
k_err_t kerr;
mqueue_ctl_t *the_ctl;
the_ctl = mqueue_by_id(mqdes);
if (!the_ctl) {
return EINVAL;
}
kerr = tos_prio_mail_q_post((k_prio_mail_q_t *)&the_ctl->kprio_mail_q, (void *)msg_ptr, msg_len, msg_prio);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
__NOTSUPP__ int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat, struct mq_attr *omqstat)
{
return EOPNOTSUPP;
}
__API__ ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio, const struct timespec *abstime)
{
k_err_t kerr;
k_tick_t ktick;
mqueue_ctl_t *the_ctl;
the_ctl = mqueue_by_id(mqdes);
if (!the_ctl) {
return EINVAL;
}
ktick = timespec_to_ktick(abstime);
kerr = tos_prio_mail_q_pend((k_prio_mail_q_t *)&the_ctl->kprio_mail_q, (void *)msg_ptr, &msg_len, ktick);
if (kerr == K_ERR_NONE) {
return 0;
}
return msg_len;
}
__NOTSUPP__ int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec *abstime)
{
return EOPNOTSUPP;
}
__NOTSUPP__ int mq_unlink(const char *name)
{
return EOPNOTSUPP;
}
#endif /* POSIX_CFG_MQUEUE_EN */

98
osal/posix/mqueue_prv.c Normal file
View File

@@ -0,0 +1,98 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
#include "mqueue.h"
#include "private/mqueue.h"
__STATIC__ mqueue_ctl_t *mqueue_ctl_table[MQUEUE_MAX] = { 0 };
__KNL__ int mqueue_id_add(mqd_t id, mqueue_ctl_t *mqueue_ctl)
{
TOS_CPU_CPSR_ALLOC();
if (id < 0 ||
id >= TOS_COUNT_OF(mqueue_ctl_table) ||
mqueue_ctl_table[id]) {
return -1;
}
TOS_CPU_INT_DISABLE();
mqueue_ctl_table[id] = mqueue_ctl;
TOS_CPU_INT_ENABLE();
return 0;
}
__KNL__ mqd_t mqueue_id_alloc(void)
{
TOS_CPU_CPSR_ALLOC();
int i = 0;
TOS_CPU_INT_DISABLE();
for (i = 0; i < TOS_COUNT_OF(mqueue_ctl_table); ++i) {
if (!mqueue_ctl_table[i]) {
TOS_CPU_INT_ENABLE();
return (mqd_t)i;
}
}
TOS_CPU_INT_ENABLE();
return -1;
}
__KNL__ int mqueue_id_free(mqd_t id)
{
TOS_CPU_CPSR_ALLOC();
if (id < 0 ||
id >= TOS_COUNT_OF(mqueue_ctl_table) ||
!mqueue_ctl_table[id]) {
return -1;
}
TOS_CPU_INT_DISABLE();
mqueue_ctl_table[id] = K_NULL;
TOS_CPU_INT_ENABLE();
return 0;
}
__KNL__ mqueue_ctl_t *mqueue_by_id(mqd_t id)
{
mqueue_ctl_t *the_ctl;
the_ctl = mqueue_ctl_table[id];
if (!the_ctl) {
return K_NULL;
}
if (the_ctl->id != id) {
return K_NULL;
}
return the_ctl;
}

1605
osal/posix/pthread.c Normal file

File diff suppressed because it is too large Load Diff

302
osal/posix/pthread_prv.c Normal file
View File

@@ -0,0 +1,302 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
#include "pthread.h"
#include "private/pthread.h"
__STATIC__ k_mutex_t pthread_mutex;
__STATIC__ pthread_ctl_t *thread_ctl_table[PTHREAD_THREADS_MAX] = { 0 };
__STATIC__ pthread_key_ctl_t pthread_key_ctl;
__KNL__ pthread_ctl_t *pthread_ctl_self(void)
{
TOS_CPU_CPSR_ALLOC();
int i = 0;
k_task_t *self_task;
pthread_ctl_t *the_info;
self_task = tos_task_curr_task_get();
TOS_CPU_INT_DISABLE();
for (i = 0; i < TOS_COUNT_OF(thread_ctl_table); ++i) {
the_info = thread_ctl_table[i];
if (the_info && the_info->the_ktask == self_task) {
TOS_CPU_INT_ENABLE();
return the_info;
}
}
TOS_CPU_INT_ENABLE();
return K_NULL;
}
__KNL__ pthread_ctl_t *pthread_ctl_by_id(pthread_t id)
{
pthread_ctl_t *the_ctl;
the_ctl = thread_ctl_table[id];
if (!the_ctl) {
return K_NULL;
}
if (the_ctl->id != id) {
return K_NULL;
}
if (the_ctl->threadstate == PTHREAD_STATE_EXITED) {
return K_NULL;
}
return the_ctl;
}
__KNL__ int pthread_id_add(pthread_t id, pthread_ctl_t *info)
{
TOS_CPU_CPSR_ALLOC();
if (id < 0 ||
id >= TOS_COUNT_OF(thread_ctl_table) ||
thread_ctl_table[id]) {
return -1;
}
TOS_CPU_INT_DISABLE();
thread_ctl_table[id] = info;
TOS_CPU_INT_ENABLE();
return 0;
}
__KNL__ pthread_t pthread_id_alloc(void)
{
TOS_CPU_CPSR_ALLOC();
int i = 0;
TOS_CPU_INT_DISABLE();
for (i = 0; i < TOS_COUNT_OF(thread_ctl_table); ++i) {
if (!thread_ctl_table[i]) {
TOS_CPU_INT_ENABLE();
return (pthread_t)i;
}
}
TOS_CPU_INT_ENABLE();
return -1;
}
__KNL__ int pthread_id_free(pthread_t id)
{
TOS_CPU_CPSR_ALLOC();
if (id < 0 ||
id >= TOS_COUNT_OF(thread_ctl_table) ||
!thread_ctl_table[id]) {
return -1;
}
TOS_CPU_INT_DISABLE();
thread_ctl_table[id] = K_NULL;
TOS_CPU_INT_ENABLE();
return 0;
}
__KNL__ void pthread_data_clear(pthread_key_t key)
{
int i = 0;
pthread_ctl_t *the_ctl;
for (i = 0; i < TOS_COUNT_OF(thread_ctl_table); ++i) {
the_ctl = thread_ctl_table[i];
if (the_ctl && the_ctl->thread_data) {
the_ctl->thread_data[key] = K_NULL;
}
}
}
__KNL__ int pthread_key_ctl_init(void)
{
int i = 0;
if (tos_bitmap_create_full(&pthread_key_ctl.key_bitmap,
pthread_key_ctl.key_bitmap_tbl,
PTHREAD_KEYS_MAX) != K_ERR_NONE) {
return -1;
}
for (i = 0; i < PTHREAD_KEYS_MAX; ++i) {
pthread_key_ctl.destructors[i] = K_NULL;
}
return 0;
}
__KNL__ pthread_key_t pthread_key_alloc(void)
{
int lsb;
lsb = tos_bitmap_lsb(&pthread_key_ctl.key_bitmap);
if (lsb > PTHREAD_KEYS_MAX) {
return -1;
}
tos_bitmap_reset(&pthread_key_ctl.key_bitmap, lsb);
return (pthread_key_t)lsb;
}
__KNL__ int pthread_key_is_alloc(pthread_key_t key)
{
if (key > PTHREAD_KEYS_MAX || key < 0) {
return K_FALSE;
}
return tos_bitmap_is_reset(&pthread_key_ctl.key_bitmap, key);
}
__KNL__ int pthread_key_free(pthread_key_t key)
{
if (key > PTHREAD_KEYS_MAX || key < 0) {
return -1;
}
if (tos_bitmap_is_set(&pthread_key_ctl.key_bitmap, key)) {
/* what we created is a full bitmap, if the bit is set means it is not used */
return -1;
}
/* make it avaliable again */
tos_bitmap_set(&pthread_key_ctl.key_bitmap, key);
return 0;
}
__KNL__ int pthread_key_destructor_register(pthread_key_t key, key_destructor_t destructor)
{
if (key > PTHREAD_KEYS_MAX || key < 0) {
return -1;
}
if (tos_bitmap_is_set(&pthread_key_ctl.key_bitmap, key)) {
/* what we created is a full bitmap, if the bit is set means it is not used */
return -1;
}
pthread_key_ctl.destructors[key] = destructor;
return 0;
}
__STATIC__ int pthread_key_destructor_is_register(pthread_key_t key)
{
if (key > PTHREAD_KEYS_MAX || key < 0) {
return K_FALSE;
}
if (tos_bitmap_is_set(&pthread_key_ctl.key_bitmap, key)) {
/* what we created is a full bitmap, if the bit is set means it is not used */
return K_FALSE;
}
return pthread_key_ctl.destructors[key] != K_NULL;
}
__KNL__ key_destructor_t pthread_key_destructor_get(pthread_key_t key)
{
if (!pthread_key_destructor_is_register(key)) {
return K_NULL;
}
return pthread_key_ctl.destructors[key];
}
__KNL__ int pthread_ctl_reap(int pthreads_ready2reap)
{
int i = 0;
pthread_ctl_t *the_ctl;
int pthreads_reaped = 0;
if (pthreads_ready2reap == 0) {
return 0;
}
for (i = 0; pthreads_ready2reap && i < TOS_COUNT_OF(thread_ctl_table); ++i) {
the_ctl = thread_ctl_table[i];
if (!the_ctl || the_ctl->threadstate != PTHREAD_STATE_EXITED) {
continue;
}
pthread_id_free((pthread_t)i);
tos_sem_destroy(&the_ctl->joinner_sem);
if (the_ctl->stackaddr) {
/* the_ctl is just on this stack */
tos_mmheap_free(the_ctl->stackaddr);
}
--pthreads_ready2reap;
++pthreads_reaped;
}
return pthreads_reaped;
}
__KNL__ void pthread_lock(void)
{
tos_mutex_pend(&pthread_mutex);
}
__KNL__ void pthread_unlock(void)
{
tos_mutex_post(&pthread_mutex);
}
__KNL__ int pthread_lock_init(void)
{
if (tos_mutex_create(&pthread_mutex) != K_ERR_NONE) {
return -1;
}
return 0;
}
__KNL__ int pthread_init(void)
{
if (pthread_lock_init() != 0) {
return -1;
}
if (pthread_key_ctl_init() != 0) {
return -1;
}
return 0;
}

105
osal/posix/sched.c Normal file
View File

@@ -0,0 +1,105 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
#include "errno.h"
#include "sched.h"
#include "private/pthread.h"
#include "private/time.h"
__API__ int sched_get_priority_max(int policy)
{
return K_TASK_PRIO_IDLE - 1;
}
__API__ int sched_get_priority_min(int policy)
{
return 0;
}
__API__ int sched_getparam(pid_t pid, struct sched_param *param)
{
pthread_ctl_t *the_ctl;
TOS_PTR_SANITY_CHECK_RC(param, EINVAL);
the_ctl = pthread_ctl_by_id(pid);
if (!the_ctl) {
return EINVAL;
}
*param = the_ctl->attr.schedparam;
return 0;
}
__NOTSUPP__ int sched_getscheduler(pid_t pid)
{
return EOPNOTSUPP;
}
__API__ int sched_rr_get_interval(pid_t pid, struct timespec *interval)
{
#if TOS_CFG_ROUND_ROBIN_EN > 0u
k_tick_t ktick;
pthread_ctl_t *the_ctl;
TOS_PTR_SANITY_CHECK_RC(interval, EINVAL);
the_ctl = pthread_ctl_by_id(pid);
if (!the_ctl) {
return EINVAL;
}
ktick = the_ctl->the_ktask->timeslice_reload;
ktick_to_timespec(ktick, interval);
return 0;
#else
return EOPNOTSUPP;
#endif
}
__API__ int sched_setparam(pid_t pid, const struct sched_param *param)
{
pthread_ctl_t *the_ctl;
TOS_PTR_SANITY_CHECK_RC(param, EINVAL);
the_ctl = pthread_ctl_by_id(pid);
if (!the_ctl) {
return EINVAL;
}
the_ctl->attr.schedparam = *param;
return 0;
}
__NOTSUPP__ int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param)
{
return EOPNOTSUPP;
}
__API__ int sched_yield(void)
{
tos_task_yield();
return 0;
}

137
osal/posix/semaphore.c Normal file
View File

@@ -0,0 +1,137 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "private/posix_config.h"
#include "errno.h"
#include "semaphore.h"
#include "private/time.h"
#if POSIX_CFG_SEM_EN > 0u
__NOTSUPP__ int sem_close(sem_t *sem)
{
return EOPNOTSUPP;
}
__API__ int sem_destroy(sem_t *sem)
{
k_err_t kerr;
TOS_PTR_SANITY_CHECK_RC(sem, EINVAL);
kerr = tos_sem_destroy((k_sem_t *)sem);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
__API__ int sem_getvalue(sem_t *sem, int *sval)
{
TOS_PTR_SANITY_CHECK_RC(sem, EINVAL);
TOS_PTR_SANITY_CHECK_RC(sval, EINVAL);
*sval = ((k_sem_t *)sem)->count;
return 0;
}
__API__ int sem_init(sem_t *sem, int pshared, unsigned value)
{
k_err_t kerr;
TOS_PTR_SANITY_CHECK_RC(sem, EINVAL);
kerr = tos_sem_create((k_sem_t *)sem, value);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
__NOTSUPP__ sem_t *sem_open(const char *name, int oflag, ...)
{
return K_NULL;
}
__API__ int sem_post(sem_t *sem)
{
k_err_t kerr;
TOS_PTR_SANITY_CHECK_RC(sem, EINVAL);
kerr = tos_sem_post((k_sem_t *)sem);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
__API__ int sem_timedwait(sem_t *sem, const struct timespec *abstime)
{
k_err_t kerr;
k_tick_t ktick;
TOS_PTR_SANITY_CHECK_RC(sem, EINVAL);
ktick = timespec_to_ktick(abstime);
kerr = tos_sem_pend((k_sem_t *)sem, ktick);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
__API__ int sem_trywait(sem_t *sem)
{
k_err_t kerr;
TOS_PTR_SANITY_CHECK_RC(sem, EINVAL);
kerr = tos_sem_pend((k_sem_t *)sem, TOS_TIME_NOWAIT);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
__NOTSUPP__ int sem_unlink(const char *name)
{
return EOPNOTSUPP;
}
__API__ int sem_wait(sem_t *sem)
{
k_err_t kerr;
TOS_PTR_SANITY_CHECK_RC(sem, EINVAL);
kerr = tos_sem_pend((k_sem_t *)sem, TOS_TIME_FOREVER);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
#endif /* POSIX_CFG_SEM_EN */

180
osal/posix/time.c Normal file
View File

@@ -0,0 +1,180 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
#include "private/posix_config.h"
#include "errno.h"
#include "time.h"
#include "private/time.h"
#include "private/timer.h"
__API__ clock_t clock(void)
{
return tos_systick_get();
}
__API__ int clock_gettime(clockid_t clock_id, struct timespec *tp)
{
k_tick_t ktick;
TOS_PTR_SANITY_CHECK_RC(tp, EINVAL);
if (clock_id != CLOCK_REALTIME) {
return EINVAL;
}
/* use systick rather than rtc now */
ktick = tos_systick_get();
ktick_to_timespec(ktick, tp);
return 0;
}
#if POSIX_CFG_TIMER_EN > 0u
__STATIC__ void timer_callback(void *arg)
{
ptimer_ctl_t *the_ctl;
the_ctl = (ptimer_ctl_t *)arg;
the_ctl->sigev_notify_function(the_ctl->sigev_value);
}
__API__ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
{
k_err_t kerr;
timer_t id;
ptimer_ctl_t *the_ctl;
TOS_PTR_SANITY_CHECK_RC(timerid, EINVAL);
TOS_PTR_SANITY_CHECK_RC(evp, EINVAL);
TOS_PTR_SANITY_CHECK_RC(evp->sigev_notify_function, EINVAL);
id = timer_id_alloc();
if (id == -1) {
return ENOMEM;
}
clockid = clockid; /* make compiler happy */
the_ctl = (ptimer_ctl_t *)tos_mmheap_alloc(sizeof(ptimer_ctl_t));
if (!the_ctl) {
return ENOMEM;
}
the_ctl->sigev_notify_function = evp->sigev_notify_function;
the_ctl->sigev_value = evp->sigev_value;
kerr = tos_timer_create((k_timer_t *)&the_ctl->ktimer, 1u, 1u,
timer_callback, the_ctl,
TOS_OPT_TIMER_PERIODIC);
if (kerr != K_ERR_NONE) {
tos_mmheap_free(the_ctl);
return EBUSY;
}
the_ctl->id = id;
timer_id_add(id, the_ctl);
return 0;
}
__API__ int timer_delete(timer_t timerid)
{
k_err_t kerr;
ptimer_ctl_t *the_ctl;
TOS_PTR_SANITY_CHECK_RC(timerid, EINVAL);
the_ctl = timer_by_id(timerid);
if (!the_ctl) {
return EINVAL;
}
kerr = tos_timer_destroy(&the_ctl->ktimer);
timer_id_free(timerid);
tos_mmheap_free(the_ctl);
if (kerr == K_ERR_NONE) {
return 0;
}
return EINVAL;
}
__NOTSUPP__ int timer_getoverrun(timer_t timerid)
{
return EOPNOTSUPP;
}
__API__ int timer_gettime(timer_t timerid, struct itimerspec *value)
{
k_tick_t expires, period;
ptimer_ctl_t *the_ctl;
the_ctl = timer_by_id(timerid);
if (!the_ctl) {
return EINVAL;
}
if (!value) {
return 0;
}
expires = the_ctl->ktimer.expires;
period = the_ctl->ktimer.period;
ktick_to_timespec(expires, &value->it_value);
ktick_to_timespec(period, &value->it_interval);
return 0;
}
__API__ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
{
k_tick_t delay, period;
ptimer_ctl_t *the_ctl;
TOS_PTR_SANITY_CHECK_RC(value, EINVAL);
the_ctl = timer_by_id(timerid);
if (!the_ctl) {
return EINVAL;
}
if (ovalue) {
timer_gettime(timerid, ovalue);
}
delay = timespec_to_ktick(&value->it_value);
period = timespec_to_ktick(&value->it_interval);
tos_timer_stop(&the_ctl->ktimer);
tos_timer_delay_change(&the_ctl->ktimer, delay);
tos_timer_period_change(&the_ctl->ktimer, period);
tos_timer_start(&the_ctl->ktimer);
return 0;
}
#endif /* POSIX_CFG_TIMER_EN */

54
osal/posix/time_prv.c Normal file
View File

@@ -0,0 +1,54 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "time.h"
#include "private/time.h"
__KNL__ k_tick_t timespec_to_ktick(const struct timespec *tp)
{
int nsecond, second;
struct timespec curr_tp;
TOS_PTR_SANITY_CHECK_RC(tp, (k_tick_t)-1);
clock_gettime(CLOCK_REALTIME, &curr_tp);
if (tp->tv_nsec - curr_tp.tv_nsec < 0) {
nsecond = NANOSECOND_PER_SECOND - (curr_tp.tv_nsec - tp->tv_nsec);
second = tp->tv_sec - curr_tp.tv_sec - 1;
} else {
nsecond = tp->tv_nsec - curr_tp.tv_nsec;
second = tp->tv_sec - curr_tp.tv_sec;
}
if (second < 0) {
return (k_tick_t)0u;
}
return (k_tick_t)(second * TOS_CFG_CPU_TICK_PER_SECOND + nsecond * TOS_CFG_CPU_TICK_PER_SECOND / NANOSECOND_PER_SECOND);
}
__KNL__ void ktick_to_timespec(k_tick_t ktick, struct timespec *tp)
{
if (!tp) {
return;
}
tp->tv_sec = ktick / TOS_CFG_CPU_TICK_PER_SECOND;
tp->tv_nsec = (ktick % TOS_CFG_CPU_TICK_PER_SECOND) * ((long)1000000000 / TOS_CFG_CPU_TICK_PER_SECOND);
}

97
osal/posix/timer_prv.c Normal file
View File

@@ -0,0 +1,97 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
#include "time.h"
#include "private/timer.h"
__STATIC__ ptimer_ctl_t *ptimer_ctl_table[TIMERS_MAX] = { 0 };
__KNL__ int timer_id_add(timer_t id, ptimer_ctl_t *ptimer_ctl)
{
TOS_CPU_CPSR_ALLOC();
if (id < 0 ||
id >= TOS_COUNT_OF(ptimer_ctl_table) ||
ptimer_ctl_table[id]) {
return -1;
}
TOS_CPU_INT_DISABLE();
ptimer_ctl_table[id] = ptimer_ctl;
TOS_CPU_INT_ENABLE();
return 0;
}
__KNL__ timer_t timer_id_alloc(void)
{
TOS_CPU_CPSR_ALLOC();
int i = 0;
TOS_CPU_INT_DISABLE();
for (i = 0; i < TOS_COUNT_OF(ptimer_ctl_table); ++i) {
if (!ptimer_ctl_table[i]) {
TOS_CPU_INT_ENABLE();
return (timer_t)i;
}
}
TOS_CPU_INT_ENABLE();
return -1;
}
__KNL__ int timer_id_free(timer_t id)
{
TOS_CPU_CPSR_ALLOC();
if (id < 0 ||
id >= TOS_COUNT_OF(ptimer_ctl_table) ||
!ptimer_ctl_table[id]) {
return -1;
}
TOS_CPU_INT_DISABLE();
ptimer_ctl_table[id] = K_NULL;
TOS_CPU_INT_ENABLE();
return 0;
}
__KNL__ ptimer_ctl_t *timer_by_id(timer_t id)
{
ptimer_ctl_t *the_ctl;
the_ctl = ptimer_ctl_table[id];
if (!the_ctl) {
return K_NULL;
}
if (the_ctl->id != id) {
return K_NULL;
}
return the_ctl;
}

26
osal/posix/tos_posix.c Normal file
View File

@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#include "tos_k.h"
#include "private/pthread.h"
__API__ int tos_posix_init(void)
{
return pthread_init();
}