1.1 --- a/pkg/devices/lib/i2c/src/jz4730.cc Tue Feb 16 22:53:31 2021 +0100
1.2 +++ b/pkg/devices/lib/i2c/src/jz4730.cc Wed Feb 17 00:48:47 2021 +0100
1.3 @@ -139,11 +139,11 @@
1.4 I2c_jz4730_channel::communicate()
1.5 {
1.6 enum I2c_jz4730_state state = I2c_jz4730_pre_start;
1.7 - _limit = 10;
1.8 + _limit = 1;
1.9
1.10 do
1.11 {
1.12 - wait_for_irq(1000);
1.13 + wait_for_irq(100000);
1.14
1.15 switch (state)
1.16 {
1.17 @@ -186,14 +186,17 @@
1.18 if (busy())
1.19 {
1.20 if (!(--_limit))
1.21 + {
1.22 + start_not_possible++;
1.23 return I2c_jz4730_end;
1.24 + }
1.25 else
1.26 return I2c_jz4730_pre_start;
1.27 }
1.28
1.29 // Use a longer time limit in subsequent activities.
1.30
1.31 - _limit = 1000;
1.32 + _limit = 1;
1.33
1.34 // Start, send address, proceed to the operation.
1.35
1.36 @@ -214,7 +217,14 @@
1.37 // Wait again if not ready to read.
1.38
1.39 if (transferring() || (!data_valid() && !nack()))
1.40 + {
1.41 + read_not_ready++;
1.42 + if (transferring())
1.43 + read_not_ready_stx++;
1.44 + else
1.45 + read_not_ready_clear++;
1.46 return I2c_jz4730_start_read;
1.47 + }
1.48
1.49 return I2c_jz4730_perform_read;
1.50 }
1.51 @@ -230,6 +240,7 @@
1.52 {
1.53 if (!(--_limit))
1.54 {
1.55 + read_not_possible++;
1.56 stop();
1.57 return I2c_jz4730_end;
1.58 }
1.59 @@ -241,6 +252,7 @@
1.60
1.61 if (nack())
1.62 {
1.63 + read_nack++;
1.64 stop();
1.65 return I2c_jz4730_end;
1.66 }
1.67 @@ -259,13 +271,14 @@
1.68
1.69 if (_nread >= _length)
1.70 {
1.71 + read_complete++;
1.72 stop();
1.73 return I2c_jz4730_end;
1.74 }
1.75
1.76 // Wait for more data otherwise.
1.77
1.78 - _limit = 1000;
1.79 + _limit = 1;
1.80 return I2c_jz4730_perform_read;
1.81 }
1.82
1.83 @@ -280,6 +293,7 @@
1.84 {
1.85 if (!(--_limit))
1.86 {
1.87 + write_not_possible++;
1.88 stop();
1.89 return I2c_jz4730_end;
1.90 }
1.91 @@ -291,8 +305,9 @@
1.92
1.93 if ((_nwritten >= _length) || nack())
1.94 {
1.95 + write_complete++;
1.96 stop();
1.97 - _limit = 1000;
1.98 + _limit = 1;
1.99 return I2c_jz4730_stop_write;
1.100 }
1.101
1.102 @@ -303,7 +318,7 @@
1.103
1.104 // Wait for the data to be sent.
1.105
1.106 - _limit = 1000;
1.107 + _limit = 1;
1.108 return I2c_jz4730_perform_write;
1.109 }
1.110
1.111 @@ -340,6 +355,7 @@
1.112 _address = address;
1.113 _buf = &buf[0];
1.114 _read = true;
1.115 + total_reads++;
1.116
1.117 communicate();
1.118
1.119 @@ -497,3 +513,33 @@
1.120 {
1.121 return static_cast<I2c_jz4730_channel *>(i2c_channel)->write(address, buf, length);
1.122 }
1.123 +
1.124 +unsigned int jz4730_i2c_start_not_possible(void *i2c_channel)
1.125 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->start_not_possible; }
1.126 +
1.127 +unsigned int jz4730_i2c_read_not_ready(void *i2c_channel)
1.128 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_not_ready; }
1.129 +
1.130 +unsigned int jz4730_i2c_read_not_ready_clear(void *i2c_channel)
1.131 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_not_ready_clear; }
1.132 +
1.133 +unsigned int jz4730_i2c_read_not_ready_stx(void *i2c_channel)
1.134 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_not_ready_stx; }
1.135 +
1.136 +unsigned int jz4730_i2c_read_not_possible(void *i2c_channel)
1.137 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_not_possible; }
1.138 +
1.139 +unsigned int jz4730_i2c_read_nack(void *i2c_channel)
1.140 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_nack; }
1.141 +
1.142 +unsigned int jz4730_i2c_read_complete(void *i2c_channel)
1.143 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->read_complete; }
1.144 +
1.145 +unsigned int jz4730_i2c_write_not_possible(void *i2c_channel)
1.146 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->write_not_possible; }
1.147 +
1.148 +unsigned int jz4730_i2c_write_complete(void *i2c_channel)
1.149 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->write_complete; }
1.150 +
1.151 +unsigned int jz4730_i2c_total_reads(void *i2c_channel)
1.152 +{ return reinterpret_cast<I2c_jz4730_channel *>(i2c_channel)->total_reads; }