+static inline void inline_write_16(unsigned int address, unsigned int data) {
+ *(gpio + 0) = GPFSEL0_OUTPUT;
+ *(gpio + 1) = GPFSEL1_OUTPUT;
+ *(gpio + 2) = GPFSEL2_OUTPUT;
+
+ *(gpio + 7) = ((data & 0xffff) << 8) | (REG_DATA << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((address & 0xffff) << 8) | (REG_ADDR_LO << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((0x0000 | (address >> 16)) << 8) | (REG_ADDR_HI << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 0) = GPFSEL0_INPUT;
+ *(gpio + 1) = GPFSEL1_INPUT;
+ *(gpio + 2) = GPFSEL2_INPUT;
+
+ while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS))
+ ;
+}
+
+static inline void inline_write_8(unsigned int address, unsigned int data) {
+ if ((address & 1) == 0)
+ data = data + (data << 8); // EVEN, A0=0,UDS
+ else
+ data = data & 0xff; // ODD , A0=1,LDS
+
+ *(gpio + 0) = GPFSEL0_OUTPUT;
+ *(gpio + 1) = GPFSEL1_OUTPUT;
+ *(gpio + 2) = GPFSEL2_OUTPUT;
+
+ *(gpio + 7) = ((data & 0xffff) << 8) | (REG_DATA << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((address & 0xffff) << 8) | (REG_ADDR_LO << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((0x0100 | (address >> 16)) << 8) | (REG_ADDR_HI << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 0) = GPFSEL0_INPUT;
+ *(gpio + 1) = GPFSEL1_INPUT;
+ *(gpio + 2) = GPFSEL2_INPUT;
+
+ while (*(gpio + 13) & (1 << PIN_TXN_IN_PROGRESS))
+ ;
+}
+
+static inline void inline_write_32(unsigned int address, unsigned int value) {
+ inline_write_16(address, value >> 16);
+ inline_write_16(address + 2, value);
+}
+
+static inline unsigned int inline_read_16(unsigned int address) {
+ *(gpio + 0) = GPFSEL0_OUTPUT;
+ *(gpio + 1) = GPFSEL1_OUTPUT;
+ *(gpio + 2) = GPFSEL2_OUTPUT;
+
+ *(gpio + 7) = ((address & 0xffff) << 8) | (REG_ADDR_LO << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((0x0200 | (address >> 16)) << 8) | (REG_ADDR_HI << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 0) = GPFSEL0_INPUT;
+ *(gpio + 1) = GPFSEL1_INPUT;
+ *(gpio + 2) = GPFSEL2_INPUT;
+
+ *(gpio + 7) = (REG_DATA << PIN_A0);
+ *(gpio + 7) = 1 << PIN_RD;
+
+ unsigned int value = *(gpio + 13);
+ while ((value=*(gpio + 13)) & (1 << PIN_TXN_IN_PROGRESS))
+ ;
+
+ *(gpio + 10) = 0xffffec;
+
+ return (value >> 8) & 0xffff;
+}
+
+static inline unsigned int inline_read_8(unsigned int address) {
+ *(gpio + 0) = GPFSEL0_OUTPUT;
+ *(gpio + 1) = GPFSEL1_OUTPUT;
+ *(gpio + 2) = GPFSEL2_OUTPUT;
+
+ *(gpio + 7) = ((address & 0xffff) << 8) | (REG_ADDR_LO << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 7) = ((0x0300 | (address >> 16)) << 8) | (REG_ADDR_HI << PIN_A0);
+ *(gpio + 7) = 1 << PIN_WR;
+ *(gpio + 10) = 1 << PIN_WR;
+ *(gpio + 10) = 0xffffec;
+
+ *(gpio + 0) = GPFSEL0_INPUT;
+ *(gpio + 1) = GPFSEL1_INPUT;
+ *(gpio + 2) = GPFSEL2_INPUT;
+
+ *(gpio + 7) = (REG_DATA << PIN_A0);
+ *(gpio + 7) = 1 << PIN_RD;
+
+ unsigned int value = *(gpio + 13);
+ while ((value=*(gpio + 13)) & (1 << PIN_TXN_IN_PROGRESS))
+ ;
+
+ *(gpio + 10) = 0xffffec;
+
+ value = (value >> 8) & 0xffff;
+
+ if ((address & 1) == 0)
+ return (value >> 8) & 0xff; // EVEN, A0=0,UDS
+ else
+ return value & 0xff; // ODD , A0=1,LDS
+}
+
+static inline unsigned int inline_read_32(unsigned int address) {
+ unsigned int a = inline_read_16(address);
+ unsigned int b = inline_read_16(address + 2);
+ return (a << 16) | b;
+}
+