~ruther/avr-shift-registers

ref: c5b0c625dfd1bb40421c62ada2c79aa30a9cae0b avr-shift-registers/simavr/main.i -rw-r--r-- 13.6 KiB
c5b0c625 — František Boháček feat: initial commit 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# 1 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/main.c"
# 1 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/main.c"
# 1 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h" 1
# 28 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
typedef void* ShiftRegisterHandle;
typedef uint8_t bool;
typedef uint8_t byte;
# 47 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
typedef struct {
    volatile byte* ddr;
    volatile byte* port;
    volatile byte* pin;
    byte position;
} DataPosition;
# 64 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern const DataPosition* data_position_create(volatile byte* ddr, volatile byte* port, volatile byte* pin, byte position);






extern void data_position_destroy(const DataPosition* position);
# 80 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern bool data_position_get_pin(const DataPosition* position);
# 91 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void data_position_set_port(const DataPosition* position);
# 102 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void data_position_reset_port(const DataPosition* position);
# 111 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void data_position_set_ddr(const DataPosition* position);
# 120 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void data_position_reset_ddr(const DataPosition* position);
# 137 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_shift_register_clock_pulse(ShiftRegisterHandle shiftRegisterHandle);
# 152 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_shift_register_enable_clock(ShiftRegisterHandle shiftRegisterHandle);
# 164 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_shift_register_disable_clock(ShiftRegisterHandle shiftRegisterHandle);
# 190 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern ShiftRegisterHandle avr_piso_shift_register_create(
    const DataPosition clockEnable,
    const DataPosition clockPulse,
    const DataPosition output,
    const DataPosition parallelLoad,
    int waitTime
);
# 208 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_piso_shift_register_init(ShiftRegisterHandle shiftRegisterHandle);






extern void avr_piso_shift_register_destroy(ShiftRegisterHandle shiftRegisterHandle);
# 227 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_piso_shift_register_parallel_load(ShiftRegisterHandle shiftRegisterHandle);
# 237 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_piso_shift_register_shift(ShiftRegisterHandle shiftRegisterHandle);
# 251 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern bool avr_piso_shift_register_read_bit(ShiftRegisterHandle shiftRegisterHandle);
# 264 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern byte avr_piso_shift_register_read_byte(ShiftRegisterHandle shiftRegisterHandle);
# 291 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern ShiftRegisterHandle avr_sipo_shift_register_create(
    const DataPosition clockEnable,
    const DataPosition clockPulse,
    const DataPosition input,
    const DataPosition outputEnable,
    const DataPosition pushOutput,
    int waitTime
);
# 310 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_sipo_shift_register_init(ShiftRegisterHandle shiftRegisterHandle);






extern void avr_sipo_shift_register_destroy(ShiftRegisterHandle shiftRegisterHandle);
# 327 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_sipo_shift_register_shift(ShiftRegisterHandle shiftRegisterHandle);
# 341 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_sipo_shift_register_write_bit(ShiftRegisterHandle shiftRegisterHandle, byte data, int position);
# 354 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_sipo_shift_register_write_byte(ShiftRegisterHandle shiftRegisterHandle, byte data);
# 364 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_sipo_shift_register_enable_output(ShiftRegisterHandle shiftRegisterHandle);
# 374 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_sipo_shift_register_disable_output(ShiftRegisterHandle shiftRegisterHandle);
# 385 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_sipo_shift_register_push_data_to_output(ShiftRegisterHandle shiftRegisterHandle);
# 396 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/../src/sr/seduce.h"
extern void avr_sipo_shift_register_reset(ShiftRegisterHandle shiftRegisterHandle);
# 2 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/main.c" 2
# 1 "/usr/avr/include/util/delay.h" 1 3
# 44 "/usr/avr/include/util/delay.h" 3
# 1 "/usr/avr/include/inttypes.h" 1 3
# 37 "/usr/avr/include/inttypes.h" 3
# 1 "/usr/lib/gcc/avr/10.2.0/include/stdint.h" 1 3 4
# 9 "/usr/lib/gcc/avr/10.2.0/include/stdint.h" 3 4
# 1 "/usr/avr/include/stdint.h" 1 3 4
# 125 "/usr/avr/include/stdint.h" 3 4

# 125 "/usr/avr/include/stdint.h" 3 4
typedef signed int int8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef signed int int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
typedef signed int int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));

typedef signed int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
# 146 "/usr/avr/include/stdint.h" 3 4
typedef int16_t intptr_t;




