module RPicSim::Sim::ClassDefinitionMethods
These methods should be called while defining a subclass of {Sim}.
Public Instance Methods
Define a pin alias.
@param our_name [Symbol] Specifies what you would like to
call the pin. A method with this name will be added to your class's +Shortcuts+ module so it is available as a method on instances of your class and also in your RSpec tests.
@param datasheet_name [Symbol] A symbol like :RB3 that specifies what pin it is.
# File lib/rpicsim/sim.rb, line 72 def def_pin(our_name, datasheet_name) our_name = our_name.to_sym @pin_aliases[our_name] = datasheet_name.to_sym self::Shortcuts.send(:define_method, our_name) { pin our_name } end
Define a symbol. Normally symbols are loaded by {#use_file} or {#import_symbols}, but this method allows for adding additional symbols one at a time.
See {RPicSim::ProgramFile#def_symbol} for details about the parameters this method takes.
# File lib/rpicsim/sim.rb, line 61 def def_symbol(name, address, memory_type = nil) program_file.def_symbol name, address, memory_type end
Define a variable. @param name [Symbol] Specifies what you would like to call the variable.
A method with this name will be added to your class's +Shortcuts+ module so it is available as a method on instances of your class and also in your RSpec tests. The method will return a {Variable} object that you can use to read or write the value of the actual variable in the simulation.
@param type [Symbol] Specifies how to interpret the data in the variable and its size.
For integers, it should be one of +:uint8+, +:int8+, +:uint16+, +:int16+, +:uint24+, +:int24+, +:uint32+, +:int32+, or +:word+. The +s+ stands for signed and the +u+ stands for unsigned, and the number stands for the number of bits. All multi-byte integers are considered to be little Endian.
@param opts [Hash] Specifies additional options. The options are:
* +:memory+: Specifies the memory that the variable lives in. Valid values are +:ram+ (default), +:eeprom+, and +:program_memory+. * +:symbol+: By default, we look for a symbol with the same name as the variable and use that as the location of the variable. This option lets you specify a different symbol to look for in the firmware, so you could call the variable one thing in your firmware and call it a different thing in your tests. This option is ignored if +:address is specified. * +:address+: An integer to use as the address of the variable.
# File lib/rpicsim/sim.rb, line 98 def def_var(name, type, opts = {}) if @variable_set.nil? raise 'The device and filename need to be specified before defining variables.' end @variable_set.def_var(name, type, opts) self::Shortcuts.send(:define_method, name) { var name } end
Specifies additional symbols to use in the simulation. Symbols might be loaded from the program file when you call {#use_file}, but if those symbols are not sufficient then you can call this method to incorporate another source of symbols.
See {RPicSim::ProgramFile#import_symbols} for details on what the parameter should be.
# File lib/rpicsim/sim.rb, line 51 def import_symbols(symbol_source) program_file.import_symbols(symbol_source) end
Specifies what exact device the firmware runs on. @param device [String] The device name, for example “PIC10F322”.
# File lib/rpicsim/sim.rb, line 29 def use_device(device) @device = device @assembly = Mplab::MplabAssembly.new(device) end
Specifies the path to the firmware file. The file can be a HEX or COF file, but COF is recommended so that you can access symbol/label addresses and other debugging information. You must call {#use_device} before calling this.
# File lib/rpicsim/sim.rb, line 38 def use_file(filename) raise "The device needs to be specified before filename (e.g. 'use_device \"PIC10F322\"')" unless @device @filename = filename.to_s load_program_file end