Main Page   Modules   Namespace List   Class Hierarchy   Data Structures   File List   Namespace Members   Data Fields   Globals   Related Pages  

utilities.h

Go to the documentation of this file.
00001 /************************************************************************************
00002  * utilities.h
00003  *
00004  *   synopsis: Function prototypes and #defines for general purpose utility routines
00005  *             and macros.
00006  ************************************************************************************/
00007 #ifndef UTILITIES
00008 #define UTILITIES
00009 
00010 #include "processor.h"
00011 
00012 /* timing macros: delta t & delay in tenths of microseconds */
00013 #ifdef CCS2
00014     #if ( (defined(I_AM_MASTER_DSP))||((defined(REV_B))||(defined(REV_C))) )
00015         #define delta_t(t0_) ((TIMER_getCount(timer1) - (t0_)) / 4)
00016 
00017         #define delay(x) { \
00018             UINT32 delay_t0; \
00019             delay_t0 = TIMER_getCount(timer1); \
00020             while( ((TIMER_getCount(timer1) - delay_t0) / 4) < (x)); \
00021         }
00022 
00023     /* Rev. E RODs have a bug in the silicon when using the timers: if the period
00024        is set to the maximum (0xffffffff), and the timer count is greater than
00025        ~0x90000000, then the DSP lapses into a state where it stalls for up to
00026        600 micro-seconds on certain function calls. Using a smaller period in the
00027        timer prevents this, but means that we must use an inlined function for
00028        delta_t instead of a macro since if it wraps the subtraction will no longer
00029        automatically handle it (delay is made into an inlined function too).
00030        The inlined functions need access to timer1; this is done using pointers
00031        to maintain transparency in the rest of the program. */
00032     #elif (defined(REV_E))
00033 
00034         static inline UINT32 delta_t(UINT32 t0);
00035         static inline void   delay(UINT32 x);
00036         
00037         static inline UINT32 delta_t(UINT32 t0) {
00038             UINT32 t1, p1;
00039             t1= *((UINT32 *) 0x01980008);  //timer 1 count
00040             p1= *((UINT32 *) 0x01980004);  //timer 1 period
00041 
00042             if (t1 < t0) return ((t1 -t0 +p1)/5);
00043             else         return ((t1 -t0)/5);
00044         }
00045 
00046         
00047         static inline void delay(UINT32 x) {
00048             UINT32 t0, t1, delta, p1;
00049             t0= *((UINT32 *) 0x01980008);  //timer 1 count
00050             p1= *((UINT32 *) 0x01980004);  //timer 1 period
00051 
00052             do {
00053                 t1= *((UINT32 *) 0x01980008);
00054                 if (t1 < t0) delta= ((t1 -t0 +p1)/5);
00055                 else         delta= ((t1 -t0)/5);
00056             } while (delta < x);
00057         }
00058 
00059     #endif
00060     
00061     /* local macro variable must not conflict with others? The backslash MUST be the
00062        last character on the line, or an odd compile error will result */
00063 #else
00064     #define delta_t(t0_) ((TIMER_GetCount(timer1) - (t0_)) / 4)
00065     
00066     /* local macro variable must not conflict with others? The backslash MUST be the
00067        last character on the line, or an odd compile error will result */
00068     #define delay(x) { \
00069         UINT32 delay_t0; \
00070         delay_t0 = TIMER_GetCount(timer1); \
00071         while( ((TIMER_GetCount(timer1) - delay_t0) / 4) < (x)); \
00072     }
00073 #endif
00074 
00075 /* led macros for quick timing calls */
00076 #if defined(I_AM_MASTER_DSP)
00077     #define yellowLed_on     (*((UINT32 *) 0x018c0024)|= 1);
00078     #define greenLed_on      (*((UINT32 *) 0x01900024)|= 1);
00079     #define redLed_on        (*((UINT32 *) 0x018c0024)|= 4);
00080     
00081     #define yellowLed_off    (*((UINT32 *) 0x018c0024)&= ~1);
00082     #define greenLed_off     (*((UINT32 *) 0x01900024)&= ~1);
00083     #define redLed_off       (*((UINT32 *) 0x018c0024)&= ~4);
00084     
00085     #define yellowLed_toggle (*((UINT32 *) 0x018c0024)^= 1);
00086     #define greenLed_toggle  (*((UINT32 *) 0x01900024)^= 1);
00087     #define redLed_toggle    (*((UINT32 *) 0x018c0024)^= 4);
00088 
00089 #elif defined(I_AM_SLAVE_DSP)
00090     #define fsrp0_on         (*((UINT32 *) 0x018c0024)|=  4);
00091     #define fsxp0_on         (*((UINT32 *) 0x018c0024)|=  8);
00092 
00093     #define fsrp0_off        (*((UINT32 *) 0x018c0024)&= ~4);
00094     #define fsxp0_off        (*((UINT32 *) 0x018c0024)&= ~8);
00095 
00096     #define fsrp0_toggle     (*((UINT32 *) 0x018c0024)^=  4);
00097     #define fsxp0_toggle     (*((UINT32 *) 0x018c0024)^=  8);
00098 
00099     //Rev. B & C RODs have the yellow LED attached to CLKXP1, while Rev. E RODs
00100     //use external pin #7 as a GPI/O output to drive the LED. However, this is
00101     //not modelled in the simulation, so the SP is used instead.
00102     #if (defined(REV_B)||defined(REV_C)||defined(SIM))
00103         #define yellowLed_on     (*((UINT32 *) 0x01900024)&= ~2);
00104         #define yellowLed_off    (*((UINT32 *) 0x01900024)|=  2);
00105         #define yellowLed_toggle (*((UINT32 *) 0x01900024)^=  2);
00106     #elif (defined(REV_E))
00107         #define yellowLed_on     (*((UINT32 *) 0x01b00008)&= ~0x80);
00108         #define yellowLed_off    (*((UINT32 *) 0x01b00008)|=  0x80);
00109         #define yellowLed_toggle (*((UINT32 *) 0x01b00008)^=  0x80);
00110     #endif
00111 #endif
00112 
00113 /* register access width (data bus width of EMIF) */
00114 #define BYTE_W    8
00115 #define HWORD_W  16
00116 #define WORD_W   32
00117 
00118 /* default value for primitive parameters, function arguments, etc */
00119 #define DEFAULT (0xFFFFFFFF)
00120 
00121 /* z is returned as lesser of x or y */
00122 #define MINI(x,y,z)   z=((x)<(y))?(x):(y);
00123 
00124 /* macros to set, reset and read fields of variables and registers */
00125 #define N_BIT_MASK(wid)           (~(0xFFFFFFFF<<(wid)))
00126 #define FIELD_MASK(bit,wid)       (N_BIT_MASK(wid) << (bit))
00127 #define FIELD_OFF(bit,wid)        (~(FIELD_MASK(bit,wid)))
00128 #define FIELD_VAL(bit,wid,val)    ((val&(N_BIT_MASK(wid))) << bit)
00129 
00130 #define SET_VBIT(var,bit)        (var |= (1 << bit))
00131 #define RST_VBIT(var,bit)        (var &= ~(1 << bit))
00132 #define ASGN_VBIT(var,bit,val)   (var = ((RST_VBIT(var,bit)) | (val<<bit)))
00133 #define GET_VBIT(var,bit)        ((var >> bit) & 1)
00134 #define RST_VFLD(var,bit,wid)    (var &= (FIELD_OFF(bit,wid)))
00135 #define ASGN_VFLD(var,bit,wid,val)  \
00136              (var = (RST_VFLD(var,bit,wid)) | (FIELD_VAL(bit,wid,val)))
00137 #define GET_VFLD(var,bit,wid)    ((FIELD_MASK(bit,wid) & var) >> bit)
00138 
00139 /*  Some of the macros below are essentially the same as those in the Texas
00140  * Instruments provided regs.h.  The ones in this file should be used in DSP code
00141  * authored by the ROD group.  If Texas Instruments changes their macro names for
00142  * some reason, the DSP code will not be affected.                  dpf             */
00143 #define CONTENTS(adr) (*((volatile UINT32 *)(adr)))
00144 
00145 #define READ_REG(adr)             (CONTENTS(adr))
00146 #define WRITE_REG(adr,val)        (CONTENTS(adr) = (val))
00147 #define SET_RBIT(adr,bit)         (CONTENTS(adr) |= (1 << (bit)))
00148 #define RST_RBIT(adr,bit)         (CONTENTS(adr) &= (~(1 << (bit))))
00149 #define ASGN_RBIT(adr,bit,val)    (CONTENTS(adr) = (RST_RBIT(adr,bit)) | (val<<bit))
00150 #define GET_RBIT(adr,bit)         ((CONTENTS(adr) >> bit) & 1)
00151 #define RST_RFLD(adr,bit,wid)     (CONTENTS(adr) &= (FIELD_OFF(bit,wid)))
00152 #define GET_RFLD(adr,bit,wid)     ((CONTENTS(adr) & FIELD_MASK(bit,wid)) >> bit)
00153 #define ASGN_RFLD(adr,bit,wid,val) (CONTENTS(adr) = \
00154                                    (RST_RFLD(adr,bit,wid)) | (FIELD_VAL(bit,wid,val)))
00155 
00156 /* Contexts for waitRegister: */
00157 #define  CONTEXT_NULL   0
00158 #define  CONTEXT_TASK   1
00159 #define  CONTEXT_PRIM   2
00160 #define  CONTEXT_ALL    3
00161 
00162 
00163 /* The copymem & setmem EDMA transfer complete codes. The only available method
00164    of monitoring the progress of an EDMA transfer is to allow an interrupt upon
00165    completion, and then in the interrupt check the TCC to decide what to do. */
00166 //#define EDMA_SETMEM_ID     14  dpsf not true...
00167 //#define EDMA_COPYMEM_ID    15
00168 
00169 #endif

Generated on Mon Dec 15 19:36:23 2003 for SCT DAQ/DCS Software by doxygen1.3-rc3