/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<< ------------------------------------------------------------------ Copyright (c) 2019-2020 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ IMPORTANT: THIS FILE IS USED BY OR GENERATED BY the LATTICE PROPELâ„¢ DEVELOPMENT SUITE, WHICH INCLUDES PROPEL BUILDER AND PROPEL SDK. Lattice grants permission to use this code pursuant to the terms of the Lattice Propel License Agreement. DISCLAIMER: LATTICE MAKES NO WARRANTIES ON THIS FILE OR ITS CONTENTS, WHETHER EXPRESSED, IMPLIED, STATUTORY, OR IN ANY PROVISION OF THE LATTICE PROPEL LICENSE AGREEMENT OR COMMUNICATION WITH LICENSEE, AND LATTICE SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. LATTICE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED HEREIN WILL MEET LICENSEE 'S REQUIREMENTS, OR THAT LICENSEE' S OPERATION OF ANY DEVICE, SOFTWARE OR SYSTEM USING THIS FILE OR ITS CONTENTS WILL BE UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS HEREIN WILL BE CORRECTED. LICENSEE ASSUMES RESPONSIBILITY FOR SELECTION OF MATERIALS TO ACHIEVE ITS INTENDED RESULTS, AND FOR THE PROPER INSTALLATION, USE, AND RESULTS OBTAINED THEREFROM. LICENSEE ASSUMES THE ENTIRE RISK OF THE FILE AND ITS CONTENTS PROVING DEFECTIVE OR FAILING TO PERFORM PROPERLY AND IN SUCH EVENT, LICENSEE SHALL ASSUME THE ENTIRE COST AND RISK OF ANY REPAIR, SERVICE, CORRECTION, OR ANY OTHER LIABILITIES OR DAMAGES CAUSED BY OR ASSOCIATED WITH THE SOFTWARE.IN NO EVENT SHALL LATTICE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS FILE OR ITS CONTENTS, EVEN IF LATTICE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. LATTICE 'S SOLE LIABILITY, AND LICENSEE' S SOLE REMEDY, IS SET FORTH ABOVE. LATTICE DOES NOT WARRANT OR REPRESENT THAT THIS FILE, ITS CONTENTS OR USE THEREOF DOES NOT INFRINGE ON THIRD PARTIES' INTELLECTUAL PROPERTY RIGHTS, INCLUDING ANY PATENT. IT IS THE USER' S RESPONSIBILITY TO VERIFY THE USER SOFTWARE DESIGN FOR CONSISTENCY AND FUNCTIONALITY THROUGH THE USE OF FORMAL SOFTWARE VALIDATION METHODS. ------------------------------------------------------------------ ================================================================== */ #ifndef GP_TIMER_H_ #define GP_TIMER_H_ #include #include #include enum GP_TIMER { GP_TIMER0 = 0, GP_TIMER1 = 1, GP_TIMER2, GP_TIMER3, GP_TIMER4, GP_TIMER5, GP_TIMER6, GP_TIMER7, GP_TIMER8, }; #define PRESCALER_RATIO_2 0 #define PRESCALER_RATIO_4 1 #define PRESCALER_RATIO_8 2 #define PRESCALER_RATIO_16 3 #define PRESCALER_RATIO_32 4 #define PRESCALER_RATIO_64 5 #define PRESCALER_RATIO_128 6 #define PRESCALER_RATIO_256 7 #define PRESCALER_RATIO_512 8 #define PRESCALER_RATIO_1024 9 #define PRESCALER_RATIO_2048 10 #define PRESCALER_RATIO_4096 11 #define PRESCALER_RATIO_8192 12 #define PRESCALER_RATIO_16384 13 #define PRESCALER_RATIO_32768 14 #define PRESCALER_RATIO_65536 15 #define PRESCALER_RATIO_131072 16 #define PRESCALER_RATIO_262144 17 #define PRESCALER_RATIO_524288 18 #define PRESCALER_RATIO_1048576 19 #define PRESCALER_RATIO_2097152 20 #define PRESCALER_RATIO_4194304 21 #define PRESCALER_RATIO_8388608 22 #define PRESCALER_RATIO_16777216 23 #define PRESCALER_RATIO_33554432 24 #define PRESCALER_RATIO_67108864 25 #define PRESCALER_RATIO_134217728 26 #define PRESCALER_RATIO_268435456 27 #define PRESCALER_RATIO_536870912 28 #define PRESCALER_RATIO_1073741824 29 #define PRESCALER_RATIO_2147483648 30 #define PRESCALER_RATIO_4294967296 31 struct timer_callback_entry { void (*timer_callback) (void *); // the registered timer callback function void *context; // the context of the callback }; struct timer_conf { uint16_t reload_value; unsigned char b_continue; }; struct gp_timer_instance{ //char *instance_name; unsigned int base_addr; unsigned int sys_clk; unsigned int timer_clk[GP_TIMER8]; unsigned char timer_num; unsigned int prescaler; struct timer_conf tc[GP_TIMER8]; struct timer_callback_entry callback_table[GP_TIMER8]; }; /* register definition */ #define TIMER_INT_EN 0x04 #define GLB_CTRL 0x0c #define TIMER_START 0x04 #define TIMER_DIR_COUNT_DOWD 0 #define TIMER_DIR_COUNT_UP 1 #define TIMER0_STATUS 0x10 #define TIMER0_CNT 0x1c #define TIMER1_CNT 0x2c #define TIMER2_CNT 0x3c #define TIMER3_CNT 0x4c #define TIMER0_PERIOD 0x18 #define TIMER0_CON 0x14 #define TIMER_INT 0x00 /*********************************************************************** * Initialize the general purpose timer IP * ***********************************************************************/ unsigned char gp_timer_init(struct gp_timer_instance *this_timer, unsigned int base_address, unsigned int clock, unsigned char gp_timer_cnt); /*********************************************************************** * Configure the timer * ***********************************************************************/ unsigned char gp_timer_config(struct gp_timer_instance *this_timer, unsigned char timer_src, bool continuous,uint32_t pscaler,uint8_t dir,uint16_t period); /*********************************************************************** * Get the snapshot of the specified timer * ***********************************************************************/ unsigned char gp_timer_snapshot_get(struct gp_timer_instance *this_timer, unsigned char timer_src, unsigned int *snapshot); /*********************************************************************** * Get the status of the specified timer * ***********************************************************************/ //unsigned char gp_timer_status_get(struct gp_timer_instance *this_timer, unsigned char timer_src, unsigned char* timer_status); /*********************************************************************** * Start/stop the specified timer * ***********************************************************************/ unsigned char gp_timer_start(struct gp_timer_instance *this_timer, unsigned char timer_src, void (*timer_callback) (void *), void *context); unsigned char gp_timer_stop(struct gp_timer_instance *this_timer, unsigned char timer_src); /*********************************************************************** * The interrupt service routine for timer * ***********************************************************************/ void gp_timer_isr(void *ctx); #endif