Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
aa400de
Added PWM module skeleton
bebenlebricolo Jun 23, 2021
3a945f4
Uploading pending changes
bebenlebricolo Oct 19, 2021
7fffc70
Moved core libraries under a single folder
bebenlebricolo Oct 19, 2021
ab84442
Moved files and removed App folder
bebenlebricolo Oct 19, 2021
c75a7c6
Removed Sensors as they are part of another library package
bebenlebricolo Oct 19, 2021
e38ce89
Fixed tests CMakelists.txt after extraction
bebenlebricolo Oct 19, 2021
1acf33e
Added ExampleApp
bebenlebricolo Feb 23, 2022
1a4244d
Tweaked a little bit AvrAsyncCore being handled as a submodule
bebenlebricolo Feb 23, 2022
d3c2ac7
Updated ExampleApp conditional configuration steps
bebenlebricolo Feb 23, 2022
0620c44
Updated pwm header to include complementary PWM config
bebenlebricolo Mar 2, 2022
42b8522
Updated PWM driver interface
bebenlebricolo Mar 14, 2022
eb06e22
Added some documentation for PWM module
bebenlebricolo Mar 15, 2022
3c07a55
Updated Timebase, IO and timers interfaces
bebenlebricolo Mar 16, 2022
d5015be
Added example config for PWM and documentation
bebenlebricolo Mar 16, 2022
fd9d61c
Updated example config file
bebenlebricolo Mar 16, 2022
f56024a
Modified TIMER 8 Bit handle configuration procedure
bebenlebricolo Mar 22, 2022
aa13e1c
Added examples to general build system
bebenlebricolo Mar 22, 2022
c62b683
Refactored timer 8 bit structure a bit
bebenlebricolo Mar 23, 2022
c03c33b
Adapted tests to timer 8 nit refacto
bebenlebricolo Mar 23, 2022
13cb5f6
Refactored Timer 8 bit async to have static config
bebenlebricolo Mar 23, 2022
350c148
Refactored Timer 16 bit to have static config
bebenlebricolo Mar 23, 2022
7f2b8ad
Updated timer generic to latest changes
bebenlebricolo Mar 23, 2022
f8fdbd8
Updated parts of PWM driver
bebenlebricolo Mar 25, 2022
c275aa2
Added proto support for timer 8 bit configuration in PWM config single
bebenlebricolo Mar 25, 2022
8265a16
Implemented 8 bit configuration with all use cases (not tested yet)
bebenlebricolo Mar 25, 2022
de856d0
Refactored cpu_freq into clock_freq, which is more accurate
bebenlebricolo Mar 30, 2022
c6e12c6
Ported prescaler single computation to timer 8 bit async and 16 bit
bebenlebricolo Mar 30, 2022
a59182a
Ported pwm implementation to timer 8 bit async
bebenlebricolo Mar 30, 2022
954efe2
Reworked a bit how generic timer treat resolution calculations
bebenlebricolo Mar 30, 2022
b9af87d
Almost finished 16 bit PWM devs
bebenlebricolo Apr 4, 2022
353ecd8
Fixed timer_16_bit tests
bebenlebricolo Apr 5, 2022
0fe435d
Added pwm module testing skeleton
bebenlebricolo Apr 6, 2022
4bdf53d
Implemented some configuration tests + small refacto
bebenlebricolo Apr 8, 2022
cefb035
Added optional support for coverage report in Tests
bebenlebricolo Apr 13, 2022
478f28e
Added stubbed config export in timer stubs (PWM module)
bebenlebricolo Apr 13, 2022
7b75fa6
Tooled stubbed timers
bebenlebricolo Apr 21, 2022
9ddde91
Modified PWM driver to output actual frequency and duty cycle at conf…
bebenlebricolo Apr 27, 2022
37b32a0
Fixed doxygen [in,out] params formatting in comments
bebenlebricolo Apr 27, 2022
f4826a1
Ported pwm actual properties probing to timer 8 bit async
bebenlebricolo Apr 27, 2022
0508fb5
Updated timer's prescaler computation apis a little bit
bebenlebricolo Apr 27, 2022
6572c52
Fixed bug in compute closest prescaler function in timer drivers
bebenlebricolo Apr 27, 2022
3dafaa1
Implemented tests for PWM 16 bit
bebenlebricolo Apr 27, 2022
30ccd0a
Implemented 16 bit timer unit B pwm test
bebenlebricolo Apr 27, 2022
b617d42
Added unimplemented body for 16 bit complementary pwm config
bebenlebricolo Apr 27, 2022
7830174
Cleaned a bit CMakeLists.txt files
bebenlebricolo Apr 27, 2022
1f9f550
Consolidated io driver api
bebenlebricolo Apr 29, 2022
18ff483
Modified timebase module to compute period based on input frequency
bebenlebricolo Apr 29, 2022
e86269f
Added PWM event generation at the same time we are handling pin switc…
bebenlebricolo Apr 29, 2022
2c5b4ce
Updated CMake minimum required version to remove deprecation warning
bebenlebricolo Jan 26, 2024
3ccbfa2
Backup : publishing left-overs
bebenlebricolo Mar 10, 2024
073ec95
Updated toolchain to match C23 pre-spec (removed -pedantic to support…
bebenlebricolo Mar 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 5 additions & 52 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,52 +1,5 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
[Bb]uild/
*.vscode/
*.vs/
*.autosave*
*.code-workspace
89 changes: 66 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,77 @@
cmake_minimum_required(VERSION 3.20)
# Use AVR GCC toolchain
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/Toolchain/avr8-gcc-toolchain.cmake)

