Repository navigation
Expand file tree
/
Copy pathtask.c
More file actions
130 lines (105 loc) · 2.9 KB
/
Copy pathtask.c
File metadata and controls
130 lines (105 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2017 Intel Corporation. All rights reserved.
//
// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
// Tomasz Lauda <tomasz.lauda@linux.intel.com>
/**
* \file
* \brief Arch task implementation file
* \authors Liam Girdwood <liam.r.girdwood@linux.intel.com>
* Tomasz Lauda <tomasz.lauda@linux.intel.com>
*/
#include <rtos/alloc.h>
#include <rtos/cache.h>
#include <sof/lib/cpu.h>
#include <sof/lib/memory.h>
#include <rtos/wait.h>
#include <sof/schedule/edf_schedule.h>
#include <sof/schedule/schedule.h>
#include <rtos/task.h>
#include <ipc/topology.h>
#include <xtensa/corebits.h>
#include <xtensa/xtruntime-frames.h>
#include <xtos-structs.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
enum task_state task_main_secondary_core(void *data)
{
#if CONFIG_MULTICORE
/* main audio processing loop */
while (1) {
/* sleep until next IDC or DMA */
wait_for_interrupt(0);
}
#endif
return SOF_TASK_STATE_COMPLETED;
}
struct task **task_main_get(void)
{
struct core_context *ctx = (struct core_context *)cpu_read_threadptr();
return &ctx->main_task;
}
volatile void *task_context_get(void)
{
struct core_context *ctx = (struct core_context *)cpu_read_threadptr();
return ctx->td.xtos_active_task;
}
void task_context_set(void *task_ctx)
{
struct core_context *ctx = (struct core_context *)cpu_read_threadptr();
ctx->td.xtos_active_task = task_ctx;
}
int task_context_alloc(void **task_ctx)
{
*task_ctx = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM,
sizeof(xtos_task_context));
if (!*task_ctx)
return -ENOMEM;
return 0;
}
int task_context_init(void *task_ctx, void *entry, void *arg0, void *arg1,
int task_core, void *stack, int stack_size)
{
xtos_task_context *ctx = task_ctx;
UserFrame *sp;
/* allocate stack if not provided */
if (stack) {
ctx->stack_base = stack;
ctx->stack_size = stack_size;
} else {
ctx->stack_base = rballoc(0, SOF_MEM_CAPS_RAM,
PLATFORM_TASK_DEFAULT_STACK_SIZE);
if (!ctx->stack_base)
return -ENOMEM;
ctx->stack_size = PLATFORM_TASK_DEFAULT_STACK_SIZE;
ctx->flags |= XTOS_TASK_CONTEXT_OWN_STACK;
}
bzero(ctx->stack_base, ctx->stack_size);
/* set initial stack pointer */
sp = (UserFrame *)((char *)ctx->stack_base + ctx->stack_size -
sizeof(UserFrame));
/* entry point */
sp->pc = (uint32_t)entry;
/* a1 is pointer to stack */
sp->a1 = (uint32_t)sp;
/* PS_WOECALL4_ABI - window overflow and increment enable
* PS_UM - user vector mode enable
*/
sp->ps = PS_WOECALL4_ABI | PS_UM;
/* a6 and a7 are the first parameters */
sp->a6 = (uint32_t)arg0;
sp->a7 = (uint32_t)arg1;
ctx->stack_pointer = sp;
return 0;
}
void task_context_free(void *task_ctx)
{
xtos_task_context *ctx = task_ctx;
if (ctx->flags & XTOS_TASK_CONTEXT_OWN_STACK)
rfree(ctx->stack_base);
ctx->stack_size = 0;
ctx->stack_pointer = NULL;
rfree(ctx);
}