/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> 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. ------------------------------------------------------------------ ================================================================== */ #include "i2c_monitor.h" #include unsigned char i2c_mon_init(struct i2c_mon_instance *this_i2cmon, unsigned int base_addr) { volatile struct i2c_mon_dev *dev; if (NULL == this_i2cmon) { return 1; } this_i2cmon->base_addr = base_addr; this_i2cmon->num_entry = 0; this_i2cmon->event_det_cnt = 0; this_i2cmon->int_en = 0; this_i2cmon->evt_entry_num = 0; return 0; } unsigned char i2c_mon_conf(struct i2c_mon_instance *this_i2cmon, struct i2c_mon_entry *entry_data, unsigned int entry_num) { volatile struct i2c_mon_entry *dev_entry; if (NULL == this_i2cmon) { return 1; } dev_entry = (struct i2c_mon_entry *) this_i2cmon->base_addr; if (entry_num <= this_i2cmon->num_entry) { for (int i = 0; i < entry_num; i++) { *dev_entry++ = *entry_data++; } } else { return 1; } return 0; } // disable/enable for each entry unsigned char i2c_mon_enable(struct i2c_mon_instance *this_i2cmon, unsigned int mon_en) { if (NULL == this_i2cmon) { return 1; } volatile struct i2c_mon_dev *dev = (struct i2c_mon_dev *) (this_i2cmon->base_addr + I2C_MON_DEV_OFFSET); if (mon_en) { dev->i2cbf_cr |= I2CBF_DET_EN; } else { dev->i2cbf_cr &= (~I2CBF_DET_EN); } return 0; } unsigned char i2c_mon_bus_stop(struct i2c_mon_instance *this_i2cmon, unsigned char bus_stop) { if (NULL == this_i2cmon) { return 1; } volatile struct i2c_mon_dev *dev = (struct i2c_mon_dev *) (this_i2cmon->base_addr + I2C_MON_DEV_OFFSET); if (bus_stop) { // stop the bus dev->i2cbf_cr |= I2CBF_BUS_STOP; } else { // release the bus dev->i2cbf_cr &= (~I2CBF_BUS_STOP); } return 0; } unsigned char i2c_mon_status_get(struct i2c_mon_instance *this_i2cmon, unsigned char *event_cnt, unsigned int *dct_evt) { if (NULL == this_i2cmon) { return 1; } volatile struct i2c_mon_dev *dev = (struct i2c_mon_dev *) (this_i2cmon->base_addr + I2C_MON_DEV_OFFSET); // disable int to avoid confliction dev->i2cbf_intenr &= (~I2CBF_INT_EN); *event_cnt = this_i2cmon->event_det_cnt; *dct_evt = this_i2cmon->evt_entry_num; this_i2cmon->evt_entry_num = 0; this_i2cmon->event_det_cnt = 0; // enable the int dev->i2cbf_intenr |= I2CBF_INT_EN; return 0; } void i2c_mon_isr(unsigned int intr_level, void *ctx) { unsigned char status = 0; struct i2c_mon_instance *this_i2cmon = (struct i2c_mon_instance *) ctx; volatile struct i2c_mon_dev *dev = (struct i2c_mon_dev *) (this_i2cmon->base_addr + I2C_MON_DEV_OFFSET); // read back the current detected event status = dev->i2cbf_sr; if (status & I2CBF_ENT_DET) { this_i2cmon->event_det_cnt += 1; this_i2cmon->evt_entry_num = (1 << (status & I2CBF_ENT_NUM_MASK)); // clear the interrupt dev->i2cbf_intsetr = I2CBF_INT_EN; } return; }