]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/utils/timer.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / utils / timer.h
diff --git a/FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/utils/timer.h b/FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/utils/timer.h
new file mode 100644 (file)
index 0000000..d75f7e2
--- /dev/null
@@ -0,0 +1,121 @@
+/* ----------------------------------------------------------------------------\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
+ *  \par Purpose\r
+ *\r
+ *  Methods and definitions for an internal timer.\r
+ *\r
+ *  Defines a common and simpliest use of timer to generate delays using PIT\r
+ *\r
+ *  \par Usage\r
+ *\r
+ *  -# Configure the System Tick with timer_configure() when MCK changed\r
+ *     \note\r
+ *     Must be done before any invoke of timer_wait(), or timer_sleep()\r
+ *  -# Uses timer_wait to actively wait according to your timer resolution.\r
+ *  -# Uses timer_sleep to passively wait ccording to your timer resolution.\r
+ *\r
+ */\r
+\r
+#ifndef TIMER_HEADER_\r
+#define TIMER_HEADER_\r
+\r
+/*----------------------------------------------------------------------------\r
+ *         Headers\r
+ *----------------------------------------------------------------------------*/\r
+\r
+#include <stdint.h>\r
+\r
+struct _timeout\r
+{\r
+       uint32_t start;\r
+       uint32_t count;\r
+};\r
+/*----------------------------------------------------------------------------\r
+ *         Global functions\r
+ *----------------------------------------------------------------------------*/\r
+\r
+/**\r
+ *  \brief Configures the PIT & reset _timer.\r
+ *  Systick interrupt handler will generates 1ms interrupt and increase a\r
+ *  tickCount.\r
+ *\r
+ *  \note PIT is enabled automatically in this function.\r
+ *  \warning This function also set PIT handler to aic which is\r
+ *  mandatory to make the timer API work\r
+ *\r
+ *  \param resolution initialize PIT resolution (in nano seconds)\r
+ */\r
+extern uint32_t timer_configure(uint32_t resolution);\r
+\r
+/**\r
+ *  \brief Sync wait for count times resoltion\r
+ */\r
+extern void timer_wait(uint32_t count);\r
+\r
+/**\r
+ * \brief Retrieve current timer resolution.\r
+ *\r
+ * \return Current timer resolution (0 if not already set)\r
+ */\r
+extern uint32_t timer_get_resolution(void);\r
+\r
+/**\r
+ *  \brief Sync sleep for count times resolution\r
+ */\r
+extern void timer_sleep(uint32_t count);\r
+\r
+/**\r
+ *  \brief Initialize a timeout\r
+ */\r
+extern void timer_start_timeout(struct _timeout* timeout, uint32_t count);\r
+\r
+/**\r
+ *  \brief Tells if the timeout as been reached\r
+ */\r
+extern uint8_t timer_timeout_reached(struct _timeout* timeout);\r
+\r
+/**\r
+ * \brief Compute elapsed number of ticks between start and end with\r
+ * taking overlaps into accounts\r
+ *\r
+ * \param start Start tick point.\r
+ * \param end End tick point.\r
+ */\r
+extern uint32_t timer_get_interval(uint32_t start, uint32_t end);\r
+\r
+/**\r
+ * \brief Returns the current number of ticks\r
+ */\r
+extern uint32_t timer_get_tick(void);\r
+\r
+#endif /* TIMER_HEADER_ */\r