1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2018 Intel Corporation. All rights reserved.
4 //
5 // Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
6 // Liam Girdwood <liam.r.girdwood@linux.intel.com>
7 // Keyon Jie <yang.jie@linux.intel.com>
8 // Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
9
10 #include <sof/audio/component.h>
11 #include <sof/schedule/task.h>
12 #include <stdint.h>
13 #include <sof/lib/wait.h>
14 #include <stdlib.h>
15
16 static struct schedulers *testbench_schedulers_ptr; /* Initialized as NULL */
17
arch_schedulers_get(void)18 struct schedulers **arch_schedulers_get(void)
19 {
20 return &testbench_schedulers_ptr;
21 }
22
schedule_task_init(struct task * task,const struct sof_uuid_entry * uid,uint16_t type,uint16_t priority,enum task_state (* run)(void * data),void * data,uint16_t core,uint32_t flags)23 int schedule_task_init(struct task *task,
24 const struct sof_uuid_entry *uid, uint16_t type,
25 uint16_t priority, enum task_state (*run)(void *data),
26 void *data, uint16_t core, uint32_t flags)
27 {
28 if (type >= SOF_SCHEDULE_COUNT)
29 return -EINVAL;
30
31 task->uid = uid;
32 task->type = SOF_SCHEDULE_EDF; /* Note: Force EDF scheduler */
33 task->priority = priority;
34 task->core = core;
35 task->flags = flags;
36 task->state = SOF_TASK_STATE_INIT;
37 task->ops.run = run;
38 task->data = data;
39
40 return 0;
41 }
42
scheduler_register(struct schedule_data * scheduler)43 static void scheduler_register(struct schedule_data *scheduler)
44 {
45 struct schedulers **sch = arch_schedulers_get();
46
47 if (!*sch) {
48 /* init schedulers list */
49 *sch = calloc(1, sizeof(**sch));
50 list_init(&(*sch)->list);
51 }
52
53 list_item_append(&scheduler->list, &(*sch)->list);
54 }
55
scheduler_init(int type,const struct scheduler_ops * ops,void * data)56 void scheduler_init(int type, const struct scheduler_ops *ops, void *data)
57 {
58 struct schedule_data *sch;
59
60 sch = calloc(1, sizeof(*sch));
61 list_init(&sch->list);
62 sch->type = SOF_SCHEDULE_EDF; /* Note: Force EDF scheduler */
63 sch->ops = ops;
64 sch->data = data;
65
66 scheduler_register(sch);
67 }
68