Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/arch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause

add_subdirectory(${ARCH})

if(NOT CONFIG_ZEPHYR_SOF_MODULE)
add_subdirectory("xtos-wrapper")
endif()
6 changes: 5 additions & 1 deletion src/arch/xtensa/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause

add_local_sources(sof interrupt.c timer.c cache_attr.c)
add_local_sources(sof interrupt.c cache_attr.c)

if(NOT CONFIG_ZEPHYR_SOF_MODULE)
add_local_sources(sof timer.c)
endif()
1 change: 1 addition & 0 deletions src/arch/xtos-wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_include_directories(sof_public_headers INTERFACE include)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <arch/drivers/timer.h>
#include <sof/lib/cpu.h>
#include <sof/sof.h>
#include <sof/platform.h>
#include <stdint.h>

struct comp_dev;
Expand Down Expand Up @@ -76,6 +77,46 @@ static inline uint64_t platform_safe_get_time(struct timer *timer)
void platform_timer_start(struct timer *timer);
void platform_timer_stop(struct timer *timer);

static inline uint64_t k_ms_to_cyc_ceil64(uint64_t ms)
{
return clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, ms);
}

static inline uint64_t k_us_to_cyc_ceil64(uint64_t us)
{
return clock_us_to_ticks(PLATFORM_DEFAULT_CLOCK, us);
}

static inline uint64_t k_ns_to_cyc_near64(uint64_t ns)
{
return clock_ns_to_ticks(PLATFORM_DEFAULT_CLOCK, ns);
}

static inline uint64_t k_cyc_to_ms_near64(uint64_t ticks)
{
return ticks / clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, 1);
}

static inline uint64_t k_cyc_to_us_near64(uint64_t ticks)
{
return ticks / clock_us_to_ticks(PLATFORM_DEFAULT_CLOCK, 1);
}

static inline uint64_t k_cycle_get_64(void)
{
return platform_timer_get(timer_get());
}

static inline uint64_t k_cycle_get_64_atomic(void)
{
return platform_timer_get_atomic(timer_get());
}

static inline uint64_t k_cycle_get_64_safe(void)
{
return platform_safe_get_time(timer_get());
}

