Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Aug 21, 2022
2 parents 7645973 + 3f70624 commit 2d15bbe
Show file tree
Hide file tree
Showing 43 changed files with 1,031 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
See the CHANGELOG.md
See the [CHANGELOG](CHANGELOG.md)
draft: false
prerelease: false
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
*.uvoptx
*.__i
*.i
*.txt
!docs/*.txt
!CMakeLists.txt
RTE/

*debug

# IAR Settings
**/settings/*.crun
**/settings/*.dbgdt
Expand Down Expand Up @@ -68,13 +72,15 @@ RTE/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Dd]ebug*/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
_build/
build/

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down Expand Up @@ -382,3 +388,13 @@ log_file.txt
project.ioc
mx.scratch
*.tilen majerle


# Altium
Project outputs*
History/
*.SchDocPreview
*.$$$Preview

# VSCode projects
project_vscode_compiled.exe
14 changes: 14 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 4,
"configurations": [
{
/*
* Full configuration is provided by CMake plugin for vscode,
* that shall be installed by user
*/
"name": "Win32",
"intelliSenseMode": "${default}",
"configurationProvider": "ms-vscode.cmake-tools"
}
]
}
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"twxs.cmake",
]
}
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": []
}
]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files.associations": {
"lwevt_types.h": "c",
"lwevt_type.h": "c",
"lwevt.h": "c",
"string.h": "c",
"lwevt_opt.h": "c",
"stdatomic.h": "c",
"lwrb.h": "c"
},
"esbonio.sphinx.confDir": ""
}
73 changes: 73 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "Build project",
"command": "cmake",
"args": ["--build", "${command:cmake.buildDirectory}", "-j", "8"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "Re-build project",
"command": "cmake",
"args": ["--build", "${command:cmake.buildDirectory}", "--clean-first", "-v", "-j", "8"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
},
{
"type": "shell",
"label": "Clean project",
"command": "cmake",
"args": ["--build", "${command:cmake.buildDirectory}", "--target", "clean"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Run application",
"command": "${command:cmake.launchTargetPath}",
"args": [],
"problemMatcher": [],
},
{
"label": "Docs: Install python plugins from requirements.txt file",
"type": "shell",
"command": "python -m pip install -r requirements.txt",
"options": {
"cwd": "${workspaceFolder}/docs"
},
"problemMatcher": []
},
{
"label": "Docs: Generate html",
"type": "shell",
"command": ".\\make html",
"options": {
"cwd": "${workspaceFolder}/docs"
},
"problemMatcher": []
},
{
"label": "Docs: Clean build directory",
"type": "shell",
"command": ".\\make clean",
"options": {
"cwd": "${workspaceFolder}/docs"
},
"problemMatcher": []
},
]
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Develop

## v3.0.0-RC1

- Split CMakeLists.txt files between library and executable
- Change license year to 2022
- Update code style with astyle
- Minimum required version is C11, with requirement of `stdatomic.h` library

## v2.0.3

- Add `library.json` for Platform.IO
Expand Down
46 changes: 46 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.22)

# Setup project
project(LwLibPROJECT)

# -------------------------------------------------
# This CMakeLists.txt is used only if it is a top-level file.
# Purpose of it is to be able to compile project in standalone way only
#
# When library sources are to be included in another project
# user shall use /lwrb/CMakeLists.txt instead
if (NOT PROJECT_IS_TOP_LEVEL)
message(FATAL_ERROR "This CMakeLists.txt can only be used as top-level. Use /lwrb/CMakeLists.txt for library include purpose")
endif()

# Set as executable
add_executable(${PROJECT_NAME})

# Add key executable block
target_sources(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/dev/main.c
)

# Add key include paths
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/dev
)

# Compilation definition information
target_compile_definitions(${PROJECT_NAME} PUBLIC
WIN32
_DEBUG
CONSOLE
LWRB_DEV
)

# Compiler options
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wpedantic
)

