00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 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 00108 //wait ready 00109 while (data != 0x8904) 00110 data = CS2100_Read(pTwid, device, 0); 00111 00112 return 0; 00113 } 00114 00115