15
15
#define CYCLES_LOOP 3
16
16
17
17
// min cycles per tx bit
18
- #define CYCLES_TX 10
18
+ #define CYCLES_TX 9
19
19
20
20
21
21
// the c preprocessor does not support floating point. to get a higher accuracy for divisions the
28
28
// minimum allowed loop value is 1; value 0 is interpreted as 256
29
29
#ifdef TINYUART_OPT_HIGH_ACCURACY
30
30
// round to nearest cycle
31
- #define CYCLES (((UPSCALE*TINYUART_F_CPU/ TINYUART_BAUD-UPSCALE*CYCLES_TX)+UPSCALE/2)/UPSCALE)
31
+ #define CYCLES (((UPSCALE*( TINYUART_F_CPU)/( TINYUART_BAUD) -UPSCALE*CYCLES_TX)+UPSCALE/2)/UPSCALE)
32
32
#define LOOP_DELAY (CYCLES/CYCLES_LOOP)
33
33
#define CYCLES_EXTRA (CYCLES-(LOOP_DELAY*CYCLES_LOOP))
34
34
35
35
#else
36
36
// round to nearest 3 cycles
37
- #define LOOP_DELAY ((((UPSCALE*TINYUART_F_CPU/ TINYUART_BAUD-UPSCALE*CYCLES_TX)/CYCLES_LOOP)+UPSCALE/2)/UPSCALE)
37
+ #define LOOP_DELAY ((((UPSCALE*( TINYUART_F_CPU)/( TINYUART_BAUD) -UPSCALE*CYCLES_TX)/CYCLES_LOOP)+UPSCALE/2)/UPSCALE)
38
38
#define CYCLES_EXTRA 0
39
39
#endif
40
40
53
53
54
54
55
55
// Calculate tolerance
56
- #define TOLERANCE_PPM (1000000*TINYUART_BAUD*(LOOP_DELAY*CYCLES_LOOP+CYCLES_TX+CYCLES_EXTRA)/TINYUART_F_CPU-1000000)
56
+ #define TOLERANCE_PPM (1000000*( TINYUART_BAUD) *(LOOP_DELAY*CYCLES_LOOP+CYCLES_TX+CYCLES_EXTRA)/TINYUART_F_CPU-1000000)
57
57
#define IS_WITHIN_RANGE (x , range ) ((x < -range) || (x > range))
58
58
59
59
#if defined(TINYUART_OPT_TOLERANCE_ERR ) && IS_WITHIN_RANGE (TOLERANCE_PPM , 45000 )
@@ -104,7 +104,7 @@ void tinyuart_send_uint8(uint8_t data)
104
104
(
105
105
"mov %[cnt], %[data] \n\t" // use cnt as scratch pad
106
106
107
- "sbi %[pin], %[io ] \n\t" // Setup START bit => moved for cycles bevore delay loop for accurate timing
107
+ "out %[pin], %[mask ] \n\t" // Setup START bit => moved for cycles bevore delay loop for accurate timing
108
108
109
109
"subi %[cnt], 128 \n\t" // invert MSB
110
110
"lsl %[cnt] \n\t" // shift to a) generate pattern with XOR b) place msb in carry
@@ -125,8 +125,8 @@ void tinyuart_send_uint8(uint8_t data)
125
125
"dec __tmp_reg__ \n\t"
126
126
"brne send_bit_delay \n\t"
127
127
128
- "sbrc %[data], 0 \n\t" // toggle TX if change is required
129
- "sbi %[pin], %[io] \n\t"
128
+ "sbrc %[data], 0 \n\t" // toggle TX if change is required
129
+ "out %[pin], %[mask] \n\t"
130
130
131
131
"ror %[data] \n\t" // rotation to access the 9th bit in carry
132
132
"dec %[cnt] \n\t"
@@ -139,7 +139,6 @@ void tinyuart_send_uint8(uint8_t data)
139
139
// input values; never write to any of the below
140
140
: [mask ] " r "(mask), // let compiler put mask in register
141
141
[loops ] "r" ((uint8_t )(LOOP_DELAY + 1 )), // the 0th loop iteration already decrements, +1 as compensation
142
- [io ] "I" (TINYUART_IO_TX ),
143
142
[pin ] "I" (_SFR_IO_ADDR (TINYUART_PIN ))
144
143
145
144
// cobblers: registers modified without compiler already knowing
0 commit comments