annotate test/c3examples/burn2.c3 @ 288:a747a45dcd78

Various styling work
author Windel Bouwman
date Thu, 21 Nov 2013 14:26:13 +0100
parents 1c7c1e619be8
children bd2593de3ff8
rev   line source
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
1 /*
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
2
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
3 This file blinks a LED on the STM32F4 discovery board.
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
4
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
5 the board has 4 leds on PD12, PD13, PD14 and PD15
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
6
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
7 */
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
8
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
9 module burn2;
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
10
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
11 import stm32f4xx;
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
12
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
13 function int add(int a, int b)
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
14 {
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
15 return a + b;
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
16 }
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
17
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
18 function void init(int pin)
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
19 {
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
20 if (pin < 12)
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
21 {
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
22 return;
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
23 }
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
24
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
25 if (pin > 15)
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
26 {
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
27 return;
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
28 }
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
29
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
30 var stm32f4xx.RCC_Type RCC;
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
31 RCC = cast<RCC_Type>(0x40023800);
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
32
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
33 // Enable the clock to port D:
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
34 RCC->AHB1ENR = RCC->AHB1ENR | (1 << 3);
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
35 // Memory mapped control registers:
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
36 var GPIO_Type GPIOD;
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
37 GPIOD = cast<GPIO_Type>(0x40020C00);
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
38
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
39 // PD13 == output (01)
279
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 271
diff changeset
40 GPIOD->MODER = (1 << (pin << 1));
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
41 GPIOD->ODR = (1 << pin);
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
42 }
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
43
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
44
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
45 function void main()
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
46 {
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
47 // Vary between 12 and 15:
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
48 init(13);
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
49
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
50 var int a;
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
51 a = 0
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
52 while (a < 1000)
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
53 {
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
54 a = add(a, 1);
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
55 }
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
56
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
57 while(true) {}
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
58 }
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
59