From 266be307770abe11c220eb493388807920914b7a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 25 Aug 2017 13:00:27 -0700 Subject: atmel-samd: Introduce a nvm module for non-volatile byte-level memory access. (#203) * atmel-samd: Introduce a nvm module for non-volatile byte-level memory access. This allows for persisting small configuration values even when the file system is read-only from CircuitPython. Fixes #160 * Review feedback: * Add tests. * Fix non-zero index. * Fix len() --- tests/circuitpython/nvm_not_present.py | 6 ++++++ tests/circuitpython/nvm_present.py | 22 ++++++++++++++++++++++ tests/skip_if.py | 11 +++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/circuitpython/nvm_not_present.py create mode 100644 tests/circuitpython/nvm_present.py (limited to 'tests') diff --git a/tests/circuitpython/nvm_not_present.py b/tests/circuitpython/nvm_not_present.py new file mode 100644 index 000000000..141e60b01 --- /dev/null +++ b/tests/circuitpython/nvm_not_present.py @@ -0,0 +1,6 @@ +import skip_if +skip_if.board_not_in("gemma_m0", "trinket_m0") + +import microcontroller + +assert(microcontroller.nvm == None) diff --git a/tests/circuitpython/nvm_present.py b/tests/circuitpython/nvm_present.py new file mode 100644 index 000000000..a2cf3a22c --- /dev/null +++ b/tests/circuitpython/nvm_present.py @@ -0,0 +1,22 @@ +import skip_if +skip_if.board_not_in("metro_m0_express", "feather_m0_express", "circuitplayground_express") + +import microcontroller +import random +nvm = microcontroller.nvm + +len(nvm) + +single = random.randint(0, 255) +nvm[1] = single +assert(nvm[1] == single) + +nvm[0] = single +assert(nvm[0] == single) + +b = bytearray() +for i in range(10): + b.append(random.randint(0, 255)) + +microcontroller.nvm[10:20] = b +assert(microcontroller.nvm[10:20] == b) diff --git a/tests/skip_if.py b/tests/skip_if.py index f6d22b4c1..7b1e06871 100644 --- a/tests/skip_if.py +++ b/tests/skip_if.py @@ -52,6 +52,17 @@ def board_in(*board): if test_env.board in board: skip() +def board_not_in(*board): + try: + import test_env + except ImportError: + class Env: + def __init__(self, board): + self.board = board + test_env = Env("unknown") + if test_env.board not in board: + skip() + def no_cpython_compat(): try: try: -- cgit v1.2.3