While working with the Q24PL with a GPS receiver we built this test code that loops data from one UART to the other UART. Maybe this would help:
#include "adl_global.h"
/***************************************************************************/
/* Mandatory variables */
/*-------------------------------------------------------------------------*/
/* wm_apmCustomStack */
/* wm_apmCustomStackSize */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );
/* Handle used to control UART2 */
s8 uart1FcmHandle = -1;
s8 uart2FcmHandle = -1;
bool uart1AtMode = TRUE;
bool uart2AtMode = TRUE;
#define SEND_TRACE(x) TRACE(( 1, x )); adl_atSendResponse ( ADL_AT_UNS, x );
void PrintFcmState(int i)
{
/*
ADL_FCM_EVENT_FLOW_OPENNED,
ADL_FCM_EVENT_FLOW_CLOSED,
ADL_FCM_EVENT_V24_DATA_MODE,
ADL_FCM_EVENT_V24_DATA_MODE_EXT,
ADL_FCM_EVENT_V24_AT_MODE,
ADL_FCM_EVENT_V24_AT_MODE_EXT,
ADL_FCM_EVENT_RESUME,
ADL_FCM_EVENT_MEM_RELEASE,
ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL,
ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL
*/
}
bool Uart1ControlHandler(adl_fcmEvent_e event)
{
char string[100];
s8 returnValue;
wm_sprintf(string, "(Uart1ControlHandler) Event: %d\r\n", event);
SEND_TRACE(string);
switch(event)
{
case ADL_FCM_EVENT_FLOW_OPENNED:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED\r\n");
returnValue = adl_fcmSwitchV24State(uart1FcmHandle, ADL_FCM_V24_STATE_DATA);
if (returnValue != OK)
{
wm_sprintf(string, "(Uart1ControlHandler) ERROR: adl_fcmSwitchV24State(ADL_FCM_V24_STATE_DATA) failed. returnValue = %d\r\n", returnValue);
SEND_TRACE(string);
}
else
{
SEND_TRACE("(Uart1ControlHandler) adl_fcmSwitchV24State(ADL_FCM_V24_STATE_DATA) Success\r\n");
}
break;
case ADL_FCM_EVENT_FLOW_CLOSED:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED\r\n");
break;
case ADL_FCM_EVENT_V24_DATA_MODE:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE\r\n");
break;
case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE_EXT\r\n");
break;
case ADL_FCM_EVENT_V24_AT_MODE:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE\r\n");
break;
case ADL_FCM_EVENT_V24_AT_MODE_EXT:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE_EXT\r\n");
break;
case ADL_FCM_EVENT_RESUME:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_RESUME\r\n");
break;
case ADL_FCM_EVENT_MEM_RELEASE:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_MEM_RELEASE\r\n");
break;
case ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL\r\n");
break;
case ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL:
SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL\r\n");
break;
default:
SEND_TRACE("(Uart1ControlHandler) Error: Unknown Event\r\n");
break;
}
return TRUE;
}
bool Uart1DataHandler(u16 dataLen, u8 *data)
{
s8 returnValue;
char string[100];
wm_sprintf(string, "(Uart1DataHandler)Bytes Received: %d\r\n", dataLen);
SEND_TRACE(string);
returnValue = adl_fcmSendData(uart2FcmHandle, data, dataLen);
if (returnValue < 0)
{
wm_sprintf(string, "(Uart1DataHandler) adl_fcmSendData() failed. returnValue=%d\r\n", returnValue);
SEND_TRACE(string);
}
return TRUE;
}
bool Uart2ControlHandler(adl_fcmEvent_e event)
{
char string[100];
s8 returnValue;
wm_sprintf(string, "(Uart2ControlHandler) Event: %d\r\n", event);
SEND_TRACE(string);
switch(event)
{
case ADL_FCM_EVENT_FLOW_OPENNED:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED\r\n");
returnValue = adl_fcmSwitchV24State(uart2FcmHandle, ADL_FCM_V24_STATE_DATA);
if (returnValue != OK)
{
wm_sprintf(string, "(Uart2ControlHandler) ERROR: adl_fcmSwitchV24State(ADL_FCM_V24_STATE_DATA) failed. returnValue = %d\r\n", returnValue);
SEND_TRACE(string);
}
else
{
SEND_TRACE("(Uart2ControlHandler) adl_fcmSwitchV24State(ADL_FCM_V24_STATE_DATA) Success\r\n");
}
break;
case ADL_FCM_EVENT_FLOW_CLOSED:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED\r\n");
break;
case ADL_FCM_EVENT_V24_DATA_MODE:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE\r\n");
break;
case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE_EXT\r\n");
break;
case ADL_FCM_EVENT_V24_AT_MODE:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE\r\n");
break;
case ADL_FCM_EVENT_V24_AT_MODE_EXT:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE_EXT\r\n");
break;
case ADL_FCM_EVENT_RESUME:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_RESUME\r\n");
break;
case ADL_FCM_EVENT_MEM_RELEASE:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_MEM_RELEASE\r\n");
break;
case ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL\r\n");
break;
case ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL:
SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL\r\n");
break;
default:
SEND_TRACE("(Uart2ControlHandler) Error: Unknown Event\r\n");
break;
}
return TRUE;
}
bool Uart2DataHandler(u16 dataLen, u8 *data)
{
s8 returnValue;
char string[100];
wm_sprintf(string, "(Uart2DataHandler)Bytes Received: %d\r\n", dataLen);
SEND_TRACE(string);
returnValue = adl_fcmSendData(uart1FcmHandle, data, dataLen);
if (returnValue < 0)
{
wm_sprintf(string, "(Uart2DataHandler) adl_fcmSendData() failed. returnValue=%d\r\n", returnValue);
SEND_TRACE(string);
}
return TRUE;
}
bool HandleWmfmSetBaudRate(adl_atResponse_t *response)
{
bool isFcmAvailable;
SEND_TRACE("AT+IPR=115200: %s");
SEND_TRACE(response->StrData);
isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART1);
if (isFcmAvailable)
{
SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART1) == TRUE\r\n");
}
else
{
SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART1) == FALSE\r\n");
}
isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART2);
if (isFcmAvailable)
{
SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART2) == TRUE\r\n");
}
else
{
SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART2) == FALSE\r\n");
}
uart1FcmHandle = adl_fcmSubscribe(ADL_PORT_UART1, Uart1ControlHandler, Uart1DataHandler);
if (uart1FcmHandle < 0)
{
char string[100];
wm_sprintf(string, "ERROR: adl_fcmSubscribe(ADL_PORT_UART1)failed. returnValue = %d\r\n", uart1FcmHandle);
SEND_TRACE(string);
}
else
{
char string[100];
wm_sprintf(string, "adl_fcmSubscribe(ADL_PORT_UART1)Success! uart2FcmHandle = %d\r\n", uart1FcmHandle);
SEND_TRACE(string);
}
uart2FcmHandle = adl_fcmSubscribe(ADL_PORT_UART2, Uart2ControlHandler, Uart2DataHandler);
if (uart2FcmHandle < 0)
{
char string[100];
wm_sprintf(string, "ERROR: adl_fcmSubscribe(ADL_PORT_UART2)failed. returnValue = %d\r\n", uart2FcmHandle);
SEND_TRACE(string);
}
else
{
char string[100];
wm_sprintf(string, "adl_fcmSubscribe(ADL_PORT_UART2)Success! uart2FcmHandle = %d\r\n", uart2FcmHandle);
SEND_TRACE(string);
}
isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART1);
if (isFcmAvailable)
{
SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART1) == TRUE\r\n");
}
else
{
SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART1) == FALSE\r\n");
}
isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART2);
if (isFcmAvailable)
{
SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART2) == TRUE\r\n");
}
else
{
SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART2) == FALSE\r\n");
}
return(FALSE);
}
void WorkAroundTitmerHandler( u8 whatever)
{
s8 returnValue;
/* Set the baud rate for UART 2 */
SEND_TRACE("AT+IPR=115200: Start\r\n");
returnValue = adl_atCmdCreate("AT+IPR=115200",
ADL_AT_PORT_TYPE (ADL_PORT_UART2, FALSE),
HandleWmfmSetBaudRate, "*", NULL);
if (returnValue != OK)
{
char string[100];
wm_sprintf(string, "ERROR: adl_atCmdCreate(AT+IPR=115200) returned %d\r\n", returnValue);
SEND_TRACE(string);
}
}
#define COMMAND_BUG 1
bool HandleWmfmUart2Enable(adl_atResponse_t *response)
{
SEND_TRACE("AT+WMFM=0,1,2:");
SEND_TRACE(response->StrData);
#if COMMAND_BUG
// For some reason, we never receive the callback after cascading the third
// AT Command. Wavecom is working on a solution...
adl_tmrSubscribe(FALSE, 1, ADL_TMR_TYPE_100MS, WorkAroundTitmerHandler);
#else
WorkAroundTitmerHandler(0);
#endif
return(FALSE);
}
bool HandleWmfmUart2Disable(adl_atResponse_t *response)
{
s8 returnValue;
SEND_TRACE("AT+WMFM=0,0,2:");
SEND_TRACE(response->StrData);
/* For <Physical Port>, <Activate>, <UART 2> */
SEND_TRACE("AT+WMFM=0,1,2: Start\r\n" );
returnValue = adl_atCmdCreate("AT+WMFM=0,1,2", FALSE,
HandleWmfmUart2Enable, "*", NULL);
if (returnValue != OK)
{
char string[100];
wm_sprintf(string, "ERROR: adl_atCmdCreate(AT+WMFM=0,1,2) returned %d\r\n", returnValue);
SEND_TRACE(string);
}
return(FALSE);
}
void AtUart2LoopbackCmdHandler(adl_atCmdPreParser_t *parser)
{
s8 returnValue;
char *parameter;
int startStop;
SEND_TRACE("(AtUart2LoopbackCmdHandler) Enter.\r\n");
parameter = wm_lstGetItem(parser->ParaList, 0);
startStop = atoi(parameter);
if (startStop == 1)
{
if ((uart1FcmHandle != -1) || (uart2FcmHandle != -1))
{
SEND_TRACE("Application Active: UART1 or UART2 still has active handle.\r\n");
}
/* Disable UART 2 just in case it wasn't disable in the previous run. */
SEND_TRACE("AT+WMFM=0,0,2: Start\r\n");
adl_atCmdCreate("AT+WMFM=0,0,2", FALSE, HandleWmfmUart2Disable, "*", NULL);
}
else
if (startStop == 0)
{
char string[100];
if (uart1FcmHandle != -1)
{
returnValue = adl_fcmUnsubscribe(uart1FcmHandle);
if (returnValue < 0)
{
wm_sprintf(string, "(AtUart2LoopbackCmdHandler) adl_fcmUnsubscribe(uart1FcmHandle) failed. returnValue=%d\r\n", returnValue);
SEND_TRACE(string);
}
else
{
uart1FcmHandle = -1;
}
}
else
{
SEND_TRACE("UART1 already Unsubscribed.\r\n");
}
if (uart1FcmHandle != -1)
{
returnValue = adl_fcmUnsubscribe(uart2FcmHandle);
if (returnValue < 0)
{
wm_sprintf(string, "(AtUart2LoopbackCmdHandler) adl_fcmUnsubscribe(uart2FcmHandle) failed. returnValue=%d\r\n", returnValue);
SEND_TRACE(string);
}
else
{
uart2FcmHandle = -1;
}
}
else
{
SEND_TRACE("UART2 already Unsubscribed.\r\n");
}
}
else
{
adl_atSendResponse ( ADL_AT_RSP, "\r\nERROR\r\n" );
return;
}
adl_atSendResponse ( ADL_AT_RSP, "\r\nOK\r\n" );
}
void adl_main ( adl_InitType_e InitType )
{
SEND_TRACE("Embedded : Appli Init\r\n");
adl_atCmdSubscribe("AT+UART2", AtUart2LoopbackCmdHandler, ADL_CMD_TYPE_PARA | 0x11);
}
[/code]