utils.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define EXTERN   extern

Functions

EXTERN void sleep (unsigned short) FPAGE_FE
 Sleep for X milli seconds.
EXTERN void sleepMicro (unsigned short) FPAGE_FE
 Sleep for X micro seconds.
EXTERN void adjustPWM (void) FPAGE_FE
 Demonstrate PWM.
EXTERN void setupPagedRAM (unsigned char) FPAGE_F8
 Setup tune switching.
EXTERN void resetToNonRunningState (void) FPAGE_F8
 Reset key state.
EXTERN void sampleEachADC (ADCArray *) FPAGE_F8
 Read ADCs one at a time.
EXTERN void sampleBlockADC (ADCArray *) FPAGE_F8
 Read ADCs with memcpy().
EXTERN unsigned char checksum (unsigned char *, unsigned short) FPAGE_F8
 Simple checksum.
EXTERN unsigned short stringCopy (unsigned char *, unsigned char *) FPAGE_F8
 Homebrew strcpy().


Detailed Description

Definition in file utils.h.


Define Documentation

#define EXTERN   extern

Definition at line 44 of file utils.h.


Function Documentation

EXTERN void adjustPWM ( void   ) 

Demonstrate PWM.

Demonstrate basic PWM module usage by setting duty to scaled ADC inputs.

Author:
Fred Cooke

Definition at line 101 of file utils.c.

References ATD0DR0, ATD0DR1, ATD0DR2, ATD0DR3, ATD0DR4, ATD0DR5, ATD0DR6, ATD0DR7, PWMDTY0, PWMDTY1, PWMDTY2, PWMDTY3, PWMDTY4, PWMDTY5, PWMDTY6, and PWMDTY7.

Referenced by main().

00101                 {
00102     PWMDTY0 = ATD0DR0 >> 2; // scale raw adc to a duty
00103     PWMDTY1 = ATD0DR1 >> 2; // scale raw adc to a duty
00104     PWMDTY2 = ATD0DR2 >> 2; // scale raw adc to a duty
00105     PWMDTY3 = ATD0DR3 >> 2; // scale raw adc to a duty
00106     PWMDTY4 = ATD0DR4 >> 2; // scale raw adc to a duty
00107     PWMDTY5 = ATD0DR5 >> 2; // scale raw adc to a duty
00108     PWMDTY6 = ATD0DR6 >> 2; // scale raw adc to a duty
00109     PWMDTY7 = ATD0DR7 >> 2; // scale raw adc to a duty (user led instead at the moment, see init)
00110 }

EXTERN unsigned char checksum ( unsigned char *  block,
unsigned short  length 
)

Simple checksum.

Generate a simple additive checksum for a block of data.

Author:
Fred Cooke
Parameters:
block a pointer to a memory region to checksum.
length how large the memory region to checksum is.
Returns:
a simple additive checksum.

Definition at line 201 of file utils.c.

Referenced by checksumAndSend().

00201                                                                    {
00202     unsigned char sum = 0;
00203     unsigned short i;
00204     for(i=0;i<length;i++){
00205         sum += *block;
00206         block++;
00207     }
00208     return sum;
00209 }

EXTERN void resetToNonRunningState ( void   ) 

Reset key state.

Reset all important variables to their non-running state.

Todo:
TODO bring this up to date and/or find a better way to do it.
Author:
Fred Cooke

Definition at line 78 of file utils.c.

References CLEAR_PRIMARY_SYNC, coreStatusA, engineCyclePeriod, RPM0, RPM1, and ticksPerCycleAtOneRPM.

Referenced by main().

00078                              {
00079     /* Reset RPM to zero */
00080     RPM0 = 0;
00081     RPM1 = 0;
00082 
00083     /* Ensure tacho reads lowest possible value */
00084     engineCyclePeriod = ticksPerCycleAtOneRPM;
00085 
00086     /* Clear all sync flags to lost state */
00087     //coreStatusA &= CLEAR_RPM_VALID;
00088     coreStatusA &= CLEAR_PRIMARY_SYNC;
00089     //coreStatusA &= CLEAR_SECONDARY_SYNC;
00090 
00091     // TODO more stuff needs resetting here, but only critical things.
00092 }

EXTERN void sampleBlockADC ( ADCArray Arrays  ) 

Read ADCs with memcpy().

Read ADCs into the correct bank using two fixed calls to memcpy()

Author:
Fred Cooke
Parameters:
Arrays a pointer to an ADCArray struct to store ADC values in.

Definition at line 152 of file utils.c.

References ATD0_BASE, and ATD1_BASE.

Referenced by PrimaryRPMISR().

00152                                      {
00153     memcpy(Arrays, (void*)ATD0_BASE, 16);
00154     memcpy(Arrays+16, (void*)ATD1_BASE, 16);
00155 }

EXTERN void sampleEachADC ( ADCArray Arrays  ) 

Read ADCs one at a time.

