Setting up an external device


#1

Please can you help me im using a Q2686 wireless CPU. I want to interface it with a PIC micro. My question is how should I setup the micro for serial link? I have setup FCM and it is ok but when I check on the header files I found the adl_port.h file for setting up an external device but i dnt understand how to do this.


#2

As far as the PIC is concerned, it’s just a standard serial interface - it neither knows nor cares whether it’s connected to a terminal, or a PC, or a modem, or anything else.

The PIC just transmits bytes from its serial port output, and receives bytes at its serial port input; it is totally irrelevant where the transmitted bytes go to, or where the received bytes come from - they are all just bytes!

Similarly for the Q26.

For previous discussions, try putting “PIC” into the forum’s 'Search" box…


#3

Thanks for the reply. Yes I do get what you are saying but then what are those header files used for? (adl_port.h and adl_OpenDevice.h). The thing is that I’m quite new in this stuff so I just want to understand properly. The way I understood was like you are saying that they are supposed to just communicate because they don’t really care what the other device is doing, that was until I saw these two header files then I started having questions but when I do some research I’m not getting the answers I’m looking for that’s why I have come here now to be clear about this thing.
Thanks.


#4

The ADL User Guide tells you which header file(s) is/are required for each ADL “service” (such as FCM)

adl_global.h includes all ADL headers.


#5

I did check the ADL user guide and it says I only need adl_fcm.h.So what u trying to say is that I don’t need to setup the port because I am using fcm? This is my code here below please take a look at it and tell me what you think about it. As I had said im trying to receive data from the PIC micro and storing it into flash memory. It seems to me from what u saying that the first part in my main function is necessary.

#include "adl_global.h"
#include "wm_uart.h"

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024*3;


/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/
u8 fcmHandle;
u8 fcm_Handle_Closed;
ascii*flhHandle;
s8 retValue;
s8 bufIn;
s8 bufOut;
//adl_tmr_t *timer_ptr;
adl_tmr_t *getStatus_timer;
u16 timeout_period = 10;
u8 count = 0;
u16 flhId = 0;
u16 objLen;
u8 data;
bool status;

static psGItfCont_t uart_if;
static u32 uart1_hdl;

/***************************************************************************/
/*  Local functions                                                        */
/***************************************************************************/
bool fcmCtrlH (adl_fcmEvent_e event );
bool fcmDataH ( u16 DataLen, u8 * buffer);
void getStatus_tmrHandler(u8 Id);


/***************************************************************************/
/*  Function   : adl_main                                                  */
/*-------------------------------------------------------------------------*/
/*  Object     : Customer application initialisation                       */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  InitType          |   |   |   |  Application start mode reason         */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
    TRACE (( 1, "Embedded Application : Main" ));
    //Setup the port
    sUartSettings_t settings;
    sUartLc_t       line_coding;

    // Set the line coding parameters
   	line_coding.valid_fields = UART_LC_ALL;
   	line_coding.rate = (eUartRate_t)( UART_RATE_USER_DEF | 9600 );
   	line_coding.stop = UART_STOP_BIT_1;
   	line_coding.data = UART_DATALENGTH_8;
   	line_coding.parity = UART_PARITY_NONE;

    // UART2 will be opened in NULL MODEM role / with synchronous read/write
   	settings.identity = "UART1";
    settings.role = UART_ROLE_NM;
    settings.capabilities = NULL;
   	settings.event_handlers = NULL;
   	settings.interface = &uart_if;
   	settings.line_coding = &line_coding;

    uart1_hdl = adl_odOpen( DF_UART_CLID, &settings );
   	if( !uart1_hdl )
      {
         // UART2 opening failed...
   	    return;
   	  }

       // UART2 successfully opened, write some bytes
      //uart1_if.write( uart1_hdl, “Tx Some bytes”, 13 );

    //Subscribe to Flash
    adl_flhSubscribe(flhHandle, 1);

    //Subscribe to FCM flow
    fcmHandle=adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART1 ,fcmCtrlH, fcmDataH);
    TRACE (( 1, "FCM subscription handle-->%d",fcmHandle ));

}

