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", "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.", "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" "keywords": "OwnTech Power API"
} }
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
///// /////
// OwnTech Power API includes // OwnTech Power API includes
#include "timer.h" #include "timer.h"
#include "hrtim.h" #include "hrtim.h"
#include "leg.h" #include "leg.h"
...@@ -32,35 +33,16 @@ ...@@ -32,35 +33,16 @@
///// /////
// Timer defines // Timer defines
#define TIMER6_NODELABEL DT_NODELABEL(timers6)
#define TIMER6_LABEL DT_PROP(TIMER6_NODELABEL, label)
static const struct device* timer6;
///// #define TIMER6_LABEL DT_PROP(DT_NODELABEL(timers6), label)
// Pointer to the user-defined periodic task static const struct device* timer6 = NULL;
static void (*periodic_task_ptr)() = NULL;
///// /////
// Functions // Public API
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();
}
void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us) void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us)
{ {
/////
// Store user-defined task
periodic_task_ptr = periodic_task;
///// /////
// Initialize peripherals // Initialize peripherals
...@@ -74,20 +56,18 @@ void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us) ...@@ -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_adc_trigger_en(0, ADC1R, AD13_TAC3);
hrtim_cmp_set(0, TIMA, CMP3xR, 1); hrtim_cmp_set(0, TIMA, CMP3xR, 1);
// Timer if (periodic_task != NULL)
{
// Configure timer
timer6 = device_get_binding(TIMER6_LABEL); timer6 = device_get_binding(TIMER6_LABEL);
struct timer_config_t timer_cfg = struct timer_config_t timer_cfg =
{ {
.timer_enable_irq = 1, .timer_enable_irq = 1,
.timer_callback = _internal_task .timer_callback = periodic_task
}; };
timer_config(timer6, &timer_cfg); timer_config(timer6, &timer_cfg);
/////
// Initialize data dispatch
data_dispatch_init();
/////
// Launch task by starting timer // Launch task by starting timer
timer_start(timer6, task_period_us); timer_start(timer6, task_period_us);
}
} }
...@@ -41,11 +41,15 @@ extern "C" { ...@@ -41,11 +41,15 @@ extern "C" {
/** /**
* @brief Library initialization function. * @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 * @param periodic_task Pointer to the void(void) function
* to be executed periodically. * to be executed periodically.
* Can be NULL if no task has to be executed.
* @param task_period_us Period of the function in µs. * @param task_period_us Period of the function in µs.
* Allowed range: 1 to 6553 µ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); 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