Read ADCs into the correct bank one at a time by name.

Author:
Fred Cooke
Parameters:
Arrays a pointer to an ADCArray struct to store ADC values in.

Definition at line 121 of file utils.c.

References ADCArray::AAP, ATD0DR0, ATD0DR1, ATD0DR2, ATD0DR3, ATD0DR4, ATD0DR5, ATD0DR6, ATD0DR7, ATD1DR0, ATD1DR1, ATD1DR2, ATD1DR3, ATD1DR4, ATD1DR5, ATD1DR6, ATD1DR7, ADCArray::BRV, ADCArray::CHT, ADCArray::EGO, ADCArray::EGO2, ADCArray::IAP, ADCArray::IAT, ADCArray::MAF, ADCArray::MAP, ADCArray::MAT, ADCArray::SpareADC3, ADCArray::SpareADC4, ADCArray::SpareADC5, ADCArray::SpareADC6, ADCArray::SpareADC7, and ADCArray::TPS.

Referenced by main().

00121                                     {
00122     /* ATD0 */
00123     Arrays->IAT = ATD0DR0;
00124     Arrays->CHT = ATD0DR1;
00125     Arrays->TPS = ATD0DR2;
00126     Arrays->EGO = ATD0DR3;
00127     Arrays->MAP = ATD0DR4;
00128     Arrays->AAP = ATD0DR5;
00129     Arrays->BRV = ATD0DR6;
00130     Arrays->MAT = ATD0DR7;
00131 
00132     /* ATD1 */
00133     Arrays->EGO2 = ATD1DR0;
00134     Arrays->IAP = ATD1DR1;
00135     Arrays->MAF = ATD1DR2;
00136     Arrays->SpareADC3 = ATD1DR3;
00137     Arrays->SpareADC4 = ATD1DR4;
00138     Arrays->SpareADC5 = ATD1DR5;
00139     Arrays->SpareADC6 = ATD1DR6;
00140     Arrays->SpareADC7 = ATD1DR7;
00141 }

EXTERN void setupPagedRAM ( unsigned char  bool  ) 

Setup tune switching.

Place the correct set of tables in RAM based on a boolean parameter

Todo:
TODO change parameter style to be a pointer to a register and a mask?
Author:
Fred Cooke
Parameters:
bool which set of data to enable.

Definition at line 55 of file utils.c.

References currentFuelRPage, currentTimeRPage, currentTuneRPage, RPAGE, RPAGE_FUEL_ONE, RPAGE_FUEL_TWO, RPAGE_TIME_ONE, RPAGE_TIME_TWO, RPAGE_TUNE_ONE, and RPAGE_TUNE_TWO.

Referenced by initAllPagedRAM().

00055                                       {
00056     if(bool){
00057         currentFuelRPage = RPAGE_FUEL_ONE;
00058         currentTimeRPage = RPAGE_TIME_ONE;
00059         currentTuneRPage = RPAGE_TUNE_ONE;
00060     }else{
00061         currentFuelRPage = RPAGE_FUEL_TWO;
00062         currentTimeRPage = RPAGE_TIME_TWO;
00063         currentTuneRPage = RPAGE_TUNE_TWO;
00064     }
00065 
00066     RPAGE = currentTuneRPage;
00067 }

EXTERN void sleep ( unsigned short  ms  ) 

Sleep for X milli seconds.

Run in a nested loop repeatedly for X milli seconds.

Author:
Fred Cooke
Parameters:
ms the number of milli seconds to kill

Definition at line 166 of file utils.c.

Referenced by initConfiguration().

00166                              {
00167     unsigned short j, k;
00168     for(j=0;j<ms;j++)
00169         for(k=0;k<5714;k++);
00170 }

EXTERN void sleepMicro ( unsigned short  us  ) 

Sleep for X micro seconds.

Run in a nested loop repeatedly for X micro seconds.

Note:
Very approximate...
Author:
Fred Cooke
Parameters:
us the number of micro seconds to kill

Definition at line 183 of file utils.c.

Referenced by main().

00183                                   {
00184     unsigned short j, k;
00185     for(j=0;j<us;j++)
00186         for(k=0;k<6;k++);
00187 }

EXTERN unsigned short stringCopy ( unsigned char *  dest,
unsigned char *  source 
)

Homebrew strcpy().

strcpy() wouldn't compile for me for some reason so I wrote my own.

Author:
Fred Cooke
Parameters:
dest where to copy the null terminated string to.
source where to copy the null terminated string from.
Returns:
the length of the string copied.

Definition at line 223 of file utils.c.

Referenced by sendDebugInternal().

00223                                                                      {
00224     unsigned short length = 0;
00225     while(*source != 0){
00226         *dest = *source;
00227         dest++;
00228         source++;
00229         length++;
00230     }
00231     *dest = 0;
00232     return length;
00233 }


Generated on Mon Jan 26 00:17:20 2009 for FreeEMS by  doxygen 1.5.8