raudi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.rvmrc +1 -1
- data/bin/raudi +17 -0
- data/configuration/atmega_328.yml +69 -0
- data/configuration/avr.yml +61 -0
- data/lib/.DS_Store +0 -0
- data/lib/raudi.rb +58 -9
- data/lib/raudi/.DS_Store +0 -0
- data/lib/raudi/action_processor.rb +34 -26
- data/lib/raudi/avr.rb +4 -0
- data/lib/raudi/avr/.DS_Store +0 -0
- data/lib/raudi/avr/controller.rb +73 -0
- data/lib/raudi/avr/pin.rb +30 -0
- data/lib/raudi/avr/pin_states.rb +73 -0
- data/lib/raudi/avr/port.rb +36 -0
- data/lib/raudi/avr/timer.rb +49 -0
- data/lib/raudi/core_ext.rb +1 -0
- data/lib/raudi/core_ext/fixnum.rb +16 -0
- data/lib/raudi/info.rb +52 -0
- data/lib/raudi/processing.rb +63 -0
- data/lib/raudi/processing/gpio.rb +25 -0
- data/lib/raudi/processing/int.rb +36 -0
- data/lib/raudi/processing/pcint.rb +35 -0
- data/lib/raudi/processing/timer.rb +56 -0
- data/lib/raudi/proxy/.DS_Store +0 -0
- data/lib/raudi/proxy/controller.rb +65 -0
- data/lib/raudi/proxy/external_interrupt.rb +30 -0
- data/lib/raudi/proxy/gpio.rb +19 -0
- data/lib/raudi/proxy/headers.rb +31 -0
- data/lib/raudi/proxy/timer.rb +61 -0
- data/lib/raudi/source.rb +48 -0
- data/lib/raudi/source/action.rb +16 -0
- data/lib/raudi/source/bit_operations.rb +35 -0
- data/lib/raudi/source/block.rb +44 -0
- data/lib/raudi/source/controller.rb +56 -0
- data/lib/raudi/source/function.rb +50 -0
- data/lib/raudi/source/interrupt.rb +35 -0
- data/lib/raudi/source/variable.rb +31 -0
- data/lib/raudi/state_list.rb +17 -0
- data/raudi.gemspec +3 -0
- data/spec/.DS_Store +0 -0
- data/spec/examples/sample.raudi +5 -0
- data/spec/lib/.DS_Store +0 -0
- data/spec/lib/raudi/.DS_Store +0 -0
- data/spec/lib/raudi/action_processor_spec.rb +35 -0
- data/spec/lib/raudi/avr/controller_spec.rb +13 -0
- data/spec/lib/raudi/avr/pin_spec.rb +70 -0
- data/spec/lib/raudi/avr/timer_spec.rb +22 -0
- data/spec/lib/raudi/info_spec.rb +9 -0
- data/spec/lib/raudi/proxy/external_interrupt_spec.rb +22 -0
- data/spec/lib/raudi/proxy/gpio_spec.rb +18 -0
- data/spec/lib/raudi/proxy/headers_spec.rb +34 -0
- data/spec/lib/raudi/proxy/timer_spec.rb +67 -0
- data/spec/lib/raudi/source/external_interrupt_spec.rb +55 -0
- data/spec/lib/raudi/source/gpio_spec.rb +18 -0
- data/spec/lib/raudi/source/main_structure_spec.rb +19 -0
- data/spec/lib/raudi/source/timer_spec.rb +44 -0
- data/spec/lib/raudi_spec.rb +41 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/raudi_spec_helper.rb +27 -0
- metadata +106 -19
- data/examples/actions.raudi +0 -1
- data/examples/config.rb +0 -3
- data/examples/result.c +0 -10
- data/lib/raudi/avr_controller.rb +0 -23
- data/spec/raudi_spec.rb +0 -9
data/.DS_Store
ADDED
Binary file
|
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.9.
|
1
|
+
rvm 1.9.2@raudi --create
|
data/bin/raudi
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'raudi'
|
5
|
+
rescue LoadError
|
6
|
+
require 'rubygems'
|
7
|
+
require 'raudi'
|
8
|
+
end
|
9
|
+
|
10
|
+
puts %Q{
|
11
|
+
Usage:
|
12
|
+
raudi source_file.raudi [options]
|
13
|
+
|
14
|
+
Options:
|
15
|
+
-o, [--output] # Set output file
|
16
|
+
|
17
|
+
} unless Raudi.process(*ARGV)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
frequency: 16000000
|
2
|
+
max_frequency: 20000000
|
3
|
+
ports:
|
4
|
+
b:
|
5
|
+
pc_number: 0
|
6
|
+
pins:
|
7
|
+
0:
|
8
|
+
- pcint_0
|
9
|
+
1:
|
10
|
+
- pcint_1
|
11
|
+
2:
|
12
|
+
- pcint_2
|
13
|
+
3:
|
14
|
+
- pcint_3
|
15
|
+
4:
|
16
|
+
- pcint_4
|
17
|
+
5:
|
18
|
+
- pcint_5
|
19
|
+
6:
|
20
|
+
- pcint_6
|
21
|
+
7:
|
22
|
+
- pcint_7
|
23
|
+
c:
|
24
|
+
pc_number: 1
|
25
|
+
pins:
|
26
|
+
0:
|
27
|
+
- pcint_8
|
28
|
+
1:
|
29
|
+
- pcint_9
|
30
|
+
2:
|
31
|
+
- pcint_10
|
32
|
+
3:
|
33
|
+
- pcint_11
|
34
|
+
4:
|
35
|
+
- pcint_12
|
36
|
+
5:
|
37
|
+
- pcint_13
|
38
|
+
6:
|
39
|
+
- pcint_14
|
40
|
+
d:
|
41
|
+
pc_number: 2
|
42
|
+
pins:
|
43
|
+
0:
|
44
|
+
- pcint_16
|
45
|
+
1:
|
46
|
+
- pcint_17
|
47
|
+
2:
|
48
|
+
- int_0
|
49
|
+
- pcint_18
|
50
|
+
3:
|
51
|
+
- int_1
|
52
|
+
- pcint_19
|
53
|
+
4:
|
54
|
+
- pcint_20
|
55
|
+
- timer_0
|
56
|
+
5:
|
57
|
+
- pcint_21
|
58
|
+
- timer_1
|
59
|
+
6:
|
60
|
+
- pcint_22
|
61
|
+
7:
|
62
|
+
- pcint_23
|
63
|
+
timers:
|
64
|
+
timer_0:
|
65
|
+
length: 8
|
66
|
+
timer_1:
|
67
|
+
length: 16
|
68
|
+
timer_2:
|
69
|
+
length: 8
|
@@ -0,0 +1,61 @@
|
|
1
|
+
headers:
|
2
|
+
avr:
|
3
|
+
- boot
|
4
|
+
- cpufunc
|
5
|
+
- eeprom
|
6
|
+
- fuse
|
7
|
+
- interrupt
|
8
|
+
- io
|
9
|
+
- lock
|
10
|
+
- pgmspace
|
11
|
+
- power
|
12
|
+
- sfr_defs
|
13
|
+
- signature
|
14
|
+
- sleep
|
15
|
+
- version
|
16
|
+
- wdt
|
17
|
+
common:
|
18
|
+
- alloca
|
19
|
+
- assert
|
20
|
+
- ctype
|
21
|
+
- errno
|
22
|
+
- inttypes
|
23
|
+
- math
|
24
|
+
- setjmp
|
25
|
+
- stdint
|
26
|
+
- stdio
|
27
|
+
- stdlib
|
28
|
+
- string
|
29
|
+
util:
|
30
|
+
- atomic
|
31
|
+
- crc16
|
32
|
+
- delay
|
33
|
+
- delay_basic
|
34
|
+
- parity
|
35
|
+
- setbaud
|
36
|
+
- twi
|
37
|
+
|
38
|
+
gpio_states:
|
39
|
+
- input
|
40
|
+
- pullup
|
41
|
+
- output
|
42
|
+
specific_pin_states:
|
43
|
+
- int
|
44
|
+
- pcint
|
45
|
+
- timer
|
46
|
+
|
47
|
+
interrupts:
|
48
|
+
events:
|
49
|
+
low: 0
|
50
|
+
both: 1
|
51
|
+
falling: 2
|
52
|
+
rising: 3
|
53
|
+
timers:
|
54
|
+
prescale:
|
55
|
+
1: 1
|
56
|
+
8: 2
|
57
|
+
64: 3
|
58
|
+
256: 4
|
59
|
+
1024: 5
|
60
|
+
falling: 6
|
61
|
+
rising: 7
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/raudi.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'yaml'
|
1
3
|
require 'raudi/action_processor'
|
2
|
-
require 'raudi/
|
4
|
+
require 'raudi/core_ext'
|
5
|
+
require 'raudi/info'
|
6
|
+
require 'raudi/avr'
|
3
7
|
|
4
8
|
module Raudi
|
5
9
|
|
@@ -8,18 +12,63 @@ module Raudi
|
|
8
12
|
attr_accessor :controller
|
9
13
|
|
10
14
|
def version
|
11
|
-
"0.0.
|
15
|
+
"0.0.2"
|
12
16
|
end
|
13
17
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def configure(model_name, &block)
|
19
|
+
Raudi::AVR::Controller.new(model_name, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def action
|
23
|
+
@action ||= Raudi::ActionProcessor.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def process(*args)
|
27
|
+
return unless filename = check_filename(args)
|
28
|
+
begin
|
29
|
+
load filename
|
30
|
+
return write_file(filename, args)
|
31
|
+
rescue Exception => e
|
32
|
+
puts e.message
|
33
|
+
end
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def check_filename(args)
|
40
|
+
filename = args.delete_at(0)
|
41
|
+
return unless filename
|
42
|
+
return unless File.exists?(filename)
|
43
|
+
return unless filename =~ /.*\.raudi$/i
|
44
|
+
filename
|
45
|
+
end
|
46
|
+
|
47
|
+
def param_alias(param)
|
48
|
+
{'--output' => '-o'}[param] or param
|
49
|
+
end
|
50
|
+
|
51
|
+
def write_file(source_path, args)
|
52
|
+
return unless source = controller.to_c
|
53
|
+
output = source_path.gsub(/\.raudi$/i, '.c')
|
54
|
+
args.each_with_index do |param, index|
|
55
|
+
next unless param_alias(param) == '-o'
|
56
|
+
custom_output = args[index + 1]
|
57
|
+
output = custom_output if custom_output
|
58
|
+
break
|
59
|
+
end
|
60
|
+
File.open(output, 'w') {|f| f.write(source) }
|
61
|
+
true
|
21
62
|
end
|
22
63
|
|
23
64
|
end
|
24
65
|
|
25
66
|
end
|
67
|
+
|
68
|
+
def action
|
69
|
+
Raudi.action
|
70
|
+
end
|
71
|
+
|
72
|
+
def configure(*args, &block)
|
73
|
+
Raudi.configure(*args, &block)
|
74
|
+
end
|
data/lib/raudi/.DS_Store
ADDED
Binary file
|
@@ -1,33 +1,41 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
output << append_libs(Raudi.controller.libs)
|
10
|
-
output << block_delimiter
|
11
|
-
output << main_block
|
1
|
+
module Raudi
|
2
|
+
|
3
|
+
class ActionProcessor
|
4
|
+
|
5
|
+
attr_accessor :collection
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
self.collection = {}
|
12
9
|
end
|
13
|
-
|
14
|
-
def
|
15
|
-
|
16
|
-
lib_name = lib_name.to_s
|
17
|
-
lib_name << '.h' unless lib_name =~ /\.h$/
|
18
|
-
"#include <#{lib_name}>"
|
19
|
-
end.join("\n")
|
10
|
+
|
11
|
+
def [](*keys)
|
12
|
+
collection[prepare_key(*keys)]
|
20
13
|
end
|
21
|
-
|
22
|
-
def
|
23
|
-
|
14
|
+
|
15
|
+
def []=(*keys, value)
|
16
|
+
collection[prepare_key(*keys)] = value
|
24
17
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def prepare_key(*keys)
|
22
|
+
number = if keys.last.is_a?(Fixnum)
|
23
|
+
keys.pop
|
28
24
|
end
|
25
|
+
|
26
|
+
key = keys.map{|key| key.to_s.downcase}.join('_')
|
27
|
+
key = key_alias(key)
|
28
|
+
|
29
|
+
key << number.to_s if number
|
30
|
+
key.to_sym
|
29
31
|
end
|
30
|
-
|
32
|
+
|
33
|
+
def key_alias(key)
|
34
|
+
{
|
35
|
+
'interrupt' => 'int'
|
36
|
+
}[key] or key
|
37
|
+
end
|
38
|
+
|
31
39
|
end
|
32
40
|
|
33
|
-
end
|
41
|
+
end
|
data/lib/raudi/avr.rb
ADDED
Binary file
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'raudi/proxy/controller'
|
2
|
+
require 'raudi/source/controller'
|
3
|
+
require 'raudi/state_list'
|
4
|
+
|
5
|
+
module Raudi
|
6
|
+
|
7
|
+
module AVR
|
8
|
+
|
9
|
+
class Controller
|
10
|
+
|
11
|
+
extend Forwardable
|
12
|
+
include Raudi::StateList
|
13
|
+
|
14
|
+
attr_accessor :model_name, :headers, :ports, :timers, :interrupt
|
15
|
+
|
16
|
+
def_delegator :source, :to_c
|
17
|
+
|
18
|
+
def initialize(model_name, &block)
|
19
|
+
self.model_name = model_name
|
20
|
+
load_ports
|
21
|
+
load_timers
|
22
|
+
self.headers = ['avr/io']
|
23
|
+
Proxy::Controller.new(self, &block) if block_given?
|
24
|
+
Raudi.controller = self
|
25
|
+
end
|
26
|
+
|
27
|
+
def ports(port_name = nil)
|
28
|
+
if port_name
|
29
|
+
@ports.detect{|port| port.name == port_name.to_s.upcase}
|
30
|
+
else
|
31
|
+
@ports
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def pins
|
36
|
+
ports.map(&:pins).flatten
|
37
|
+
end
|
38
|
+
|
39
|
+
def source
|
40
|
+
@source ||= Source::Controller.new(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def config
|
46
|
+
@config ||= begin
|
47
|
+
path = File.join(File.dirname(__FILE__), '/../../../configuration', "/#{model_name}.yml")
|
48
|
+
raise "Unknow controller model" unless File.exist?(path)
|
49
|
+
YAML.load_file(path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_ports
|
54
|
+
self.ports = config['ports'].map {|port_name, config| Port.new(port_name, config)}
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_timers
|
58
|
+
self.timers = config['timers'].map{|timer_name, config| Timer.new(timer_name, config)}
|
59
|
+
end
|
60
|
+
|
61
|
+
def method_missing(method_name, *args, &block)
|
62
|
+
if value = config[method_name.to_s]
|
63
|
+
value
|
64
|
+
else
|
65
|
+
super
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'raudi/avr/pin_states'
|
2
|
+
|
3
|
+
module Raudi
|
4
|
+
|
5
|
+
module AVR
|
6
|
+
|
7
|
+
class Pin
|
8
|
+
|
9
|
+
extend Forwardable
|
10
|
+
include PinStates
|
11
|
+
|
12
|
+
attr_accessor :port, :number
|
13
|
+
|
14
|
+
def_delegator :port, :name
|
15
|
+
|
16
|
+
def initialize(port, number, types)
|
17
|
+
self.port = port
|
18
|
+
self.number = number
|
19
|
+
load_states(types)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"Pin #{name}#{number} <#{state}>"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Raudi
|
2
|
+
|
3
|
+
module AVR
|
4
|
+
|
5
|
+
module PinStates
|
6
|
+
|
7
|
+
DELIMITER = '_'
|
8
|
+
|
9
|
+
def self.included(klass)
|
10
|
+
|
11
|
+
klass.class_eval do
|
12
|
+
|
13
|
+
attr_accessor :states, :state, :state_params
|
14
|
+
|
15
|
+
Info.pin_states.each do |pin_state|
|
16
|
+
|
17
|
+
define_method :get_state do |pin_state|
|
18
|
+
states.detect { |state| state =~ Regexp.new("\\A(#{pin_state})(_\d+)?") }
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method :get_state! do |pin_state|
|
22
|
+
valid_state = get_state(pin_state)
|
23
|
+
raise "#{to_s} can be #{pin_state}" unless valid_state
|
24
|
+
valid_state
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method "#{pin_state}!" do |*args|
|
28
|
+
self.state = get_state!(pin_state)
|
29
|
+
self.state_params = args.first
|
30
|
+
end
|
31
|
+
|
32
|
+
define_method "#{pin_state}?" do |*args|
|
33
|
+
self.state == get_state(pin_state)
|
34
|
+
end
|
35
|
+
|
36
|
+
define_method "can_be_#{pin_state}?" do |*args|
|
37
|
+
return unless full_state = get_state(pin_state)
|
38
|
+
if(number = args.first)
|
39
|
+
return unless full_state[number.to_s]
|
40
|
+
end
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def state_number
|
51
|
+
state.split(DELIMITER).last
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_c
|
55
|
+
if Info.gpio_states.include?(state)
|
56
|
+
"PIN#{name}#{number}"
|
57
|
+
else
|
58
|
+
state.to_s.gsub(DELIMITER, '').upcase
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def load_states(states)
|
65
|
+
self.states = (Info.gpio_states + states).uniq
|
66
|
+
self.state = self.states.first
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|