ADF4360 - See http://mbed.org/forum/helloworld/topic/1430

Committer:
AjK
Date:
Mon Nov 22 13:14:01 2010 +0000
Revision:
0:528dac948be7
Child:
1:4037b46f2040
http://mbed.org/forum/helloworld/topic/1430

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:528dac948be7 1 /*
AjK 0:528dac948be7 2 Copyright (c) 2010 Andy Kirkham
AjK 0:528dac948be7 3
AjK 0:528dac948be7 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AjK 0:528dac948be7 5 of this software and associated documentation files (the "Software"), to deal
AjK 0:528dac948be7 6 in the Software without restriction, including without limitation the rights
AjK 0:528dac948be7 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AjK 0:528dac948be7 8 copies of the Software, and to permit persons to whom the Software is
AjK 0:528dac948be7 9 furnished to do so, subject to the following conditions:
AjK 0:528dac948be7 10
AjK 0:528dac948be7 11 The above copyright notice and this permission notice shall be included in
AjK 0:528dac948be7 12 all copies or substantial portions of the Software.
AjK 0:528dac948be7 13
AjK 0:528dac948be7 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AjK 0:528dac948be7 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AjK 0:528dac948be7 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AjK 0:528dac948be7 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AjK 0:528dac948be7 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AjK 0:528dac948be7 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AjK 0:528dac948be7 20 THE SOFTWARE.
AjK 0:528dac948be7 21 */
AjK 0:528dac948be7 22
AjK 0:528dac948be7 23 #ifndef MODADF4360_H
AjK 0:528dac948be7 24 #define MODADF4360_H
AjK 0:528dac948be7 25
AjK 0:528dac948be7 26 #include "mbed.h"
AjK 0:528dac948be7 27
AjK 0:528dac948be7 28 #define GET_CNTL_LATCH(pos,mask) return(control_latch>>pos)&mask
AjK 0:528dac948be7 29 #define SET_CNTL_LATCH(pos,mask,n) control_latch&=~(mask<<pos);control_latch|=((n&mask)<<pos)
AjK 0:528dac948be7 30 #define GET_N_LATCH(pos,mask) return(counterNlatch>>pos)&mask
AjK 0:528dac948be7 31 #define SET_N_LATCH(pos,mask,n) counterNlatch&=~(mask<<pos);counterNlatch|=((n&mask)<<pos)
AjK 0:528dac948be7 32 #define GET_R_LATCH(pos,mask) return(counterRlatch>>pos)&mask
AjK 0:528dac948be7 33 #define SET_R_LATCH(pos,mask,n) counterRlatch&=~(mask<<pos);counterRlatch|=((n&mask)<<pos)
AjK 0:528dac948be7 34
AjK 0:528dac948be7 35 /** @defgroup Control_Latch The Control Latch */
AjK 0:528dac948be7 36 /** @defgroup Counter_N_Latch The Counter N Latch */
AjK 0:528dac948be7 37 /** @defgroup Counter_R_Latch The Counter R Latch */
AjK 0:528dac948be7 38
AjK 0:528dac948be7 39 class ADF4360 {
AjK 0:528dac948be7 40 public:
AjK 0:528dac948be7 41
AjK 0:528dac948be7 42 ADF4360(PinName mosi, PinName miso, PinName sclk, PinName le) {
AjK 0:528dac948be7 43 _le = new DigitalOut(le);
AjK 0:528dac948be7 44 _le->write(1);
AjK 0:528dac948be7 45 _ssp = new SPI(mosi, miso, sclk);
AjK 0:528dac948be7 46 _ssp->format(8,0);
AjK 0:528dac948be7 47 _ssp->frequency(1000000);
AjK 0:528dac948be7 48 };
AjK 0:528dac948be7 49
AjK 0:528dac948be7 50 ~ADF4360() { delete(_le); delete(_ssp); };
AjK 0:528dac948be7 51
AjK 0:528dac948be7 52 /** @ingroup Control_Latch */
AjK 0:528dac948be7 53 int prescalerValue(void) { GET_CNTL_LATCH(22,3); }
AjK 0:528dac948be7 54 /** @ingroup Control_Latch */
AjK 0:528dac948be7 55 void prescalerValue(int i) { SET_CNTL_LATCH(22,3UL,i); }
AjK 0:528dac948be7 56
AjK 0:528dac948be7 57 /** @ingroup Control_Latch */
AjK 0:528dac948be7 58 int powerDown2(void) { GET_CNTL_LATCH(21,1); }
AjK 0:528dac948be7 59 /** @ingroup Control_Latch */
AjK 0:528dac948be7 60 void powerDown2(int i) { SET_CNTL_LATCH(21,1UL,i); }
AjK 0:528dac948be7 61
AjK 0:528dac948be7 62 /** @ingroup Control_Latch */
AjK 0:528dac948be7 63 int powerDown1(void) { GET_CNTL_LATCH(20,1); }
AjK 0:528dac948be7 64 /** @ingroup Control_Latch */
AjK 0:528dac948be7 65 void powerDown1(int i) { SET_CNTL_LATCH(20,1UL,i); }
AjK 0:528dac948be7 66
AjK 0:528dac948be7 67 /** @ingroup Control_Latch */
AjK 0:528dac948be7 68 int currentSetting2(void) { GET_CNTL_LATCH(17,7); }
AjK 0:528dac948be7 69 /** @ingroup Control_Latch */
AjK 0:528dac948be7 70 void currentSetting2(int i) { SET_CNTL_LATCH(17,7UL,i); }
AjK 0:528dac948be7 71
AjK 0:528dac948be7 72 /** @ingroup Control_Latch */
AjK 0:528dac948be7 73 int currentSetting1(void) { GET_CNTL_LATCH(14,7); }
AjK 0:528dac948be7 74 /** @ingroup Control_Latch */
AjK 0:528dac948be7 75 void currentSetting1(int i) { SET_CNTL_LATCH(14,7UL,i); }
AjK 0:528dac948be7 76
AjK 0:528dac948be7 77 /** @ingroup Control_Latch */
AjK 0:528dac948be7 78 int outputPowerLevel(void) { GET_CNTL_LATCH(12,3); }
AjK 0:528dac948be7 79 /** @ingroup Control_Latch */
AjK 0:528dac948be7 80 void outputPowerLevel(int i) { SET_CNTL_LATCH(12,3UL,i); }
AjK 0:528dac948be7 81
AjK 0:528dac948be7 82 /** @ingroup Control_Latch */
AjK 0:528dac948be7 83 int muteTillLockDetect(void) { GET_CNTL_LATCH(11,1); }
AjK 0:528dac948be7 84 /** @ingroup Control_Latch */
AjK 0:528dac948be7 85 void muteTillLockDetect(int i) { SET_CNTL_LATCH(11,1UL,i); }
AjK 0:528dac948be7 86
AjK 0:528dac948be7 87 /** @ingroup Control_Latch */
AjK 0:528dac948be7 88 int cpGain(void) { GET_CNTL_LATCH(10,1); }
AjK 0:528dac948be7 89 /** @ingroup Control_Latch */
AjK 0:528dac948be7 90 void cpGain(int i) { SET_CNTL_LATCH(10,1UL,i); }
AjK 0:528dac948be7 91
AjK 0:528dac948be7 92 /** @ingroup Control_Latch */
AjK 0:528dac948be7 93 int cpOutput(void) { GET_CNTL_LATCH(9,1); }
AjK 0:528dac948be7 94 /** @ingroup Control_Latch */
AjK 0:528dac948be7 95 void cpOutput(int i) { SET_CNTL_LATCH(9,1UL,i); }
AjK 0:528dac948be7 96
AjK 0:528dac948be7 97 /** @ingroup Control_Latch */
AjK 0:528dac948be7 98 int phaseDetectPol(void) { GET_CNTL_LATCH(8,1); }
AjK 0:528dac948be7 99 /** @ingroup Control_Latch */
AjK 0:528dac948be7 100 void phaseDetectPol(int i) { SET_CNTL_LATCH(8,1UL,i); }
AjK 0:528dac948be7 101
AjK 0:528dac948be7 102 /** @ingroup Control_Latch */
AjK 0:528dac948be7 103 int muxControl(void) { GET_CNTL_LATCH(5,7); }
AjK 0:528dac948be7 104 /** @ingroup Control_Latch */
AjK 0:528dac948be7 105 void muxControl(int i) { SET_CNTL_LATCH(5,7UL,i); }
AjK 0:528dac948be7 106
AjK 0:528dac948be7 107 /** @ingroup Control_Latch */
AjK 0:528dac948be7 108 int counterReset(void) { GET_CNTL_LATCH(4,1); }
AjK 0:528dac948be7 109 /** @ingroup Control_Latch */
AjK 0:528dac948be7 110 void counterReset(int i) { SET_CNTL_LATCH(4,1UL,i); }
AjK 0:528dac948be7 111
AjK 0:528dac948be7 112 /** @ingroup Control_Latch */
AjK 0:528dac948be7 113 int corePowerLevel(void) { GET_CNTL_LATCH(2,3); }
AjK 0:528dac948be7 114 /** @ingroup Control_Latch */
AjK 0:528dac948be7 115 void corePowerLevel(int i) { SET_CNTL_LATCH(2,3UL,i); }
AjK 0:528dac948be7 116
AjK 0:528dac948be7 117 void controlLatchWrite(void) {
AjK 0:528dac948be7 118 _le->write(0);
AjK 0:528dac948be7 119 _ssp->write((control_latch >> 16) & 0xFF);
AjK 0:528dac948be7 120 _ssp->write((control_latch >> 8) & 0xFF);
AjK 0:528dac948be7 121 _ssp->write((control_latch & 0xFF) & ~(3UL << 0));
AjK 0:528dac948be7 122 _le->write(1);
AjK 0:528dac948be7 123 }
AjK 0:528dac948be7 124
AjK 0:528dac948be7 125 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 126 int divideBy2Select(void) { GET_N_LATCH(23,1); }
AjK 0:528dac948be7 127 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 128 void divideBy2Select(int i) { SET_N_LATCH(23,1UL,i); }
AjK 0:528dac948be7 129
AjK 0:528dac948be7 130 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 131 int divideBy2(void) { GET_N_LATCH(22,1); }
AjK 0:528dac948be7 132 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 133 void divideBy2(int i) { SET_N_LATCH(22,1UL,i); }
AjK 0:528dac948be7 134
AjK 0:528dac948be7 135 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 136 int nCPGain(void) { GET_N_LATCH(21,1); }
AjK 0:528dac948be7 137 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 138 void nCPGain(int i) { SET_N_LATCH(21,1UL,i); }
AjK 0:528dac948be7 139
AjK 0:528dac948be7 140 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 141 int counterB(void) { GET_N_LATCH(8,0x1FFF); }
AjK 0:528dac948be7 142 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 143 void counterB(int i) { SET_N_LATCH(8,0x1FFFUL,i); }
AjK 0:528dac948be7 144
AjK 0:528dac948be7 145 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 146 int counterA(void) { GET_N_LATCH(2,0x1F); }
AjK 0:528dac948be7 147 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 148 void counterA(int i) { SET_N_LATCH(2,0x1FUL,i); }
AjK 0:528dac948be7 149
AjK 0:528dac948be7 150 void counterNWrite(void) {
AjK 0:528dac948be7 151 _le->write(0);
AjK 0:528dac948be7 152 _ssp->write((counterNlatch >> 16) & 0xFF);
AjK 0:528dac948be7 153 _ssp->write((counterNlatch >> 8) & 0xFF);
AjK 0:528dac948be7 154 _ssp->write(((counterNlatch & 0xFF) & ~(0x3CUL << 0)) | (2UL << 0));
AjK 0:528dac948be7 155 _le->write(1);
AjK 0:528dac948be7 156 }
AjK 0:528dac948be7 157
AjK 0:528dac948be7 158 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 159 int bandSelectClock(void) { GET_R_LATCH(20,3); }
AjK 0:528dac948be7 160 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 161 void bandSelectClock(int i) { SET_R_LATCH(20,3UL,i); }
AjK 0:528dac948be7 162
AjK 0:528dac948be7 163 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 164 int testModeBit(void) { GET_R_LATCH(19,1); }
AjK 0:528dac948be7 165 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 166 void testModeBit(int i) { SET_R_LATCH(19,1UL,i); }
AjK 0:528dac948be7 167
AjK 0:528dac948be7 168 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 169 int lockDetect(void) { GET_R_LATCH(18,1); }
AjK 0:528dac948be7 170 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 171 void lockDetect(int i) { SET_R_LATCH(18,1UL,i); }
AjK 0:528dac948be7 172
AjK 0:528dac948be7 173 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 174 int antiBacklash(void) { GET_R_LATCH(16,3); }
AjK 0:528dac948be7 175 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 176 void antiBacklash(int i) { SET_R_LATCH(16,3UL,i); }
AjK 0:528dac948be7 177
AjK 0:528dac948be7 178 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 179 int counterRef(void) { GET_R_LATCH(2,0x3FFF); }
AjK 0:528dac948be7 180 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 181 void counterRef(int i) { SET_R_LATCH(2,0x3FFFUL,i); }
AjK 0:528dac948be7 182
AjK 0:528dac948be7 183 void counterRWrite(void) {
AjK 0:528dac948be7 184 _le->write(0);
AjK 0:528dac948be7 185 _ssp->write((counterRlatch >> 16) & 0xFF);
AjK 0:528dac948be7 186 _ssp->write((counterRlatch >> 8) & 0xFF);
AjK 0:528dac948be7 187 _ssp->write(((counterRlatch & 0xFF) & ~(0x3CUL << 0)) | (1UL << 0));
AjK 0:528dac948be7 188 _le->write(1);
AjK 0:528dac948be7 189 }
AjK 0:528dac948be7 190
AjK 0:528dac948be7 191 protected:
AjK 0:528dac948be7 192
AjK 0:528dac948be7 193 uint32_t control_latch;
AjK 0:528dac948be7 194 uint32_t counterNlatch;
AjK 0:528dac948be7 195 uint32_t counterRlatch;
AjK 0:528dac948be7 196
AjK 0:528dac948be7 197 SPI *_ssp;
AjK 0:528dac948be7 198 DigitalOut *_le;
AjK 0:528dac948be7 199 };
AjK 0:528dac948be7 200
AjK 0:528dac948be7 201
AjK 0:528dac948be7 202 #endif