sfrp 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cda721742189d74dac30ae37d3d0ec59d4b97085
4
- data.tar.gz: 2a9ebf80928a7718b4241d5718f6f8d5fa1e035b
3
+ metadata.gz: e9a7c8ab88c8c2982d435d3cdf05f98357cfead9
4
+ data.tar.gz: cc77e8fe3362408cb92f5fb9f4a8fd8c5a40e894
5
5
  SHA512:
6
- metadata.gz: ead9d2c66049bd7bf9debe408f39ccaa4c7e842096c830274ac7c3ced18f4ee426f0522b845d3394eaba2023e5cebf18b3066b7a3dc9bf2de62779c45f8718cc
7
- data.tar.gz: d658239d964311003df0fa64798981d0cb9dbcd75dfc63cdc8599fc6bef846707e8c9c5f4629d15753ed6d1654856944f22d257b9e9838abcffb7ae43191be69
6
+ metadata.gz: e3f05fb04cb256828eb17e25aa499da775d33860e86650057410e9b192f8071c43809a8cd485b6eccb97fd06a313c3c830e2147901c87718d718a367d82887e9
7
+ data.tar.gz: 8b8506c2f3d635273386f745a973f2f58734a572282046e773b464697154a779b0a69ec13d5683e75395b4804df9fe33b8dc0a87df958641994fec43d68b7acc
@@ -40,6 +40,12 @@ int portB(int port_num, int high_or_low) {
40
40
  return 0;
41
41
  }
42
42
 
43
+ int portBs(int output) {
44
+ DDRB = 0b11111111;
45
+ PORTB = output;
46
+ return 0;
47
+ }
48
+
43
49
  // PC
44
50
 
