comparison core/RTAudio.cpp @ 254:173978a5ab6a aux_task_args

Allow arguments to be passed to aux task function
author Liam Donovan <l.b.donovan@qmul.ac.uk>
date Tue, 03 May 2016 11:04:56 +0100
parents 18d03901f866
children 3e93d9793da3
comparison
equal deleted inserted replaced
251:cbf70fe3711b 254:173978a5ab6a
39 39
40 // Data structure to keep track of auxiliary tasks we 40 // Data structure to keep track of auxiliary tasks we
41 // can schedule 41 // can schedule
42 typedef struct { 42 typedef struct {
43 RT_TASK task; 43 RT_TASK task;
44 void (*function)(void); 44 void (*function)(void*);
45 char *name; 45 char *name;
46 int priority; 46 int priority;
47 bool started; 47 bool started;
48 void* args;
48 } InternalAuxiliaryTask; 49 } InternalAuxiliaryTask;
49 50
50 const char gRTAudioThreadName[] = "beaglert-audio"; 51 const char gRTAudioThreadName[] = "beaglert-audio";
51 const char gRTAudioInterruptName[] = "beaglert-pru-irq"; 52 const char gRTAudioInterruptName[] = "beaglert-pru-irq";
52 53
289 290
290 // Create a calculation loop which can run independently of the audio, at a different 291 // Create a calculation loop which can run independently of the audio, at a different
291 // (equal or lower) priority. Audio priority is defined in BEAGLERT_AUDIO_PRIORITY; 292 // (equal or lower) priority. Audio priority is defined in BEAGLERT_AUDIO_PRIORITY;
292 // priority should be generally be less than this. 293 // priority should be generally be less than this.
293 // Returns an (opaque) pointer to the created task on success; 0 on failure 294 // Returns an (opaque) pointer to the created task on success; 0 on failure
294 AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void), int priority, const char *name) 295 AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void*), int priority, const char *name, void* args)
295 { 296 {
296 InternalAuxiliaryTask *newTask = (InternalAuxiliaryTask*)malloc(sizeof(InternalAuxiliaryTask)); 297 InternalAuxiliaryTask *newTask = (InternalAuxiliaryTask*)malloc(sizeof(InternalAuxiliaryTask));
297 298
298 // Attempt to create the task 299 // Attempt to create the task
299 if(rt_task_create(&(newTask->task), name, 0, priority, T_JOINABLE | T_FPU)) { 300 if(rt_task_create(&(newTask->task), name, 0, priority, T_JOINABLE | T_FPU)) {
305 // Populate the rest of the data structure and store it in the vector 306 // Populate the rest of the data structure and store it in the vector
306 newTask->function = functionToCall; 307 newTask->function = functionToCall;
307 newTask->name = strdup(name); 308 newTask->name = strdup(name);
308 newTask->priority = priority; 309 newTask->priority = priority;
309 newTask->started = false; 310 newTask->started = false;
311 newTask->args = args;
310 312
311 getAuxTasks().push_back(newTask); 313 getAuxTasks().push_back(newTask);
312 314
313 return (AuxiliaryTask)newTask; 315 return (AuxiliaryTask)newTask;
314 } 316 }
329 // priority than the audio thread. Simple wrapper for Xenomai calls. 331 // priority than the audio thread. Simple wrapper for Xenomai calls.
330 // Treat the argument as containing the task structure 332 // Treat the argument as containing the task structure
331 void auxiliaryTaskLoop(void *taskStruct) 333 void auxiliaryTaskLoop(void *taskStruct)
332 { 334 {
333 // Get function to call from the argument 335 // Get function to call from the argument
334 void (*auxiliary_function)(void) = ((InternalAuxiliaryTask *)taskStruct)->function; 336 void (*auxiliary_function)(void*) = ((InternalAuxiliaryTask *)taskStruct)->function;
335 const char *name = ((InternalAuxiliaryTask *)taskStruct)->name; 337 const char *name = ((InternalAuxiliaryTask *)taskStruct)->name;
336 338
337 // Wait for a notification 339 // Wait for a notification
338 rt_task_suspend(NULL); 340 rt_task_suspend(NULL);
339 341
340 while(!gShouldStop) { 342 while(!gShouldStop) {
341 // Then run the calculations 343 // Then run the calculations
342 auxiliary_function(); 344 auxiliary_function(((InternalAuxiliaryTask *)taskStruct)->args);
343 345
344 // Wait for a notification 346 // Wait for a notification
345 rt_task_suspend(NULL); 347 rt_task_suspend(NULL);
346 } 348 }
347 349