Andy K / MODADF4360
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MODADF4360.h Source File

MODADF4360.h

00001 /*
00002     Copyright (c) 2010 Andy Kirkham
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021 */
00022 
00023 #ifndef MODADF4360_H
00024 #define MODADF4360_H
00025 
00026 #include "mbed.h"
00027 
00028 #define GET_CNTL_LATCH(pos,mask)    return(control_latch>>pos)&mask
00029 #define SET_CNTL_LATCH(pos,mask,n)  control_latch&=~(mask<<pos);control_latch|=((n&mask)<<pos)
00030 #define GET_N_LATCH(pos,mask)       return(counterNlatch>>pos)&mask
00031 #define SET_N_LATCH(pos,mask,n)     counterNlatch&=~(mask<<pos);counterNlatch|=((n&mask)<<pos)
00032 #define GET_R_LATCH(pos,mask)       return(counterRlatch>>pos)&mask
00033 #define SET_R_LATCH(pos,mask,n)     counterRlatch&=~(mask<<pos);counterRlatch|=((n&mask)<<pos)
00034 
00035 /** @defgroup Control_Latch The Control Latch */
00036 /** @defgroup Counter_N_Latch The Counter N Latch */
00037 /** @defgroup Counter_R_Latch The Counter R Latch */
00038 
00039 /**
00040  * @author Andy Kirkham
00041  * @see Control_Latch
00042  * @see Counter_N_Latch
00043  * @see Counter_R_Latch
00044  *
00045  * <b>MODADF4360</b> Test library
00046  *
00047  * Standard example:
00048  * @code
00049  * #include "mbed.h"
00050  * #include "MODADF4360.h"
00051  *
00052  * DigitalOut led1(LED1);
00053  * ADF4360 adf(p5, p6, p7, p8);
00054  *
00055  * int main() {
00056  *
00057  *     // Setup all the parts of the Control Latch
00058  *     adf.prescalerValue(1);
00059  *     adf.cpGain(1);
00060  *     //... set all the parts you need, then...
00061  *     
00062  *     // Once all the parts ate set, write them to the device.
00063  *     adf.controlLatchWrite();
00064  *
00065  *     // repeat for N and R latches.
00066  *
00067  *     while(1) {
00068  *         led1 = !led1;
00069  *         wait(1);
00070  *     }
00071  * }
00072  * @endcode
00073  */
00074 class ADF4360  {
00075 public:
00076 
00077     ADF4360 (PinName mosi, PinName miso, PinName sclk, PinName le) {
00078         _le = new DigitalOut(le);
00079         _le->write(1);    
00080         _ssp = new SPI(mosi, miso, sclk);
00081         _ssp->format(8,0);
00082         _ssp->frequency(1000000);    
00083     };
00084 
00085     ~ADF4360 () { delete(_le); delete(_ssp); };
00086 
00087     /** 
00088      * @ingroup Control_Latch 
00089      */
00090     int  prescalerValue(void)       { GET_CNTL_LATCH(22,3); }
00091     
00092     /** 
00093      * @ingroup Control_Latch 
00094      */
00095     void prescalerValue(int i)      { SET_CNTL_LATCH(22,3UL,i); }
00096 
00097     /** 
00098      * @ingroup Control_Latch 
00099      */
00100     int  powerDown2(void)           { GET_CNTL_LATCH(21,1); }
00101     
00102     /** 
00103      * @ingroup Control_Latch 
00104      */
00105     void powerDown2(int i)          { SET_CNTL_LATCH(21,1UL,i); }
00106     
00107     /** 
00108      * @ingroup Control_Latch 
00109      */
00110     int  powerDown1(void)           { GET_CNTL_LATCH(20,1); } 
00111     
00112     /** 
00113      * @ingroup Control_Latch 
00114      */
00115     void powerDown1(int i)          { SET_CNTL_LATCH(20,1UL,i); }
00116     
00117     /** 
00118      * @ingroup Control_Latch 
00119      */
00120     int  currentSetting2(void)      { GET_CNTL_LATCH(17,7); }
00121     
00122     /** 
00123      * @ingroup Control_Latch 
00124      */
00125     void currentSetting2(int i)     { SET_CNTL_LATCH(17,7UL,i); }
00126     
00127     /** 
00128      * @ingroup Control_Latch 
00129      */
00130     int  currentSetting1(void)      { GET_CNTL_LATCH(14,7); } 
00131     
00132     /** 
00133      * @ingroup Control_Latch 
00134      */
00135     void currentSetting1(int i)     { SET_CNTL_LATCH(14,7UL,i); }
00136     
00137     /** 
00138      * @ingroup Control_Latch 
00139      */
00140     int  outputPowerLevel(void)     { GET_CNTL_LATCH(12,3); }
00141     
00142     /** 
00143      * @ingroup Control_Latch 
00144      */
00145     void outputPowerLevel(int i)    { SET_CNTL_LATCH(12,3UL,i); }
00146     
00147     /** 
00148      * @ingroup Control_Latch 
00149      */
00150     int  muteTillLockDetect(void)   { GET_CNTL_LATCH(11,1); } 
00151     
00152     /** 
00153      * @ingroup Control_Latch 
00154      */
00155     void muteTillLockDetect(int i)  { SET_CNTL_LATCH(11,1UL,i); }
00156     
00157     /** 
00158      * @ingroup Control_Latch 
00159      */
00160     int  cpGain(void)               { GET_CNTL_LATCH(10,1); }
00161     
00162     /** 
00163      * @ingroup Control_Latch 
00164      */
00165     void cpGain(int i)              { SET_CNTL_LATCH(10,1UL,i); }
00166     
00167     /** 
00168      * @ingroup Control_Latch 
00169      */
00170     int  cpOutput(void)             { GET_CNTL_LATCH(9,1); }
00171     
00172     /** 
00173      * @ingroup Control_Latch 
00174      */
00175     void cpOutput(int i)            { SET_CNTL_LATCH(9,1UL,i); }
00176     
00177     /** 
00178      * @ingroup Control_Latch 
00179      */
00180     int  phaseDetectPol(void)       { GET_CNTL_LATCH(8,1); }
00181     
00182     /** 
00183      * @ingroup Control_Latch 
00184      */
00185     void phaseDetectPol(int i)      { SET_CNTL_LATCH(8,1UL,i); }
00186     
00187     /** 
00188      * @ingroup Control_Latch 
00189      */
00190     int  muxControl(void)           { GET_CNTL_LATCH(5,7); }
00191     
00192     /** 
00193      * @ingroup Control_Latch 
00194      */
00195     void muxControl(int i)          { SET_CNTL_LATCH(5,7UL,i); }
00196     
00197     /** 
00198      * @ingroup Control_Latch 
00199      */
00200     int  counterReset(void)         { GET_CNTL_LATCH(4,1); }
00201     
00202     /** 
00203      * @ingroup Control_Latch 
00204      */
00205     void counterReset(int i)        { SET_CNTL_LATCH(4,1UL,i); }
00206     
00207     /** 
00208      * @ingroup Control_Latch 
00209      */
00210     int  corePowerLevel(void)       { GET_CNTL_LATCH(2,3); }
00211     
00212     /** 
00213      * @ingroup Control_Latch 
00214      */
00215     void corePowerLevel(int i)      { SET_CNTL_LATCH(2,3UL,i); }
00216     
00217     void controlLatchWrite(void) {
00218         _le->write(0);
00219         _ssp->write((control_latch >> 16) & 0xFF);
00220         _ssp->write((control_latch >> 8) & 0xFF);
00221         _ssp->write((control_latch & 0xFF) & ~(3UL << 0));
00222         _le->write(1);
00223     }
00224 
00225     /** 
00226      * @ingroup Counter_N_Latch 
00227      */
00228     int  divideBy2Select(void)      { GET_N_LATCH(23,1); }
00229     
00230     /** 
00231      * @ingroup Counter_N_Latch 
00232      */
00233     void divideBy2Select(int i)     { SET_N_LATCH(23,1UL,i); }
00234 
00235     /** 
00236      * @ingroup Counter_N_Latch 
00237      */
00238     int  divideBy2(void)            { GET_N_LATCH(22,1); }
00239     
00240     /** 
00241      * @ingroup Counter_N_Latch 
00242      */
00243     void divideBy2(int i)           { SET_N_LATCH(22,1UL,i); }
00244     
00245     /** 
00246      * @ingroup Counter_N_Latch 
00247      */
00248     int  nCPGain(void)              { GET_N_LATCH(21,1); }
00249     
00250     /** 
00251      * @ingroup Counter_N_Latch 
00252      */
00253     void nCPGain(int i)             { SET_N_LATCH(21,1UL,i); }
00254     
00255     /** 
00256      * @ingroup Counter_N_Latch 
00257      */
00258     int  counterB(void)             { GET_N_LATCH(8,0x1FFF); }
00259     
00260     /** 
00261      * @ingroup Counter_N_Latch 
00262      */
00263     void counterB(int i)            { SET_N_LATCH(8,0x1FFFUL,i); }
00264     
00265     /** 
00266      * @ingroup Counter_N_Latch 
00267      */
00268     int  counterA(void)             { GET_N_LATCH(2,0x1F); }
00269     
00270     /** 
00271      * @ingroup Counter_N_Latch 
00272      */
00273     void counterA(int i)            { SET_N_LATCH(2,0x1FUL,i); }
00274     
00275     void counterNWrite(void) {
00276         _le->write(0);
00277         _ssp->write((counterNlatch >> 16) & 0xFF);
00278         _ssp->write((counterNlatch >> 8) & 0xFF);
00279         _ssp->write(((counterNlatch & 0xFF) & ~(0x3CUL << 0)) | (2UL << 0));
00280         _le->write(1);
00281     }
00282     
00283     /** 
00284      * @ingroup Counter_R_Latch 
00285      */
00286     int  bandSelectClock(void)      { GET_R_LATCH(20,3); }
00287     /** 
00288      * @ingroup Counter_R_Latch 
00289      */
00290     void bandSelectClock(int i)     { SET_R_LATCH(20,3UL,i); }
00291     
00292     /** 
00293      * @ingroup Counter_R_Latch 
00294      */
00295     int  testModeBit(void)          { GET_R_LATCH(19,1); }
00296     
00297     /** 
00298      * @ingroup Counter_R_Latch 
00299      */
00300     void testModeBit(int i)         { SET_R_LATCH(19,1UL,i); }
00301     
00302     /** 
00303      * @ingroup Counter_R_Latch 
00304      */
00305     int  lockDetect(void)           { GET_R_LATCH(18,1); }
00306     
00307     /** 
00308      * @ingroup Counter_R_Latch 
00309      */
00310     void lockDetect(int i)          { SET_R_LATCH(18,1UL,i); }
00311     
00312     /** 
00313      * @ingroup Counter_R_Latch 
00314      */
00315     int  antiBacklash(void)         { GET_R_LATCH(16,3); }
00316     
00317     /** 
00318      * @ingroup Counter_R_Latch 
00319      */
00320     void antiBacklash(int i)        { SET_R_LATCH(16,3UL,i); }
00321     
00322     /** 
00323      * @ingroup Counter_R_Latch 
00324      */
00325     int  counterRef(void)           { GET_R_LATCH(2,0x3FFF); }
00326     
00327     /** 
00328      * @ingroup Counter_R_Latch 
00329      */
00330     void counterRef(int i)          { SET_R_LATCH(2,0x3FFFUL,i); }
00331     
00332     void counterRWrite(void) {
00333         _le->write(0);
00334         _ssp->write((counterRlatch >> 16) & 0xFF);
00335         _ssp->write((counterRlatch >> 8) & 0xFF);
00336         _ssp->write(((counterRlatch & 0xFF) & ~(0x3CUL << 0)) | (1UL << 0));
00337         _le->write(1);
00338     }
00339     
00340 protected:
00341 
00342     uint32_t control_latch;
00343     uint32_t counterNlatch;
00344     uint32_t counterRlatch;
00345     
00346     SPI         *_ssp;
00347     DigitalOut  *_le;
00348 };
00349    
00350 
00351 #endif