From: Matt Mullins Date: Sun, 23 Dec 2012 03:49:41 +0000 (-0800) Subject: Refactor spin loops, to prepare for global -O3 X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=91e2321901fb59462d71a5d30afbfe1306a3aba1;p=stellaris%2Fled_blink.git Refactor spin loops, to prepare for global -O3 --- diff --git a/led_blink.c b/led_blink.c index 9b0f47b..7d25e4e 100644 --- a/led_blink.c +++ b/led_blink.c @@ -1,14 +1,15 @@ #include "led_blink.h" #include +static void spin(int); + __attribute__((isr)) void main_isr() { // Enable Port F SYSCTL_RCGCGPIO_R = 0x20; // Wait for a few clocks to let GPIO module stabilize - for (int i = 0; i < 10; ++i) { - } + spin(10); // RGB pins (PF1, 2, 3) as outputs GPIO_PORTF_DIR_R = 0xE; @@ -26,7 +27,10 @@ void main_isr() { for (;;) { *(GPIO_PORTF_DATA_BITS_R + 0xC) ^= 0xC; - for (int j = 0; j < 1000000; ++j) { - } + spin(1000000); } } + +void spin(int cycles) { + while (cycles) { cycles -= 1; } +}