# Add subdir with lwrb and link to project
add_subdirectory("lwrb" lwrb)
target_link_libraries(${PROJECT_NAME} lwrb)
30 changes: 30 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": 3,
"configurePresets": [
{
"name": "default",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "Win32-Debug",
"inherits": "default",
"toolchainFile": "${sourceDir}/cmake/i686-w64-mingw32-gcc.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "Win64-Debug",
"inherits": "default",
"toolchainFile": "${sourceDir}/cmake/x86_64-w64-mingw32-gcc.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
}
]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Tilen MAJERLE
Copyright (c) 2022 Tilen MAJERLE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ Library provides generic FIFO ring buffer implementation.
## Features

* Written in ANSI C99, compatible with ``size_t`` for size data types
* Platform independent, no architecture specific code
* Platform independent default code - with restrictions for smaller CPU architectures (`< sizeof(size_t)`)
* FIFO (First In First Out) buffer implementation
* No dynamic memory allocation, data is static array
* Uses optimized memory copy instead of loops to read/write data from/to memory
* Thread safe when used as pipe with single write and single read entries
* Interrupt safe when used as pipe with single write and single read entries
* Thread safe when used as pipe with single write and single read entries - when CPU read/write operation for `size_t` are single instruction (ARM Cortex-M for instance)
* Interrupt safe when used as pipe with single write and single read entries - when CPU read/write operation for `size_t` are single instruction (ARM Cortex-M for instance)
* For CPU systems with smaller achitecture than `sizeof(size_t)` (AVR for instance), atomic protection is required for read-write operation of buffer writes
* Suitable for DMA transfers from and to memory with zero-copy overhead between buffer and application memory
* Supports data peek, skip for read and advance for write
* Implements support for event notifications
Expand Down
7 changes: 7 additions & 0 deletions cmake/i686-w64-mingw32-gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Windows)

# Some default GCC settings
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
7 changes: 7 additions & 0 deletions cmake/x86_64-w64-mingw32-gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Windows)

# Some default GCC settings
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
File renamed without changes.
4 changes: 2 additions & 2 deletions dev/VisualStudio/lwrb_dev.vcxproj → dev/lwrb_dev.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\lwrb\src\include\;$(IncludePath)</IncludePath>
<IncludePath>..\lwrb\src\include\;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -140,7 +140,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\lwrb\src\lwrb\lwrb.c" />
<ClCompile Include="..\lwrb\src\lwrb\lwrb.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ClCompile Include="main.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\lwrb\src\lwrb\lwrb.c">
<ClCompile Include="..\lwrb\src\lwrb\lwrb.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
28 changes: 2 additions & 26 deletions dev/VisualStudio/main.c → dev/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
uint8_t lwrb_data[8 + 1];
lwrb_t buff;

static void debug_buff(uint8_t cmp, size_t r_w, size_t r_r, size_t r_f, size_t r_e);

uint8_t tmp[8];

void
my_buff_evt_fn(lwrb_t* buff, lwrb_evt_type_t type, size_t len) {
(void)buff;
switch (type) {
case LWRB_EVT_RESET:
printf("[EVT] Buffer reset event!\r\n");
Expand Down Expand Up @@ -59,30 +58,7 @@ main() {

lwrb_reset(&buff);

//for (size_t r = 0; r < sizeof(lwrb_data); ++r) {
// void* ptr;
// for (size_t w = 0; w < sizeof(lwrb_data); ++w) {
// buff.r = r;
// buff.w = w;
// ptr = lwrb_get_linear_block_write_address(&buff);
// len = lwrb_get_linear_block_write_length(&buff);
// printf("W: %3d, R: %3d, LEN: %3d\r\n", (int)w, (int)r, (int)len);
// }
//}
(void)len;

return 0;
}

static void
debug_buff(uint8_t cmp, size_t r_w, size_t r_r, size_t r_f, size_t r_e) {
/* Previous and current write, read pointers and full, empty values */
static size_t p_r, p_w, p_f, p_e;
size_t r, w, f, e;

r = buff.r;
w = buff.w;
f = lwrb_get_full(&buff);
e = lwrb_get_free(&buff);

printf("R: %3d, W: %3d, F: %3d, E: %3d\r\n", (int)r, (int)w, (int)f, (int)e);
}
Loading

0 comments on commit 2d15bbe

Please sign in to comment.