Dummy program to demonstrate problems: working code

Dependencies:   SLCD mbed-rtos mbed

Fork of MNG_TC by Shreesha S

Revision:
14:a4c259ca0325
Parent:
13:7b27a8e9cbb4
diff -r 7b27a8e9cbb4 -r a4c259ca0325 adf.h
--- a/adf.h	Mon Aug 03 14:29:35 2015 +0000
+++ b/adf.h	Mon Aug 17 12:05:09 2015 +0000
@@ -1,4 +1,3 @@
-SPI spi(PTA16, PTA17, PTA15); //MOSI, MISO, CLOCK
 DigitalOut cs_adf(D10);
 DigitalOut led2(LED_RED);
 InterruptIn IRQ(D8);
@@ -8,80 +7,80 @@
 bool transmission_done = false;
 bool sent_tmfrom_SDcard;
 unsigned char bbram_buffer[66]={0x19,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0xF4,0xc2,0x10,0xC0,0x00,0x30,0x31,0x07,0x00,0x01,0x00,0x7F,0x00,0x0B,0x37,0x00,0x00,0x40,0x0C,0x00,0x05,0x00,0x00,0x18,0x12,0x34,0x56,0x10,0x10,0xC4,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00};
-void bbram_write(){   
-    SPI_mutex.lock(); 
-    cs_adf=0;
-    spi.write(0xB0);//PHY_OFF
-    wait_us(300);
-    cs_adf=1;
-    SPI_mutex.unlock();
-    
-    SPI_mutex.lock();
-    // Write bbram
-    cs_adf=0;
-    for(int i=0;i<66;i++){
-        spi.write(bbram_buffer[i]);    
-    }
-    cs_adf=1;
-    SPI_mutex.unlock();
-}
+//void inline bbram_write(){   
+//    SPI_mutex.lock(); 
+//    cs_adf=0;
+//    spi.write(0xB0);//PHY_OFF
+//    wait_us(300);
+//    cs_adf=1;
+//    SPI_mutex.unlock();
+//    
+//    SPI_mutex.lock();
+//    // Write bbram
+//    cs_adf=0;
+//    for(int i=0;i<66;i++){
+//        spi.write(bbram_buffer[i]);    
+//    }
+//    cs_adf=1;
+//    SPI_mutex.unlock();
+//}
  
  
 /******************************************************************************************/
  
-void initiate(void){
-    SPI_mutex.lock();
-    cs_adf=0;
-    spi.write(0xFF);
-    spi.write(0xFF);
-    cs_adf=1;
-//    wait_ms(2);
- 
-    cs_adf=0;
-    spi.write(0x08);    // TRANSMIT_DATA LENGTH
-    spi.write(0x14);
-    spi.write(0xFF);
-    cs_adf=1;
-//    wait_ms(2);
-    cs_adf=0;
-    spi.write(0x08);        // TRANSMIT_DATA LENGTH
-    spi.write(0x15);
-    spi.write(0xFF);
-    cs_adf=1;
-//    wait_ms(2);
-    
-    cs_adf=0;
-    spi.write(0x09);
-    spi.write(0x24);   // TX_BASE ADDRESS   0x20(starting Tx Byte)
-    spi.write(0x20);
-    cs_adf=1;
-//    wait_ms(2);
-    
-    cs_adf=0;
-    spi.write(0x09);
-    spi.write(0x37);// BUFFER SIZE 0xE0=224 Bytes 0x137 is adress of buffer size
-    spi.write(0xE0);
-    cs_adf=1;
-//    wait_ms(2);
-    
-    cs_adf=0;
-    spi.write(0x09);
-    spi.write(0x36);//BB_Tx_Buffer Signal when Buffer is half filled
-    spi.write(0x70);//0x70 = 112 >> When Half buffer interrupt is given
-    cs_adf=1;
-//    wait_ms(2);
-    
-    
-    cs_adf=0;
-    spi.write(0x09);
-    spi.write(0x39);//BB_Tx_Buffer Signal when Buffer is half filled
-    spi.write(0x10);//0x70 = 112 >> When Half buffer interrupt is given
-    cs_adf=1;
-//    wait_ms(2);    
-    SPI_mutex.unlock();
-    }
- 
- 
+//void initiate(void){
+//    SPI_mutex.lock();
+//    cs_adf=0;
+//    spi.write(0xFF);
+//    spi.write(0xFF);
+//    cs_adf=1;
+////    wait_ms(2);
+// 
+//    cs_adf=0;
+//    spi.write(0x08);    // TRANSMIT_DATA LENGTH
+//    spi.write(0x14);
+//    spi.write(0xFF);
+//    cs_adf=1;
+////    wait_ms(2);
+//    cs_adf=0;
+//    spi.write(0x08);        // TRANSMIT_DATA LENGTH
+//    spi.write(0x15);
+//    spi.write(0xFF);
+//    cs_adf=1;
+////    wait_ms(2);
+//    
+//    cs_adf=0;
+//    spi.write(0x09);
+//    spi.write(0x24);   // TX_BASE ADDRESS   0x20(starting Tx Byte)
+//    spi.write(0x20);
+//    cs_adf=1;
+////    wait_ms(2);
+//    
+//    cs_adf=0;
+//    spi.write(0x09);
+//    spi.write(0x37);// BUFFER SIZE 0xE0=224 Bytes 0x137 is adress of buffer size
+//    spi.write(0xE0);
+//    cs_adf=1;
+////    wait_ms(2);
+//    
+//    cs_adf=0;
+//    spi.write(0x09);
+//    spi.write(0x36);//BB_Tx_Buffer Signal when Buffer is half filled
+//    spi.write(0x70);//0x70 = 112 >> When Half buffer interrupt is given
+//    cs_adf=1;
+////    wait_ms(2);
+//    
+//    
+//    cs_adf=0;
+//    spi.write(0x09);
+//    spi.write(0x39);//BB_Tx_Buffer Signal when Buffer is half filled
+//    spi.write(0x10);//0x70 = 112 >> When Half buffer interrupt is given
+//    cs_adf=1;
+////    wait_ms(2);    
+//    SPI_mutex.unlock();
+//    }
+// 
+// 
  
 void write_data(void){
    
@@ -164,9 +163,196 @@
     }
 }
   
