编辑: cyhzg 2017-07-26

s state machine'

s initial state. */ APP_STATE_INIT=0, APP_STATE_WRITE, APP_STATE_WAIT_WRITE_COMPLETE, APP_STATE_READ, APP_STATE_WAIT_READ_COMPLETE, APP_STATE_VERIFY, APP_STATE_ERROR, APP_STATE_IDLE, /* TODO: Define states used by the application state machine. */ } APP_STATES;

/* Application Data Summary: Holds application data Description: This structure holds the application'

s data.

17 Remarks: Application strings and buffers are be defined outside this structure. */ typedef struct { /* The application'

s current state */ APP_STATES state;

DRV_HANDLE drvHandle;

uint8_t writeBuffer[BUFFER_SIZE];

uint8_t readBuffer[BUFFER_SIZE];

volatile bool isTransferDone;

/* TODO: Define any additional data used by the application. */ } APP_DATA;

18

(九)app.c 里增加如下测试代码 // Section: Global Data Definitions #define AT24_EEPROM_MEM_ADDR 0x00 /* Application Data Summary: Holds application data Description: This structure holds the application'

s data. Remarks: This structure should be initialized by the APP_Initialize function. Application strings and buffers are be defined outside this structure. */ APP_DATA appData;

// Section: Application Callback Functions /* TODO: Add any necessary callback functions. */ void APP_EEPROM_EventHandler(DRV_AT24_TRANSFER_STATUS event, uintptr_t context) { switch(event) { case DRV_AT24_TRANSFER_STATUS_COMPLETED: appData.isTransferDone = true;

break;

case DRV_AT24_TRANSFER_STATUS_ERROR: default:

19 appData.isTransferDone = false;

appData.state = APP_STATE_ERROR;

break;

} } // Section: Application Local Functions /* TODO: Add any necessary local functions. */ // Section: Application Initialization and State Machine Functions Function: void APP_Initialize ( void ) Remarks: See prototype in app.h. */ void APP_Initialize ( void ) { /* Place the App state machine in its initial state. */ appData.state = APP_STATE_INIT;

appData.isTransferDone = false;

} Function: void APP_Tasks ( void )

20 Remarks: See prototype in app.h. */ void APP_Tasks ( void ) { /* Check the application'

s current state. */ switch ( appData.state ) { /* Application'

s initial state. */ case APP_STATE_INIT: appData.drvHandle = DRV_AT24_Open(DRV_AT24_INDEX, DRV_IO_INTENT_READWRITE);

if (appData.drvHandle != DRV_HANDLE_INVALID) { DRV_AT24_EventHandlerSet(appData.drvHandle, APP_EEPROM_EventHandler, 0);

appData.state = APP_STATE_WRITE;

} else { appData.state = APP_STATE_ERROR;

} break;

case APP_STATE_WRITE: /* Fill up the write buffer */ for (uint32_t i = 0;

i <

BUFFER_SIZE;

i++) { appData.writeBuffer[i] = i;

} appData.state = APP_STATE_WAIT_WRITE_COMPLETE;

if (DRV_AT24_Write(appData.drvHandle, appData.writeBuffer, BUFFER_SIZE, AT24_EEPROM_MEM_ADDR) == false) { appData.state = APP_STATE_ERROR;

21 } break;

case APP_STATE_WAIT_WRITE_COMPLETE: if (appData.isTransferDone == true) { appData.isTransferDone = false;

appData.state = APP_STATE_READ;

} break;

case APP_STATE_READ: appData.state = APP_STATE_WAIT_READ_COMPLETE;

if (DRV_AT24_Read(appData.drvHandle, appData.readBuffer, BUFFER_SIZE, AT24_EEPROM_MEM_ADDR) == false) { appData.state = APP_STATE_ERROR;

} break;

case APP_STATE_WAIT_READ_COMPLETE: if (appData.isTransferDone == true) { appData.isTransferDone = false;

appData.state = APP_STATE_VERIFY;

} break;

case APP_STATE_VERIFY: if (memcmp(appData.writeBuffer, appData.readBuffer, BUFFER_SIZE ) == 0) { appData.state = APP_STATE_IDLE;

} else { appData.state = APP_STATE_ERROR;

下载(注:源文件不在本站服务器,都将跳转到源网站下载)
备用下载
发帖评论
相关话题
发布一个新话题