/* get timestamp for host stream DMA position */
void platform_host_timestamp(struct comp_dev *host,
struct sof_ipc_stream_posn *posn);
Expand Down
35 changes: 15 additions & 20 deletions src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,6 @@ static int kpb_buffer_data(struct comp_dev *dev,
uint64_t current_time;
enum kpb_state state_preserved = kpb->state;
size_t sample_width = kpb->config.sampling_width;
struct timer *timer = timer_get();

comp_dbg(dev, "kpb_buffer_data()");

Expand All @@ -874,8 +873,7 @@ static int kpb_buffer_data(struct comp_dev *dev,

kpb_change_state(kpb, KPB_STATE_BUFFERING);

timeout = platform_timer_get(timer) +
clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, 1);
timeout = k_cycle_get_64() + k_ms_to_cyc_ceil64(1);
/* Let's store audio stream data in internal history buffer */
while (size_to_copy) {
/* Reset was requested, it's time to stop buffering and finish
Expand All @@ -888,12 +886,13 @@ static int kpb_buffer_data(struct comp_dev *dev,
}

/* Are we stuck in buffering? */
current_time = platform_timer_get(timer);
current_time = k_cycle_get_64();
if (timeout < current_time) {
if (current_time - timeout <= UINT_MAX)
timeout = k_cyc_to_ms_near64(current_time - timeout);
if (timeout <= UINT_MAX)
comp_err(dev,
"kpb_buffer_data(): timeout of %u [ms] (current state %d, state log %x)",
(unsigned int)(current_time - timeout), kpb->state,
(unsigned int)(timeout), kpb->state,
kpb->state_log);
else
comp_err(dev,
Expand Down Expand Up @@ -1156,13 +1155,11 @@ static void kpb_init_draining(struct comp_dev *dev, struct kpb_client *cli)
* shall take place. This time will be used to
* synchronize us with application interrupts.
*/
drain_interval = clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK,
host_period_size / bytes_per_ms) /
drain_interval = k_ms_to_cyc_ceil64(host_period_size / bytes_per_ms) /
KPB_DRAIN_NUM_OF_PPL_PERIODS_AT_ONCE;
period_bytes_limit = host_period_size;
comp_info(dev, "kpb_init_draining(): sync_draining_mode selected with interval %u [uS].",
(unsigned int)(drain_interval * 1000 /
clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, 1)));
(unsigned int)k_cyc_to_us_near64(drain_interval));
} else {
/* Unlimited draining */
drain_interval = 0;
Expand Down Expand Up @@ -1225,8 +1222,7 @@ static enum task_state kpb_draining_task(void *arg)
uint64_t current_time;
size_t period_bytes = 0;
size_t period_bytes_limit = draining_data->pb_limit;
struct timer *timer = timer_get();
size_t period_copy_start = platform_timer_get(timer);
size_t period_copy_start = k_cycle_get_64();
size_t time_taken;
size_t *rt_stream_update = &draining_data->buffered_while_draining;
struct comp_data *kpb = comp_get_drvdata(draining_data->dev);
Expand All @@ -1243,7 +1239,7 @@ static enum task_state kpb_draining_task(void *arg)
/* Change KPB internal state to DRAINING */
kpb_change_state(kpb, KPB_STATE_DRAINING);

draining_time_start = platform_timer_get(timer);
draining_time_start = k_cycle_get_64();

while (drain_req > 0) {
/* Have we received reset request? */
Expand All @@ -1256,12 +1252,12 @@ static enum task_state kpb_draining_task(void *arg)
* to read the data already provided?
*/
if (sync_mode_on &&
next_copy_time > platform_timer_get(timer)) {
next_copy_time > k_cycle_get_64()) {
period_bytes = 0;
period_copy_start = platform_timer_get(timer);
period_copy_start = k_cycle_get_64();
continue;
} else if (next_copy_time == 0) {
period_copy_start = platform_timer_get(timer);
period_copy_start = k_cycle_get_64();
}

size_to_read = (uintptr_t)buff->end_addr - (uintptr_t)buff->r_ptr;
Expand Down Expand Up @@ -1308,7 +1304,7 @@ static enum task_state kpb_draining_task(void *arg)
}

if (sync_mode_on && period_bytes >= period_bytes_limit) {
current_time = platform_timer_get(timer);
current_time = k_cycle_get_64();
time_taken = current_time - period_copy_start;
next_copy_time = current_time + drain_interval -
time_taken;
Expand Down Expand Up @@ -1338,14 +1334,13 @@ static enum task_state kpb_draining_task(void *arg)
}

out:
draining_time_end = platform_timer_get(timer);
draining_time_end = k_cycle_get_64();

/* Reset host-sink copy mode back to its pre-draining value */
comp_set_attribute(kpb->host_sink->sink, COMP_ATTR_COPY_TYPE,
&kpb->draining_task_data.copy_type);

draining_time_ms = (draining_time_end - draining_time_start)
/ clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, 1);
draining_time_ms = k_cyc_to_ms_near64(draining_time_end - draining_time_start);
if (draining_time_ms <= UINT_MAX)
comp_cl_info(&comp_kpb, "KPB: kpb_draining_task(), done. %u drained in %u ms",
drained, (unsigned int)draining_time_ms);
Expand Down
3 changes: 1 addition & 2 deletions src/audio/pipeline/pipeline-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ int pipeline_trigger_run(struct pipeline *p, struct comp_dev *host, int cmd)
list_init(&walk_ctx.pipelines);

if (data.delay_ms)
wait_delay(clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK,
data.delay_ms));
wait_delay_ms(data.delay_ms);