+// 
+//void send_data(void){
+//    SPI_mutex.lock();
+//    cs_adf=0;
+//    spi.write(0xBB);
+//    cs_adf=1;
+////    wait_us(300); 
+//    
+//    cs_adf=0;
+//    spi.write(0xFF);
+//    spi.write(0xFF);
+//    cs_adf=1;
+//    SPI_mutex.unlock();
+////    wait_ms(2);
+//    if(sent_tmfrom_SDcard){
+//        printf("inside if\r\n");
+//        send_tm_from_SD_card();
+//    }
+//    else{
+//        printf("inside else\r\n");
+//        snd_tm.transmit_data(buffer_112,&last_buffer);
+//    }
+////    SPI_mutex.lock();
+////    write_data();
+////    SPI_mutex.unlock();
+////    if(sent_tmfrom_SDcard)
+////    {
+////        send_tm_from_SD_card();
+////    }
+////    else
+////    { 
+////        snd_tm.transmit_data(buffer_112,&last_buffer);
+////    }
+////    SPI_mutex.lock();
+////    write_data();
+////    SPI_mutex.unlock();
+////    if(sent_tmfrom_SDcard)
+////    {
+////        send_tm_from_SD_card();
+////    }
+////    else
+////    { 
+////        snd_tm.transmit_data(buffer_112,&last_buffer);
+////    }
+////    SPI_mutex.lock();
+////    cs_adf=0;
+////    spi.write(0xB1);
+////    cs_adf=1;
+////    SPI_mutex.unlock();
+////    wait_us(300); 
+////    SPI_mutex.lock();
+////    cs_adf=0;
+////    spi.write(0xFF);
+////    spi.write(0xFF);
+////    cs_adf=1;
+////    
+//////    wait_ms(2);  
+////    
+////    cs_adf=0;
+////    spi.write(0xB5);
+////    cs_adf=1;
+//////    cout<<"B5 given"<<ENDL;
+////    SPI_mutex.unlock();
+////    wait_us(300);  
+//////    int b5=t.read_us();
+////    SPI_mutex.lock();
+////    cs_adf=0;
+////    spi.write(0xFF);
+////    spi.write(0xFF);
+////    cs_adf=1;
+////    SPI_mutex.unlock();
+//////    wait_ms(2);
+////    ticker.attach_us(&check,32000);
+////    
+////    while(!transmission_done){
+////        led2=!led2;
+////        printf("x");
+////        Thread::signal_wait(0x2);
+////        
+////        SPI_mutex.lock();
+////        write_data();
+////        SPI_mutex.unlock();
+////        if(sent_tmfrom_SDcard){
+////            send_tm_from_SD_card();
+////        }
+////        else{
+////            snd_tm.transmit_data(buffer_112,&last_buffer);
+////        }
+////    }
+//}
+//    
+//    
+    
+void inline spi_SND_SDCard(uint64_t x,uint64_t y ){
+    start_block_num = x;
+    end_block_num = y;
+    sent_tmfrom_SDcard = true;
+    spi.format(8,0);
+    spi.frequency(1000000);
  
-void send_data(void){
-    SPI_mutex.lock();    
+//    bbram_write();
+//    initiate();
+//    send_data();
+ 
+}
+    
+void read_TC(TC_list* TC_ptr){
+    unsigned char service_subtype = 0;
+    uint64_t starting_add  = 0, ending_add = 0;
+    service_subtype = (TC_ptr->TC_string[2])&0x0f;
+    starting_add =  (TC_ptr->TC_string[5]) +  ( (TC_ptr->TC_string[4])<<8 ) + ( (TC_ptr->TC_string[3]) <<16);
+    ending_add =  (TC_ptr->TC_string[8]) +  ( (TC_ptr->TC_string[7])<<8 ) + ( (TC_ptr->TC_string[6]) <<16);
+    spi_SND_SDCard(starting_add , ending_add);   
+}
+    
+ 
+void inline adf_not_SDcard(){
+    spi.format(8,0);
+    spi.frequency(1000000);
+    sent_tmfrom_SDcard = false;
+//    bbram_write();
+    SPI_mutex.lock(); 
+    cs_adf=0;
+    spi.write(0xB0);//PHY_OFF
+    wait_us(300);
+    cs_adf=1;
+    SPI_mutex.unlock();
+    
+    SPI_mutex.lock();
+    // Write bbram
+    cs_adf=0;
+    for(int i=0;i<66;i++){
+        spi.write(bbram_buffer[i]);    
+    }
+    cs_adf=1;
+    SPI_mutex.unlock();
+//    initiate();
+
+SPI_mutex.lock();
+    cs_adf=0;
+    spi.write(0xFF);
+    spi.write(0xFF);
+    cs_adf=1;
+//    wait_ms(2);
+ 
+    cs_adf=0;
+    spi.write(0x08);    // TRANSMIT_DATA LENGTH
+    spi.write(0x14);
+    spi.write(0xFF);
+    cs_adf=1;
+//    wait_ms(2);
+    cs_adf=0;
+    spi.write(0x08);        // TRANSMIT_DATA LENGTH
+    spi.write(0x15);
+    spi.write(0xFF);
+    cs_adf=1;
+//    wait_ms(2);
+    
+    cs_adf=0;
+    spi.write(0x09);
+    spi.write(0x24);   // TX_BASE ADDRESS   0x20(starting Tx Byte)
+    spi.write(0x20);
+    cs_adf=1;
+//    wait_ms(2);
+    
+    cs_adf=0;
+    spi.write(0x09);
+    spi.write(0x37);// BUFFER SIZE 0xE0=224 Bytes 0x137 is adress of buffer size
+    spi.write(0xE0);
+    cs_adf=1;
+//    wait_ms(2);
+    
+    cs_adf=0;
+    spi.write(0x09);
+    spi.write(0x36);//BB_Tx_Buffer Signal when Buffer is half filled
+    spi.write(0x70);//0x70 = 112 >> When Half buffer interrupt is given
+    cs_adf=1;
+//    wait_ms(2);
+    
+    
+    cs_adf=0;
+    spi.write(0x09);
+    spi.write(0x39);//BB_Tx_Buffer Signal when Buffer is half filled
+    spi.write(0x10);//0x70 = 112 >> When Half buffer interrupt is given
+    cs_adf=1;
+//    wait_ms(2);    
+    SPI_mutex.unlock();
+//    send_data();
+
+SPI_mutex.lock();
     cs_adf=0;
     spi.write(0xBB);
     cs_adf=1;
@@ -181,7 +367,7 @@
     if(sent_tmfrom_SDcard){
         send_tm_from_SD_card();
     }
-    else{ 
+    else{
         snd_tm.transmit_data(buffer_112,&last_buffer);
     }
     SPI_mutex.lock();
@@ -250,41 +436,4 @@
             snd_tm.transmit_data(buffer_112,&last_buffer);
         }
     }
-    
-}
-    
-    
-    
-void inline spi_SND_SDCard(uint64_t x,uint64_t y ){
-    start_block_num = x;
-    end_block_num = y;
-    sent_tmfrom_SDcard = true;
-    spi.format(8,0);
-    spi.frequency(1000000);
- 
-    bbram_write();
-    initiate();
-    send_data();
- 
-}
-    
-void read_TC(TC_list* TC_ptr){
-    unsigned char service_subtype = 0;
-    uint64_t starting_add  = 0, ending_add = 0;
-    service_subtype = (TC_ptr->TC_string[2])&0x0f;
-    starting_add =  (TC_ptr->TC_string[5]) +  ( (TC_ptr->TC_string[4])<<8 ) + ( (TC_ptr->TC_string[3]) <<16);
-    ending_add =  (TC_ptr->TC_string[8]) +  ( (TC_ptr->TC_string[7])<<8 ) + ( (TC_ptr->TC_string[6]) <<16);
-    spi_SND_SDCard(starting_add , ending_add);   
-}
-    
- 
-void adf_not_SDcard(){
-    spi.format(8,0);
-    spi.frequency(1000000);
-    sent_tmfrom_SDcard = false;
-    
-    bbram_write();
-    initiate();
-    send_data();
- 
 }
\ No newline at end of file