Root/
| 1 | /* |
| 2 | * Test code for the Tornado CPU board |
| 3 | */ |
| 4 | |
| 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
| 7 | |
| 8 | |
| 9 | extern uint32_t _data_flash; |
| 10 | extern uint32_t _data_begin; |
| 11 | extern uint32_t _data_end; |
| 12 | extern uint32_t _bss_end; |
| 13 | extern uint32_t _stack_end; |
| 14 | extern uint32_t _neg_stack_end; |
| 15 | |
| 16 | |
| 17 | #define IOCONFIG 0x40044000 |
| 18 | #define GPIO_BASE_0 0x50000000 |
| 19 | #define GPIO0DATA (GPIO_BASE_0+0x3ffc) |
| 20 | #define GPIO0DIR (GPIO_BASE_0+0x8000) |
| 21 | |
| 22 | /* LED is on PIO0_5 */ |
| 23 | |
| 24 | |
| 25 | int main(int argc, char **argv) |
| 26 | { |
| 27 | volatile uint32_t *data = (void *) GPIO0DATA; |
| 28 | volatile uint32_t *dir = (void *) GPIO0DIR; |
| 29 | uint32_t mask = 0; |
| 30 | uint32_t loop; |
| 31 | |
| 32 | *dir = 1 << 5; |
| 33 | |
| 34 | while (1) { |
| 35 | *data = mask; |
| 36 | mask ^= 1 << 5; |
| 37 | for (loop = 100000; loop; loop--); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | |
| 42 | void __attribute__((naked, section(".init"))) __init(void) |
| 43 | { |
| 44 | register uint32_t *t = &_data_begin; |
| 45 | register uint32_t *s = &_data_flash; |
| 46 | |
| 47 | while (t != &_data_end) |
| 48 | *t++ = *s++; |
| 49 | while (t != &_bss_end) |
| 50 | *t++ = 0; |
| 51 | main(0, NULL); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | #define INITIAL_SP ((uint32_t) &_stack_end) |
| 56 | #define NEG_INITIAL_SP ((uint32_t) &_neg_stack_end) |
| 57 | #define VECTORS 8 |
| 58 | |
| 59 | |
| 60 | uint32_t __vectors[VECTORS] __attribute__((section(".vectors"))) = { |
| 61 | INITIAL_SP, /* initial SP value @@@ */ |
| 62 | VECTORS*4+1, /* reset */ |
| 63 | 0, /* NMI */ |
| 64 | 0, /* HardFault */ |
| 65 | 0, /* reserved */ |
| 66 | 0, /* reserved */ |
| 67 | 0, /* reserved */ |
| 68 | NEG_INITIAL_SP-(VECTORS*4+1),/* checksum */ |
| 69 | }; |
| 70 |
Branches:
master
