Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cm3cpp_systick.h - github.com/thirdpin/libopencm3_cpp_extensions.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 91ae5ae2e5c011d7136b96b8b9e5627e222d281d (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * This file is part of the libopencm3_cpp_extensions project.
 * hosted at http://github.com/thirdpin/libopencm3_cpp_extensions
 *
 * Copyright (C) 2016  Third Pin LLC
 * Written by Anastasiia Lazareva <a.lazareva@thirdpin.ru>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
SYSTICK implementation, public interface
*/

#ifndef SYSTICK_API_H
#define SYSTICK_API_H

#include "cm3cpp_config.h"
#include <libopencm3/cm3/systick.h>
#include <stdint.h>

extern "C" void sys_tick_handler(void);
extern "C" void delay_nop(uint32_t count);

namespace cm3cpp {

namespace systick {

void init(uint32_t div = CM3CPP_SYSTICK_CLOCK_DIV);
void deinit();
uint32_t get_counter();
void delay_systick(uint32_t ms);

class Counter
{
 public:
    enum Mode
    {
        CYCLE,
        ONE_SHOT
    };

    Counter(Mode mode, uint32_t period);
    void init(Mode mode, uint32_t period);
    bool timeout();
    bool start();
    bool stop();

    void set_period(uint32_t const period) { _period = period; }
    uint32_t period() const { return _period; }

 private:
    uint32_t _saved;
    uint32_t _period;
    Mode _mode;
    bool _is_active;
};

}  // namespace systick

}  // namespace cm3cpp
#endif