1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 16:55:20 +03:00
* sport.log only active if SPORT_FILE_LOG=YES
* audio concurrent access fixes
* added IO mutex
* added Event Trace Buffer
* fixed SD card error

Conflicts:
	radio/src/Makefile
	radio/src/targets/taranis/diskio.cpp
This commit is contained in:
Damjan Adamic 2014-09-26 11:31:16 +02:00 committed by bsongis
parent c4c7fed727
commit 874156122d
12 changed files with 901 additions and 578 deletions

View file

@ -297,6 +297,16 @@ CHANNELS_MONITOR_INV_HIDE = NO
# Values = NO, YES
NANO = NO
# Enable trace of events into Trace Buffer for debugging purposes
# Activating any of these options also activates DEBUG and DEBUG_TRACE_BUFFER
# Values = NO, YES
# TRACE_SD_CARD SD card operations (read, write, etc)
# TRACE_FATFS FatFs file operations
# TRACE_AUDIO Audio processing (not yet implemented)
TRACE_SD_CARD = NO
TRACE_FATFS = NO
TRACE_AUDIO = NO
#------- END BUILD OPTIONS ---------------------------
# Define programs and commands.
@ -311,6 +321,7 @@ CPPSRC =
INCDIRS = . translations
EXTRAINCDIRS =
LUADEP =
DEBUG_TRACE_BUFFER = NO
# MCU name
ifneq ($(PCB), $(filter $(PCB), STD 9X 9XR STD128 9X128 9XR128 9X2561 9XR2561 GRUVIN9X MEGA2560 SKY9X 9XRPRO TARANIS))
@ -669,9 +680,26 @@ ifeq ($(PCB), TARANIS)
CPPDEFS = -DREV4
endif
ifeq ($(SPORT_FILE_LOG), YES)
DEBUG = YES
CPPDEFS += -DSPORT_FILE_LOG
endif
ifeq ($(TRACE_SD_CARD), YES)
DEBUG = YES
DEBUG_TRACE_BUFFER = YES
CPPDEFS += -DTRACE_SD_CARD
endif
ifeq ($(TRACE_FATFS), YES)
DEBUG = YES
DEBUG_TRACE_BUFFER = YES
CPPDEFS += -DTRACE_FATFS
endif
ifeq ($(TRACE_AUDIO), YES)
DEBUG = YES
DEBUG_TRACE_BUFFER = YES
CPPDEFS += -DTRACE_AUDIO
endif
ifeq ($(DEBUG_TRACE_BUFFER), YES)
CPPDEFS += -DDEBUG_TRACE_BUFFER
endif
LDSCRIPT = targets/taranis/stm32_flash_bl.ld
TRGT = arm-none-eabi-
MCU = cortex-m3

View file

@ -494,21 +494,6 @@ void audioTask(void* pdata)
}
#endif
void AudioQueue::pushBuffer(AudioBuffer *buffer)
{
buffer->state = AUDIO_BUFFER_FILLED;
__disable_irq();
bufferWIdx = nextBufferIdx(bufferWIdx);
if (dacQueue(buffer)) {
buffer->state = AUDIO_BUFFER_PLAYING;
}
__enable_irq();
}
void mixSample(uint16_t * result, int sample, unsigned int fade)
{
*result = limit(0, *result + ((sample >> fade) >> 4), 4095);
@ -762,8 +747,11 @@ void AudioQueue::wakeup()
// push the buffer if needed
if (size > 0) {
__disable_irq();
bufferWIdx = nextBufferIdx(bufferWIdx);
buffer->size = size;
pushBuffer(buffer);
buffer->state = dacQueue(buffer) ? AUDIO_BUFFER_PLAYING : AUDIO_BUFFER_FILLED;
__enable_irq();
}
}
}

View file

