From 91e2321901fb59462d71a5d30afbfe1306a3aba1 Mon Sep 17 00:00:00 2001 From: Matt Mullins Date: Sat, 22 Dec 2012 19:49:41 -0800 Subject: [PATCH] Refactor spin loops, to prepare for global -O3 --- led_blink.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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; } +} -- 2.11.0