#include <st25_i2c.hpp>
+#define TW_US 5000
+
enum DYNAMIC_REGISTERS
{
GPO_CTRL_DYN= 0x2000,
=> dynamic configuration => register 0x2000-0x2007
=> FTM mailbox => register 0x2008-0x2107 */
if(ioctl(fd_,I2C_SLAVE,i2cAdd_ >> 1) < 0) throw I2cAddressError(errno);
-
}
St25I2c::~St25I2c(void)
if((c=::write(fd_,buffer,count+sizeof addr)) < 0) throw WriteError(errno);
delete[] buffer;
+ /* Tw*pages */
+ int writeTime=TW_US*(count+3+addr%4)/4;
+ usleep(writeTime);
+
if((addr < DYNAMIC_CONFIG) || (addr == FTM_MAILBOX)) setFtm(savedFtm);
return c-sizeof addr;
--- /dev/null
+TARGET=st25_i2c_write
+SRCS=$(TARGET).cpp
+
+FLAGS=-O2 -Wall -g -MMD
+INCLUDE=-I../include
+LIBDIR=-L../lib
+LIBS=-lst25_i2c
+
+CC=$(CROSS_COMPILE)g++
+CFLAGS=$(FLAGS) $(INCLUDE)
+LDFLAGS=$(LIBDIR) $(LIBS) -MMD
+
+all: $(TARGET)
+
+$(TARGET): $(SRCS:.cpp=.o)
+ $(CC) -o $@ $^ $(LDFLAGS)
+
+%.o: %.cpp
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+-include $(SRCS:.cpp=.d)
+
+clean:
+ rm -f *~ *.bak *.o *.d
+
+distclean: clean
+ rm -f $(TARGET)
--- /dev/null
+/*
+
+ Copyright (c) 2018 Walter Fetter Lages <w.fetter@ieee.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*/
+
+#include <stdlib.h>
+
+#include <iomanip>
+#include <iostream>
+
+#include <st25_i2c.hpp>
+
+int main(int argc,char *argv[])
+{
+ if(argc < 3 || argc > 256+2)
+ {
+ std::cout << argv[0]
+ << "Write to ST25 user memory, dynamic configuration registers or FTM mailbox."
+ << std::endl;
+ std::cout << "\tUsage: " << argv[0] << " address data0 [.. [data255]]" << std::endl;
+ return -1;
+ }
+
+ uint16_t addr=strtol(argv[1],NULL,0);
+ size_t count=argc-2;
+
+ char *data=new char[count];
+ for(size_t i=0;i < count;i++) data[i]=strtol(argv[i+2],NULL,0);
+
+ try
+ {
+ St25I2c st25I2c;
+ st25I2c.write(addr,data,count);
+ }
+ catch(std::exception &e)
+ {
+ std::cerr << e.what() << std::endl;
+ const St25I2c::Error *err=dynamic_cast<St25I2c::Error *>(&e);
+ return (err==NULL)? -1:err->code();
+ }
+
+ delete[] data;
+
+ return 0;
+}