From 9b147c25513490e959acf299a0fed9beaee04457 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 5 Jun 2011 07:05:29 +0000 Subject: SDC driver state machine improved. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3027 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/dox/sdc.dox | 6 ++++-- os/hal/src/sdc.c | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'os') diff --git a/os/hal/dox/sdc.dox b/os/hal/dox/sdc.dox index 2a18977ff..df88796af 100644 --- a/os/hal/dox/sdc.dox +++ b/os/hal/dox/sdc.dox @@ -52,9 +52,10 @@ stop -> stop [label="\nsdcStop()"]; stop -> ready [label="\nsdcStart()"]; ready -> stop [label="\nsdcStop()"]; - ready -> ready [label="\nsdcStart()"]; + ready -> ready [label="\nsdcStart()\nsdcDisconnect()"]; ready -> connecting [label="\nsdcConnect()"]; connecting -> active [label="\nconnection\nsuccessful"]; + connecting -> active [label="\nsdcConnect()", dir="back"]; connecting -> ready [label="\nconnection\nfailed"]; disconnecting -> active [label="\nsdcDisconnect()", dir="back"]; ready -> disconnecting [label="\ndisconnection\nfinished", dir="back"]; @@ -85,9 +86,10 @@ stop -> stop [label="\nsdcStop()"]; stop -> ready [label="\nsdcStart()"]; ready -> stop [label="\nsdcStop()"]; - ready -> ready [label="\nsdcStart()"]; + ready -> ready [label="\nsdcStart()\nsdcDisconnect()"]; ready -> connecting [label="\nsdcConnect()"]; connecting -> active [label="\nconnection\nsuccessful"]; + connecting -> active [label="\nsdcConnect()", dir="back"]; connecting -> ready [label="\nconnection\nfailed"]; disconnecting -> active [label="\nsdcDisconnect()", dir="back"]; ready -> disconnecting [label="\ndisconnection\nfinished", dir="back"]; diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index a7a39c268..08c667df4 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -169,7 +169,8 @@ bool_t sdcConnect(SDCDriver *sdcp) { chDbgCheck(sdcp != NULL, "sdcConnect"); chSysLock(); - chDbgAssert(sdcp->state == SDC_READY, "mmcConnect(), #1", "invalid state"); + chDbgAssert((sdcp->state == SDC_READY) || (sdcp->state == SDC_ACTIVE), + "mmcConnect(), #1", "invalid state"); sdcp->state = SDC_CONNECTING; chSysUnlock(); @@ -302,6 +303,10 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, "sdcDisconnect(), #1", "invalid state"); + if (sdcp->state == SDC_READY) { + chSysUnlock(); + return FALSE; + } sdcp->state = SDC_DISCONNECTING; chSysUnlock(); -- cgit v1.2.3