@ -199,6 +199,10 @@ class AudioQueue {
AudioBuffer * buffer = &buffers[idx];
if (buffer->state == AUDIO_BUFFER_FILLED) {
buffer->state = AUDIO_BUFFER_PLAYING;
if (idx != bufferRIdx) {
TRACEI_AUDIO_EVENT(1, audio_getNextFilledBuffer_skip, ((uint32_t)bufferRIdx << 8) + idx);
bufferRIdx = idx;
}
return buffer;
}
idx = nextBufferIdx(idx);
@ -239,8 +243,6 @@ class AudioQueue {
else
return NULL;
}
void pushBuffer(AudioBuffer *buffer);
};
extern AudioQueue audioQueue;

View file

@ -116,6 +116,7 @@ else
EXTRAINCDIRS += ../targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc
EXTRAINCDIRS += ../targets/taranis
EXTRAINCDIRS += ../fonts/std
EXTRAINCDIRS += ../
ifeq ($(PCBREV), REV3)
CPPDEFS += -DREV3

View file

@ -38,7 +38,7 @@
#include <stdio.h>
#include <stdarg.h>
#if !defined(SIMU)
#if !defined(SIMU) && defined(DEBUG)
Fifo<512> debugRxFifo;
@ -215,3 +215,65 @@ void debugTask(void* pdata)
}
}
#endif
#if defined(DEBUG_TRACE_BUFFER)
static struct TraceElement traceBuffer[TRACE_BUFFER_LEN];
static uint8_t traceBufferPos;
extern Fifo<512> uart3TxFifo;
gtime_t filltm(gtime_t *t, struct gtm *tp);
void trace_event(enum TraceEvent event, uint32_t data)
{
if (traceBufferPos >= TRACE_BUFFER_LEN) return;
__disable_irq();
struct TraceElement * p = &traceBuffer[traceBufferPos++];
__enable_irq();
p->time = g_rtcTime;
p->time_ms = g_ms100;
p->event = event;
p->data = data;
}
void trace_event_i(enum TraceEvent event, uint32_t data)
{
if (traceBufferPos >= TRACE_BUFFER_LEN) return;
struct TraceElement * p = &traceBuffer[traceBufferPos++];
p->time = g_rtcTime;
p->time_ms = g_ms100;
p->event = event;
p->data = data;
}
const struct TraceElement * getTraceElement(uint16_t idx)
{
if (idx < TRACE_BUFFER_LEN) return &traceBuffer[idx];
return 0;
}
#include "stamp-opentx.h"
void dumpTraceBuffer()
{
TRACE("Dump of Trace Buffer ("VERS_STR " " DATE_STR " " TIME_STR "):");
TRACE("# Time Event Data");
for(int n = 0; n < TRACE_BUFFER_LEN; ++n) {
struct gtm tp;
filltm(&traceBuffer[n].time, &tp);
TRACE_INFO_WP("%02d ", n);
TRACE_INFO_WP("%4d-%02d-%02d,%02d:%02d:%02d.%02d0", tp.tm_year+1900, tp.tm_mon+1, tp.tm_mday, tp.tm_hour, tp.tm_min, tp.tm_sec, traceBuffer[n].time_ms);
TRACE(" %03d 0x%08x", traceBuffer[n].event, traceBuffer[n].data);
if (traceBuffer[n].time == 0 && traceBuffer[n].time_ms == 0) break;
if ((n % 5) == 0) {
while (!uart3TxFifo.empty()) {
CoTickDelay(1);
}
}
}
TRACE("End of Trace Buffer dump");
}
#endif

View file

