-
Notifications
You must be signed in to change notification settings - Fork 1
/
peripheralScript.py
executable file
·72 lines (59 loc) · 1.17 KB
/
peripheralScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
import json
base = """
package caravan.bus.common
import chisel3._
import chisel3.experimental.ChiselEnum
"""
dccm = """
object Peripherals extends ChiselEnum {
val DCCM = Value(0.U)
"""
closer = "}"
file1 = open("src/main/scala/config.json")
data = json.load(file1)
file1.close()
main_str = base + dccm
dev_count = 1
if data["gpio"] == 1:
gpio = f"""
val GPIO = Value({dev_count}.U)
"""
main_str += gpio
dev_count += 1
if data["spi"] == 1:
spi = f"""
val SPI = Value({dev_count}.U)
"""
main_str += spi
dev_count += 1
if data["uart"] == 1:
uart = f"""
val UART = Value({dev_count}.U)
"""
main_str += uart
dev_count += 1
if data["timer"] == 1:
timer = f"""
val TIMER = Value({dev_count}.U)
"""
main_str += timer
dev_count += 1
if data["spi_flash"] == 1:
spi_f = f"""
val SPIFLASH = Value({dev_count}.U)
"""
main_str += spi_f
dev_count += 1
if data["i2c"] == 1:
i2c = f"""
val I2C = Value({dev_count}.U)
"""
main_str += i2c
dev_count += 1
main_str += closer
print(main_str)
caravan_path = "caravan/src/main/scala/caravan/bus/common/PeripheralsMap.scala"
file2 = open(caravan_path, "w")
file2.write(main_str)
file2.close()