semaf

Dependencies:   Freetronics_16x2_LCD

Fork of HelloWorld_CCA01M1_mbedOS45 by STarks

Files at this revision

API Documentation at this revision

Comitter:
vidica94
Date:
Fri Jan 26 15:52:57 2018 +0000
Parent:
15:3624055fac29
Commit message:
wsdfghj

Changed in this revision

X_NUCLEO_CCA01M1.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
my_song.h Show annotated file Show diff for this revision Revisions of this file
diff -r 3624055fac29 -r 5e8108b82891 X_NUCLEO_CCA01M1.lib
--- a/X_NUCLEO_CCA01M1.lib	Mon Jan 22 12:20:32 2018 +0000
+++ b/X_NUCLEO_CCA01M1.lib	Fri Jan 26 15:52:57 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/vidica94/code/x-nucleo-cca01m1/#aef84cf5e74b
+https://os.mbed.com/users/vidica94/code/x-nucleo-cca01m1/#b197c23d0cc3
diff -r 3624055fac29 -r 5e8108b82891 main.cpp
--- a/main.cpp	Mon Jan 22 12:20:32 2018 +0000
+++ b/main.cpp	Fri Jan 26 15:52:57 2018 +0000
@@ -21,19 +21,44 @@
 Thread Suona_Thread;
 argomento* arg=(argomento*) malloc(sizeof(argomento));
 
-
+Mutex mutex_ping;
 
-    
-    
+Semaphore SPAZIO_DISP(2);
+Semaphore MSG_DISP(2);
+
 void Leggi_SD(argomento * arg){
     
     while(1){
-  
-    if(arg->sel == 0){
+        mutex_ping.lock();
+        SPAZIO_DISP.wait();
+        if ( arg->ping_r==0){
+
         fread(arg->ping,sizeof(int16_t), arg->size, arg->fd);
-        }else if(arg->sel == 1){
+        arg->ping_r=1;
+                //printf(" caricato ping\r\n");
+
+        }else if( arg->pong_r==0){
+                
+                fread(arg->pong,sizeof(int16_t), arg->size, arg->fd);
+                arg->pong_r=1;
+                        }
+                        
+        MSG_DISP.release();
+        mutex_ping.unlock();
+                        
+       // printf(" caricato ping\r\n");
+/*
+        
+                            arg->mutex_pong.lock();
+
         fread(arg->pong, sizeof(int16_t), arg->size, arg->fd);
-            }
+                arg->pong_r=1;
+                arg->mutex_pong.unlock();
+                printf(" caricato pong\r\n");        
+
+          
+            arg->sel=!(arg->sel);
+            */
         }  
     
     }
@@ -48,7 +73,7 @@
 /* Initialization parameters. */
 STA350BW_init_t init =
 {
-    32000,   /* Default Sampling Frequency [Hz]. */
+    22000,   /* Default Sampling Frequency [Hz]. */
     100      /* Default Volume. */
 };
 
@@ -103,7 +128,6 @@
     }
 }    
     
-   
 
 void return_error(int ret_val){
   if (ret_val)
@@ -121,23 +145,33 @@
 
 void Suona(argomento * arg){
         
-        while(1){
-        if(arg->sel == 0){    
-        sound_terminal->play((int16_t *) arg->pong, (uint16_t) sizeof(int16_t)*arg->size, true);
-        } else if( arg->sel == 1) {
-            sound_terminal->play((int16_t *) arg->ping, (uint16_t) sizeof(int16_t)*arg->size, true);
-            }
-            
-        arg->sel =  !(arg->sel);
+        while(1){    
+                    mutex_ping.lock();
+                    MSG_DISP.wait();
+if(arg->ping_r==1){
+            sound_terminal->play((int16_t *) arg->ping, (uint16_t) sizeof(int16_t)*(arg->size), false);
+                 // printf(" suonato ping\r\n");
+                arg->ping_r=0;
+}
+ if(arg->pong_r==1){
+    
+    sound_terminal->play((int16_t *) arg->pong, (uint16_t) sizeof(int16_t)*(arg->size), false);
+                 // printf(" suonato ping\r\n");
+                arg->pong_r=0;
+    }
+    
+    mutex_ping.unlock();
+    SPAZIO_DISP.release();
         }
-    
     }
 
 int main() {
       
        /*----- Initialization. -----*/
-arg->sel=0;
-arg->size=4000;
+//arg->sel=0;
+arg->size=9000;
+     arg->ping_r=0;
+     arg->pong_r=0;
 
     /* Initializing I2C bus. */
     DevI2C *dev_i2c = new DevI2C(PB_9, PB_8);
@@ -167,7 +201,7 @@
 
     /* Setting Sound Terminal Component's parameters. */
     sound_terminal->set_frequency(MY_SONG_AUDIO_FREQUENCY);
-    sound_terminal->set_volume(STA350BW_CHANNEL_MASTER, 60);
+    sound_terminal->set_volume(STA350BW_CHANNEL_MASTER, 55);
 
     /* Printing to the console. */
     printf("Sound Terminal Application Example\r\n\n");
@@ -198,7 +232,7 @@
   printf(" done.\r\n");
 
   printf("Re-opening file read-only.");
- FILE* fd = fopen("/fs/campagnola.wav", "r");
+ FILE* fd = fopen("/fs/marcia.wav", "r");
   errno_error(fd);
   arg->fd=fd;
    Leggi_SD_Thread.start(callback(Leggi_SD,arg));
diff -r 3624055fac29 -r 5e8108b82891 my_song.h
--- a/my_song.h	Mon Jan 22 12:20:32 2018 +0000
+++ b/my_song.h	Fri Jan 26 15:52:57 2018 +0000
@@ -1,9 +1,12 @@
-#define MY_SONG_AUDIO_FREQUENCY 32000
+#define MY_SONG_AUDIO_FREQUENCY 21000
 #define MY_SONG_SIZE            (14679 << 1)
 typedef struct {
-	int16_t ping[4000];
-	int16_t pong[4000];
-int sel ;
+	int16_t ping[9000];
+	int16_t pong[9000];
+int sel;
 int size;
 FILE * fd;
+int ping_r;
+int pong_r;
+
 	}argomento;
\ No newline at end of file