typedef uint16_t uintptr_t;
# 163 "/usr/avr/include/stdint.h" 3 4
typedef int8_t int_least8_t;




typedef uint8_t uint_least8_t;




typedef int16_t int_least16_t;




typedef uint16_t uint_least16_t;




typedef int32_t int_least32_t;




typedef uint32_t uint_least32_t;







typedef int64_t int_least64_t;






typedef uint64_t uint_least64_t;
# 217 "/usr/avr/include/stdint.h" 3 4
typedef int8_t int_fast8_t;




typedef uint8_t uint_fast8_t;




typedef int16_t int_fast16_t;




typedef uint16_t uint_fast16_t;




typedef int32_t int_fast32_t;




typedef uint32_t uint_fast32_t;







typedef int64_t int_fast64_t;






typedef uint64_t uint_fast64_t;
# 277 "/usr/avr/include/stdint.h" 3 4
typedef int64_t intmax_t;




typedef uint64_t uintmax_t;
# 10 "/usr/lib/gcc/avr/10.2.0/include/stdint.h" 2 3 4
# 38 "/usr/avr/include/inttypes.h" 2 3
# 77 "/usr/avr/include/inttypes.h" 3
typedef int32_t int_farptr_t;



typedef uint32_t uint_farptr_t;
# 45 "/usr/avr/include/util/delay.h" 2 3
# 1 "/usr/avr/include/util/delay_basic.h" 1 3
# 40 "/usr/avr/include/util/delay_basic.h" 3
static __inline__ void _delay_loop_1(uint8_t __count) __attribute__((__always_inline__));
static __inline__ void _delay_loop_2(uint16_t __count) __attribute__((__always_inline__));
# 80 "/usr/avr/include/util/delay_basic.h" 3
void
_delay_loop_1(uint8_t __count)
{
 __asm__ volatile (
  "1: dec %0" "\n\t"
  "brne 1b"
  : "=r" (__count)
  : "0" (__count)
 );
}
# 102 "/usr/avr/include/util/delay_basic.h" 3
void
_delay_loop_2(uint16_t __count)
{
 __asm__ volatile (
  "1: sbiw %0,1" "\n\t"
  "brne 1b"
  : "=w" (__count)
  : "0" (__count)
 );
}
# 46 "/usr/avr/include/util/delay.h" 2 3
# 1 "/usr/avr/include/math.h" 1 3
# 127 "/usr/avr/include/math.h" 3
extern double cos(double __x) __attribute__((__const__));





extern double sin(double __x) __attribute__((__const__));





extern double tan(double __x) __attribute__((__const__));






extern double fabs(double __x) __attribute__((__const__));






extern double fmod(double __x, double __y) __attribute__((__const__));
# 168 "/usr/avr/include/math.h" 3
extern double modf(double __x, double *__iptr);


extern float modff (float __x, float *__iptr);




extern double sqrt(double __x) __attribute__((__const__));


extern float sqrtf (float) __attribute__((__const__));




extern double cbrt(double __x) __attribute__((__const__));
# 195 "/usr/avr/include/math.h" 3
extern double hypot (double __x, double __y) __attribute__((__const__));







extern double square(double __x) __attribute__((__const__));






extern double floor(double __x) __attribute__((__const__));






extern double ceil(double __x) __attribute__((__const__));
# 235 "/usr/avr/include/math.h" 3
extern double frexp(double __x, int *__pexp);







extern double ldexp(double __x, int __exp) __attribute__((__const__));





extern double exp(double __x) __attribute__((__const__));





extern double cosh(double __x) __attribute__((__const__));





extern double sinh(double __x) __attribute__((__const__));





extern double tanh(double __x) __attribute__((__const__));







extern double acos(double __x) __attribute__((__const__));







extern double asin(double __x) __attribute__((__const__));






extern double atan(double __x) __attribute__((__const__));
# 299 "/usr/avr/include/math.h" 3
extern double atan2(double __y, double __x) __attribute__((__const__));





extern double log(double __x) __attribute__((__const__));





extern double log10(double __x) __attribute__((__const__));





extern double pow(double __x, double __y) __attribute__((__const__));






extern int isnan(double __x) __attribute__((__const__));
# 334 "/usr/avr/include/math.h" 3
extern int isinf(double __x) __attribute__((__const__));






