#include <ctaskanaloginputadc.h>


Public Member Functions | |
| CTaskAnalogInputADC () | |
| virtual void | event (CEvent *e) |
| recieve events that wake up bottom half. | |
| virtual CMachine::bit32 | fault () |
| The CTaskScheduler will call the fault() method when a fault code was returned by any of the task's other methods. | |
| virtual void | irq (CMachine::InterruptVector v) |
| receive a hardware interrupt | |
| virtual const char * | name () |
| returns a CString containing an human readable name for the task | |
| virtual CMachine::bit32 | run () |
| called exactly once. perform task initialization such as initializing private variable. Other tasks are not guaranteed so do not interract with other tasks at this stage. | |
| virtual CMachine::bit32 | start () |
| initialize the class. | |
| virtual CMachine::bit32 | stop () |
| The CTaskScheduler will call the stop () method after the task was scheduled for cancelation. | |
| CMachine::ubit32 | value (CMachine::ubit32 y) |
| Fetch the value last latched from an analog channel. | |
| virtual | ~CTaskAnalogInputADC () |
Protected Member Functions | |
| void | calibrate () |
| Start a calibration cycle. WARNING: does not yield CPU time! | |
Definition at line 33 of file ctaskanaloginputadc.h.
| PikeAero::CTaskAnalogInputADC::CTaskAnalogInputADC | ( | ) |
Disable ADC Interrupts
Reset Control Registers
Power up the ADC
Enable auto clock off
Set the conversion and sampling prescaler configuration (fADC = fMCLK/14) = 2.28MHz
Set the conversion scan mode - continuous scan all channels
Enable Interrupts on End of Chain (all 16 channels converted)
Install self into interupt vector
This is an event driven task, should get no run time unless an event occures
Definition at line 26 of file ctaskanaloginputadc.cpp.
References ADC, ADC_ACKO, ADC_CNVP, ADC_FCH, ADC_IT_ECH, ADC_NCH, ADC_PWDN, ADC_SMPP, ADC_SPEN, PikeAero::CMachine::installVectorIRQ(), PikeAero::ITask::PriorityLow, PikeAero::ITask::setPriority(), and PikeAero::CMachine::Vector_ADC.
00027 : ITask() 00028 { 00029 /** Disable ADC Interrupts */ 00030 ADC->IMR = 0; 00031 00032 /** Reset Control Registers */ 00033 ADC->CLR0 = 0; 00034 ADC->CLR1 = 0; 00035 ADC->CLR2 = 0; 00036 ADC->CLR3 = 0; 00037 ADC->CLR4 = 0; 00038 00039 /** Power up the ADC */ 00040 ADC->CLR4 &= ~ADC_PWDN; 00041 /** Enable auto clock off */ 00042 ADC->CLR4 |= ADC_ACKO; 00043 /** Set the conversion and sampling prescaler configuration (fADC = fMCLK/14) = 2.28MHz */ 00044 ADC->CLR1 = ( ADC_SPEN | ADC_CNVP(0x07) | ADC_SMPP(0x07) ); 00045 /** Set the conversion scan mode - continuous scan all channels */ 00046 ADC->CLR2 = ( ADC_NCH(0x0F) | ADC_FCH(0x00) ); 00047 /** Enable Interrupts on End of Chain (all 16 channels converted) */ 00048 ADC->IMR = ( ADC_IT_ECH ); 00049 00050 /** Install self into interupt vector */ 00051 CMachine::installVectorIRQ(CMachine::Vector_ADC,this); 00052 00053 /** This is an event driven task, should get no run time unless an event occures */ 00054 setPriority( ITask::PriorityLow ); 00055 }

| PikeAero::CTaskAnalogInputADC::~CTaskAnalogInputADC | ( | ) | [virtual] |
stop the A/D conversion chain
Remove self from interrupt vector
Definition at line 58 of file ctaskanaloginputadc.cpp.
References ADC, ADC_START, PikeAero::CEventQueue::removeListener(), PikeAero::CMachine::removeVectorIRQ(), and PikeAero::CEvent::Tick.
00059 { 00060 CEventQueue::removeListener(this,CEvent::Tick); 00061 /** stop the A/D conversion chain */ 00062 ADC->CLR0 &= ~ADC_START; 00063 /** Remove self from interrupt vector */ 00064 CMachine::removeVectorIRQ(this); 00065 }

| void PikeAero::CTaskAnalogInputADC::calibrate | ( | ) | [protected] |
Start a calibration cycle. WARNING: does not yield CPU time!
Definition at line 81 of file ctaskanaloginputadc.cpp.
References ADC, ADC_CAL, and PikeAero::CMachine::resetWatchDog().
Referenced by start().
00082 { 00083 ADC->CLR0 = ADC_CAL; 00084 for ( CMachine::ubit32 timeout = 1000000; timeout && (ADC->CLR0 & ADC_CAL); timeout-- ) 00085 { 00086 CMachine::resetWatchDog(); 00087 } 00088 }