project(LabBenchPowerSupply_Firmware C)
# Use AVR GCC toolchain (needs to be added before the project is declared, otherwise CMake does not take it into account)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Toolchain/avr8-gcc-toolchain.cmake)
endif()


set(AVR_MCU atmega328p)
set(AVR_MCU_SPEED 16000000)
project(AvrAsyncCoreLibs C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD 17)


# This option, disabled by default, allows CMake to configure subproject and build examples that are located within
# Driver's or Module's "examples" folder.
# The aim behind that is to validate that the examples are well declared and build fine altogether with regular codebase
option(BUILD_EXAMPLES "Will configure example projects as well" OFF )

############################################################################################################################################
############################################# Checking environment is setup correctly ######################################################
############################################################################################################################################

add_compile_definitions(
F_CPU=${AVR_MCU_SPEED}
__AVR_ATmega328P__
I2C_IMPLEM_MASTER_FULL
)
add_compile_options(-mmcu=${AVR_MCU})
# If we are not in a submodule (this project is used as a standalone project)
# we do not want to set the CONFIG FILE
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# This variable is needed by some drivers in order to locate the config.h file
# Provided by the application
set (CONFIG_FILE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ExampleApp/inc)
set(AVR_MCU atmega328pb)
set(AVR_MCU_SPEED 16000000)
set(AVR_MCU_HEADER_DEFINITION __AVR_ATmega328P__)

set(CMAKE_EXE_LINKER_FLAGS "-mmcu=${AVR_MCU}")
# Global definitions for avr-gcc
add_compile_definitions(
F_CPU=${AVR_MCU_SPEED}
${AVR_MCU_HEADER_DEFINITION}
)
add_compile_options(-mmcu=${AVR_MCU})

if(CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DDEBUG_WITH_SIMAVR)
endif()

# This variable is needed by some drivers in order to locate the config.h file
# Provided by the application
set (CONFIG_FILE_DIR ${CMAKE_SOURCE_DIR}/App/inc)
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
message(ERROR " This async core needs to know about toolchain file, please set the CMAKE_TOOLCHAIN_FILE variable to a valid toolchain file !")
message(STATUS "Some example toolchain files can be found at : https://github.com/bebenlebricolo/CMakeAS7-Toolchains")
endif()

# Check that the config file directory was specified
if (NOT DEFINED CONFIG_FILE_DIR)
message(ERROR " Some drivers need to know the CONFIG_FILE_DIR variable ! You must use it to point to your config.h file's parent directory !")
endif()

