Code: Select all
import os
bdev = RAMBlockDev(512, 5) # ~2K5
os.VfsFat.mkfs(bdev)
os.mount(bdev, '/ramdisk')
Code: Select all
class RAMBlockDev:
def __init__(self, block_size, num_blocks):
self.block_size = block_size
self.data = bytearray(block_size * num_blocks)
def readblocks(self, block_num, buf):
for i in range(len(buf)):
buf[i] = self.data[block_num * self.block_size + i]
def writeblocks(self, block_num, buf):
for i in range(len(buf)):
self.data[block_num * self.block_size + i] = buf[i]
def ioctl(self, op, arg):
if op == 4: # get number of blocks
return len(self.data) // self.block_size
if op == 5: # get block size
return self.block_size
Code: Select all
# put header in a new datalog.csv file
try:
with open('/ramdisk/datalog.csv', 'w') as outfile:
outfile.write('Time' + ',' 'Batt voltage' + '\n')
except OSError as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write(str(error) + '\n')
except OSError:
print('oops')
/ramdisk and the device re-boots ... with no messages in errors.txt.
gc.mem_free() indicates that there is 4-5 times more memory available
than the 2K5 used for /ramdisk
Could someone suggest where to throw some error-trapping into
class RAMBlockDev to gain some insight into what is going wrong?
Thanks