📄 exstbeeprom.c
字号:
/*****************************************************************************//* Copyright (c) 2008 NXP B.V. All rights are reserved. *//* *//* Redistribution and use in source and binary forms, with or without *//* modification, are permitted provided that the following conditions *//* are met: *//* *//* Redistributions of source code must retain the above copyright *//* notice, this list of conditions and the following disclaimer. *//* *//* Redistributions in binary form must reproduce the above copyright *//* notice, this list of conditions and the following disclaimer in the *//* documentation and/or other materials provided with the distribution. *//* *//* Neither the name of NXP nor the names of its *//* contributors may be used to endorse or promote products derived from *//* this software without specific prior written permission. *//* *//* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *//* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *//* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *//* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *//* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *//* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *//* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *//* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *//* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *//* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *//* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *//* DAMAGE. *//* *//*****************************************************************************//* IPSTB Project ---------------------------------Filename: exStbEeprom.c@file Simple test program for EEPROM read/write.Rev Date Author Comments-------------------------------------------------------------------------------- 1 20070606 Caroline Original 2 20080205 batelaan Update file copyright/license text-------------------------------------------------------------------------------- For consistency and standardisation retain the Section Separators.*//************************************************ INCLUDE FILES *************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <fcntl.h>#include <termios.h>#include <ctype.h>#include "at24c64.h"/************************************************ LOCAL MACROS *************************************************//******************************************************************* LOCAL TYPEDEFS ********************************************************************//******************************************************************* STATIC FUNCTION PROTOTYPES <Module>_<Word>+ ********************************************************************//******************************************************************* STATIC DATA g[k|p|kp|pk|kpk]<Module>_<Word>+ ********************************************************************//*************************************************************************** EXPORTED DATA g[k|p|kp|pk|kpk]ph[<lnx|tm|NONE>]StbTemplate_<Word>+ ****************************************************************************//******************************************************************************** FUNCTION IMPLEMENTATION <Module>[_<Word>+] for static functions ** tm[<layer>]<Module>[_<Word>+] for exported functions*********************************************************************************/int main(int argc, char *argv[]){ int eeprom; unsigned char data_1[256]; unsigned char data_2[256]; unsigned char ReadData_1[256]; unsigned char ReadData_2[256]; unsigned char test_write = 0x88; unsigned char test_read; int i; for (i=0; i<256; i++) { data_1[i] = 0xAA; } for (i=0; i<256; i++) { data_2[i] = 0xFF; } eeprom = open("/dev/at24c64", O_RDWR); if (eeprom < 0) { printf("Error : Failed to open eeprom device\n"); exit(1); } printf("/dev/at24c64 opened %d\n",eeprom); lseek(eeprom, 5,0); write(eeprom, &test_write,1); lseek(eeprom, 5,0); read(eeprom,&test_read,1); printf("The read data is 0x%02x \n", test_read); lseek(eeprom, 240,0); write(eeprom, &data_1,256); lseek(eeprom, 240,0); read(eeprom,ReadData_1,256); printf("-------------------------------------\n"); lseek(eeprom, 256,0); write(eeprom, &data_2,256); lseek(eeprom, 256,0); read(eeprom,ReadData_2,256); for (i=0; i<1000; i++) { ; } for (i=0; i<256; i++) { if((i!=0)&&((i%16) == 0)) printf("\n"); printf(" 0x%02x ", ReadData_1[i]); } printf("\n\n\n"); for (i=0; i<256; i++) { if((i!=0)&&((i%16) == 0)) printf("\n"); printf(" 0x%02x ", ReadData_2[i]); } printf("\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -