mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 16:55:20 +03:00
Re #1610:
* 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:
parent
c4c7fed727
commit
874156122d
12 changed files with 901 additions and 578 deletions
|
@ -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))
|
||||
|
@ -645,13 +656,13 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO))
|
|||
endif
|
||||
|
||||
ifeq ($(BLUETOOTH), YES)
|
||||
CPPDEFS += -DBLUETOOTH
|
||||
CPPSRC += targets/sky9x/bluetooth.cpp
|
||||
CPPDEFS += -DBLUETOOTH
|
||||
CPPSRC += targets/sky9x/bluetooth.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG), YES)
|
||||
CPPSRC += debug.cpp
|
||||
SRC += targets/sky9x/syscalls.c
|
||||
SRC += targets/sky9x/syscalls.c
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -669,9 +680,26 @@ ifeq ($(PCB), TARANIS)
|
|||
CPPDEFS = -DREV4
|
||||
endif
|
||||
ifeq ($(SPORT_FILE_LOG), YES)
|
||||
DEBUG = YES
|
||||
CPPDEFS += -DSPORT_FILE_LOG
|
||||
endif
|
||||
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
|
||||
|
@ -990,7 +1018,7 @@ endif
|
|||
ifeq ($(EXT), $(filter $(EXT), FRSKY FRSKY_SPORT TELEMETREZ))
|
||||
CPPDEFS += -DFRSKY
|
||||
ifeq ($(EXT), FRSKY_SPORT)
|
||||
CPPSRC += telemetry/frsky.cpp telemetry/frsky_sport.cpp telemetry/frsky_d.cpp
|
||||
CPPSRC += telemetry/frsky.cpp telemetry/frsky_sport.cpp telemetry/frsky_d.cpp
|
||||
CPPDEFS += -DFRSKY_SPORT
|
||||
else
|
||||
CPPSRC += telemetry/frsky.cpp telemetry/frsky_d.cpp
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -1272,33 +1282,38 @@ DRESULT disk_read (
|
|||
BYTE count /* Sector count (1..255) */
|
||||
)
|
||||
{
|
||||
uint32_t result ;
|
||||
uint32_t result ;
|
||||
|
||||
if (drv || !count) return RES_PARERR;
|
||||
if (drv || !count) return RES_PARERR;
|
||||
|
||||
if ( sd_card_ready() == 0 ) return RES_NOTRDY;
|
||||
if ( sd_card_ready() == 0 ) return RES_NOTRDY;
|
||||
|
||||
do {
|
||||
result = sd_read_block(sector, dma_sd_buffer) ;
|
||||
if (result) {
|
||||
memcpy(buff, dma_sd_buffer, 512);
|
||||
sector += 1 ;
|
||||
buff += 512 ;
|
||||
count -= 1 ;
|
||||
}
|
||||
else {
|
||||
count = 1 ; // Flag error
|
||||
break ;
|
||||
}
|
||||
} while ( count ) ;
|
||||
IO_MUTEX_ENTER();
|
||||
|
||||
if (!count)
|
||||
return RES_OK;
|
||||
do {
|
||||
result = sd_read_block(sector, dma_sd_buffer) ;
|
||||
if (result) {
|
||||
memcpy(buff, dma_sd_buffer, 512);
|
||||
sector += 1 ;
|
||||
buff += 512 ;
|
||||
count -= 1 ;
|
||||
}
|
||||
else {
|
||||
count = 1 ; // Flag error
|
||||
break ;
|
||||
}
|
||||
} while ( count ) ;
|
||||
|
||||
if (++sdErrorCount > 3)
|
||||
Card_state = SD_ST_ERR;
|
||||
if (!count) {
|
||||
IO_MUTEX_LEAVE();
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
return RES_ERROR;
|
||||
if (++sdErrorCount > 3)
|
||||
Card_state = SD_ST_ERR;
|
||||
|
||||
IO_MUTEX_LEAVE();
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1315,49 +1330,54 @@ DRESULT disk_write (
|
|||
BYTE count /* Sector count (1..255) */
|
||||
)
|
||||
{
|
||||
uint32_t result ;
|
||||
uint32_t result ;
|
||||
|
||||
if (drv || !count) return RES_PARERR;
|
||||
if (drv || !count) return RES_PARERR;
|
||||
|
||||
if ( sd_card_ready() == 0 ) return RES_NOTRDY;
|
||||
if ( sd_card_ready() == 0 ) return RES_NOTRDY;
|
||||
|
||||
do {
|
||||
IO_MUTEX_ENTER();
|
||||
|
||||
while (1) {
|
||||
do {
|
||||
|
||||
memcpy(dma_sd_buffer, buff, 512);
|
||||
while (1) {
|
||||
|
||||
result = sd_write_block(sector, dma_sd_buffer) ;
|
||||
memcpy(dma_sd_buffer, buff, 512);
|
||||
|
||||
sd_read_block(sector, dma_sd_buffer) ;
|
||||
result = sd_write_block(sector, dma_sd_buffer) ;
|
||||
|
||||
if (!memcmp(dma_sd_buffer, buff, 512))
|
||||
break;
|
||||
else {
|
||||
TRACE_ERROR("Block %d ko SR=%.2X\r\n", sector, HSMCI->HSMCI_SR);
|
||||
// DUMP(buff, 512);
|
||||
// DUMP(copy, 512);
|
||||
}
|
||||
}
|
||||
sd_read_block(sector, dma_sd_buffer) ;
|
||||
|
||||
if (result) {
|
||||
sector += 1 ;
|
||||
buff += 512 ;
|
||||
count -= 1 ;
|
||||
}
|
||||
else {
|
||||
count = 1 ; // Flag error
|
||||
break ;
|
||||
}
|
||||
} while ( count ) ;
|
||||
if (!memcmp(dma_sd_buffer, buff, 512))
|
||||
break;
|
||||
else {
|
||||
TRACE_ERROR("Block %d ko SR=%.2X\r\n", sector, HSMCI->HSMCI_SR);
|
||||
// DUMP(buff, 512);
|
||||
// DUMP(copy, 512);
|
||||
}
|
||||
}
|
||||
|
||||
if (!count)
|
||||
return RES_OK;
|
||||
if (result) {
|
||||
sector += 1 ;
|
||||
buff += 512 ;
|
||||
count -= 1 ;
|
||||
}
|
||||
else {
|
||||
count = 1 ; // Flag error
|
||||
break ;
|
||||
}
|
||||
} while ( count ) ;
|
||||
|
||||
if (++sdErrorCount > 3)
|
||||
Card_state = SD_ST_ERR;
|
||||
if (!count) {
|
||||
IO_MUTEX_LEAVE();
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
return RES_ERROR;
|
||||
if (++sdErrorCount > 3)
|
||||
Card_state = SD_ST_ERR;
|
||||
|
||||
IO_MUTEX_LEAVE();
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1372,89 +1392,92 @@ DRESULT disk_ioctl (
|
|||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
DRESULT res;
|
||||
|
||||
if (drv) return RES_PARERR;
|
||||
if (drv) return RES_PARERR;
|
||||
|
||||
res = RES_ERROR;
|
||||
res = RES_ERROR;
|
||||
|
||||
if (ctrl == CTRL_POWER) {
|
||||
IO_MUTEX_ENTER();
|
||||
|
||||
if (ctrl == CTRL_POWER) {
|
||||
#if 0
|
||||
switch (ptr[0]) {
|
||||
case 0: /* Sub control code (POWER_OFF) */
|
||||
power_off(); /* Power off */
|
||||
res = RES_OK;
|
||||
break;
|
||||
case 1: /* Sub control code (POWER_GET) */
|
||||
ptr[1] = (BYTE)power_status();
|
||||
res = RES_OK;
|
||||
break;
|
||||
default :
|
||||
res = RES_PARERR;
|
||||
}
|
||||
switch (ptr[0]) {
|
||||
case 0: /* Sub control code (POWER_OFF) */
|
||||
power_off(); /* Power off */
|
||||
res = RES_OK;
|
||||
break;
|
||||
case 1: /* Sub control code (POWER_GET) */
|
||||
ptr[1] = (BYTE)power_status();
|
||||
res = RES_OK;
|
||||
break;
|
||||
default :
|
||||
res = RES_PARERR;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
switch (ctrl) {
|
||||
case CTRL_SYNC : /* Make sure that no pending write process. Do not remove this or written sector might not left updated. */
|
||||
res = RES_OK;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
switch (ctrl) {
|
||||
case CTRL_SYNC : /* Make sure that no pending write process. Do not remove this or written sector might not left updated. */
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
|
||||
*(DWORD*)buff = SD_GET_BLOCKNR();
|
||||
res = RES_OK;
|
||||
break;
|
||||
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
|
||||
*(DWORD*)buff = SD_GET_BLOCKNR();
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */
|
||||
*(WORD*)buff = 512;
|
||||
res = RES_OK;
|
||||
break;
|
||||
case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */
|
||||
*(WORD*)buff = 512;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */
|
||||
*(WORD*)buff = 1;
|
||||
res = RES_OK;
|
||||
break;
|
||||
case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */
|
||||
*(WORD*)buff = 1;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case MMC_GET_TYPE : /* Get card type flags (1 byte) */
|
||||
*ptr = CardType;
|
||||
res = RES_OK;
|
||||
break;
|
||||
case MMC_GET_TYPE : /* Get card type flags (1 byte) */
|
||||
*ptr = CardType;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */
|
||||
if (send_cmd(CMD9, 0) == 0 /* READ_CSD */
|
||||
&& rcvr_datablock(ptr, 16))
|
||||
res = RES_OK;
|
||||
break;
|
||||
case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */
|
||||
if (send_cmd(CMD9, 0) == 0 /* READ_CSD */
|
||||
&& rcvr_datablock(ptr, 16))
|
||||
res = RES_OK;
|
||||
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))
|
||||
res = RES_OK;
|
||||
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))
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
|
||||
if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
|
||||
for (n = 4; n; n--) *ptr++ = rcvr_spi();
|
||||
res = RES_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
case MMC_GET_SDSTAT : /* Receive SD statsu as a data block (64 bytes) */
|
||||
if (send_cmd(ACMD13, 0) == 0) { /* SD_STATUS */
|
||||
rcvr_spi();
|
||||
if (rcvr_datablock(ptr, 64))
|
||||
res = RES_OK;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
break;
|
||||
}
|
||||
|
||||
// BSS deselect();
|
||||
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
|
||||
if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
|
||||
for (n = 4; n; n--) *ptr++ = rcvr_spi();
|
||||
res = RES_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
return res;
|
||||
case MMC_GET_SDSTAT : /* Receive SD statsu as a data block (64 bytes) */
|
||||
if (send_cmd(ACMD13, 0) == 0) { /* SD_STATUS */
|
||||
rcvr_spi();
|
||||
if (rcvr_datablock(ptr, 64))
|
||||
res = RES_OK;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
break;
|
||||
}
|
||||
// BSS deselect();
|
||||
}
|
||||
|
||||
IO_MUTEX_LEAVE();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue