aud_sched.c
4.41 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*************************************************************
aud_sched.c : Nintendo 64 Music Tools Programmers Library
(c) Copyright 1997/1998, Software Creations (Holdings) Ltd.
Version 3.14
Music library scheduler functions.
**************************************************************/
/* include configuartion */
#include "libmus_config.h"
/* include system headers */
#include <ultra64.h>
#include <sched.h>
/* include other header files */
#include "libmus.h"
#include "lib_memory.h"
/* include current header file */
#include "aud_sched.h"
/* internal macros */
#define QUEUE_SIZE 4
/* internal function prototypes */
static void __OsSchedInstall(void);
static void __OsSchedWaitFrame(void);
static void __OsSchedDoTask(musTask *task);
/* internal data structures */
typedef struct
{
OSScClient client;
OSMesgQueue frame_queue;
OSMesg frame_messages[QUEUE_SIZE];
OSMesgQueue task_queue;
OSMesg task_messages[QUEUE_SIZE];
} ossched_workspace_t;
/* internal workspace */
static OSSched *audio_sched;
static ossched_workspace_t *sched_mem;
static musSched default_sched = { __OsSchedInstall, __OsSchedWaitFrame, __OsSchedDoTask };
musSched *__libmus_current_sched=&default_sched;
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[EXTERNAL FUNCTION]
__MusIntSchedInit(sched)
[Parameters]
sched adress of OSSched structure
[Explanation]
Initialise scheduler support functions.
[Return value]
NONE
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void __MusIntSchedInit(void *sched)
{
audio_sched = (OSSched *)sched;
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[CALLBACK FUNCTION]
__OsSchedInstall()
[Explanation]
Default scheduler 'install' function. Called once when audio thread first starts.
[Return value]
NONE
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void __OsSchedInstall(void)
{
sched_mem = __MusIntMemMalloc(sizeof(ossched_workspace_t));
osCreateMesgQueue(&sched_mem->frame_queue, &sched_mem->frame_messages[0], QUEUE_SIZE);
osCreateMesgQueue(&sched_mem->task_queue, &sched_mem->task_messages[0], QUEUE_SIZE);
osScAddClient(audio_sched, &sched_mem->client, &sched_mem->frame_queue);
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[CALLBACK FUNCTION]
__OsSchedWaitFrame()
[Explanation]
Default scheduler 'waitframe' function. Called in audio thread mail loop to wait
for vsync message.
[Return value]
NONE
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void __OsSchedWaitFrame(void)
{
OSScMsg *message;
do
{
osRecvMesg(&sched_mem->frame_queue, (OSMesg *)&message, OS_MESG_BLOCK);
osRecvMesg(&sched_mem->frame_queue, NULL, OS_MESG_NOBLOCK); /* bin any missed syncs! <- only happens if a higher priority thread takes a huge amount of time */
} while (message->type!=OS_SC_RETRACE_MSG);
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[EXTERNAL FUNCTION]
__OsSchedDoTask(task)
[Parameters]
task address of task descriptor structure
[Explanation]
Default scheduler 'dotask' function. Called to process the given task as an RSP
task and wait for its completion.
[Return value]
NONE
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void __OsSchedDoTask(musTask *task)
{
OSScTask t;
OSScMsg message;
t.next = 0;
t.msgQ = &sched_mem->task_queue;
t.msg = &message;
t.flags = OS_SC_NEEDS_RSP;
t.list.t.data_ptr = task->data;
t.list.t.data_size = task->data_size;
t.list.t.type = M_AUDTASK;
t.list.t.ucode_boot = (u64 *)rspbootTextStart;
t.list.t.ucode_boot_size = ((int) rspbootTextEnd - (int) rspbootTextStart);
t.list.t.flags = 0;
t.list.t.ucode = (u64 *) task->ucode;
t.list.t.ucode_data = (u64 *) task->ucode_data;
t.list.t.ucode_size = 4096;
t.list.t.ucode_data_size = SP_UCODE_DATA_SIZE;
t.list.t.dram_stack = (u64 *) NULL;
t.list.t.dram_stack_size = 0;
t.list.t.output_buff = (u64 *) NULL;
t.list.t.output_buff_size = 0;
t.list.t.yield_data_ptr = NULL;
t.list.t.yield_data_size = 0;
osSendMesg(osScGetCmdQ(audio_sched), (OSMesg) &t, OS_MESG_BLOCK);
osRecvMesg(&sched_mem->task_queue, NULL, OS_MESG_BLOCK);
}
/* end of file */