Generic driver for the RWD RFID Modules from IB Technology.

Dependents:   RSEDP_DPDemo

Committer:
donatien
Date:
Thu Jul 22 16:24:31 2010 +0000
Revision:
4:0c21bc193afa
Parent:
2:37fafd1e1a20

        

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 4:0c21bc193afa 29 //!Generic driver for the RWD RFID Modules from IB Technology.
donatien 4:0c21bc193afa 30 /*!
donatien 2:37fafd1e1a20 31 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 32 */
donatien 0:a893227b988a 33 class RWDModule
donatien 0:a893227b988a 34 {
donatien 0:a893227b988a 35 public:
donatien 4:0c21bc193afa 36 //!Creates an instance of the class.
donatien 4:0c21bc193afa 37 /*!
donatien 2:37fafd1e1a20 38 Connect module using serial port pins tx, rx and DigitalIn pin cts (clear-to-send).
donatien 2:37fafd1e1a20 39 */
donatien 0:a893227b988a 40 RWDModule(PinName tx, PinName rx, PinName cts);
donatien 2:37fafd1e1a20 41
donatien 4:0c21bc193afa 42 /*!
donatien 2:37fafd1e1a20 43 Destroys instance.
donatien 2:37fafd1e1a20 44 */
donatien 0:a893227b988a 45 virtual ~RWDModule();
donatien 0:a893227b988a 46
donatien 4:0c21bc193afa 47 //!Executes a command.
donatien 4:0c21bc193afa 48 /*!
donatien 2:37fafd1e1a20 49 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 50 This is a non-blocking function, and ready() should be called to check completion.
donatien 2:37fafd1e1a20 51 Please note that the buffers references must remain valid until the command has been executed.
donatien 2:37fafd1e1a20 52 */
donatien 2:37fafd1e1a20 53 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 54
donatien 4:0c21bc193afa 55 //!Ready for a command / response is available.
donatien 4:0c21bc193afa 56 /*!
donatien 2:37fafd1e1a20 57 Returns true if the previous command has been executed and an other command is ready to be sent.
donatien 2:37fafd1e1a20 58 */
donatien 4:0c21bc193afa 59 bool ready();
donatien 0:a893227b988a 60
donatien 4:0c21bc193afa 61 //!Get whether last command was succesful, and complete ack byte if a ptr is provided.
donatien 4:0c21bc193afa 62 /*!
donatien 2:37fafd1e1a20 63 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 64 */
donatien 4:0c21bc193afa 65 bool result(uint8_t* pAck = NULL);
donatien 0:a893227b988a 66
donatien 0:a893227b988a 67 private:
donatien 1:e96aaf4d5c55 68 void intClearToSend(); //Called on interrupt when CTS line falls
donatien 1:e96aaf4d5c55 69 void intTx(); //Called on interrupt when TX buffer is not full anymore (bytes sent)
donatien 1:e96aaf4d5c55 70 void intRx(); //Called on interrrupt when RX buffer is not empty anymore (bytes received)
donatien 0:a893227b988a 71
donatien 0:a893227b988a 72 Serial m_serial;
donatien 0:a893227b988a 73 InterruptIn m_cts;
donatien 0:a893227b988a 74
donatien 2:37fafd1e1a20 75 uint8_t m_cmd;
donatien 2:37fafd1e1a20 76 uint8_t* m_paramsBuf;
donatien 2:37fafd1e1a20 77 uint8_t* m_respBuf;
donatien 2:37fafd1e1a20 78 size_t m_pos;
donatien 2:37fafd1e1a20 79 size_t m_paramsLen;
donatien 2:37fafd1e1a20 80 size_t m_respLen;
donatien 0:a893227b988a 81
donatien 2:37fafd1e1a20 82 uint8_t m_ackOk;
donatien 2:37fafd1e1a20 83 uint8_t m_ackOkMask;
donatien 0:a893227b988a 84
donatien 2:37fafd1e1a20 85 uint8_t m_ack;
donatien 0:a893227b988a 86
donatien 0:a893227b988a 87 enum
donatien 0:a893227b988a 88 {
donatien 0:a893227b988a 89 READY,
donatien 0:a893227b988a 90 CMD_QUEUED,
donatien 0:a893227b988a 91 SENDING_CMD,
donatien 0:a893227b988a 92 WAITING_FOR_ACK,
donatien 0:a893227b988a 93 RECEIVING_ACK
donatien 0:a893227b988a 94 } m_state;
donatien 0:a893227b988a 95
donatien 0:a893227b988a 96 };
donatien 0:a893227b988a 97
donatien 0:a893227b988a 98 #endif