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

Committer:
claytong
Date:
Wed Jan 25 20:32:53 2012 +0000
Revision:
0:82ff15078322
1.0 (initial public release)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
claytong 0:82ff15078322 1 /*---------------------------------------------------------------------------
claytong 0:82ff15078322 2
claytong 0:82ff15078322 3 QRSS Receiver Application
claytong 0:82ff15078322 4
claytong 0:82ff15078322 5 by Clayton ZL3TKA/VK1TKA
claytong 0:82ff15078322 6 clayton@isnotcrazy.com
claytong 0:82ff15078322 7
claytong 0:82ff15078322 8 Header File for I2S Receiver
claytong 0:82ff15078322 9
claytong 0:82ff15078322 10 I2S Receiver operates in slave mode
claytong 0:82ff15078322 11
claytong 0:82ff15078322 12 ---------------------------------------------------------------------------*/
claytong 0:82ff15078322 13 #ifndef _I2S_RX_H
claytong 0:82ff15078322 14 #define _I2S_RX_H
claytong 0:82ff15078322 15
claytong 0:82ff15078322 16 #include "mbed.h"
claytong 0:82ff15078322 17 #include "BufferSys.h"
claytong 0:82ff15078322 18
claytong 0:82ff15078322 19 // Definitions
claytong 0:82ff15078322 20
claytong 0:82ff15078322 21 #define I2S_DUMMY_BUFFER_SIZE 16
claytong 0:82ff15078322 22
claytong 0:82ff15078322 23 // Macros
claytong 0:82ff15078322 24
claytong 0:82ff15078322 25 //
claytong 0:82ff15078322 26 // Classes
claytong 0:82ff15078322 27 //
claytong 0:82ff15078322 28
claytong 0:82ff15078322 29 //---------------------------------------------------------------------------
claytong 0:82ff15078322 30 //
claytong 0:82ff15078322 31 // I2S Receiver Class
claytong 0:82ff15078322 32 //
claytong 0:82ff15078322 33 class TI2SReceiver
claytong 0:82ff15078322 34 {
claytong 0:82ff15078322 35 // create/destroy
claytong 0:82ff15078322 36 public:
claytong 0:82ff15078322 37 TI2SReceiver( TBufferPool &BuffPol );
claytong 0:82ff15078322 38 ~TI2SReceiver()
claytong 0:82ff15078322 39 {
claytong 0:82ff15078322 40 Stop();
claytong 0:82ff15078322 41 }
claytong 0:82ff15078322 42
claytong 0:82ff15078322 43 // API
claytong 0:82ff15078322 44 public:
claytong 0:82ff15078322 45 // Initialise the hardware
claytong 0:82ff15078322 46 void Init();
claytong 0:82ff15078322 47
claytong 0:82ff15078322 48 // Start receiving
claytong 0:82ff15078322 49 void Start();
claytong 0:82ff15078322 50
claytong 0:82ff15078322 51 // Stop receiving
claytong 0:82ff15078322 52 void Stop();
claytong 0:82ff15078322 53
claytong 0:82ff15078322 54 // Receiver status
claytong 0:82ff15078322 55 bool Running()
claytong 0:82ff15078322 56 { return bRunning; }
claytong 0:82ff15078322 57
claytong 0:82ff15078322 58 // Test for a buffer available
claytong 0:82ff15078322 59 // Return number of queued buffers
claytong 0:82ff15078322 60 int Count() const
claytong 0:82ff15078322 61 { return ReceivedBuffers.Count(); }
claytong 0:82ff15078322 62 // Test if empty
claytong 0:82ff15078322 63 bool Empty() const
claytong 0:82ff15078322 64 { return ReceivedBuffers.Empty(); }
claytong 0:82ff15078322 65
claytong 0:82ff15078322 66 // Read out a buffer
claytong 0:82ff15078322 67 bool Read( TBufferHandle &Handle )
claytong 0:82ff15078322 68 {
claytong 0:82ff15078322 69 // queue is filled from interrupts, so we need to ensure we always access it with interrupts off
claytong 0:82ff15078322 70 __disable_irq();
claytong 0:82ff15078322 71 bool bRet = ReceivedBuffers.Read(Handle);
claytong 0:82ff15078322 72 __enable_irq();
claytong 0:82ff15078322 73 return bRet;
claytong 0:82ff15078322 74 }
claytong 0:82ff15078322 75
claytong 0:82ff15078322 76 // report the number of buffer failures
claytong 0:82ff15078322 77 uint32_t BufferFailures() const
claytong 0:82ff15078322 78 { return ulBufferFailures; }
claytong 0:82ff15078322 79
claytong 0:82ff15078322 80 // DMA IRQ Routine
claytong 0:82ff15078322 81 void DMA_Interrupt(void);
claytong 0:82ff15078322 82
claytong 0:82ff15078322 83 // Debug routine -
claytong 0:82ff15078322 84 // Read samples from the I2S by polling it
claytong 0:82ff15078322 85 // Returns number of samples read
claytong 0:82ff15078322 86 int PolledRead( int32_t *piBuffer, int iLen );
claytong 0:82ff15078322 87
claytong 0:82ff15078322 88 // Debug routine -
claytong 0:82ff15078322 89 // Read status register
claytong 0:82ff15078322 90 uint32_t Status();
claytong 0:82ff15078322 91
claytong 0:82ff15078322 92 // Debug routine -
claytong 0:82ff15078322 93 // Report Status
claytong 0:82ff15078322 94 void Report();
claytong 0:82ff15078322 95
claytong 0:82ff15078322 96 // Private methods
claytong 0:82ff15078322 97 private:
claytong 0:82ff15078322 98
claytong 0:82ff15078322 99 // Start a new DMA transfer
claytong 0:82ff15078322 100 void StartDMATransfer();
claytong 0:82ff15078322 101
claytong 0:82ff15078322 102 // data
claytong 0:82ff15078322 103 private:
claytong 0:82ff15078322 104 // pool to get buffers from
claytong 0:82ff15078322 105 TBufferPool &EmptyBuffersPool;
claytong 0:82ff15078322 106
claytong 0:82ff15078322 107 // queue of incoming sample buffers
claytong 0:82ff15078322 108 TBufferQueue ReceivedBuffers;
claytong 0:82ff15078322 109
claytong 0:82ff15078322 110 // the current buffer being used
claytong 0:82ff15078322 111 TBufferHandle CurrentRxBuffer;
claytong 0:82ff15078322 112
claytong 0:82ff15078322 113 // flags indicating run status
claytong 0:82ff15078322 114 bool bRunning;
claytong 0:82ff15078322 115
claytong 0:82ff15078322 116 // a buffer to use when there are no empty buffers available
claytong 0:82ff15078322 117 int32_t aulDummyBuffer[I2S_DUMMY_BUFFER_SIZE];
claytong 0:82ff15078322 118
claytong 0:82ff15078322 119 // frame counters etc
claytong 0:82ff15078322 120 uint32_t ulBufferCount;
claytong 0:82ff15078322 121 uint32_t ulBufferAllocations;
claytong 0:82ff15078322 122 uint32_t ulBufferFailures;
claytong 0:82ff15078322 123
claytong 0:82ff15078322 124 };
claytong 0:82ff15078322 125
claytong 0:82ff15078322 126 #endif
claytong 0:82ff15078322 127
claytong 0:82ff15078322 128 //---------------------------------------------------------------------------
claytong 0:82ff15078322 129 // END
claytong 0:82ff15078322 130 //---------------------------------------------------------------------------
claytong 0:82ff15078322 131