00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00047
00048 #include <stdio.h>
00049 #include <string.h>
00050 #include <io.h>
00051 #include <dev/gpio.h>
00052
00053 #include <cfg/arch.h>
00054 #include <dev/board.h>
00055
00056 #include <sys/thread.h>
00057 #include <sys/timer.h>
00058 #include <dev/twif.h>
00059 #include <dev/pca9555.h>
00060 #include <dev/eeprom.h>
00061 #define MYPRINT(fmt, ...) printf ("%s:%s(%d)\t" fmt "\n", \
00062 __FILE__,__FUNCTION__,__LINE__, ##__VA_ARGS__);
00063
00064 #define LED_OFF 0
00065 #define LED_ON 1
00066
00067 #define LED(led,state) if( state == LED_OFF )IOExpSetBit( 1, led );else IOExpClrBit( 1, led )
00068 #define LED1(state) LED( 0, state )
00069 #define LED2(state) LED( 1, state )
00070 #define LED3(state) LED( 2, state )
00071 #define LED4(state) LED( 3, state )
00072 #define LED5(state) LED( 4, state )
00073
00074 #define DLED(led,state) if( state == LED_OFF )IOExpSetBit( 0, led + 4 );else IOExpClrBit( 0, led + 4 )
00075 #define DLED1(state) DLED( 0, state )
00076 #define DLED2(state) DLED( 1, state )
00077 #define DLED3(state) DLED( 2, state )
00078 #define DLED4(state) DLED( 3, state )
00079
00080 #define KEY1 (1<<0)
00081 #define KEY2 (1<<1)
00082 #define KEY3 (1<<2)
00083 #define KEY4 (1<<3)
00084
00085 int8_t ledid = 0;
00086 uint8_t up = 0;
00087
00088
00089 THREAD(Led, arg)
00090 {
00091
00092
00093
00094 NutThreadSetPriority(16);
00095 for (;;)
00096 {
00097 if( up == 1 )
00098 {
00099 LED( ledid, LED_OFF );
00100 if( ++ledid > 4 )
00101 {
00102 ledid = 3;
00103 up = 0;
00104 }
00105 LED( ledid, LED_ON );
00106 }
00107 else
00108 {
00109 LED( ledid, LED_OFF );
00110 if( --ledid < 0 )
00111 {
00112 ledid = 1;
00113 up = 1;
00114 }
00115 LED( ledid, LED_ON );
00116 }
00117 NutSleep(200);
00118 }
00119 }
00120
00121 void HexDump( uint8_t *rxb, uint16_t len )
00122 {
00123 uint16_t i;
00124 uint16_t f = 1;
00125 char ascii[17];
00126
00127 for( i = 0; i < len; i++ )
00128 {
00129 if( f == 1 )
00130 {
00131 f = 0;
00132 printf ( "%04x : ", i );
00133 }
00134 printf( "%02X ", rxb[i] );
00135 ascii[ i % 16] = ( rxb[i] > 31 && rxb[i] < 128 ) ? rxb[i] : '.';
00136
00137 if((( i + 1) % 16 ) == 0 )
00138 {
00139 f = 1;
00140 ascii[16] = 0;
00141 printf( "| %s\n", ascii );
00142 }
00143 }
00144 }
00145
00146 const uint8_t teststr[64] = { "This is an ultimatly long string that reaches 61 bytes length\0"};
00147
00148
00149
00150
00151 int main(void)
00152 {
00153
00154 uint8_t txBuffer[128];
00155 uint8_t rxBuffer[128];
00156 u_long baud = 115200;
00157
00158
00159
00160
00161
00162 NutRegisterDevice(&DEV_DEBUG, 0, 0);
00163 freopen(DEV_DEBUG_NAME, "w", stdout);
00164 _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00165
00166 printf( "\n*** EEPROM Test ***\n");
00167
00168 baud = 100000;
00169 TwInit( 0 );
00170 TwIOCtl( TWI_SETSPEED, &baud);
00171
00172 EEInit();
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 memset( rxBuffer, 0x00, sizeof( rxBuffer));
00187 memset( txBuffer, 0xff, sizeof( txBuffer));
00188
00189 printf( "Read\n" );
00190 EEReadData( 2, rxBuffer, 64);
00191 HexDump( rxBuffer, 64 );
00192
00193 if( !strncmp( rxBuffer, teststr, strlen( teststr)))
00194 printf( "Test successfull, data is equal!\n");
00195 else
00196 printf( "Test failed, data not equal!\n");
00197
00198 printf( "\nInit: Fill 0xFF\n" );
00199 EEWriteData( 0, txBuffer, 64);
00200 EEReadData( 0, rxBuffer, 64);
00201 HexDump( rxBuffer, 64 );
00202
00203 strcpy( txBuffer, "First, " );
00204 EEWriteData( 24, txBuffer, strlen( txBuffer ));
00205 EEReadData( 0, rxBuffer, 64);
00206 printf( "1 Step\n" );
00207 HexDump( rxBuffer, 64 );
00208
00209 strcpy( txBuffer, "Third." );
00210 EEWriteData( 24+16, txBuffer, strlen( txBuffer ));
00211 EEReadData( 0, rxBuffer, 64);
00212 printf( "2 Step\n" );
00213 HexDump( rxBuffer, 64 );
00214
00215 strcpy( txBuffer, "Second, " );
00216 EEWriteData( 24+8, txBuffer, strlen( txBuffer ));
00217 EEReadData( 0, rxBuffer, 64);
00218 printf( "3 Step\n" );
00219 HexDump( rxBuffer, 64 );
00220
00221 EEWriteData( 2, (void*)teststr, strlen( teststr));
00222 EEReadData( 2, rxBuffer, 64);
00223 printf( "4 Step\n" );
00224 HexDump( rxBuffer, 64 );
00225
00226
00227
00228
00229 for (;;)
00230 {
00231 NutSleep(1000);
00232 }
00233 return 0;
00234 }