00001 /* ---------------------------------------------------------------------------- 00002 * SAM Software Package License 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2014, Atmel Corporation 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the disclaimer below. 00013 * 00014 * Atmel's name may not be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00020 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00023 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00026 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * ---------------------------------------------------------------------------- 00028 */ 00029 00030 /** 00031 * \file 00032 * 00033 * Implementation CS2100 driver. 00034 * 00035 */ 00036 00037 /*---------------------------------------------------------------------------- 00038 * Headers 00039 *----------------------------------------------------------------------------*/ 00040 00041 #include "board.h" 00042 00043 /*---------------------------------------------------------------------------- 00044 * Type 00045 *----------------------------------------------------------------------------*/ 00046 typedef struct { 00047 uint16_t value; 00048 uint8_t address; 00049 }CS2100_PARA; 00050 00051 /*---------------------------------------------------------------------------- 00052 * Exported functions 00053 *----------------------------------------------------------------------------*/ 00054 /** 00055 * \brief Read data from CS2100 Register. 00056 * 00057 * \param pTwid Pointer to twi driver structure 00058 * \param device Twi slave address. 00059 * \param regAddr Register address to read. 00060 * \return value in the given register. 00061 */ 00062 uint16_t CS2100_Read(Twid *pTwid, 00063 uint32_t device, 00064 uint32_t regAddr) 00065 { 00066 uint16_t bitsDataRegister; 00067 uint8_t Tdata[2]={0,0}; 00068 00069 TWID_Read(pTwid, device, regAddr, 1, Tdata, 2, 0); 00070 bitsDataRegister = (Tdata[0] << 8) | Tdata[1]; 00071 return bitsDataRegister; 00072 } 00073 00074 /** 00075 * \brief Write data to CS2100 Register. 00076 * 00077 * \param pTwid Pointer to twi driver structure 00078 * \param device Twi slave address. 00079 * \param regAddr Register address to write. 00080 * \param data Data to write 00081 */ 00082 void CS2100_Write(Twid *pTwid, 00083 uint32_t device, 00084 uint32_t regAddr, 00085 uint16_t data) 00086 { 00087 uint8_t tmpData[2]; 00088 tmpData[0] = (data & 0xff00) >> 8; 00089 tmpData[1] = data & 0xff; 00090 TWID_Write(pTwid, device, regAddr, 1, tmpData, 2, 0); 00091 } 00092 00093 /** 00094 * \brief Initialize CS2100 Clock Multiplier. 00095 * 00096 * \param pTwid Pointer to twi driver structure 00097 * \param device Twi slave address. 00098 * \param PCK Device programmable clock 00099 */ 00100 uint8_t CS2100_Init(Twid *pTwid, uint32_t device, uint32_t PCK) 00101 { 00102 uint16_t data = 0; 00103 // Reset (write Reg@0x0 to reset) 00104 CS2100_Write(pTwid, device, 0, 0xFFFF); 00105 00106 for(data = 0; data < 1000; data++); 00107 //wait ready 00108 while(data!=0x8904) 00109 data = CS2100_Read(pTwid, device, 0); 00110 return 0; 00111 } 00112 00113