1818#include <zephyr/device.h>
1919#include <zephyr/drivers/counter.h>
2020#endif
21+ #include <zephyr/logging/log_ctrl.h>
2122
2223/* TODO: Remove platform-specific code, see https://github.com/thesofproject/sof/issues/7549 */
2324#if defined(CONFIG_SOC_SERIES_INTEL_ACE ) || defined(CONFIG_INTEL_ADSP_CAVS )
@@ -32,6 +33,7 @@ DECLARE_SOF_RT_UUID("basefw", basefw_comp_uuid, 0xe398c32, 0x5ade, 0xba4b,
3233DECLARE_TR_CTX (basefw_comp_tr , SOF_UUID (basefw_comp_uuid ), LOG_LEVEL_INFO );
3334
3435static struct ipc4_system_time_info global_system_time_info ;
36+ static uint64_t time_delta ;
3537
3638static int basefw_config (uint32_t * data_offset , char * data )
3739{
@@ -234,24 +236,46 @@ static int basefw_mem_state_info(uint32_t *data_offset, char *data)
234236 return 0 ;
235237}
236238
239+ static log_timestamp_t basefw_get_timestamp (void )
240+ {
241+ return sof_cycle_get_64 () + time_delta ;
242+ }
243+
237244static uint32_t basefw_set_system_time (uint32_t param_id ,
238245 bool first_block ,
239246 bool last_block ,
240247 uint32_t data_offset ,
241248 const char * data )
242249{
243- /* TODO: configurate time to logging subsystem */
250+ uint64_t host_time , host_time_cycle ;
251+ uint64_t current_dsp_time ;
252+ uint64_t current_dsp_cycle ;
253+
244254 if (!(first_block && last_block ))
245255 return IPC4_INVALID_REQUEST ;
246256
247257 global_system_time_info .host_time .val_l = ((const struct ipc4_system_time * )data )-> val_l ;
248258 global_system_time_info .host_time .val_u = ((const struct ipc4_system_time * )data )-> val_u ;
249259
250- uint64_t current_dsp_time = sof_cycle_get_64 ();
260+ current_dsp_cycle = sof_cycle_get_64 ();
261+ current_dsp_time = k_cyc_to_ns_ceil64 (current_dsp_cycle );
251262
252263 global_system_time_info .dsp_time .val_l = (uint32_t )(current_dsp_time );
253264 global_system_time_info .dsp_time .val_u = (uint32_t )(current_dsp_time >> 32 );
254265
266+ /* use default timestamp if 64bit is not enabled since 64bit is necessary for host time */
267+ if (!IS_ENABLED (CONFIG_LOG_TIMESTAMP_64BIT )) {
268+ LOG_WRN ("64bits timestamp is disabled, so use default timestamp" );
269+ return IPC4_SUCCESS ;
270+ }
271+
272+ host_time = global_system_time_info .host_time .val_l |
273+ ((uint64_t )global_system_time_info .host_time .val_u << 32 );
274+ host_time_cycle = k_ns_to_cyc_ceil64 (host_time );
275+ time_delta = host_time_cycle - current_dsp_cycle ;
276+ log_set_timestamp_func (basefw_get_timestamp ,
277+ sys_clock_hw_cycles_per_sec ());
278+
255279 return IPC4_SUCCESS ;
256280}
257281
0 commit comments