ioMutex removed

This commit is contained in:
bsongis
2014-11-19 07:34:52 +01:00
parent 72f58e0b0b
commit e322fba277
2 changed files with 12 additions and 52 deletions
+6 -23
View File
@@ -94,22 +94,16 @@ uint32_t Cmd_A41_resp ;
uint8_t cardType; uint8_t cardType;
uint32_t transSpeed; 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 */ /* Lock / unlock functions */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#if !defined(BOOT)
static OS_MutexID ioMutex;
volatile int mutexCheck = 0;
int ff_cre_syncobj (BYTE vol, _SYNC_t *mutex) int ff_cre_syncobj (BYTE vol, _SYNC_t *mutex)
{ {
*mutex = CoCreateMutex(); *mutex = ioMutex;
return 1; return 1;
} }
@@ -128,6 +122,7 @@ int ff_del_syncobj (_SYNC_t mutex)
{ {
return 1; return 1;
} }
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/// Get Trans Speed Value (Kbit/s) /// Get Trans Speed Value (Kbit/s)
@@ -1288,8 +1283,6 @@ DRESULT disk_read (
if ( sd_card_ready() == 0 ) return RES_NOTRDY; if ( sd_card_ready() == 0 ) return RES_NOTRDY;
IO_MUTEX_ENTER();
do { do {
result = sd_read_block(sector, dma_sd_buffer) ; result = sd_read_block(sector, dma_sd_buffer) ;
if (result) { if (result) {
@@ -1304,8 +1297,6 @@ DRESULT disk_read (
} }
} while ( count ) ; } while ( count ) ;
IO_MUTEX_LEAVE();
if (!count) if (!count)
return RES_OK; return RES_OK;
@@ -1335,8 +1326,6 @@ DRESULT disk_write (
if ( sd_card_ready() == 0 ) return RES_NOTRDY; if ( sd_card_ready() == 0 ) return RES_NOTRDY;
IO_MUTEX_ENTER();
do { do {
while (1) { while (1) {
@@ -1368,14 +1357,12 @@ DRESULT disk_write (
} while ( count ) ; } while ( count ) ;
if (!count) { if (!count) {
IO_MUTEX_LEAVE();
return RES_OK; return RES_OK;
} }
if (++sdErrorCount > 3) if (++sdErrorCount > 3)
Card_state = SD_ST_ERR; Card_state = SD_ST_ERR;
IO_MUTEX_LEAVE();
return RES_ERROR; return RES_ERROR;
} }
@@ -1397,8 +1384,6 @@ DRESULT disk_ioctl (
res = RES_ERROR; res = RES_ERROR;
IO_MUTEX_ENTER();
if (ctrl == CTRL_POWER) { if (ctrl == CTRL_POWER) {
#if 0 #if 0
switch (ptr[0]) { switch (ptr[0]) {
@@ -1476,7 +1461,5 @@ DRESULT disk_ioctl (
// BSS deselect(); // BSS deselect();
} }
IO_MUTEX_LEAVE();
return res; return res;
} }
+6 -29
View File
@@ -96,9 +96,12 @@ uint32_t transSpeed; */
/* Lock / unlock functions */ /* Lock / unlock functions */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#if !defined(BOOT) #if !defined(BOOT)
static OS_MutexID ioMutex;
volatile int mutexCheck = 0;
int ff_cre_syncobj (BYTE vol, _SYNC_t *mutex) int ff_cre_syncobj (BYTE vol, _SYNC_t *mutex)
{ {
*mutex = CoCreateMutex(); *mutex = ioMutex;
return 1; return 1;
} }
@@ -119,16 +122,6 @@ int ff_del_syncobj (_SYNC_t mutex)
} }
#endif #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_cp = (1 << 0);
static const DWORD socket_state_mask_wp = (1 << 1); static const DWORD socket_state_mask_wp = (1 << 1);
@@ -652,8 +645,6 @@ DSTATUS disk_initialize (
if (drv) return STA_NOINIT; /* Supports only single drive */ if (drv) return STA_NOINIT; /* Supports only single drive */
if (Stat & STA_NODISK) return Stat; /* No card in the socket */ if (Stat & STA_NODISK) return Stat; /* No card in the socket */
IO_MUTEX_ENTER();
power_on(); /* Force socket power on and initialize interface */ power_on(); /* Force socket power on and initialize interface */
interface_speed(INTERFACE_SLOW); interface_speed(INTERFACE_SLOW);
for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */ for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */
@@ -687,12 +678,11 @@ DSTATUS disk_initialize (
if (ty) { /* Initialization succeeded */ if (ty) { /* Initialization succeeded */
Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */ Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
interface_speed(INTERFACE_FAST); interface_speed(INTERFACE_FAST);
} else { /* Initialization failed */ }
else { /* Initialization failed */
power_off(); power_off();
} }
IO_MUTEX_LEAVE();
return Stat; return Stat;
} }
@@ -718,8 +708,6 @@ 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 */ if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
IO_MUTEX_ENTER();
if (count == 1) { /* Single block read */ if (count == 1) { /* Single block read */
if (send_cmd(CMD17, sector) == 0) { /* READ_SINGLE_BLOCK */ if (send_cmd(CMD17, sector) == 0) { /* READ_SINGLE_BLOCK */
if (rcvr_datablock(buff, 512)) { if (rcvr_datablock(buff, 512)) {
@@ -747,8 +735,6 @@ int8_t SD_ReadSectors(uint8_t *buff, uint32_t sector, uint32_t count)
release_spi(); release_spi();
TRACE_SD_CARD_EVENT((count != 0), sd_SD_ReadSectors, (count << 24) + ((sector/((CardType & CT_BLOCK) ? 1 : 512)) & 0x00FFFFFF)); 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; return count ? -1 : 0;
} }
@@ -776,8 +762,6 @@ 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 */ if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
IO_MUTEX_ENTER();
if (count == 1) { /* Single block write */ if (count == 1) { /* Single block write */
if (send_cmd(CMD24, sector) == 0) { /* WRITE_BLOCK */ if (send_cmd(CMD24, sector) == 0) { /* WRITE_BLOCK */
if (xmit_datablock(buff, 0xFE)) { if (xmit_datablock(buff, 0xFE)) {
@@ -805,8 +789,6 @@ int8_t SD_WriteSectors(const uint8_t *buff, uint32_t sector, uint32_t count)
release_spi(); release_spi();
TRACE_SD_CARD_EVENT((count != 0), sd_SD_WriteSectors, (count << 24) + ((sector/((CardType & CT_BLOCK) ? 1 : 512)) & 0x00FFFFFF)); 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; return count ? -1 : 0;
} }
@@ -848,8 +830,6 @@ DRESULT disk_ioctl (
res = RES_ERROR; res = RES_ERROR;
IO_MUTEX_ENTER();
if (ctrl == CTRL_POWER) { if (ctrl == CTRL_POWER) {
switch (*ptr) { switch (*ptr) {
case 0: /* Sub control code == 0 (POWER_OFF) */ case 0: /* Sub control code == 0 (POWER_OFF) */
@@ -871,7 +851,6 @@ DRESULT disk_ioctl (
} }
else { else {
if (Stat & STA_NOINIT) { if (Stat & STA_NOINIT) {
IO_MUTEX_LEAVE();
return RES_NOTRDY; return RES_NOTRDY;
} }
@@ -987,8 +966,6 @@ DRESULT disk_ioctl (
release_spi(); release_spi();
} }
IO_MUTEX_LEAVE();
return res; return res;
} }