1818
1919#include "../drv/gpio/gpio_ev3.h"
2020
21+ #include <pbdrv/compiler.h>
2122#include <pbdrv/gpio.h>
2223#include <pbio/error.h>
2324#include <pbio/os.h>
@@ -76,8 +77,14 @@ static inline void delaydelay() {
7677 for (int i = 0 ; i < 100 ; i ++ ) __asm__ volatile ("" );
7778}
7879
80+ extern void panic_puts (const char * c );
81+ extern void panic_putu8 (uint8_t x );
82+
83+ uint8_t i2c_wip_buf [16 ];
84+
7985pbio_error_t ev3_i2c_wip_process_thread (pbio_os_state_t * state , void * context ) {
8086 static pbio_os_timer_t timer ;
87+ static int i ;
8188 // static int bit;
8289 // static uint8_t byte;
8390
@@ -88,33 +95,52 @@ pbio_error_t ev3_i2c_wip_process_thread(pbio_os_state_t *state, void *context) {
8895 pbdrv_gpio_out_low (& test_sda );
8996 pbdrv_gpio_input (& test_sda );
9097
91- PBIO_OS_AWAIT_MS (state , & timer , 1000 );
92- * (volatile uint8_t * )(0x80010004 ) = 0xaa ;
98+ PBIO_OS_AWAIT_MS (state , & timer , 100 );
99+ i2c_wip_buf [0 ] = 0x10 ;
100+ pbdrv_compiler_memory_barrier ();
101+ * (volatile uint32_t * )(0x80010008 ) = (uint32_t )i2c_wip_buf ;
102+ * (volatile uint32_t * )(0x80010004 ) = 0x010601aa ;
93103
94- PBIO_OS_AWAIT_UNTIL (state , * (volatile uint8_t * )(0x80010004 ) == 0x55 );
104+ pbio_os_timer_set (& timer , 1000 );
105+ PBIO_OS_AWAIT_UNTIL (state , * (volatile uint8_t * )(0x80010004 ) == 0x55 || pbio_os_timer_is_expired (& timer ));
95106 debug_pr ("i2c test done\r\n" );
96- debug_pr ("i2c ack 0: %d \r\n" , * (volatile uint8_t * )(0x80010004 + 1 ));
97- debug_pr ("i2c ack 1: %d\r\n" , * (volatile uint8_t * )(0x80010004 + 2 ));
107+ debug_pr ("i2c flags %08x \r\n" , * (volatile uint32_t * )(0x80010004 ));
108+ debug_pr ("i2c delays %d\r\n" , * (volatile uint32_t * )(0x8001000c ));
98109
99- uint32_t x ;
100- x = * (volatile uint32_t * )(0x80010014 + 0 );
101- debug_pr ("i2c debug time %d\r\n" , x );
102- x = * (volatile uint32_t * )(0x80010014 + 4 );
103- debug_pr ("i2c debug 0 clk%d dat%d\r\n" , !!(x & (1 << 12 )), !!(x & (1 << (14 + 16 ))));
104- x = * (volatile uint32_t * )(0x80010014 + 8 );
105- debug_pr ("i2c debug 1 clk%d dat%d\r\n" , !!(x & (1 << 12 )), !!(x & (1 << (14 + 16 ))));
110+ PBIO_OS_AWAIT_MS (state , & timer , 100 );
106111
107- debug_pr ("i2c ack 2: %d\r\n" , * (volatile uint8_t * )(0x80010004 + 3 ));
112+ for (i = 0 ; i < 512 ; i ++ ) {
113+ panic_putu8 (* (volatile uint8_t * )(0x01C32000 + i ));
114+ if (i % 16 == 15 ) {
115+ panic_puts ("\r\n" );
116+ }
117+ }
118+ // debug_pr("i2c ack 0: %d\r\n", *(volatile uint8_t *)(0x80010004 + 1));
119+ // debug_pr("i2c ack 1: %d\r\n", *(volatile uint8_t *)(0x80010004 + 2));
108120
109- debug_pr ("i2c get 0: %02x\r\n" , * (volatile uint8_t * )(0x80010004 + 4 ));
110- debug_pr ("i2c get 1: %02x\r\n" , * (volatile uint8_t * )(0x80010004 + 5 ));
121+ // uint32_t x;
122+ // x = *(volatile uint32_t *)(0x80010014 + 0);
123+ // debug_pr("i2c debug time %d\r\n", x);
124+ // x = *(volatile uint32_t *)(0x80010014 + 4);
125+ // debug_pr("i2c debug 0 clk%d dat%d\r\n", !!(x & (1 << 12)), !!(x & (1 << (14 + 16))));
126+ // x = *(volatile uint32_t *)(0x80010014 + 8);
127+ // debug_pr("i2c debug 1 clk%d dat%d\r\n", !!(x & (1 << 12)), !!(x & (1 << (14 + 16))));
128+
129+ // debug_pr("i2c ack 2: %d\r\n", *(volatile uint8_t *)(0x80010004 + 3));
130+
131+ // debug_pr("i2c get 0: %02x\r\n", *(volatile uint8_t *)(0x80010004 + 4));
132+ // debug_pr("i2c get 1: %02x\r\n", *(volatile uint8_t *)(0x80010004 + 5));
111133
112134 debug_pr ("i2c test end C%d D%d\r\n" , pbdrv_gpio_input (& test_scl ), pbdrv_gpio_input (& test_sda ));
113135
114136 PBIO_OS_AWAIT_MS (state , & timer , 100 );
115137
116138 debug_pr ("i2c test end 2 C%d D%d\r\n" , pbdrv_gpio_input (& test_scl ), pbdrv_gpio_input (& test_sda ));
117139
140+ for (i = 0 ; i < 6 ; i ++ ) {
141+ debug_pr ("i2c get %02x\r\n" , i2c_wip_buf [1 + i ]);
142+ }
143+
118144 PBIO_OS_ASYNC_END (PBIO_SUCCESS );
119145}
120146
0 commit comments