Commit 978099da authored by Clément Foucher's avatar Clément Foucher
Browse files

Update library as OwnTech data acquisition is now autonomous.

parent 5e7e3f1c
{
"name": "opalib_quick_start",
"version": "1.1.0",
"version": "1.2.0",
"description": "OwnTech Power API Library Quick Start initializes all required OwnTech Power API drivers. It allows the user to define a function that will be called periodically.",
"keywords": "OwnTech Power API"
}
......@@ -24,6 +24,7 @@
/////
// OwnTech Power API includes
#include "timer.h"
#include "hrtim.h"
#include "leg.h"
......@@ -32,35 +33,16 @@
/////
// Timer defines
#define TIMER6_NODELABEL DT_NODELABEL(timers6)
#define TIMER6_LABEL DT_PROP(TIMER6_NODELABEL, label)
static const struct device* timer6;
/////
// Pointer to the user-defined periodic task
static void (*periodic_task_ptr)() = NULL;
#define TIMER6_LABEL DT_PROP(DT_NODELABEL(timers6), label)
static const struct device* timer6 = NULL;
/////
// Functions
static void _internal_task()
{
// Dispatch data from the DMA buffers to per-channel buffers
data_dispatch_do_dispatch();
// Call user-defined peroidic task
if (periodic_task_ptr != NULL)
periodic_task_ptr();
}
// Public API
void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us)
{
/////
// Store user-defined task
periodic_task_ptr = periodic_task;
/////
// Initialize peripherals
......@@ -74,20 +56,18 @@ void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us)
hrtim_adc_trigger_en(0, ADC1R, AD13_TAC3);
hrtim_cmp_set(0, TIMA, CMP3xR, 1);
// Timer
if (periodic_task != NULL)
{
// Configure timer
timer6 = device_get_binding(TIMER6_LABEL);
struct timer_config_t timer_cfg =
{
.timer_enable_irq = 1,
.timer_callback = _internal_task
.timer_callback = periodic_task
};
timer_config(timer6, &timer_cfg);
/////
// Initialize data dispatch
data_dispatch_init();
/////
// Launch task by starting timer
timer_start(timer6, task_period_us);
}
}
......@@ -41,11 +41,15 @@ extern "C" {
/**
* @brief Library initialization function.
* This function uses Timer 6 is a user periodic
* task is to be executed.
*
* @param periodic_task Pointer to the void(void) function
* to be executed periodically.
* Can be NULL if no task has to be executed.
* @param task_period_us Period of the function in µs.
* Allowed range: 1 to 6553 µs.
* Value is ignored if first parameter is NULL.
*/
void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment