瀏覽代碼

removed unecessary indirect register adressing in serial.

Bernhard 13 年之前
父節點
當前提交
b9ad0bb2ce
共有 2 個檔案被更改,包括 20 行新增47 行删除
  1. 16
    29
      Marlin/MarlinSerial.cpp
  2. 4
    18
      Marlin/MarlinSerial.h

+ 16
- 29
Marlin/MarlinSerial.cpp 查看文件

@@ -75,22 +75,9 @@ inline void store_char(unsigned char c)
75 75
 
76 76
 // Constructors ////////////////////////////////////////////////////////////////
77 77
 
78
-MarlinSerial::MarlinSerial(
79
-  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
80
-  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
81
-  volatile uint8_t *udr,
82
-  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
78
+MarlinSerial::MarlinSerial()
83 79
 {
84
-  _ubrrh = ubrrh;
85
-  _ubrrl = ubrrl;
86
-  _ucsra = ucsra;
87
-  _ucsrb = ucsrb;
88
-  _udr = udr;
89
-  _rxen = rxen;
90
-  _txen = txen;
91
-  _rxcie = rxcie;
92
-  _udre = udre;
93
-  _u2x = u2x;
80
+
94 81
 }
95 82
 
96 83
 // Public Methods //////////////////////////////////////////////////////////////
@@ -98,39 +85,39 @@ MarlinSerial::MarlinSerial(
98 85
 void MarlinSerial::begin(long baud)
99 86
 {
100 87
   uint16_t baud_setting;
101
-  bool use_u2x = true;
88
+  bool useU2X0 = true;
102 89
 
103 90
 #if F_CPU == 16000000UL
104 91
   // hardcoded exception for compatibility with the bootloader shipped
105 92
   // with the Duemilanove and previous boards and the firmware on the 8U2
106 93
   // on the Uno and Mega 2560.
107 94
   if (baud == 57600) {
108
-    use_u2x = false;
95
+    useU2X0 = false;
109 96
   }
110 97
 #endif
111 98
   
112
-  if (use_u2x) {
113
-    *_ucsra = 1 << _u2x;
99
+  if (useU2X0) {
100
+    UCSR0A = 1 << U2X0;
114 101
     baud_setting = (F_CPU / 4 / baud - 1) / 2;
115 102
   } else {
116
-    *_ucsra = 0;
103
+    UCSR0A = 0;
117 104
     baud_setting = (F_CPU / 8 / baud - 1) / 2;
118 105
   }
119 106
 
120 107
   // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
121
-  *_ubrrh = baud_setting >> 8;
122
-  *_ubrrl = baud_setting;
108
+  UBRR0H = baud_setting >> 8;
109
+  UBRR0L = baud_setting;
123 110
 
124
-  sbi(*_ucsrb, _rxen);
125
-  sbi(*_ucsrb, _txen);
126
-  sbi(*_ucsrb, _rxcie);
111
+  sbi(UCSR0B, RXEN0);
112
+  sbi(UCSR0B, TXEN0);
113
+  sbi(UCSR0B, RXCIE0);
127 114
 }
128 115
 
129 116
 void MarlinSerial::end()
130 117
 {
131
-  cbi(*_ucsrb, _rxen);
132
-  cbi(*_ucsrb, _txen);
133
-  cbi(*_ucsrb, _rxcie);  
118
+  cbi(UCSR0B, RXEN0);
119
+  cbi(UCSR0B, TXEN0);
120
+  cbi(UCSR0B, RXCIE0);  
134 121
 }
135 122
 
136 123
 
@@ -367,7 +354,7 @@ void MarlinSerial::printFloat(double number, uint8_t digits)
367 354
 // Preinstantiate Objects //////////////////////////////////////////////////////
368 355
 
369 356
 #if defined(UBRR0H) && defined(UBRR0L)
370
-  MarlinSerial MSerial( &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
357
+  MarlinSerial MSerial;
371 358
 #else
372 359
   #error no serial port defined  (port 0)
373 360
 #endif

+ 4
- 18
Marlin/MarlinSerial.h 查看文件

@@ -46,23 +46,9 @@ struct ring_buffer
46 46
 
47 47
 class MarlinSerial //: public Stream
48 48
 {
49
-  private:
50
-    volatile uint8_t *_ubrrh;
51
-    volatile uint8_t *_ubrrl;
52
-    volatile uint8_t *_ucsra;
53
-    volatile uint8_t *_ucsrb;
54
-    volatile uint8_t *_udr;
55
-    uint8_t _rxen;
56
-    uint8_t _txen;
57
-    uint8_t _rxcie;
58
-    uint8_t _udre;
59
-    uint8_t _u2x;
49
+
60 50
   public:
61
-    MarlinSerial(
62
-      volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
63
-      volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
64
-      volatile uint8_t *udr,
65
-      uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
51
+    MarlinSerial();
66 52
     void begin(long);
67 53
     void end();
68 54
     inline int available(void)
@@ -74,10 +60,10 @@ class MarlinSerial //: public Stream
74 60
     void flush(void);
75 61
     inline void write(uint8_t c)
76 62
     {
77
-      while (!((*_ucsra) & (1 << _udre)))
63
+      while (!((UCSR0A) & (1 << UDRE0)))
78 64
         ;
79 65
 
80
-      *_udr = c;
66
+      UDR0 = c;
81 67
     }
82 68
     
83 69
     

Loading…
取消
儲存