add_subdirectory(${CMAKE_SOURCE_DIR}/Utils)
add_subdirectory(${CMAKE_SOURCE_DIR}/Drivers)
add_subdirectory(${CMAKE_SOURCE_DIR}/Modules)
add_subdirectory(${CMAKE_SOURCE_DIR}/Sensors)
add_subdirectory(${CMAKE_SOURCE_DIR}/App)
if (NOT DEFINED AVR_MCU)
message(WARNING " AVR_MCU was not found at this point, drivers need that variable in order to target the right MCU !")
endif()

if (NOT DEFINED AVR_MCU_SPEED)
message(WARNING " AVR_MCU_SPEED was not found at this point, drivers need that variable in order to handle the right CPU clock speed !")
endif()

if (NOT DEFINED AVR_MCU_HEADER_DEFINITION)
message(WARNING " AVR_MCU_HEADER_DEFINITION was not found at this point, drivers need that variable in order to consume the right files in atmel's lib !")
endif()

############################################################################################################################################
###################################################### Configuring all the libs ############################################################
############################################################################################################################################

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Drivers)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Modules)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Utils)

# If we are not in a submodule (this project is used as a standalone project)
# we do not want to set the CONFIG FILE
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ExampleApp)
endif()
2 changes: 1 addition & 1 deletion Drivers/Adc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.20)

add_library(adc_driver STATIC
${CMAKE_CURRENT_SOURCE_DIR}/src/adc_stack.c
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Adc/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.20)

project(adc_tests)
enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion Drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.20)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Adc)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Timers/Timer_8_bit)
Expand Down
2 changes: 1 addition & 1 deletion Drivers/I2c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.20)

# Stop here as we need an extra config.h file in order to build this driver
# This file provides symbols for the driver to work properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* When a read operation (master reads from this slave), current_byte is considered as an output.
* When a write operation (master writes to this slave), current_byte is considered as an input.
* The request parameter informs about the nature of the current i2c transaction (read or write requests)
* @param[in/out] current_byte : interface byte used by the I2C driver
* @param[in,out] current_byte : interface byte used by the I2C driver
* @param[in] request : nature of the I2C transaction currently taking place
* @return I2C_SLAVE_HANDLER_ERROR_OK or any other error from the i2c_slave_handler_error_t enum in case of failure.
*/
Expand Down
2 changes: 1 addition & 1 deletion Drivers/I2c/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.20)

project(i2c_tests)
enable_testing()
Expand Down
4 changes: 2 additions & 2 deletions Drivers/I2c/Tests/Stub/i2c_fake_slave_application_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@<FreeMyCode>
FreeMyCode version : 1.0 RC alpha
Author : bebenlebricolo
License :
License :
name : GPLv3
url : https://www.gnu.org/licenses/quick-guide-gplv3.html
Date : 12/02/2021
Expand Down Expand Up @@ -78,7 +78,7 @@ void i2c_fake_slave_application_init(void);

/**
* @brief handles the first byte of a read/write operation when configured as a slave
* @param[in/out] byte : gives the current byte on which we are working
* @param[in,out] byte : gives the current byte on which we are working
* @param[in] request : gives the current I2C operation from master's point of view
* => when master reads from slave, request shall be set to I2C_REQUEST_READ
*/
Expand Down
4 changes: 2 additions & 2 deletions Drivers/I2c/inc/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@<FreeMyCode>
FreeMyCode version : 1.0 RC alpha
Author : bebenlebricolo
License :
License :
name : GPLv3
url : https://www.gnu.org/licenses/quick-guide-gplv3.html
Date : 12/02/2021
Expand Down Expand Up @@ -206,7 +206,7 @@ typedef enum
* When a read operation (master reads from this slave), current_byte is considered as an output.
* When a write operation (master writes to this slave), current_byte is considered as an input.
* The request parameter informs about the nature of the current i2c transaction (read or write requests)
* @param[in/out] current_byte : interface byte used by the I2C driver
* @param[in,out] current_byte : interface byte used by the I2C driver
* @param[in] request : nature of the I2C transaction currently taking place
*
* Example given :
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Io/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.20)

