[En-Nut-Discussion] Heartbeat LED for ARM

Krzysztof Sawicki krzysztof.sawicki at mobile.put.edu.pl
Wed Feb 19 14:44:07 CET 2014


a copy from cm3 nutinit:

Index: nut/arch/arm/os/nutinit.c
===================================================================
--- nut/arch/arm/os/nutinit.c	(revision 5578)
+++ nut/arch/arm/os/nutinit.c	(working copy)
@@ -43,6 +43,7 @@
  #endif

  #include <dev/board.h>
+#include <dev/gpio.h>

  #ifdef EARLY_STDIO_DEV
  #include <sys/device.h>
@@ -117,6 +118,27 @@
      /* Initialize system timers. */
      NutTimerInit();

+
+#if defined(HEARTBEAT_IDLE_PORT) && defined(HEARTBEAT_IDLE_PIN)
+    GpioPinConfigSet(HEARTBEAT_IDLE_PORT, HEARTBEAT_IDLE_PIN, 
GPIO_CFG_OUTPUT);
+    GpioPinSetHigh(HEARTBEAT_IDLE_PORT, HEARTBEAT_IDLE_PIN);
+#if defined(HEARTBEAT_IDLE_INVERT)
+#define HEARTBEAT_ACTIVE() \
+    GpioPinSetLow(HEARTBEAT_IDLE_PORT, HEARTBEAT_IDLE_PIN)
+#define HEARTBEAT_IDLE()  \
+    GpioPinSetHigh(HEARTBEAT_IDLE_PORT, HEARTBEAT_IDLE_PIN)
+#else
+#define HEARTBEAT_ACTIVE()  \
+    GpioPinSetHigh(HEARTBEAT_IDLE_PORT, HEARTBEAT_IDLE_PIN)
+#define HEARTBEAT_IDLE() \
+    GpioPinSetLow(HEARTBEAT_IDLE_PORT, HEARTBEAT_IDLE_PIN)
+#endif
+#else
+#define HEARTBEAT_ACTIVE()
+#define HEARTBEAT_IDLE()
+#endif
+
+
      /* Read OS configuration from non-volatile memory. We can't do this
      ** earlier, because the low level driver may be interrupt driven. */
      NutLoadConfig();
@@ -136,11 +158,13 @@
      ** all other threads are waiting for an event. */
      NutThreadSetPriority(254);
      for (;;) {
+    	HEARTBEAT_ACTIVE();
          /* Check if other threads became ready to run. */
          NutThreadYield();
          /* Remove terminated threads. */
          NutThreadDestroy();
          /* We could do some power management. */
+        HEARTBEAT_IDLE();
      }
  }

-- 
Krzysztof Sawicki
Mobile Systems Research Labs, Poznan University of Technology


More information about the En-Nut-Discussion mailing list