Many changes. Timer works now (using calloc instead of malloc). Adding test framework.
This commit is contained in:
parent
1f6c94746c
commit
f8e09d656d
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
@ -12,7 +12,7 @@
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"browse": {
|
||||
"path": [
|
||||
"/usr/include",
|
||||
"/usr/include/**",
|
||||
"${workspaceFolder}/**"
|
||||
]
|
||||
}
|
||||
|
21
Makefile
21
Makefile
@ -2,17 +2,30 @@ TARGETNAME = inverter
|
||||
BUILDFOLDER = ./build/
|
||||
TARGET = $(BUILDFOLDER)$(TARGETNAME)
|
||||
|
||||
TEST_TARGETNAME = test
|
||||
TEST_BUILDFOLDER = ./test/build/
|
||||
TEST_TARGET = $(TEST_BUILDFOLDER)$(TEST_TARGETNAME)
|
||||
|
||||
INC = -Isrc/include -I/usr/include -I/usr/include/libftdi1
|
||||
CFLAGS = -Wall -Wpedantic -Wextra -Os
|
||||
CFLAGS = -Wall -Wpedantic -Wextra -g
|
||||
CPPFLAGS =
|
||||
|
||||
SRC = $(wildcard src/*.c)
|
||||
TEST_SRC = $(filter-out src/main.c, $(SRC) $(wildcard test/*.c))
|
||||
|
||||
all: $(TARGET)
|
||||
$(TARGETNAME): $(TARGET)
|
||||
|
||||
$(TARGET): $(SRC)
|
||||
mkdir -p build
|
||||
gcc -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(INC) -lm -lftdi1 -g
|
||||
cc -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(INC) -lm -lftdi1
|
||||
|
||||
$(TEST_TARGETNAME): $(TEST_TARGET)
|
||||
|
||||
$(TEST_TARGET): $(TEST_SRC)
|
||||
echo $(TEST_SRC)
|
||||
mkdir -p $(TEST_BUILDFOLDER)
|
||||
cc -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(INC) -lm -lftdi1 -lcunit
|
||||
|
||||
clean:
|
||||
rm -fr ./src/*.o ./build/
|
||||
rm -fr ./src/*.o ./build/*
|
||||
rm -fr $(TEST_BUILDFOLDER)*
|
||||
|
@ -39,45 +39,45 @@ sm_t bridge_statemachine = {
|
||||
void brdg_BothGndOn(void)
|
||||
{
|
||||
/* Turn both GND transistors on */
|
||||
setPin(PB6);
|
||||
setPin(PB4);
|
||||
setPin(D0);
|
||||
setPin(D2);
|
||||
|
||||
/* Turn both PWR transistors off */
|
||||
unsetPin(PB7);
|
||||
unsetPin(PB5);
|
||||
unsetPin(D3);
|
||||
unsetPin(D1);
|
||||
}
|
||||
|
||||
void brdg_Hb1GndOn(void)
|
||||
{
|
||||
/* We turn GND of half-bridge 1 on */
|
||||
setPin(PB6);
|
||||
setPin(D0);
|
||||
|
||||
/* And then we turn GND of half-bridge 2 off */
|
||||
unsetPin(PB4);
|
||||
unsetPin(D2);
|
||||
}
|
||||
|
||||
void brdg_Hb1PowerOn(void)
|
||||
{
|
||||
setPin(PB7);
|
||||
setPin(D3);
|
||||
}
|
||||
|
||||
void brdg_Hb1PowerOff(void)
|
||||
{
|
||||
unsetPin(PB7);
|
||||
unsetPin(D3);
|
||||
}
|
||||
|
||||
void brdg_Hb2GndOn(void)
|
||||
{
|
||||
setPin(PB4);
|
||||
unsetPin(PB6);
|
||||
setPin(D0);
|
||||
unsetPin(D2);
|
||||
}
|
||||
|
||||
void brdg_Hb2PowerOn(void)
|
||||
{
|
||||
setPin(PB5);
|
||||
setPin(D1);
|
||||
}
|
||||
|
||||
void brdg_Hb2PowerOff(void)
|
||||
{
|
||||
unsetPin(PB5);
|
||||
unsetPin(D1);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#define PB6 1
|
||||
#define PB4 2
|
||||
#define PB5 3
|
||||
#define PB7 4
|
||||
#define D0 0
|
||||
#define D1 1
|
||||
#define D2 2
|
||||
#define D3 3
|
||||
|
||||
void togglePin(unsigned int pin);
|
||||
void unsetPin(unsigned int pin);
|
||||
|
@ -14,4 +14,4 @@ typedef struct
|
||||
void tmr_initTimer(tmr_ctx *ctx);
|
||||
void tmr_handleTimerOverflow(union sigval);
|
||||
int tmr_callEvery(void (*func)(void), long nsec);
|
||||
void tmr_add_ns_to_current_time(struct itimerspec *current, long usecs);
|
||||
void tmr_add_ns_to_current_time(struct itimerspec *current, long nsecs);
|
19
src/main.c
19
src/main.c
@ -12,43 +12,32 @@ static uint64_t counter = 0;
|
||||
void test1(void)
|
||||
{
|
||||
printf("%lu\n", counter);
|
||||
fflush(stdout);
|
||||
counter++;
|
||||
}
|
||||
|
||||
void test2(void)
|
||||
{
|
||||
printf("This is test2\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void togglePin1(void)
|
||||
{
|
||||
printf("toggling pin\n");
|
||||
setPin(0);
|
||||
togglePin(D0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Program started\n");
|
||||
|
||||
if (tmr_callEvery(test1, 1 * SEC))
|
||||
{
|
||||
printf("Error starting timer for test\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (tmr_callEvery(test2, 1 * SEC))
|
||||
{
|
||||
printf("Error starting timer for test\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (init_ftdi())
|
||||
{
|
||||
printf("Error initializing ftdi\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (tmr_callEvery(togglePin1, 1 * SEC))
|
||||
if (tmr_callEvery(togglePin1, 10 * USEC))
|
||||
{
|
||||
printf("Error starting timer for togglePin\n");
|
||||
return EXIT_FAILURE;
|
||||
|
@ -10,7 +10,8 @@
|
||||
int tmr_registry_index = 0;
|
||||
tmr_ctx *tmr_registry[10];
|
||||
|
||||
void tmr_add_to_registry(tmr_ctx* ctx) {
|
||||
void tmr_add_to_registry(tmr_ctx *ctx)
|
||||
{
|
||||
tmr_registry[tmr_registry_index] = ctx;
|
||||
tmr_registry_index++;
|
||||
}
|
||||
@ -44,7 +45,8 @@ void tmr_handleTimerOverflow(sigval_t ctx_par)
|
||||
|
||||
int tmr_callEvery(void (*func)(void), long nsec)
|
||||
{
|
||||
tmr_ctx *tmr = malloc(sizeof(tmr_ctx));
|
||||
tmr_ctx *tmr = calloc(1,sizeof(tmr_ctx));
|
||||
// tmr_ctx *tmr = malloc(sizeof(tmr_ctx));
|
||||
|
||||
tmr_add_to_registry(tmr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user