__attribute__((__const__)) static inline int isfinite (double __x)
{
    unsigned char __exp;
    __asm__ (
 "mov	%0, %C1		\n\t"
 "lsl	%0		\n\t"
 "mov	%0, %D1		\n\t"
 "rol	%0		"
 : "=r" (__exp)
 : "r" (__x) );
    return __exp != 0xff;
}






__attribute__((__const__)) static inline double copysign (double __x, double __y)
{
    __asm__ (
 "bst	%D2, 7	\n\t"
 "bld	%D0, 7	"
 : "=r" (__x)
 : "0" (__x), "r" (__y) );
    return __x;
}
# 377 "/usr/avr/include/math.h" 3
extern int signbit (double __x) __attribute__((__const__));






extern double fdim (double __x, double __y) __attribute__((__const__));
# 393 "/usr/avr/include/math.h" 3
extern double fma (double __x, double __y, double __z) __attribute__((__const__));







extern double fmax (double __x, double __y) __attribute__((__const__));







extern double fmin (double __x, double __y) __attribute__((__const__));






extern double trunc (double __x) __attribute__((__const__));
# 427 "/usr/avr/include/math.h" 3
extern double round (double __x) __attribute__((__const__));
# 440 "/usr/avr/include/math.h" 3
extern long lround (double __x) __attribute__((__const__));
# 454 "/usr/avr/include/math.h" 3
extern long lrint (double __x) __attribute__((__const__));
# 47 "/usr/avr/include/util/delay.h" 2 3
# 86 "/usr/avr/include/util/delay.h" 3
static __inline__ void _delay_us(double __us) __attribute__((__always_inline__));
static __inline__ void _delay_ms(double __ms) __attribute__((__always_inline__));
# 165 "/usr/avr/include/util/delay.h" 3
void
_delay_ms(double __ms)
{
 double __tmp ;
# 190 "/usr/avr/include/util/delay.h" 3
 uint16_t __ticks;
 __tmp = (() / 4e3) * __ms;
 if (__tmp < 1.0)
  __ticks = 1;
 else if (__tmp > 65535)
 {

  __ticks = (uint16_t) (__ms * 10.0);
  while(__ticks)
  {

   _delay_loop_2((() / 4e3) / 10);
   __ticks --;
  }
  return;
 }
 else
  __ticks = (uint16_t)__tmp;
 _delay_loop_2(__ticks);

}
# 254 "/usr/avr/include/util/delay.h" 3
void
_delay_us(double __us)
{
 double __tmp ;
# 279 "/usr/avr/include/util/delay.h" 3
 uint8_t __ticks;
 double __tmp2 ;
 __tmp = (() / 3e6) * __us;
 __tmp2 = (() / 4e6) * __us;
 if (__tmp < 1.0)
  __ticks = 1;
 else if (__tmp2 > 65535)
 {
  _delay_ms(__us / 1000.0);
 }
 else if (__tmp > 255)
 {
  uint16_t __ticks=(uint16_t)__tmp2;
  _delay_loop_2(__ticks);
  return;
 }
 else
  __ticks = (uint8_t)__tmp;
 _delay_loop_1(__ticks);

}
# 3 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/main.c" 2


# 4 "/home/ruther/Documents/MyProjects/MCU/avr-shift-registers/simavr/main.c"
int main(void)
{

    ShiftRegisterHandle sipoSrHandle = avr_sipo_shift_register_create(
        data_position_create(&DDRB, &PORTB, &PINB, 0),
        data_position_create(&DDRB, &PORTB, &PINB, 1),
        data_position_create(&DDRB, &PORTB, &PINB, 2),
        data_position_create(&DDRB, &PORTB, &PINB, 3),
        data_position_create(&DDRB, &PORTB, &PINB, 4),
        1
    );

    avr_sipo_shift_register_init(sipoSrHandle);

    avr_sipo_shift_register_write_byte(sipoSrHandle, 0b11001111);
    avr_sipo_shift_register_push_data_to_output(sipoSrHandle);
    avr_sipo_shift_register_enable_output(sipoSrHandle);



    _delay_ms(100);

    ShiftRegisterHandle pisoSrHandle = avr_piso_shift_register_create(
        data_position_create(&DDRC, &PORTC, &PINC, 0),
        data_position_create(&DDRC, &PORTC, &PINC, 1),
        data_position_create(&DDRC, &PORTC, &PINC, 2),
        data_position_create(&DDRC, &PORTC, &PINC, 3),
        1
    );

    avr_piso_shift_register_parallel_load();
    byte read = avr_piso_shift_register_read_byte();
}