Research issue where togglePin1() is not being called.
This commit is contained in:
parent
013c619eaf
commit
1f6c94746c
11
.vscode/c_cpp_properties.json
vendored
11
.vscode/c_cpp_properties.json
vendored
@ -4,17 +4,16 @@
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"/usr/include/**",
|
||||
"${workspaceFolder}/src/include/**"
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/clang",
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++14",
|
||||
"intelliSenseMode": "linux-clang-x64",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"browse": {
|
||||
"path": [
|
||||
"/usr/include/**",
|
||||
"${workspaceFolder}/src/include/**"
|
||||
"/usr/include",
|
||||
"${workspaceFolder}/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -5,7 +5,7 @@
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/inverter",
|
||||
"stopAtEntry": true,
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
|
@ -7,10 +7,11 @@ typedef struct
|
||||
long interval;
|
||||
struct sigevent sevp;
|
||||
struct itimerspec times;
|
||||
struct timespec runsSince;
|
||||
void (*funcToBeCalled)(void);
|
||||
} tmr_ctx;
|
||||
|
||||
void tmr_initTimer(tmr_ctx *ctx);
|
||||
void tmr_handleTimerOverflow(union sigval);
|
||||
int tmr_callEveryMs(void (*func)(void));
|
||||
int tmr_callEvery(void (*func)(void), long nsec);
|
||||
void tmr_add_ns_to_current_time(struct itimerspec *current, long usecs);
|
41
src/main.c
41
src/main.c
@ -1,21 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ftdi.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ftdi_utils.h"
|
||||
#include "timer_utils.h"
|
||||
#include "time_scales.h"
|
||||
#include "pins.h"
|
||||
|
||||
static uint64_t counter = 0;
|
||||
void test(void)
|
||||
void test1(void)
|
||||
{
|
||||
printf("%lu\n", counter);
|
||||
counter++;
|
||||
}
|
||||
|
||||
void test2(void)
|
||||
{
|
||||
printf("This is test2\n");
|
||||
}
|
||||
|
||||
void togglePin1(void)
|
||||
{
|
||||
printf("toggling pin\n");
|
||||
setPin(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Program started\n");
|
||||
tmr_callEveryMs(test);
|
||||
|
||||
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))
|
||||
{
|
||||
printf("Error starting timer for togglePin\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -7,6 +7,14 @@
|
||||
#include "time_scales.h"
|
||||
#include "timer_utils.h"
|
||||
|
||||
int tmr_registry_index = 0;
|
||||
tmr_ctx *tmr_registry[10];
|
||||
|
||||
void tmr_add_to_registry(tmr_ctx* ctx) {
|
||||
tmr_registry[tmr_registry_index] = ctx;
|
||||
tmr_registry_index++;
|
||||
}
|
||||
|
||||
void tmr_initTimer(tmr_ctx *ctx)
|
||||
{
|
||||
ctx->sevp = (struct sigevent){
|
||||
@ -17,6 +25,10 @@ void tmr_initTimer(tmr_ctx *ctx)
|
||||
|
||||
timer_create(CLOCK_MONOTONIC, &ctx->sevp, &ctx->timerid);
|
||||
clock_gettime(CLOCK_MONOTONIC, &ctx->times.it_value);
|
||||
|
||||
ctx->runsSince.tv_sec = ctx->times.it_value.tv_sec;
|
||||
ctx->runsSince.tv_nsec = ctx->times.it_value.tv_nsec;
|
||||
|
||||
tmr_add_ns_to_current_time(&ctx->times, ctx->interval);
|
||||
timer_settime(ctx->timerid, TIMER_ABSTIME, &ctx->times, NULL);
|
||||
}
|
||||
@ -30,10 +42,13 @@ void tmr_handleTimerOverflow(sigval_t ctx_par)
|
||||
timer_settime(ctx->timerid, TIMER_ABSTIME, &ctx->times, NULL);
|
||||
}
|
||||
|
||||
int tmr_callEveryMs(void (*func)(void))
|
||||
int tmr_callEvery(void (*func)(void), long nsec)
|
||||
{
|
||||
tmr_ctx *tmr = malloc(sizeof(tmr_ctx));
|
||||
tmr->interval = 1000000;
|
||||
|
||||
tmr_add_to_registry(tmr);
|
||||
|
||||
tmr->interval = nsec;
|
||||
tmr->funcToBeCalled = func;
|
||||
|
||||
if (!func)
|
||||
|
Loading…
Reference in New Issue
Block a user