opalib_quick_start.c 1.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * 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
27

28
29
30
31
32
33
34
35
36
#include "timer.h"
#include "hrtim.h"
#include "leg.h"
#include "data_acquisition.h"


/////
// Timer defines

37
38
#define TIMER6_LABEL DT_PROP(DT_NODELABEL(timers6), label)
static const struct device* timer6 = NULL;
39
40
41


/////
42
// Public API
43
44
45
46
47
48
49
50
51
52

void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us)
{
	/////
	// Initialize peripherals

	// ADC
	data_acquisition_init();

	// Leg
53
	leg_init(true);
54
55
56
57
58

	// HRTIM
	hrtim_adc_trigger_en(0, ADC1R, AD13_TAC3);
	hrtim_cmp_set(0, TIMA, CMP3xR, 1);

59
	if (periodic_task != NULL)
60
	{
61
62
63
64
65
66
67
68
69
70
71
72
		// Configure timer
		timer6 = device_get_binding(TIMER6_LABEL);
		struct timer_config_t timer_cfg =
		{
			.timer_enable_irq = 1,
			.timer_callback   = periodic_task
		};
		timer_config(timer6, &timer_cfg);

		// Launch task by starting timer
		timer_start(timer6, task_period_us);
	}
73
}