interrupt handling

Dependencies:  

Revision:
9:9266e0109d26
Parent:
7:96baf1b2fd07
Child:
10:98a58968dc7d
--- a/main.cpp	Tue Apr 07 20:20:56 2015 +0000
+++ b/main.cpp	Wed Apr 08 20:48:05 2015 +0000
@@ -19,7 +19,9 @@
 
 //#include    "NFC_7970.h"
 #include    "readerComm.h"
-
+#include "BLEDevice.h"
+#include "HeartRateService.h"
+#include "DeviceInformationService.h"
 SPI         spi(p25, p28, p29); // MOSI, MISO, SCLK
            // Slave Select (SS)
 Serial      pc(USBTX, USBRX);   // Serial communication over USB with PC
@@ -27,34 +29,86 @@
 DigitalOut  debug2LED(LED2);    // "Debug2" LED
 DigitalOut  ISO15693LED(LED3);  // "Detected ISO15693 tag" LED
 DigitalOut  debug1LED(LED1);    // "Debug1" LED
+
+
 //DigitalInOut  ook_ask(p6);      // Control ASK/OOK pin on TRF7970
 //DigitalOut  mod(p5);            // Control MOD pin on TRF7970
 InterruptIn     readerInt(p7); 
 DigitalOut  testPin(p1);
-
+BLEDevice  ble;
 uint8_t     buf[300];
 uint8_t noBytes=0;
-
+extern uint8_t    turnRFOn[2]; 
+extern uint8_t    testcommand[2]; 
 uint8_t     found=0;
 bool tagFound=0;
 int main()
-{
+{testPin=0;
 pc.baud(115200);
+
+//=============================================================ble test
+ ble.init();
+// ble.onDisconnection(disconnectionCallback);
+ //
+//    /* Setup advertising. */
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+//  //  ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
+//   // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.setAdvertisingInterval(1000);
+    ble.startAdvertising();
+//===============================================================*/
+
 readerInt.rise(&handlerNFC);
-PowerUpNFC();
 SpiInit(); //spi=1Mhz
+PowerUpNFC2();
+
 NFCInit();
-wait_ms(1);
-RegisterReInitNFC();
-RegistersReadNFC();
+//wait_ms(1);
+//RegisterReInitNFC();
+//RegistersReadNFC();
+//wait_ms(10);
+//PowerDownNFC();
+//wait(10);
+//
+//PowerUpNFC2();
+//NFCInit();
+////
+//wait_ms(1);
+//RegisterReInitNFC();
+
+//RegistersReadNFC();
+
+
+
+
+//wait_ms(10);
+//PowerUpNFC();
 while(1)
-{
+{PowerUpNFC2();
+ NFCInit();
+//wait_ms(1);
+//RegisterReInitNFC();
+//RegistersReadNFC();
+//turnRFOn[0] = CHIP_STATUS_CONTROL;
+//turnRFOn[1] = CHIP_STATUS_CONTROL;
+////
+//turnRFOn[1] &= 0x3F;
+//turnRFOn[1] |= 0x20;
+//trf797xWriteSingle(turnRFOn, 2);
+//////wait_ms(2);
+//// 
+//testcommand[0] = ISO_CONTROL;
+//testcommand[1] = 0x02;                  // 6.78 MHz, OOK 100%
+//trf797xWriteSingle(testcommand, 2);
+//RegisterReInitNFC();
 MemReadReqNFC();
 if(found==1)
 {
 ReadNFC();
-
-printf("read single block:");
+PowerDownNFC();
+//printf("read single block:");
 for(uint8_t i=0; i<noBytes; i++)
 printf("%X ", buf[i]);
 printf("\r\n");
@@ -63,20 +117,22 @@
 else 
 {printf("tnf1 \r\n");
 }
-InventoryReqNFC();
-if(found==1)
-{
-ReadNFC();
-printf("tag id:");
-for(uint8_t i=0; i<noBytes; i++)
-printf("%X ", buf[i]);
-printf("\r\n");
-found=0;
+//InventoryReqNFC();
+//if(found==1)
+//{
+//ReadNFC();
+//printf("tag id:");
+//for(uint8_t i=0; i<noBytes; i++)
+//printf("%X ", buf[i]);
+//printf("\r\n");
+//found=0;
+//}
+//else 
+//{printf("tnf2 \r\n");
+//}
+wait(1);
 }
-else 
-{printf("tnf2 \r\n");
-}
-}
+
 }  
 
 
@@ -87,92 +143,3 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-    
-    ////  Setup LEDs
-//    heartbeatLED = LED_OFF;
-//    ISO15693LED = LED_OFF;
-//    debug1LED = LED_OFF;
-//    debug2LED = LED_OFF;
-    
-    //for (uint8_t i=0; i<4; i++) {
-//        heartbeatLED = LED_ON;
-//       ISO15693LED = LED_ON;
-//       debug1LED = LED_ON;
-//       wait_ms(100);
-//       heartbeatLED = LED_OFF;
-//       ISO15693LED = LED_OFF;
-//       debug1LED = LED_OFF;
-//       wait_ms(100);
-//           }
-//    
-//    Ticker  heartbeat;
-//    heartbeat.attach(blinkHeartbeatLED, 1);
-//    printf("LEDs, ");
-   //=============================================================== 
-    //  Setup the SPI interface
- //   spi.format(8, 1);       // 8 bit data, mode = 1 (transition on rising edge, sample on falling edge)
-//    spi.frequency(1000000); // SCLK = 1 MHz
-////    printf("SPI, ");
-//    
-//    //  Set On-Off Keying modulation
-//    ook_ask.output();
-//    ook_ask = 1;
-////    printf("OOK, ");
-//    
-//    //  Apply initial settings to the TRF7970
-//    testPin=1;
-//    trf797xInitialSettings();
-////    printf("Initialized, ");
-//   testPin=0;
-//    //  Tri-state OOK pin
-//    ook_ask.input();
-//    ook_ask.mode(PullUp);
-//    
-//    readerMode = 0x00;
-   //============================================================= 
-    /*
-    //  Test: Write 0xAA to MODULATOR_CONTROL, then verify by reading MODULATOR_CONTROL.
-//    printf("\r\n");
-    buffer[0] = MODULATOR_CONTROL;
-    buffer[1] = 0xAA;
-//    printf("BEFORE WR: buffer[0]: %X  buffer[1]: %X\r\n", buffer[0], buffer[1]);
-    spiWriteSingle(buffer, 2);
-//    printf("AFTER WR:  buffer[0]: %X  buffer[1]: %X\r\n", buffer[0], buffer[1]);
-    spiReadSingle(buffer, 1);
-//    printf("AFTER RD:  buffer[0]: %X  buffer[1]: %X\r\n", buffer[0], buffer[1]);
-//    printf("\r\n");
-    */
-    
-   // printf("\r\nFinished Init\r\n");
-    
-    //  Setup interrupt from TRF7970
-  //  testPin=1;
-  //========================
- //  trf797xSetupIrq();
-   //======================
-  // testPin=0;
-//    printf("IRQ setup, ");
-    
-//    printf("finished init.\r\n\r\n");
-
-  //  while(1) {                                    // changed TRUE to 1 $SG
-//       iso15693FindTag();
-//    }
-//    
-//}   // End of main()