@ -38,6 +38,7 @@
#define debug_h
#include <inttypes.h>
#include "rtc.h"
#if defined(SIMU)
@ -108,5 +109,88 @@ void debugTask(void* pdata);
#endif
#if defined(DEBUG_TRACE_BUFFER)
#define TRACE_BUFFER_LEN 50
enum TraceEvent {
trace_start = 1,
sd_wait_ready = 10,
sd_rcvr_datablock,
sd_xmit_datablock_wait_ready,
sd_xmit_datablock_rcvr_spi,
sd_send_cmd_wait_ready,
sd_send_cmd_rcvr_spi,
sd_SD_ReadSectors = 16,
sd_disk_read,
sd_SD_WriteSectors,
sd_disk_write,
sd_disk_ioctl_CTRL_SYNC = 20,
sd_disk_ioctl_GET_SECTOR_COUNT,
sd_disk_ioctl_MMC_GET_CSD,
sd_disk_ioctl_MMC_GET_CID,
sd_disk_ioctl_MMC_GET_OCR,
sd_disk_ioctl_MMC_GET_SDSTAT_1,
sd_disk_ioctl_MMC_GET_SDSTAT_2,
sd_spi_reset,
ff_f_write_validate = 30,
ff_f_write_flag,
ff_f_write_clst,
ff_f_write_sync_window,
ff_f_write_disk_write_dirty,
ff_f_write_clust2sect,
ff_f_write_disk_write,
ff_f_write_disk_read,
ff_f_write_move_window,
audio_getNextFilledBuffer_skip = 50,
};
struct TraceElement {
gtime_t time;
uint8_t time_ms;
uint8_t event;
uint32_t data;
};
void trace_event(enum TraceEvent event, uint32_t data);
void trace_event_i(enum TraceEvent event, uint32_t data);
const struct TraceElement * getTraceElement(uint16_t idx);
void dumpTraceBuffer();
#define TRACE_EVENT(condition, event, data) if (condition) { trace_event(event, data); }
#define TRACEI_EVENT(condition, event, data) if (condition) { trace_event_i(event, data); }
#else // #if defined(DEBUG_TRACE_BUFFER)
#define TRACE_EVENT(condition, event, data)
#define TRACEI_EVENT(condition, event, data)
#endif // #if defined(DEBUG_TRACE_BUFFER)
#if defined(TRACE_SD_CARD)
#define TRACE_SD_CARD_EVENT(condition, event, data) TRACE_EVENT(condition, event, data)
#else
#define TRACE_SD_CARD_EVENT(condition, event, data)
#endif
#if defined(TRACE_FATFS)
#define TRACE_FATFS_EVENT(condition, event, data) TRACE_EVENT(condition, event, data)
#else
#define TRACE_FATFS_EVENT(condition, event, data)
#endif
#if defined(TRACE_AUDIO)
#define TRACE_AUDIO_EVENT(condition, event, data) TRACE_EVENT(condition, event, data)
#define TRACEI_AUDIO_EVENT(condition, event, data) TRACEI_EVENT(condition, event, data)
#else
#define TRACE_AUDIO_EVENT(condition, event, data)
#define TRACEI_AUDIO_EVENT(condition, event, data)
#endif
#endif // #ifndef debug_h

View file

@ -141,6 +141,9 @@ void menuModelCustomFunctions(uint8_t event);
void menuStatisticsView(uint8_t event);
void menuStatisticsDebug(uint8_t event);
void menuAboutView(uint8_t event);
#if defined(DEBUG_TRACE_BUFFER)
void menuTraceBuffer(uint8_t event);
#endif
#if !defined(CPUM64)
void displaySlider(coord_t x, coord_t y, uint8_t value, uint8_t max, uint8_t attr);

View file

