gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
system.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2020 Joey Castillo
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#include <stdint.h>
26#include <stdbool.h>
27#include <stddef.h>
28#include "sam.h"
29
30#pragma once
31
32#if __EMSCRIPTEN__
33
34typedef int tc_instance_details_t;
35typedef int tcc_instance_details_t;
37
38#else
39
40typedef struct {
41 Tc* tc;
42 uint32_t clock_enable_mask;
43 uint8_t gclk_id;
47
48typedef struct {
49 Tcc* tcc;
50 uint32_t clock_enable_mask;
51 uint8_t gclk_id;
55
56typedef struct {
57 Sercom* sercom;
58 uint32_t clock_enable_mask;
59 uint8_t gclk_id;
63
64#endif
65
66extern const tc_instance_details_t TC_Peripherals[];
67extern const uint8_t Num_TC_Instances;
68extern const uint8_t TC_First_Index;
69
70extern const tcc_instance_details_t TCC_Peripherals[];
71extern const uint8_t Num_TCC_Instances;
72
73extern const sercom_instance_details_t SERCOM_Peripherals[];
74extern const uint8_t Num_SERCOM_Instances;
75
76#if !defined(__EMSCRIPTEN__) && !defined(_SAMD21_) && !defined(_SAMD11_)
85static inline void _gclk_pchctrl_configure(uint8_t id, generic_clock_generator_t gen) {
86 GCLK->PCHCTRL[id].reg &= ~GCLK_PCHCTRL_CHEN;
87 while (GCLK->PCHCTRL[id].bit.CHEN);
88 GCLK->PCHCTRL[id].reg = GCLK_PCHCTRL_GEN(gen);
89 GCLK->PCHCTRL[id].reg = GCLK_PCHCTRL_GEN(gen) | GCLK_PCHCTRL_CHEN;
90 while (!GCLK->PCHCTRL[id].bit.CHEN);
91}
92#endif
93
95
130void sys_init(void);
131
135uint32_t get_cpu_frequency(void);
136
162bool set_cpu_frequency(uint32_t freq);
163
180
198void set_light_sleep_enabled(bool enabled);
199
205
213
void _enter_standby_mode(void)
Enters the configured sleep mode. Does not return until an interrupt fires.
bool set_cpu_frequency(uint32_t freq)
Sets the CPU frequency.
void set_light_sleep_enabled(bool enabled)
Enables or disables light sleep mode.
uint32_t get_cpu_frequency(void)
Gets the CPU frequency.
bool get_light_sleep_enabled(void)
Gets whether light sleep mode is enabled.
void sys_init(void)
Initializes the system clocks and performs any required system-wide setup.
void _enable_48mhz_gclk1(void)
Enables the 48 MHz clock on GCLK1 for USB operation.
Definition system.h:56
uint8_t interrupt_line_count
number of consecutive NVIC lines (1 on most chips; more on SAM D51)
Definition system.h:61
uint8_t interrupt_line
first (or only) NVIC interrupt line for this instance
Definition system.h:60
Definition system.h:40
uint8_t interrupt_line
first (or only) NVIC interrupt line for this instance
Definition system.h:44
uint8_t interrupt_line_count
number of consecutive NVIC lines (1 on most chips; more on SAM D51)
Definition system.h:45
Definition system.h:48
uint8_t interrupt_line_count
number of consecutive NVIC lines (1 on most chips; more on SAM D51)
Definition system.h:53
uint8_t interrupt_line
first (or only) NVIC interrupt line for this instance
Definition system.h:52