Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion os/arch/arm/src/armino/armino_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,20 @@ int armino_i2c_transfer(struct i2c_dev_s *dev, struct i2c_msg_s *msgs, int msgc)
int ret = OK;
bk_err_t err;
uint8_t i = 0;
uint16_t addr = msgs->addr;
uint16_t addr;
uint32_t timeout_ms = 2000;

/* I2C_TRANSFER() passes dev/msgs through without any check, so the
* callee must validate them. The sibling ops (setaddress/setclock)
* already check dev the same way.
*/
if (priv == NULL || msgs == NULL) {
i2cinfo("i2c dev/msgs is NULL\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We can use error or warning in this case instead of info. @eunwoo-nam Could you guide him which one is proper?
  2. We can find the reason why this function returns ERROR by null priv or by null msgs. Let's print the value of both for easiler debugging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunghan-chang @eunwoo-nam
I'd prefer i2cerr : a NULL dev / msgs is caller misuse and we return ERROR , so error level fits. But this file defines i2cinfo as an empty macro, and i2cerr also requires CONFIG_DEBUG_I2C_ERROR to print, so neither shows by default. Would lowsyslog(LOG_ERR, ...) be acceptable instead?

return ERROR;
}

addr = msgs->addr;

/* Ensure that address or flags don't change meanwhile */
sem_wait(&priv->sem_excl);

Expand Down
7 changes: 7 additions & 0 deletions os/arch/arm/src/armino/armino_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ static int armino_rdtime(FAR struct rtc_lowerhalf_s *lower, FAR struct rtc_time
int ret;

DEBUGASSERT(lower != NULL && rtctime != NULL);
if (lower == NULL || rtctime == NULL) {
Comment on lines 211 to +212

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eunwoo-nam Do we need to keep both line 211 and line 212?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two checks are redundant, and with assertions enabled DEBUGASSERT panics before reaching -EINVAL . armino_settime() (line 255) uses only the if check. Can we drop DEBUGASSERT and keep just the if ?

return -EINVAL;
}
rtc = (FAR struct armino_lowerhalf_s *)lower;
ret = sem_wait(&rtc->devsem);
if (ret < 0) {
Expand Down Expand Up @@ -249,6 +252,10 @@ static int armino_settime(FAR struct rtc_lowerhalf_s *lower, FAR const struct rt
{
struct timespec ts;

if (lower == NULL || rtctime == NULL) {
return -EINVAL;
}

/* Convert the struct rtc_time to a time_t. Here we assume that struct
* rtc_time is cast compatible with struct tm.
*/
Expand Down
22 changes: 20 additions & 2 deletions os/board/bk7239n/src/components/bk_pm/src/services/bk_pm_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define PM_THREAD_PRIORITY (BEKEN_DEFAULT_WORKER_PRIORITY - 3)/* With priority 3 thread, 200ms buffer (20*10ms) is sufficient */

#define PM_UART_RXD_WAKEUP_TIME_MS (2000)
#define PM_POP_ERROR_BACKOFF_MS (10)

/*=====================DEFINE SECTION END=====================*/
/*=====================STRUCT AND ENUM SECTION START==========*/
Expand Down Expand Up @@ -214,7 +215,7 @@ static bk_err_t pm_message_handle(void)
if(ret != BK_OK)
{
LOGE("register rxd_wk_alarm failed\r\n");
return BK_FAIL;
break;
}
} else if (msg.param1 == PM_MODE_NORMAL_SLEEP) {
LOGI("NS GPIO wakeup[reason:%d][id:%d]\r\n", bk_pm_sleep_wakeup_reason_get(), msg.param3);
Expand All @@ -235,6 +236,11 @@ static bk_err_t pm_message_handle(void)
break;
}
}
else
{
/* Never busy-spin if the queue becomes invalid or is destroyed */
rtos_delay_milliseconds(PM_POP_ERROR_BACKOFF_MS);
}
}

return ret;
Expand All @@ -243,6 +249,13 @@ static bk_err_t pm_message_handle(void)
bk_err_t pm_thread_main(void)
{
bk_err_t ret = BK_OK;

if (s_queue != NULL)
{
LOGE("pm thread already initialized\n");
return BK_OK;
}

ret = rtos_init_queue(&s_queue,
"pm_queue",
sizeof(pm_ap_core_msg_t),
Expand All @@ -251,6 +264,8 @@ bk_err_t pm_thread_main(void)
if (ret != BK_OK)
{
LOGE("create pm que fail\n");
s_queue = NULL;
return ret;
}

/* Optimization: Use higher priority (lower number = higher priority)
Expand All @@ -266,6 +281,9 @@ bk_err_t pm_thread_main(void)
if (ret != BK_OK)
{
LOGE("create pm thrd fail\n");
rtos_deinit_queue(&s_queue);
s_queue = NULL;
return ret;
}
return 0;
return BK_OK;
}
23 changes: 20 additions & 3 deletions os/board/bk7239n/src/middleware/driver/rtc/ana_rtc_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static uint32_t s_aon_rtc_clock_freq = AON_RTC_DEFAULT_CLOCK_FREQ;
#endif

#define ANA_RTC_OPS_SAFE_DELAY_US (125)
#define ANA_RTC_TICK_RESET_RETRY_MAX (100000)
static uint64_t s_ana_rtc_base_tick = 0; // use for rtc reset
#if defined(CONFIG_ROSC_COMPENSATION)
static int64_t s_ana_rtc_diff_tick = 0; // use for rtc compesation
Expand Down Expand Up @@ -914,11 +915,27 @@ static void ana_rtc_hw_init(void)

// wait until rtc tick reset ok, will cost about 32us
#if !defined(CONFIG_AON_RTC_KEEP_TIME_SUPPORT)
while (1)
if (s_ana_rtc_base_tick == 0)
{
if (aon_pmu_hal_rtc_tick_l_get() < s_ana_rtc_base_tick)
// base==0 keeps the unsigned comparison below false forever, so
// waiting here would hang the boot sequence. Skip it.
ANA_RTC_LOGW("%s: rtc base tick is 0, skip tick reset wait\r\n", __func__);
}
else
{
// Bounded polling: a stalled 32K clock would also freeze any
// tick-based timeout, so bound the wait by iteration count.
uint32_t retry = ANA_RTC_TICK_RESET_RETRY_MAX;

while ((aon_pmu_hal_rtc_tick_l_get() >= s_ana_rtc_base_tick) && (retry > 0))
{
break;
retry--;
}

if (retry == 0)
{
ANA_RTC_LOGE("%s: wait rtc tick reset timeout, base=0x%llx cur=0x%x\r\n",
__func__, s_ana_rtc_base_tick, aon_pmu_hal_rtc_tick_l_get());
}
}
#endif
Expand Down