Bläddra i källkod

removed unecessary indirect register adressing in serial.

Bernhard 13 år sedan
förälder
incheckning
b9ad0bb2ce
2 ändrade filer med 20 tillägg och 47 borttagningar
  1. 16
    29
      Marlin/MarlinSerial.cpp
  2. 4
    18
      Marlin/MarlinSerial.h

+ 16
- 29
Marlin/MarlinSerial.cpp Visa fil

75
 
75
 
76
 // Constructors ////////////////////////////////////////////////////////////////
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
 // Public Methods //////////////////////////////////////////////////////////////
83
 // Public Methods //////////////////////////////////////////////////////////////
98
 void MarlinSerial::begin(long baud)
85
 void MarlinSerial::begin(long baud)
99
 {
86
 {
100
   uint16_t baud_setting;
87
   uint16_t baud_setting;
101
-  bool use_u2x = true;
88
+  bool useU2X0 = true;
102
 
89
 
103
 #if F_CPU == 16000000UL
90
 #if F_CPU == 16000000UL
104
   // hardcoded exception for compatibility with the bootloader shipped
91
   // hardcoded exception for compatibility with the bootloader shipped
105
   // with the Duemilanove and previous boards and the firmware on the 8U2
92
   // with the Duemilanove and previous boards and the firmware on the 8U2
106
   // on the Uno and Mega 2560.
93
   // on the Uno and Mega 2560.
107
   if (baud == 57600) {
94
   if (baud == 57600) {
108
-    use_u2x = false;
95
+    useU2X0 = false;
109
   }
96
   }
110
 #endif
97
 #endif
111
   
98
   
112
-  if (use_u2x) {
113
-    *_ucsra = 1 << _u2x;
99
+  if (useU2X0) {
100
+    UCSR0A = 1 << U2X0;
114
     baud_setting = (F_CPU / 4 / baud - 1) / 2;
101
     baud_setting = (F_CPU / 4 / baud - 1) / 2;
115
   } else {
102
   } else {
116
-    *_ucsra = 0;
103
+    UCSR0A = 0;
117
     baud_setting = (F_CPU / 8 / baud - 1) / 2;
104
     baud_setting = (F_CPU / 8 / baud - 1) / 2;
118
   }
105
   }
119
 
106
 
120
   // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
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
 void MarlinSerial::end()
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
 // Preinstantiate Objects //////////////////////////////////////////////////////
354
 // Preinstantiate Objects //////////////////////////////////////////////////////
368
 
355
 
369
 #if defined(UBRR0H) && defined(UBRR0L)
356
 #if defined(UBRR0H) && defined(UBRR0L)
370
-  MarlinSerial MSerial( &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
357
+  MarlinSerial MSerial;
371
 #else
358
 #else
372
   #error no serial port defined  (port 0)
359
   #error no serial port defined  (port 0)
373
 #endif
360
 #endif

+ 4
- 18
Marlin/MarlinSerial.h Visa fil

46
 
46
 
47
 class MarlinSerial //: public Stream
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
   public:
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
     void begin(long);
52
     void begin(long);
67
     void end();
53
     void end();
68
     inline int available(void)
54
     inline int available(void)
74
     void flush(void);
60
     void flush(void);
75
     inline void write(uint8_t c)
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
     

Laddar…
Avbryt
Spara