interrupt handling

Dependencies:  

Committer:
soumi_ghsoh
Date:
Thu Apr 30 23:30:55 2015 +0000
Revision:
13:16a5b43ac874
Parent:
11:d5e8f47880f1
2015apr30

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rwclough 1:1eb96189824d 1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
rwclough 2:bd5afc5aa139 2 Filename: main.cpp
soumi_ghsoh 13:16a5b43ac874 3 Description: Interface nRF51-DK eval board to TRF7970 eval board
soumi_ghsoh 13:16a5b43ac874 4 to test the suitability of the TRF7970 NFC chip
rwclough 1:1eb96189824d 5 for use in Gymtrack products.
rwclough 1:1eb96189824d 6 The nRF51-DK board has an nRF51422 MCU.
rwclough 1:1eb96189824d 7 Copyright (C) 2015 Gymtrack, Inc.
rwclough 1:1eb96189824d 8 Author: Ron Clough
rwclough 1:1eb96189824d 9 Date: 2015-02-26
soumi_ghsoh 13:16a5b43ac874 10
rwclough 1:1eb96189824d 11 Changes:
rwclough 1:1eb96189824d 12 Rev Date Who Details
rwclough 1:1eb96189824d 13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rwclough 1:1eb96189824d 14 0.0 2015-02-26 RWC Original version.
soumi_ghsoh 13:16a5b43ac874 15
rwclough 1:1eb96189824d 16 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
rwclough 0:5622c60e9d3a 17
rwclough 1:1eb96189824d 18 #include "mbed.h"
soumi_ghsoh 5:93c612f43ec2 19
soumi_ghsoh 5:93c612f43ec2 20 //#include "NFC_7970.h"
rwclough 1:1eb96189824d 21 #include "readerComm.h"
soumi_ghsoh 9:9266e0109d26 22 #include "BLEDevice.h"
soumi_ghsoh 9:9266e0109d26 23 #include "HeartRateService.h"
soumi_ghsoh 9:9266e0109d26 24 #include "DeviceInformationService.h"
soumi_ghsoh 13:16a5b43ac874 25 #include "GT_Timer.h"
soumi_ghsoh 13:16a5b43ac874 26 #include "CompareTime.h"
soumi_ghsoh 13:16a5b43ac874 27 SPI spi(p7, p8, p3); // MOSI, MISO, SCLK
soumi_ghsoh 13:16a5b43ac874 28 // Slave Select (SS)
soumi_ghsoh 13:16a5b43ac874 29 #define BLED_PIN p17
soumi_ghsoh 13:16a5b43ac874 30 #define RLED_PIN p19
soumi_ghsoh 13:16a5b43ac874 31 #define GLED_PIN p18
soumi_ghsoh 13:16a5b43ac874 32 DigitalOut BLED(BLED_PIN);
soumi_ghsoh 13:16a5b43ac874 33 DigitalOut RLED(RLED_PIN);
soumi_ghsoh 13:16a5b43ac874 34 DigitalOut GLED(GLED_PIN);
soumi_ghsoh 13:16a5b43ac874 35
soumi_ghsoh 13:16a5b43ac874 36 Serial pc(p24, p25); // Serial communication over USB with PC
soumi_ghsoh 13:16a5b43ac874 37 //DigitalOut heartbeatLED(LED4); // "Heartbeat" LED
soumi_ghsoh 13:16a5b43ac874 38 //DigitalOut debug2LED(LED2); // "Debug2" LED
soumi_ghsoh 13:16a5b43ac874 39 //DigitalOut ISO15693LED(LED3); // "Detected ISO15693 tag" LED
soumi_ghsoh 13:16a5b43ac874 40 //DigitalOut debug1LED(LED1); // "Debug1" LED
soumi_ghsoh 10:98a58968dc7d 41 extern DigitalOut EN; // Control EN pin on TRF7970
soumi_ghsoh 10:98a58968dc7d 42 extern DigitalOut EN2; // Control EN2 pin on TRF7970
soumi_ghsoh 13:16a5b43ac874 43 extern DigitalOut CS;
soumi_ghsoh 13:16a5b43ac874 44 extern DigitalOut AO_7970;
soumi_ghsoh 13:16a5b43ac874 45 extern DigitalOut MOD_7970;
soumi_ghsoh 7:96baf1b2fd07 46 //DigitalInOut ook_ask(p6); // Control ASK/OOK pin on TRF7970
soumi_ghsoh 7:96baf1b2fd07 47 //DigitalOut mod(p5); // Control MOD pin on TRF7970
soumi_ghsoh 13:16a5b43ac874 48 InterruptIn readerInt(p28);
soumi_ghsoh 13:16a5b43ac874 49 //DigitalOut testPin(p1);
soumi_ghsoh 9:9266e0109d26 50 BLEDevice ble;
soumi_ghsoh 11:d5e8f47880f1 51 extern uint8_t buf[300];
soumi_ghsoh 7:96baf1b2fd07 52 uint8_t noBytes=0;
soumi_ghsoh 13:16a5b43ac874 53 extern uint8_t turnRFOn[2];
soumi_ghsoh 13:16a5b43ac874 54 extern uint8_t testcommand[2];
soumi_ghsoh 11:d5e8f47880f1 55 extern uint8_t found;
soumi_ghsoh 13:16a5b43ac874 56 extern int nfc;
soumi_ghsoh 7:96baf1b2fd07 57 bool tagFound=0;
soumi_ghsoh 11:d5e8f47880f1 58 //uint8_t WAIT=0;
soumi_ghsoh 13:16a5b43ac874 59 int next_reading_tag=0;
rwclough 2:bd5afc5aa139 60 int main()
soumi_ghsoh 13:16a5b43ac874 61 {
soumi_ghsoh 13:16a5b43ac874 62 //testPin=0;
soumi_ghsoh 13:16a5b43ac874 63 pc.baud(115200);
soumi_ghsoh 13:16a5b43ac874 64 AO_7970= 0;
soumi_ghsoh 13:16a5b43ac874 65 MOD_7970=0;
soumi_ghsoh 9:9266e0109d26 66 //=============================================================ble test
soumi_ghsoh 13:16a5b43ac874 67 // ble.init();
soumi_ghsoh 13:16a5b43ac874 68 //// ble.onDisconnection(disconnectionCallback);
soumi_ghsoh 13:16a5b43ac874 69 // //
soumi_ghsoh 13:16a5b43ac874 70 //// /* Setup advertising. */
soumi_ghsoh 13:16a5b43ac874 71 // ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
soumi_ghsoh 13:16a5b43ac874 72 //// // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
soumi_ghsoh 13:16a5b43ac874 73 // ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
soumi_ghsoh 13:16a5b43ac874 74 //// // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
soumi_ghsoh 13:16a5b43ac874 75 // ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
soumi_ghsoh 13:16a5b43ac874 76 // ble.setAdvertisingInterval(1000);
soumi_ghsoh 13:16a5b43ac874 77 // ble.startAdvertising();
soumi_ghsoh 9:9266e0109d26 78 //===============================================================*/
soumi_ghsoh 9:9266e0109d26 79
soumi_ghsoh 13:16a5b43ac874 80 readerInt.rise(&handlerNFC);
soumi_ghsoh 13:16a5b43ac874 81 CS=1;
soumi_ghsoh 13:16a5b43ac874 82 SpiInit(); //spi=1Mhz
soumi_ghsoh 13:16a5b43ac874 83 PowerUpNFC();
soumi_ghsoh 13:16a5b43ac874 84 NFCInit();
soumi_ghsoh 13:16a5b43ac874 85 RegisterReInitNFC();
soumi_ghsoh 13:16a5b43ac874 86 RegistersReadNFC();
soumi_ghsoh 13:16a5b43ac874 87 //PowerDownNFC(); //SleepNFC() //StandByNFC()
soumi_ghsoh 11:d5e8f47880f1 88 //SleepNFC();
soumi_ghsoh 13:16a5b43ac874 89 BLED=0;
soumi_ghsoh 13:16a5b43ac874 90 /** Print the text
soumi_ghsoh 13:16a5b43ac874 91 *
soumi_ghsoh 13:16a5b43ac874 92 * @groups PollNFC
soumi_ghsoh 13:16a5b43ac874 93 *
soumi_ghsoh 13:16a5b43ac874 94 * 1 on success,
soumi_ghsoh 13:16a5b43ac874 95 * 0 on serial error
soumi_ghsoh 13:16a5b43ac874 96 */
soumi_ghsoh 13:16a5b43ac874 97
soumi_ghsoh 13:16a5b43ac874 98 while(1) {
soumi_ghsoh 13:16a5b43ac874 99 // PowerUpNFC();
soumi_ghsoh 13:16a5b43ac874 100 // NFCInit();
soumi_ghsoh 13:16a5b43ac874 101 // RegisterReInitNFC();
soumi_ghsoh 13:16a5b43ac874 102
soumi_ghsoh 13:16a5b43ac874 103
soumi_ghsoh 13:16a5b43ac874 104 while(tagFound==0) {
soumi_ghsoh 13:16a5b43ac874 105 // printf("tag nt found \r\n");
soumi_ghsoh 13:16a5b43ac874 106 //BLED=1;
soumi_ghsoh 13:16a5b43ac874 107 //testcommand[0] = 0x17;
soumi_ghsoh 13:16a5b43ac874 108 //trf797xDirectCommand(testcommand);
soumi_ghsoh 13:16a5b43ac874 109 //testcommand[0] = 0x18;
soumi_ghsoh 13:16a5b43ac874 110 //trf797xDirectCommand(testcommand);
soumi_ghsoh 13:16a5b43ac874 111 //wait_ms(5);
soumi_ghsoh 13:16a5b43ac874 112 //testcommand[0] = RSSI_LEVELS; //Read RSSI levels and oscillator status(0x0F/0x4F)
soumi_ghsoh 13:16a5b43ac874 113 //trf797xReadSingle(testcommand, 1);
soumi_ghsoh 13:16a5b43ac874 114 //printf("RSSI:%X \r\n", testcommand[0]);
soumi_ghsoh 13:16a5b43ac874 115 //tagFound=PollNFC();
soumi_ghsoh 9:9266e0109d26 116
soumi_ghsoh 13:16a5b43ac874 117 tagFound=PollNFC();
soumi_ghsoh 13:16a5b43ac874 118 // RegisterReInitNFC();
soumi_ghsoh 13:16a5b43ac874 119 //wait_ms(5);
soumi_ghsoh 13:16a5b43ac874 120 //int tag= CompareTime( gt_read_ms(),next_reading_tag,50);
soumi_ghsoh 13:16a5b43ac874 121 //
soumi_ghsoh 13:16a5b43ac874 122 // if (tag<0) {
soumi_ghsoh 13:16a5b43ac874 123 // ;
soumi_ghsoh 13:16a5b43ac874 124 // } else {
soumi_ghsoh 13:16a5b43ac874 125 // RLED=1;
soumi_ghsoh 13:16a5b43ac874 126 // wait_ms(5);
soumi_ghsoh 13:16a5b43ac874 127 // RLED=0;
soumi_ghsoh 13:16a5b43ac874 128 // next_reading_tag = gt_read_ms();
soumi_ghsoh 13:16a5b43ac874 129 // printf("time out : no tag \r\n");
soumi_ghsoh 13:16a5b43ac874 130 // break;
soumi_ghsoh 13:16a5b43ac874 131 //
soumi_ghsoh 13:16a5b43ac874 132 // }
soumi_ghsoh 13:16a5b43ac874 133 }
soumi_ghsoh 13:16a5b43ac874 134 //
soumi_ghsoh 13:16a5b43ac874 135 if(tagFound==1) {nfc=0;
soumi_ghsoh 13:16a5b43ac874 136 //printf("read single block:");
soumi_ghsoh 13:16a5b43ac874 137 BLED=1;
soumi_ghsoh 13:16a5b43ac874 138 for(uint8_t i=0; i<noBytes; i++)
soumi_ghsoh 13:16a5b43ac874 139 printf("%X ", buf[i]);
soumi_ghsoh 13:16a5b43ac874 140 printf("\r\n");
soumi_ghsoh 13:16a5b43ac874 141 printf("tag found \r\n");
soumi_ghsoh 13:16a5b43ac874 142 BLED=0;
soumi_ghsoh 13:16a5b43ac874 143 tagFound=0;
soumi_ghsoh 13:16a5b43ac874 144 //////
soumi_ghsoh 13:16a5b43ac874 145 //////// //break;
soumi_ghsoh 13:16a5b43ac874 146 } //else {
soumi_ghsoh 13:16a5b43ac874 147 // printf("tag nt found \r\n");
soumi_ghsoh 13:16a5b43ac874 148 // }
soumi_ghsoh 13:16a5b43ac874 149 //////
soumi_ghsoh 11:d5e8f47880f1 150
soumi_ghsoh 13:16a5b43ac874 151
soumi_ghsoh 13:16a5b43ac874 152 PowerDownNFC();
soumi_ghsoh 13:16a5b43ac874 153 // wait(2);
soumi_ghsoh 13:16a5b43ac874 154 }
soumi_ghsoh 13:16a5b43ac874 155
soumi_ghsoh 7:96baf1b2fd07 156 }
soumi_ghsoh 9:9266e0109d26 157
soumi_ghsoh 5:93c612f43ec2 158