uracoli-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[uracoli-devel] radio_set_state()


From: Daniel Thiele
Subject: [uracoli-devel] radio_set_state()
Date: Mon, 12 Jul 2010 22:35:43 +0200

Dear uracoli developers,
after hampling around (ger.: rumhampeln) with the radio_set_state() function
in module radio_rf230, I could observe the following error:
The switch() case does not decode the parameter "state" correctly, it ends
up in case "default" in most cases. "Most cases" sound ugly, but I could not
observe under which circumstances this happened. Sometimes it worked, with
different code constellations (call from another location, etc..) it ended
up in "default", which leads to radio_error(). The problem already occurred
some months ago and I could bypass by declaring the function parameter
"radio_state_t state" as volatile. Now its on focus again.

I could eliminate the effect by adding the attribute "SHORTENUM" to enum
"radio_state_t" in radio.h. It seems that the compiler declares the enum as
16-bit and optimizes something in the switch-case. But what? What is
happening? Do we have to look at other locations handling around with enums?

Best regards
Daniel

Here are some code snippets:

typedef enum ***SHORTENUM****
{
    STATE_OFF = 0,  /**< TRX is in off state */
    STATE_TX,       /**< TRX is in transmit state (a call to @ref
                         radio_send_frame transmits a frame)*/
    STATE_RX,       /**< TRX is in receive state (incoming frames are
                         signalled by the @ref usr_radio_receive_frame
                         callback)*/
    STATE_TXAUTO,   /**< TX_ARET state */
    STATE_RXAUTO,   /**< RX_AACK state */
    STATE_SLEEP,    /**< TRX is in sleep state (lowest power consumption) */
} radio_state_t;

void radio_set_state(radio_state_t state)
{
trx_regval_t cmd, expstatus, currstatus;
uint8_t retries;
bool do_sleep = false;

    switch(state)
    {
        case STATE_OFF:
            expstatus = TRX_OFF;
            cmd = CMD_TRX_OFF;
            break;

        case STATE_RX:
            expstatus = RX_ON;
            cmd = CMD_RX_ON;
            break;

        case STATE_TX:
            expstatus = PLL_ON;
            cmd = CMD_PLL_ON;
            break;

        case STATE_RXAUTO:
            expstatus = RX_AACK_ON;
            cmd = CMD_RX_AACK_ON;
            break;

        case STATE_TXAUTO:
            expstatus = TX_ARET_ON;
            cmd = CMD_TX_ARET_ON;
            break;

        case STATE_SLEEP:
            expstatus = TRX_OFF;
            cmd = CMD_FORCE_TRX_OFF;
            do_sleep = true;
            break;

        default:
            radio_error(GENERAL_ERROR);
            expstatus = TRX_OFF;
            cmd = CMD_TRX_OFF;
            break;

     }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]