| void PikeAero::CTaskAnalogInputADC::event | ( | CEvent * | e | ) | [virtual] |
recieve events that wake up bottom half.
receive a software event
Reimplemented from PikeAero::CObject.
Definition at line 148 of file ctaskanaloginputadc.cpp.
References PikeAero::ITask::setSleeping(), PikeAero::CEvent::Tick, and PikeAero::CEvent::type().
Referenced by run().
00149 { 00150 switch( e->type() ) 00151 { 00152 case CEvent::Tick: /* 1/10 second */ 00153 { 00154 setSleeping(false); 00155 } 00156 break; 00157 default: 00158 break; 00159 } 00160 }


| CMachine::bit32 PikeAero::CTaskAnalogInputADC::fault | ( | ) | [virtual] |
The CTaskScheduler will call the fault() method when a fault code was returned by any of the task's other methods.
Reimplemented from PikeAero::ITask.
Definition at line 140 of file ctaskanaloginputadc.cpp.
References PikeAero::CObject::errOK.
00141 { 00142 return errOK; 00143 }
| void PikeAero::CTaskAnalogInputADC::irq | ( | CMachine::InterruptVector | v | ) | [virtual] |
receive a hardware interrupt
receive a hardware interrupt [ top half ]
Clear the End of Chain (all 16 channels converted) interrupt pending flags
stop the A/D conversion chain
clear the End Of Chain pending bit
wake up the bottom half
Reimplemented from PikeAero::CObject.
Definition at line 165 of file ctaskanaloginputadc.cpp.
References ADC, ADC_IT_EOC, and ADC_START.
00166 { 00167 /** Clear the End of Chain (all 16 channels converted) interrupt pending flags */ 00168 if ( ADC->PBR & ADC_IT_EOC ) 00169 { 00170 /** stop the A/D conversion chain */ 00171 ADC->CLR0 &= ~ADC_START; 00172 /** clear the End Of Chain pending bit */ 00173 ADC->PBR &= ~ADC_IT_EOC; 00174 /** wake up the bottom half */ 00175 } 00176 }
| virtual const char* PikeAero::CTaskAnalogInputADC::name | ( | ) | [inline, virtual] |
returns a CString containing an human readable name for the task
Reimplemented from PikeAero::ITask.
Definition at line 40 of file ctaskanaloginputadc.h.
| CMachine::bit32 PikeAero::CTaskAnalogInputADC::run | ( | ) | [virtual] |
called exactly once. perform task initialization such as initializing private variable. Other tasks are not guaranteed so do not interract with other tasks at this stage.
called periodically by CTaskScheduler to do a piece of work. [ bottom half ]
dispatch the event. dispatch() takes pointer ownership.
done working, go back to sleep
start the A/D conversion chain
Reimplemented from PikeAero::ITask.
Definition at line 108 of file ctaskanaloginputadc.cpp.
References ADC, ADC_MAX_Y, ADC_START, PikeAero::CObject::dispatch(), PikeAero::CObject::errOK, event(), PikeAero::ITask::setSleeping(), and value().
00109 { 00110 /** 00111 ** dispatch the event. dispatch() takes pointer ownership. 00112 */ 00113 CEventAnalogConversion* event = new CEventAnalogConversion(this); 00114 for( CMachine::ubit32 y=0; y < ADC_MAX_Y; y++ ) 00115 { 00116 event->setValue(y,value(y)); 00117 } 00118 dispatch( event ); 00119 00120 setSleeping(true); /** done working, go back to sleep */ 00121 ADC->CLR0 |= ADC_START; /** start the A/D conversion chain */ 00122 00123 return errOK; 00124 }

| CMachine::bit32 PikeAero::CTaskAnalogInputADC::start | ( | ) | [virtual] |
initialize the class.
perform calibration of the ADC system
start the A/D conversion chain
Reimplemented from PikeAero::ITask.
Definition at line 93 of file ctaskanaloginputadc.cpp.
References ADC, ADC_START, calibrate(), PikeAero::CObject::errOK, PikeAero::CEventQueue::installListener(), PikeAero::ITask::setSleeping(), and PikeAero::CEvent::Tick.
00094 { 00095 CEventQueue::installListener(this,CEvent::Tick); 00096 setSleeping(true); 00097 /** perform calibration of the ADC system */ 00098 calibrate(); 00099 /** start the A/D conversion chain */ 00100 ADC->CLR0 |= ADC_START; 00101 return errOK; 00102 }

| CMachine::bit32 PikeAero::CTaskAnalogInputADC::stop | ( | ) | [virtual] |
The CTaskScheduler will call the stop () method after the task was scheduled for cancelation.
stop the A/D conversion chain
Reimplemented from PikeAero::ITask.
Definition at line 130 of file ctaskanaloginputadc.cpp.
References ADC, ADC_START, PikeAero::CObject::errOK, and PikeAero::ITask::setSleeping().
00131 { 00132 setSleeping(true); 00133 ADC->CLR0 &= ~ADC_START; /** stop the A/D conversion chain */ 00134 return errOK; 00135 }

| CMachine::ubit32 PikeAero::CTaskAnalogInputADC::value | ( | CMachine::ubit32 | y | ) |
Fetch the value last latched from an analog channel.
Definition at line 71 of file ctaskanaloginputadc.cpp.
References ADC.
Referenced by run().
00072 { 00073 const volatile CMachine::ubit32* data = (CMachine::ubit32*)&ADC->D0; 00074 return ((data[(y&0x0F)])&0x3FF); 00075 }

1.5.8