⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cy22393.c

📁 Freescale MCF5445evb 参考测试代码
💻 C
字号:
/*!  * \file    cy22393.c * \brief   Cypress Clock Generator Driver *  * This driver uses the I2C bus to communicate with the Cypress CY22393. All * writes to the CY22393 are volatile.  A device reset will revert the clock * outputs to the state defined in the non-volatile memory of the CY22393. * * \author  Michael Norman * \version $Revision: 1.1 $ */#include "common.h"#include "cy22393.h"#include "i2c.h"extern I2C_BUFFER i2c_tx_buffer;extern I2C_BUFFER i2c_rx_buffer;/********************************************************************/voidcy22393_init(void){    /* Configure GPIO pins to I2C function */    MCF_GPIO_PAR_FECI2C |= 0        | MCF_GPIO_PAR_FECI2C_SCL_SCL         | MCF_GPIO_PAR_FECI2C_SDA_SDA;    /* Set transmission frequency 0x19 = 103.9kHz, 0x1A = 86.6kHz */    MCF_I2C_I2FDR = 0x19;    /* Set module's I2C address to 0x6A */    MCF_I2C_I2AR = 0x6A;    /* Enable I2C module */    MCF_I2C_I2CR = 0xC0;}/********************************************************************/voidcy22393_read(int addr, uint8 *buf, int bytes){    int i;        i2c_tx_buffer.tx_index = 0;    i2c_tx_buffer.rx_index = 0;    i2c_tx_buffer.data_present = TRUE;    i2c_tx_buffer.length = 1;    i2c_tx_buffer.buf[0] = addr; /* Starting address of Cypress clock memory */    /* Initialize RX buffer structure */    i2c_rx_buffer.tx_index = 0;    i2c_rx_buffer.rx_index = 0;    i2c_rx_buffer.data_present = FALSE;    i2c_rx_buffer.length = bytes;    /* Perform TX/RX using Repeated start */    i2c_master(I2C_TXRX, CY22393_WR_ADDR);        for (i = 0; i < bytes; i++)        buf[i] = i2c_rx_buffer.buf[i];}/********************************************************************/voidcy22393_write(int addr, uint8 *buf, int bytes){}/********************************************************************/voidcy22393_dump (void){    int i;        i2c_tx_buffer.tx_index = 0;    i2c_tx_buffer.rx_index = 0;    i2c_tx_buffer.data_present = TRUE;    i2c_tx_buffer.length = 1;    i2c_tx_buffer.buf[0] = 0x0; /* Starting address of Cypress clock memory */    /* Initialize RX buffer structure */    i2c_rx_buffer.tx_index = 0;    i2c_rx_buffer.rx_index = 0;    i2c_rx_buffer.data_present = FALSE;    i2c_rx_buffer.length = 88;    /* Perform TX/RX using Repeated start */    i2c_master(I2C_TXRX, CY22393_WR_ADDR);        printf("   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");    printf("   -----------------------------------------------");    for ( i = 0; i < 88; i++ )    {        if ((i % 16) == 0)            printf("\n%02X ", i);        printf("%02X ", i2c_rx_buffer.buf[i]);    }}/********************************************************************/voidcy22393_disable_clk(CY22393_CLK clk){    switch (clk)    {        case CY22393_CLKA:             i2c_tx_buffer.buf[0] = 0x08;            i2c_tx_buffer.buf[1] = 0x0;            i2c_tx_buffer.buf[2] = 0x0;            i2c_tx_buffer.length = 3;            break;        case CY22393_CLKB:             i2c_tx_buffer.buf[0] = 0x0A;            i2c_tx_buffer.buf[1] = 0x0;            i2c_tx_buffer.buf[2] = 0x0;            i2c_tx_buffer.length = 3;            break;        case CY22393_CLKC:             i2c_tx_buffer.buf[0] = 0x0C;            i2c_tx_buffer.buf[1] = 0x0;            i2c_tx_buffer.length = 2;            break;        case CY22393_CLKD:             i2c_tx_buffer.buf[0] = 0x0D;            i2c_tx_buffer.buf[1] = 0x0;            i2c_tx_buffer.length = 2;            break;        case CY22393_CLKE:             i2c_tx_buffer.buf[0] = 0x0F;            i2c_tx_buffer.buf[1] = 0x58;            i2c_tx_buffer.length = 2;            break;        default:            break;    }        i2c_tx_buffer.tx_index = 0;    i2c_tx_buffer.rx_index = 0;    i2c_tx_buffer.data_present = TRUE;        i2c_master(I2C_TX, CY22393_WR_ADDR);}/********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -