]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/misc/led.c
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / drivers / misc / led.c
diff --git a/FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/misc/led.c b/FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/misc/led.c
new file mode 100644 (file)
index 0000000..643ded3
--- /dev/null
@@ -0,0 +1,149 @@
+/* ----------------------------------------------------------------------------\r
+ *         SAM Software Package License\r
+ * ----------------------------------------------------------------------------\r
+ * Copyright (c) 2015, Atmel Corporation\r
+ *\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions are met:\r
+ *\r
+ * - Redistributions of source code must retain the above copyright notice,\r
+ * this list of conditions and the disclaimer below.\r
+ *\r
+ * Atmel's name may not be used to endorse or promote products derived from\r
+ * this software without specific prior written permission.\r
+ *\r
+ * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
+ * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ----------------------------------------------------------------------------\r
+ */\r
+\r
+/**\r
+ * \file\r
+ */\r
+\r
+/*------------------------------------------------------------------------------\r
+ *         Headers\r
+ *------------------------------------------------------------------------------*/\r
+\r
+#include "board.h"\r
+#include "misc/led.h"\r
+#include "peripherals/pio.h"\r
+\r
+/*------------------------------------------------------------------------------\r
+ *         Local Variables\r
+ *------------------------------------------------------------------------------*/\r
+\r
+#ifdef PINS_LEDS\r
+static const struct _pin pinsLeds[] = PINS_LEDS;\r
+\r
+static const uint32_t numLeds = ARRAY_SIZE(pinsLeds);\r
+#endif\r
+\r
+/*------------------------------------------------------------------------------\r
+ *         Global Functions\r
+ *------------------------------------------------------------------------------*/\r
+\r
+/**\r
+ *  Configures the pin associated with the given LED number. If the LED does\r
+ *  not exist on the board, the function does nothing.\r
+ *  \param dwLed  Number of the LED to configure.\r
+ *  \return 1 if the LED exists and has been configured; otherwise 0.\r
+ */\r
+extern uint32_t led_configure (uint32_t led)\r
+{\r
+#ifdef PINS_LEDS\r
+       // Check that LED exists\r
+       if (led >= numLeds) {\r
+               return 0;\r
+       }\r
+       // Configure LED\r
+       return pio_configure(&pinsLeds[led], 1);\r
+#else\r
+       return 0;\r
+#endif\r
+}\r
+\r
+/**\r
+ *  Turns the given LED on if it exists; otherwise does nothing.\r
+ *  \param dwLed  Number of the LED to turn on.\r
+ *  \return 1 if the LED has been turned on; 0 otherwise.\r
+ */\r
+extern uint32_t led_set(uint32_t led)\r
+{\r
+#ifdef PINS_LEDS\r
+       /* Check if LED exists */\r
+       if (led >= numLeds) {\r
+               return 0;\r
+       }\r
+\r
+       /* Turn LED on */\r
+       if (pinsLeds[led].type == PIO_OUTPUT_0) {\r
+               pio_set(&pinsLeds[led]);\r
+       } else {\r
+               pio_clear(&pinsLeds[led]);\r
+       }\r
+       return 1;\r
+#else\r
+       return 0;\r
+#endif\r
+}\r
+\r
+/**\r
+ *  Turns a LED off.\r
+ *\r
+ *  \param dwLed  Number of the LED to turn off.\r
+ *  \return 1 if the LED has been turned off; 0 otherwise.\r
+ */\r
+extern uint32_t led_clear (uint32_t led)\r
+{\r
+#ifdef PINS_LEDS\r
+       /* Check if LED exists */\r
+       if (led >= numLeds) {\r
+               return 0;\r
+       }\r
+       /* Turn LED off */\r
+       if (pinsLeds[led].type == PIO_OUTPUT_0) {\r
+               pio_clear(&pinsLeds[led]);\r
+       } else {\r
+               pio_set(&pinsLeds[led]);\r
+       }\r
+       return 1;\r
+#else\r
+       return 0;\r
+#endif\r
+}\r
+\r
+/**\r
+ *  Toggles the current state of a LED.\r
+ *\r
+ *  \param dwLed  Number of the LED to toggle.\r
+ *  \return 1 if the LED has been toggled; otherwise 0.\r
+ */\r
+extern uint32_t led_toggle(uint32_t led)\r
+{\r
+#ifdef PINS_LEDS\r
+       /* Check if LED exists */\r
+       if (led >= numLeds) {\r
+               return 0;\r
+       }\r
+       /* Toggle LED */\r
+       if (pio_get_output_data_status(&pinsLeds[led])) {\r
+               pio_clear(&pinsLeds[led]);\r
+       } else {\r
+               pio_set(&pinsLeds[led]);\r
+       }\r
+       return 1;\r
+#else\r
+       return 0;\r
+#endif\r
+}\r