Versão limpa em 04/09/2014. Telnet funcionando.

Dependencies:   EthernetInterface mbed-rtos mbed NTPClient

Committer:
rebonatto
Date:
Thu Jan 14 17:25:00 2016 +0000
Revision:
39:9fd8397cbef9
Parent:
37:51fed2a3e009
Child:
42:d6f9ce115eaf
Inicio dos trabalhos para aquisi??o por CPU (Vinincius) e FFT.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rebonatto 0:66d8bd1f9d4c 1 /*
rebonatto 0:66d8bd1f9d4c 2 * Capture.h
rebonatto 0:66d8bd1f9d4c 3 *
rebonatto 0:66d8bd1f9d4c 4 * Created on:
rebonatto 0:66d8bd1f9d4c 5 * Author:
rebonatto 0:66d8bd1f9d4c 6 */
rebonatto 0:66d8bd1f9d4c 7 #include "Capture.h"
rebonatto 0:66d8bd1f9d4c 8
rebonatto 0:66d8bd1f9d4c 9 Semaphore Capture::m_CaptureSemaphore(1); //used to alert the capture thread about a ready capture
rebonatto 0:66d8bd1f9d4c 10 int Capture::m_BufferIndex;
rebonatto 0:66d8bd1f9d4c 11
rebonatto 0:66d8bd1f9d4c 12 //extern char LargeBuffer[1024];
rebonatto 0:66d8bd1f9d4c 13
rebonatto 0:66d8bd1f9d4c 14 __attribute((section("AHBSRAM1"),aligned)) dmaLinkedListNode Capture::m_Nodes[2];// __attribute__((section("AHBSRAM0"))); //this list holds the buffer configuration for the DMA peripheral
rebonatto 0:66d8bd1f9d4c 15 __attribute((section("AHBSRAM1"),aligned)) unsigned short int Capture::m_AdcBuffers[2][NUMBER_OF_SAMPLES][NUMBER_OF_CHANNELS];// __attribute__((section("AHBSRAM0")));
rebonatto 1:fe2d4530da1b 16 Serial rfid_serial(p28,p27);
rebonatto 0:66d8bd1f9d4c 17
rebonatto 0:66d8bd1f9d4c 18 //This function prepares the capture buffers and starts the DMA peripheral
rebonatto 0:66d8bd1f9d4c 19 void Capture::Start()
rebonatto 0:66d8bd1f9d4c 20 {
rebonatto 0:66d8bd1f9d4c 21 m_Nodes[0].destAddr = (unsigned int)m_AdcBuffers[0];// HERE GOES THE BUFFER ADDRESS(unsigned int)adval;
rebonatto 0:66d8bd1f9d4c 22 m_Nodes[0].sourceAddr = (unsigned int)&LPC_ADC->ADGDR;
rebonatto 0:66d8bd1f9d4c 23 m_Nodes[0].dmaControl = (NUMBER_OF_SAMPLES*NUMBER_OF_CHANNELS)| DMA_DST_WIDTH_HALFWORD | DMA_SRC_WIDTH_HALFWORD | DMA_DST_INCREMENT | DMA_TC_INT;
rebonatto 0:66d8bd1f9d4c 24 m_Nodes[0].nextNode = (unsigned int)&m_Nodes[1];
rebonatto 0:66d8bd1f9d4c 25
rebonatto 0:66d8bd1f9d4c 26 m_Nodes[1].destAddr = (unsigned int)m_AdcBuffers[1];// HERE GOES THE BUFFER ADDRESS(unsigned int)adval2;
rebonatto 0:66d8bd1f9d4c 27 m_Nodes[1].sourceAddr = (unsigned int)&LPC_ADC->ADGDR;
rebonatto 0:66d8bd1f9d4c 28 m_Nodes[1].dmaControl = (NUMBER_OF_SAMPLES*NUMBER_OF_CHANNELS)| DMA_DST_WIDTH_HALFWORD | DMA_SRC_WIDTH_HALFWORD | DMA_DST_INCREMENT | DMA_TC_INT;
rebonatto 0:66d8bd1f9d4c 29 m_Nodes[1].nextNode = (unsigned int)&m_Nodes[0];
rebonatto 0:66d8bd1f9d4c 30
rebonatto 0:66d8bd1f9d4c 31 m_BufferIndex=0;
rebonatto 0:66d8bd1f9d4c 32
rebonatto 0:66d8bd1f9d4c 33 while(!(LPC_ADC->ADDR0&(1U<<31))); //waits the completion of the ADC Channel 0 capture - for synchronization purposes
rebonatto 0:66d8bd1f9d4c 34 while(!(LPC_ADC->ADDR0&(1U<<31))); //waits the completion of the ADC Channel 0 capture - for synchronization purposes
rebonatto 0:66d8bd1f9d4c 35
rebonatto 0:66d8bd1f9d4c 36 setup_channel(&m_Nodes[0],0,DMA_PERIPHERAL_ADC,DMA_MEMORY);
rebonatto 0:66d8bd1f9d4c 37 }
rebonatto 0:66d8bd1f9d4c 38
rebonatto 0:66d8bd1f9d4c 39 //This function initializes the ADC and DMA peripherals
rebonatto 0:66d8bd1f9d4c 40 void Capture::Initialize()
rebonatto 0:66d8bd1f9d4c 41 {
rebonatto 0:66d8bd1f9d4c 42 //printf("0x%lx\n", LargeBuffer);
rebonatto 0:66d8bd1f9d4c 43 init_adc(FREQBASE*NUMBER_OF_SAMPLES*NUMBER_OF_CHANNELS);
rebonatto 0:66d8bd1f9d4c 44 select_channels(ADC_CH_0|ADC_CH_1|ADC_CH_2|ADC_CH_3|ADC_CH_4|ADC_CH_5);
rebonatto 0:66d8bd1f9d4c 45 LPC_ADC->ADCR |= ADC_MODE_BURST;
rebonatto 0:66d8bd1f9d4c 46
rebonatto 0:66d8bd1f9d4c 47 init_dma();
rebonatto 0:66d8bd1f9d4c 48
rebonatto 0:66d8bd1f9d4c 49 Start();
rebonatto 0:66d8bd1f9d4c 50
rebonatto 0:66d8bd1f9d4c 51 m_CaptureSemaphore.wait();
rebonatto 0:66d8bd1f9d4c 52 }
rebonatto 0:66d8bd1f9d4c 53
rebonatto 0:66d8bd1f9d4c 54 void Capture::Stop()
rebonatto 0:66d8bd1f9d4c 55 {
rebonatto 0:66d8bd1f9d4c 56 m_CaptureSemaphore.release(); //release semaphore
rebonatto 0:66d8bd1f9d4c 57 stop_channel();
rebonatto 0:66d8bd1f9d4c 58 }
rebonatto 0:66d8bd1f9d4c 59
rebonatto 0:66d8bd1f9d4c 60 void Capture::Wait()
rebonatto 0:66d8bd1f9d4c 61 {
rebonatto 0:66d8bd1f9d4c 62 m_CaptureSemaphore.wait(osWaitForever);
rebonatto 0:66d8bd1f9d4c 63 }
rebonatto 0:66d8bd1f9d4c 64
rebonatto 0:66d8bd1f9d4c 65 unsigned short int Capture::GetValue(int nsamples, int nchannel)
rebonatto 0:66d8bd1f9d4c 66 {
rebonatto 0:66d8bd1f9d4c 67 return ADC_CONVERT(m_AdcBuffers[m_BufferIndex][nsamples][nchannel]);
rebonatto 0:66d8bd1f9d4c 68 }
rebonatto 0:66d8bd1f9d4c 69
rebonatto 0:66d8bd1f9d4c 70 void Capture::CopyBuffer(int channel, unsigned short int *dest)
rebonatto 0:66d8bd1f9d4c 71 {
rebonatto 0:66d8bd1f9d4c 72 for(int i=0;i<NUMBER_OF_SAMPLES;i++)
rebonatto 0:66d8bd1f9d4c 73 {
rebonatto 0:66d8bd1f9d4c 74 dest[i] = GetValue(i,channel);
rebonatto 0:66d8bd1f9d4c 75 }
rebonatto 0:66d8bd1f9d4c 76 }
rebonatto 0:66d8bd1f9d4c 77
rebonatto 29:fcfcb31a6362 78 void Capture::CopyBufferSigned(int channel, short int *dest)
rebonatto 29:fcfcb31a6362 79 {
rebonatto 29:fcfcb31a6362 80 for(int i=0;i<NUMBER_OF_SAMPLES;i++)
rebonatto 29:fcfcb31a6362 81 {
rebonatto 29:fcfcb31a6362 82 dest[i] = GetValue(i,channel);
rebonatto 29:fcfcb31a6362 83 }
rebonatto 29:fcfcb31a6362 84 }
rebonatto 29:fcfcb31a6362 85
rebonatto 31:647771325538 86 void Capture::CopyBufferFloat(int channel, float *dest)
rebonatto 31:647771325538 87 {
rebonatto 31:647771325538 88 for(int i=0;i<NUMBER_OF_SAMPLES;i++)
rebonatto 31:647771325538 89 {
rebonatto 31:647771325538 90 dest[i] = (float) GetValue(i,channel);
rebonatto 31:647771325538 91 }
rebonatto 31:647771325538 92 }
rebonatto 31:647771325538 93
rebonatto 0:66d8bd1f9d4c 94 void Capture::ISRHandler()
rebonatto 0:66d8bd1f9d4c 95 {
rebonatto 0:66d8bd1f9d4c 96 Capture::m_BufferIndex = (~Capture::m_BufferIndex)&1;
rebonatto 0:66d8bd1f9d4c 97
rebonatto 0:66d8bd1f9d4c 98 Capture::m_CaptureSemaphore.release();
rebonatto 0:66d8bd1f9d4c 99 LPC_GPDMA->DMACIntTCClear = 0xFF;
rebonatto 0:66d8bd1f9d4c 100 }
rebonatto 37:51fed2a3e009 101 /*
rebonatto 1:fe2d4530da1b 102 bool Capture::ReadRFID(int channel,char *rfid)
rebonatto 0:66d8bd1f9d4c 103 {
rebonatto 1:fe2d4530da1b 104
rebonatto 0:66d8bd1f9d4c 105 char cmd[4];
rebonatto 0:66d8bd1f9d4c 106 cmd[0] = 'S';
rebonatto 0:66d8bd1f9d4c 107 cmd[1] = '0'+channel;
rebonatto 0:66d8bd1f9d4c 108 cmd[2] = '\n';
rebonatto 0:66d8bd1f9d4c 109 cmd[3] = '\0';
rebonatto 0:66d8bd1f9d4c 110
rebonatto 0:66d8bd1f9d4c 111 //send
rebonatto 0:66d8bd1f9d4c 112 rfid_serial.puts(cmd);
rebonatto 0:66d8bd1f9d4c 113
rebonatto 0:66d8bd1f9d4c 114 //receive
rebonatto 0:66d8bd1f9d4c 115 char ch=0;
rebonatto 0:66d8bd1f9d4c 116 char ans[10];
rebonatto 0:66d8bd1f9d4c 117 int cnt=0;
rebonatto 0:66d8bd1f9d4c 118 int tmout=1000;
rebonatto 0:66d8bd1f9d4c 119 while(ch != '\n' && tmout-- && cnt<9)
rebonatto 0:66d8bd1f9d4c 120 {
rebonatto 0:66d8bd1f9d4c 121 if(rfid_serial.readable())
rebonatto 0:66d8bd1f9d4c 122 {
rebonatto 0:66d8bd1f9d4c 123 ch = rfid_serial.getc();
rebonatto 0:66d8bd1f9d4c 124 if(!((ch>='0' && ch<='9') || (ch >= 'A' && ch <= 'F')))ch='0';
rebonatto 0:66d8bd1f9d4c 125 ans[cnt++] = ch;
rebonatto 0:66d8bd1f9d4c 126 }
rebonatto 0:66d8bd1f9d4c 127 else
rebonatto 0:66d8bd1f9d4c 128 wait_ms(1);
rebonatto 0:66d8bd1f9d4c 129
rebonatto 0:66d8bd1f9d4c 130 }
rebonatto 1:fe2d4530da1b 131 if (cnt > 0){
rebonatto 1:fe2d4530da1b 132 ans[cnt-1] = '\0';
rebonatto 1:fe2d4530da1b 133 for(int i=0;i<10;i++)
rebonatto 1:fe2d4530da1b 134 rfid[i] = ans[i];
rebonatto 1:fe2d4530da1b 135 return true;
rebonatto 1:fe2d4530da1b 136 }
rebonatto 1:fe2d4530da1b 137 return false;
rebonatto 1:fe2d4530da1b 138
rebonatto 37:51fed2a3e009 139 }
rebonatto 37:51fed2a3e009 140 */
rebonatto 37:51fed2a3e009 141
rebonatto 37:51fed2a3e009 142 void Capture::ReadRFID(int channel,char *rfid)
rebonatto 37:51fed2a3e009 143 {
rebonatto 37:51fed2a3e009 144
rebonatto 37:51fed2a3e009 145 char cmd[4];
rebonatto 37:51fed2a3e009 146 cmd[0] = 'S';
rebonatto 37:51fed2a3e009 147 cmd[1] = '0'+channel;
rebonatto 37:51fed2a3e009 148 cmd[2] = '\n';
rebonatto 37:51fed2a3e009 149 cmd[3] = '\0';
rebonatto 37:51fed2a3e009 150
rebonatto 37:51fed2a3e009 151 //send
rebonatto 37:51fed2a3e009 152 rfid_serial.puts(cmd);
rebonatto 37:51fed2a3e009 153
rebonatto 37:51fed2a3e009 154 //receive
rebonatto 37:51fed2a3e009 155 char ch=0;
rebonatto 37:51fed2a3e009 156 char ans[10];
rebonatto 37:51fed2a3e009 157 int cnt=0;
rebonatto 37:51fed2a3e009 158 int tmout=1000;
rebonatto 37:51fed2a3e009 159 while(ch != '\n' && tmout-- && cnt<9)
rebonatto 37:51fed2a3e009 160 {
rebonatto 37:51fed2a3e009 161 if(rfid_serial.readable())
rebonatto 37:51fed2a3e009 162 {
rebonatto 37:51fed2a3e009 163 ch = rfid_serial.getc();
rebonatto 37:51fed2a3e009 164 if(!((ch>='0' && ch<='9') || (ch >= 'A' && ch <= 'F')))ch='0';
rebonatto 37:51fed2a3e009 165 ans[cnt++] = ch;
rebonatto 37:51fed2a3e009 166 }
rebonatto 37:51fed2a3e009 167 else
rebonatto 37:51fed2a3e009 168 wait_ms(1);
rebonatto 37:51fed2a3e009 169
rebonatto 37:51fed2a3e009 170 }
rebonatto 37:51fed2a3e009 171 ans[cnt-1] = '\0';
rebonatto 37:51fed2a3e009 172 for(int i=0;i<9;i++)
rebonatto 37:51fed2a3e009 173 rfid[i] = ans[i];
rebonatto 37:51fed2a3e009 174
rebonatto 0:66d8bd1f9d4c 175 }