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,23 +236,42 @@ 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 k_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+
244252 if (!(first_block && last_block ))
245253 return IPC4_INVALID_REQUEST ;
246254
247255 global_system_time_info .host_time .val_l = ((const struct ipc4_system_time * )data )-> val_l ;
248256 global_system_time_info .host_time .val_u = ((const struct ipc4_system_time * )data )-> val_u ;
249257
250- uint64_t current_dsp_time = sof_cycle_get_64 ();
258+ uint64_t current_dsp_cycle = sof_cycle_get_64 ();
259+
260+ global_system_time_info .dsp_time .val_l = (uint32_t )(current_dsp_cycle );
261+ global_system_time_info .dsp_time .val_u = (uint32_t )(current_dsp_cycle >> 32 );
262+
263+ /* use default timestamp if 64bit is not enabled since 64bit is necessary for host time */
264+ if (!IS_ENABLED (CONFIG_LOG_TIMESTAMP_64BIT )) {
265+ LOG_WRN ("64bits timestamp is disabled, so use default timestamp" );
266+ return IPC4_SUCCESS ;
267+ }
251268
252- global_system_time_info .dsp_time .val_l = (uint32_t )(current_dsp_time );
253- global_system_time_info .dsp_time .val_u = (uint32_t )(current_dsp_time >> 32 );
269+ host_time = global_system_time_info .host_time .val_l |
270+ ((uint64_t )global_system_time_info .host_time .val_u << 32 );
271+ host_time_cycle = k_ns_to_cyc_ceil64 (host_time );
272+ time_delta = host_time_cycle - current_dsp_cycle ;
273+ log_set_timestamp_func (basefw_get_timestamp ,
274+ sys_clock_hw_cycles_per_sec ());
254275
255276 return IPC4_SUCCESS ;
256277}
0 commit comments