Browse files

add support for user defined code in interrupts

  • Loading branch information...
1 parent e825772 commit 49ed154a9314485bbf6d3d8c54b8c20ed82e0abb Sergey Pchelincev committed Feb 8, 2012
View
1 examples/actions.raudi
@@ -1 +0,0 @@
-//
View
3 examples/config.rb
@@ -1,3 +0,0 @@
-AVR::Controller.define :atmega328 do |controller|
- controller.add_lib 'util/delay'
-end
View
10 examples/result.c
@@ -1,10 +0,0 @@
-#include <avr/io.h>
-#include <util/delay.h>
-
-void main()
-{
- while(1)
- {
-
- }
-}
View
1 lib/raudi.rb
@@ -18,7 +18,6 @@ def generate(config_file, actions_file)
raise 'Create configuration file config.rb before' unless File.exists?(absolute_config_path)
raise 'Create actions file actions.raudi before' unless File.exists?(absolute_actions_path)
load(absolute_config_path)
- ActionProcessor.generate_source(absolute_config_path)
end
end
View
6 lib/raudi/avr/int_processing.rb
@@ -7,7 +7,11 @@ class IntProcessing < Processing
private
def interrupts
- int_pins.each { |pin| interrupt_block vector_name(pin.to_c) }
+ int_pins.each do |pin|
+ interrupt_block vector_name(pin.to_c) do
+ code_lines action_source(pin.to_c)
+ end
+ end
end
def config
View
23 lib/raudi/avr/processing.rb
@@ -1,4 +1,3 @@
-require 'forwardable'
require 'raudi/avr/state_list'
module Raudi
@@ -7,16 +6,10 @@ module AVR
class Processing
- extend Forwardable
include StateList
attr_accessor :controller, :source
- def_delegator :controller, :ports
- def_delegator :source, :write_register
- def_delegator :source, :clear_register
- def_delegator :source, :interrupt_block
-
class << self
attr_accessor :processings
@@ -50,6 +43,22 @@ def pins
ports.map(&:pins).flatten
end
+ def action_source(action_name)
+ action_name = "#{action_name}_action"
+ begin
+ eval action_name
+ rescue
+ ''
+ end
+ end
+
+ def method_missing(method_name, *args, &block)
+ [source, controller].each do |delegate|
+ return delegate.send(method_name, *args, &block) if delegate.respond_to?(method_name)
+ end
+ super
+ end
+
private
def interrupts
View
2 spec/raudi/avr/controller_source_spec.rb
@@ -31,6 +31,8 @@
source.should include('ISR(INT0_vect)')
source.should include('EIMSK |= 1 << INT0;')
source.should include('EICRA |= 1 << ISC00 | 1 << ISC01;')
+ source.should include('int k;')
+ source.should include('for(k = 0; k < 4; k++);')
end
it 'falling' do
View
1 spec/spec_helper.rb
@@ -8,6 +8,7 @@ def klass
end
+load('spec/test_actions.rb')
RSpec.configure do |config|
config.include SupportHelpers
View
4 spec/test_actions.rb
@@ -0,0 +1,4 @@
+INT0_action = <<AVR
+ int k;
+ for(k = 0; k < 4; k++);
+AVR

0 comments on commit 49ed154

Please sign in to comment.