Skip to content

Commit

Permalink
Merge pull request zephyrproject-rtos#10 from finikorg/wip
Browse files Browse the repository at this point in the history
Wip: latest patch collection
  • Loading branch information
jhedberg authored Aug 26, 2019
2 parents a3b8bc0 + d94070d commit e08cbf8
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 74 deletions.
49 changes: 45 additions & 4 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <errno.h>
#include <stdbool.h>

#include "sys_clock.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -2902,7 +2904,42 @@ extern void k_delayed_work_init(struct k_delayed_work *work,
k_work_handler_t handler);

/**
* @brief Submit a delayed work item.
* @brief Submit a delayed work item (with delay in microseconds).
*
* This routine schedules work item @a work to be processed by workqueue
* @a work_q after a delay of @a delay milliseconds. The routine initiates
* an asynchronous countdown for the work item and then returns to the caller.
* Only when the countdown completes is the work item actually submitted to
* the workqueue and becomes pending.
*
* Submitting a previously submitted delayed work item that is still
* counting down cancels the existing submission and restarts the
* countdown using the new delay. Note that this behavior is
* inherently subject to race conditions with the pre-existing
* timeouts and work queue, so care must be taken to synchronize such
* resubmissions externally.
*
* @warning
* A delayed work item must not be modified until it has been processed
* by the workqueue.
*
* @note Can be called by ISRs.
*
* @param work_q Address of workqueue.
* @param work Address of delayed work item.
* @param delay Delay before submitting the work item (in microseconds).
*
* @retval 0 Work item countdown started.
* @retval -EINVAL Work item is being processed or has completed its work.
* @retval -EADDRINUSE Work item is pending on a different workqueue.
* @req K-DWORK-001
*/
extern int k_delayed_work_submit_to_queue_us(struct k_work_q *work_q,
struct k_delayed_work *work,
s32_t us_delay);

/**
* @brief Submit a delayed work item (with delay in milliseconds).
*
* This routine schedules work item @a work to be processed by workqueue
* @a work_q after a delay of @a delay milliseconds. The routine initiates
Expand Down Expand Up @@ -2932,9 +2969,13 @@ extern void k_delayed_work_init(struct k_delayed_work *work,
* @retval -EADDRINUSE Work item is pending on a different workqueue.
* @req K-DWORK-001
*/
extern int k_delayed_work_submit_to_queue(struct k_work_q *work_q,
struct k_delayed_work *work,
s32_t delay);
static inline int k_delayed_work_submit_to_queue(struct k_work_q *work_q,
struct k_delayed_work *work,
s32_t delay)
{
return k_delayed_work_submit_to_queue_us(work_q, work,
(delay * USEC_PER_MSEC));
}

/**
* @brief Cancel a delayed work item.
Expand Down
8 changes: 4 additions & 4 deletions kernel/work_q.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ static int work_cancel(struct k_delayed_work *work)
return 0;
}

int k_delayed_work_submit_to_queue(struct k_work_q *work_q,
struct k_delayed_work *work,
s32_t delay)
int k_delayed_work_submit_to_queue_us(struct k_work_q *work_q,
struct k_delayed_work *work,
s32_t delay)
{
k_spinlock_key_t key = k_spin_lock(&lock);
int err = 0;
Expand Down Expand Up @@ -108,7 +108,7 @@ int k_delayed_work_submit_to_queue(struct k_work_q *work_q,

/* Add timeout */
z_add_timeout(&work->timeout, work_timeout,
_TICK_ALIGN + z_ms_to_ticks(delay));
_TICK_ALIGN + z_us_to_ticks(delay));

done:
k_spin_unlock(&lock, key);
Expand Down
2 changes: 1 addition & 1 deletion samples/audio/sof/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ CONFIG_LOG_PRINTK=y
CONFIG_LOG_IMMEDIATE=y
CONFIG_SOF_LOG_LEVEL=4
# SOF requires malloc/calloc
CONFIG_HEAP_MEM_POOL_SIZE=64000
CONFIG_HEAP_MEM_POOL_SIZE=196608
5 changes: 5 additions & 0 deletions soc/xtensa/intel_apl_adsp/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ config 2ND_LEVEL_INTERRUPTS
config DYNAMIC_INTERRUPTS
default y

# Work queues in SOF needs microsecond delays.
# 100000 = 10us per tick
config SYS_CLOCK_TICKS_PER_SEC
default 100000

endif

