cs2200.h File Reference


Detailed Description

Driver of the iPod authentication chip.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file cs2200.h.

#include <avr32/io.h>
#include "compiler.h"
#include "conf_cs2200.h"

Go to the source code of this file.

Defines

#define _32_BITS_RATIO(frequency)   ((int)(((float)frequency/FOSC0)*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2))
 Build the 32-bits ratio constant to be loaded in the CS2200 to make the desired frequency.
#define PPM(value, ppm)   ( ((int)( (long long)value*(ppm)/1000000) ) )
 Compute the PPM of a number.
#define PPM_ADD(value, ppm)   ( ((int)(value + (long long)value*(ppm)/1000000)) )
 Add x PPM to a value.
#define PPM_SUB(value, ppm)   ( ((int)(value - (long long)value*(ppm)/1000000)) )
 Remove x PPM to a value.
Communication Interfaces
#define CS2200_INTERFACE_SPI   1
#define CS2200_INTERFACE_TWI   2
Macro Constructors
These macros create inline functions to access the cs2200 registers.

#define CS2200_READ(name)
#define CS2200_READ1(name)
#define CS2200_READ2(name)
#define CS2200_READ4(name)
#define CS2200_WRITE(name)
#define CS2200_WRITE1(name)
#define CS2200_WRITE2(name)
#define CS2200_WRITE4(name)
Register Addresses
#define CS2200_REG_32_BITS_RATIO_ADDR   0x06
#define CS2200_REG_DEVICE_CFG_1_ADDR   0x03
#define CS2200_REG_DEVICE_CTRL_ADDR   0x02
#define CS2200_REG_DEVICE_ID_ADDR   0x01
#define CS2200_REG_FUNCT_CFG_1_ADDR   0x16
#define CS2200_REG_FUNCT_CFG_2_ADDR   0x17
#define CS2200_REG_GLOBAL_CFG_ADDR   0x05
#define CS2200_REG_LSB_RATIO_ADDR   0x09
#define CS2200_REG_LSW_RATIO_ADDR   0x08
#define CS2200_REG_TEST_MODE_1_ADDR   0x00
#define CS2200_REG_TEST_MODE_2_ADDR   0x77

Functions

void cs2200_enter_power_down_mode (void)
 Enter power down mode and stop twi comms.
void cs2200_enter_test_mode (void)
 Enter into the test mode.
void cs2200_freq_clk_adjust (U16 lsw_ratio)
 Function used to adjust the CLK_OUT frequency (LSW only).
void cs2200_freq_clk_out (U32 ratio)
 Function used to program the CLK_OUT frequency.
void cs2200_leave_power_down_mode (void)
 Leave power down mode and twi comms can be restarted.
void cs2200_leave_test_mode (void)
 Leave the test mode.
void cs2200_read (U8 address, void *buffer, U8 len)
 Reads data from the CS2200 chip.
 CS2200_READ1 (FUNCT_CFG_2)
 CS2200_READ1 (FUNCT_CFG_1)
 CS2200_READ1 (GLOBAL_CFG)
 CS2200_READ1 (DEVICE_CFG_1)
 CS2200_READ1 (DEVICE_CTRL)
 CS2200_READ1 (DEVICE_ID)
 CS2200_READ4 (32_BITS_RATIO)
void cs2200_set_new_freq_clk_out (U32 ratio)
 Function used to program the CLK_OUT frequency and wait that the PLL is locked.
Bool cs2200_setup (U32 out_freq)
 Function used to initialize the chip and communication interface.
void cs2200_switch_off (void)
void cs2200_switch_on (void)
void cs2200_write (U8 address, const void *buffer, U8 len)
 Writes data into the CS2200 chip.
 CS2200_WRITE1 (TEST_MODE_2)
 CS2200_WRITE1 (TEST_MODE_1)
 CS2200_WRITE1 (FUNCT_CFG_2)
 CS2200_WRITE1 (FUNCT_CFG_1)
 CS2200_WRITE1 (LSB_RATIO)
 CS2200_WRITE1 (GLOBAL_CFG)
 CS2200_WRITE1 (DEVICE_CFG_1)
 CS2200_WRITE1 (DEVICE_CTRL)
 CS2200_WRITE4 (32_BITS_RATIO)
int cs2200_write_ex (U8 address, const void *buffer, U8 len)
 Writes data into the CS2200 chip using the non blocking release of the TWI driver.


Define Documentation

#define _32_BITS_RATIO ( frequency   )     ((int)(((float)frequency/FOSC0)*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2))

Build the 32-bits ratio constant to be loaded in the CS2200 to make the desired frequency.

Definition at line 64 of file cs2200.h.

Referenced by cs2200_setup(), and main().

#define CS2200_INTERFACE_SPI   1

Definition at line 59 of file cs2200.h.

#define CS2200_INTERFACE_TWI   2

Definition at line 60 of file cs2200.h.

#define CS2200_READ ( name   ) 

Value:

