git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2255 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2010-10-14 12:16:41 +00:00
parent 4fab7c06d1
commit a122640ac6
3 changed files with 55 additions and 51 deletions

View File

@ -440,44 +440,54 @@
digraph example { digraph example {
size="5, 7"; size="5, 7";
rankdir="LR"; rankdir="LR";
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
edge [fontname=Helvetica, fontsize=8]; edge [fontname=Helvetica, fontsize=8];
uninit [label="CAN_UNINIT", style="bold"];
stop [label="CAN_STOP\nLow Power"]; stop [label="CAN_STOP\nLow Power"];
uninit [label="CAN_UNINIT", style="bold"];
starting [label="CAN_STARTING\nInitializing"];
ready [label="CAN_READY\nClock Enabled"]; ready [label="CAN_READY\nClock Enabled"];
sleep [label="CAN_SLEEP\nLow Power"]; sleep [label="CAN_SLEEP\nLow Power"];
uninit -> stop [label="canInit()"];
stop -> stop [label="canStop()"]; uninit -> stop [label=" canInit()", constraint=false];
stop -> ready [label="canStart()"]; stop -> stop [label="\ncanStop()"];
ready -> stop [label="canStop()"]; stop -> ready [label="\ncanStart()\n(fast implementation)"];
ready -> ready [label="canReceive()\ncanTransmit()"]; stop -> starting [label="\ncanStart()\n(slow implementation)"];
ready -> ready [label="canStart()"]; starting -> starting [label="\ncanStart()\n(other thread)"];
ready -> sleep [label="canSleep()"]; starting -> ready [label="\ninitialization complete\n(all threads)"];
sleep -> sleep [label="canSleep()"]; ready -> stop [label="\ncanStop()"];
sleep -> ready [label="canWakeup()"]; ready -> ready [label="\ncanStart()\ncanReceive()\ncanTransmit()"];
sleep -> ready [label="wakeup event"]; ready -> sleep [label="\ncanSleep()"];
sleep -> sleep [label="\ncanSleep()"];
sleep -> ready [label="\ncanWakeup()"];
sleep -> ready [label="\nhardware\nwakeup event"];
} }
* @enddot * @enddot
* @else * @else
* @dot * @dot
digraph example { digraph example {
rankdir="LR"; rankdir="LR";
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
edge [fontname=Helvetica, fontsize=8]; edge [fontname=Helvetica, fontsize=8];
uninit [label="CAN_UNINIT", style="bold"];
stop [label="CAN_STOP\nLow Power"]; stop [label="CAN_STOP\nLow Power"];
uninit [label="CAN_UNINIT", style="bold"];
starting [label="CAN_STARTING\nInitializing"];
ready [label="CAN_READY\nClock Enabled"]; ready [label="CAN_READY\nClock Enabled"];
sleep [label="CAN_SLEEP\nLow Power"]; sleep [label="CAN_SLEEP\nLow Power"];
uninit -> stop [label="canInit()"];
stop -> stop [label="canStop()"]; uninit -> stop [label=" canInit()", constraint=false];
stop -> ready [label="canStart()"]; stop -> stop [label="\ncanStop()"];
ready -> stop [label="canStop()"]; stop -> ready [label="\ncanStart()\n(fast implementation)"];
ready -> ready [label="canReceive()\ncanTransmit()"]; stop -> starting [label="\ncanStart()\n(slow implementation)"];
ready -> ready [label="canStart()"]; starting -> starting [label="\ncanStart()\n(other thread)"];
ready -> sleep [label="canSleep()"]; starting -> ready [label="\ninitialization complete\n(all threads)"];
sleep -> sleep [label="canSleep()"]; ready -> stop [label="\ncanStop()"];
sleep -> ready [label="canWakeup()"]; ready -> ready [label="\ncanStart()\ncanReceive()\ncanTransmit()"];
sleep -> ready [label="wakeup event"]; ready -> sleep [label="\ncanSleep()"];
sleep -> sleep [label="\ncanSleep()"];
sleep -> ready [label="\ncanWakeup()"];
sleep -> ready [label="\nhardware\nwakeup event"];
} }
* @enddot * @enddot
* @endif * @endif
@ -510,7 +520,7 @@
* @dot * @dot
digraph example { digraph example {
rankdir="LR"; rankdir="LR";
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
edge [fontname=Helvetica, fontsize=8]; edge [fontname=Helvetica, fontsize=8];
uninit [label="PWM_UNINIT", style="bold"]; uninit [label="PWM_UNINIT", style="bold"];
stop [label="PWM_STOP\nLow Power"]; stop [label="PWM_STOP\nLow Power"];
@ -592,7 +602,7 @@
digraph example { digraph example {
size="5, 7"; size="5, 7";
rankdir="LR"; rankdir="LR";
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
edge [fontname=Helvetica, fontsize=8]; edge [fontname=Helvetica, fontsize=8];
any [label="Any State"]; any [label="Any State"];
@ -632,7 +642,7 @@
* @dot * @dot
digraph example { digraph example {
rankdir="LR"; rankdir="LR";
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
edge [fontname=Helvetica, fontsize=8]; edge [fontname=Helvetica, fontsize=8];
any [label="Any State"]; any [label="Any State"];
@ -711,7 +721,7 @@
* @dot * @dot
digraph example { digraph example {
rankdir="LR"; rankdir="LR";
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
edge [fontname=Helvetica, fontsize=8]; edge [fontname=Helvetica, fontsize=8];
uninit [label="UART_UNINIT", style="bold"]; uninit [label="UART_UNINIT", style="bold"];
@ -734,7 +744,7 @@
* @dot * @dot
digraph example { digraph example {
rankdir="LR"; rankdir="LR";
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
edge [fontname=Helvetica, fontsize=8]; edge [fontname=Helvetica, fontsize=8];
tx_idle [label="TX_IDLE", style="bold"]; tx_idle [label="TX_IDLE", style="bold"];
@ -760,7 +770,7 @@
* @dot * @dot
digraph example { digraph example {
rankdir="LR"; rankdir="LR";
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
edge [fontname=Helvetica, fontsize=8]; edge [fontname=Helvetica, fontsize=8];
rx_idle [label="RX_IDLE", style="bold"]; rx_idle [label="RX_IDLE", style="bold"];

View File

@ -236,11 +236,10 @@ void can_lld_start(CANDriver *canp) {
cfp->FR1 = 0; cfp->FR1 = 0;
cfp->FR2 = 0; cfp->FR2 = 0;
} }
cfp++;
fmask <<= 1;
/* Gives a chance for preemption since this is a rather long loop.*/ /* Gives a chance for preemption since this is a rather long loop.*/
chSysUnlock(); chSysUnlock();
chThdYield(); cfp++;
fmask <<= 1;
chSysLock(); chSysLock();
} }
} }

View File

@ -81,6 +81,9 @@ void canObjectInit(CANDriver *canp) {
/** /**
* @brief Configures and activates the CAN peripheral. * @brief Configures and activates the CAN peripheral.
* @note Activating the CAN bus can be a slow operation this this function
* is not atomic, it waits internally for the initialization to
* complete.
* *
* @param[in] canp pointer to the @p CANDriver object * @param[in] canp pointer to the @p CANDriver object
* @param[in] config pointer to the @p CANConfig object * @param[in] config pointer to the @p CANConfig object
@ -95,8 +98,7 @@ void canStart(CANDriver *canp, const CANConfig *config) {
chDbgAssert((canp->cd_state == CAN_STOP) || chDbgAssert((canp->cd_state == CAN_STOP) ||
(canp->cd_state == CAN_STARTING) || (canp->cd_state == CAN_STARTING) ||
(canp->cd_state == CAN_READY), (canp->cd_state == CAN_READY),
"canStart(), #1", "canStart(), #1", "invalid state");
"invalid state");
while (canp->cd_state == CAN_STARTING) while (canp->cd_state == CAN_STARTING)
chThdSleepS(1); chThdSleepS(1);
if (canp->cd_state == CAN_STOP) { if (canp->cd_state == CAN_STOP) {
@ -120,8 +122,7 @@ void canStop(CANDriver *canp) {
chSysLock(); chSysLock();
chDbgAssert((canp->cd_state == CAN_STOP) || (canp->cd_state == CAN_READY), chDbgAssert((canp->cd_state == CAN_STOP) || (canp->cd_state == CAN_READY),
"canStop(), #1", "canStop(), #1", "invalid state");
"invalid state");
can_lld_stop(canp); can_lld_stop(canp);
chSemResetI(&canp->cd_rxsem, 0); chSemResetI(&canp->cd_rxsem, 0);
chSemResetI(&canp->cd_txsem, 0); chSemResetI(&canp->cd_txsem, 0);
@ -146,8 +147,8 @@ void canStop(CANDriver *canp) {
* . * .
* @return The operation result. * @return The operation result.
* @retval RDY_OK the frame has been queued for transmission. * @retval RDY_OK the frame has been queued for transmission.
* @retval RDY_TIMEOUT operation not finished within the specified time. * @retval RDY_TIMEOUT The operation has timed out.
* @retval RDY_RESET driver stopped while waiting. * @retval RDY_RESET The driver has been stopped while waiting.
* *
* @api * @api
*/ */
@ -157,8 +158,7 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) {
chSysLock(); chSysLock();
chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP),
"canTransmit(), #1", "canTransmit(), #1", "invalid state");
"invalid state");
while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_transmit(canp)) {
msg_t msg = chSemWaitTimeoutS(&canp->cd_txsem, timeout); msg_t msg = chSemWaitTimeoutS(&canp->cd_txsem, timeout);
if (msg != RDY_OK) { if (msg != RDY_OK) {
@ -187,10 +187,8 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) {
* . * .
* @return The operation result. * @return The operation result.
* @retval RDY_OK a frame has been received and placed in the buffer. * @retval RDY_OK a frame has been received and placed in the buffer.
* @retval RDY_TIMEOUT operation not finished within the specified time or * @retval RDY_TIMEOUT The operation has timed out.
* frame not immediately available if invoked using * @retval RDY_RESET The driver has been stopped while waiting.
* @p TIME_IMMEDIATE.
* @retval RDY_RESET driver stopped while waiting.
* *
* @api * @api
*/ */
@ -200,8 +198,7 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) {
chSysLock(); chSysLock();
chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP),
"canReceive(), #1", "canReceive(), #1", "invalid state");
"invalid state");
while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_receive(canp)) { while ((canp->cd_state == CAN_SLEEP) || !can_lld_can_receive(canp)) {
msg_t msg = chSemWaitTimeoutS(&canp->cd_rxsem, timeout); msg_t msg = chSemWaitTimeoutS(&canp->cd_rxsem, timeout);
if (msg != RDY_OK) { if (msg != RDY_OK) {
@ -251,8 +248,7 @@ void canSleep(CANDriver *canp) {
chSysLock(); chSysLock();
chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP),
"canSleep(), #1", "canSleep(), #1", "invalid state");
"invalid state");
if (canp->cd_state == CAN_READY) { if (canp->cd_state == CAN_READY) {
can_lld_sleep(canp); can_lld_sleep(canp);
canp->cd_state = CAN_SLEEP; canp->cd_state = CAN_SLEEP;
@ -275,8 +271,7 @@ void canWakeup(CANDriver *canp) {
chSysLock(); chSysLock();
chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP), chDbgAssert((canp->cd_state == CAN_READY) || (canp->cd_state == CAN_SLEEP),
"canWakeup(), #1", "canWakeup(), #1", "invalid state");
"invalid state");
if (canp->cd_state == CAN_SLEEP) { if (canp->cd_state == CAN_SLEEP) {
can_lld_wakeup(canp); can_lld_wakeup(canp);
canp->cd_state = CAN_READY; canp->cd_state = CAN_READY;