Commit 0b2393cb authored by Clément Foucher's avatar Clément Foucher
Browse files

OwnTech Power API Library Quick Start repository initialization.

parents
.pio
.vscode
\ No newline at end of file
This diff is collapsed.
{
"name": "opalib_quick_start",
"version": "1.0.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"
}
/*
* Copyright (c) 2021 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGLPV2.1
*/
/**
* @author Clément Foucher <clement.foucher@laas.fr>
*/
/////
// OwnTech Power API includes
#include "timer.h"
#include "hrtim.h"
#include "leg.h"
#include "data_acquisition.h"
/////
// 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;
/////
// 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();
}
void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us)
{
/////
// Store user-defined task
periodic_task_ptr = periodic_task;
/////
// Initialize peripherals
// ADC
data_acquisition_init();
// Leg
leg_init();
// HRTIM
hrtim_adc_trigger_en(0, ADC1R, AD13_TAC3);
hrtim_cmp_set(0, TIMA, CMP3xR, 1);
// Timer
timer6 = device_get_binding(TIMER6_LABEL);
struct timer_config_t timer_cfg =
{
.timer_enable_irq = 1,
.timer_callback = _internal_task
};
timer_config(timer6, &timer_cfg);
/////
// Initialize data dispatch
data_dispatch_init();
/////
// Launch task by starting timer
timer_start(timer6, task_period_us);
}
/*
* Copyright (c) 2021 LAAS-CNRS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGLPV2.1
*/
/**
* @brief This library provides a quick start configuration
* by configuring the paripherals to perform a measure
* on all defined ADCs, and running a user-defined
* task periodically.
*
* @author Clément Foucher <clement.foucher@laas.fr>
*/
#ifndef OPALIB_QUICK_START_H_
#define OPALIB_QUICK_START_H_
// Stdlib
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Library initialization function.
*
* @param periodic_task Pointer to the void(void) function
* to be executed periodically.
* @param task_period_us Period of the function in µs.
* Allowed range: 1 to 6553 µs.
*/
void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us);
#ifdef __cplusplus
}
#endif
#endif // OPALIB_QUICK_START_H_
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