Commit aed650b1 authored by Martin Vítek's avatar Martin Vítek

Add CircularBuffer class

parent 42fe45dc
#pragma once
#include <cstdint>
template<typename T, int SIZE>
class CircularBuffer
{
private:
T buffer[SIZE];
uint32_t read_position;
uint32_t write_position;
public:
CircularBuffer(): read_position(0),
write_position(0)
{
}
T* read()
{
return &(buffer[read_position]);
}
T* write()
{
return &(buffer[write_position]);
}
void read_advance()
{
if (read_position == (SIZE-1)) read_position = 0;
else read_position++;
}
void write_advance()
{
if (write_position == (SIZE-1)) write_position = 0;
else write_position++;
}
uint32_t check()
{
if (write_position < read_position) return (SIZE + write_position - read_position);
else return (write_position - read_position);
}
};
......@@ -121,75 +121,75 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<ArmGccCpp>
<armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex>
<armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss>
<armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep>
<armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin>
<armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec>
<armgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</armgcc.compiler.symbols.DefSymbols>
<armgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
<armgcc.compiler.optimization.level>Optimize (-O1)</armgcc.compiler.optimization.level>
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcc.compiler.optimization.PrepareDataForGarbageCollection>True</armgcc.compiler.optimization.PrepareDataForGarbageCollection>
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
<armgcc.compiler.warnings.ExtraWarnings>True</armgcc.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</armgcccpp.compiler.symbols.DefSymbols>
<armgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.compiler.directories.IncludePaths>
<armgcccpp.compiler.optimization.level>Optimize (-O1)</armgcccpp.compiler.optimization.level>
<armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>
<armgcccpp.compiler.optimization.DebugLevel>Maximum (-g3)</armgcccpp.compiler.optimization.DebugLevel>
<armgcccpp.compiler.warnings.AllWarnings>True</armgcccpp.compiler.warnings.AllWarnings>
<armgcccpp.compiler.warnings.ExtraWarnings>True</armgcccpp.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.miscellaneous.OtherFlags>-std=gnu++14</armgcccpp.compiler.miscellaneous.OtherFlags>
<armgcccpp.linker.general.AdditionalSpecs>Use syscall stubs (--specs=nosys.specs)</armgcccpp.linker.general.AdditionalSpecs>
<armgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</armgcccpp.linker.libraries.Libraries>
<armgcccpp.linker.libraries.LibrarySearchPaths>
<ListValues>
<Value>%24(ProjectDir)\Device_Startup</Value>
</ListValues>
</armgcccpp.linker.libraries.LibrarySearchPaths>
<armgcccpp.linker.optimization.GarbageCollectUnusedSections>True</armgcccpp.linker.optimization.GarbageCollectUnusedSections>
<armgcccpp.linker.memorysettings.ExternalRAM />
<armgcccpp.linker.miscellaneous.LinkerFlags>-Tsamd20g18_flash.ld</armgcccpp.linker.miscellaneous.LinkerFlags>
<armgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.assembler.general.IncludePaths>
<armgcccpp.assembler.debugging.DebugLevel>Default (-g)</armgcccpp.assembler.debugging.DebugLevel>
<armgcccpp.preprocessingassembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.preprocessingassembler.general.IncludePaths>
<armgcccpp.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcccpp.preprocessingassembler.debugging.DebugLevel>
</ArmGccCpp>
<armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex>
<armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss>
<armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep>
<armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin>
<armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec>
<armgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</armgcc.compiler.symbols.DefSymbols>
<armgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
<armgcc.compiler.optimization.level>Optimize (-O1)</armgcc.compiler.optimization.level>
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcc.compiler.optimization.PrepareDataForGarbageCollection>True</armgcc.compiler.optimization.PrepareDataForGarbageCollection>
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
<armgcc.compiler.warnings.ExtraWarnings>True</armgcc.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</armgcccpp.compiler.symbols.DefSymbols>
<armgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.compiler.directories.IncludePaths>
<armgcccpp.compiler.optimization.level>Optimize (-O1)</armgcccpp.compiler.optimization.level>
<armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>
<armgcccpp.compiler.optimization.DebugLevel>Maximum (-g3)</armgcccpp.compiler.optimization.DebugLevel>
<armgcccpp.compiler.warnings.AllWarnings>True</armgcccpp.compiler.warnings.AllWarnings>
<armgcccpp.compiler.warnings.ExtraWarnings>True</armgcccpp.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.miscellaneous.OtherFlags>-std=gnu++14</armgcccpp.compiler.miscellaneous.OtherFlags>
<armgcccpp.linker.general.AdditionalSpecs>Use syscall stubs (--specs=nosys.specs)</armgcccpp.linker.general.AdditionalSpecs>
<armgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</armgcccpp.linker.libraries.Libraries>
<armgcccpp.linker.libraries.LibrarySearchPaths>
<ListValues>
<Value>%24(ProjectDir)\Device_Startup</Value>
</ListValues>
</armgcccpp.linker.libraries.LibrarySearchPaths>
<armgcccpp.linker.optimization.GarbageCollectUnusedSections>True</armgcccpp.linker.optimization.GarbageCollectUnusedSections>
<armgcccpp.linker.memorysettings.ExternalRAM />
<armgcccpp.linker.miscellaneous.LinkerFlags>-Tsamd20g18_flash.ld</armgcccpp.linker.miscellaneous.LinkerFlags>
<armgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.assembler.general.IncludePaths>
<armgcccpp.assembler.debugging.DebugLevel>Default (-g)</armgcccpp.assembler.debugging.DebugLevel>
<armgcccpp.preprocessingassembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.preprocessingassembler.general.IncludePaths>
<armgcccpp.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcccpp.preprocessingassembler.debugging.DebugLevel>
</ArmGccCpp>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
......@@ -211,6 +211,9 @@
<Compile Include="Button.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="CircularBuffer.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="Debug.cpp">
<SubType>compile</SubType>
</Compile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment