Skip to content

Commit

Permalink
Put the trace API into AtOS interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
At-EC committed Mar 20, 2024
1 parent 520d446 commit 466bf64
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/remote_build/native_gcc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(void)
}

/* At_RTOS kernal running starts */
AtOS.at_rtos_run();
AtOS.kernal_run();
D_ASSERT(0);

while(1) {};
Expand Down
6 changes: 3 additions & 3 deletions build_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
extern "C" {
#endif

#define ATOS_BUILD_TIME "2024-03-19,13:50"
#define ATOS_COMMIT_HEAD_ID "9448ad094554b116852766d85667479349978042"
#define ATOS_BUILD_TIME "2024-03-20,11:42"
#define ATOS_COMMIT_HEAD_ID "2473e49870fbf1d073cb4dc23a50e156472c63d3"
#define ATOS_VERSION_MAJOR_NUMBER (1u)
#define ATOS_VERSION_MINOR_NUMBER (2u)
#define ATOS_VERSION_PATCH_NUMBER (8u)
#define ATOS_VERSION_PATCH_NUMBER (9u)

#define ATOS_VERSION_MAJOR_NUMBER_MASK (0x03FFu)
#define ATOS_VERSION_MAJOR_NUMBER_POS (22u)
Expand Down
78 changes: 59 additions & 19 deletions include/kernal/at_rtos.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,40 @@ static inline b_t os_id_is_invalid(struct os_id id)
return (b_t)_impl_kernal_os_id_is_invalid(id);
}

/**
* @brief Get the current running thread id.
*
* @return The id of current running thread.
**
* demo usage:
*
* os_thread_id_t current = os_id_current_thread();
* printf("At-RTOS kernal current running thread is %s\n", current.pName);
* ...
*/
static inline os_thread_id_t os_id_current_thread(void)
{
os_thread_id_t id = {0u};
id.val = _impl_kernal_thread_runIdGet();
id.number = _impl_thread_os_id_to_number(id.val);
id.pName = _impl_thread_name_get(id.val);

return id;
}

/**
* @brief The kernal OS start to run.
**
* demo usage:
*
* os_kernal_run();
* // Doesn't arrive
*/
static inline u32p_t os_kernal_run(void)
{
return _impl_kernal_at_rtos_run();
}

/**
* @brief To check if the kernal OS is running.
*
Expand All @@ -679,37 +713,39 @@ static inline b_t os_kernal_is_running(void)
}

/**
* @brief Get the current running thread id.
*
* @return The id of current running thread.
* @brief Print At-RTOS firmware information.
**
* demo usage:
*
* os_thread_id_t current = os_id_current_thread();
* printf("At-RTOS kernal current running thread is %s\n", current.pName);
* ...
* os_trace_firmware_print();
*/
static inline os_thread_id_t os_id_current_thread(void)
static inline void os_trace_firmware_print(void)
{
os_thread_id_t id = {0u};
id.val = _impl_kernal_thread_runIdGet();
id.number = _impl_thread_os_id_to_number(id.val);
id.pName = _impl_thread_name_get(id.val);
_impl_trace_firmware_snapshot_print();
}

return id;
/**
* @brief Print At-RTOS failed postcode value.
**
* demo usage:
*
* os_trace_postcode_print();
*/
static inline void os_trace_postcode_print(void)
{
_impl_trace_postcode_snapshot_print();
}

/**
* @brief The kernal OS start to run.
* @brief Print At-RTOS kernal information.
**
* demo usage:
*
* kernal_atos_run();
* // Doesn't arrive
* os_trace_kernal_print();
*/
static inline u32p_t kernal_atos_run(void)
static inline void os_trace_kernal_print(void)
{
return _impl_kernal_at_rtos_run();
_impl_trace_kernal_snapshot_print();
}

/* It defined the AtOS extern symbol for convenience use, but it has extra memory consumption */
Expand Down Expand Up @@ -746,9 +782,13 @@ typedef struct {
u32p_t (*msgq_get)(os_msgq_id_t, const u8_t *, u16_t, b_t, u32_t);

b_t (*id_isInvalid)(struct os_id);
u32p_t (*at_rtos_run)(void);
b_t (*kernal_is_running)(void);
os_thread_id_t (*id_current_thread)(void);
u32p_t (*kernal_run)(void);
b_t (*kernal_is_running)(void);

void (*trace_firmware)(void);
void (*trace_postcode)(void);
void (*trace_kernal)(void);
} at_rtos_api_t;

