Add the RTOS processing. for the Network radio streaming receiver.

Fork of VS1053b by Christian Schmiljun

Files at this revision

API Documentation at this revision

Comitter:
ban4jp
Date:
Sun Feb 22 14:44:41 2015 +0000
Parent:
9:0d76f559a151
Commit message:
Add support the RTOS processing.

Changed in this revision

VS1053.cpp Show annotated file Show diff for this revision Revisions of this file
VS1053.h Show annotated file Show diff for this revision Revisions of this file
--- a/VS1053.cpp	Sun Jan 16 16:53:16 2011 +0000
+++ b/VS1053.cpp	Sun Feb 22 14:44:41 2015 +0000
@@ -55,8 +55,18 @@
         _RST(rst),
         _DCS(dcs),
         _DREQ(dreq),        
+#ifdef DEBUG
+        _led(D8),
+#endif
+#ifdef VS1053_RTOS
+        _thread(VS1053::dataRequestHandler_start, this, osPriorityNormal, 1024)
+#else
         _DREQ_INTERUPT_IN(dreq) 
+#endif
 {           
+        cs_high();
+        dcs_high();
+
         _volume = DEFAULT_VOLUME;
         _balance = DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT;
         _sb_amplitude = DEFAULT_BASS_AMPLITUDE;
@@ -65,9 +75,15 @@
         _st_freqlimit = DEFAULT_TREBLE_FREQUENCY;   
         _buffer = buffer;
         BUFFER_SIZE = buffer_size;
+#ifndef VS1053_RTOS
         _DREQ_INTERUPT_IN.mode(PullDown);
+#endif
         INTERRUPT_HANDLER_DISABLE;
         bufferReset();
+        
+#ifdef VS1053_RTOS
+        _thread.signal_set(START_THREAD);
+#endif
 }
 
 
@@ -357,6 +373,7 @@
     changeVolume();
     changeBass();    
     _isIdle = true;
+    _isPlay = false;
     return true;
 }
 
@@ -570,12 +587,35 @@
     _bufferWritePointer = _buffer;            
 }
 
+#ifdef VS1053_RTOS
+void VS1053::dataRequestHandler_start(const void *args)
+{
+    VS1053 *instance = (VS1053*)args;
+    instance->dataRequestHandler();
+}
+#endif
 
 void VS1053::dataRequestHandler(void)
 {    
+#ifdef VS1053_RTOS
+    _thread.signal_wait(START_THREAD);
+    
+    while(1)
+    {
+        if (!_DREQ || !_isPlay) {
+            Thread::wait(10);
+            continue;
+        }
+#else
     if (_isIdle && _DREQ) 
     {
+#endif
         _isIdle = false;
+
+#ifdef DEBUG
+        _led = 0;
+#endif
+
         // write buffer to vs1053b
         unsigned length = bufferCount();        
         int i = 0;   
@@ -591,6 +631,8 @@
             }
             
             length -= l2;
+            
+            //wait_us(50);
     
             if (!_DREQ || i > 4)
                 break;    
@@ -598,8 +640,17 @@
         }
         
         sdi_dis();   
+
+#ifdef DEBUG
+        _led = 1;
+#endif
         
         _isIdle = true;
+
+#ifdef VS1053_RTOS
+        //Thread::wait(10);
+        Thread::yield();
+#endif
     }               
 }
 
@@ -613,12 +664,17 @@
 {
     INTERRUPT_HANDLER_DISABLE;
     DEBUGOUT("VS1053b: Pause.\r\n");
+#ifdef DEBUG
+    _led = 1;
+#endif
 }
 
 void VS1053::stop(void)
 {
     INTERRUPT_HANDLER_DISABLE;
+#ifndef VS1053_RTOS
     __disable_irq();
+#endif
     DEBUGOUT("VS1053b: Song stoping..\r\n");
     while(!_isIdle) 
         ;
@@ -668,7 +724,9 @@
     }
             
     bufferReset();  
+#ifndef VS1053_RTOS
     __enable_irq();  
+#endif
 }
 
 void VS1053::getAudioInfo(AudioInfo* aInfo)
--- a/VS1053.h	Sun Jan 16 16:53:16 2011 +0000
+++ b/VS1053.h	Sun Feb 22 14:44:41 2015 +0000
@@ -48,6 +48,11 @@
 #include "defines.h"
 #include "mbed.h"
 
+#ifdef VS1053_RTOS
+#include "rtos.h"
+#define START_THREAD 1
+#endif
+
 #if defined(VS1053_PATCH_1_4_FLAC) && defined(VS1053_PATCH_1_5) && defined(VS1053_PATCH_1_5_FLAC) && defined(VS1053_SPECANA) && defined(VS1053B_PCM_RECORDER_0_9)
 #error "VS1053: Exclusive use of patch and app versions."
 #endif
@@ -133,8 +138,13 @@
 #define para_positionMsec_1                         0x1E28
 #define para_resync                                 0x1E29
    
+#ifdef VS1053_RTOS
+#define INTERRUPT_HANDLER_ENABLE                    _isPlay = true
+#define INTERRUPT_HANDLER_DISABLE                   _isPlay = false
+#else
 #define INTERRUPT_HANDLER_ENABLE                    _DREQ_INTERUPT_IN.rise(this, &VS1053::dataRequestHandler); timer.attach_us(this, &VS1053::dataRequestHandler, 1000)
 #define INTERRUPT_HANDLER_DISABLE                   _DREQ_INTERUPT_IN.rise(NULL); timer.detach()  
+#endif
 
 
 /** Types of audio streams
@@ -497,6 +507,9 @@
     
     unsigned char bufferGetByte(void);    
     void bufferReset(void);         
+#ifdef VS1053_RTOS
+    static void dataRequestHandler_start(const void *args);
+#endif
     void dataRequestHandler(void);
     
     SPI                             _spi;
@@ -504,7 +517,15 @@
     DigitalOut                      _RST;
     DigitalOut                      _DCS;    
     DigitalIn                       _DREQ;    
+#ifdef DEBUG
+    DigitalOut                      _led;
+#endif
+    
+#ifdef VS1053_RTOS
+    Thread                          _thread;
+#else
     InterruptIn                     _DREQ_INTERUPT_IN;
+#endif
     
     char*                            _buffer;
     char*                           _bufferReadPointer;
@@ -512,6 +533,7 @@
     int                             BUFFER_SIZE;
     
     bool                            _isIdle;
+    bool                            _isPlay;
 
     // variables to save 
     //   volume, values in db