endif
16 changes: 8 additions & 8 deletions soc/xtensa/intel_apl_adsp/include/sof_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#define CONFIG_CAVS 1
#define CONFIG_CAVS_VERSION_1_5 1
#define CONFIG_FIRMWARE_SHORT_NAME "apl"
#define CONFIG_CAVS_DMIC 1
#define CONFIG_CAVS_DMIC_FIR_FULL 1
#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_2 1
#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_3 1
#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_4 1
#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_5 1
#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_6 1
#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_8 1
//#define CONFIG_CAVS_DMIC 1
//#define CONFIG_CAVS_DMIC_FIR_FULL 1
//#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_2 1
//#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_3 1
//#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_4 1
//#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_5 1
//#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_6 1
//#define CONFIG_CAVS_DMIC_FIR_DECIMATE_BY_8 1
#define CONFIG_CAVS_SSP 1
#define CONFIG_DW 1
#define CONFIG_DW_DMA 1
Expand Down
78 changes: 24 additions & 54 deletions subsys/audio/sof.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(sof, CONFIG_SOF_LOG_LEVEL);

#include <platform/dai.h>
#include <platform/dma.h>
#include <platform/shim.h>
#include <platform/timer.h>
#include <sof/clk.h>
#include <sof/interrupt.h>
#include <sof/mailbox.h>
#include <sof/notifier.h>
#include <sof/timer.h>
Expand Down Expand Up @@ -212,49 +216,6 @@ void debug_print(char *message)
LOG_DBG("%s", message);
}

/* FIXME: The following definitions are to satisfy linker errors */
struct dai dai;

/* Make use of dai_install to register DAI drivers, there maybe common code
* from i2s_cavs.c and codec.h */
struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
{
return &dai;
}

void dai_put(struct dai *dai)
{
}

int dai_init(void)
{
return 0;
}

struct dma dma;

struct dma *dma_get(uint32_t dir, uint32_t caps, uint32_t dev, uint32_t flags)
{
return &dma;
}

void dma_put(struct dma *dma)
{
}

int dma_sg_alloc(struct dma_sg_elem_array *elem_array,
int zone,
uint32_t direction,
uint32_t buffer_count, uint32_t buffer_bytes,
uintptr_t dma_buffer_addr, uintptr_t external_addr)
{
return 0;
}

void dma_sg_free(struct dma_sg_elem_array *elem_array)
{
}

static void prepare_host_windows()
{
/* window0, for fw status & outbox/uplink mbox */
Expand Down Expand Up @@ -329,6 +290,8 @@ static int sof_init(struct device *unused)
{
int ret;

platform_interrupt_init();

/* prepare host windows */
prepare_host_windows();

Expand All @@ -340,9 +303,27 @@ static int sof_init(struct device *unused)
/* init static modules */
sys_module_init();

/* start DSP wall clock */
platform_timer_start(platform_timer);

/* init clocks in SOF */
clock_init();

/* init scheduler */
ret = scheduler_init();
if (ret < 0) {
LOG_ERR("scheduler init: %d", ret);
return ret;
}

LOG_INF("scheduler initialized");

/* init DMAC */
ret = dmac_init();
if (ret < 0) {
return ret;
}

/* init IPC */
ret = ipc_init(&sof);
if (ret < 0) {
Expand All @@ -359,15 +340,6 @@ static int sof_init(struct device *unused)
return ret;
}

/* init scheduler */
ret = scheduler_init();
if (ret < 0) {
LOG_ERR("scheduler init: %d", ret);
return ret;
}

LOG_INF("scheduler initialized");

#if defined(CONFIG_SOF_STATIC_PIPELINE)
/* init static pipeline */
ret = init_static_pipeline(sof.ipc);
Expand All @@ -379,8 +351,6 @@ static int sof_init(struct device *unused)
LOG_INF("pipeline initialized");
#endif /* CONFIG_SOF_STATIC_PIPELINE */

mailbox_sw_reg_write(SRAM_REG_ROM_STATUS, 0xabbac0fe);

sof_boot_complete();

LOG_INF("FW Boot Completed");
Expand Down
7 changes: 4 additions & 3 deletions subsys/logging/log_backend_adsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static inline void dcache_writeback_region(void *addr, size_t size)

static void trace(const u8_t *data, size_t length)
{
volatile u8_t *t;
volatile u8_t *t, *region;
int space;
int i;

Expand All @@ -54,6 +54,7 @@ static void trace(const u8_t *data, size_t length)
}

ring_buf_put_claim(&ringbuf, (u8_t **)&t, BUF_SIZE);
region = t;

/* Add magic number at the beginning of the slot */
*(u16_t *)t = magic;
Expand All @@ -63,11 +64,11 @@ static void trace(const u8_t *data, size_t length)
*(u16_t *)t = log_id++;
t += 2;

for (i = 0; i < length; i++) {
for (i = 0; i < MIN(length, BUF_SIZE - 4); i++) {
*t++ = data[i];
}

dcache_writeback_region((void *)t, i);
dcache_writeback_region((void *)region, BUF_SIZE);

ring_buf_put_finish(&ringbuf, BUF_SIZE);
}
Expand Down

0 comments on commit e08cbf8

Please sign in to comment.