Problem open and closing UART 1

Hi all. I have a FXT009 with 7.52.0.201306260837 loaded.

I have now created a state machine based application that connects the bearer, then creates a TCPServer which listens on port 8080, then once a connection is received it create a tunnel between the socket and UART 1. I can get that to work reliably etc…

But… now I want to enable low power mode and to do that I need to close UART1 so it enters low power mode. I am using FCM for data flow management on the UART. However I am having problems reliably opening and close the UART. Could you please describe what I need to do to make it work?

What I currently do to open and then close the UART is listed in the below code. I would appreciate your comments.

Init and Shutdown are called when the TCP socket is connected to and closed respectively.

void serialFcmInit(void)
{
    s8 status = -1;
//    setIPR();

    if (serial_state.serial1FcmHandle != -1 && serial_state.serialState == SERIAL_DISCONNECTING)
    {
       //if we get here, then we assume the previous disconnect did not complete, so continue as if serial port is closed.
              applog("UART: Serial1 already defined as =%d", serial_state.serial1FcmHandle);
              serial_state.serial1FcmHandle = -1;
              serial_state.serialState = SERIAL_CLOSED;
    }

    if (serial_state.serialState == SERIAL_CONNECTED && serial_state.serial1FcmHandle != -1)
    {
       //applog("UART: Already connected. Not initialising FCM");
    }
    else if (serial_state.serialState == SERIAL_CLOSED && serial_state.serial1FcmHandle == -1)
    {
              applog("UART: Serial Init");
              serial_state.serialState = SERIAL_CONNECTING;
              ringBuf1Reset();
              status = adl_fcmSubscribe(ADL_PORT_UART1, (adl_fcmCtrlHdlr_f)serial1FcmCtrlHandler, (adl_fcmDataHdlr_f)serial1FcmDataHandler);

              if(status >= 0)
              {
                     serial_state.serial1FcmHandle = status;
                     applog("UART: serial1=%d", serial_state.serial1FcmHandle);
              }
              else
                     applog("UART: fcmSubscribe failed. Error: %d", status);
    }
    else if (serial_state.serialState == SERIAL_CONNECTING && serial_state.serial1FcmHandle != -1)
    {
              applog("UART: Waiting for connection. %d", serial_state.serialState);
    }
    else
       applog("UART: FCMInit - unhandled scenario Handle: %d Status:%d", serial_state.serial1FcmHandle, serial_state.serialState);
    //comTimerStart();
}

void serialFcmShutdown()
{
    s8 status = -1;

       if (serial_state.serial1FcmHandle != -1 && serial_state.serialState == SERIAL_CONNECTED)
       {
              applog("UART 1: Serial shutdown");
              ringBuf1Reset();
              serial_state.serialState = SERIAL_DISCONNECTING;
              status = adl_fcmSwitchV24State(serial_state.serial1FcmHandle, ADL_FCM_V24_STATE_AT);

              if(status == OK)
              {
                     serial_state.serial1FcmHandle = status;
                     applog("UART 1: adl_fcmSwitchV24State changed to AT");
              }
              else
              {
                     applog("UART 1: adl_fcmSwitchV24State change to AT. Error: %d", status);

                     //try force close on the rest.
                     adl_fcmReleaseCredits( serial_state.serial1FcmHandle, 0XFF );
                     status = adl_fcmUnsubscribe(serial_state.serial1FcmHandle);
                     if(status == OK)
                     {
                           serial_state.serial1FcmHandle = status;
                           applog("UART 1: adl_fcmUnsubscribed");
                     }
                     else
                           applog("UART 1: adl_fcmUnsubscribed failed. Error: %d", status);

            serial_state.serial1FcmHandle = -1;
            serial_state.serialState = SERIAL_CLOSED;
              }

       }
       else
applog("UART: FCM Shutdown - unhandled scenario Handle: %d Status:%d", serial_state.serial1FcmHandle, serial_state.serialState);

       comTimerStop();
}

