Skip to content

Commit

Permalink
improve the support for EventRecorder
Browse files Browse the repository at this point in the history
  • Loading branch information
GorgonMeducer committed Jan 17, 2024
1 parent f894704 commit ee560a0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
24 changes: 21 additions & 3 deletions perf_counter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2022 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
* Copyright 2024 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -180,8 +180,13 @@ volatile static int32_t s_nSystemUS = 0;

volatile static int64_t s_lSystemClockCounts = 0;

PERF_NOINIT
volatile static int64_t s_lNoInitTimestamp;


/*============================ PROTOTYPES ====================================*/
static int64_t get_no_init_timestamp(void);

/*============================ IMPLEMENTATION ================================*/
/*============================ INCLUDES ======================================*/

Expand Down Expand Up @@ -210,6 +215,7 @@ void user_code_insert_to_systick_handler(void)
{
uint32_t wLoad = SysTick->LOAD + 1;
s_lSystemClockCounts += wLoad;
s_lNoInitTimestamp += wLoad;

// update system ms counter
do {
Expand Down Expand Up @@ -313,7 +319,7 @@ void before_cycle_counter_reconfiguration(void)

}
s_lSystemClockCounts = get_system_ticks(); /* get the final cycle counter value */

s_lNoInitTimestamp = get_no_init_timestamp();
SysTick->LOAD = 0UL;
SysTick->VAL = 0UL; /* clear the Current Value Register */
}
Expand Down Expand Up @@ -390,6 +396,17 @@ int64_t get_system_ticks(void)
return lTemp;
}

static int64_t get_no_init_timestamp(void)
{
int64_t lTemp = 0;

__IRQ_SAFE {
lTemp = check_systick() + s_lNoInitTimestamp;
}

return lTemp;
}

/*! \note the prototype of this clock() is different from the one defined in
*! time.h. As clock_t is usually defined as unsigned int, it is
*! not big enough in Cortex-M system to hold a time-stamp. clock()
Expand Down Expand Up @@ -497,6 +514,7 @@ bool __perfc_is_time_out(int64_t lPeriod, int64_t *plTimestamp, bool bAutoReload
uint32_t EventRecorderTimerSetup (void)
{
/* doing nothing at all */
s_lNoInitTimestamp = 0;
return 1;
}

Expand All @@ -511,7 +529,7 @@ uint32_t EventRecorderTimerGetFreq (void)
/// \return timer count (32-bit)
uint32_t EventRecorderTimerGetCount (void)
{
return get_system_ticks();
return get_no_init_timestamp();
}


Expand Down
25 changes: 22 additions & 3 deletions perf_counter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2022 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
* Copyright 2024 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -35,9 +35,9 @@ extern "C" {
*/
#define __PERF_COUNTER_VER_MAJOR__ 2
#define __PERF_COUNTER_VER_MINOR__ 2
#define __PERF_COUNTER_VER_REVISE__ 4
#define __PERF_COUNTER_VER_REVISE__ 5

#define __PERF_COUNTER_VER_STR__ ""
#define __PERF_COUNTER_VER_STR__ "dev"

#define __PER_COUNTER_VER__ (__PERF_COUNTER_VER_MAJOR__ * 10000ul \
+__PERF_COUNTER_VER_MINOR__ * 100ul \
Expand Down Expand Up @@ -134,6 +134,25 @@ extern "C" {
# define UNUSED_PARAM(__VAR) (void)(__VAR)
#endif

/*!
* \brief an attribute for static variables that no initialisation is required
* in the C startup process.
*/
#ifndef PERF_NOINIT
# if defined(__IS_COMPILER_ARM_COMPILER_5__)
# define PERF_NOINIT __attribute__(( section( ".bss.noinit"),zero_init))
# elif defined(__IS_COMPILER_ARM_COMPILER_6__)
# define PERF_NOINIT __attribute__(( section( ".bss.noinit")))
# elif defined(__IS_COMPILER_IAR__)
# define PERF_NOINIT __no_init
# elif (defined(__IS_COMPILER_GCC__) || defined(__IS_COMPILER_LLVM__)) && !defined(__APPLE__)
# define PERF_NOINIT __attribute__(( section( ".bss.noinit")))
# else
# define PERF_NOINIT
# endif
#endif


#undef __CONNECT2
#undef __CONNECT3
#undef __CONNECT4
Expand Down

0 comments on commit ee560a0

Please sign in to comment.