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

Dependencies:   EthernetInterface mbed-rtos mbed NTPClient

Files at this revision

API Documentation at this revision

Comitter:
rebonatto
Date:
Thu Jan 14 17:25:00 2016 +0000
Parent:
38:132e83a591d0
Child:
40:b87bbdb97ac7
Commit message:
Inicio dos trabalhos para aquisi??o por CPU (Vinincius) e FFT.

Changed in this revision

Codes/Capture.cpp Show annotated file Show diff for this revision Revisions of this file
Codes/CapturecDMA.cpp Show annotated file Show diff for this revision Revisions of this file
Headers/Capture.h Show diff for this revision Revisions of this file
Headers/CapturecDMA.h Show annotated file Show diff for this revision Revisions of this file
--- a/Codes/Capture.cpp	Thu Jan 07 18:44:44 2016 +0000
+++ b/Codes/Capture.cpp	Thu Jan 14 17:25:00 2016 +0000
@@ -91,12 +91,6 @@
     }
 }
 
-//DMA ISR signals the capture thread about the end of capture event
-extern "C" void DMA_IRQHandler(void)
-{
-    Capture::ISRHandler();
-}
-
 void Capture::ISRHandler()
 {
     Capture::m_BufferIndex = (~Capture::m_BufferIndex)&1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Codes/CapturecDMA.cpp	Thu Jan 14 17:25:00 2016 +0000
@@ -0,0 +1,141 @@
+/*
+ * Capture.cpp
+ *
+ *  Created on: 
+ *      Author: 
+ */
+#include "CapturecDMA.h"
+
+Semaphore CapturecDMA::m_CaptureSemaphore(1); //used to alert the capture thread about a ready capture 
+int CapturecDMA::m_BufferIndex;
+
+//extern char LargeBuffer[1024];
+
+__attribute((section("AHBSRAM1"),aligned)) dmaLinkedListNode CapturecDMA::m_Nodes[2];// __attribute__((section("AHBSRAM0"))); //this list holds the buffer configuration for the DMA peripheral
+__attribute((section("AHBSRAM1"),aligned)) unsigned short int CapturecDMA::m_AdcBuffers[2][NUMBER_OF_SAMPLES][NUMBER_OF_CHANNELS];// __attribute__((section("AHBSRAM0")));
+Serial rfid_seriaLcDMA(p28,p27); //Ficou non capture sem DMA
+
+//This function prepares the capture buffers and starts the DMA peripheral
+void CapturecDMA::Start()
+{
+    m_Nodes[0].destAddr = (unsigned int)m_AdcBuffers[0];// HERE GOES THE BUFFER ADDRESS(unsigned int)adval;
+    m_Nodes[0].sourceAddr = (unsigned int)&LPC_ADC->ADGDR;
+    m_Nodes[0].dmaControl = (NUMBER_OF_SAMPLES*NUMBER_OF_CHANNELS)| DMA_DST_WIDTH_HALFWORD | DMA_SRC_WIDTH_HALFWORD | DMA_DST_INCREMENT | DMA_TC_INT;
+    m_Nodes[0].nextNode = (unsigned int)&m_Nodes[1];
+
+    m_Nodes[1].destAddr = (unsigned int)m_AdcBuffers[1];// HERE GOES THE BUFFER ADDRESS(unsigned int)adval2;
+    m_Nodes[1].sourceAddr = (unsigned int)&LPC_ADC->ADGDR;
+    m_Nodes[1].dmaControl = (NUMBER_OF_SAMPLES*NUMBER_OF_CHANNELS)| DMA_DST_WIDTH_HALFWORD | DMA_SRC_WIDTH_HALFWORD | DMA_DST_INCREMENT | DMA_TC_INT;
+    m_Nodes[1].nextNode = (unsigned int)&m_Nodes[0];
+
+    m_BufferIndex=0;
+
+    while(!(LPC_ADC->ADDR0&(1U<<31)));  //waits the completion of the ADC Channel 0 capture - for synchronization purposes
+    while(!(LPC_ADC->ADDR0&(1U<<31)));  //waits the completion of the ADC Channel 0 capture - for synchronization purposes
+
+    setup_channel(&m_Nodes[0],0,DMA_PERIPHERAL_ADC,DMA_MEMORY);
+}
+
+//This function initializes the ADC and DMA peripherals
+void CapturecDMA::Initialize()
+{   
+    //printf("0x%lx\n",  LargeBuffer);
+    init_adc(FREQBASE*NUMBER_OF_SAMPLES*NUMBER_OF_CHANNELS);
+    select_channels(ADC_CH_0|ADC_CH_1|ADC_CH_2|ADC_CH_3|ADC_CH_4|ADC_CH_5);
+    LPC_ADC->ADCR |= ADC_MODE_BURST;
+
+    init_dma();
+    
+    Start();
+    
+    m_CaptureSemaphore.wait();
+}
+
+void CapturecDMA::Stop()
+{
+    m_CaptureSemaphore.release();   //release semaphore
+    stop_channel();
+}
+
+void CapturecDMA::Wait()
+{
+    m_CaptureSemaphore.wait(osWaitForever);
+}
+
+unsigned short int CapturecDMA::GetValue(int nsamples, int nchannel)
+{
+    return ADC_CONVERT(m_AdcBuffers[m_BufferIndex][nsamples][nchannel]);
+}
+
+void CapturecDMA::CopyBuffer(int channel, unsigned short int *dest)
+{
+    for(int i=0;i<NUMBER_OF_SAMPLES;i++)
+    {
+        dest[i] = GetValue(i,channel);
+    }
+}
+
+void CapturecDMA::CopyBufferSigned(int channel, short int *dest)
+{
+    for(int i=0;i<NUMBER_OF_SAMPLES;i++)
+    {
+        dest[i] = GetValue(i,channel);
+    }
+}
+
+void CapturecDMA::CopyBufferFloat(int channel, float *dest)
+{
+    for(int i=0;i<NUMBER_OF_SAMPLES;i++)
+    {
+        dest[i] = (float) GetValue(i,channel);
+    }
+}
+
+//DMA ISR signals the capture thread about the end of capture event
+extern "C" void DMA_IRQHandler(void)
+{
+    CapturecDMA::ISRHandler();
+}
+
+void CapturecDMA::ISRHandler()
+{
+    CapturecDMA::m_BufferIndex = (~CapturecDMA::m_BufferIndex)&1;
+
+    CapturecDMA::m_CaptureSemaphore.release();
+    LPC_GPDMA->DMACIntTCClear = 0xFF;
+}
+
+void CapturecDMA::ReadRFID(int channel,char *rfid)
+{
+    
+    char cmd[4];
+    cmd[0] = 'S';
+    cmd[1] = '0'+channel;
+    cmd[2] = '\n';
+    cmd[3] = '\0';
+    
+    //send
+    rfid_seriaLcDMA.puts(cmd);
+    
+    //receive
+    char ch=0;
+    char ans[10];
+    int cnt=0;
+    int tmout=1000;
+    while(ch != '\n' && tmout-- && cnt<9)
+    {
+        if(rfid_seriaLcDMA.readable())
+        {
+            ch = rfid_seriaLcDMA.getc();
+            if(!((ch>='0' && ch<='9') || (ch >= 'A' && ch <= 'F')))ch='0';
+            ans[cnt++] = ch;
+        }
+        else
+            wait_ms(1);
+        
+    }
+    ans[cnt-1] = '\0';
+    for(int i=0;i<9;i++)
+        rfid[i] = ans[i];
+    
+}
\ No newline at end of file
--- a/Headers/Capture.h	Thu Jan 07 18:44:44 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * capture.h
- *
- *  Created on: 
- *      Author: 
- */
-
-#ifndef CAPTURE_H
-#define CAPTURE_H
-
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
-#include "mbed.h"
-#include "rtos.h"
-#include "dma.h"
-#include "adc.h"
-
-#include "Settings.h"
-
-// MTR: Estes defines nao deveriam estar no arquivo de configuraçeos?
-//#define SAMPLE_RATE         256U
-
-
-class Capture
-{
-    
-protected:
-    
-    static Semaphore m_CaptureSemaphore; //used to alert the capture thread about a ready capture 
-    static int m_BufferIndex;
-    
-    static dmaLinkedListNode m_Nodes[2]; //this list holds the buffer configuration for the DMA peripheral
-public:
-    static unsigned short int m_AdcBuffers[2][NUMBER_OF_SAMPLES][NUMBER_OF_CHANNELS];    
-    
-public:
-
-    static unsigned short int GetValue(int nsamples, int nchannel);
-    static void CopyBuffer(int channel, unsigned short int *dest);
-    static void CopyBufferSigned(int channel, short int *dest);
-    static void CopyBufferFloat(int channel, float *dest);
-
-    static void ISRHandler();
-
-    static void Initialize();
-    static void Start();
-    static void Stop();
-    static void Wait();        
-
-    static void ReadRFID(int channel,char *rfid);
-
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Headers/CapturecDMA.h	Thu Jan 14 17:25:00 2016 +0000
@@ -0,0 +1,56 @@
+/*
+ * capturecDMA.h
+ *
+ *  Created on: 
+ *      Author: 
+ */
+
+#ifndef CAPTURE_H
+#define CAPTURE_H
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include "mbed.h"
+#include "rtos.h"
+#include "dma.h"
+#include "adc.h"
+
+#include "Settings.h"
+
+// MTR: Estes defines nao deveriam estar no arquivo de configuraçeos?
+//#define SAMPLE_RATE         256U
+
+
+class CapturecDMA
+{
+    
+protected:
+    
+    static Semaphore m_CaptureSemaphore; //used to alert the capture thread about a ready capture 
+    static int m_BufferIndex;
+    
+    static dmaLinkedListNode m_Nodes[2]; //this list holds the buffer configuration for the DMA peripheral
+public:
+    static unsigned short int m_AdcBuffers[2][NUMBER_OF_SAMPLES][NUMBER_OF_CHANNELS];    
+    
+public:
+
+    static unsigned short int GetValue(int nsamples, int nchannel);
+    static void CopyBuffer(int channel, unsigned short int *dest);
+    static void CopyBufferSigned(int channel, short int *dest);
+    static void CopyBufferFloat(int channel, float *dest);
+
+    static void ISRHandler();
+
+    static void Initialize();
+    static void Start();
+    static void Stop();
+    static void Wait();        
+
+    static void ReadRFID(int channel,char *rfid);
+
+};
+
+#endif
\ No newline at end of file