interrupt handling
Diff: readerComm.cpp
- Revision:
- 1:1eb96189824d
- Child:
- 2:bd5afc5aa139
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/readerComm.cpp Mon Mar 02 19:50:31 2015 +0000 @@ -0,0 +1,179 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + Filename: readerComm.c + Description: Functions used to communicate with the TRF7970 eval bd. + Communication is by means of an SPI interface between + the nRF51-DK board (nRF51422 MCU) and the TRF7970 eval bd. + Copyright (C) 2015 Gymtrack, Inc. + Author: Ron Clough + Date: 2015-02-27 + + Changes: + Rev Date Who Details + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 0.0 2015-02-2 RWC Original version. + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "mbed.h" +#include "readerComm.h" + +extern SPI spi; // main.cpp +extern DigitalOut CS; // main.cpp + +void firstComm(void) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// firstComm() +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + int mod_control[2]; + + mod_control[0] = SOFT_INIT; + directCommand(mod_control); + mod_control[0] = IDLE; + directCommand(mod_control); + mod_control[0] = MODULATOR_CONTROL; + mod_control[1] = 0x21; + writeSingle(mod_control, 2); + mod_control[0] = MODULATOR_CONTROL; + readSingle(mod_control, 1); +} // End of firstComm() + +void directCommand(int *buffer) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// directCommand() +// Description: Transmit a Direct Command to the reader chip. +// Parameter: *buffer = the direct command. +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + *buffer = (0x80 | *buffer); // Setup command mode + *buffer = (0x9f & *buffer); // Setup command mode + CS = SELECT; + spi.write(*buffer); + CS = DESELECT; +} // End of directCommand() + +void writeSingle(int *buffer, int length) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// writeSingle() +// Description: Writes to specified reader registers. +// Parameters: *buffer = addresses of the registers followed by the +// contends to write. +// length = number of registers * 2. +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + int i=0; + + CS = SELECT; + while(length > 0) { + *buffer = (0x1f & *buffer); // Register address + for(i = 0; i < 2; i++) { + spi.write(*buffer); + buffer++; + length--; + } // if + } // while + CS = DESELECT; +} // End of writeSingle() + +void readSingle(int *buffer, int number) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// readSingle() +// Description: Reads specified reader chip registers and +// writes register contents to *buffer. +// Parameters: *buffer = addresses of the registers. +// number = number of registers. +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + int temp; + + CS = SELECT; + while(number > 0) { + *buffer = (0x40 | *buffer); // Address, read, single + *buffer = (0x5f & *buffer); // Register address + temp = spi.write(*buffer); + *buffer = spi.write(0x00); + buffer++; + number--; + } // while + CS = DESELECT; +} // End of readSingle() + +void turnRfOn(void) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// turnRfOn() +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + int command[2]; + + command[0] = CHIP_STATUS_CONTROL; + command[1] = CHIP_STATUS_CONTROL; + readSingle(&command[1], 1); + command[1] &= 0x3F; + command[1] |= 0x20; + writeSingle(command, 2); +} // End of turnRfOn() + +void turnRfOff(void) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// turnRfOff() +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + int command[2]; + + command[0] = CHIP_STATUS_CONTROL; + command[1] = CHIP_STATUS_CONTROL; + readSingle(&command[1], 1); + command[1] &= 0x1F; + writeSingle(command, 2); +} // End of turnRfOff() + +void writeIsoControl(int iso_control) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// writeIsoControl() +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + int write[4]; + +// if((iso_control & BIT5) == BIT5) +// { +// return; +// } + + write[0] = ISO_CONTROL; + write[1] = iso_control; +// write[1] &= ~BIT5; + writeSingle(write, 2); + + iso_control &= 0x1F; +} // End of writeIsoControl() + +void resetIrqStatus(void) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// resetIrqStatus() +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + +} + +void iso15693FindTag(void) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// iso15693FindTag() +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + turnRfOn(); + + writeIsoControl(0x02); + + // The VCD should wait at least 1 ms after it activated the + // powering field before sending the first request, to + // ensure that the VICCs are ready to receive it. (ISO15693-3) + wait_ms(6); + +// flags = SIXTEEN_SLOTS; +// flags = ONE_SLOT; + +// buf[20] = 0x00; +// Iso15693Anticollision(&buf[20], 0x00); // Send Inventory request + + turnRfOff(); + + resetIrqStatus(); // Clear any IRQs +} // End of iso15693FindTag() + +void Iso15693Anticollision(int *mask, int length) { +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// Iso15693Anticollision() +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + +} // End of Iso15693Anticollision()