Skip to content

Commit ea77228

Browse files
committed
atmel-samd building and passing smoke tets
1 parent 63460de commit ea77228

File tree

19 files changed

+224
-145
lines changed

19 files changed

+224
-145
lines changed

extmod/vfs_fat.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,77 @@ static mp_obj_t vfs_fat_umount(mp_obj_t self_in) {
455455
}
456456
static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount);
457457

458+
// CIRCUITPY-CHANGE
459+
static mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_in) {
460+
mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in);
461+
const char *path = mp_obj_str_get_str(path_in);
462+
if (!mp_obj_is_tuple_compatible(times_in)) {
463+
mp_raise_type_arg(&mp_type_TypeError, times_in);
464+
}
465+
466+
mp_obj_t *otimes;
467+
mp_obj_get_array_fixed_n(times_in, 2, &otimes);
468+
469+
// Validate that both elements of the tuple are int and discard the second one
470+
int time[2];
471+
time[0] = mp_obj_get_int(otimes[0]);
472+
time[1] = mp_obj_get_int(otimes[1]);
473+
timeutils_struct_time_t tm;
474+
timeutils_seconds_since_epoch_to_struct_time(time[0], &tm);
475+
476+
FILINFO fno;
477+
fno.fdate = (WORD)(((tm.tm_year - 1980) * 512U) | tm.tm_mon * 32U | tm.tm_mday);
478+
fno.ftime = (WORD)(tm.tm_hour * 2048U | tm.tm_min * 32U | tm.tm_sec / 2U);
479+
FRESULT res = f_utime(&self->fatfs, path, &fno);
480+
if (res != FR_OK) {
481+
mp_raise_OSError_fresult(res);
482+
}
483+
484+
return mp_const_none;
485+
}
486+
static MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_utime_obj, vfs_fat_utime);
487+
488+
static mp_obj_t vfs_fat_getreadonly(mp_obj_t self_in) {
489+
fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in);
490+
return mp_obj_new_bool(!filesystem_is_writable_by_python(self));
491+
}
492+
static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getreadonly_obj, vfs_fat_getreadonly);
493+
494+
static MP_PROPERTY_GETTER(fat_vfs_readonly_obj,
495+
(mp_obj_t)&fat_vfs_getreadonly_obj);
496+
497+
#if MICROPY_FATFS_USE_LABEL
498+
static mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) {
499+
fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in);
500+
char working_buf[12];
501+
FRESULT res = f_getlabel(&self->fatfs, working_buf, NULL);
502+
if (res != FR_OK) {
503+
mp_raise_OSError_fresult(res);
504+
}
505+
return mp_obj_new_str(working_buf, strlen(working_buf));
506+
}
507+
static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getlabel_obj, vfs_fat_getlabel);
508+
509+
static mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) {
510+
fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in);
511+
verify_fs_writable(self);
512+
const char *label_str = mp_obj_str_get_str(label_in);
513+
FRESULT res = f_setlabel(&self->fatfs, label_str);
514+
if (res != FR_OK) {
515+
if (res == FR_WRITE_PROTECTED) {
516+
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Read-only filesystem"));
517+
}
518+
mp_raise_OSError_fresult(res);
519+
}
520+
return mp_const_none;
521+
}
522+
static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_setlabel_obj, vfs_fat_setlabel);
523+
524+
static MP_PROPERTY_GETSET(fat_vfs_label_obj,
525+
(mp_obj_t)&fat_vfs_getlabel_obj,
526+
(mp_obj_t)&fat_vfs_setlabel_obj);
527+
#endif
528+
458529
static const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = {
459530
// CIRCUITPY-CHANGE: correct name
460531
#if FF_FS_REENTRANT

ports/stm/mpconfigport_nanbox.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

py/asmxtensa.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ void asm_xtensa_l32r(asm_xtensa_t *as, mp_uint_t reg, mp_uint_t label);
311311
#define ASM_XTENSA_REG_TEMPORARY ASM_XTENSA_REG_A6
312312
#define ASM_XTENSA_REG_TEMPORARY_WIN ASM_XTENSA_REG_A12
313313

314-
#if GENERIC_ASM_API
314+
// CIRCUITPY-CHANGE: prevent #if warning
315+
#if defined(GENERIC_ASM_API) && GENERIC_ASM_API
315316

316317
// The following macros provide a (mostly) arch-independent API to
317318
// generate native code, and are used by the native emitter.

py/circuitpy_mpconfig.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
// Always 1: defined in circuitpy_mpconfig.mk
1818
// #define CIRCUITPY (1)
1919

20+
#ifndef MP_SSIZE_MAX
21+
#define MP_SSIZE_MAX (0x7fffffff)
22+
#endif
23+
2024
// REPR_C encodes qstrs, 31-bit ints, and 30-bit floats in a single 32-bit word.
2125
#ifndef MICROPY_OBJ_REPR
2226
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
@@ -303,12 +307,10 @@ typedef long mp_off_t;
303307

304308
#ifdef LONGINT_IMPL_MPZ
305309
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
306-
#define MP_SSIZE_MAX (0x7fffffff)
307310
#endif
308311

309312
#ifdef LONGINT_IMPL_LONGLONG
310313
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
311-
#define MP_SSIZE_MAX (0x7fffffff)
312314
#endif
313315

314316
#ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS

py/emitcommon.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ static bool strictly_equal(mp_obj_t a, mp_obj_t b) {
7979
#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_COMP_CONST_FLOAT
8080
if (a_type == &mp_type_float) {
8181
mp_float_t a_val = mp_obj_float_get(a);
82+
// CIRCUITPY-CHANGE: ignore float equal warning
83+
#pragma GCC diagnostic push
84+
#pragma GCC diagnostic ignored "-Wfloat-equal"
8285
if (a_val == (mp_float_t)0.0) {
8386
// Although 0.0 == -0.0, they are not strictly_equal and
8487
// must be stored as two different constants in .mpy files
8588
mp_float_t b_val = mp_obj_float_get(b);
8689
return signbit(a_val) == signbit(b_val);
8790
}
91+
#pragma GCC diagnostic pop
8892
}
8993
#endif
9094
return true;

py/malloc.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#error MICROPY_ENABLE_FINALISER requires MICROPY_ENABLE_GC
7171
#endif
7272

73+
// CIRCUITPY-CHANGE: Add selective collect support to malloc to optimize GC for large buffers
7374
#if MICROPY_ENABLE_SELECTIVE_COLLECT
7475
#error MICROPY_ENABLE_SELECTIVE_COLLECT requires MICROPY_ENABLE_GC
7576
#endif
@@ -125,32 +126,35 @@ void *m_malloc_helper(size_t num_bytes, uint8_t flags) {
125126
}
126127

127128
void *m_malloc(size_t num_bytes) {
128-
// CIRCUITPY-CHANGE
129+
// CIRCUITPY-CHANGE: use helper
129130
return m_malloc_helper(num_bytes, M_MALLOC_RAISE_ERROR | M_MALLOC_COLLECT);
130131
}
131132

132133
void *m_malloc_maybe(size_t num_bytes) {
133-
// CIRCUITPY-CHANGE
134+
// CIRCUITPY-CHANGE: use helper
134135
return m_malloc_helper(num_bytes, M_MALLOC_COLLECT);
135136
}
136137

137138
#if MICROPY_ENABLE_FINALISER
138139
void *m_malloc_with_finaliser(size_t num_bytes) {
139-
// CIRCUITPY-CHANGE
140+
// CIRCUITPY-CHANGE: use helper
140141
return m_malloc_helper(num_bytes, M_MALLOC_COLLECT | M_MALLOC_WITH_FINALISER);
142+
}
141143
#endif
142144

143145
void *m_malloc0(size_t num_bytes) {
144-
// CIRCUITPY-CHANGE
145-
return m_malloc_helper(num_bytes, M_MALLOC_ENSURE_ZEROED | M_MALLOC_RAISE_ERROR | M_MALLOC_COLLECT);
146+
// CIRCUITPY-CHANGE: use helper
147+
return m_malloc_helper(num_bytes,
148+
(MICROPY_GC_CONSERVATIVE_CLEAR ? 0 : M_MALLOC_ENSURE_ZEROED)
149+
| M_MALLOC_RAISE_ERROR | M_MALLOC_COLLECT);
146150
}
147151

148-
// CIRCUITPY-CHANGE: selective collect
152+
// CIRCUITPY-CHANGE: add selective collect
149153
void *m_malloc_without_collect(size_t num_bytes) {
150154
return m_malloc_helper(num_bytes, M_MALLOC_RAISE_ERROR);
151155
}
152156

153-
// CIRCUITPY-CHANGE: selective collect
157+
// CIRCUITPY-CHANGE: add selective collect
154158
void *m_malloc_maybe_without_collect(size_t num_bytes) {
155159

156160
return m_malloc_helper(num_bytes, 0);

py/misc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
#include <stdbool.h>
3636
#include <stdint.h>
3737
#include <stddef.h>
38-
#if __cplusplus // Required on at least one compiler to get ULLONG_MAX
38+
// CIRCUITPY-CHANGE: #ifdef instead of #if
39+
#ifdef __cplusplus // Required on at least one compiler to get ULLONG_MAX
3940
#include <climits>
4041
#else
4142
#include <limits.h>
@@ -84,7 +85,8 @@ typedef unsigned int uint;
8485
#if defined(_MSC_VER) || defined(__cplusplus)
8586
#define MP_STATIC_ASSERT_NONCONSTEXPR(cond) ((void)1)
8687
#else
87-
// CIRCUITPY-CHANGE: defined()#if defined(__clang__)
88+
// CIRCUITPY-CHANGE: defined()
89+
#if defined(__clang__)
8890
#pragma GCC diagnostic ignored "-Wgnu-folding-constant"
8991
#endif
9092
#define MP_STATIC_ASSERT_NONCONSTEXPR(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
@@ -456,8 +458,6 @@ static inline uint32_t mp_popcount(uint32_t x) {
456458
#define mp_clzll(x) __builtin_clzll(x)
457459
#define mp_ctz(x) __builtin_ctz(x)
458460
#define mp_check(x) (x)
459-
// CIRCUITPY-CHANGE: defined()
460-
#if defined __has_builtin
461461
#if __has_builtin(__builtin_popcount)
462462
#define mp_popcount(x) __builtin_popcount(x)
463463
#else

py/mpconfig.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,6 @@ typedef time_t mp_timestamp_t;
23842384
#ifndef MP_NORETURN
23852385
#define MP_NORETURN __attribute__((noreturn))
23862386
#endif
2387-
#endif // INT_FMT
23882387

23892388
#if !MICROPY_PREVIEW_VERSION_2
23902389
#define NORETURN MP_NORETURN
@@ -2435,6 +2434,11 @@ typedef time_t mp_timestamp_t;
24352434
#define MP_COLD __attribute__((cold))
24362435
#endif
24372436

2437+
// CIRCUITPY-CHANGE: avoid undefined warnings
2438+
#ifndef MICROPY_HAL_HAS_STDIO_MODE_SWITCH
2439+
#define MICROPY_HAL_HAS_STDIO_MODE_SWITCH (0)
2440+
#endif
2441+
24382442
// To annotate that code is unreachable
24392443
#ifndef MP_UNREACHABLE
24402444
#if defined(__GNUC__)

0 commit comments

Comments
 (0)