annotate python/c3/examples/burn2.c3 @ 280:02385f62f250

Rework from str interface to Instruction interface
author Windel Bouwman
date Sat, 02 Nov 2013 10:03:26 +0100
parents 2ccd57b1d78c
children
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
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
9 package burn2;
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
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
19 function void init(int pin)
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
20 {
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
21 if (pin < 12)
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
22 {
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
23 return;
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
24 }
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
25
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
26 /*if (pin > 15)
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
27 {
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
28 return;
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
29 }*/
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
30
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
31 var RCC_Type RCC;
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
32 RCC = cast<RCC_Type>(0x40023800);
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
33
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
34 // Enable the clock to port D:
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
35 RCC->AHB1ENR = RCC->AHB1ENR | (1 << 3);
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
36 // Memory mapped control registers:
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
37 var GPIO_Type GPIOD;
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
38 GPIOD = cast<GPIO_Type>(0x40020C00);
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
39
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
40 // PD13 == output (01)
279
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 271
diff changeset
41 GPIOD->MODER = (1 << (pin << 1));
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
42 GPIOD->ODR = (1 << pin);
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
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
46 function void main()
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
47 {
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
48 // Vary between 12 and 15:
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
49 init(13);
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
50
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
51 var int a;
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
52 a = 0
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
53 while (a < 1000)
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
54 {
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 279
diff changeset
55 a = a + 1;
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
56 }
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
57
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
58 while(true) {}
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
59 }
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents:
diff changeset
60