2020-10-17 14:31:55 -05:00
|
|
|
#!/usr/bin/python3
|
2019-01-07 21:16:31 -06:00
|
|
|
import os
|
|
|
|
import struct
|
|
|
|
|
|
|
|
PORT_RES = '/dev/port'
|
|
|
|
|
|
|
|
|
|
|
|
def portio_reg_write(resource, offset, val):
|
|
|
|
fd = os.open(resource, os.O_RDWR)
|
|
|
|
if(fd < 0):
|
2020-10-17 14:31:55 -05:00
|
|
|
print('file open failed %s' % resource)
|
2019-01-07 21:16:31 -06:00
|
|
|
return
|
|
|
|
if(os.lseek(fd, offset, os.SEEK_SET) != offset):
|
2020-10-17 14:31:55 -05:00
|
|
|
print('lseek failed on %s' % resource)
|
2019-01-07 21:16:31 -06:00
|
|
|
return
|
|
|
|
ret = os.write(fd, struct.pack('B', val))
|
|
|
|
if(ret != 1):
|
2020-10-17 14:31:55 -05:00
|
|
|
print('write failed %d' % ret)
|
2019-01-07 21:16:31 -06:00
|
|
|
return
|
|
|
|
os.close(fd)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
portio_reg_write(PORT_RES, 0xcf9, 0xe)
|