Skip to content

Commit 120fde0

Browse files
Merge branch 'main' into new-macros-in-flags
2 parents e601f33 + d55b43e commit 120fde0

File tree

19 files changed

+928
-26
lines changed

19 files changed

+928
-26
lines changed

Testing/Makefile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
3+
# Compiler
4+
CC := gcc
5+
6+
# Project directories
7+
PROJECT_DIR := /home/app
8+
TEST_DIR := $(PROJECT_DIR)/Tests
9+
MOCKS_DIR := $(TEST_DIR)/Mocks
10+
TEST_BUILD := $(TEST_DIR)/build
11+
TEST_BUILD_BIN := $(TEST_BUILD)/bin
12+
UNITY_SRC := /cmock_portable/vendor/unity/src
13+
CMOCK_SRC := /cmock_portable/src
14+
EMEBEDDED_TESTING_DIR := Drivers/Embedded-Base/Testing
15+
16+
# Command line variables (must be provided)
17+
TEST_NAME ?=
18+
TEST_FILE ?=
19+
TEST_PACKAGE ?=
20+
C_SOURCES ?=
21+
INCLUDE_DIRS ?=
22+
C_DEFINES ?=
23+
24+
TEST_BUILD_OBJS := $(TEST_BUILD)/objs/$(TEST_PACKAGE)
25+
26+
# Sanity check
27+
ifeq ($(TEST_NAME),)
28+
$(error You must define TEST_NAME)
29+
endif
30+
ifeq ($(TEST_FILE),)
31+
$(error You must define TEST_FILE)
32+
endif
33+
ifeq ($(TEST_PACKAGE),)
34+
$(error You must define TEST_PACKAGE)
35+
endif
36+
ifeq ($(C_SOURCES),)
37+
$(error You must define C_SOURCES)
38+
endif
39+
40+
# Output executable
41+
TARGET := $(TEST_BUILD_BIN)/$(TEST_NAME)
42+
43+
# Include dirs
44+
C_INCLUDES := \
45+
-I$(UNITY_SRC) \
46+
-I$(CMOCK_SRC) \
47+
$(addprefix -I,$(INCLUDE_DIRS)) \
48+
-I$(MOCKS_DIR)/$(TEST_PACKAGE) \
49+
-I$(TEST_DIR)/Inc
50+
51+
CFLAGS = -w $(C_DEFINES) $(C_INCLUDES)
52+
53+
TEST_SOURCES = $(CMOCK_SRC)/cmock.c $(UNITY_SRC)/unity.c
54+
55+
# All source files
56+
SOURCES := $(TEST_FILE) $(C_SOURCES)
57+
TEST_SRCS := $(TEST)/cmock.c $(UNITY_SRC)/unity.c
58+
59+
# Object files
60+
OBJS := $(patsubst %.c,$(TEST_BUILD_OBJS)/%.o,$(SOURCES))
61+
TEST_OBJS := $(TEST_BUILD_OBJS)/cmock.o $(TEST_BUILD_OBJS)/unity.o
62+
63+
ALL_OBJS := $(OBJS) $(TEST_OBJS)
64+
65+
# Default target
66+
all: $(TARGET)
67+
68+
# Link executable
69+
$(TARGET): $(ALL_OBJS)
70+
@mkdir -p $(dir $@)
71+
$(CC) $(CFLAGS) $^ -o $@ -lm
72+
73+
# Compile object files
74+
$(TEST_BUILD_OBJS)/%.o: %.c
75+
@mkdir -p $(dir $@)
76+
$(CC) $(CFLAGS) -c $< -o $@ -lm
77+
78+
$(TEST_BUILD_OBJS)/cmock.o: $(CMOCK_SRC)/cmock.c
79+
@mkdir -p $(dir $@)
80+
$(CC) $(CFLAGS) -c $< -o $@
81+
82+
$(TEST_BUILD_OBJS)/unity.o: $(UNITY_SRC)/unity.c
83+
@mkdir -p $(dir $@)
84+
@echo "Compiling $< -> $@"
85+
$(CC) $(CFLAGS) -c $< -o $@
86+
87+
88+
# Clean
89+
clean:
90+
rm -rf $(TEST_BUILD)

