summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tree-ssa/pr38699.c
blob: 6845324e41a6d699b3db796d75af3146b1b0a12d (plain)
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
/* { dg-do compile } */
/* { dg-options "-Os -fdump-tree-optimized" } */
/*
 * License: GPL
 * Copyright: (c) 2007 by Till Harbaum <till@harbaum.org>
 * Copyright: (c) 2008 Wolfgang Moser, http://d81.de
 */

/* #include <avr/wdt.h> */
/* some declarations from the include above for ATMega8 */
#define _SFR_IO8(io_addr) (*(volatile unsigned char *)((io_addr) + 0x20))
#define TOV0    0
#define TCNT0    _SFR_IO8(0x32)
#define TIFR    _SFR_IO8(0x38)
#define DDRC    _SFR_IO8(0x14)
#define DDRD    _SFR_IO8(0x11)
#define PORTC    _SFR_IO8(0x15)
#define PORTD    _SFR_IO8(0x12)

static void delay_wait_us( unsigned char timeout ) {
    __asm__ __volatile__ ("wdr");

    TCNT0 = timeout;
    TIFR |= (1 << (TOV0));

    /* wait until counter overflows */
    while(!(TIFR & (1 << (TOV0))));
}

static void delay_wait_us_ms( unsigned char timeout ) {
    delay_wait_us( timeout * 1000 );
}


void makeUseOfTimerWait( unsigned char val ) {
    delay_wait_us( 10 );
    DDRC |= 0x10;
    delay_wait_us( 10 );
    DDRD |= 0x20;

    delay_wait_us( 20 );
    PORTC &= ~0x10;
    delay_wait_us( 10 );
    PORTD &= ~0x20;

    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );
    delay_wait_us_ms( 5 );

    PORTC |= val & 0x10;
    delay_wait_us( 10 );
    PORTD |= val & 0x20;

    delay_wait_us( 10 );
}
/* We should not inline the delay loops.  */
/* { dg-final { scan-tree-dump "delay_wait_us" "optimized"} } */
/* { dg-final { scan-tree-dump "delay_wait_us_ms" "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */