QRSS Rx Network receiver. A receiver to sample a segment of RF spectrum and send this data to a server for further processing and display. NXP mbed Design Challenge entry (Honorable Mention). Published in Circuit Cellar, Feb 2012

Dependencies:   NetServices mbed DNSResolver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers I2S_Rx.h Source File

I2S_Rx.h

00001 /*---------------------------------------------------------------------------
00002 
00003     QRSS Receiver Application
00004         
00005     by Clayton ZL3TKA/VK1TKA
00006     clayton@isnotcrazy.com
00007 
00008     Header File for I2S Receiver
00009         
00010     I2S Receiver operates in slave mode
00011 
00012 ---------------------------------------------------------------------------*/
00013 #ifndef _I2S_RX_H
00014 #define _I2S_RX_H
00015 
00016 #include "mbed.h"
00017 #include "BufferSys.h"
00018 
00019 // Definitions
00020 
00021 #define I2S_DUMMY_BUFFER_SIZE       16
00022 
00023 // Macros
00024 
00025 //
00026 // Classes
00027 //
00028 
00029 //---------------------------------------------------------------------------
00030 //
00031 //  I2S Receiver Class
00032 //
00033 class TI2SReceiver
00034 {
00035     // create/destroy
00036     public:
00037         TI2SReceiver( TBufferPool &BuffPol );
00038         ~TI2SReceiver() 
00039             {
00040                 Stop();
00041             }
00042 
00043     // API
00044     public:
00045         // Initialise the hardware
00046         void Init();
00047 
00048         // Start receiving
00049         void Start();
00050         
00051         // Stop receiving
00052         void Stop();
00053         
00054         // Receiver status
00055         bool Running()
00056             { return bRunning; }
00057         
00058         // Test for a buffer available
00059         //  Return number of queued buffers
00060         int Count() const
00061             { return ReceivedBuffers.Count(); }
00062         //  Test if empty
00063         bool Empty() const
00064             { return ReceivedBuffers.Empty(); }
00065 
00066         // Read out a buffer
00067         bool Read( TBufferHandle &Handle )
00068             {
00069                 // queue is filled from interrupts, so we need to ensure we always access it with interrupts off
00070                 __disable_irq();
00071                 bool bRet = ReceivedBuffers.Read(Handle);
00072                 __enable_irq();
00073                 return bRet;
00074             }
00075 
00076         // report the number of buffer failures
00077         uint32_t BufferFailures() const
00078             { return ulBufferFailures; }
00079 
00080         // DMA IRQ Routine
00081         void DMA_Interrupt(void);
00082 
00083         // Debug routine - 
00084         // Read samples from the I2S by polling it
00085         //  Returns number of samples read
00086         int PolledRead( int32_t *piBuffer, int iLen );
00087 
00088         //  Debug routine - 
00089         //      Read status register
00090         uint32_t Status();
00091 
00092         //  Debug routine - 
00093         //      Report Status
00094         void Report();
00095 
00096     // Private methods
00097     private:
00098 
00099         //  Start a new DMA transfer
00100         void StartDMATransfer();
00101 
00102     // data
00103     private:
00104         // pool to get buffers from
00105         TBufferPool     &EmptyBuffersPool;
00106 
00107         // queue of incoming sample buffers
00108         TBufferQueue    ReceivedBuffers;
00109 
00110         // the current buffer being used
00111         TBufferHandle   CurrentRxBuffer;
00112 
00113         // flags indicating run status
00114         bool            bRunning;
00115 
00116         // a buffer to use when there are no empty buffers available
00117         int32_t        aulDummyBuffer[I2S_DUMMY_BUFFER_SIZE];
00118         
00119         // frame counters etc
00120         uint32_t        ulBufferCount;
00121         uint32_t        ulBufferAllocations;
00122         uint32_t        ulBufferFailures;
00123         
00124 };
00125 
00126 #endif
00127 
00128 //---------------------------------------------------------------------------
00129 //  END
00130 //---------------------------------------------------------------------------
00131