ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
testflash.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 
4 
5 
52 int main(int argc, char *argv[])
53 {
54  int i;
55  char *p;
56  char *name;
57  int wf = 0;
58  int rf = 0;
59  int size = 0;
60  int count = 0;
61  int errors = 0;
62  FILE *FP;
63  unsigned int *buffer;
64 
65  for(i=1;i<argc;++i)
66  {
67  p = argv[i];
68  if(p == NULL)
69  break;
70  if(*p == '-')
71  {
72  ++p;
73  if(*p == 'w')
74  {
75  name = argv[++i];
76  wf = 1;
77  continue;
78  }
79  if(*p == 'r')
80  {
81  name = argv[++i];
82  rf = 1;
83  continue;
84  }
85  if(*p == 's')
86  {
87  ++p;
88  if(*p)
89  size = strtol(p, NULL,16);
90  else
91  size = strtol(argv[++i], NULL,16);
92  continue;
93  }
94  }
95  }
96 
97  if(!size || (!rf && !wf))
98  {
99  fprintf(stderr,"Usage: %s [-w filename ]|[-r filename] -s size\n", argv[0]);
100  exit(1);
101  }
102 
103  buffer = (unsigned int *) calloc(size,1);
104  if(!buffer)
105  {
106  fprintf(stderr,"Can not alocate %d bytes\n", size);
107  exit(1);
108  }
109 
110  if(wf)
111  {
112  FP = fopen(name,"w");
113  if(!FP)
114  {
115  fprintf(stderr,"Can not open %s for writting\n", name);
116  free((void *) buffer);
117  exit(1);
118  }
119  for(i=0;i<size/4;++i)
120  {
121  buffer[i] = i;
122  }
123  count = fwrite(buffer, 1, size,FP);
124  fclose(FP);
125  free((void *) buffer);
126  if(count != size)
127  {
128  fprintf(stderr,"wrote:%08x bytes, expected:%08x bytes\n", count, size);
129  }
130  }
131  if(rf)
132  {
133  FP = fopen(name,"r");
134  if(!FP)
135  {
136  fprintf(stderr,"Can not open %s for writting\n", name);
137  free((void *) buffer);
138  exit(1);
139  }
140  count = fread(buffer, 1, size,FP);
141  fclose(FP);
142  if(count != size)
143  {
144  fprintf(stderr,"read:%08x bytes, expected:%08x bytes\n", count, size);
145  free((void *) buffer);
146  exit(1);
147  }
148  for(i=0;i<size/4;++i)
149  {
150  if(buffer[i] != i)
151  {
152  fprintf(stderr,"addr:%08x, expected:%08x, got:%08x\n",
153  i * 4, i, buffer[i]);
154  ++errors;
155  }
156  }
157  free((void *) buffer);
158  }
159  if(errors)
160  printf("%d errors\n",errors);
161  else
162  printf("No errors\n");
163  return(errors);
164 }
int main(int argc, char *argv[])
Create or read a flash test pattern file - used for testing esp8266 flash Depends on esptool from htt...
Definition: testflash.c:52
MEMSPACE FILE * fopen(const char *path, const char *mode)
POSIX Open a file with path name and ascii file mode string.
Definition: posix.c:782
FILE type structure.
Definition: posix.h:156
MEMSPACE int fprintf(FILE *fp, const char *format,...)
fprintf function Example user defined printf function using fputc for I/O This method allows I/O to d...
Definition: posix.c:2484
MEMSPACE size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
POSIX read nmemb elements from buf, size bytes each, to the stream fd.
Definition: posix.c:803
MEMSPACE void * calloc(size_t nmemb, size_t size)
calloc buffer POSIX function
Definition: system.c:69
#define NULL
Definition: cpu.h:55
MEMSPACE void free(void *p)
Free buffer POSIX function We only call os_free() is pointer is not null.
Definition: system.c:87
MEMSPACE size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
POSIX write nmemb elements from buf, size bytes each, to the stream fd.
Definition: posix.c:868
MEMSPACE int fclose(FILE *stream)
POSIX close a file stream.
Definition: posix.c:1239
MEMSPACE long strtol(const char *nptr, char **endptr, int base)
Convert ASCII string to number in a given base.
Definition: mathio.c:136
MEMSPACE int printf(const char *format,...)
#define stderr
Definition: posix.h:271