Then y this is not working it actually doesnt go into handler "es_READ_CmdHandler "
plz check and let me know
/********************************************************************************************/
/* Appli.c - Copyright Wavecom S.A. (c) 2002 */
/* */
/* */
/* DISCLAIMER OF WARRANTY */
/* ====================== */
/* This Software is provided free of charge on an 'as is' basis. No warranty is given */
/* by Wavecom S.A. in relation to the Software of the uses to which it may be put by you, */
/* the user, or its merchantability, fitness or suitability for any particular purpose */
/* or conditions; and/or that the use of the Software and all documentation relating */
/* thereto by the Licensee will not infringe any third party copyright or other */
/* intellectual property rights. Wavecom S.A. shall furthermore be under no obligation */
/* to provide support of any nature for the Software and the Documentation. */
/* */
/* LIMIT OF LIABILITY */
/* ================== */
/* In no event shall Wavecom S.A. be liable for any loss or damages whatsoever or howsoever */
/* caused arising directly or indirectly in connection with this licence, the Software, */
/* its use or otherwise except to the extent that such liability may not be lawfully */
/* excluded. Notwithstanding the generality of the foregoing, Wavecom S.A. expressly */
/* excludes liability for indirect, special, incidental or consequential loss or damage */
/* which may arise in respect of the Software or its use, or in respect of other equipment */
/* or property, or for loss of profit, business, revenue, goodwill or anticipated savings. */
/* */
/********************************************************************************************/
/***************************************************************************/
/* File : Appli.c */
/*-------------------------------------------------------------------------*/
/* Object : Customer application */
/* */
/* contents : Customer main procedures */
/* */
/* Change : */
/***************************************************************************/
/*
$LogWavecom: G:\projet\mmi\pvcsarch\archives\open-mmi\SAMPLES\adl\New_Project\src\appli.c-arc $
* --------------------------------------------------------------------------
* Date | Author | Revision | Description
* ----------+--------+----------------+-------------------------------------
* 25.10.05 | DPO | 1.1 | * New V4 interface
* ----------+--------+----------------+-------------------------------------
* 16.12.02 | dpo | 1.0 | Initial revision.
* ----------+--------+----------------+-------------------------------------
*/
#include "adl_global.h"
#include "drv_m24cxx.h"
/***************************************************************************/
/* Mandatory variables */
/*-------------------------------------------------------------------------*/
/* wm_apmCustomStackSize */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024*3;
const u32 wm_apmIRQLowLevelStackSize = 1024;
const u32 wm_apmIRQHighLevelStackSize = 1024;
/***************************************************************************/
/* Local variables */
/***************************************************************************/
static const ascii * ES_STR_READ_CMD = "at+READ";
static const ascii * ES_STR_WRITE_CMD = "at+WRITE";
// Used I2C E2P chip
#define USED_E2P_I2C_CHIP DRV_I2C_E2P_M24C64
// MAX data length
#define MAX_DATA_LENGTH 128
// Max address sizes
static const u32 ChipMaxSizes = DRV_I2C_E2P_M24CXX_READ_MAX_LENGTH(USED_E2P_I2C_CHIP);
// Max write sizes
static const u32 ChipMaxWriteSizes = DRV_I2C_E2P_M24CXX_WRITE_MAX_LENGTH;
adl_busAccess_t *I2CBus_Access;
// Read buffer
drv_Read_I2C_E2P_M24CXX_t *ReadBuff;
// Write buffer
drv_Write_I2C_E2P_M24CXX_t *WriteBuff;
// Asynchronous Reading Context
AsyncReadCtxt_t * AsyncReadCtxt;
// IIC Bus Driver Handle
u32 DRV_HANDLE;
// Is asynchrnous reading result awaited ?
bool AsyncReadRes;
// low level IRQ Handle for asynchronous bus mode
s32 appBusLowIrqHandle;
// High level IRQ Handle for asynchronous bus mode
s32 appBusHighIrqHandle;
// mode : synchronous by default
static u16 mode = 1;
// Trace level
u8 drv_TraceLevel;
/***************************************************************************/
/* Local functions */
/***************************************************************************/
/***************************************************************************/
/* Function : es_READ_CmdHandler */
/*-------------------------------------------------------------------------*/
/* Objet : External Storage read command */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* paras | | | | holding command parameter */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void es_READ_CmdHandler ( adl_atCmdPreParser_t *paras )
{
u8 sReturn = ADL_STR_OK;
TRACE (( drv_TraceLevel, "Parameters error " ));
// Switch on CmdType
switch(paras->Type)
{
case ADL_CMD_TYPE_TEST :
{
// Possible values
ascii result[100];
wm_sprintf ( result, "\r\n%s: (0-%X),(1-%d)\r\n",
ES_STR_READ_CMD + 2,
ChipMaxSizes - 1,
MAX_DATA_LENGTH - 1 );
adl_atSendResponse ( ADL_AT_PORT_TYPE ( paras->Port, ADL_AT_RSP ), result );
}
break;
case ADL_CMD_TYPE_PARA :
{
ascii * P0 = ADL_GET_PARAM ( paras, 0 ),
* P1 = ADL_GET_PARAM ( paras, 1 );
// Get Byte length
u16 ByteLength = P1 ? wm_atoi ( P1 ) : 1;
if ( ByteLength >= MAX_DATA_LENGTH )
{
TRACE (( drv_TraceLevel, "Parameters error " ));
sReturn = ADL_STR_ERROR;
}
else
{
if (ReadBuff)
{
adl_memRelease ( ReadBuff );
}
if (AsyncReadCtxt)
{
adl_memRelease ( AsyncReadCtxt );
}
ReadBuff = adl_memGet ( sizeof ( drv_Read_I2C_E2P_M24CXX_t ) + ByteLength );
AsyncReadCtxt = adl_memGet ( sizeof ( AsyncReadCtxt_t ) );
ReadBuff->Length = ByteLength ? ByteLength : 1;
ReadBuff->Address = P0 ? wm_hexatoi ( P0 , wm_strlen ( P0 ) ) % ChipMaxSizes : 0;
AsyncReadCtxt->ByteLength = ByteLength ? ByteLength : 1;
AsyncReadCtxt->Port = paras->Port;
if (!mode)
{
// in asynchronous mode
// set global variable to get reading result in high irq handler
AsyncReadRes = TRUE;
}
// Read from driver
if ( !drv_I2C_E2P_M24CXX_Read ( ReadBuff, AsyncReadCtxt ) )
{
// if mode is synchronous reading result is synchronously available
if (mode)
{
// Build response string
ascii * StrResult = adl_memGet ( ByteLength * 2 + 30 );
// I2C chip: 4 digits address
wm_sprintf ( StrResult, "\r\n%s: %.4X,\"", ES_STR_READ_CMD + 2, ReadBuff->Address );
wm_ibuftohexa ( StrResult + wm_strlen ( StrResult ), ReadBuff->Data, ByteLength );
wm_strcat ( StrResult, "\"\r\n" );
adl_atSendResponse ( ADL_AT_PORT_TYPE ( paras->Port, ADL_AT_RSP ), StrResult );
adl_memRelease ( StrResult );
adl_memRelease ( ReadBuff );
}
}
else
{
if (!mode)
{
// in asynchronous mode
// reset global variable since reading failed
AsyncReadRes = FALSE;
}
}
}
}
break;
}
adl_atSendStdResponse ( ADL_AT_PORT_TYPE ( paras->Port, ADL_AT_RSP ), sReturn );
}
/***************************************************************************/
/* Function : es_WRITE_CmdHandler */
/*-------------------------------------------------------------------------*/
/* Objet : External Storage write command */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* paras | | | | holding command parameter */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void es_WRITE_CmdHandler ( adl_atCmdPreParser_t *paras )
{
u8 sReturn = ADL_STR_OK;
// Switch on CmdType
switch(paras->Type)
{
case ADL_CMD_TYPE_TEST :
{
// Possible values
ascii result[100];
int MaxWriteSizes = ChipMaxWriteSizes * 2 ;
wm_sprintf ( result, "\r\n%s: (0-%X),(1-%d)\r\n",
ES_STR_WRITE_CMD + 2,
ChipMaxSizes - 1,
MaxWriteSizes );
adl_atSendResponse ( ADL_AT_PORT_TYPE ( paras->Port, ADL_AT_RSP ), result );
}
break;
case ADL_CMD_TYPE_PARA :
{
ascii * P0 = ADL_GET_PARAM ( paras, 0 );
ascii * P1 = ADL_GET_PARAM ( paras, 1 );
u16 DataLength = wm_strlen ( P1 ) / 2;
// Fill write buffer
WriteBuff = adl_memGet ( sizeof ( drv_Write_I2C_E2P_M24CXX_t ) + DataLength );
WriteBuff->Address = wm_hexatoi ( P0 , wm_strlen ( P0 ) ) % ChipMaxSizes;
WriteBuff->Length = DataLength ?
( DataLength > ChipMaxWriteSizes ?
ChipMaxWriteSizes :
DataLength ) :
1;
wm_hexatoibuf ( WriteBuff->Data, P1 );
if ( ( P1 == NULL )
|| ( WriteBuff->Length < 1 )
|| ( WriteBuff->Length > MAX_DATA_LENGTH ) )
{
TRACE (( drv_TraceLevel, "Parameters error " ));
sReturn = ADL_STR_ERROR;
}
else
{
// Write from driver
if ( !drv_I2C_E2P_M24CXX_Write ( WriteBuff ) )
{
// All is OK, nothing to do
}
}
adl_memRelease ( WriteBuff );
}
break;
}
adl_atSendStdResponse ( ADL_AT_PORT_TYPE ( paras->Port, ADL_AT_RSP ), sReturn );
}
/***************************************************************************/
/* Function : busLowIrqHandler */
/*-------------------------------------------------------------------------*/
/* Objet : IRQ low level handler for Bus asynchronous operation */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* Source | X | | | holding command parameter */
/*--------------------+---+---+---+----------------------------------------*/
/* NotificationLevel | X | | | holding command parameter */
/*--------------------+---+---+---+----------------------------------------*/
/* Data | X | | | holding command parameter */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
bool busLowIrqHandler(adl_irqID_e Source, adl_irqNotificationLevel_e NotificationLevel,
adl_irqEventData_t *Data)
{
adl_busAsyncInfo_t *info = (adl_busAsyncInfo_t*)Data->SourceData;
TRACE (( drv_TraceLevel, "Low level Bus handler" ));
// Check result
if (info->Result!=OK)
{
TRACE (( drv_TraceLevel, "Wrong result : %d (expected %d)", info->Result, OK));
}
return TRUE;
}
/***************************************************************************/
/* Function : busHighIrqHandler */
/*-------------------------------------------------------------------------*/
/* Objet : IRQ high level handler for Bus asynchronous operation */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* Source | X | | | holding command parameter */
/*--------------------+---+---+---+----------------------------------------*/
/* NotificationLevel | X | | | holding command parameter */
/*--------------------+---+---+---+----------------------------------------*/
/* Data | X | | | holding command parameter */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
bool busHighIrqHandler(adl_irqID_e Source, adl_irqNotificationLevel_e NotificationLevel,
adl_irqEventData_t *Data)
{
AsyncReadCtxt = (AsyncReadCtxt_t*)Data->Context;
TRACE (( drv_TraceLevel, "High level Bus handler" ));
if (AsyncReadRes)
{
// asynchronous reading result is awaited and now availble
// Build response string
ascii * StrResult = adl_memGet ( AsyncReadCtxt->ByteLength * 2 + 30 );
// I2C chip: 4 digits address
wm_sprintf ( StrResult, "\r\n%s: %.4X,\"", "at+READ" + 2, ReadBuff->Address );
wm_ibuftohexa ( StrResult + wm_strlen ( StrResult ), ReadBuff->Data, AsyncReadCtxt->ByteLength );
wm_strcat ( StrResult, "\"\r\n" );
adl_atSendResponse ( ADL_AT_PORT_TYPE ( AsyncReadCtxt->Port, ADL_AT_RSP ), StrResult );
adl_memRelease ( StrResult );
// reset variable
AsyncReadRes = FALSE;
}
return FALSE;
}
/***************************************************************************/
/* Function : drv_I2C_E2P_M24CXX_Init */
/*-------------------------------------------------------------------------*/
/* Object : Subscribe to the peripheral IIC bus */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
u32 drv_I2C_E2P_M24CXX_Init ( void )
{
u32 length = 16;
adl_busI2CSettings_t I2CSettings =
{
0x50>>1, // ChipAddress
ADL_BUS_I2C_CLK_STD // Clk_Speed
};
/* Open I2C bus */
DRV_HANDLE = adl_busSubscribe ( ADL_BUS_I2C,
1,
&I2CSettings );
// Initialize IRQ for asynchronous bus mode test
appBusLowIrqHandle = adl_irqSubscribe ( busLowIrqHandler, ADL_IRQ_NOTIFY_LOW_LEVEL,
ADL_IRQ_PRIORITY_LOW_LEVEL, ADL_IRQ_OPTION_AUTO_READ );
appBusHighIrqHandle = adl_irqSubscribe ( busHighIrqHandler,ADL_IRQ_NOTIFY_HIGH_LEVEL,
ADL_IRQ_PRIORITY_HIGH_LEVEL, ADL_IRQ_OPTION_AUTO_READ );
adl_busIOCtl(DRV_HANDLE, ADL_BUS_CMD_SET_ADD_SIZE, &length);
return DRV_HANDLE;
}
/***************************************************************************/
/* Function : drv_I2C_E2P_M24CXX_Close */
/*-------------------------------------------------------------------------*/
/* Object : Unsubscribe to the peripheral IIC bus */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void drv_I2C_E2P_M24CXX_Close ( void )
{
TRACE (( drv_TraceLevel, "M24CXX Driver unsubscription" ));
/* Close I2C bus */
adl_busUnsubscribe ( DRV_HANDLE );
DRV_HANDLE = ERROR;
}
// Bus access structure compute function
static adl_busAccess_t * drv_I2C_E2P_M24CXX_ComputeBusAccess ( u32 Address )
{
// Compute Bus Access structure from provided opcode & address
static adl_busAccess_t iicBus_Access = { 0, 0 };
u8 AddressMax = 32;
u8 length = 16;
// Check if address is required
if ( Address != 0xFFFF )
{
// Set address
iicBus_Access.Address = Address << ( AddressMax - length );
}
else
{
// Reset address
length = iicBus_Access.Address = 0;
}
TRACE (( drv_TraceLevel, "[M24CXX Driver] compute access (address : %x (length %d))", iicBus_Access.Address, length ));
// Return structure
return &iicBus_Access;
}
/***************************************************************************/
/* Function : drv_I2C_E2P_M24CXX_Read */
/*-------------------------------------------------------------------------*/
/* Object : Read on the the peripheral IIC bus */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* pRead | x | | | Reading buffer */
/*--------------------+---+---+---+----------------------------------------*/
/* AsyncReadCtxt | x | | | Asynchronous Reading Context */
/*--------------------+---+---+---+----------------------------------------*/
/* sRet | x | | | Reading result OK / ERRROR */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
u32 drv_I2C_E2P_M24CXX_Read ( drv_Read_I2C_E2P_M24CXX_t * pRead,
AsyncReadCtxt_t * AsyncReadCtxt )
{
u32 sRet;
ReadBuff = pRead;
I2CBus_Access = drv_I2C_E2P_M24CXX_ComputeBusAccess ( ReadBuff->Address );
TRACE (( drv_TraceLevel, "M24CXX Driver read" ));
/* I2C bus read */
sRet = adl_busReadExt ( DRV_HANDLE,
I2CBus_Access,
ReadBuff->Length,
ReadBuff->Data,
AsyncReadCtxt );
return sRet;
}
/***************************************************************************/
/* Function : drv_I2C_E2P_M24CXX_Write */
/*-------------------------------------------------------------------------*/
/* Object : Write on the the peripheral IIC bus */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* pWrite | x | | | Writing buffer */
/*--------------------+---+---+---+----------------------------------------*/
/* sRet | x | | | Writing result OK / ERRROR */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
u32 drv_I2C_E2P_M24CXX_Write ( drv_Write_I2C_E2P_M24CXX_t * pWrite )
{
u32 sRet;
WriteBuff = pWrite;
I2CBus_Access = drv_I2C_E2P_M24CXX_ComputeBusAccess ( WriteBuff->Address );
TRACE (( drv_TraceLevel, "M24CXX Driver write" ));
DUMP ( drv_TraceLevel, WriteBuff->Data, WriteBuff->Length );
/* I2C bus write */
sRet = adl_busWrite ( DRV_HANDLE,
I2CBus_Access,
WriteBuff->Length,
WriteBuff->Data );
return sRet;
}
void I2c_read()
{
TRACE (( 5, "Readng : Issuing at+READ: Cmd..."));
adl_atCmdCreate( "at+READ=1,4",
FALSE,
(adl_atRspHandler_t)es_READ_CmdHandler,
"*",
NULL );
}
/***************************************************************************/
/* 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" ));
if ( drv_I2C_E2P_M24CXX_Init() )
{
TRACE (( drv_TraceLevel, "External Memory driver subscribed" ));
TRACE (( drv_TraceLevel, "at+SETMODE=X : 0 for Asynchronous mode OR 1 for Synchronous mode " ));
// adl_atCmdSubscribe ( (ascii *)ES_STR_READ_CMD, es_READ_CmdHandler, ADL_CMD_TYPE_TEST | ADL_CMD_TYPE_PARA | 0x22 );
// Subscribe to READ/WRITE/SET MODE commands
I2c_read();
}
TRACE (( 1, "Embedded Application : end" ));
// TO DO : Add your initialization code here
}