commit a77fd20d2dbb8406b340c7296dfee0e836128c5e Author: bartoolina Date: Sun Sep 6 16:13:07 2020 +0200 Project starting point diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..83e0b8c --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,22 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/var/lib/gems/2.7.0/gems/ceedling-0.30.0/vendor/unity/src", + "/var/lib/gems/2.7.0/gems/ceedling-0.30.0/vendor/cmock/src", + "/usr/lib/avr/include" + ], + "defines": [ + "__AVR_ATmega644PA__", + "F_CPU=11059200" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c99", + "cppStandard": "gnu++14", + "intelliSenseMode": "gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5760901 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // 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": "Ceedling Test Explorer Debug", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/test/out/${command:ceedlingExplorer.debugTestExecutable}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "miDebuggerPath": "/usr/bin/gdb" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f7e0123 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "ceedlingExplorer.debugConfiguration": "Ceedling Test Explorer Debug" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..012b659 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,43 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "make", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "make clean", + "type": "shell", + "command": "make", + "args": [ + "clean" + ], + "problemMatcher": [] + }, + { + "label": "ceedling clobber", + "type": "shell", + "command": "ceedling", + "args": [ + "clobber" + ], + "problemMatcher": [] + }, + { + "label": "clean", + "dependsOn": [ + "make clean", + "ceedling clobber" + ], + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7a52530 --- /dev/null +++ b/Makefile @@ -0,0 +1,125 @@ +SHELL := /bin/bash +# Created by bartool +# 15.03.2020 +# TODO +# Create pattern for upload +# Create pattern for init (create main.c, src dir, setting.json, c_cpp_properties.json) +PROCESSOR := ATmega644PA +F_CPU := 11059200UL + +DUDE_PROGRAMMER := ATB-FT232R +DUDE_PORT := ft0 + +SRC_DIR := src +BUILD_DIR := build/$(PROCESSOR) + +OPTIMIZE = Os +AVRDUDE_PATH := C:/avr/avrdude +CC := avr-gcc +OBJCOPY := avr-objcopy +OBJDUMP := avr-objdump +OBJSIZE := avr-size + +PROJECT_NAME := $(notdir $(CURDIR)) +ELF := $(BUILD_DIR)/$(PROJECT_NAME).elf +LSS := $(BUILD_DIR)/$(PROJECT_NAME).lss +MAP := $(BUILD_DIR)/$(PROJECT_NAME).map +FLASH_IMAGE := $(BUILD_DIR)/$(PROJECT_NAME).hex +EEPROM_IMAGE := $(BUILD_DIR)/$(PROJECT_NAME).eep + +C_FILES := $(wildcard $(SRC_DIR)/*/*.c) $(wildcard $(SRC_DIR)/*.c) +OBJ_FILES := $(patsubst src/%.c, $(BUILD_DIR)/%.o, $(C_FILES)) +DIRS := $(sort $(dir $(OBJ_FILES))) + +# lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1)))))))))))))))))))))))))) +MCU := $(shell echo $(PROCESSOR) | tr '[:upper:]' '[:lower:]') +# MCU = $(call lc,$(PROCESSOR)) + +# kratka sa oznaczene opcje wykorzystywane przez eclipse +CFLAGS = -mmcu=$(MCU)# +CFLAGS += -$(OPTIMIZE)# +CFLAGS += -g +CFLAGS += -std=gnu99# +CFLAGS += -funsigned-char# +CFLAGS += -funsigned-bitfields# +CFLAGS += -fpack-struct# +#CFLAGS += -ffreestanding +CFLAGS += -ffunction-sections# +CFLAGS += -fdata-sections# +CFLAGS += -fshort-enums# +CFLAGS += -fverbose-asm +CFLAGS += -Wall# +#CFLAGS += -Ic:/avr/avr_toolchain/avr/include +CFLAGS += -Wstrict-prototypes +CFLAGS += -DF_CPU=$(F_CPU)# + +ESC := \033[ +STOP := $(ESC)0m +RESET := $(ESC)$(STOP) +DEBUG := $(RESET)$(ESC)36;49;2m +FOCUS := $(RESET)$(ESC)35;49;10m +PROGRAM := $(RESET)$(ESC)33;49;1m + +all: $(ELF) $(LSS) $(FLASH_IMAGE) $(EEPROM_IMAGE) sizedummy + +build: $(ELF) + +$(DIRS): + @echo -e "$(DEBUG)>>> Making a dir: $(FOCUS)$@$(DEBUG) <<<$(STOP)" + @mkdir -p $@ + +$(ELF): $(OBJ_FILES) + @echo -e "$(DEBUG)>>> Building target: $(FOCUS)$@$(DEBUG) <<<$(STOP)" + @echo -e "$(DEBUG)>>> Invoking: AVR C Linker <<<$(STOP)" + $(CC) -Wl,-Map,$(MAP) -mmcu=$(MCU) -o $(ELF) $(OBJ_FILES) + +$(LSS): $(ELF) + @echo -e "$(DEBUG)>>> Invoking: AVR Create Extended Listing $(FOCUS)$@$(DEBUG) <<<$(STOP)" + $(OBJDUMP) -h -S $(ELF) > $(LSS) + +$(FLASH_IMAGE): $(ELF) + @echo -e "$(DEBUG)>>> Create flash image (ihex format) $(FOCUS)$@$(DEBUG) <<<$(STOP)" + $(OBJCOPY) -j .text -j .data -O ihex $(ELF) $(FLASH_IMAGE) + +$(EEPROM_IMAGE): $(ELF) + @echo -e "$(DEBUG)>>> Create eeprom image (ihex format) $(FOCUS)$@$(DEBUG) <<<$(STOP)" + $(OBJCOPY) -j .eeprom --no-change-warnings --change-section-lma .eeprom=0 -O ihex $(ELF) $(EEPROM_IMAGE) + +sizedummy: $(ELF) + @echo -e "$(DEBUG)>>> Invoking: Print size <<<$(STOP)" + $(OBJSIZE) --format=avr --mcu=$(MCU) $(ELF) + +clean: + @echo -e "$(DEBUG)>>> Cleaning... <<<$(STOP)" + rm -rf $(ELF) $(LSS) $(MAP) $(FLASH_IMAGE) $(EEPROM_IMAGE) $(OBJ_FILES) + rm -rf $(DIRS) + +info: + @echo -e "$(DEBUG)MCU: $(MCU) F_CPU: $(F_CPU)$(STOP)" + @echo -e "$(DEBUG)Programer: $(DUDE_PROGRAMMER) Port: $(DUDE_PORT)$(STOP)" + @echo -e "$(DEBUG)Source dir: $(SRC_DIR) Build dir: $(BUILD_DIR)$(STOP)" + @echo -e "$(DEBUG)Project name: $(PROJECT_NAME)$(STOP)" + @echo -e "$(FOCUS)elf: $(ELF) lss: $(LSS) map: $(MAP)$(STOP)" + @echo -e "$(DEBUG)hex: $(FLASH_IMAGE) $(ESC)$(STOP)$(FOCUS)eep: $(EEPROM_IMAGE)$(STOP)" + @echo -e "$(DEBUG)All dirs: $(DIRS)$(STOP)" + @echo -e "$(DEBUG)All c files: $(C_FILES)$(STOP)" + @echo -e "$(DEBUG)All o files: $(OBJ_FILES)$(STOP)" + @echo -e "$(DEBUG)Cflags: $(CFLAGS)$(STOP)" + @echo $(LOWER_VAR) + @echo "done" + +# nie testowane! sprawdzic poprawnosc parametrow +flash: $(FLASH_IMAGE) + @echo -e " $(PROGRAM)>>> Uplod only flash <<<$(STOP)" + $(AVRDUDE_PATH)/avrdude -p $(MCU) -P $(DUDE_PORT) -c $(DUDE_PROGRAMMER) -U flash:w:$(FLASH_IMAGE):i + +flash_eeprom: + @echo -e " $(PROGRAM)>>> Upload flash and eeprom <<<$(STOP)" + avrdude -p $(MCU) -P $(DUDE_PORT) -c $(DUDE_PROGRAMMER) -U flash:w:$(FLASH_IMAGE):i -D -U eeprom:w:$(EEPROM_IMAGE):i + +.SECONDEXPANSION: +$(OBJ_FILES): $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $$(wildcard $$(dir $(SRC_DIR)/%.c)*.h) + @if [ ! -d "$(dir $@)" ]; then echo -e "$(DEBUG) >>> Create dir: $(FOCUS)$(dir $@)$(DEBUG) <<<$(STOP)"; mkdir -p $(dir $@); fi + @echo -e "$(DEBUG)>>> Building file: $(FOCUS)$<$(DEBUG) --> $(FOCUS)$@$(DEBUG) <<<$(STOP)" + $(CC) $(CFLAGS) -c -o $@ $< + diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..2464cf3 --- /dev/null +++ b/project.yml @@ -0,0 +1,102 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.30.0 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:test/** + - -:test/support + :source: + - src/** + :support: + - test/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator + - xml_tests_report +... diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..df2d601 --- /dev/null +++ b/readme.md @@ -0,0 +1,122 @@ +# Template for AVR projects ic C + + + + + + +To jest projekt bazowy, z którego korzystam zaczynając prace nad nowym projektem. Jest w pełnu skonfigorwany tak, aby odrazu zacząć prace nad projektem. + +## Prerequisites + +Before you begin, ensure you have met the following requirements: +* You have installed the latest version of + - testing: `ceedling` (_requires ruby_) + - building: `built-essenstial`, `avr-libc` + - debuging: `gdb` + - ide: `Visual Studio Code` (_extensios:_ `C/C++ for Visual Studio Code`, `Ceedling Test Expoler)` +* You have a `Linux` machine. + +## New project + +To start new project, follow these steps: + +``` +mkdir +cd +git init +git pull link +``` +Project should be ready to go. The files structure looks like this: +```bash +├── .vscode +│ ├── c_cpp_properties.json +│ ├── launch.json +│ ├── settings.json +│ └── tasks.json +├── src +│ ├── i2c +│ │ ├── i2c.c +│ │ └── i2c.h +│ ├── lights +│ │ ├── lights.c +│ │ └── lights.h +│ ├── tempSensor +│ │ ├── tempSensor.c +│ │ └── tempSensor.h +│ └── main.c +├── test +│ ├── support +│ │ ├── HowToUseCeedlingForEmbedded_TDD.pdf +│ │ └── ceedling.txt +│ ├── test_lights.c +│ └── test_tempSensor.c +├── Makefile +├── project.yml +├── .gitignore +└── readme.md +``` +## Using templete + +#####1. Mikrokontroler i częstotliwość +* W pliku `c_cpp_properties.json` w sekcji `defines` nalaży dostosować typ mikrontrolera i jego częstotliwość. Wartość można pobrac z pliku `io.h`. + + ```json + "defines": [ + "__AVR_ATmega644PA__", + "F_CPU=11059200" + ], + ``` + +* Identycznie należy postąpić w pliku `Makefile`(`PROCESSOR` i `F_CPU`). + + ```makefile + PROCESSOR := ATmega644PA + F_CPU := 11059200UL + ``` + Przykładowe wartości: + + Makefile | c_cpp_properties.json + --- | --- + Atmega32 | \_\_AVR_ATmega32\_\_ + Atmega32U4 | \_\_AVR_ATmega32U4\_\_ + Atmega644P | \_\_AVR_ATmega644P\_\_ + Atmega644PA | \_\_AVR_ATmega644PA\_\_ + Atmega8A | \_\_AVR_ATmega8A\_\_ + Atmega328P | \_\_AVR_ATmega328P\_\_ + +#####2. Kompilowanie dla AVR +* Tasks in Visual Studio Code +Aby zbudować pliki dla mikrokontrolera można użyć skrótu klawiszowego `Ctrl+Shift+B`. Uruchomi to domyślne zadanie (`tasks.json`). +* Command line +Aby otrorzyc terminal użyj skrótu `Ctrl+shift+~`.
+ **kompilacja AVR:** + ```bash + make + ``` + lub + ```bash + make build + ``` + +#####3. Uruchamianie testów +Inforamcje jak używać testów znajdziesz w katalogu `/test/support` +* Z poziomu `Visual Studio Code` +zakładka `Test` lub bezpośrdnio w pliku z testami. +* z poziomu lini komend + ```bash + ceedling + ``` +#####4. Debugownaie +Nie wymaga opisu. + + + +## License + + +This project uses the following license: [MIT](https://choosealicense.com/licenses/mit/). diff --git a/src/i2c/i2c.c b/src/i2c/i2c.c new file mode 100644 index 0000000..fa4533a --- /dev/null +++ b/src/i2c/i2c.c @@ -0,0 +1,6 @@ +#include "i2c.h" + +uint16_t i2c_readRegister(uint8_t registerAddress) +{ + return 0x00; +} \ No newline at end of file diff --git a/src/i2c/i2c.h b/src/i2c/i2c.h new file mode 100644 index 0000000..5c70789 --- /dev/null +++ b/src/i2c/i2c.h @@ -0,0 +1,7 @@ +#ifndef i2c_H +#define i2c_H +#include + +uint16_t i2c_readRegister(uint8_t registerAddress); + +#endif // i2c_H \ No newline at end of file diff --git a/src/lights/lights.c b/src/lights/lights.c new file mode 100644 index 0000000..31ee9ec --- /dev/null +++ b/src/lights/lights.c @@ -0,0 +1,19 @@ +#include "lights.h" +#include + +static bool areLightsOn = false; + +void lights_SetHeadlightSwitchOff(void) +{ + areLightsOn = false; +} + +void lights_SetHeadlightSwitchOn(void) +{ + areLightsOn = true; +} + +bool lights_AreHeadlightsOn(void) +{ + return areLightsOn; +} \ No newline at end of file diff --git a/src/lights/lights.h b/src/lights/lights.h new file mode 100644 index 0000000..86f8620 --- /dev/null +++ b/src/lights/lights.h @@ -0,0 +1,10 @@ +#ifndef LIGHTS_H +#define LIGHTS_H + +#include + +void lights_SetHeadlightSwitchOff(void); +void lights_SetHeadlightSwitchOn(void); +bool lights_AreHeadlightsOn(void); + +#endif // LIGHTS_H diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..252ad67 --- /dev/null +++ b/src/main.c @@ -0,0 +1,8 @@ +#include + +int main(void) +{ + while (1) + { + } +} \ No newline at end of file diff --git a/src/tempSensor/tempSensor.c b/src/tempSensor/tempSensor.c new file mode 100644 index 0000000..5808cb4 --- /dev/null +++ b/src/tempSensor/tempSensor.c @@ -0,0 +1,9 @@ +#include "tempSensor.h" +#include "../i2c/i2c.h" +#include + +float tempSensor_getTemperature(void) +{ + uint16_t rawValue = i2c_readRegister(0x03); + return -100.0f + (0.2f * (float)rawValue); +} \ No newline at end of file diff --git a/src/tempSensor/tempSensor.h b/src/tempSensor/tempSensor.h new file mode 100644 index 0000000..3eb2502 --- /dev/null +++ b/src/tempSensor/tempSensor.h @@ -0,0 +1,6 @@ +#ifndef TEMPSENSOR_H +#define TEMPSENSOR_H + +float tempSensor_getTemperature(void); + +#endif // TEMPSENSOR_H diff --git a/test/support/.gitkeep b/test/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/support/HowToUseCeedlingForEmbedded_TDD.pdf b/test/support/HowToUseCeedlingForEmbedded_TDD.pdf new file mode 100644 index 0000000..03a04d3 Binary files /dev/null and b/test/support/HowToUseCeedlingForEmbedded_TDD.pdf differ diff --git a/test/support/ceedling.txt b/test/support/ceedling.txt new file mode 100644 index 0000000..da0eb9b --- /dev/null +++ b/test/support/ceedling.txt @@ -0,0 +1,178 @@ +1. ceedling commands + --- ceedling help --- + + ceedling clean # Delete all build artifacts and temporary products + ceedling clobber # Delete all generated files (and build artifacts) + ceedling environment # List all configured environment variables + ceedling files:include # List all collected include files + ceedling files:source # List all collected source files + ceedling files:support # List all collected support files + ceedling files:test # List all collected test files + ceedling logging # Enable logging + ceedling module:create[module_path] # Generate module (source, header and test files) + ceedling module:destroy[module_path] # Destroy module (source, header and test files) + ceedling module:stub[module_path] # Generate module stubs from header + ceedling options:export[filename] # Export tools options to a new project file + ceedling paths:include # List all collected include paths + ceedling paths:source # List all collected source paths + ceedling paths:support # List all collected support paths + ceedling paths:test # List all collected test paths + ceedling summary # Execute plugin result summaries (no build triggering) + ceedling test:* # Run single test ([*] real test or source file name, no path) + ceedling test:all # Run all unit tests (also just 'test' works) + ceedling test:delta # Run tests for changed files + ceedling test:path[dir] # Run tests whose test path contains [dir] or [dir] substring + ceedling test:pattern[regex] # Run tests by matching regular expression pattern + ceedling verbosity[level] # Set verbose output (silent:[0] - obnoxious:[4]) + ceedling version # Display build environment version info + +2. ceedling test asserts (info https://github.com/ThrowTheSwitch/Unity) + + Basic Validity Tests + + TEST_ASSERT_TRUE(condition) + + Evaluates whatever code is in condition and fails if it evaluates to false + + TEST_ASSERT_FALSE(condition) + + Evaluates whatever code is in condition and fails if it evaluates to true + + TEST_ASSERT(condition) + + Another way of calling TEST_ASSERT_TRUE + + TEST_ASSERT_UNLESS(condition) + + Another way of calling TEST_ASSERT_FALSE + + TEST_FAIL() + TEST_FAIL_MESSAGE(message) + + This test is automatically marked as a failure. The message is output stating why. + Numerical Assertions: Integers + + TEST_ASSERT_EQUAL_INT(expected, actual) + TEST_ASSERT_EQUAL_INT8(expected, actual) + TEST_ASSERT_EQUAL_INT16(expected, actual) + TEST_ASSERT_EQUAL_INT32(expected, actual) + TEST_ASSERT_EQUAL_INT64(expected, actual) + + Compare two integers for equality and display errors as signed integers. A cast will be performed to your natural integer size so often this can just be used. When you need to specify the exact size, like when comparing arrays, you can use a specific version: + + TEST_ASSERT_EQUAL_UINT(expected, actual) + TEST_ASSERT_EQUAL_UINT8(expected, actual) + TEST_ASSERT_EQUAL_UINT16(expected, actual) + TEST_ASSERT_EQUAL_UINT32(expected, actual) + TEST_ASSERT_EQUAL_UINT64(expected, actual) + + Compare two integers for equality and display errors as unsigned integers. Like INT, there are variants for different sizes also. + + TEST_ASSERT_EQUAL_HEX(expected, actual) + TEST_ASSERT_EQUAL_HEX8(expected, actual) + TEST_ASSERT_EQUAL_HEX16(expected, actual) + TEST_ASSERT_EQUAL_HEX32(expected, actual) + TEST_ASSERT_EQUAL_HEX64(expected, actual) + + Compares two integers for equality and display errors as hexadecimal. Like the other integer comparisons, you can specify the size... here the size will also effect how many nibbles are shown (for example, HEX16 will show 4 nibbles). + + TEST_ASSERT_EQUAL(expected, actual) + + Another way of calling TEST_ASSERT_EQUAL_INT + + TEST_ASSERT_INT_WITHIN(delta, expected, actual) + + Asserts that the actual value is within plus or minus delta of the expected value. This also comes in size specific variants. + + TEST_ASSERT_GREATER_THAN(threshold, actual) + + Asserts that the actual value is greater than the threshold. This also comes in size specific variants. + + TEST_ASSERT_LESS_THAN(threshold, actual) + + Asserts that the actual value is less than the threshold. This also comes in size specific variants. + Arrays + + _ARRAY + + You can append _ARRAY to any of these macros to make an array comparison of that type. Here you will need to care a bit more about the actual size of the value being checked. You will also specify an additional argument which is the number of elements to compare. For example: + + TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, elements) + + _EACH_EQUAL + + Another array comparison option is to check that EVERY element of an array is equal to a single expected value. You do this by specifying the EACH_EQUAL macro. For example: + + TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, elements) + + Numerical Assertions: Bitwise + + TEST_ASSERT_BITS(mask, expected, actual) + + Use an integer mask to specify which bits should be compared between two other integers. High bits in the mask are compared, low bits ignored. + + TEST_ASSERT_BITS_HIGH(mask, actual) + + Use an integer mask to specify which bits should be inspected to determine if they are all set high. High bits in the mask are compared, low bits ignored. + + TEST_ASSERT_BITS_LOW(mask, actual) + + Use an integer mask to specify which bits should be inspected to determine if they are all set low. High bits in the mask are compared, low bits ignored. + + TEST_ASSERT_BIT_HIGH(bit, actual) + + Test a single bit and verify that it is high. The bit is specified 0-31 for a 32-bit integer. + + TEST_ASSERT_BIT_LOW(bit, actual) + + Test a single bit and verify that it is low. The bit is specified 0-31 for a 32-bit integer. + Numerical Assertions: Floats + + TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) + + Asserts that the actual value is within plus or minus delta of the expected value. + + TEST_ASSERT_EQUAL_FLOAT(expected, actual) + TEST_ASSERT_EQUAL_DOUBLE(expected, actual) + + Asserts that two floating point values are "equal" within a small % delta of the expected value. + String Assertions + + TEST_ASSERT_EQUAL_STRING(expected, actual) + + Compare two null-terminate strings. Fail if any character is different or if the lengths are different. + + TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len) + + Compare two strings. Fail if any character is different, stop comparing after len characters. + + TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) + + Compare two null-terminate strings. Fail if any character is different or if the lengths are different. Output a custom message on failure. + + TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message) + + Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure. + Pointer Assertions + + Most pointer operations can be performed by simply using the integer comparisons above. However, a couple of special cases are added for clarity. + + TEST_ASSERT_NULL(pointer) + + Fails if the pointer is not equal to NULL + + TEST_ASSERT_NOT_NULL(pointer) + + + Fails if the pointer is equal to NULL + Memory Assertions + + TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) + + Compare two blocks of memory. This is a good generic assertion for types that can't be coerced into acting like standard types... but since it's a memory compare, you have to be careful that your data types are packed. + _MESSAGE + + you can append _MESSAGE to any of the macros to make them take an additional argument. This argument is a string that will be printed at the end of the failure strings. This is useful for specifying more information about the problem. + About + +3. ceedling mocks (info https://github.com/ThrowTheSwitch/CMock/blob/master/docs/CMock_Summary.md) diff --git a/test/test_lights.c b/test/test_lights.c new file mode 100644 index 0000000..d547c67 --- /dev/null +++ b/test/test_lights.c @@ -0,0 +1,32 @@ +#include "unity.h" + +#include "lights.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +// void test_lights_NeedToImplement(void) +// { +// TEST_IGNORE_MESSAGE("Need to Implement lights"); +// } + +void test_WhenTheHeadlightSwitchIsOff_ThenTheHeadLightsAreOff(void) +{ + // When the headlight switch is off... + lights_SetHeadlightSwitchOff(); + // then the headlights are off. + TEST_ASSERT_EQUAL(false, lights_AreHeadlightsOn()); +} + +void test_WhenTheHeadlightSwitchIsOn_ThenTheHeadLightsAreOn(void) +{ + // When the headlight switch is on... + lights_SetHeadlightSwitchOn(); + // then the headlights are on. + TEST_ASSERT_EQUAL(true, lights_AreHeadlightsOn()); +} \ No newline at end of file diff --git a/test/test_tempSensor.c b/test/test_tempSensor.c new file mode 100644 index 0000000..99ccce0 --- /dev/null +++ b/test/test_tempSensor.c @@ -0,0 +1,29 @@ +#include "unity.h" + +#include "tempSensor.h" +#include "mock_i2c.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +// void test_tempSensor_NeedToImplement(void) +// { +// TEST_IGNORE_MESSAGE("Need to Implement tempSensor"); +// } + +void test_whenTempRegisterReadsMaxValue_thenTheTempIsTheMaxValue(void) +{ + uint8_t tempRegisterAddress = 0x03; + float expectedTemperature = 104.6f; + float tolerance = 0.1f; + //When + i2c_readRegister_ExpectAndReturn(tempRegisterAddress, 0x3ff); + //Then + float actualTemperature = tempSensor_getTemperature(); + TEST_ASSERT_FLOAT_WITHIN(tolerance, expectedTemperature, actualTemperature); +}