--- /dev/null
+/*****************************************************************************\r
+* © 2015 Microchip Technology Inc. and its subsidiaries.\r
+* You may use this software and any derivatives exclusively with\r
+* Microchip products.\r
+* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".\r
+* NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,\r
+* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,\r
+* AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP\r
+* PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.\r
+* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,\r
+* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND\r
+* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS\r
+* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.\r
+* TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL\r
+* CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF\r
+* FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.\r
+* MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE\r
+* OF THESE TERMS.\r
+******************************************************************************\r
+\r
+Version Control Information (Perforce)\r
+******************************************************************************\r
+$Revision: #1 $ \r
+$DateTime: 2016/09/22 08:03:49 $ \r
+$Author: pramans $\r
+Last Change: Updated with unit testing feedbacks\r
+******************************************************************************/\r
+/** @file btimer.h\r
+* \brief Basic Timer Peripheral Header file\r
+* \author jvasanth\r
+* \r
+* This file is the header file for Basic Timer Peripheral \r
+******************************************************************************/\r
+\r
+/** @defgroup Basic_Timer\r
+ * @{\r
+ */\r
+\r
+#ifndef _BTIMER_H\r
+#define _BTIMER_H\r
+\r
+/******************************************************************************/\r
+/** Logical Timer ID for APIs.\r
+ * This is the timer IDs passed to Basic Timer API function calls \r
+ *******************************************************************************/\r
+enum _PID_BTIMER_\r
+{\r
+ PID_BTIMER_0,\r
+ PID_BTIMER_1,\r
+ PID_BTIMER_2,\r
+ PID_BTIMER_3,\r
+ PID_BTIMER_4,\r
+ PID_BTIMER_5,\r
+ PID_BTIMER_MAX \r
+};\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* Logical flags for Timer Control */\r
+/* ---------------------------------------------------------------------- */\r
+//This is for tmr_cntl parameter in btimer_init function\r
+#define BTIMER_AUTO_RESTART (0x08u)\r
+#define BTIMER_ONE_SHOT (0u)\r
+#define BTIMER_COUNT_UP (0x04u)\r
+#define BTIMER_COUNT_DOWN (0u)\r
+#define BTIMER_INT_EN (0x01u)\r
+#define BTIMER_NO_INT (0u)\r
+/* ---------------------------------------------------------------------- */\r
+\r
+\r
+//Timer Block Hardware Bits and Masks\r
+#define BTIMER_CNTL_HALT (0x80UL)\r
+#define BTIMER_CNTL_RELOAD (0x40UL)\r
+#define BTIMER_CNTL_START (0x20UL)\r
+#define BTIMER_CNTL_SOFT_RESET (0x10UL)\r
+#define BTIMER_CNTL_AUTO_RESTART (0x08UL)\r
+#define BTIMER_CNTL_COUNT_UP (0x04UL)\r
+#define BTIMER_CNTL_ENABLE (0x01UL)\r
+\r
+#define BTIMER_CNTL_HALT_BIT (7U)\r
+#define BTIMER_CNTL_RELOAD_BIT (6U)\r
+#define BTIMER_CNTL_START_BIT (5U)\r
+#define BTIMER_CNTRL_SOFT_RESET_BIT (4U)\r
+#define BTIMER_CNTL_AUTO_RESTART_BIT (3U)\r
+#define BTIMER_CNTL_COUNT_DIR_BIT (2U)\r
+#define BTIMER_CNTL_ENABLE_BIT (0U)\r
+\r
+#define BTIMER_GIRQ MEC_GIRQ23_ID\r
+#define BTIMER_MAX_INSTANCE PID_BTIMER_MAX\r
+\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Basic Timer Intitialization function */\r
+/* ---------------------------------------------------------------------- */\r
+\r
+/** Initialize specified timer\r
+ * @param btimer_id Basic Timer ID\r
+ * @param tmr_cntl Logical flags for Timer Control\r
+ * @param initial_count Initial Count\r
+ * @param preload_count Preload Count\r
+ * @note Performs a soft reset of the timer before configuration \r
+ */\r
+void btimer_init(uint8_t btimer_id, \r
+ uint16_t tmr_cntl,\r
+ uint16_t prescaler,\r
+ uint32_t initial_count,\r
+ uint32_t preload_count);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Functions to program and read the Basic Timer Counter */\r
+/* ---------------------------------------------------------------------- */\r
+/** Program timer's counter register.\r
+ * @param btimer_id Basic Timer ID\r
+ * @param count new counter value \r
+ * @note Timer hardware may implement a 16-bit or 32-bit \r
+ * hardware counter. If the timer is 16-bit only the lower\r
+ * 16-bits of the count paramter are used.\r
+ */\r
+void btimer_count_set(uint8_t btimer_id, uint32_t count);\r
+\r
+/** Return current value of timer's count register.\r
+ * @param btimer_id Basic Timer ID. \r
+ * @return uint32_t timer count may be 32 or 16 bits depending \r
+ * upon the hardware. Timers 0-3 are 16-bit\r
+ * and Timers 4-5 are 32-bit.\r
+ */\r
+uint32_t btimer_count_get(uint8_t btimer_id);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Function to reload counter from Preload Register */\r
+/* ---------------------------------------------------------------------- */\r
+/** Force timer to reload counter from preload \r
+ * register. \r
+ * @param btimer_id Basic Timer ID. \r
+ * @note Hardware will only reload counter if timer is running. \r
+ */\r
+void btimer_reload(uint8_t btimer_id);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Functions for stopping and starting the basic Timer */\r
+/* ---------------------------------------------------------------------- */\r
+/** Start timer counting.\r
+ * @param btimer_id Basic Timer ID.\r
+ */\r
+void btimer_start(uint8_t btimer_id);\r
+\r
+/** Stop timer. \r
+ * @param btimer_id Basic Timer ID. \r
+ * @note When a stopped timer is started again it will reload \r
+ * the count register from preload value.\r
+ */\r
+void btimer_stop(uint8_t btimer_id);\r
+\r
+/** Return state of timer's START bit. \r
+ * @param btimer_id Basic Timer ID. \r
+ * @return uint8_t 0(timer not started), 1 (timer started)\r
+ */\r
+uint8_t btimer_is_started(uint8_t btimer_id);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Function to perform basic timer soft reset */\r
+/* ---------------------------------------------------------------------- */\r
+/** Peform soft reset of specified timer. \r
+ * @param btimer_id Basic Timer ID \r
+ * @note Soft reset set all registers to POR values.\r
+ * Spins 256 times waiting on hardware to clear reset bit. \r
+ */\r
+void btimer_reset(uint8_t btimer_id);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Functions to halt/unhalt the timer counting */\r
+/* ---------------------------------------------------------------------- */\r
+/** Halt timer counting with no reload on unhalt. \r
+ * @param btimer_id Basic Timer ID. \r
+ * @note A halted timer will not reload the count register when \r
+ * unhalted, it will continue counting from the current\r
+ * count value.\r
+ */\r
+void btimer_halt(uint8_t btimer_id);\r
+\r
+/** Unhalt timer counting. \r
+ * @param btimer_id Basic Timer ID.\r
+ */\r
+void btimer_unhalt(uint8_t btimer_id);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Functions for Basic Timer interrupt */\r
+/* ---------------------------------------------------------------------- */\r
+/** Enable specified timer's interrupt from the block. \r
+ * @param btimer_id Basic Timer ID.\r
+ * @param ien Non-zero enable interrupt in timer block, 0 \r
+ * disable.\r
+ */\r
+void btimer_interrupt_enable(uint8_t btimer_id, uint8_t ien);\r
+\r
+/** Read Timer interrupt status and clear if set \r
+ * @param btimer_id Basic Timer ID. \r
+ * @return uint8_t 1 (Timer interrupt status set) else 0. \r
+ * @note If timer interrupt status is set then clear it before \r
+ * returning.\r
+ */\r
+uint8_t btimer_interrupt_status_get_clr(uint8_t btimer_id);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Functions for Basic Timer GIRQ */\r
+/* ---------------------------------------------------------------------- */\r
+/** Enables GIRQ enable bit for the timer \r
+ * @param btimer_id Basic Timer ID.\r
+ */\r
+void btimer_girq_enable_set(uint8_t btimer_id);\r
+\r
+/** Clears GIRQ enable bit for the timer \r
+ * @param btimer_id Basic Timer ID.\r
+ */\r
+void btimer_girq_enable_clr(uint8_t btimer_id);\r
+\r
+/** Returns GIRQ source bit for the timer \r
+ * @param btimer_id Basic Timer ID.\r
+ * @return uint8_t 0(src bit not set), Non-zero (src bit set)\r
+ */\r
+uint8_t btimer_girq_src_get(uint8_t btimer_id);\r
+\r
+/** Clears GIRQ source bit for the timer \r
+ * @param btimer_id Basic Timer ID.\r
+ */\r
+void btimer_girq_src_clr(uint8_t btimer_id);\r
+\r
+/** Returns GIRQ result bit for the timer \r
+ * @param btimer_id Basic Timer ID.\r
+ * @return uint8_t 0(result bit not set), Non-zero (result bit set)\r
+ */\r
+uint8_t btimer_girq_result_get(uint8_t btimer_id);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* API - Functions for Basic Timer Sleep */\r
+/* ---------------------------------------------------------------------- */\r
+/** Enable/Disable clock gating on idle of a timer \r
+ * @param btimer_id Basic Timer ID.\r
+ * @param sleep_en 1 = Sleep enable, 0 = Sleep disable\r
+ */\r
+void btimer_sleep(uint8_t btimer_id, uint8_t sleep_en);\r
+\r
+/** Returns clk required status for the timer block\r
+ * @param btimer_id Basic Timer ID.\r
+ * @return Non-zero if clk required, else 0\r
+ */\r
+uint32_t btimer_clk_reqd_sts_get(uint8_t btimer_id);\r
+\r
+/** Enable/Disable reset on sleep for the timer block \r
+ * @param btimer_id Basic Timer ID.\r
+ * @param reset_en 1 to enable, 0 to disable\r
+ */\r
+void btimer_reset_on_sleep(uint8_t btimer_id, uint8_t reset_en);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* Peripheral Function - Functions to set and read Timer Counter Register */\r
+/* ---------------------------------------------------------------------- */\r
+/** Sets timer counter\r
+ * @param btimer_id Basic Timer ID\r
+ * @param count - 32-bit counter \r
+ */\r
+void p_btimer_count_set(uint8_t btimer_id, uint32_t count);\r
+\r
+/** Read the timer counter\r
+ * @param btimer_id Basic Timer ID\r
+ * @return count - 32-bit counter \r
+ */\r
+uint32_t p_btimer_count_get(uint8_t btimer_id);\r
+\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* Peripheral Function - Function to program the Preload */\r
+/* ---------------------------------------------------------------------- */\r
+/** Sets preload for the counter\r
+ * @param btimer_id Basic Timer ID\r
+ * @param preload_count - 32-bit pre-load value \r
+ */\r
+void p_btimer_preload_set(uint8_t btimer_id, uint32_t preload_count);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* Peripheral Functions - Functions for basic timer interrupts */\r
+/* ---------------------------------------------------------------------- */\r
+/** Reads the interrupt status bit in the timer block\r
+ * @param btimer_id Basic Timer ID \r
+ * @return status - 1 if interrupt status set, else 0\r
+ */\r
+uint8_t p_btimer_int_status_get(uint8_t btimer_id);\r
+\r
+/** Clears interrupt status bit in the timer block\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_int_status_clr(uint8_t btimer_id);\r
+\r
+/** Sets interrupt enable bit in the timer block\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_int_enable_set(uint8_t btimer_id);\r
+\r
+/** Clears interrupt enable bit for the timer block\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_int_enable_clr(uint8_t btimer_id);\r
+\r
+/* ---------------------------------------------------------------------- */\r
+/* Peripheral Functions - Functions for Control Register */\r
+/* ---------------------------------------------------------------------- */\r
+/** Writes the control register 32-bits\r
+ * @param btimer_id Basic Timer ID\r
+ * @param value - 32-bit value to program\r
+ */\r
+void p_btimer_ctrl_write(uint8_t btimer_id, uint32_t value);\r
+\r
+/** Reads the control register \r
+ * @param btimer_id Basic Timer ID\r
+ * @return uint32_t - 32-bit value\r
+ */\r
+uint32_t p_btimer_ctrl_read(uint8_t btimer_id);\r
+\r
+/** Clears enable bit in the control register\r
+ * @param btimer_id Basic Timer ID\r
+ */\r
+void p_btimer_ctrl_enable_set(uint8_t btimer_id);\r
+\r
+/** Clears enable bit in the control register\r
+ * @param btimer_id Basic Timer ID\r
+ */\r
+void p_btimer_ctrl_enable_clr(uint8_t btimer_id);\r
+\r
+/** Sets counter direction bit in the control register\r
+ * @param btimer_id Basic Timer ID\r
+ */\r
+void p_btimer_ctrl_counter_dir_set(uint8_t btimer_id);\r
+\r
+/** Clears counter direction bit in the control register\r
+ * @param btimer_id Basic Timer ID\r
+ */\r
+void p_btimer_ctrl_counter_dir_clr(uint8_t btimer_id);\r
+\r
+/** Sets auto restart bit in the control register\r
+ * @param btimer_id Basic Timer ID\r
+ */\r
+void p_btimer_ctrl_auto_restart_set(uint8_t btimer_id);\r
+\r
+/** Clears auto resetart bit in the control register\r
+ * @param btimer_id Basic Timer ID\r
+ */\r
+void p_btimer_ctrl_auto_restart_clr(uint8_t btimer_id);\r
+\r
+/** Sets soft reset bit in the control register\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_ctrl_soft_reset_set(uint8_t btimer_id);\r
+\r
+/** Read Soft Reset bit \r
+ * @param btimer_id Basic Timer ID\r
+ * @return 0 if soft reset status bit cleared; else non-zero value\r
+ */\r
+uint8_t p_btimer_ctrl_soft_reset_sts_get(uint8_t btimer_id);\r
+\r
+/** Sets start bit in the control register\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_ctrl_start_set(uint8_t btimer_id);\r
+\r
+/** Read start bit in the control register\r
+ * @param btimer_id Basic Timer ID \r
+ * @return 0 if start bit not set; else non-zero value\r
+ */\r
+uint8_t p_btimer_ctrl_start_get(uint8_t btimer_id);\r
+\r
+/** Clears start bit in the control register\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_ctrl_start_clr(uint8_t btimer_id);\r
+\r
+/** Sets reload bit in the control register\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_ctrl_reload_set(uint8_t btimer_id);\r
+\r
+/** Clears reload bit in the control register\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_ctrl_reload_clr(uint8_t btimer_id);\r
+\r
+/** Sets halt bit in the control register\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+void p_btimer_ctrl_halt_set(uint8_t btimer_id);\r
+\r
+/** Clears halt bit in the control register\r
+ * @param btimer_id Basic Timer ID \r
+ */\r
+\r
+void p_btimer_ctrl_halt_clr(uint8_t btimer_id);\r
+\r
+/** Sets prescale value\r
+ * @param btimer_id Basic Timer ID\r
+ * @param prescaler - 16-bit pre-scale value \r
+ */\r
+void p_btimer_ctrl_prescale_set(uint8_t btimer_id, uint16_t prescaler);\r
+\r
+\r
+#endif // #ifndef _BTIMER_H\r
+\r
+/* end btimer_perphl.c */\r
+\r
+/** @} //Peripherals Basic_Timer\r
+ */\r
+\r