Generic driver for the RWD RFID Modules from IB Technology.

Dependents:   RSEDP_DPDemo

Committer:
donatien
Date:
Tue Jul 13 16:11:29 2010 +0000
Revision:
2:37fafd1e1a20
Parent:
1:e96aaf4d5c55
Child:
4:0c21bc193afa

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 2:37fafd1e1a20 1
donatien 2:37fafd1e1a20 2 /*
donatien 2:37fafd1e1a20 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
donatien 2:37fafd1e1a20 4
donatien 2:37fafd1e1a20 5 Permission is hereby granted, free of charge, to any person obtaining a copy
donatien 2:37fafd1e1a20 6 of this software and associated documentation files (the "Software"), to deal
donatien 2:37fafd1e1a20 7 in the Software without restriction, including without limitation the rights
donatien 2:37fafd1e1a20 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
donatien 2:37fafd1e1a20 9 copies of the Software, and to permit persons to whom the Software is
donatien 2:37fafd1e1a20 10 furnished to do so, subject to the following conditions:
donatien 2:37fafd1e1a20 11
donatien 2:37fafd1e1a20 12 The above copyright notice and this permission notice shall be included in
donatien 2:37fafd1e1a20 13 all copies or substantial portions of the Software.
donatien 2:37fafd1e1a20 14
donatien 2:37fafd1e1a20 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donatien 2:37fafd1e1a20 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donatien 2:37fafd1e1a20 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donatien 2:37fafd1e1a20 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donatien 2:37fafd1e1a20 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 2:37fafd1e1a20 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
donatien 2:37fafd1e1a20 21 THE SOFTWARE.
donatien 2:37fafd1e1a20 22 */
donatien 0:a893227b988a 23
donatien 0:a893227b988a 24 #ifndef RWD_MODULE_H
donatien 0:a893227b988a 25 #define RWD_MODULE_H
donatien 0:a893227b988a 26
donatien 0:a893227b988a 27 #include "mbed.h"
donatien 0:a893227b988a 28
donatien 2:37fafd1e1a20 29 /*
donatien 2:37fafd1e1a20 30 The RWD modules from IB Technology are RFID readers working with different frequencies and protocols but with a common instructions set and pinout.
donatien 2:37fafd1e1a20 31 */
donatien 0:a893227b988a 32 class RWDModule
donatien 0:a893227b988a 33 {
donatien 0:a893227b988a 34 public:
donatien 2:37fafd1e1a20 35 /*
donatien 2:37fafd1e1a20 36 Connect module using serial port pins tx, rx and DigitalIn pin cts (clear-to-send).
donatien 2:37fafd1e1a20 37 */
donatien 0:a893227b988a 38 RWDModule(PinName tx, PinName rx, PinName cts);
donatien 2:37fafd1e1a20 39
donatien 2:37fafd1e1a20 40 /*
donatien 2:37fafd1e1a20 41 Destroys instance.
donatien 2:37fafd1e1a20 42 */
donatien 0:a893227b988a 43 virtual ~RWDModule();
donatien 0:a893227b988a 44
donatien 2:37fafd1e1a20 45
donatien 2:37fafd1e1a20 46 /*
donatien 2:37fafd1e1a20 47 Executes the command cmd on the reader, with parameters set in params buffer of paramsLen length. The acknowledge byte sent back by the reader masked with ackOkMask must be equal to ackOk for the command to be considered a success. If so, the result is stored in buffer resp of length respLen.
donatien 2:37fafd1e1a20 48 This is a non-blocking function, and ready() should be called to check completion.
donatien 2:37fafd1e1a20 49 Please note that the buffers references must remain valid until the command has been executed.
donatien 2:37fafd1e1a20 50 */
donatien 2:37fafd1e1a20 51 void command(uint8_t cmd, const uint8_t* params, int paramsLen, uint8_t* resp, size_t respLen, uint8_t ackOk, size_t ackOkMask); //Ack Byte is not included in the resp buf
donatien 0:a893227b988a 52
donatien 2:37fafd1e1a20 53 /*
donatien 2:37fafd1e1a20 54 Returns true if the previous command has been executed and an other command is ready to be sent.
donatien 2:37fafd1e1a20 55 */
donatien 1:e96aaf4d5c55 56 bool ready(); //Ready for a command / response is available
donatien 0:a893227b988a 57
donatien 2:37fafd1e1a20 58 /*
donatien 2:37fafd1e1a20 59 Returns true if the previous command was successful. If pAck is provided, the actual acknowledge byte returned by the reader is stored in that variable.
donatien 2:37fafd1e1a20 60 */
donatien 2:37fafd1e1a20 61 bool result(uint8_t* pAck = NULL); //Get wether last command was succesful, and complete ack byte if a ptr is provided
donatien 0:a893227b988a 62
donatien 0:a893227b988a 63 private:
donatien 1:e96aaf4d5c55 64 void intClearToSend(); //Called on interrupt when CTS line falls
donatien 1:e96aaf4d5c55 65 void intTx(); //Called on interrupt when TX buffer is not full anymore (bytes sent)
donatien 1:e96aaf4d5c55 66 void intRx(); //Called on interrrupt when RX buffer is not empty anymore (bytes received)
donatien 0:a893227b988a 67
donatien 0:a893227b988a 68 Serial m_serial;
donatien 0:a893227b988a 69 InterruptIn m_cts;
donatien 0:a893227b988a 70
donatien 2:37fafd1e1a20 71 uint8_t m_cmd;
donatien 2:37fafd1e1a20 72 uint8_t* m_paramsBuf;
donatien 2:37fafd1e1a20 73 uint8_t* m_respBuf;
donatien 2:37fafd1e1a20 74 size_t m_pos;
donatien 2:37fafd1e1a20 75 size_t m_paramsLen;
donatien 2:37fafd1e1a20 76 size_t m_respLen;
donatien 0:a893227b988a 77
donatien 2:37fafd1e1a20 78 uint8_t m_ackOk;
donatien 2:37fafd1e1a20 79 uint8_t m_ackOkMask;
donatien 0:a893227b988a 80
donatien 2:37fafd1e1a20 81 uint8_t m_ack;
donatien 0:a893227b988a 82
donatien 0:a893227b988a 83 enum
donatien 0:a893227b988a 84 {
donatien 0:a893227b988a 85 READY,
donatien 0:a893227b988a 86 CMD_QUEUED,
donatien 0:a893227b988a 87 SENDING_CMD,
donatien 0:a893227b988a 88 WAITING_FOR_ACK,
donatien 0:a893227b988a 89 RECEIVING_ACK
donatien 0:a893227b988a 90 } m_state;
donatien 0:a893227b988a 91
donatien 0:a893227b988a 92 };
donatien 0:a893227b988a 93
donatien 0:a893227b988a 94 #endif