extern const at_rtos_api_t AtOS;
Expand Down
2 changes: 1 addition & 1 deletion include/kernal/kernal.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ u32_t _impl_kernal_member_id_unifiedConvert(u8_t member_id, u32_t unified_id);
void _impl_kernal_thread_list_transfer_toEntry(linker_head_t *pCurHead);
u32p_t _impl_kernal_thread_exit_trigger(os_id_t id, os_id_t hold, list_t *pToList, u32_t timeout_us, void (*pCallback)(os_id_t));
u32p_t _impl_kernal_thread_entry_trigger(os_id_t id, os_id_t release, u32_t result, void (*pCallback)(os_id_t));
u32_t _impl_kernal_schedule_entry_result_read_clean(action_schedule_t *pSchedule);
u32_t _impl_kernal_schedule_entry_result_take(action_schedule_t *pSchedule);
void _impl_kernal_thread_list_transfer_toPend(linker_head_t *pCurHead);
list_t *_impl_kernal_list_pendingHeadGet(void);
u32_t _impl_kernal_stack_frame_init(void (*pEntryFunction)(void), u32_t *pAddress, u32_t size);
Expand Down
7 changes: 4 additions & 3 deletions include/kernal/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,17 @@ typedef struct {
#pragma warning restore
#endif

void _impl_trace_firmware_snapshot_take(void);
void _impl_trace_postcode_snapshot_take(void);
void _impl_trace_kernal_snapshot_take(void);
b_t _impl_trace_thread_snapshot(u32_t instance, kernal_snapshot_t *pMsgs);
b_t _impl_trace_semaphore_snapshot(u32_t instance, kernal_snapshot_t *pMsgs);
b_t _impl_trace_mutex_snapshot(u32_t instance, kernal_snapshot_t *pMsgs);
b_t _impl_trace_event_snapshot(u32_t instance, kernal_snapshot_t *pMsgs);
b_t _impl_trace_queue_snapshot(u32_t instance, kernal_snapshot_t *pMsgs);
b_t _impl_trace_timer_snapshot(u32_t instance, kernal_snapshot_t *pMsgs);

void _impl_trace_firmware_snapshot_print(void);
void _impl_trace_postcode_snapshot_print(void);
void _impl_trace_kernal_snapshot_print(void);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion kernal/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ u32p_t _impl_event_wait(os_id_t id, u32_t *pEvent, u32_t trigger, u32_t listen,

if (PC_IOK(postcode)) {
thread_context_t *pCurThread = (thread_context_t *)_impl_kernal_thread_runContextGet();
postcode = (u32p_t)_impl_kernal_schedule_entry_result_read_clean((action_schedule_t *)&pCurThread->schedule);
postcode = (u32p_t)_impl_kernal_schedule_entry_result_take((action_schedule_t *)&pCurThread->schedule);
}

if (PC_IOK(postcode) && (postcode != PC_SC_TIMEOUT)) {
Expand Down
2 changes: 1 addition & 1 deletion kernal/kernal.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ u32p_t _impl_kernal_thread_entry_trigger(os_id_t id, os_id_t release, u32_t resu
*
* @return The result of entry action schedule.
*/
u32_t _impl_kernal_schedule_entry_result_read_clean(action_schedule_t *pSchedule)
u32_t _impl_kernal_schedule_entry_result_take(action_schedule_t *pSchedule)
{
if (!pSchedule) {
return 0u;
Expand Down
6 changes: 5 additions & 1 deletion kernal/kthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ const at_rtos_api_t AtOS = {
.msgq_get = msgq_get,

.id_isInvalid = os_id_is_invalid,
.at_rtos_run = kernal_atos_run,
.kernal_run = os_kernal_run,
.kernal_is_running = os_kernal_is_running,
.id_current_thread = os_id_current_thread,

.trace_firmware = os_trace_firmware_print,
.trace_postcode = os_trace_postcode_print,
.trace_kernal = os_trace_kernal_print,
};
#endif

Expand Down
2 changes: 1 addition & 1 deletion kernal/postcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ u32p_t _impl_postcode_cmpt_failed_save(u32p_t postcode)
if (FLAG(postcode & PC_FAILED_CODE_MASK)) {
g_postcode_cmpt_failed_container[cmpt_instance] = (postcode & PC_LINE_NUMBER_MASK);

_impl_trace_postcode_snapshot_take();
_impl_trace_postcode_snapshot_print();
/* Dead loop */
while (1) {};
}
Expand Down
2 changes: 1 addition & 1 deletion kernal/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ u32p_t _impl_queue_send(os_id_t id, const u8_t *pUserBuffer, u16_t bufferSize, b
ENTER_CRITICAL_SECTION();
if (postcode == PC_SC_UNAVAILABLE) {
thread_context_t *pCurThread = (thread_context_t *)_impl_kernal_thread_runContextGet();
postcode = (u32p_t)_impl_kernal_schedule_entry_result_read_clean((action_schedule_t *)&pCurThread->schedule);
postcode = (u32p_t)_impl_kernal_schedule_entry_result_take((action_schedule_t *)&pCurThread->schedule);
}

if (PC_IOK(postcode) && (postcode != PC_SC_TIMEOUT)) {
Expand Down
2 changes: 1 addition & 1 deletion kernal/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ u32p_t _impl_semaphore_take(os_id_t id, u32_t timeout_ms)

if (postcode == PC_SC_UNAVAILABLE) {
thread_context_t *pCurThread = _impl_kernal_thread_runContextGet();
postcode = (u32p_t)_impl_kernal_schedule_entry_result_read_clean((action_schedule_t *)&pCurThread->schedule);
postcode = (u32p_t)_impl_kernal_schedule_entry_result_take((action_schedule_t *)&pCurThread->schedule);
}

if (PC_IOK(postcode) && (postcode != PC_SC_TIMEOUT)) {
Expand Down
10 changes: 5 additions & 5 deletions kernal/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern vu32_t g_postcode_cmpt_failed_container[POSTCODE_COMPONENT_NUMBER];
/**
* @brief Take firmare snapshot information.
*/
void _impl_trace_firmware_snapshot_take(void)
void _impl_trace_firmware_snapshot_print(void)
{
#if defined KTRACE
KTRACE(">> At-RTOS Version: v%d.%d.%d snaphost!!!\n", ATOS_VERSION_MAJOR_NUMBER, ATOS_VERSION_MINOR_NUMBER, ATOS_VERSION_PATCH_NUMBER);
Expand All @@ -32,7 +32,7 @@ void _impl_trace_firmware_snapshot_take(void)
/**
* @brief Take postcode snapshot information.
*/
void _impl_trace_postcode_snapshot_take(void)
void _impl_trace_postcode_snapshot_print(void)
{
b_t is_failed = FALSE;

Expand All @@ -55,14 +55,14 @@ void _impl_trace_postcode_snapshot_take(void)
/**
* @brief Take kernal snapshot information.
*/
void _impl_trace_kernal_snapshot_take(void)
void _impl_trace_kernal_snapshot_print(void)
{
#if defined KTRACE
u32_t unused[7] = {0u};
kernal_snapshot_t snapshot_data;

_impl_trace_firmware_snapshot_take();
_impl_trace_postcode_snapshot_take();
_impl_trace_firmware_snapshot_print();
_impl_trace_postcode_snapshot_print();

KTRACE(">> %-6s %-15s %-5s %-7s %-3s %-10s %-6s\n", "Thread", "Name", "ID", "STATE", "PRI", "PSP_ADDR", "USE(%)");
for (u32_t i = 0u; i < THREAD_INSTANCE_SUPPORTED_NUMBER; i++) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "At-RTOS",
"homepage": "https://github.com/At-EC/At-RTOS",
"version": "1.2.8",
"timestamp": "2024-03-19,13:50",
"commit_id": "3438a8d43f2424c9087a8b70d4869489731338e3"
"version": "1.2.9",
"timestamp": "2024-03-20,11:42",
"commit_id": "9448ad094554b116852766d85667479349978042"
}

0 comments on commit 466bf64

Please sign in to comment.