Subversion Repositories svn.mios32

Rev

Rev 2340 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2336 Sauraen 1
/*
2
 * VGM Data and Playback Driver: SD Card Buffer Task
3
 *
4
 * ==========================================================================
5
 *
6
 *  Copyright (C) 2016 Sauraen (sauraen@gmail.com)
7
 *  Licensed for personal non-commercial use only.
8
 *  All other rights reserved.
9
 *
10
 * ==========================================================================
11
 */
12
 
13
 
14
#include "vgmsdtask.h"
15
#include "vgmhead.h"
16
#include "vgmstream.h"
17
 
18
#include <FreeRTOS.h>
19
#include <portmacro.h>
20
#include <task.h>
21
#include <queue.h>
22
#include <semphr.h>
23
 
24
#define VGM_SDTASK_PRIORITY 3
25
 
2340 Sauraen 26
xSemaphoreHandle xSDCardSemaphore;
27
 
2336 Sauraen 28
u8 vgm_sdtask_disable;
29
u8 vgm_sdtask_usingsdcard;
30
 
31
static void VGM_SDTask(void* pvParameters){
32
    portTickType xLastExecutionTime;
33
    xLastExecutionTime = xTaskGetTickCount();
34
    u8 i, fi = 0;
35
    VgmHead* vh;
36
    while(1){
37
        vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
38
        i = fi;
39
        while(1){
40
            if(vgm_sdtask_disable){
41
                fi = i; //start back where you are now
42
                break; //stop immediately
43
            }
44
            vh = vgm_heads[i];
45
            if(vh != NULL){
46
                if(vh->playing && vh->source->type == VGM_SOURCE_TYPE_STREAM){
47
                    VGM_HeadStream_BackgroundBuffer(vh);
48
                }
49
            }
50
            ++i;
51
            if(i >= vgm_numheads) i = 0;
52
            if(i == fi) break; //Have done them all
53
        }
54
    }
55
}
56
 
57
void VGM_SDTask_Init(){
2340 Sauraen 58
    xSDCardSemaphore = xSemaphoreCreateRecursiveMutex();
2336 Sauraen 59
    vgm_sdtask_disable = 0;
60
    vgm_sdtask_usingsdcard = 0;
2425 tk 61
    xTaskCreate(VGM_SDTask, "VGM_SD", configMINIMAL_STACK_SIZE, NULL, VGM_SDTASK_PRIORITY, NULL);
2336 Sauraen 62
}