/***************************************************************************/
/*  Command Handlers                                                        */
/***************************************************************************/
bool fcmCtrlH (adl_fcmEvent_e event )
{
	switch(event)
	{
	case ADL_FCM_EVENT_FLOW_OPENNED:

		adl_atSendResponse(ADL_AT_UNS, "FCM Flow Opened\r\n");

		adl_flhWrite(flhHandle, flhId, objLen, &data);

		adl_fcmSwitchV24State(fcmHandle,ADL_FCM_V24_STATE_DATA);
		break;

	case ADL_FCM_EVENT_V24_DATA_MODE:

		adl_atSendResponse(ADL_AT_UNS, "Flow in Data Mode\r\n");
		/*Use a cyclic timer to poll in the buffer status to switching the V24 state from Data to AT*/
		getStatus_timer = adl_tmrSubscribe(TRUE, 1, ADL_TMR_TYPE_100MS, getStatus_tmrHandler);

		/*Reading data from flash*/
		adl_flhRead(flhHandle, flhId, objLen, &data);
		adl_atSendResponse(ADL_AT_UNS, "I just read some data from flash\r\n");
		adl_fcmSwitchV24State(fcmHandle,ADL_FCM_V24_STATE_AT);
		break;

	case ADL_FCM_EVENT_FLOW_CLOSED:

		adl_atSendResponse(ADL_AT_UNS, "Flow Closed\r\n");
		break;

	case ADL_FCM_EVENT_V24_AT_MODE:

		adl_atSendResponse(ADL_AT_UNS, "Flow in AT Mode\r\n");
		adl_fcmReleaseCredits( fcmHandle, 0XFF );
		adl_fcmUnsubscribe(fcmHandle);
		adl_tmrUnSubscribe(getStatus_timer, getStatus_tmrHandler, ADL_TMR_TYPE_100MS);
		break;

	case ADL_FCM_EVENT_V24_AT_MODE_EXT:

		adl_atSendResponse(ADL_AT_UNS, "Flow in AT Mode\r\n");
		adl_fcmReleaseCredits( fcmHandle, 0XFF );

		break;

	case ADL_FCM_EVENT_RESUME:

		adl_atSendResponse(ADL_AT_UNS, "Resume data\r\n");
		break;

	case ADL_FCM_EVENT_MEM_RELEASE:

		adl_atSendResponse(ADL_AT_UNS, "Data released\r\n");
		break;

	case ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL:

		adl_atSendResponse(ADL_AT_UNS, "Calling for AT\r\n");
		break;

	case ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL:

		adl_atSendResponse(ADL_AT_UNS, "Calling Data Mode\r\n");
		break;

	case ADL_FCM_EVENT_V24_DATA_MODE_EXT:

		adl_atSendResponse(ADL_AT_UNS, "Flow in Data Mode\r\n");
		break;
	}
	return TRUE;
}

bool fcmDataH ( u16 datalen, u8 * databuf)
{
	TRACE((1,"Data handler = %d", datalen ));
	return TRUE;
}

void getStatus_tmrHandler(u8 Id)
{
	if ((adl_fcmGetStatus(fcmHandle, ADL_FCM_WAY_TO_EMBEDDED) == ADL_FCM_RET_BUFFER_EMPTY))
	{
		//adl_tmrUnSubscribe(getStatus_timer, getStatus_tmrHandler, ADL_TMR_TYPE_100MS);

		//Switching V24 state from Data to AT
		adl_fcmSwitchV24State(fcmHandle, ADL_FCM_V24_STATE_AT);
	}
	else
	{
		adl_atSendResponse(ADL_AT_UNS, "Buffer is not empty,fetching data...\r\n");
		status = adl_memRelease(objLen);
		if (status == TRUE)
		{
			adl_flhWrite(flhHandle, flhId, objLen, &data);
			flhId = flhId +1;
			adl_atSendResponse(ADL_AT_UNS, "Data successfully stored in flash\r\n");
		}
		else
		{
			adl_atSendResponse(ADL_AT_UNS, "Data could not be released\r\n");
		}
	}
}

#6

ADL provides two distinct ways to use the UARTs: you use either FCM or Direct access - but not both!

I recommend that you use FCM.


#7

Clarification: for each UART, you can use either FCM or Direct access, but an application can use FCM for one UART, and Direct Access for another.

Again, I recommend that you use FCM.


#8

Thanks a lot I think I’m gonna stick to FCM.


#9

Always check the return values from all API calls :exclamation:


#10

I though I only need to check the return values of the values that I need to know for doing a particular action. I don’t understand why I have to check return values I don’t need.


#11

Because you do need them!
They tell you whether the operation succeeded or not - you obviously need to know that the operation succeeded before you carry on and rely upon it!

If the operation failed, it gives you some indication for the reason - so that you know what to fix.

This is basic stuff for any programming exercise - not specific to Wavecom or Open-AT.

In any programming job, dealing with the path where everything “just works” is almost trivial - it’s coping with all the things that could go wrong that takes 90% of the effort!