45
51
  int pinC(int num) {
@@ -59,6 +65,12 @@ int portC(int port_num, int high_or_low) {
59
65
  return 0;
60
66
  }
61
67
 
68
+ int portCs(int output) {
69
+ DDRC = 0b11111111;
70
+ PORTC = output;
71
+ return 0;
72
+ }
73
+
62
74
  // PD
63
75
 
64
76
  int pinD(int num) {
@@ -77,3 +89,9 @@ int portD(int port_num, int high_or_low) {
77
89
  PORTD = (~(1 << port_num) & PORTD) | (high_or_low << port_num);
78
90
  return 0;
79
91
  }
92
+
93
+ int portDs(int output) {
94
+ DDRD = 0b11111111;
95
+ PORTD = output;
96
+ return 0;
97
+ }
@@ -5,11 +5,18 @@
5
5
  int pinB(int);
6
6
  int posEdgePB(int);
7
7
  int portB(int, int);
8
+ int portBs(int);
8
9
 
9
10
  // PC
11
+ int pinC(int);
12
+ int posEdgePC(int);
10
13
  int portC(int, int);
14
+ int portCs(int);
11
15
 
12
16
  // PD
17
+ int pinD(int);
18
+ int posEdgePD(int);
13
19
  int portD(int, int);
20
+ int portDs(int);
14
21
 
15
22
  #endif
@@ -23,6 +23,7 @@ in @posEdgePB6 from $posEdgePB(6)
23
23
  in @posEdgePB7 from $posEdgePB(7)
24
24
 
25
25
  foreign portB as $portB(Int, Bool) : Unit
26
+ foreign portBs as $portBs(Int) : Unit
26
27
 
27
28
  -- PC
28
29
 
@@ -47,6 +48,7 @@ in @posEdgePC6 from $posEdgePC(6)
47
48
  in @posEdgePC7 from $posEdgePC(7)
48
49
 
49
50
  foreign portC as $portC(Int, Bool) : Unit
51
+ foreign portCs as $portCs(Int) : Unit
50
52
 
51
53
  -- PD
52
54
 
@@ -71,3 +73,4 @@ in @posEdgePD6 from $posEdgePD(6)
71
73
  in @posEdgePD7 from $posEdgePD(7)
72
74
 
73
75
  foreign portD as $portD(Int, Bool) : Unit
76
+ foreign portDs as $portDs(Int) : Unit
@@ -1,29 +1,59 @@
1
1
  #include<avr/io.h>
2
2
  #include <avr/interrupt.h>
3
3
 
4
- static unsigned int elapsed_time_counter = 0;
4
+ static unsigned int elapsed_clock_div256 = 0;
5
5
 
6
6
  ISR(TIMER0_OVF_vect)
7
7
  {
8
- elapsed_time_counter++;
8
+ elapsed_clock_div256++;
9
9
  }
10
10
 
11
- void initialize() {
11
+ void initialize_timer() {
12
+ static int flag = 0;
13
+ if (!flag) {
14
+ flag = 1;
15
+ return;
16
+ }
12
17
  cli();
13
18
  TIMSK = 0b00000001;
14
- //TCCR0 = 0b00000011;
15
- TCCR0 = 0b00000010;
19
+ TCCR0 = 0b00000001; // No prescaling
16
20
  sei();
17
21
  }
18
22
 
19
- int elapsed_time() {
20
- static int initial = 1;
21
- int res;
22
- if (initial) {
23
- initialize();
24
- initial = 0;
25
- }
26
- res = elapsed_time_counter * 2;
27
- elapsed_time_counter = 0;
28
- return res;
23
+ int get_dsec(clk_io_kilohertz) {
24
+ static unsigned int last = 0;
25
+ unsigned int current;
26
+ unsigned int dsec;
27
+ initialize_timer();
28
+
29
+ current = elapsed_clock_div256;
30
+ dsec = (current - last) / (clk_io_kilohertz * 4); // clk_io_kilohertz * 1024 / 256
31
+ last = current - (current - last) % (clk_io_kilohertz * 4);
32
+ return dsec;
33
+ }
34
+
35
+ int get_dmsec(clk_io_kilohertz) {
36
+ static unsigned int last = 0;
37
+ unsigned int current;
38
+ unsigned int dmsec;
39
+ initialize_timer();
40
+
41
+ current = elapsed_clock_div256;
42
+ dmsec = (current - last) / (clk_io_kilohertz / 2); // clk_io_kilohertz * 1024 / 256 / 8
43
+ last = current - (current - last) % (clk_io_kilohertz / 2);
44
+ return dmsec * 125;
45
+ }
46
+
47
+ // This function assumes 0.97656(=1000/1024)msec as 1msec
48
+ // so accumulates about 2% error.
49
+ int get_uncertain_dmsec(clk_io_kilohertz) {
50
+ static unsigned int last = 0;
51
+ unsigned int current;
52
+ unsigned int dmsec;
53
+ initialize_timer();
54
+
55
+ current = elapsed_clock_div256;
56
+ dmsec = (current - last) / (clk_io_kilohertz / 256); // clk_io_kilohertz * 1024 / 256 / 1024
57
+ last = current - (current - last) % (clk_io_kilohertz / 256);
58
+ return dmsec;
29
59
  }
@@ -1,6 +1,8 @@
1
1
  #ifndef BASE_IO_AVR_ATMEGA8_TIMER
2
2
  #define BASE_IO_AVR_ATMEGA8_TIMER
3
3
 
4
- int elapsed_time();
4
+ int get_dsec(int);
5
+ int get_dmsec(int);
6
+ int get_uncertain_dmsec(int);
5
7
 
6
8
  #endif
@@ -1,4 +1,10 @@
1
1
  import Base
2
2
 
3
- foreign elapsed_time as $elapsedTime() : Int
4
- in @elapsedTime from $elapsedTime()
3
+ foreign get_dsec as $getDsec(Int) : Int
4
+ in @dsec : Int from $getDsec(1024)
5
+
6
+ foreign get_dmsec as $getDmsec(Int) : Int
7
+ in @dmsec : Int from $getDmsec(1024)
8
+
9
+ foreign get_uncertain_dmsec as $getUncertainDmsec(Int) : Int
10
+ in @uncertainDmsec : Int from $getUncertainDmsec(1024)
@@ -1,4 +1,4 @@
1
- ptype Int{int} = /^((0x)?[0-9]+)$/\1/
1
+ ptype Int{int} = /^(((0x)|(0b))?[0-9]+)$/\1/
2
2
  ptype Float{float} = /^([0-9]+\.[0-9]+)$/\1f/
3
3
  ptype Bool{int} = True{1} | False{0}
4
4
  ptype Unit{int} = Unit{0}
@@ -3,9 +3,8 @@ require 'sfrp/error'
3
3
  module SFRP
4
4
  module Raw
5
5
  class NameError < CompileError
6
- def initialize(target_str, source_position)
6
+ def initialize(target_str)
7
7
  @target_str = target_str
8
- @source_position = source_position
9
8
  end
10
9
 
11
10
  def message
@@ -14,10 +13,9 @@ module SFRP
14
13
  end
15
14
 
16
15
  class AmbiguousNameError < CompileError
17
- def initialize(target_str, selection_strs, source_position)
16
+ def initialize(target_str, selection_strs)
18
17
  @target_str = target_str
19
18
  @selection_strs = selection_strs
20
- @source_position = source_position
21
19
  end
22
20
 
23
21
  def message
@@ -27,9 +25,8 @@ module SFRP
27
25
  end
28
26
 
29
27
  class IllegalSideEffectError < CompileError
30
- def initialize(target_str, source_position)
28
+ def initialize(target_str)
31
29
  @target_str = target_str
32
- @source_position = source_position
33
30
  end
34
31
 
35
32
  def message
data/lib/sfrp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SFRP
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfrp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kensuke Sawada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-11 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler