From d00131973b769384186c09fe866ac844797c985c Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 5 Jun 2018 23:01:13 -0700 Subject: [PATCH] Add script to generate SPI DO files. --- spi_encoder.cr | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 spi_encoder.cr diff --git a/spi_encoder.cr b/spi_encoder.cr new file mode 100644 index 0000000..e922f84 --- /dev/null +++ b/spi_encoder.cr @@ -0,0 +1,42 @@ +require "option_parser" + +encode = "" +slave_pin = "{sim:/cpu_controller/spi_ss}" +data_pin = "{sim:/cpu_controller/spi_mosi}" +clock_pin = "{sim:/cpu_controller/spi_clk}" +unit = "ns" +start = 20 +cycle = 40 + +OptionParser.parse! do |parser| + parser.banner = "Usage: parser [arguments]" + parser.on("-s STRING", "--string=STRING", "Sets the string to be encoded.") do |s| + encode = s + end + parser.on("-u UNIT", "--unit=UNIT", "select the time units.") do |u| + unit = u + end + parser.on("-c CYCLE", "--cycle=CYCLE", "select the clock cycle speed") do |c| + cycle = c.to_i? || 20 + end + parser.on("-b BEGIN", "--begin=BEGIN", "select the beginning of the programming mode") do |b| + start = b.to_i? || 20 + end + parser.on("-s SPIN", "--ss-pin=SPIN", "select the slave select pin") do |sp| + slave_pin = sp + end + parser.on("-d DPIN", "--data-pin=DPIN", "select data pin") do |dp| + data_pin = dp + end + parser.on("-p CPIN", "--clk-pin=CPIN", "select master clock pin") do |cp| + clock_pin = cp + end +end + +STDOUT << "force " << slave_pin << " 0 @ " << start << unit << "\n" +encode.chars.each_with_index do |char, index| + STDOUT << "force " << clock_pin << " 1 @ " << (start + cycle * index) << unit << "\n" + STDOUT << "force " << clock_pin << " 0 @ " << (start + cycle * index + cycle / 2) << unit << "\n" + STDOUT << "force " << data_pin << " " << char << " @ " << (start + cycle * index) << unit << "\n" +end +STDOUT << "force " << slave_pin << " 1 @ " << (start + cycle * (encode.size + 1)) << unit << "\n"