1.1 --- a/pkg/devices/lib/i2c/include/i2c-jz4730.h Tue Feb 16 22:53:31 2021 +0100
1.2 +++ b/pkg/devices/lib/i2c/include/i2c-jz4730.h Wed Feb 17 00:48:47 2021 +0100
1.3 @@ -67,6 +67,12 @@
1.4 unsigned int read(uint8_t address, uint8_t buf[], unsigned int length);
1.5 unsigned int write(uint8_t address, uint8_t buf[], unsigned int length);
1.6
1.7 + // Statistics.
1.8 +
1.9 + unsigned int start_not_possible = 0, read_not_ready = 0, read_not_ready_clear = 0, read_not_ready_stx = 0,
1.10 + read_not_possible = 0, read_nack = 0, read_complete = 0,
1.11 + write_not_possible = 0, write_complete = 0, total_reads = 0;
1.12 +
1.13 protected:
1.14 void set_frequency();
1.15
1.16 @@ -144,4 +150,24 @@
1.17
1.18 unsigned int jz4730_i2c_write(void *i2c_channel, uint8_t address, uint8_t buf[], unsigned int length);
1.19
1.20 +unsigned int jz4730_i2c_start_not_possible(void *i2c_channel);
1.21 +
1.22 +unsigned int jz4730_i2c_read_not_ready(void *i2c_channel);
1.23 +
1.24 +unsigned int jz4730_i2c_read_not_ready_clear(void *i2c_channel);
1.25 +
1.26 +unsigned int jz4730_i2c_read_not_ready_stx(void *i2c_channel);
1.27 +
1.28 +unsigned int jz4730_i2c_read_not_possible(void *i2c_channel);
1.29 +
1.30 +unsigned int jz4730_i2c_read_nack(void *i2c_channel);
1.31 +
1.32 +unsigned int jz4730_i2c_read_complete(void *i2c_channel);
1.33 +
1.34 +unsigned int jz4730_i2c_write_not_possible(void *i2c_channel);
1.35 +
1.36 +unsigned int jz4730_i2c_write_complete(void *i2c_channel);
1.37 +
1.38 +unsigned int jz4730_i2c_total_reads(void *i2c_channel);
1.39 +
1.40 EXTERN_C_END
2.1 --- a/pkg/devices/lib/i2c/src/jz4730.cc Tue Feb 16 22:53:31 2021 +0100
2.2 +++ b/pkg/devices/lib/i2c/src/jz4730.cc Wed Feb 17 00:48:47 2021 +0100
2.3 @@ -139,11 +139,11 @@
2.4 I2c_jz4730_channel::communicate()
2.5 {
2.6 enum I2c_jz4730_state state = I2c_jz4730_pre_start;
2.7 - _limit = 10;
2.8 + _limit = 1;
2.9
2.10 do
2.11 {
2.12 - wait_for_irq(1000);
2.13 + wait_for_irq(100000);
2.14
2.15 switch (state)
2.16 {
2.17 @@ -186,14 +186,17 @@
2.18 if (busy())
2.19 {
2.20 if (!(--_limit))
2.21 + {
2.22 + start_not_possible++;
2.23 return I2c_jz4730_end;
2.24 + }
2.25 else
2.26 return I2c_jz4730_pre_start;
2.27 }
2.28
2.29 // Use a longer time limit in subsequent activities.
2.30
2.31 - _limit = 1000;
2.32 + _limit = 1;
2.33
2.34 // Start, send address, proceed to the operation.
2.35
2.36 @@ -214,7 +217,14 @@
2.37 // Wait again if not ready to read.
2.38
2.39 if (transferring() || (!data_valid() && !nack()))
2.40 + {
2.41 + read_not_ready++;
2.42 + if (transferring())
2.43 + read_not_ready_stx++;
2.44 + else
2.45 + read_not_ready_clear++;
2.46 return I2c_jz4730_start_read;
2.47 + }
2.48
2.49 return I2c_jz4730_perform_read;
2.50 }
2.51 @@ -230,6 +240,7 @@
2.52 {
2.53 if (!(--_limit))
2.54 {
2.55 + read_not_possible++;
2.56 stop();
2.57 return I2c_jz4730_end;
2.58 }
2.59 @@ -241,6 +252,7 @@
2.60
2.61 if (nack())
2.62 {
2.63 + read_nack++;
2.64 stop();
2.65 return I2c_jz4730_end;
2.66 }
2.67 @@ -259,13 +271,14 @@
2.68
2.69 if (_nread >= _length)
2.70 {
2.71 + read_complete++;
2.72 stop();
2.73 return I2c_jz4730_end;
2.74 }
2.75
2.76 // Wait for more data otherwise.
2.77
2.78 - _limit = 1000;
2.79 + _limit = 1;
2.80 return I2c_jz4730_perform_read;
2.81 }
2.82
2.83 @@ -280,6 +293,7 @@
2.84 {
2.85 if (!(--_limit))
2.86 {
2.87 + write_not_possible++;
2.88 stop();
2.89 return I2c_jz4730_end;
2.90 }
2.91 @@ -291,8 +305,9 @@
2.92
2.93 if ((_nwritten >= _length) || nack())
2.94 {
2.95 + write_complete++;
2.96 stop();
2.97 - _limit = 1000;
2.98 + _limit = 1;
2.99 return I2c_jz4730_stop_write;
2.100 }
2.101
2.102 @@ -303,7 +318,7 @@
2.103
2.104 // Wait for the data to be sent.
2.105
2.106 - _limit = 1000;
2.107 + _limit = 1;
2.108 return I2c_jz4730_perform_write;
2.109 }
2.110
2.111 @@ -340,6 +355,7 @@
2.112 _address = address;
2.113 _buf = &buf[0];
2.114 _read = true;
2.115 + total_reads++;
2.116
2.117 communicate();
2.118
2.119 @@ -497,3 +513,33 @@
2.120 {
2.121 return static_cast<I2c_jz4730_channel *>(i2c_channel)->write(address, buf, length);
2.122 }
2.123 +
2.124 +unsigned int jz4730_i2c_start_not_possible(void *i2c_channel)
2.125 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->start_not_possible; }
2.126 +
2.127 +unsigned int jz4730_i2c_read_not_ready(void *i2c_channel)
2.128 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_not_ready; }
2.129 +
2.130 +unsigned int jz4730_i2c_read_not_ready_clear(void *i2c_channel)
2.131 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_not_ready_clear; }
2.132 +
2.133 +unsigned int jz4730_i2c_read_not_ready_stx(void *i2c_channel)
2.134 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_not_ready_stx; }
2.135 +
2.136 +unsigned int jz4730_i2c_read_not_possible(void *i2c_channel)
2.137 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_not_possible; }
2.138 +
2.139 +unsigned int jz4730_i2c_read_nack(void *i2c_channel)
2.140 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_nack; }
2.141 +
2.142 +unsigned int jz4730_i2c_read_complete(void *i2c_channel)
2.143 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_complete; }
2.144 +
2.145 +unsigned int jz4730_i2c_write_not_possible(void *i2c_channel)
2.146 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->write_not_possible; }
2.147 +
2.148 +unsigned int jz4730_i2c_write_complete(void *i2c_channel)
2.149 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->write_complete; }
2.150 +
2.151 +unsigned int jz4730_i2c_total_reads(void *i2c_channel)
2.152 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->total_reads; }
3.1 --- a/pkg/landfall-examples/letux400_i2c/letux400_i2c.cc Tue Feb 16 22:53:31 2021 +0100
3.2 +++ b/pkg/landfall-examples/letux400_i2c/letux400_i2c.cc Wed Feb 17 00:48:47 2021 +0100
3.3 @@ -258,6 +258,22 @@
3.4 sleep(5);
3.5 }
3.6
3.7 + printf("start_not_possible = %d\n"
3.8 + "read_not_ready = %d\n"
3.9 + "read_not_ready_clear = %d\n"
3.10 + "read_not_ready_stx = %d\n"
3.11 + "read_not_possible = %d\n"
3.12 + "read_nack = %d\n"
3.13 + "read_complete = %d\n"
3.14 + "write_not_possible = %d\n"
3.15 + "write_complete = %d\n"
3.16 + "total_reads = %d\n",
3.17 + jz4730_i2c_start_not_possible(i2c0), jz4730_i2c_read_not_ready(i2c0), jz4730_i2c_read_not_ready_clear(i2c0), jz4730_i2c_read_not_ready_stx(i2c0),
3.18 + jz4730_i2c_read_not_possible(i2c0), jz4730_i2c_read_nack(i2c0), jz4730_i2c_read_complete(i2c0),
3.19 + jz4730_i2c_write_not_possible(i2c0), jz4730_i2c_write_complete(i2c0), jz4730_i2c_total_reads(i2c0));
3.20 +
3.21 + sleep(30);
3.22 +
3.23 /* Issue a shutdown request. */
3.24
3.25 buf[0] = 0xd8; buf[1] = 1;