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
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_subdirectory(arch)
add_subdirectory(ipc)
add_subdirectory(audio)
add_subdirectory(lib)
add_subdirectory(math)
add_local_sources(sof spinlock.c)

if(CONFIG_LIBRARY)
Expand All @@ -14,7 +15,6 @@ endif()
add_subdirectory(debug)
add_subdirectory(drivers)
add_subdirectory(init)
add_subdirectory(math)
add_subdirectory(schedule)

if (CONFIG_TRACE)
Expand Down
5 changes: 5 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ if(NOT CONFIG_LIBRARY)
detect_test.c
)
endif()
if(CONFIG_COMP_TEST_SMART_AMP)
add_local_sources(sof
smart_amp_test.c
)
endif()
add_subdirectory(pcm_converter)
if(CONFIG_COMP_ASRC)
add_subdirectory(asrc)
Expand Down
7 changes: 7 additions & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ config COMP_DCBLOCK
Select for DC Blocking Filter component. This component filters out
the DC offset which often originates from a microphone's output.

config COMP_TEST_SMART_AMP
depends on CAVS && !CAVS_VERSION_1_5
bool "Smart amplifier test component"
default y
help
Select for test smart amplifier component

config COMP_TEST_KEYPHRASE
bool "KEYPHRASE_TEST component"
default y
Expand Down
152 changes: 152 additions & 0 deletions src/audio/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,158 @@ int comp_verify_params(struct comp_dev *dev, uint32_t flag,
return 0;
}

void comp_free_model_data(struct comp_dev *dev, struct comp_model_data *model)
{
if (!model->data)
return;

rfree(model->data);
model->data = NULL;
model->data_size = 0;
model->crc = 0;
model->data_pos = 0;
}

int comp_alloc_model_data(struct comp_dev *dev, struct comp_model_data *model,
uint32_t size)
{
if (!size)
return 0;

comp_free_model_data(dev, model);

model->data = rballoc(0, SOF_MEM_CAPS_RAM, size);

if (!model->data) {
comp_err(dev, "comp_alloc_model_data(): model->data rballoc failed");
return -ENOMEM;
}

bzero(model->data, size);
model->data_size = size;
model->data_pos = 0;
model->crc = 0;

return 0;
}

int comp_set_model(struct comp_dev *dev, struct comp_model_data *model,
struct sof_ipc_ctrl_data *cdata)
{
bool done = false;
int ret = 0;

comp_dbg(dev, "comp_set_model() msg_index = %d, num_elems = %d, remaining = %d ",
cdata->msg_index, cdata->num_elems,
cdata->elems_remaining);

/* in case when the current package is the first, we should allocate
* memory for whole model data
*/
if (!cdata->msg_index) {
ret = comp_alloc_model_data(dev, model, cdata->data->size);
if (ret < 0)
return ret;
}

/* return an error in case when we do not have allocated memory for
* model data
*/
if (!model->data) {
comp_err(dev, "comp_set_model(): buffer not allocated");
return -ENOMEM;
}

if (!cdata->elems_remaining) {
/* when we receive the last package and do not fill the whole
* allocated buffer, we return an error
*/
if (cdata->num_elems + model->data_pos < model->data_size) {
comp_err(dev, "comp_set_model(): not enough data to fill the buffer");
// TODO: handle this situation

return -EINVAL;
}

/* the whole data were received properly */
done = true;
comp_dbg(dev, "comp_set_model(): final package received");
}

/* return an error in case when received data exceed allocated
* memory
*/
if (cdata->num_elems > model->data_size - model->data_pos) {
comp_err(dev, "comp_set_model(): too much data");
return -EINVAL;
}

ret = memcpy_s((char *)model->data + model->data_pos,
model->data_size - model->data_pos,
cdata->data->data, cdata->num_elems);
assert(!ret);

/* update data_pos variable with received number of elements (num_elem)
*/
model->data_pos += cdata->num_elems;

/* Update crc value when done */
if (done) {
model->crc = crc32(0, model->data, model->data_size);
comp_dbg(dev, "comp_set_model() done, memory_size = 0x%x, crc = 0x%08x",
model->data_size, model->crc);
}

return 0;
}

int comp_get_model(struct comp_dev *dev, struct comp_model_data *model,
struct sof_ipc_ctrl_data *cdata, int size)
{
size_t bs;
int ret = 0;

comp_dbg(dev, "comp_get_model() msg_index = %d, num_elems = %d, remaining = %d ",
cdata->msg_index, cdata->num_elems,
cdata->elems_remaining);

/* Copy back to user space */
if (model->data) {
/* reset data_pos variable in case of copying first element */
if (!cdata->msg_index) {
model->data_pos = 0;
comp_dbg(dev, "comp_get_model() model data_size = 0x%x",
model->data_size);
}

bs = cdata->num_elems;

/* return an error in case of mismatch between num_elems and
* required size
*/
if (bs > size) {
comp_err(dev, "comp_get_model(): invalid size %d", bs);
return -EINVAL;
}

/* copy required size of data */
ret = memcpy_s(cdata->data->data, size,
(char *)model->data + model->data_pos,
bs);
assert(!ret);

cdata->data->abi = SOF_ABI_VERSION;
cdata->data->size = model->data_size;
model->data_pos += bs;

} else {
comp_err(dev, "comp_get_model(): !model->data");
ret = -EINVAL;
}

return ret;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of large uncommented functions here, please use inline comment describing each code block and what the function does.

Copy link
Collaborator Author

@bkokoszx bkokoszx May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood
I've commented comp_set_model() and comp_get_model() functions. Is that alright for you? Or do you want more detailed comments?
BTW
This functions are basically moved from detect_test component, just to enable their usage by other components (for example smart_amp component()).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, btw - is this for test reasons only ? if so we would need to use a kconfig to enable building of this code (to reduce the production image size).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM, it is used for configuration and sending large configs for detect_test and smart_amp_test components only. I can enable this part of code in case when we are building firmware with detector or smart amp component.


struct comp_dev *comp_make_shared(struct comp_dev *dev)
{
struct list_item *old_bsource_list = &dev->bsource_list;
Expand Down
Loading