Skip to content

Commit

Permalink
Добавление методички 14ой лабы и пустого ридми 15-ой
Browse files Browse the repository at this point in the history
  • Loading branch information
HepoH3 committed Dec 17, 2023
1 parent 2df86a1 commit 37e0c04
Show file tree
Hide file tree
Showing 10 changed files with 1,598 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
- [Лабораторная №11. Интеграция подсистемы прерываний](Labs/11.%20Interrupt%20integration/README.md)
- [Лабораторная №12. Периферийные устройства](Labs/12.%20Peripheral%20units/README.md)
- [Лабораторная №13. Программирование](Labs/13.%20Programming/README.md)
- [Лабораторная №14. Программатор](Labs/14.%20Programming%20device/README.md)
- [Лабораторная №15. Оценка производительности](Labs/14.%20Coremark/README.md)

---

Expand Down
Binary file added .pic/Labs/lab_14_programming_device/fig_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
509 changes: 509 additions & 0 deletions Labs/14. Programming device/README.md

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions Labs/14. Programming device/flash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import argparse
import serial

parser = argparse.ArgumentParser()
parser.add_argument("instr", type=str, help="File for instr mem initialization")
parser.add_argument("comport", type=str, help="COM-port name")
parser.add_argument("-d", "--data", type=str, help="File for data mem initialization")
parser.add_argument("-t", "--tiff", type=str, help="File for tiff mem initialization")

args = parser.parse_args()

def parse_file(fname: str, base: int = 16, word_size: int = 2) -> bytes:
res_bytes=b''
with open(fname, 'r') as fp:
for line in fp:
if line[0] == '@':
continue
for word in line.split():
res_bytes += bytes(int(word,base).to_bytes(len(word)//word_size,"little"))
return res_bytes[::-1]

def flash(data: bytes, port: serial.Serial, mem_name: str):
assert(len(mem_name) == 4)

if data:
data_len = len(data)
else:
data_len = 0
data_len_bytes = data_len.to_bytes(4, "big")
port.write(data_len_bytes)

data_len_ack = port.read(4)
print(int.from_bytes(data_len_ack,"big"))
assert(data_len_ack == data_len_bytes)

if(data):
port.write(data)

print("finished write {} mem".format(mem_name))

data_flash_ack = port.read(10)
data_flash_ack_str = data_flash_ack.decode("ascii")
print(data_flash_ack_str)
assert(data_flash_ack_str == "{} done\n".format(mem_name))



# Main block

inst_file = args.instr
data_file = args.data
tiff_file = args.tiff
com = args.comport

instr = parse_file(inst_file)

if data_file:
data = parse_file(data_file)
else:
data = b''

if tiff_file:
tiff = parse_file(tiff_file, 2, 8)
else:
tiff = b''


ser = serial.Serial(
port=com,
baudrate=115200,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=None
)

init_msg = ser.read(6)
print(init_msg.decode("ascii"))
assert(init_msg == b'ready\n')

flash(instr, ser, "inst")
flash(data, ser, "data")
flash(tiff, ser, "tiff")
Loading

0 comments on commit 37e0c04

Please sign in to comment.