1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-21 15:25:17 +03:00

Mutex to protect the audio functions

This commit is contained in:
bsongis 2012-07-03 19:41:53 +00:00
parent 4b3fad5266
commit b78533f86c
2 changed files with 11 additions and 1 deletions

View file

@ -224,7 +224,7 @@ void audioTask(void* pdata)
DACC->DACC_TNCR = read/4;
toneStop();
toneWavFile[0] = '\0';
toneWavFile[1] = 0;
toneWavFile[1] = '\0';
f_close(&wavFile);
audioState = 0;
}
@ -319,9 +319,13 @@ void pause(uint8_t tLen)
play(0, 0, tLen); // a pause
}
extern OS_MutexID audioMutex;
void play(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
uint8_t tFlags, int8_t tFreqIncr)
{
CoEnterMutexSection(audioMutex);
if (tFlags & PLAY_SOUND_VARIO) {
tone2Freq = tFreq;
tone2TimeLeft = tLen;
@ -363,12 +367,16 @@ void play(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
}
}
}
CoLeaveMutexSection(audioMutex);
}
void playFile(const char *filename)
{
CoEnterMutexSection(audioMutex);
strcpy(toneWavFile, filename);
CoSetFlag(audioFlag);
CoLeaveMutexSection(audioMutex);
}
void audioEvent(uint8_t e, uint8_t f)

View file

@ -53,6 +53,7 @@ OS_TCID audioTimer;
OS_FlagID audioFlag;
OS_MutexID sdMutex;
OS_MutexID audioMutex;
/*OS_TID btTask;
OS_STK btStack[BT_STACK_SIZE];
@ -3122,6 +3123,7 @@ int main(void)
audioTaskId = CoCreateTask(audioTask, NULL, 7, &audioStack[AUDIO_STACK_SIZE-1], AUDIO_STACK_SIZE);
sdMutex = CoCreateMutex();
audioMutex = CoCreateMutex();
CoStartOS();
#else