Yann Garcia / FM24Vxx_I2C

Dependents:   FM24Vxx_I2CApp

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FM24Vxx_SN.h Source File

FM24Vxx_SN.h

00001 /* mbed simplified access to RAMTRON FV24xx Serial 3V F-RAM Memory (I2C)
00002  * Copyright (c) 2013 ygarcia, MIT License
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
00005  * and associated documentation files (the "Software"), to deal in the Software without restriction, 
00006  * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
00007  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in all copies or 
00011  * substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
00014  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
00015  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
00016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019 #if !defined(__FM24VXX_SN_H__)
00020 #define __FM24VXX_SN_H__
00021 
00022 #include <mbed.h>
00023 //#include "Debug.h"
00024 
00025 namespace _FM24VXX_I2C {
00026 
00027 /**
00028  * Device ID description
00029  * @remark See FM24V10_ds Figure 14. Manufacturer and Product ID
00030  */
00031 class CFM24VXX_SN {
00032 
00033     /** Serial number description
00034      */
00035     union { // See FM24V10_ds Figure 15. 8-Byte Serial Number (read-only)
00036         unsigned char snumber[8];
00037         struct {
00038             unsigned char crc;
00039             unsigned char un[5];
00040             unsigned char cid[2];
00041         } sn;
00042     } _sn;
00043     
00044     public:
00045         inline CFM24VXX_SN(const unsigned char *pdatas) {
00046 //            for (int i = 0; i < 8; i++) {
00047 //                DEBUG("CFM24VXX_SN::CFM24VXX_SN: byte #%d = 0x%02x", i, *(pdatas + i))
00048 //            }
00049             memcpy((void *)&(_sn.snumber[0]), pdatas, 8 * sizeof(unsigned char));
00050         } // End of Constructor
00051         
00052         inline unsigned short GetCustomerID() const { return _sn.sn.cid[0] << 8 | _sn.sn.cid[1]; };
00053         
00054         inline unsigned char * GetUniqueID() const { return (unsigned char *)&(_sn.sn.un[0]); };
00055         
00056         inline unsigned char GetChecksum() const { return _sn.sn.crc; };
00057         
00058 }; // End of class CFM24VXX_SN
00059 
00060 } // End of namespace _FM24VXX_I2C
00061 
00062 #endif // __FM24VXX_SN_H__