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