Skip to content

Commit 9e277b8

Browse files
committed
[ISSUE-32] using DPORT UART FIFO register for uart fifo read operation.
1 parent da8ca90 commit 9e277b8

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

examples/0ledctrl/ledctrl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const uint64_t gu64tckSchedulePeriod = (CLK_FREQ_HZ / SCHEDULE_FREQ_HZ);
3838

3939
// ==================== Local Data ================
4040
static UART_Type *gpsUART0 = &gsUART0;
41+
static UART_Type *gpsUART0M = &gsUART0Mapped;
4142

4243
// Implementation
4344

@@ -55,7 +56,7 @@ static void _ledctrl_cycle(uint64_t u64Ticks) {
5556

5657
if (u64NextTick <= u64Ticks) {
5758
while (0 < (gpsUART0->STATUS & 0xff)) {
58-
char cCtrl = gpsUART0->FIFO & 0xff;
59+
char cCtrl = gpsUART0M->FIFO & 0xff;
5960
switch (cCtrl) {
6061
case 'y':
6162
gpio_reg_setbit(&gsGPIO.OUT_W1TS, LED1_GPIO);

examples/3prog1/prog.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
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);
122123
static void _bme280_cycle(uint64_t u64Ticks);
123124
static void _log_cycle(uint64_t u64Ticks);
124125
static void _inc_cycle(uint64_t u64Ticks);
126+
static void _uartctrl_cycle(uint64_t u64Ticks);
125127

126128
// =================== Global constants ================
127129
const bool gbStartAppCpu = START_APP_CPU;
@@ -134,6 +136,7 @@ static const char message_sfx[] = " ms\r\n";
134136
static const char acLedPhase[] = "*O";
135137

136138
static UART_Type *gpsUART0 = &gsUART0;
139+
static UART_Type *gpsUART0M = &gsUART0Mapped; // for FIFO read
137140
static volatile bool gbLedState = false;
138141
static volatile EDisplayState geOledState = DISPLAY_INIT;
139142
static 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+
591596
static 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

Comments
 (0)