@ -141,6 +141,13 @@ void menuStatisticsDebug(uint8_t event)
maxMixerDuration = 0;
AUDIO_KEYPAD_UP();
break;
#if defined(DEBUG_TRACE_BUFFER)
case EVT_KEY_FIRST(KEY_UP):
pushMenu(menuTraceBuffer);
return;
#endif
case EVT_KEY_FIRST(KEY_DOWN):
chainMenu(menuStatisticsView);
break;
@ -256,3 +263,58 @@ void menuStatisticsDebug(uint8_t event)
lcd_puts(3*FW, 7*FH+1, STR_MENUTORESET);
lcd_status_line();
}
#if defined(DEBUG_TRACE_BUFFER)
#include "stamp-opentx.h"
void menuTraceBuffer(uint8_t event)
{
switch(event)
{
case EVT_KEY_LONG(KEY_ENTER):
dumpTraceBuffer();
killEvents(event);
break;
}
SIMPLE_SUBMENU("Trace Buffer " VERS_STR, TRACE_BUFFER_LEN);
/* RTC time */
struct gtm t;
gettime(&t);
putsTime(LCD_W+1, 0, t, TIMEBLINK);
uint8_t y = 0;
uint8_t k = 0;
int8_t sub = m_posVert;
lcd_putc(0, FH, '#');
lcd_puts(4*FW, FH, "Time");
lcd_puts(14*FW, FH, "Event");
lcd_puts(20*FW, FH, "Data");
for (uint8_t i=0; i<LCD_LINES-2; i++) {
y = 1 + (i+2)*FH;
k = i+s_pgOfs;
//item
lcd_outdezAtt(0, y, k, LEFT | (sub==k ? INVERS : 0));
const struct TraceElement * te = getTraceElement(k);
if (te) {
//time
putstime_t tme = te->time % SECS_PER_DAY;
putsTimer(4*FW, y, tme, TIMEHOUR|LEFT, TIMEHOUR|LEFT);
//event
lcd_outdezNAtt(14*FW, y, te->event, LEADING0|LEFT, 3);
//data
lcd_putsn (20*FW, y, "0x", 2);
lcd_outhex4(22*FW-2, y, (uint16_t)(te->data >> 16));
lcd_outhex4(25*FW, y, (uint16_t)(te->data & 0xFFFF));
}
}
}
#endif //#if defined(DEBUG_TRACE_BUFFER)

View file

