2015-09-27 07:45:48 -04:00
|
|
|
from machine import Pin
|
|
|
|
from machine import RTC
|
|
|
|
import time
|
2015-08-09 08:30:50 -04:00
|
|
|
import os
|
|
|
|
|
|
|
|
"""
|
|
|
|
Execute it like this:
|
|
|
|
|
2021-03-11 00:09:27 -05:00
|
|
|
python3 run-tests.py --target wipy --device 192.168.1.1 ../cc3200/tools/smoke.py
|
2015-08-09 08:30:50 -04:00
|
|
|
"""
|
|
|
|
|
2015-08-19 07:59:33 -04:00
|
|
|
pin_map = [23, 24, 11, 12, 13, 14, 15, 16, 17, 22, 28, 10, 9, 8, 7, 6, 30, 31, 3, 0, 4, 5]
|
2015-08-20 02:21:12 -04:00
|
|
|
test_bytes = os.urandom(1024)
|
2015-08-09 08:30:50 -04:00
|
|
|
|
2020-02-26 23:36:53 -05:00
|
|
|
|
|
|
|
def test_pin_read(pull):
|
2015-08-09 08:30:50 -04:00
|
|
|
# enable the pull resistor on all pins, then read the value
|
|
|
|
for p in pin_map:
|
2020-02-26 23:36:53 -05:00
|
|
|
pin = Pin("GP" + str(p), mode=Pin.IN, pull=pull)
|
2015-08-09 08:30:50 -04:00
|
|
|
# read the pin value
|
2015-08-20 02:21:12 -04:00
|
|
|
print(pin())
|
2015-08-09 08:30:50 -04:00
|
|
|
|
2020-02-26 23:36:53 -05:00
|
|
|
|
|
|
|
def test_pin_shorts(pull):
|
2015-09-27 07:45:48 -04:00
|
|
|
if pull == Pin.PULL_UP:
|
|
|
|
pull_inverted = Pin.PULL_DOWN
|
2015-08-09 08:30:50 -04:00
|
|
|
else:
|
2015-09-27 07:45:48 -04:00
|
|
|
pull_inverted = Pin.PULL_UP
|
2015-08-09 08:30:50 -04:00
|
|
|
# enable all pulls of the specified type
|
|
|
|
for p in pin_map:
|
2020-02-26 23:36:53 -05:00
|
|
|
pin = Pin("GP" + str(p), mode=Pin.IN, pull=pull_inverted)
|
2015-08-09 08:30:50 -04:00
|
|
|
# then change the pull one pin at a time and read its value
|
|
|
|
i = 0
|
|
|
|
while i < len(pin_map):
|
2020-02-26 23:36:53 -05:00
|
|
|
pin = Pin("GP" + str(pin_map[i]), mode=Pin.IN, pull=pull)
|
|
|
|
Pin("GP" + str(pin_map[i - 1]), mode=Pin.IN, pull=pull_inverted)
|
2015-08-09 08:30:50 -04:00
|
|
|
i += 1
|
|
|
|
# read the pin value
|
2015-08-20 02:21:12 -04:00
|
|
|
print(pin())
|
2015-08-09 08:30:50 -04:00
|
|
|
|
2020-02-26 23:36:53 -05:00
|
|
|
|
2015-09-27 07:45:48 -04:00
|
|
|
test_pin_read(Pin.PULL_UP)
|
|
|
|
test_pin_read(Pin.PULL_DOWN)
|
|
|
|
test_pin_shorts(Pin.PULL_UP)
|
|
|
|
test_pin_shorts(Pin.PULL_DOWN)
|
2015-08-09 08:30:50 -04:00
|
|
|
|
|
|
|
# create a test directory
|
2020-02-26 23:36:53 -05:00
|
|
|
os.mkdir("/flash/test")
|
|
|
|
os.chdir("/flash/test")
|
2015-08-09 08:30:50 -04:00
|
|
|
print(os.getcwd())
|
|
|
|
# create a new file
|
2020-02-26 23:36:53 -05:00
|
|
|
f = open("test.txt", "w")
|
2015-08-20 02:21:12 -04:00
|
|
|
n_w = f.write(test_bytes)
|
|
|
|
print(n_w == len(test_bytes))
|
2015-08-09 08:30:50 -04:00
|
|
|
f.close()
|
2020-02-26 23:36:53 -05:00
|
|
|
f = open("test.txt", "r")
|
|
|
|
r = bytes(f.read(), "ascii")
|
2015-08-09 08:30:50 -04:00
|
|
|
# check that we can write and read it correctly
|
2015-08-20 02:21:12 -04:00
|
|
|
print(r == test_bytes)
|
2015-08-09 08:30:50 -04:00
|
|
|
f.close()
|
2020-02-26 23:36:53 -05:00
|
|
|
os.remove("test.txt")
|
|
|
|
os.chdir("..")
|
|
|
|
os.rmdir("test")
|
2015-08-09 08:30:50 -04:00
|
|
|
|
|
|
|
ls = os.listdir()
|
2020-02-26 23:36:53 -05:00
|
|
|
print("test" not in ls)
|
2015-08-09 08:30:50 -04:00
|
|
|
print(ls)
|
|
|
|
|
2015-08-19 07:59:33 -04:00
|
|
|
# test the real time clock
|
2015-09-27 07:45:48 -04:00
|
|
|
rtc = RTC()
|
2015-09-16 08:09:51 -04:00
|
|
|
while rtc.now()[6] > 800:
|
2015-08-19 07:59:33 -04:00
|
|
|
pass
|
|
|
|
|
2015-09-16 08:09:51 -04:00
|
|
|
time1 = rtc.now()
|
2015-09-27 07:45:48 -04:00
|
|
|
time.sleep_ms(1000)
|
2015-09-16 08:09:51 -04:00
|
|
|
time2 = rtc.now()
|
|
|
|
print(time2[5] - time1[5] == 1)
|
2020-02-26 23:36:53 -05:00
|
|
|
print(time2[6] - time1[6] < 5000) # microseconds
|