4242#define INC_PERIOD_MS 1900U
4343#define I2CSCAN_PERIOD_MS 8600U
4444#define ALARM_PERIOD_MS 4500U
45+ #define UARTCTRL_PERIOD_MS 503U
4546
4647#define BH1750_RETRY_WAIT_HMS 10U
4748
@@ -122,6 +123,7 @@ static void _bme280_print_result(const SBme280TPH *psRes, uint32_t u32TFine);
122123static void _bme280_cycle (uint64_t u64Ticks );
123124static void _log_cycle (uint64_t u64Ticks );
124125static void _inc_cycle (uint64_t u64Ticks );
126+ static void _uartctrl_cycle (uint64_t u64Ticks );
125127
126128// =================== Global constants ================
127129const bool gbStartAppCpu = START_APP_CPU ;
@@ -134,6 +136,7 @@ static const char message_sfx[] = " ms\r\n";
134136static const char acLedPhase [] = "*O" ;
135137
136138static UART_Type * gpsUART0 = & gsUART0 ;
139+ static UART_Type * gpsUART0M = & gsUART0Mapped ; // for FIFO read
137140static volatile bool gbLedState = false;
138141static volatile EDisplayState geOledState = DISPLAY_INIT ;
139142static volatile uint64_t gu64tckAlarmCur = 0 ;
@@ -192,24 +195,6 @@ static void _flush_message(uint64_t u64tckTimestamp) {
192195 * (buf_e ++ ) = ' ' ;
193196 buf_e = print_dec (buf_e , gau32IncVal [i ]);
194197 }
195- if (false) {
196- * (buf_e ++ ) = ' ' ;
197- buf_e = print_hex32 (buf_e , gpio_regs ()-> FUNC_OUT_SEL_CFG [I2C0_SCL_GPIO ]);
198- * (buf_e ++ ) = ' ' ;
199- buf_e = print_hex32 (buf_e , gpio_regs ()-> FUNC_OUT_SEL_CFG [I2C0_SDA_GPIO ]);
200- * (buf_e ++ ) = ' ' ;
201- buf_e = print_hex32 (buf_e , i2c_regs (I2C0 )-> SR );
202- * (buf_e ++ ) = ' ' ;
203- buf_e = print_hex32 (buf_e , i2c_regs (I2C0 )-> FIFO_CONF );
204- * (buf_e ++ ) = ' ' ;
205- buf_e = print_hex32 (buf_e , i2c_regs (I2C0 )-> INT_RAW );
206- * (buf_e ++ ) = ' ' ;
207- buf_e = print_hex32 (buf_e , i2c_regs (I2C0 )-> INT_ST );
208- * (buf_e ++ ) = ' ' ;
209- buf_e = print_hex8 (buf_e , u8Phase & 0x0f );
210- * (buf_e ++ ) = ':' ;
211- buf_e = print_hex32 (buf_e , i2c_regs (I2C0 )-> COMD [u8Phase & 0x0f ]);
212- }
213198 } else {
214199 // some internal call causes WDT
215200 snprintf (buf , LOG_BUFLEN , "%s%" PRIu64 "%s" , message_pfx , u64tckTimestamp , message_sfx );
@@ -588,6 +573,26 @@ static void _i2cscan_cycle(uint64_t u64Ticks) {
588573 }
589574}
590575
576+ static void _uartctrl_cycle (uint64_t u64Ticks ) {
577+ static uint64_t u64NextTick = 0 ;
578+
579+ if (u64NextTick <= u64Ticks ) {
580+ while (0 < (gpsUART0 -> STATUS & 0xff )) {
581+ uint32_t u32msNow = u64Ticks / TICKS_PER_MS ;
582+ char cCtrl = gpsUART0M -> FIFO & 0xff ;
583+ switch (cCtrl ) {
584+ case 'i' : // I2C status
585+ uart_printf (gpsUART0 , "[%d] GPIO_FUNC_OUT: %08X %08X" , u32msNow , gpio_regs ()-> FUNC_OUT_SEL_CFG [I2C0_SCL_GPIO ], gpio_regs ()-> FUNC_OUT_SEL_CFG [I2C0_SDA_GPIO ]);
586+ uart_printf (gpsUART0 , "\tI2C Regs: %08X %08X %08X %08X\r\n" , i2c_regs (I2C0 )-> SR , i2c_regs (I2C0 )-> FIFO_CONF , i2c_regs (I2C0 )-> INT_RAW , i2c_regs (I2C0 )-> INT_ST );
587+ break ;
588+ default :
589+ uart_printf (gpsUART0 , "[%d] `%c' command not recognized\r\n" , u32msNow , cCtrl );
590+ }
591+ }
592+ u64NextTick += MS2TICKS (UARTCTRL_PERIOD_MS );
593+ }
594+ }
595+
591596static void _schedule_isr () {
592597 gsPCbDesc .eCpu = xt_utils_get_core_id () ? CPU_APP : CPU_PRO ;
593598 timg_callback_at (gsPCbDesc .u64tckAlarmCur , gsPCbDesc .eCpu , gsPCbDesc .sTimer , gsPCbDesc .u8Int , & _timer_isr , (void * ) & gsPCbDesc );
@@ -624,4 +629,5 @@ void prog_cycle_pro(uint64_t u64tckNow) {
624629 _i2cscan_cycle (u64tckNow );
625630 _bh1750_cycle (u64tckNow );
626631 _bme280_cycle (u64tckNow );
632+ _uartctrl_cycle (u64tckNow );
627633}
0 commit comments