//And then the handler does a little extra as well

bool serial1FcmCtrlHandler(adl_fcmEvent_e event)
{
       s8 status = -1;
       applog("SOCKET: serial1FcmCtrlHandler %d", event);

    switch(event)
    {
        case ADL_FCM_EVENT_FLOW_OPENNED:
                     /* Switching V24 state from AT to Data. */
              status = adl_fcmSwitchV24State(serial_state.serial1FcmHandle, ADL_FCM_V24_STATE_DATA);

                     if(status == OK)
                     {
                           serial_state.serial1FcmHandle = status;
                           applog("UART: Serial 1 FCM Opened -> Switching V24 state from AT to Data");
                     }
                     else
                           applog("UART: Serial 1 FCM Opened -> Switching V24 state from AT to Data FAILED. Error: %d", status);
                     break;
        case ADL_FCM_EVENT_FLOW_CLOSED:
            applog("UART: ADL_FCM_EVENT_FLOW_CLOSED.");
            serial_state.serial1FcmHandle = -1;
            serial_state.serialState = SERIAL_CLOSED;
              break;
        case ADL_FCM_EVENT_V24_DATA_MODE:
                     /* sending data to the external application via V24 serial link */
            applog("UART: Flow in Data Mode");
            serial_state.serialState = SERIAL_CONNECTED;

                     break;
        case ADL_FCM_EVENT_V24_AT_MODE:
            serial_state.serialState = SERIAL_DISCONNECTED;

            applog("UART: ADL_FCM_EVENT_V24_AT_MODE");
            adl_fcmReleaseCredits( serial_state.serial1FcmHandle, 0XFF );

              status = adl_fcmUnsubscribe(serial_state.serial1FcmHandle);

              if(status == OK)
              {
                     serial_state.serial1FcmHandle = status;
                     applog("UART 1: adl_fcmUnsubscribed");
              }
              else
                     applog("UART 1: adl_fcmUnsubscribed failed. Error: %d", status);

              //serial_state.serial1FcmHandle = -1;
            break;
        case ADL_FCM_EVENT_MEM_RELEASE:
            applog("UART: ADL_FCM_EVENT_MEM_RELEASE");
              break;
        case ADL_FCM_EVENT_RESUME:
            applog("UART: ADL_FCM_EVENT_RESUME");
              break;
        case ADL_FCM_EVENT_V24_AT_MODE_EXT:
            applog("UART: ADL_FCM_EVENT_V24_AT_MODE_EXT");
              break;
        case ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL:
            applog("UART: ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL");
              break;
        case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
            applog("UART: ADL_FCM_EVENT_V24_DATA_MODE_EXT");
              break;
        case ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL:
            applog("UART: ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL");
              break;
        case ADL_FCM_EVENT_V24_TX_DATA_FLUSHED:
            applog("UART: ADL_FCM_EVENT_V24_TX_DATA_FLUSHED");
              break;
        }

    return TRUE;
}

I have now started to try close the port directly and for some reason it seams I cannot close UART1 at all using AT+WMFM=0,0,1 I just keep getting an error, event though AT+WMFM? shows it being open.

Is this something to do with the way the firmware managed the port? Anything I should be aware of?

Thanks,

Karl

Which port are you sending the command on?
You should use the internal virtual port and not UART1 for example, if you’re trying to use the command from within an OpenAT application.

Hi Tobias, thanks for your reply. I am sending out as below…

adl_atCmdCreate("AT+W32K=1,0", ADL_AT_PORT_TYPE (ADL_PORT_UART1, FALSE), LowPowerModeResponse, "*", NULL );

From the samples it seems this is how they send it out? What should I be using instead of ADL_PORT_UART1?

Thanks,

Karl

Hi Tobias, just an update, that you were right. I changed to the port to which I was sending and that sorted the problem…

Thanks,

Karl