基本参考的Android的代码
cmd : loglevel debug
#define LOG_IMPL(...) \
log_print(1, "AOS", COL_DEF, "V", __VA_ARGS__)
/*
* Log at debug level.
*
* @param[in] mod string description of module.
* @param[in] fmt same as printf() usage.
*/
#define LOGD(mod, ...) LOGD_IMPL(mod, __VA_ARGS__)
/*
* Log at the level set by aos_set_log_level().
*
* @param[in] fmt same as printf() usage.
*/
#define LOG(...) LOG_IMPL(__VA_ARGS__)
__attribute__((weak)) int csp_printf(const char *fmt, ...)
{
va_list args;
int ret;
ret = aos_mutex_lock(&log_mutex, AOS_WAIT_FOREVER);
if (ret == 0) {
va_start(args, fmt);
ret = vprintf(fmt, args);
va_end(args);
fflush(stdout);
}
aos_mutex_unlock(&log_mutex);
return ret;
}
对于aos_mutex_lock 调用krhino_mutex_lock,
不能在中断中调用
kstat_t krhino_mutex_lock(kmutex_t *mutex, tick_t ticks)
{
CPSR_ALLOC();
kstat_t ret;
ktask_t *mutex_task;
uint8_t cur_cpu_num;
NULL_PARA_CHK(mutex);
if (g_sys_stat == RHINO_STOPPED) {
return RHINO_SUCCESS;
}
RHINO_CRITICAL_ENTER();
INTRPT_NESTED_LEVEL_CHK();
if (mutex->blk_obj.obj_type != RHINO_MUTEX_OBJ_TYPE) {
RHINO_CRITICAL_EXIT();
return RHINO_KOBJ_TYPE_ERR;
}
...
RHINO_NOT_CALLED_BY_INTRPT = 1000u,
#define INTRPT_NESTED_LEVEL_CHK() \
do { \
if (g_intrpt_nested_level[cpu_cur_get()] > 0u) { \
RHINO_CRITICAL_EXIT(); \
return RHINO_NOT_CALLED_BY_INTRPT; \
} \
} while (0)
网友评论