![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Versão limpa em 04/09/2014. Telnet funcionando.
Dependencies: EthernetInterface mbed-rtos mbed NTPClient
Codes/Capture.cpp@0:66d8bd1f9d4c, 2014-09-04 (annotated)
- Committer:
- rebonatto
- Date:
- Thu Sep 04 19:40:18 2014 +0000
- Revision:
- 0:66d8bd1f9d4c
- Child:
- 1:fe2d4530da1b
Vers?o do protegemed com limpeza da memoria. Est? com mailbox de 10 posi??es e telnet funcinando.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:66d8bd1f9d4c | 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 | 0:66d8bd1f9d4c | 78 | //DMA ISR signals the capture thread about the end of capture event |
rebonatto | 0:66d8bd1f9d4c | 79 | extern "C" void DMA_IRQHandler(void) |
rebonatto | 0:66d8bd1f9d4c | 80 | { |
rebonatto | 0:66d8bd1f9d4c | 81 | Capture::ISRHandler(); |
rebonatto | 0:66d8bd1f9d4c | 82 | } |
rebonatto | 0:66d8bd1f9d4c | 83 | |
rebonatto | 0:66d8bd1f9d4c | 84 | void Capture::ISRHandler() |
rebonatto | 0:66d8bd1f9d4c | 85 | { |
rebonatto | 0:66d8bd1f9d4c | 86 | Capture::m_BufferIndex = (~Capture::m_BufferIndex)&1; |
rebonatto | 0:66d8bd1f9d4c | 87 | |
rebonatto | 0:66d8bd1f9d4c | 88 | Capture::m_CaptureSemaphore.release(); |
rebonatto | 0:66d8bd1f9d4c | 89 | LPC_GPDMA->DMACIntTCClear = 0xFF; |
rebonatto | 0:66d8bd1f9d4c | 90 | } |
rebonatto | 0:66d8bd1f9d4c | 91 | |
rebonatto | 0:66d8bd1f9d4c | 92 | void Capture::ReadRFID(int channel,char *rfid) |
rebonatto | 0:66d8bd1f9d4c | 93 | { |
rebonatto | 0:66d8bd1f9d4c | 94 | /* |
rebonatto | 0:66d8bd1f9d4c | 95 | char cmd[4]; |
rebonatto | 0:66d8bd1f9d4c | 96 | cmd[0] = 'S'; |
rebonatto | 0:66d8bd1f9d4c | 97 | cmd[1] = '0'+channel; |
rebonatto | 0:66d8bd1f9d4c | 98 | cmd[2] = '\n'; |
rebonatto | 0:66d8bd1f9d4c | 99 | cmd[3] = '\0'; |
rebonatto | 0:66d8bd1f9d4c | 100 | |
rebonatto | 0:66d8bd1f9d4c | 101 | //send |
rebonatto | 0:66d8bd1f9d4c | 102 | rfid_serial.puts(cmd); |
rebonatto | 0:66d8bd1f9d4c | 103 | |
rebonatto | 0:66d8bd1f9d4c | 104 | //receive |
rebonatto | 0:66d8bd1f9d4c | 105 | char ch=0; |
rebonatto | 0:66d8bd1f9d4c | 106 | char ans[10]; |
rebonatto | 0:66d8bd1f9d4c | 107 | int cnt=0; |
rebonatto | 0:66d8bd1f9d4c | 108 | int tmout=1000; |
rebonatto | 0:66d8bd1f9d4c | 109 | while(ch != '\n' && tmout-- && cnt<9) |
rebonatto | 0:66d8bd1f9d4c | 110 | { |
rebonatto | 0:66d8bd1f9d4c | 111 | if(rfid_serial.readable()) |
rebonatto | 0:66d8bd1f9d4c | 112 | { |
rebonatto | 0:66d8bd1f9d4c | 113 | ch = rfid_serial.getc(); |
rebonatto | 0:66d8bd1f9d4c | 114 | if(!((ch>='0' && ch<='9') || (ch >= 'A' && ch <= 'F')))ch='0'; |
rebonatto | 0:66d8bd1f9d4c | 115 | ans[cnt++] = ch; |
rebonatto | 0:66d8bd1f9d4c | 116 | } |
rebonatto | 0:66d8bd1f9d4c | 117 | else |
rebonatto | 0:66d8bd1f9d4c | 118 | wait_ms(1); |
rebonatto | 0:66d8bd1f9d4c | 119 | |
rebonatto | 0:66d8bd1f9d4c | 120 | } |
rebonatto | 0:66d8bd1f9d4c | 121 | ans[cnt-1] = '\0'; |
rebonatto | 0:66d8bd1f9d4c | 122 | for(int i=0;i<8;i++) |
rebonatto | 0:66d8bd1f9d4c | 123 | rfid[i] = ans[i]; |
rebonatto | 0:66d8bd1f9d4c | 124 | */ |
rebonatto | 0:66d8bd1f9d4c | 125 | } |