8000
We read every piece of feedback, and take your input very seriously.
time
1 parent bac841d commit 211b44eCopy full SHA for 211b44e
atmel-samd/Makefile
@@ -213,11 +213,12 @@ SRC_C = \
213
214
SRC_COMMON_HAL = \
215
board/__init__.c \
216
+ digitalio/__init__.c \
217
+ digitalio/DigitalInOut.c \
218
microcontroller/__init__.c \
219
microcontroller/Pin.c \
220
microcontroller/Processor.c \
- digitalio/__init__.c \
- digitalio/DigitalInOut.c
221
+ time/__init__.c
222
# analogio/__init__.c \
223
analogio/AnalogIn.c \
224
analogio/AnalogOut.c \
@@ -238,7 +239,6 @@ SRC_COMMON_HAL = \
238
239
pulseio/PulseOut.c \
240
pulseio/PWMOut.c \
241
storage/__init__.c \
- time/__init__.c \
242
touchio/__init__.c \
243
touchio/TouchIn.c \
244
usb_hid/__init__.c \
atmel-samd/asf4_conf/samd21/peripheral_clk_config.h
@@ -41,7 +41,7 @@
41
* \brief CPU's Clock frequency
42
*/
43
#ifndef CONF_CPU_FREQUENCY
44
-#define CONF_CPU_FREQUENCY 1000000
+#define CONF_CPU_FREQUENCY 48000000
45
#endif
46
47
// <y> Core Clock Source
atmel-samd/common-hal/microcontroller/Processor.c
@@ -63,6 +63,7 @@
63
64
#include "common-hal/microcontroller/Processor.h"
65
66
+#include "peripheral_clk_config.h"
67
68
// #define ADC_TEMP_SAMPLE_LENGTH 4
69
// #define INT1V_VALUE_FLOAT 1.0
@@ -226,6 +227,6 @@ float common_hal_mcu_processor_get_temperature(void) {
226
227
228
229
uint32_t common_hal_mcu_processor_get_frequency(void) {
- return 0;
230
- //return system_cpu_clock_get_hz();
+ // TODO(tannewt): Determine this dynamically.
231
+ return CONF_CPU_FREQUENCY;
232
}
atmel-samd/mpconfigport.h
@@ -203,7 +203,6 @@ extern const struct _mp_obj_module_t usb_hid_module;
203
// { MP_OBJ_NEW_QSTR(MP_QSTR_touchio), (mp_obj_t)&touchio_module },
204
// { MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module },
205
// { MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module },
206
-// { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module },
207
// { MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module },
208
// { MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid),(mp_obj_t)&usb_hid_module },
209
// { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module },
@@ -213,9 +212,10 @@ extern const struct _mp_obj_module_t usb_hid_module;
212
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)µcontroller_module }, \
- { MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)µcontroller_module }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module },
EXTRA_BUILTIN_MODULES
#define MICROPY_PORT_BUILTIN_DEBUG_MODULES \
atmel-samd/mphalport.c
@@ -18,6 +18,7 @@
18
#include "mpconfigboard.h"
19
#include "mphalport.h"
20
#include "reset.h"
21
+#include "tick.h"
22
#include "usb.h"
23
24
extern struct usart_module usart_instance;
@@ -64,7 +65,7 @@ void mp_hal_delay_ms(mp_uint_t delay) {
void mp_hal_delay_us(mp_uint_t delay) {
- delay_us(delay);
+ tick_delay(delay);
70
71
void mp_hal_disable_all_interrupts(void) {
atmel-samd/supervisor/port.c
@@ -89,8 +89,6 @@ safe_mode_t port_init(void) {
89
90
init_mcu();
91
92
- delay_init(SysTick);
93
-
94
board_init();
95
96
// Configure millisecond timer initialization.
atmel-samd/tick.c
@@ -1,24 +1,40 @@
1
+/*
2
+ * This file is part of the MicroPython project, http://micropython.org/
3
+ *
4
+ * The MIT License (MIT)
5
6
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
25
+ */
26
27
28
-#include <peripheral_clk_config.h>
-#include "hal/include/hal_timer.h"
-#include "hpl/pm/hpl_pm_base.h"
-#include "hpl/tc/hpl_tc_base.h"
-#include "hpl/gclk/hpl_gclk_base.h"
-#include "include/component/gclk.h"
29
30
31
#include "supervisor/shared/autoreload.h"
-#include "tick.h"
32
+#include "shared-bindings/microcontroller/Processor.h"
33
34
// Global millisecond tick count
35
volatile uint64_t ticks_ms = 0;
36
-struct timer_descriptor ms_timer;
-//static struct timer_task task;
-void timer_tick(const struct timer_task *const timer_task) {
37
+void SysTick_Handler(void) {
38
// SysTick interrupt handler called when the SysTick timer reaches zero
39
// (every millisecond).
40
ticks_ms += 1;
@@ -29,18 +45,20 @@ void timer_tick(const struct timer_task *const timer_task) {
void tick_init() {
- #ifdef SAMD21
- _pm_enable_bus_clock(PM_BUS_APBC, TC5);
- #endif
- // _gclk_enable_channel(TC5_GCLK_ID, GCLK_SOURCE_DFLL48M);
- // timer_init(&ms_timer, TC5, _tc_get_timer());
48
+ uint32_t ticks_per_ms = common_hal_mcu_processor_get_frequency() / 1000;
49
+ SysTick_Config(ticks_per_ms);
50
+ NVIC_EnableIRQ(SysTick_IRQn);
51
+}
52
- // timer_set_clock_cycles_per_tick(&ms_timer, 48000000 / 1000 - 1);
- // task.cb = timer_tick;
- // task.interval = 1;
- // task.mode = TIMER_TASK_REPEAT;
- // timer_add_task(&ms_timer, &task);
- //
- // timer_start(&ms_timer);
53
+void tick_delay(uint32_t us) {
54
+ uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency() / 1000 / 1000;
55
+ uint32_t us_between_ticks = SysTick->VAL / ticks_per_us;
56
+ uint64_t start_ms = ticks_ms;
57
+ while (us > 1000) {
58
+ while (ticks_ms == start_ms) {}
59
+ us -= us_between_ticks;
60
+ start_ms = ticks_ms;
61
+ us_between_ticks = 1000;
62
+ }
+ while (SysTick->VAL > ((1000 - us) * ticks_per_us)) {}
atmel-samd/tick.h
@@ -34,4 +34,6 @@ extern struct timer_descriptor ms_timer;
void tick_init(void);
+void tick_delay(uint32_t us);
+
#endif // MICROPY_INCLUDED_ATMEL_SAMD_TICK_H