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