Class: OrigenLink::Server::Sequencer
- Inherits:
-
Object
- Object
- OrigenLink::Server::Sequencer
- Defined in:
- lib/origen_link/server/sequencer.rb
Instance Attribute Summary collapse
-
#cycletiming ⇒ Object
readonly
Returns the value of attribute cycletiming.
-
#patternorder ⇒ Object
readonly
Returns the value of attribute patternorder.
-
#patternpinindex ⇒ Object
readonly
Returns the value of attribute patternpinindex.
-
#pinmap ⇒ Object
readonly
Returns the value of attribute pinmap.
Instance Method Summary collapse
-
#initialize ⇒ Sequencer
constructor
initialize method Create empty pinmap, pattern pin index and pattern order instance variables.
-
#new_timeset(tset) ⇒ Object
new_timeset(tset) creates a new empty timeset hash.
-
#pin_assign(args) ⇒ Object
pin_assign method arguments: <args> from the message request see “processmessage” method returns: “P:” or error message.
-
#pin_clear ⇒ Object
pin_clear method.
-
#pin_cycle(args) ⇒ Object
pin_cycle method arguments: <args> from the message request returns: “P:” or “F:” followed by results.
-
#pin_format(args) ⇒ Object
pin_format method arguments: <args> from the message request Should be <timeset>,<pin>,rl or rh multi-clock not currently supported.
-
#pin_patternorder(args) ⇒ Object
pin_patternorder method arguments: <args> from the message request returns: “P:” or error message.
-
#pin_timing(args) ⇒ Object
pin_timing method arguments: <args> from the message request Should be ‘1,pin,-1,pin2,0,pin3,1’ First integer is timeset number If argument is ”, default timing is created Default timeset number is 0, this is used if no timeset is explicitly defined.
-
#process_events(events, pindata) ⇒ Object
process_events used by pin_cycle to avoid duplicating code.
-
#process_pindata(pin, data) ⇒ Object
process_pindata method arguments: pin: the pin object to be operated on data: the pin data to be executed returns: the drive data or read data.
-
#processmessage(message) ⇒ Object
processmessage method arguments: message message format is <group>_<command>:<args> returns: message response.
Constructor Details
#initialize ⇒ Sequencer
initialize method
Create empty pinmap, pattern pin index
and pattern order instance variables
59 60 61 62 63 64 |
# File 'lib/origen_link/server/sequencer.rb', line 59 def initialize @pinmap = Hash.new(-1) @patternpinindex = Hash.new(-1) @patternorder = [] @cycletiming = Hash.new(-1) end |
Instance Attribute Details
#cycletiming ⇒ Object (readonly)
Returns the value of attribute cycletiming.
51 52 53 |
# File 'lib/origen_link/server/sequencer.rb', line 51 def cycletiming @cycletiming end |
#patternorder ⇒ Object (readonly)
Returns the value of attribute patternorder.
50 51 52 |
# File 'lib/origen_link/server/sequencer.rb', line 50 def patternorder @patternorder end |
#patternpinindex ⇒ Object (readonly)
Returns the value of attribute patternpinindex.
52 53 54 |
# File 'lib/origen_link/server/sequencer.rb', line 52 def patternpinindex @patternpinindex end |
#pinmap ⇒ Object (readonly)
Returns the value of attribute pinmap.
49 50 51 |
# File 'lib/origen_link/server/sequencer.rb', line 49 def pinmap @pinmap end |
Instance Method Details
#new_timeset(tset) ⇒ Object
new_timeset(tset)
creates a new empty timeset hash
133 134 135 136 |
# File 'lib/origen_link/server/sequencer.rb', line 133 def new_timeset(tset) @cycletiming[tset] = {} @cycletiming[tset]['timing'] = [[], [], []] end |
#pin_assign(args) ⇒ Object
pin_assign method
arguments: <args> from the message request
see "processmessage" method
returns: "P:" or error message
This method creates a pin instance for each
pin in the pin map and builds the pinmap
hash. Before the pinmap is created, any
information from a previous pattern run is
cleared.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/origen_link/server/sequencer.rb', line 110 def pin_assign(args) pin_clear success = true = '' argarr = args.split(',') 0.step(argarr.length - 2, 2) do |index| @pinmap[argarr[index]] = Pin.new(argarr[index + 1]) unless @pinmap[argarr[index]].gpio_valid success = false = + 'pin ' + argarr[index] + ' gpio' + argarr[index + 1] + ' is invalid' end end if success 'P:' else 'F:' + end end |
#pin_clear ⇒ Object
pin_clear method
This method clears all storage objects. It
is called by the "pin_assign" method
343 344 345 346 347 348 349 350 |
# File 'lib/origen_link/server/sequencer.rb', line 343 def pin_clear @pinmap.each { |pin_name, pin| pin.destroy } @pinmap.clear @patternpinindex.clear @patternorder.delete_if { true } @cycletiming.clear 'P:' end |
#pin_cycle(args) ⇒ Object
pin_cycle method
arguments: <args> from the message request
returns: "P:" or "F:" followed by results
This method executes one cycle of pin vector
data. The vector data is decomposed and
sequenced. Each pin object and pin data
is passed to the "process_pindata" method
for decoding and execution
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/origen_link/server/sequencer.rb', line 226 def pin_cycle(args) # set default repeats and timeset repeat_count = 1 tset = 0 if args =~ /,/ parsedargs = args.split(',') args = parsedargs.pop parsedargs.each do |arg| if arg =~ /repeat/ repeat_count = arg.sub(/repeat/, '').to_i elsif arg =~ /tset/ tset = arg.sub(/tset/, '').to_i end end end = '' pindata = args.split('') @cycle_failure = false 0.upto(repeat_count - 1) do |count| response = {} # process time 0 events response = process_events(@cycletiming[tset]['timing'][0], pindata) # send drive data for return format pins response = (process_events(@cycletiming[tset]['rl'], pindata)).merge(response) response = (process_events(@cycletiming[tset]['rh'], pindata)).merge(response) # process time 1 events response = process_events(@cycletiming[tset]['timing'][1], pindata).merge(response) # send return data unless @cycletiming[tset]['rl'].nil? @cycletiming[tset]['rl'].each do |pin| process_pindata(@pinmap[pin], '0') end end unless @cycletiming[tset]['rh'].nil? @cycletiming[tset]['rh'].each do |pin| process_pindata(@pinmap[pin], '1') end end # process time 2 events response = process_events(@cycletiming[tset]['timing'][2], pindata).merge(response) if (count == 0) || (@cycle_failure) = '' @patternorder.each do |pin| += response[pin] end end end # end cycle through repeats if @cycle_failure rtnmsg = 'F:' + + ' Expected:' + args else rtnmsg = 'P:' + end rtnmsg += ' Repeat ' + repeat_count.to_s if repeat_count > 1 rtnmsg end |
#pin_format(args) ⇒ Object
pin_format method
arguments: <args> from the message request
Should be <timeset>,<pin>,rl or rh
multi-clock not currently supported
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/origen_link/server/sequencer.rb', line 145 def pin_format(args) argarr = args.split(',') tset_key = argarr.delete_at(0).to_i new_timeset(tset_key) unless @cycletiming.key?(tset_key) @cycletiming[tset_key].delete('rl') @cycletiming[tset_key].delete('rh') 0.step(argarr.length - 2, 2) do |index| @cycletiming[tset_key][argarr[index + 1]] = [] unless @cycletiming[tset_key].key?(argarr[index + 1]) @cycletiming[tset_key][argarr[index + 1]] << argarr[index] end 'P:' end |
#pin_patternorder(args) ⇒ Object
pin_patternorder method
arguments: <args> from the message request
returns: "P:" or error message
This method is used to define the order
for pin vector data.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/origen_link/server/sequencer.rb', line 198 def pin_patternorder(args) argarr = args.split(',') index = 0 if @cycletiming.key?(0) @cycletiming[0]['timing'][0].delete_if { true } else new_timeset(0) end argarr.each do |pin| @patternorder << pin @patternpinindex[pin] = index @cycletiming[0]['timing'][0] << pin index += 1 end 'P:' end |
#pin_timing(args) ⇒ Object
pin_timing method
arguments: <args> from the message request
Should be '1,pin,-1,pin2,0,pin3,1'
First integer is timeset number
If argument is '', default timing is created
Default timeset number is 0, this is used
if no timeset is explicitly defined
cycle arg: 0 1 2
waveform : ___/***\___
returns "P:" or error message
This method sets up a time set. All retrun
format pins are driven between 0 and 1 and
return between 1 and 2. Non-return pins are
acted upon during the 0, 1 or 2 time period.
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/origen_link/server/sequencer.rb', line 177 def pin_timing(args) argarr = args.split(',') tset_key = argarr.delete_at(0).to_i new_timeset(tset_key) unless @cycletiming.key?(tset_key) @cycletiming[tset_key]['timing'].each do |index| index.delete_if { true } end 0.step(argarr.length - 2, 2) do |index| @cycletiming[tset_key]['timing'][argarr[index + 1].to_i] << argarr[index] end 'P:' end |
#process_events(events, pindata) ⇒ Object
process_events
used by pin_cycle to avoid duplicating code
287 288 289 290 291 292 293 294 295 |
# File 'lib/origen_link/server/sequencer.rb', line 287 def process_events(events, pindata) response = {} unless events.nil? events.each do |pin| response[pin] = process_pindata(@pinmap[pin], pindata[@patternpinindex[pin]]) end end response end |
#process_pindata(pin, data) ⇒ Object
process_pindata method
arguments:
pin: the pin object to be operated on
data: the pin data to be executed
returns: the drive data or read data
This method translates pin data into one
of three possible events. Drive 0, drive 1
or read. Supported character decode:
drive 0: '0'
drive 1: '1'
read: anything else
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/origen_link/server/sequencer.rb', line 311 def process_pindata(pin, data) if data == '0' || data == '1' pin.out(data) data else case pin.in when '0' @cycle_failure = true if data == 'H' if data == 'X' '.' else 'L' end when '1' @cycle_failure = true if data == 'L' if data == 'X' '`' else 'H' end else 'W' end end end |
#processmessage(message) ⇒ Object
processmessage method
arguments: message
message format is <group>_<command>:<args>
returns: message response
This method splits a message into it's
command and arguments and passes this
information to the method that performs
the requested command
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/origen_link/server/sequencer.rb', line 77 def () command = .split(':') case command[0] when 'pin_assign' pin_assign(command[1]) when 'pin_patternorder' pin_patternorder(command[1]) when 'pin_cycle' pin_cycle(command[1]) when 'pin_clear' pin_clear when 'pin_format' pin_format(command[1]) when 'pin_timing' pin_timing(command[1]) else 'Error Invalid command: ' + command[0].to_s end end |