ret = walk_ctx.comp_func(host, NULL, &walk_ctx, host->direction);
if (ret < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/dw/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ static int dw_dma_status(struct dma_chan_data *channel,
status->state = channel->status;
status->r_pos = dma_reg_read(channel->dma, DW_SAR(channel->index));
status->w_pos = dma_reg_read(channel->dma, DW_DAR(channel->index));
status->timestamp = timer_get_system(timer_get());
status->timestamp = k_cycle_get_64();

if (status->ipc_posn_data) {
uint32_t *llp = (uint32_t *)status->ipc_posn_data;
Expand Down
4 changes: 1 addition & 3 deletions src/drivers/dw/ssi-spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ static void spi_stop(struct spi *spi)

static void delay(unsigned int ms)
{
uint64_t tick = clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, ms);

wait_delay(tick);
wait_delay_ms(ms);
}

static int spi_trigger(struct spi *spi, int cmd, int direction)
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/generic/dummy-dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static int dummy_dma_status(struct dma_chan_data *channel,
status->r_pos = ch->r_pos;
status->w_pos = ch->w_pos;

status->timestamp = timer_get_system(timer_get());
status->timestamp = k_cycle_get_64();
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions src/drivers/host/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void platform_dai_timestamp(struct comp_dev *dai,
{
}

#ifndef __ZEPHYR__
uint64_t platform_timer_get(struct timer *timer)
{
return 0;
Expand All @@ -33,3 +34,4 @@ uint64_t platform_timer_get_atomic(struct timer *timer)
void platform_timer_stop(struct timer *timer)
{
}
#endif /* __ZEPHYR__ */
2 changes: 1 addition & 1 deletion src/drivers/imx/edma.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static int edma_status(struct dma_chan_data *channel,
*/
status->r_pos = dma_chan_reg_read(channel, EDMA_TCD_SADDR);
status->w_pos = dma_chan_reg_read(channel, EDMA_TCD_DADDR);
status->timestamp = timer_get_system(timer_get());
status->timestamp = k_cycle_get_64();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/imx/sdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ static int sdma_status(struct dma_chan_data *channel,
status->flags = 0;
status->w_pos = 0;
status->r_pos = 0;
status->timestamp = timer_get_system(timer_get());
status->timestamp = k_cycle_get_64();

bd = (struct sdma_bd *)pdata->ccb->current_bd_paddr;

Expand Down
8 changes: 6 additions & 2 deletions src/drivers/intel/baytrail/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <errno.h>
#include <stdint.h>

#ifndef __ZEPHYR__
static void platform_timer_64_handler(void *arg)
{
struct timer *timer = arg;
Expand Down Expand Up @@ -142,6 +143,7 @@ uint64_t platform_timer_get_atomic(struct timer *timer)
{
return platform_timer_get(timer);
}
#endif /* __ZEPHYR__ */

/* get timestamp for host stream DMA position */
void platform_host_timestamp(struct comp_dev *host,
Expand All @@ -167,7 +169,7 @@ void platform_dai_timestamp(struct comp_dev *dai,
posn->flags |= SOF_TIME_DAI_VALID;

/* get SSP wallclock - DAI sets this to stream start value */
posn->wallclock = platform_timer_get(timer_get()) - posn->wallclock;
posn->wallclock = k_cycle_get_64() - posn->wallclock;
posn->wallclock_hz = clock_get_freq(PLATFORM_DEFAULT_CLOCK);
posn->flags |= SOF_TIME_WALL_VALID | SOF_TIME_WALL_64;
}
Expand All @@ -176,9 +178,10 @@ void platform_dai_timestamp(struct comp_dev *dai,
void platform_dai_wallclock(struct comp_dev *dai, uint64_t *wallclock)
{
/* only 1 wallclock on BYT */
*wallclock = platform_timer_get(timer_get());
*wallclock = k_cycle_get_64();
}

#ifndef __ZEPHYR__
static int platform_timer_register(struct timer *timer,
void (*handler)(void *arg), void *arg)
{
Expand Down Expand Up @@ -235,3 +238,4 @@ void timer_disable(struct timer *timer, void *arg, int core)
interrupt_disable(timer->irq, arg);

}
#endif /* __ZEPHYR__ */
8 changes: 6 additions & 2 deletions src/drivers/intel/cavs/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/** \brief Minimum number of timer recovery cycles in case of delay. */
#define TIMER_MIN_RECOVER_CYCLES 240 /* ~10us at 24.576MHz */

#ifndef __ZEPHYR__
void platform_timer_start(struct timer *timer)
{
/* run timer */
Expand Down Expand Up @@ -112,6 +113,7 @@ uint64_t platform_timer_get_atomic(struct timer *timer)

return ticks_now;
}
#endif /* __ZEPHYR__ */

/* get timestamp for host stream DMA position */
void platform_host_timestamp(struct comp_dev *host,
Expand All @@ -137,17 +139,18 @@ void platform_dai_timestamp(struct comp_dev *dai,
posn->flags |= SOF_TIME_DAI_VALID;

/* get SSP wallclock - DAI sets this to stream start value */
posn->wallclock = shim_read64(SHIM_DSPWC) - posn->wallclock;
posn->wallclock = k_cycle_get_64() - posn->wallclock;
posn->wallclock_hz = clock_get_freq(PLATFORM_DEFAULT_CLOCK);
posn->flags |= SOF_TIME_WALL_VALID;
}

/* get current wallclock for componnent */
void platform_dai_wallclock(struct comp_dev *dai, uint64_t *wallclock)
{
*wallclock = shim_read64(SHIM_DSPWC);
*wallclock = k_cycle_get_64();
}

#ifndef __ZEPHYR__
static int platform_timer_register(struct timer *timer,
void (*handler)(void *arg), void *arg)
{
Expand Down Expand Up @@ -248,3 +251,4 @@ void timer_disable(struct timer *timer, void *arg, int core)
}

}
#endif /* __ZEPHYR__ */
12 changes: 10 additions & 2 deletions src/drivers/intel/haswell/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <errno.h>
#include <stdint.h>

#ifndef __ZEPHYR__

void platform_timer_start(struct timer *timer)
{
//nothing to do on BDW & HSW for cpu timer
Expand Down Expand Up @@ -45,6 +47,8 @@ uint64_t platform_timer_get_atomic(struct timer *timer)
return arch_timer_get_system(timer);
}

#endif /* __ZEPHYR__ */

/* get timestamp for host stream DMA position */
void platform_host_timestamp(struct comp_dev *host,
struct sof_ipc_stream_posn *posn)
Expand All @@ -69,7 +73,7 @@ void platform_dai_timestamp(struct comp_dev *dai,
posn->flags |= SOF_TIME_DAI_VALID;

/* get SSP wallclock - DAI sets this to stream start value */
posn->wallclock = timer_get_system(timer_get()) - posn->wallclock;
posn->wallclock = k_cycle_get_64() - posn->wallclock;
posn->wallclock_hz = clock_get_freq(PLATFORM_DEFAULT_CLOCK);
posn->flags |= SOF_TIME_WALL_VALID | SOF_TIME_WALL_64;
}
Expand All @@ -78,9 +82,11 @@ void platform_dai_timestamp(struct comp_dev *dai,
void platform_dai_wallclock(struct comp_dev *dai, uint64_t *wallclock)
{
/* only 1 wallclock on HSW */
*wallclock = timer_get_system(timer_get());
*wallclock = k_cycle_get_64();
}

#ifndef __ZEPHYR__

int timer_register(struct timer *timer, void (*handler)(void *arg), void *arg)
{
int ret;
Expand Down Expand Up @@ -116,3 +122,5 @@ void timer_disable(struct timer *timer, void *arg, int core)
interrupt_disable(timer->irq, arg);

}

#endif /* __ZEPHYR__ */
Loading