Testing/cmock-config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
:cmock:
3+
:mock_prefix: mock_
4+
:includes:
5+
- stubs.h
6+
:plugins:
7+
- :ignore
8+
- :ignore_arg
9+
- :callback
10+
- :expect
11+
- :expect_any_args
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#ifndef _TEST_EXAMPLE_H
3+
#define _TEST_EXAMPLE_H
4+
5+
#include "unity.h"
6+
7+
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#include "test_example.h"
3+
#include <stdbool.h>
4+
#include <stdlib.h>
5+
6+
// clang-format off
7+
8+
// gets run before every test function
9+
void setUp(void) {
10+
11+
}
12+
13+
// gets run after every test function
14+
void tearDown(void) {
15+
16+
}
17+
18+
// test function
19+
void test_exmaple(void) {
20+
TEST_ASSERT_EQUAL_INT(9 + 10, 19);
21+
}
22+
23+
// run tests in main function
24+
int main(void) {
25+
UNITY_BEGIN();
26+
RUN_TEST(test_exmaple);
27+
return UNITY_END();
28+
}
29+
30+
// clang-format on
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Example NER Testing Config
2+
3+
title = "Example NER Testing"
4+
5+
# Files that will be mocked for every test package
6+
mocked-files = [
7+
"Drivers/Embedded-Base/Testing/manual_mocks/stubs.h",
8+
]
9+
10+
# sources to compile for each test exe
11+
sources = [
12+
"Drivers/Embedded-Base/middleware/src/bitstream.c",
13+
"Drivers/Embedded-Base/middleware/src/timer.c",
14+
"Drivers/adbms/adbms6830/program/src/serialPrintResult.c",
15+
"Drivers/Embedded-Base/middleware/src/c_utils.c",
16+
]
17+
18+
# headers directories to include in build
19+
include-dirs = [
20+
"Core/Inc",
21+
"Tests/Inc",
22+
"Drivers/Embedded-Base/middleware/include",
23+
"Drivers/Embedded-Base/platforms/stm32f405/include",
24+
"Drivers/Embedded-Base/general/include",
25+
]
26+
27+
# Test Package definitionss
28+
29+
[test-packages.example1]
30+
mocked-files = ["Drivers/Embedded-Base/middleware/include/timer.h"]
31+
32+
[test-packages.example2]
33+
parent-package = "example1"
34+
mocked-files = ["Drivers/Embedded-Base/middleware/include/bitstream.h"]
35+
36+
# Test definitions
37+
38+
[test.example]
39+
test-package = "example2"
40+
test-file = "Tests/Src/example.c"
41+
42+
43+

dev/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ RUN apt-get update && apt-get install -y \
2323
cmake \
2424
libssl-dev \
2525
python3 \
26-
python3-pip
27-
26+
python3-pip \
27+
ruby
2828

2929
RUN wget https://github.com/renode/renode/releases/download/v1.15.3/renode-1.15.3.linux-portable.tar.gz
3030
RUN mkdir renode_portable && tar -xvf renode-*.linux-portable.tar.gz -C renode_portable --strip-components=1
3131
ENV PATH $PATH:/renode_portable
3232

33+
RUN wget https://github.com/ThrowTheSwitch/CMock/archive/refs/tags/v2.6.0.tar.gz -O cmock.tar.gz
34+
RUN mkdir cmock_portable && tar -xvf cmock.tar.gz -C cmock_portable --strip-components=1
35+
ENV PATH $PATH:/cmock_portable
36+
37+
RUN wget https://github.com/ThrowTheSwitch/Unity/archive/refs/tags/v2.6.1.tar.gz -O unity.tar.gz
38+
RUN mkdir -p /cmock_portable/vendor/unity && tar -xvf unity.tar.gz -C /cmock_portable/vendor/unity --strip-components=1
39+
3340
# Set up a development tools directory
3441
WORKDIR /home/dev
3542
ADD . /home/dev