static inline void CS2200_READ_##name(void *data, size_t len)                  \
{                                                                              \
  cs2200_read(CS2200_REG_##name##_ADDR, data, len);                            \
}

Definition at line 143 of file cs2200.h.

#define CS2200_READ1 ( name   ) 

Value:

static inline U8 CS2200_READ_##name(void)                                      \
{                                                                              \
  U8 data;                                                                     \
  cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data));                  \
  return data;                                                                 \
}

Definition at line 149 of file cs2200.h.

#define CS2200_READ2 ( name   ) 

Value:

static inline U16 CS2200_READ_##name(void)                                     \
{                                                                              \
  U16 data;                                                                    \
  cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data));                  \
  return data;                                                                 \
}

Definition at line 157 of file cs2200.h.

#define CS2200_READ4 ( name   ) 

Value:

static inline U32 CS2200_READ_##name(void)                                     \
{                                                                              \
  U32 data;                                                                    \
  cs2200_read(CS2200_REG_##name##_ADDR, &data, sizeof(data));                  \
  return data;                                                                 \
}

Definition at line 165 of file cs2200.h.

#define CS2200_REG_32_BITS_RATIO_ADDR   0x06

Definition at line 206 of file cs2200.h.

#define CS2200_REG_DEVICE_CFG_1_ADDR   0x03

Definition at line 204 of file cs2200.h.

#define CS2200_REG_DEVICE_CTRL_ADDR   0x02

Definition at line 203 of file cs2200.h.

#define CS2200_REG_DEVICE_ID_ADDR   0x01

Definition at line 202 of file cs2200.h.

#define CS2200_REG_FUNCT_CFG_1_ADDR   0x16

Definition at line 209 of file cs2200.h.

#define CS2200_REG_FUNCT_CFG_2_ADDR   0x17

Definition at line 210 of file cs2200.h.

#define CS2200_REG_GLOBAL_CFG_ADDR   0x05

Definition at line 205 of file cs2200.h.

#define CS2200_REG_LSB_RATIO_ADDR   0x09

Definition at line 208 of file cs2200.h.

#define CS2200_REG_LSW_RATIO_ADDR   0x08

Definition at line 207 of file cs2200.h.

Referenced by cs2200_freq_clk_adjust().

#define CS2200_REG_TEST_MODE_1_ADDR   0x00

Definition at line 201 of file cs2200.h.

#define CS2200_REG_TEST_MODE_2_ADDR   0x77

Definition at line 211 of file cs2200.h.

#define CS2200_WRITE ( name   ) 

Value:

static inline void CS2200_WRITE_##name(const void *data, size_t len)           \
{                                                                              \
  cs2200_write(CS2200_REG_##name##_ADDR, data, len);                           \
}

Definition at line 173 of file cs2200.h.

#define CS2200_WRITE1 ( name   ) 

Value:

static inline void CS2200_WRITE_##name(U8 data)                                \
{                                                                              \
  cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data));                 \
}

Definition at line 179 of file cs2200.h.

#define CS2200_WRITE2 ( name   ) 

Value:

static inline void CS2200_WRITE_##name(U16 data)                               \
{                                                                              \
  cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data));                 \
}

Definition at line 185 of file cs2200.h.

#define CS2200_WRITE4 ( name   ) 

Value:

static inline void CS2200_WRITE_##name(U32 data)                               \
{                                                                              \
  cs2200_write(CS2200_REG_##name##_ADDR, &data, sizeof(data));                 \
}

Definition at line 191 of file cs2200.h.

#define PPM ( value,
ppm   )     ( ((int)( (long long)value*(ppm)/1000000) ) )

Compute the PPM of a number.

Definition at line 67 of file cs2200.h.

Referenced by main().

#define PPM_ADD ( value,
ppm   )     ( ((int)(value + (long long)value*(ppm)/1000000)) )

Add x PPM to a value.

Definition at line 70 of file cs2200.h.

#define PPM_SUB ( value,
ppm   )     ( ((int)(value - (long long)value*(ppm)/1000000)) )

Remove x PPM to a value.

Definition at line 73 of file cs2200.h.


Function Documentation

void cs2200_enter_power_down_mode ( void   ) 

Enter power down mode and stop twi comms.

void cs2200_enter_test_mode ( void   ) 

Enter into the test mode.

Definition at line 139 of file cs2200.c.

Referenced by cs2200_setup().

00140 {
00141   CS2200_WRITE_TEST_MODE_1(0x99); // Unlock
00142   CS2200_WRITE_TEST_MODE_2(0x80); // force_normal state
00143 }

void cs2200_freq_clk_adjust ( U16  lsw_ratio  ) 

Function used to adjust the CLK_OUT frequency (LSW only).

Definition at line 159 of file cs2200.c.

References CS2200_REG_LSW_RATIO_ADDR, and cs2200_write_ex().

Referenced by main().

00160 {
00161   static U16 s_ratio;
00162   s_ratio=lsh_ratio;
00163   cs2200_write_ex(CS2200_REG_LSW_RATIO_ADDR, &s_ratio, sizeof(lsh_ratio));
00164 }

void cs2200_freq_clk_out ( U32  ratio  ) 

Function used to program the CLK_OUT frequency.

