@@ -48,6 +48,13 @@ static inline void update_pwm(uint8_t val, uint8_t time_now, uint32_t gpio_bit)
4848#define SENSOR_PORT_4_PIN_SCL 1
4949#define SENSOR_PORT_4_PIN_SDA (15 + 16)
5050
51+ // I2C event definition. This currently is set up by the SUART code
52+ // and is thus defined to coexist with it.
53+ #define SENSOR_PORT_1_IRQ_EVT 42
54+ #define SENSOR_PORT_2_IRQ_EVT 44
55+ #define SENSOR_PORT_3_IRQ_EVT 46
56+ #define SENSOR_PORT_4_IRQ_EVT 48
57+
5158// This timeout specifies the *total permissible delay* of an I2C transaction.
5259// This is the permissible sum total of all clock stretching as well as
5360// the initial wait for the bus to become free. Time spent actually transferring
@@ -163,6 +170,10 @@ typedef struct i2c_state_struct {
163170 // Bit index of the IO pins in GPIO bank 0/1
164171 uint8_t scl_bit ;
165172 uint8_t sda_bit ;
173+
174+ // Event to trigger to inform the ARM of completion
175+ // (has bit5 already set)
176+ uint8_t intr_event ;
166177} i2c_state_struct ;
167178i2c_state_struct i2c_states [PBDRV_RPROC_EV3_PRU1_NUM_I2C_CHANNELS ];
168179
@@ -382,6 +393,7 @@ static void handle_i2c(volatile pbdrv_rproc_ev3_pru1_i2c_command_t *cmd, i2c_sta
382393 0 ,
383394 PBDRV_RPROC_EV3_PRU1_I2C_STAT_DONE | PBDRV_RPROC_EV3_PRU1_I2C_STAT_OK
384395 );
396+ __R31 = i2c -> intr_event ;
385397 }
386398 }
387399 break ;
@@ -492,6 +504,7 @@ static void handle_i2c(volatile pbdrv_rproc_ev3_pru1_i2c_command_t *cmd, i2c_sta
492504 PBDRV_RPROC_EV3_PRU1_I2C_STAT_DONE | PBDRV_RPROC_EV3_PRU1_I2C_STAT_NAK
493505 );
494506 state = I2C_STATE_IDLE ;
507+ __R31 = i2c -> intr_event ;
495508 }
496509
497510 if (0 ) {
@@ -505,6 +518,7 @@ static void handle_i2c(volatile pbdrv_rproc_ev3_pru1_i2c_command_t *cmd, i2c_sta
505518 PBDRV_RPROC_EV3_PRU1_I2C_STAT_DONE | PBDRV_RPROC_EV3_PRU1_I2C_STAT_TIMEOUT
506519 );
507520 state = I2C_STATE_IDLE ;
521+ __R31 = i2c -> intr_event ;
508522 }
509523 }
510524
@@ -521,12 +535,16 @@ void main() {
521535 // We initialize this in code to avoid having to copy a data ram binary
522536 i2c_states [0 ].scl_bit = SENSOR_PORT_1_PIN_SCL ;
523537 i2c_states [0 ].sda_bit = SENSOR_PORT_1_PIN_SDA ;
538+ i2c_states [0 ].intr_event = SENSOR_PORT_1_IRQ_EVT ;
524539 i2c_states [1 ].scl_bit = SENSOR_PORT_2_PIN_SCL ;
525540 i2c_states [1 ].sda_bit = SENSOR_PORT_2_PIN_SDA ;
541+ i2c_states [1 ].intr_event = SENSOR_PORT_2_IRQ_EVT ;
526542 i2c_states [2 ].scl_bit = SENSOR_PORT_3_PIN_SCL ;
527543 i2c_states [2 ].sda_bit = SENSOR_PORT_3_PIN_SDA ;
544+ i2c_states [2 ].intr_event = SENSOR_PORT_3_IRQ_EVT ;
528545 i2c_states [3 ].scl_bit = SENSOR_PORT_4_PIN_SCL ;
529546 i2c_states [3 ].sda_bit = SENSOR_PORT_4_PIN_SDA ;
547+ i2c_states [3 ].intr_event = SENSOR_PORT_4_IRQ_EVT ;
530548
531549 while (1 ) {
532550 // 24 MHz / 256 ==> 93.75 kHz tick rate for this counter
0 commit comments