@ -2055,6 +2055,10 @@ void opentxStart()
{
doSplash();
#if defined(DEBUG_TRACE_BUFFER)
trace_event(trace_start, 0x12345678);
#endif
#if defined(PCBSKY9X) && defined(SDCARD) && !defined(SIMU)
for (int i=0; i<500 && !Card_initialized; i++) {
CoTickDelay(1); // 2ms

View file

@ -94,6 +94,16 @@ uint32_t Cmd_A41_resp ;
uint8_t cardType;
uint32_t transSpeed;
#if !defined(BOOT)
static OS_MutexID ioMutex;
#define IO_MUTEX_ENTER() CoEnterMutexSection(ioMutex);
#define IO_MUTEX_LEAVE() CoLeaveMutexSection(ioMutex);
#else
#define IO_MUTEX_ENTER()
#define IO_MUTEX_LEAVE()
#endif //#if !defined(BOOT)
/*-----------------------------------------------------------------------*/
/* Lock / unlock functions */
/*-----------------------------------------------------------------------*/
@ -1278,6 +1288,8 @@ DRESULT disk_read (
if ( sd_card_ready() == 0 ) return RES_NOTRDY;
IO_MUTEX_ENTER();
do {
result = sd_read_block(sector, dma_sd_buffer) ;
if (result) {
@ -1292,12 +1304,15 @@ DRESULT disk_read (
}
} while ( count ) ;
if (!count)
if (!count) {
IO_MUTEX_LEAVE();
return RES_OK;
}
if (++sdErrorCount > 3)
Card_state = SD_ST_ERR;
IO_MUTEX_LEAVE();
return RES_ERROR;
}
@ -1321,6 +1336,8 @@ DRESULT disk_write (
if ( sd_card_ready() == 0 ) return RES_NOTRDY;
IO_MUTEX_ENTER();
do {
while (1) {
@ -1351,12 +1368,15 @@ DRESULT disk_write (
}
} while ( count ) ;
if (!count)
if (!count) {
IO_MUTEX_LEAVE();
return RES_OK;
}
if (++sdErrorCount > 3)
Card_state = SD_ST_ERR;
IO_MUTEX_LEAVE();
return RES_ERROR;
}
@ -1378,6 +1398,8 @@ DRESULT disk_ioctl (
res = RES_ERROR;
IO_MUTEX_ENTER();
if (ctrl == CTRL_POWER) {
#if 0
switch (ptr[0]) {
@ -1452,9 +1474,10 @@ DRESULT disk_ioctl (
res = RES_PARERR;
break;
}
// BSS deselect();
}
IO_MUTEX_LEAVE();
return res;
}

View file

@ -40,6 +40,7 @@
#include "../../FatFs/ff.h"
#include "../../CoOS/kernel/CoOS.h"
#include "hal.h"
#include "debug.h"
/* Definitions for MMC/SDC command */
#define CMD0 (0x40+0) /* GO_IDLE_STATE */
@ -118,6 +119,16 @@ int ff_del_syncobj (_SYNC_t mutex)
}
#endif
#if !defined(BOOT)
static OS_MutexID ioMutex;
#define IO_MUTEX_ENTER() CoEnterMutexSection(ioMutex);
#define IO_MUTEX_LEAVE() CoLeaveMutexSection(ioMutex);
#else
#define IO_MUTEX_ENTER()
#define IO_MUTEX_LEAVE()
#endif //#if !defined(BOOT)
static const DWORD socket_state_mask_cp = (1 << 0);
static const DWORD socket_state_mask_wp = (1 << 1);
@ -229,28 +240,25 @@ BYTE rcvr_spi (void)
/*-----------------------------------------------------------------------*/
/* Wait for card ready */
/*-----------------------------------------------------------------------*/
static
BYTE wait_ready (void)
static BYTE wait_ready (void)
{
BYTE res;
Timer2 = 50; /* Wait for ready in timeout of 500ms */
rcvr_spi();
do
do {
res = rcvr_spi();
while ((res != 0xFF) && Timer2);
} while ((res != 0xFF) && Timer2);
return res;
}
static void spi_reset()
{
for (int n=0; n<520; ++n) {
stm32_spi_rw(0xFF);
}
TRACE_SD_CARD_EVENT(1, sd_spi_reset, 0);
}
/*-----------------------------------------------------------------------*/
@ -482,6 +490,7 @@ BOOL rcvr_datablock (
token = rcvr_spi();
} while ((token == 0xFF) && Timer1);
if(token != 0xFE) {
TRACE_SD_CARD_EVENT(1, sd_rcvr_datablock, ((uint32_t)(Timer1) << 24) + ((uint32_t)(btr) << 8) + token);
spi_reset();
return FALSE; /* If not valid data token, return with error */
}
@ -523,6 +532,7 @@ BOOL xmit_datablock (
#endif
if (wait_ready() != 0xFF) {
TRACE_SD_CARD_EVENT(1, sd_xmit_datablock_wait_ready, token);
spi_reset();
return FALSE;
}
@ -552,17 +562,19 @@ BOOL xmit_datablock (
Timer2 = DATA_RESPONSE_TIMEOUT;
do {
resp = rcvr_spi(); /* Receive data response */
if ((resp & 0x1F) == 0x05) { /* If not accepted, return with error */
if ((resp & 0x1F) == 0x05) {
TRACE_SD_CARD_EVENT((Timer2 != DATA_RESPONSE_TIMEOUT), sd_xmit_datablock_rcvr_spi, ((uint32_t)(Timer2) << 16) + ((uint32_t)(resp) << 8) + token);
return TRUE;
}
if (resp != 0xFF) {
TRACE_SD_CARD_EVENT(1, sd_xmit_datablock_rcvr_spi, ((uint32_t)(Timer2) << 16) + ((uint32_t)(resp) << 8) + token);
spi_reset();
return FALSE;
}
} while (Timer2);
TRACE_SD_CARD_EVENT(1, sd_xmit_datablock_rcvr_spi, ((uint32_t)(Timer2) << 16) + ((uint32_t)(resp) << 8) + token);
return FALSE;
}
return TRUE;
}
@ -589,6 +601,7 @@ BYTE send_cmd (
/* Select the card and wait for ready */
SELECT();
if (wait_ready() != 0xFF) {
TRACE_SD_CARD_EVENT(1, sd_send_cmd_wait_ready, cmd);
spi_reset();
return 0xFF;
}
@ -612,6 +625,8 @@ BYTE send_cmd (
res = rcvr_spi();
} while ((res & 0x80) && --n);
TRACE_SD_CARD_EVENT((res > 1), sd_send_cmd_rcvr_spi, ((uint32_t)(n) << 16) + ((uint32_t)(res) << 8) + cmd);
return res; /* Return with the response value */
}
@ -637,6 +652,8 @@ DSTATUS disk_initialize (
if (drv) return STA_NOINIT; /* Supports only single drive */
if (Stat & STA_NODISK) return Stat; /* No card in the socket */
IO_MUTEX_ENTER();
power_on(); /* Force socket power on and initialize interface */
interface_speed(INTERFACE_SLOW);
for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */
@ -674,6 +691,8 @@ DSTATUS disk_initialize (
power_off();
}
IO_MUTEX_LEAVE();
return Stat;
}
@ -695,11 +714,12 @@ DSTATUS disk_status (
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
// TODO quick & dirty
int8_t SD_ReadSectors(uint8_t *buff, uint32_t sector, uint32_t count)
{
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
IO_MUTEX_ENTER();
if (count == 1) { /* Single block read */
if (send_cmd(CMD17, sector) == 0) { /* READ_SINGLE_BLOCK */
if (rcvr_datablock(buff, 512)) {
@ -724,8 +744,10 @@ int8_t SD_ReadSectors(uint8_t *buff, uint32_t sector, uint32_t count)
spi_reset();
}
}
release_spi();
TRACE_SD_CARD_EVENT((count != 0), sd_SD_ReadSectors, (count << 24) + ((sector/((CardType & CT_BLOCK) ? 1 : 512)) & 0x00FFFFFF));
IO_MUTEX_LEAVE();
return count ? -1 : 0;
}
@ -740,6 +762,7 @@ DRESULT disk_read (
if (drv || !count) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
int8_t res = SD_ReadSectors(buff, sector, count);
TRACE_SD_CARD_EVENT((res != 0), sd_disk_read, (count << 24) + (sector & 0x00FFFFFF));
return (res != 0) ? RES_ERROR : RES_OK;
}
@ -749,10 +772,12 @@ DRESULT disk_read (
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
// TODO quick & dirty
int8_t SD_WriteSectors(const uint8_t *buff, uint32_t sector, uint32_t count)
{
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
IO_MUTEX_ENTER();
if (count == 1) { /* Single block write */
if (send_cmd(CMD24, sector) == 0) { /* WRITE_BLOCK */
if (xmit_datablock(buff, 0xFE)) {
@ -763,7 +788,7 @@ int8_t SD_WriteSectors(const uint8_t *buff, uint32_t sector, uint32_t count)
spi_reset();
}
}
else {
else { /* Multiple block write */
if (CardType & CT_SDC) send_cmd(ACMD23, count);
if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */
do {
@ -777,8 +802,10 @@ int8_t SD_WriteSectors(const uint8_t *buff, uint32_t sector, uint32_t count)
spi_reset();
}
}
release_spi();
TRACE_SD_CARD_EVENT((count != 0), sd_SD_WriteSectors, (count << 24) + ((sector/((CardType & CT_BLOCK) ? 1 : 512)) & 0x00FFFFFF));
IO_MUTEX_LEAVE();
return count ? -1 : 0;
}
@ -796,6 +823,7 @@ DRESULT disk_write (
if (Stat & STA_NOINIT) return RES_NOTRDY;
if (Stat & STA_PROTECT) return RES_WRPRT;
int8_t res = SD_WriteSectors(buff, sector, count);
TRACE_SD_CARD_EVENT((res != 0), sd_disk_write, (count << 24) + (sector & 0x00FFFFFF));
return (res != 0) ? RES_ERROR : RES_OK;
}
#endif /* _READONLY == 0 */
@ -820,6 +848,8 @@ DRESULT disk_ioctl (
res = RES_ERROR;
IO_MUTEX_ENTER();
if (ctrl == CTRL_POWER) {
switch (*ptr) {
case 0: /* Sub control code == 0 (POWER_OFF) */
@ -840,13 +870,20 @@ DRESULT disk_ioctl (
}
}
else {
if (Stat & STA_NOINIT) return RES_NOTRDY;
if (Stat & STA_NOINIT) {
IO_MUTEX_LEAVE();
return RES_NOTRDY;
}
switch (ctrl) {
case CTRL_SYNC : /* Make sure that no pending write process */
SELECT();
if (wait_ready() == 0xFF)
if (wait_ready() == 0xFF) {
res = RES_OK;
}
else {
TRACE_SD_CARD_EVENT(1, sd_disk_ioctl_CTRL_SYNC, 0);
}
break;
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
@ -861,6 +898,9 @@ DRESULT disk_ioctl (
}
res = RES_OK;
}
else {
TRACE_SD_CARD_EVENT(1, sd_disk_ioctl_GET_SECTOR_COUNT, 0);
}
break;
case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */
@ -897,14 +937,22 @@ DRESULT disk_ioctl (
case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */
if (send_cmd(CMD9, 0) == 0 /* READ_CSD */
&& rcvr_datablock(ptr, 16))
&& rcvr_datablock(ptr, 16)) {
res = RES_OK;
}
else {
TRACE_SD_CARD_EVENT(1, sd_disk_ioctl_MMC_GET_CSD, 0);
}
break;
case MMC_GET_CID : /* Receive CID as a data block (16 bytes) */
if (send_cmd(CMD10, 0) == 0 /* READ_CID */
&& rcvr_datablock(ptr, 16))
&& rcvr_datablock(ptr, 16)) {
res = RES_OK;
}
else {
TRACE_SD_CARD_EVENT(1, sd_disk_ioctl_MMC_GET_CID, 0);
}
break;
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
@ -912,14 +960,24 @@ DRESULT disk_ioctl (
for (n = 4; n; n--) *ptr++ = rcvr_spi();
res = RES_OK;
}
else {
TRACE_SD_CARD_EVENT(1, sd_disk_ioctl_MMC_GET_OCR, 0);
}
break;
case MMC_GET_SDSTAT : /* Receive SD status as a data block (64 bytes) */
if (send_cmd(ACMD13, 0) == 0) { /* SD_STATUS */
rcvr_spi();
if (rcvr_datablock(ptr, 64))
if (rcvr_datablock(ptr, 64)) {
res = RES_OK;
}
else {
TRACE_SD_CARD_EVENT(1, sd_disk_ioctl_MMC_GET_SDSTAT_1, 0);
}
}
else {
TRACE_SD_CARD_EVENT(1, sd_disk_ioctl_MMC_GET_SDSTAT_2, 0);
}
break;
default:
@ -929,6 +987,8 @@ DRESULT disk_ioctl (
release_spi();
}
IO_MUTEX_LEAVE();
return res;
}
@ -988,6 +1048,12 @@ void sdInit(void)
// TODO shouldn't be there!
void sdInit(void)
{
ioMutex = CoCreateMutex();
if (ioMutex >= CFG_MAX_MUTEX ) {
//sd error
return;
}
if (f_mount(0, &g_FATFS_Obj) == FR_OK) {
referenceSystemAudioFiles();

View file

@ -286,7 +286,7 @@ void telemetryWakeup()
#if defined(PCBTARANIS)
uint8_t data;
#if defined(DEBUG) && !defined(SIMU)
#if defined(SPORT_FILE_LOG) && !defined(SIMU)
static tmr10ms_t lastTime = 0;
tmr10ms_t newTime = get_tmr10ms();
struct gtm utm;