Definition at line 153 of file cs2200.c.

Referenced by main().

00154 {
00155   CS2200_WRITE_32_BITS_RATIO(ratio);
00156 }

void cs2200_leave_power_down_mode ( void   ) 

Leave power down mode and twi comms can be restarted.

void cs2200_leave_test_mode ( void   ) 

Leave the test mode.

Definition at line 146 of file cs2200.c.

00147 {
00148   CS2200_WRITE_TEST_MODE_2(0x00); // test mode default setting
00149   CS2200_WRITE_TEST_MODE_1(0x00); // Lock
00150 }

void cs2200_read ( U8  address,
void *  buffer,
U8  len 
)

Reads data from the CS2200 chip.

CS2200_READ1 ( FUNCT_CFG_2   ) 

CS2200_READ1 ( FUNCT_CFG_1   ) 

CS2200_READ1 ( GLOBAL_CFG   ) 

CS2200_READ1 ( DEVICE_CFG_1   ) 

CS2200_READ1 ( DEVICE_CTRL   ) 

CS2200_READ1 ( DEVICE_ID   ) 

CS2200_READ4 ( 32_BITS_RATIO   ) 

void cs2200_set_new_freq_clk_out ( U32  ratio  ) 

Function used to program the CLK_OUT frequency and wait that the PLL is locked.

Bool cs2200_setup ( U32  out_freq  ) 

Function used to initialize the chip and communication interface.

Definition at line 101 of file cs2200.c.

References _32_BITS_RATIO, CS2200_DEVICE_ID_REG_MASK, CS2200_DEVICE_ID_REG_OFFSET, cs2200_enter_test_mode(), CS2200_EXPECTED_DEVICE_ID, and CS2200_NB_TRIES.

Referenced by main().

00102 {
00103   int device_id;
00104   int nb_tries = CS2200_NB_TRIES;
00105 
00106   do
00107   {
00108     device_id = (CS2200_READ_DEVICE_ID() & CS2200_DEVICE_ID_REG_MASK) >> CS2200_DEVICE_ID_REG_OFFSET;
00109   // Make sure the chip is functional.
00110   } while ((device_id != CS2200_EXPECTED_DEVICE_ID)
00111          && --nb_tries);
00112 
00113   // If number of tries is over, return an error.
00114   if (!nb_tries)
00115     return FALSE;
00116 
00117   // Freeze chip during the programmation
00118   CS2200_WRITE_GLOBAL_CFG(1<<3);
00119 
00120   CS2200_WRITE_DEVICE_CTRL(0x00); // AUX_OUT output driver enabled. CLK_OUT output driver enabled.
00121   CS2200_WRITE_DEVICE_CFG_1( 0 << 5 // Left-shift R-value by 0 (x 1).
00122                            | 0 << 1 // RefClk: is the source of the AUX_OUT signal
00123                            );
00124   CS2200_WRITE_32_BITS_RATIO(_32_BITS_RATIO(out_freq)); // Program a default clock.
00125   CS2200_WRITE_FUNCT_CFG_1( 0x00 << 6 // Push-Pull, Active High (output ‘high’ for unlocked condition, ‘low’ for locked condition).
00126                           | 0x02 << 3 // Reference Clock Input Divider: ÷ 1 [8 MHz to 18.75 MHz]
00127                           );
00128   CS2200_WRITE_FUNCT_CFG_2( 0x00 << 4 // Clock outputs are driven ‘low’ when PLL is unlocked.
00129                           );
00130 
00131   // Unleash chip
00132   CS2200_WRITE_GLOBAL_CFG( 0x00 << 3 // Freeze
00133                          | 0x01 << 0 // EnDevCfg2
00134                          );
00135   cs2200_enter_test_mode();
00136   return TRUE;
00137 }

void cs2200_switch_off ( void   ) 

Definition at line 97 of file cs2200.c.

00098 {
00099 }

void cs2200_switch_on ( void   ) 

Definition at line 93 of file cs2200.c.

00094 {
00095 }

void cs2200_write ( U8  address,
const void *  buffer,
U8  len 
)

Writes data into the CS2200 chip.

CS2200_WRITE1 ( TEST_MODE_2   ) 

CS2200_WRITE1 ( TEST_MODE_1   ) 

CS2200_WRITE1 ( FUNCT_CFG_2   ) 

CS2200_WRITE1 ( FUNCT_CFG_1   ) 

CS2200_WRITE1 ( LSB_RATIO   ) 

CS2200_WRITE1 ( GLOBAL_CFG   ) 

CS2200_WRITE1 ( DEVICE_CFG_1   ) 

CS2200_WRITE1 ( DEVICE_CTRL   ) 

CS2200_WRITE4 ( 32_BITS_RATIO   ) 

int cs2200_write_ex ( U8  address,
const void *  buffer,
U8  len 
)

Writes data into the CS2200 chip using the non blocking release of the TWI driver.

Referenced by cs2200_freq_clk_adjust().


Generated on Thu Dec 17 19:57:30 2009 for AVR32 - CLOCK_SYNTHESIZER CS2200 by  doxygen 1.5.5