add_library(io_driver STATIC
${CMAKE_CURRENT_SOURCE_DIR}/src/io.c
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Io/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.20)

project(io_driver_tests)

Expand Down
2 changes: 1 addition & 1 deletion Drivers/Io/Tests/Stub/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ io_t io_pins_lut[IO_MAX_PINS] =
};


io_config_t io_config =
io_reg_config_t io_reg_config =
{
.mcucr_reg = &stubbed_registers.st_mcucr,
.porta_cfg =
Expand Down
63 changes: 54 additions & 9 deletions Drivers/Io/Tests/io_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,24 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "io.h"
#include "config.h"

TEST(io_driver, test_init)
class IoDriverTests : public ::testing::Test
{
io_init();
public :
void SetUp() override
{
}

void TearDown() override
{
memset(get_stubbed_registers(), 0, sizeof(stubbed_registers_t));
(void) io_deinit();
}
};

TEST_F(IoDriverTests, test_init)
{
io_error_t err = io_init();
ASSERT_EQ(IO_ERROR_OK, err);
auto stubs = get_stubbed_registers();
ASSERT_EQ(stubs->st_mcucr, 0);

Expand All @@ -53,29 +68,59 @@ TEST(io_driver, test_init)
ASSERT_EQ(stubs->st_portd.st_port_reg, (uint8_t)(1 << 5U));
ASSERT_EQ(stubs->st_portd.st_pin_reg, 0);
ASSERT_EQ(stubs->st_portd.st_ddr_reg, 1 << 5U | 1 << 1U);

ASSERT_TRUE(io_is_initialised());
}

TEST(io_driver, test_read)
TEST_F(IoDriverTests, test_deinit)
{
io_init();
io_error_t err = io_init();
ASSERT_EQ(IO_ERROR_OK, err);
ASSERT_TRUE(io_is_initialised());

err = io_deinit();
ASSERT_FALSE(io_is_initialised());
}

TEST_F(IoDriverTests, test_read)
{
io_state_t state = IO_STATE_UNDEFINED;
io_error_t err = IO_ERROR_OK;
err = io_read(PIN_POWER_SWITCH, &state);
ASSERT_EQ(IO_ERROR_NOT_INITIALISED, err);

err = io_init();
ASSERT_EQ(IO_ERROR_OK, err);
auto stubs = get_stubbed_registers();
stubs->st_portc.st_pin_reg |= 0xF0;

auto state = io_read(PIN_POWER_SWITCH);
// Check out of range detection
err = io_read(IO_MAX_PINS, &state);
ASSERT_EQ(IO_ERROR_INDEX_OUT_OF_RANGE, err);

err = io_read(PIN_POWER_SWITCH, &state);
ASSERT_EQ(state, IO_STATE_LOW);
ASSERT_EQ(IO_ERROR_OK, err);

stubs->st_portc.st_pin_reg |= (1 << 3U);
state = io_read(PIN_POWER_SWITCH);
err = io_read(PIN_POWER_SWITCH, &state);
ASSERT_EQ(state, IO_STATE_HIGH);
ASSERT_EQ(IO_ERROR_OK, err);

stubs->st_portc.st_pin_reg &= ~(1 << 3U);
state = io_read(PIN_POWER_SWITCH);
err = io_read(PIN_POWER_SWITCH, &state);
ASSERT_EQ(state, IO_STATE_LOW);
ASSERT_EQ(IO_ERROR_OK, err);
}

TEST(io_driver, test_write)
TEST_F(IoDriverTests, test_write)
{
io_init();
io_error_t err = IO_ERROR_OK;
err = io_write(PIN_POWER_SWITCH, IO_STATE_HIGH);
ASSERT_EQ(IO_ERROR_NOT_INITIALISED, err);

err = io_init();
ASSERT_EQ(IO_ERROR_OK, err);
auto stubs = get_stubbed_registers();
ASSERT_EQ(stubs->st_portb.st_port_reg, 0x2);

Expand Down
Loading