general/include/honeywellSSC.h

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
SSCMANN060PG2A3 Air Pressure Sensor I2C Driver
3+
Datasheet: https://datasheet.octopart.com/SSCMANN060PG2A3-Honeywell-datasheet-36842084.pdf?src-supplier=IHS
4+
Honeywell I2C Doc: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/ja/products/sensors/pressure-sensors/board-mount-pressure-sensors/common/documents/sps-siot-i2c-comms-digital-output-pressure-sensors-tn-008201-3-en-ciid-45841.pdf
5+
6+
SSCMANN060PG2A3
7+
Product series - SSC: Standard Accuracy, Compensated/Amplified
8+
Package - M: SMT (Surface Mount Technology)
9+
Pressure port - AN: Single axial barbed port
10+
Options - N: Dry gasses only, no diagnostics
11+
Pressure range - 060PG: 0 psi to 60 psi
12+
Output type - 2: I2C, Address 0x28
13+
Transfer function - A: 10% to 90% of Vsupply (analog), 2^14 counts (digital)
14+
Supply voltage - 3: 3.3 Vdc
15+
16+
Pressure Range Specs:
17+
Pressure Range: 0 to 60 psi
18+
Over Pressure: 120 psi
19+
Burst Pressure: 240 psi
20+
Common Mode Pressure: 250 psi
21+
Total Error Band: ±2% FFS
22+
Long-term Stability: ±0.25% FFS
23+
*/
24+
25+
#ifndef honeywellSSC_H
26+
#define honeywellSSC_H
27+
#include <stdint.h>
28+
#include <math.h>
29+
30+
// I2C DEVICE ADDRESS
31+
#define SSC_I2C_ADDR 0x28 // Output type 2
32+
33+
// STATUS BIT VALUES (bits S1 S0 from first byte)
34+
#define SSC_STATUS_NORMAL 0x00 // normal operation, valid data
35+
#define SSC_STATUS_COMMAND_MODE \
36+
0x01 // used for programming, should not be seen in normal operation
37+
#define SSC_STATUS_STALE_DATA 0x02 // data is old
38+
#define SSC_STATUS_DIAGNOSTIC 0x03 // hardware error
39+
40+
// BIT MASKS
41+
#define SSC_STATUS_MASK 0xC000 // Bits 14-15 for 2-bit status in first 2 bytes
42+
#define SSC_PRESSURE_MASK \
43+
0x3FFF // Bits 0-13 for 14-bit pressure data in first 2 bytes
44+
#define SSC_TEMP_MASK \
45+
0xFFE0 // Bits 6-16 for 11-bit temperature data in last 2 bytes
46+
47+
#define SSC_DATA_LENGTH \
48+
4 // first 2 bytes for pressure (and status), 2 bytes for temperature (and junk)
49+
50+
/*
51+
Pressure is calculated from the reading as:
52+
Pressure = ((output - output_min) * (pressure_max - pressure_min)) / (output_max - output_min) + pressure_min
53+
The following are the constants for that equation
54+
*/
55+
// TRANSFER FUNCTION VALUES (2^14 counts)
56+
#define SSC_OUTPUT_MIN 0 // 0% of 2^14
57+
#define SSC_OUTPUT_MAX 16384 // 100% of 2^14
58+
59+
// PRESSURE RANGE VALUES (0 to 60 psi)
60+
#define SSC_PRESSURE_MIN 0.0f // 0 psi
61+
#define SSC_PRESSURE_MAX 60.0f // 60 psi
62+
63+
/*
64+
Temperature is calculated drom the reading as:
65+
Temperature (celcius) = (Output(dec)/2047 * 200) - 50
66+
The following are constants for that equation
67+
*/
68+
// TEMPERATURE CONVERSION CONSTANTS
69+
#define SSC_TEMP_COUNTS_MAX 2047.0f // 11-bit max value
70+
#define SSC_TEMP_OFFSET -50.0f // Offset in equation
71+
#define SSC_TEMP_SCALE 200.0f // Scale factor in equation
72+
73+
// Function pointer
74+
typedef int (*ReadPtr)(
75+
uint16_t dev_addr, uint8_t *data,
76+
uint16_t data_size); // if data_size == 2: just reads pressure data, if data_size == 4 reads temp data too
77+
// I think the sensor is read-only so no WritePtr needed
78+
79+
// struct that records the current information
80+
typedef struct {
81+
uint16_t dev_addr;
82+
ReadPtr read;
83+
uint8_t min_pressure;
84+
uint8_t max_pressure;
85+
} honeywellSSC_t;
86+
87+
// sets stuff up
88+
void honeywellSSC_init(honeywellSSC_t *ssc, ReadPtr read, uint16_t dev_addr,
89+
uint8_t min_pressure, uint8_t max_pressure);
90+
91+
// Reads the data into the provided data pointer
92+
// expects honeywellSSC_t and a pointer to a uint8_t array of length 2 or 4
93+
int honeywellSSC_read_data(honeywellSSC_t *ssc, uint8_t *data,
94+
uint8_t data_size);
95+
96+
// Reads the status message
97+
void honeywellSSC_read_status(uint16_t data, uint8_t *result);
98+
99+
// Reads the pressure in psi
100+
int honeywellSSC_read_pressure(honeywellSSC_t *ssc, float *result);
101+
102+
// Reads the temperature in celcius
103+
int honeywellSSC_read_temp(honeywellSSC_t *ssc, float *result);
104+
105+
#endif

general/include/stm32xx_hal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
#include "stm32g4xx_hal.h"
1818
#endif
1919

20-
#endif /* STM32XX_HAL_H*/
20+
#endif /* STM32XX_HAL_H */

general/include/tca9539.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef TCA9539_H
22
#define TCA9539_H
33

4-
#include "stm32f4xx_hal.h"
4+
#include "stm32xx_hal.h"
55
#include <stdint.h>
66

77
/*

0 commit comments

Comments
 (0)