Zerocat Chipflasher  v0.4.3 (board-edition-1)
Flash free firmware to BIOS chips, kick the Manageability Engine.
kick.c
Go to the documentation of this file.
1 /******************************************************************/
45 //parallax propside workspace: 'Simple Libraries'
46 #include "simpletext.h"
47 #include "simpletools.h"
48 
49 //additional parallax propeller-elf headers
50 #include <ctype.h>
51 
52 //project headers
53 #include "libprop/putChar.h"
54 #include "libcommon/common.h"
55 #include "libcommon/serial-codes.h"
56 #include "libcommon/filespec.h"
57 #include "libSPI/SPI-command-set.h"
58 #include "libSPI/SPI-flash-bits.h"
59 #include "libkick/proppins.h"
60 #include "libkick/chipspec.h"
62 #include "libkick/fast-SPI.h"
63 #include "kick.h" //include macro defs, type defs and func prototypes
64 
65 //project source files
66 #include "libprop/putChar.c" //modified putChar()
67 #include "libcommon/hexdigit2bin.c"
68 #include "libcommon/bin2hexdigit.c"
69 #include "libcommon/filespec.c" //file format database
70 #include "libkick/chipspec.c" //chip database
71 
72 //globals, will be patched by propeller-load
74 int _cfg_rstdisable = -1;
75 int _cfg_baudrate = -1;
76 
77 //globals
78 unsigned char cmd_CE = CMD__CE_0X60;
79 struct tag_xcog0 xcog0;
80 struct tag_xcog1 xcog1;
82 struct tag_chip chip = { 0, chipspec };
83 struct tag_filespec * pfspec;
84 
85 
86 
87 /******************************************************************/
116 int main(void) {
117  //setup ledstat():
118  xcog1.yellow = ON;
119  xcog1.inlevel = 0;
120  cog_run(&ledstat, STACK_LEDSTAT);
121 
122  //SPI-Bus ini: SPI-Bus is off
123  xcog1.green = ON; //indicate status: SPI-Bus is off
124 
125  //disable RST
126  if(_cfg_rstdisable > 0) {
127  high(RST_DISABLE); //disable RST
128  xcog1.orange = ON;
129  }
130 
131  //reconfigure simpleterm
133  simpleterm_reopen(PIN_RX, PIN_TX, 0, _cfg_baudrate);
134 
135  //data initialisation
137  pfspec = &(filespec[MOTBIN]);
138 
139  //Do we talk to connect or to a propeller-terminal?
140  if(_cfg_modeterminal > 0) { //terminal mode?
141  greeting();
142  connected();
143  if(plug_detect()) {
144  outstr("Terminal Mode. Using reduced set of keys.\r\n");
145  menu(MODE_TERMINAL); //call menu
146  }
147  }
148  else { //normal connect mode
149  char k; //used for initial handshake
150  outfifo(ENQ); //request trigger (if not already on the way)
151  k = getChar(); //receive (any) trigger
152 
153  //enable RST
154  _cfg_rstdisable = 0;
155  low(RST_DISABLE);
156  xcog1.orange = OFF;
157 
158  if(k == ACK) { //connect has replied
159  greeting();
160  connected();
161  if(plug_detect()) {
162  outstr("\r\n");
163  menu(MODE_CONNECT); //call menu
164  }
165  }
166  }
167 
168  //end of program
170  OUTA |= BIT_PNP_DEVICE; //disable pnp device, make sure SPI-Bus is off
171  outstr("You may now switch off the chipflasher board.\r\n");
172  for(int n = 3; n; n--) {
173  exit_sequence(0x00); //this is understood by both, connect _and_ propeller-terminal
174  usleep(200000);
175  }
176  while(1); //hang-up
177  return(0); //normal quit
178 }
179 
180 
181 
182 void connected (
183  void
184  )
185 {
186  char s[SIZE_STR_MESSAGE];
187  sprinti(s, "%s%d%s", "Connected with ", _cfg_baudrate, " baud.\r\n");
188  outstr(s);
189 }
190 
191 
192 
193 void mirror (
194  char * keymsg
195  )
196 {
197  outstr("\r\n");
198  outstr(keymsg);
199  outstr("...\r\n");
200 }
201 
202 
203 
205  const enum tag_blocksize blocksize
206  )
207 {
208  char s[SIZE_STR_MESSAGE];
209  unsigned int blocks;
210 
211  //setup
212  blocks = chip.pspec->chipsize / blocksize;
213 
214  //more input
215  unsigned int block_to_read;
216  xcog1.inlevel++;
217  sprinti(s, "Block to read (hex 0..%x): ", blocks - 1);
218  outstr(s);
219  block_to_read = getHex();
220 
221  //catch range errors
222  if(block_to_read >= blocks) {
223  range_error();
224  return;
225  }
226 
227  //more input
228  unsigned char mode_screen_output;
229  mode_screen_output = yes_no("Do you need output on screen", 0) << 7;
230 
231  //action
232  SPI_ON;
233  chip_txfile(
234  pfspec,
236  block_to_read * blocksize,
237  blocksize,
238  mode_screen_output
239  );
241 }
242 
243 
244 
245 /******************************************************************/
252  void
253  )
254 {
255  int r = WIP_polling();
256  if(r > MAX_POLLING) {
257  outstr("WIP_polling overflow.\r\n");
258  return -1;
259  }
260  else {
261  char s[SIZE_STR_MESSAGE];
262  sprinti(s, "WIP_polling: %d\r\n", r);
263  outstr(s);
264  }
265  return 0; //success
266 }
267 
268 
269 
270 /******************************************************************/
276  void
277  )
278 {
279  xcog1.inlevel = 0;
280  outstr("Out of range error!\r\n");
281 }
282 
283 
284 
285 /******************************************************************/
292  const enum tag_blocksize blocksize,
293  const unsigned char blockcmd
294  )
295 {
296  char s[SIZE_STR_MESSAGE];
297  unsigned int first_block;
298  unsigned int last_block;
299  unsigned int blocks;
300 
301  //setup
302  blocks = chip.pspec->chipsize / blocksize;
303 
304  //more input
305  xcog1.inlevel++;
306  sprinti(s, "First block to erase (hex 0..%x): ", blocks - 1);
307  outstr(s);
308  first_block = getHex();
309 
310  //catch out of range error
311  if(first_block >= blocks) {
312  range_error();
313  return;
314  }
315 
316  //more input
317  xcog1.inlevel++;
318  sprinti(s, "Last block to erase (hex %x..%x): ", first_block, blocks - 1);
319  outstr(s);
320  last_block = getHex();
321 
322  //catch out of range error
323  if( (last_block >= blocks) ||
324  (last_block < first_block) ) {
325  range_error();
326  return;
327  }
328 
329  //check for dry-run
330  check_dryrun();
331 
332  //action
333  if(yes_no("Sure to proceed", 0)) {
334  SPI_ON;
335  while(first_block <= last_block) {
336  unsigned int firstloc;
337 
338  firstloc = first_block * blocksize;
339  WPn_HIGH;
340  cmd_WREN();
341  CHIP_ON;
342  cmd(blockcmd, firstloc, chip.addrlen_in_bits);
343  CHIP_OFF;
344  WPn_LOW;
345 
346  sprinti(s, "Block 0x%x... ", first_block++);
347  outstr(s);
348  if(!do__WIP_polling()) {
349  outstr("verifying...\r\n");
350  if(verify_0xff(firstloc, blocksize)) {
351  outstr("Verify error!\r\n");
352  break;
353  }
354  }
355  else
356  break;
357  }
358  }
359  SPI_OFF(MODE_SPI_OFF); //check_dryrun() has left SPI Bus in standby mode
360 }
361 
362 
363 
364 /******************************************************************/
369 void SR_intro(
370  unsigned char regno
371  )
372 {
373  char s[SIZE_STR_MESSAGE];
374  sprinti(s, "\r\n" \
375  "SR%d:\r\n" \
376  , regno + 1);
377  outstr(s);
378 }
379 
380 
381 
382 /******************************************************************/
388  unsigned char pswitch
389  )
390 {
391  xcog1.inlevel = 0;
392  if(yes_no("Sure to proceed", 0)) {
393  SPI_ON;
394  WPn_HIGH;
395 
396  //any address within sector will do
397  for(unsigned int addr = chip.pspec->chipsize; addr; addr -= SIZE_4K) {
398  cmd_WREN();
399  CHIP_ON;
400  pswitch == OFF ? \
401  cmd(CMD__US, addr - 1, 24) : \
402  cmd(CMD__PS, addr - 1, 24);
403  CHIP_OFF;
404  WIP_polling();
405  }
406  WPn_LOW;
407  SR_report(0);
409  }
410 }
411 
412 
413 
414 /******************************************************************/
421  unsigned char * key_is_valid,
422  unsigned char * quit
423  )
424 {
425  char keyinput;
426  int keyid = 0;
427 
428  keyinput = getChar();
429  while((keymsg[keyid][1] != keyinput) &&
430  (keymsg[keyid][3] != keyinput || keyinput == ' ') &&
431  (keyid != ID_NONE))
432  keyid++;
433 
434  if(!(keyreg & (1 << keyid))) {
435  *key_is_valid = 0;
436  }
437  else {
438  mirror(keymsg[keyid]);
439 
440  switch(keyinput) {
441  //key active by default
442  case 'q': //quit
443  {
444  //action
445  if(DIRA & BIT_PNP_DEVICE) {
447  outstr("The SPI bus has been powered off.\r\n");
448  //TODO: Why do we have to reset the chip index?
451  }
452  else {
453  xcog1.inlevel = 0;
454  *quit = 1;
455  xcog1.green = ON; //restore LED
456  }
457  }
458  break;
459 
460  //key active by default
461  case 't': //toggle output format
462  {
463  //action
464  xcog1.inlevel = 0;
465  if(pfspec == &(filespec[MOTBIN]))
466  pfspec = &(filespec[HEXDUMP]);
467  else
468  pfspec--;
469  }
470  break;
471 
472  case 'W': { //set config
473  char s[SIZE_STR_MESSAGE];
474  unsigned char byte = 0;
475  unsigned char m = 8;
476  unsigned char bit;
477  unsigned char max_regno = 0;
478  unsigned char regno = 0;
479  unsigned char bitmask;
480  char* p;
481 
482  if(chip.pspec->cmdset & (1 << X35_RDSR2))
483  max_regno = 1;
484  if(chip.pspec->cmdset & (1 << X15_RDSR3))
485  max_regno = 2;
486 
487  if(max_regno > 0) {
488  xcog1.inlevel++;
489  sprinti(s, "Which config register to change (%d..%d)? ", 1, max_regno + 1);
490  outstr(s);
491  regno = getDec() - 1;
492  if(regno < 0 || regno > max_regno) {
493  range_error();
494  break;
495  }
496  }
497  bitmask = chip.pspec->sr_wrmask[regno];
498  p = chip.pspec->sr_bitnames[regno];
499 
500  SPI_ON;
501  byte = SR_report(regno);
503  xcog1.inlevel++;
504  SR_intro(regno);
505  outstr( "Bitname\tBit\tStatus\tValue?\r\n" \
506  "-------\t---\t------\t------\r\n" \
507  );
508  while(*p != '\0') {
509  outfifo(*p);
510  if(*p == '\t') {
511  char cstat;
512  outfifo('0' + --m);
513  outstr(":\t"); //trigger permanent flush with ':'.
514  bit = 1 << m;
515  cstat = byte & bit ? '1' : '0';
516  outfifo(cstat);
517  outfifo('\t');
518  if(bitmask & bit) {
519  unsigned char in;
520  in = getChar();
521  if(in == '0') {
522  outfifo('0');
523  byte &= ~bit;
524  }
525  else if(in == '1') {
526  outfifo('1');
527  byte |= bit;
528  }
529  else {
530  outfifo(cstat);
531  }
532  }
533  else {
534  outfifo('x');
535  }
536  outstr("\r\n");
537  }
538  p++;
539  }
540  sprinti(s, "New register value would be: %d\r\n", byte);
541  outstr(s);
542  //action
543  if(yes_no("Sure to proceed", 0)) {
544  SPI_ON;
545  WPn_HIGH;
546  cmd_WRSR(regno, byte);
547  sprinti(s, "polling checks: %d\r\n", WIP_polling());
548  outstr(s);
549  WPn_LOW;
550  SR_report(regno);
552  }
553  }
554  break;
555 
556  case 'r': //show config
557  {
558  //action
559  xcog1.inlevel = 0;
560  SPI_ON;
561  SR_report(0);
562  if(chip.pspec->cmdset & (1 << X35_RDSR2))
563  SR_report(1);
564  if(chip.pspec->cmdset & (1 << X15_RDSR3))
565  SR_report(2);
567  }
568  break;
569 
570  case 'G': //global sector protect
572  break;
573 
574  case 'X': //global sector unprotect
576  break;
577 
578  //key active by default
579  case 'f': //force chip model
580  {
581  //action
582  xcog1.inlevel = 0;
583  if(!chip.index)
585  else
586  chip_ini(chip.index - 1);
588  }
589  break;
590 
591  //key active by default
592  case 'd': //detect chip
593  {
594  char s[SIZE_STR_MESSAGE];
595 
596  //JEDEC__RDID (should be the first command to use)
597  xcog1.inlevel = 0;
598  unsigned char powerup_extra = POWERUP_EXTRA;
599  int id_JEDEC;
600 
601  //power up
602  do {
603  SPI_ON;
604  if(!(id_JEDEC = cmd_RDID_JEDEC())) {
606  usleep(POWERUP_OFFTIME);
607  }
608  else
609  break;
610  } while(powerup_extra--);
611 
612  //set chip
613  if(powerup_extra == 0xff) {
614  outstr("Power failure? Clip attached?\r\n");
615  }
616  else {
617  struct tag_chipspec * check = chip.pspec - chip.index;
618  unsigned char i = 0;
619  while(i < ARRAY_CHIPSPEC) {
620  if((check->cmdset & (1 << X9F_RDID)) && id_JEDEC == check->id_JEDEC)
621  break;
622  i++;
623  check++;
624  }
625  if(i == ARRAY_CHIPSPEC) { //no match occured
626  outstr("No match in database.\r\n");
627  sprinti(s, "Chip's JEDEC ID: 0x%06x\r\n", id_JEDEC);
628  outstr(s);
630  }
631  else {
632  chip_ini(i);
634  sprinti(s, "Chip successfully detected: %s\r\n", chip.pspec->name);
635  outstr(s);
636  if(!chip.pspec->sr_is_static)
637  outstr("NOTE: The Status Register is not static, the SPI bus is kept powered until you quit.\r\n");
638  if(chip.pspec->id_JEDEC == 0x00ef3013)
639  outstr("NOTE: You may set bit SRP in the status register to enable #WP control.\r\n");
641  }
642  }
643  }
644  break;
645 
646  case 'p': //read page
647  {
648  //get more input
649  char s[SIZE_STR_MESSAGE];
650  unsigned int page_to_read;
651  xcog1.inlevel++;
652  sprinti(s, "Page to read (hex 0..%x): ", chip.pages - 1);
653  outstr(s);
654  page_to_read = getHex();
655 
656  //catch range error
657  if(page_to_read >= chip.pages) {
658  range_error();
659  break;
660  }
661 
662  //more input
663  unsigned char mode_screen_output;
664  mode_screen_output = yes_no("Do you need output on screen", 0) << 7;
665 
666  //action
667  unsigned int firstloc;
668  SPI_ON;
669  firstloc = page_to_read * chip.pspec->pagesize;
670  chip_txfile(
671  pfspec,
673  firstloc,
675  mode_screen_output
676  );
678  }
679  break;
680 
681  case 'm': //read random area
682  {
683  //more input
684  char s[SIZE_STR_MESSAGE];
685  unsigned int startaddr;
686  xcog1.inlevel++;
687  sprinti(s, "Startaddress (hex 0..%08x): ", chip.pspec->chipsize - 1);
688  outstr(s);
689  startaddr = getHex();
690 
691  //catch error
692  if(startaddr >= chip.pspec->chipsize) {
693  range_error();
694  break;
695  }
696 
697  //more input
698  unsigned int lastaddr;
699  xcog1.inlevel++;
700  sprinti(s, "Last address (hex %08x..%08x): ", startaddr, chip.pspec->chipsize - 1);
701  outstr(s);
702  lastaddr = getHex();
703 
704  //catch error
705  if(lastaddr >= chip.pspec->chipsize) {
706  range_error();
707  break;
708  }
709 
710  //more input
711  unsigned char mode_screen_output;
712  mode_screen_output = yes_no("Do you need output on screen", 0) << 7;
713 
714  //action
715  SPI_ON;
716  chip_txfile(
717  pfspec,
719  startaddr,
720  lastaddr - startaddr + 1,
721  mode_screen_output
722  );
724  }
725  break;
726 
727  case 's': //read block 4k
729  break;
730 
731  case 'k': //read block 32k
733  break;
734 
735  case 'b': //read block 64k
737  break;
738 
739  case 'c': //read chip
740  {
741  //more input
742  unsigned char mode_screen_output;
743  mode_screen_output = yes_no("Do you need output on screen", 0) << 7;
744 
745  //action
746  SPI_ON;
747  chip_txfile(
748  pfspec,
750  0x00,
752  mode_screen_output
753  );
755  }
756  break;
757 
758  case 'S': //4k block erase
760  break;
761 
762  case 'K': //erase block 32k
764  break;
765 
766  case 'B': //erase block 64k
768  break;
769 
770  case 'C': //erase chip
771  {
772  //action
773  if(yes_no("Sure to proceed", 0)) {
774  SPI_ON;
775  chip_erase();
776  outstr("verifying...\r\n");
777  if(verify_0xff(0x00, chip.pspec->chipsize) != 0)
778  outstr("Verify error!\r\n");
780  }
781  }
782  break;
783 
784  case 'I': //write file to chip
785  {
786  //more input
787  unsigned char screen_output;
788  screen_output = yes_no("Do you need output on screen", 1);
789 
790  //check for dry-run
791  check_dryrun();
792 
793  //action
794  if(yes_no("Sure to proceed", 0))
795  chip_rxfile(&xcog0, screen_output);
796  else
798  }
799  break;
800 
801  default:
802  *key_is_valid = 0;
803  }
804  if(key_is_valid)
805  outstr(MSG_DONE);
806  }
807 }
808 
809 
810 
811 /******************************************************************/
821  void
822  )
823 {
824  //check for dry-run
825  unsigned char sr;
826  SPI_ON;
827  sr = cmd_RDSR(CMD__RDSR);
828 
829  if(chip.pspec->id_JEDEC == 0x00ef3013)
830  sr &= 0b01111111; //don't care for SRP
831 
832  if(sr & chip.pspec->sr_wrmask[0]) {
833  outstr("Be aware: The Status Register 1 is not zero, some memory areas may be write protected.\r\n");
834  }
836 }
837 
838 
839 
840 /******************************************************************/
846  void
847  )
848 {
849  if(input(PIN_PLUGTESTn)) {
850  outstr("No SPI-plug detected!\r\n");
851  return(0);
852  }
853  else {
854  outstr("SPI-plug seems to be attached.\r\n");
855  return(1);
856  }
857 }
858 
859 
860 
861 /******************************************************************/
866 void menu(
867  unsigned char mode
868  )
869 {
870  char s[SIZE_STR_MESSAGE];
871  unsigned char quit = 0;
872  unsigned char key_is_valid = 1;
873 
874  while(!quit) {
875  if(key_is_valid) {
876  //set key
878  if(mode & MODE_CONNECT)
879  key_config();
880 
881  //greeting
882  greeting();
883 
884  //status line 1
885  sprinti(s, "Chip: %s", chip.pspec->name);
886  outstr(s);
887  sprinti(s, "\r\t\t\t\tFormat: %s", pfspec->format_name);
888  outstr(s);
889  {
890  unsigned char mode_0xff = pfspec->mode_0xff;
891  outstr("\r\t\t\t\t\t\t\t\t0xFF: ");
892  outstr(mode_0xff & MODE_SPLIT ? "split, " : "");
893  outstr(mode_0xff & MODE_STRIP ? "strip, " : "");
894  sprinti(s, "inline_%d\r\n", mode_0xff & 0b00011111);
895  outstr(s);
896  }
897 
898  //menu
899  menu_options();
900  outstr("Your Choice? ");
901  }
902  else
903  key_is_valid = 1;
904 
905  //key polling
906  xcog1.inlevel = 1;
907  key_polling(&key_is_valid, &quit);
908  xcog1.inlevel = 0;
909  }
910 }
911 
912 
913 
914 /******************************************************************/
919 void hr(
920  char c,
921  int n,
922  char nl
923  )
924 {
925  while(n--)
926  outfifo(c);
927  if(nl != NULL)
928  outstr("\r\n");
929 }
930 
931 
932 
933 /******************************************************************/
939 unsigned char get_addrlen(
940  enum tag_type_of_addrlen type_of_addrlen,
941  unsigned int addr
942  )
943 {
944  unsigned char addrlen_in_bytes;
945 
946  if(addr < SIZE_256) {
947  if(type_of_addrlen == ADDRLEN_MOT)
948  addrlen_in_bytes = 2;
949  else
950  addrlen_in_bytes = 1;
951  }
952  else if(addr < SIZE_64K)
953  addrlen_in_bytes = 2;
954  else if(addr < SIZE_128MBIT)
955  addrlen_in_bytes = 3;
956  else
957  addrlen_in_bytes = 4;
958 
959  if(type_of_addrlen == ADDRLEN_IN_BITS)
960  return(addrlen_in_bytes << 3);
961  return(addrlen_in_bytes);
962 }
963 
964 
965 
966 /******************************************************************/
972  void
973  )
974 {
975  if(chip.pspec->cmdset & (1 << X03_READ)) {
976  unsigned int reg = keyreg;
977 
978  //enable 'fetch file and write chip'
979  if((chip.pspec->cmdset & (1 << X02_PP)) ||
980  (chip.pspec->cmdset & (1 << X02_BP)) ||
981  (chip.pspec->cmdset & (1 << XAD_CP)))
982  reg |= KEYBIT_I;
983 
984  //enable 'read page'
985  if(chip.pspec->cmdset & (1 << X02_PP))
986  reg |= KEYBIT_p;
987 
988  //enable 'sector erase'
989  if(chip.pspec->cmdset & (1 << X20_SE))
990  reg |= KEYBIT_s | KEYBIT_S;
991 
992  //read block 32k
993  //erase block 32k
994  if(chip.pspec->cmdset & (1 << X52_BE32K))
995  reg |= KEYBIT_k | KEYBIT_K;
996 
997  //read block 64k
998  //erase block 64k
999  if(chip.pspec->cmdset & (1 << XD8_BE64K))
1000  reg |= KEYBIT_b | KEYBIT_B;
1001 
1002  reg |= KEYBIT_c | KEYBIT_m;
1003 
1004  //enable 'erase chip'
1005  if(chip.pspec->cmdset & (1 << X60_CE)) {
1006  reg |= KEYBIT_C;
1007  }
1008  else if(chip.pspec->cmdset & (1 << XC7_CE)) {
1009  reg |= KEYBIT_C;
1010  cmd_CE = CMD__CE_0XC7; //override global CE command
1011  }
1012 
1013  //enable 'report status register'
1014  if(chip.pspec->cmdset & (1 << X05_RDSR))
1015  reg |= KEYBIT_r;
1016 
1017  //enable 'write block protection bits'
1018  if(chip.pspec->cmdset & (1 << X01_WRSR))
1019  reg |= KEYBIT_W;
1020 
1021  //enable 'global protect'
1022  if(chip.pspec->cmdset & (1 << X36_PS))
1023  reg |= KEYBIT_G;
1024 
1025  //enable 'global unprotect'
1026  if(chip.pspec->cmdset & (1 << X39_US))
1027  reg |= KEYBIT_X;
1028 
1029  keyreg = reg;
1030  }
1031 }
1032 
1033 
1034 
1035 /******************************************************************/
1041  unsigned int k1,
1042  char * k1msg,
1043  unsigned int k2,
1044  char * k2msg,
1045  unsigned int k3,
1046  char * k3msg
1047  )
1048 {
1049  if(keyreg & (k1 | k2 | k3)) {
1050  if(keyreg & k1)
1051  outstr(k1msg);
1052  if(keyreg & k2) {
1053  outstr("\r\t\t\t\t");
1054  outstr(k2msg);
1055  }
1056  if(keyreg & k3) {
1057  outstr("\r\t\t\t\t\t\t\t\t");
1058  outstr(k3msg);
1059  }
1060  outstr("\r\n");
1061  }
1062 }
1063 
1064 
1065 
1066 /******************************************************************/
1072  void
1073  )
1074 {
1075  hr('-', MENUWIDTH, '\n');
1076  menu_line(
1080  );
1081  menu_line(
1085  );
1086  menu_line(
1090  );
1091  menu_line(
1095  );
1096  menu_line(
1100  );
1101  menu_line(
1105  );
1106  menu_line(
1108  0, NULL,
1109  0, NULL
1110  );
1111 }
1112 
1113 
1114 
1115 /******************************************************************/
1122 unsigned char verify_0xff(
1123  unsigned int firstloc,
1124  unsigned int memsize
1125  )
1126 {
1127  unsigned char err = 0;
1128 
1129  CHIP_ON;
1130  cmd(CMD__READ, firstloc, chip.addrlen_in_bits);
1131  while(memsize--) {
1132  if(inb() != 0xff) {
1133  err = 1;
1134  break;
1135  }
1136  }
1137  CHIP_OFF;
1138  return err;
1139 }
1140 
1141 
1142 
1143 /******************************************************************/
1163  struct tag_linedat * linedat,
1164  union tag_typeS * typeS,
1165  char * linebuf
1166  )
1167 {
1168  unsigned char checksum;
1169  unsigned char v;
1170  unsigned char n;
1171 
1172  //make sure struct is filled up
1173  MOT_typeS_fillup(typeS);
1174 
1175  //store datalength in first location, line ending is CR+NL
1176  *linebuf++ = 4 + (typeS->bf.addrlen << 1) + linedat->payload + 4;
1177 
1178  //print Sn... (2 bytes)
1179  linebuf += sprinti(linebuf, "S%01d", typeS->bf.num);
1180 
1181  //print length (2 bytes)
1182  v = typeS->bf.addrlen + linedat->payload + 1;
1183  linebuf += sprinti(linebuf, "%02x", v);
1184  checksum = v; //start summing checksum
1185 
1186  //print address (4..8 bytes)
1187  n = typeS->bf.addrlen;
1188  while(n--) {
1189  v = (linedat->startaddr >> (n << 3)) & 0xff;
1190  linebuf += sprinti(linebuf, "%02x", v);
1191  checksum += v;
1192  };
1193 
1194  //print data (n bytes)
1195  n = linedat->payload;
1196  linedat->startaddr += n; //update startaddress
1197  while(n--) {
1198  char byte = linedat->buf[linedat->rd++ & linedat->mask];
1199  *linebuf++ = byte;
1200  checksum += byte;
1201  };
1202 
1203  //print checksum (2 bytes) and CR+NL (2 bytes)
1204  sprinti(linebuf, "%02x\r\n", ~checksum & 0xff);
1205 }
1206 
1207 
1208 
1209 /******************************************************************/
1215  char * str,
1216  char c
1217  )
1218 {
1219  int n = 0;
1220  char * p = str;
1221 
1222  while((*(p++) != c) && (n < SIZE_STRBUF))
1223  n++;
1224  return n;
1225 }
1226 
1227 
1228 
1229 /******************************************************************/
1238  char * header,
1239  char * linebuf
1240  )
1241 {
1242  struct tag_linedat linedat = {
1243  header, //buf: characters are stored in header
1244  0xff, //mask: allow 0..255 characters
1245  0, //rd: reset to zero
1246  0, //wr: reset to zero
1247  0x0000, //startaddr: 0x0000
1248  strpos(header, '\0') //payload: length of header string
1249  };
1250  union tag_typeS typeS = {
1251  0 //typeS.bf.addrlen is 0x00, typeS.num is 0x00; MOT_typeS_fillup() will
1252  //result in an S0 record.
1253  };
1254  MOT_mkline(&linedat, &typeS, linebuf);
1255 }
1256 
1257 
1258 
1259 /******************************************************************/
1263 void MOT_data (
1264  struct tag_linedat * linedat,
1265  char * linebuf
1266 )
1267 {
1268  union tag_typeS typeS = { 0 };
1269  typeS.bf.data = 1;
1270  typeS.bf.addrlen = get_addrlen(ADDRLEN_MOT, linedat->startaddr);
1271  MOT_mkline(linedat, &typeS, linebuf);
1272 }
1273 
1274 
1275 
1276 /******************************************************************/
1281  unsigned int lines,
1282  char * linebuf
1283  )
1284 {
1285  struct tag_linedat r = { NULL, 0, 0, 0, lines, 0 };
1286  union tag_typeS typeS = { 0 };
1287  typeS.bf.linecount = 1;
1288  typeS.bf.addrlen = get_addrlen(ADDRLEN_MOT, lines);
1289  MOT_mkline(&r, &typeS, linebuf);
1290 }
1291 
1292 
1293 
1294 /******************************************************************/
1303 unsigned char yes_no (
1304  char * question,
1305  unsigned char level_rst
1306  )
1307 {
1308  unsigned char k;
1309 
1310  xcog1.inlevel++; //increase input level
1311  outstr(question);
1312  outstr(" (Y = yes | n = no)? ");
1313  k = getChar();
1314  if(!level_rst)
1315  xcog1.inlevel = 0; //no more input, action follows
1316  if(k == 'Y') {
1317  outstr("yes\r\n");
1318  return 1;
1319  }
1320  outstr("no\r\n");
1321  return 0;
1322 }
1323 
1324 
1325 
1326 /******************************************************************/
1331 void chip_ini (
1332  unsigned char new_index
1333  )
1334 {
1335  chip.pspec = chip.pspec - chip.index + new_index;
1336  chip.index = new_index;
1341 }
1342 
1343 
1344 
1345 signed char chip_read (
1346  struct tag_filespec * filespec,
1347  unsigned int firstloc,
1348  unsigned int memsize,
1349  unsigned int * lines,
1350  char * linebuf
1351  )
1352 {
1353  //switches:
1354  #define SCANNING_DATA 0x00 //test != 0xff, test_old != 0xff
1355  #define DATA_START 0x01 //test != 0xff, test_old == 0xff
1356  #define FF_START 0x02 //test == 0xff, test_old != 0xff
1357  #define SCANNING_FF 0x03 //test == 0xff, test_old == 0xff
1358  //flags:
1359  #define APPLY_CUT 0x01
1360  #define HAS_NOT_BEEN_CUT_YET 0x02
1361  #define IS_0XFF 0x04
1362  //aux:
1363  #define MODE_0XFF filespec->mode_0xff
1364  #define INLINE_0XFF (MODE_0XFF & MODE_INLINE)
1365  #define PAYLOAD_DEFAULT (filespec->payload_default)
1366 
1367  struct tag_linedat linedat = {
1368  malloc(PAYLOAD_DEFAULT << 1), //shift left: provide extra space for inline prefetch
1369  (PAYLOAD_DEFAULT << 1) - 1,
1370  0,
1371  0,
1372  firstloc,
1373  0
1374  };
1375  unsigned char chars_tested = 0;
1376  unsigned char cut = 0;
1377  unsigned char test_old;
1378 
1379  /*
1380  * Create special startup condition:
1381  * We are jumping directly into DATA_START or SCANNING_FF.
1382  */
1383  unsigned char test = 0xff; //makes it easy to check for 0xff
1384  unsigned char runlen = INLINE_0XFF + 1; //SCANNING_FF decrements runlen
1385  unsigned char flags = ((IS_0XFF | HAS_NOT_BEEN_CUT_YET) & ~APPLY_CUT);
1386 
1387  //scan specified memory
1388  while(memsize) {
1389  //save & prefetch
1390  test_old = test; //save
1391  test = inb(); //prefetch in respect to chars_tested
1392 
1393  //check memsize first to catch address roll-over
1394  if(chars_tested == memsize) {
1395  cut = chars_tested;
1396  flags |= APPLY_CUT;
1397  }
1398  else if(MODE_0XFF & MODE_SPLIT) {
1399  switch((((test == 0xff) << 1) | (test_old == 0xff))) {
1400  case FF_START:
1401  cut = chars_tested; //save cut position in case we need later
1402  flags |= HAS_NOT_BEEN_CUT_YET;
1403  runlen = INLINE_0XFF;
1404  if(!runlen) {
1405  if(cut)
1406  flags |= APPLY_CUT;
1407  }
1408  break;
1409 
1410  case SCANNING_FF:
1411  if(runlen) {
1412  runlen--;
1413  }
1414  else {
1415  if(flags & HAS_NOT_BEEN_CUT_YET) {
1416  flags &= ~HAS_NOT_BEEN_CUT_YET;
1417  if(cut)
1418  flags |= APPLY_CUT;
1419  }
1420  }
1421  break;
1422 
1423  case DATA_START:
1424  if(!runlen) {
1425  cut = chars_tested; //save cut position in case we need later
1426  if(cut)
1427  flags |= APPLY_CUT;
1428  }
1429  else {
1430  cut = 0; //we didn’t use the saved cut position, let’s reset to zero
1431  }
1432  break;
1433 
1434  case SCANNING_DATA:
1435  break;
1436  }
1437  }
1438 
1439  //maximal payload?
1440  if(!(flags & APPLY_CUT)) {
1441  if(chars_tested == PAYLOAD_DEFAULT) {
1442  if(!cut)
1443  cut = chars_tested;
1444  flags |= APPLY_CUT;
1445  }
1446  }
1447 
1448  //store prefetch in buffer
1449  linedat.buf[linedat.wr++ & linedat.mask] = test;
1450 
1451  //check for 0xff line
1452  if(test_old != 0xff)
1453  flags &= ~IS_0XFF;
1454 
1455  //evaluate flags
1456  if(flags & APPLY_CUT) {
1457  //update
1458  chars_tested -= cut;
1459  memsize -= cut;
1460 
1461  //skip output of 0xff?
1462  if((MODE_0XFF & MODE_STRIP) && (flags & IS_0XFF)) {
1463  linedat.rd += cut;
1464  linedat.startaddr += cut;
1465  if(linebuf_out(NULL) == -1)
1466  goto ERROR;
1467  }
1468  else {
1469  //update linedat
1470  linedat.payload = cut;
1471 
1472  //make data line
1473  switch(filespec->format) {
1474  case HEXDUMP:
1475  HEXDUMP_mkline(&linedat, linebuf);
1476  break;
1477 
1478  case MOTBIN:
1479  MOT_data(&linedat, linebuf);
1480  break;
1481  }
1482 
1483  //put out
1484  if(linebuf_out(linebuf) == -1)
1485  goto ERROR;
1486  *lines += 1; //sum up
1487  }
1488 
1489  //reset values
1490  cut = 0;
1491  flags = (IS_0XFF & ~APPLY_CUT & ~HAS_NOT_BEEN_CUT_YET);
1492  }
1493 
1494  //increment counter
1495  chars_tested++;
1496  }
1497  free(linedat.buf);
1498  return 0;
1499 
1500  ERROR:
1501  free(linedat.buf);
1502  return -1;
1503 }
1504 
1505 
1506 
1508  struct tag_filespec * filespec,
1509  unsigned char addrlen_in_bits,
1510  unsigned int firstloc,
1511  unsigned int memsize,
1512  unsigned char screenmode
1513  )
1514 {
1515  char linebuf[SIZE_LINEBUF];
1516  unsigned int lines = 0;
1517 
1518  //activate host
1519  outfifo(SOH);
1520  if(screenmode & MODE_SCREEN_OUTPUT)
1522  else
1525 
1526  //put chip on
1527  CHIP_ON;
1528  cmd(CMD__READ, firstloc, addrlen_in_bits);
1529 
1530  //create header
1531  char header[SIZE_HEADER];
1532  sprinti(header, HEADER, chip.pspec->name);
1533 
1534  //select format
1535  switch(filespec->format) {
1536  case MOTBIN:
1537  //make & put header
1538  MOT_header(header, linebuf);
1539  if(linebuf_out(linebuf) == -1)
1540  goto ERROR;
1541 
1542  //read chip
1543  if(chip_read(filespec, firstloc, memsize, &lines, linebuf) == -1)
1544  goto ERROR;
1545 
1546  //make & put summary line
1547  MOT_summary(lines, linebuf);
1548  if(linebuf_out(linebuf) == -1)
1549  goto ERROR;
1550  break;
1551 
1552  case HEXDUMP:
1553  //make & put header
1554  *linebuf = sprinti(linebuf, "-#header: %s\r\n", header) - 1;
1555  if(linebuf_out(linebuf) == -1)
1556  goto ERROR;
1557 
1558  //read chip
1559  if(chip_read(filespec, firstloc, memsize, &lines, linebuf) == -1)
1560  goto ERROR;
1561 
1562  //make & put summary line
1563  *linebuf = sprinti(linebuf, "-#lines: %d\r\n", lines) - 1;
1564  if(linebuf_out(linebuf) == -1)
1565  goto ERROR;
1566  break;
1567  }
1568  goto SUCCESS;
1569 
1570  ERROR:
1571 
1572  SUCCESS:
1573  CHIP_OFF;
1574  //terminate connection
1575  outfifo(EOT);
1576  return;
1577 }
1578 
1579 
1580 
1581 /******************************************************************/
1592 signed char linebuf_out (
1593  char * linebuf
1594  )
1595 {
1596  unsigned char c;
1597  char * p;
1598 
1599  do {
1600  p = linebuf;
1601  outfifo(STX);
1602  for(int n = *p++; n; n--)
1603  outfifo(*p++);
1604  outfifo(ETX);
1605  c = getChar();
1606  } while(c == ENQ);
1607 
1608  if(c != ACK)
1609  return -1;
1610  return 0;
1611 }
1612 
1613 
1614 
1615 char outfifo (
1616  char c
1617  )
1618 {
1619  if(c == CARR_RET)
1620  c = CLIM_CR;
1621  else if(c == NEW_LINE)
1622  c = CLIM_NL;
1623  putChar(c);
1624  return (c);
1625 }
1626 
1627 
1628 
1629 int outstr (
1630  char * s
1631  )
1632 {
1633  int n = 0;
1634 
1635  //don't allow this loop to run infinitively
1636  while(*s != '\0' && n < 256) {
1637  outfifo(*s++);
1638  n++;
1639  }
1640  return(n);
1641 }
1642 
1643 
1644 
1645 /******************************************************************/
1661  struct tag_linedat * linedat,
1662  char * linebuf_orig
1663  )
1664 {
1665  char * linebuf = linebuf_orig;
1666  unsigned int prescan = linedat->rd;
1667  unsigned char n, tab, fillup;
1668 
1669  //create space for datalength
1670  linebuf++;
1671 
1672  //write addr
1673  linebuf += sprinti(linebuf, "%08x: ", linedat->startaddr);
1674 
1675  //write hex bytes
1676  n = linedat->payload;
1677  linedat->startaddr += n; //update startaddr in advance
1678  while(n--)
1679  linebuf += sprinti(linebuf, "%02x ", linedat->buf[prescan++ & linedat->mask]);
1680 
1681  //append ascii equivalent
1682  n = linedat->payload;
1683  tab = fillup = pfspec->payload_default - n;
1684  while(tab--)
1685  linebuf += sprinti(linebuf, " ");
1686  linebuf += sprinti(linebuf, " #");
1687  while(n--) {
1688  unsigned char test;
1689  test = linedat->buf[linedat->rd++ & linedat->mask];
1690  *linebuf++ = isprint(test) ? test : '.';
1691  }
1692  while(fillup--)
1693  *linebuf++ = ' ';
1694 
1695  //write new line
1696  *linebuf++ = '\r';
1697  *linebuf++ = '\n';
1698 
1699  //save datalength
1700  *linebuf_orig = linebuf - linebuf_orig - 1;
1701 }
1702 
1703 
1704 
1705 /******************************************************************/
1711 void greeting (
1712  )
1713 {
1714  outfifo('\r');
1715  hr('=', 5, NULL);
1717  hr('=', MENUWIDTH - (sizeof(HEADER_KICK) - 1) - 5, '\n');
1718 }
1719 
1720 
1721 
1722 /******************************************************************/
1727 void cmd_WREN (
1728  void
1729  )
1730 {
1731  CHIP_ON;
1732  outbits(CMD__WREN, 1 << 7);
1733  CHIP_OFF;
1734 }
1735 
1736 
1737 
1738 /******************************************************************/
1743 void cmd_WRSR (
1744  const unsigned char regno,
1745  const unsigned char byte
1746  )
1747 {
1748  unsigned char msbit = 7;
1749  unsigned int value = 0x00000000 | byte;
1750 
1751  //get SR0 backup for some chips using X01_WRSR to access SR1.
1752  value |= (cmd_RDSR(0) & chip.pspec->sr_wrmask[0]) << 8;
1753 
1754  CHIP_ON;
1755  if(chip.pspec->cmdset & (1 << X50_EWSR))
1756  outbits(CMD__EWSR, 1 << 7);
1757  else
1758  outbits(CMD__WREN, 1 << 7);
1759  CHIP_OFF;
1760  CHIP_ON;
1761  switch(regno) {
1762  case 2:
1763  outbits(CMD__WRSR3, 1 << 7);
1764  break;
1765 
1766  case 1:
1767  if(!(chip.pspec->cmdset & (1 << X31_WRSR2))) {
1768  /*
1769  * FIXME
1770  * Take care NOT to read volatile '1'-bits of SR0 and writing it
1771  * into non-volatile bits!
1772  *
1773  */
1774  msbit = 15;
1775  outbits(CMD__WRSR, 1 << 7);
1776  }
1777  else {
1778  outbits(CMD__WRSR2, 1 << 7);
1779  }
1780  break;
1781 
1782  case 0:
1783  default:
1784  outbits(CMD__WRSR, 1 << 7);
1785  break;
1786  }
1787  outbits(value, 1 << msbit);
1788  CHIP_OFF;
1789 }
1790 
1791 
1792 
1793 /******************************************************************/
1807  const unsigned int addr,
1808  unsigned char * buffer
1809  )
1810 {
1811  unsigned int pageaddr;
1812  int n_bytes;
1813 
1814  //mask page address
1815  pageaddr = addr & ~(chip.pspec->pagesize - 1);
1816 
1817  //disable hardware write protection
1818  WPn_HIGH;
1819 
1820  //set Write Enable Latch Bit
1821  cmd_WREN();
1822 
1823  //start
1824  CHIP_ON;
1825 
1826  //send PAGE PROGRAM command
1827  cmd(CMD__PP, pageaddr, chip.addrlen_in_bits);
1828 
1829  //how many bytes?
1830  n_bytes = chip.pspec->pagesize;
1831 
1832  while(n_bytes--) {
1833  //send databyte
1834  outbits(*buffer, 1 << 7);
1835 
1836  //increment pointers
1837  buffer++;
1838 
1839  //TODO: still in range?
1840  }
1841 
1842  //initiate pgm-cycle
1843  CHIP_OFF;
1844 
1845  //detect end of write cycle
1846  WIP_polling(); //wait until write cycle is finished
1847 
1848  //enable hardware write protection
1849  WPn_LOW;
1850 }
1851 
1852 
1853 
1854 /******************************************************************/
1863  const char status
1864  )
1865 {
1868  outfifo(status); //status
1869 }
1870 
1871 
1872 
1873 /******************************************************************/
1879  void
1880  )
1881 {
1882  unsigned char b;
1883  int n = 0;
1884 
1885  CHIP_ON;
1886  outbits(CMD__RDSR, 1 << 7);
1887  do {
1888  b = inb();
1889  if(++n > MAX_POLLING)
1890  break;
1891  } while(b & WIP); //cancel on overflow
1892  CHIP_OFF;
1893  return n;
1894 }
1895 
1896 
1897 
1898 /******************************************************************/
1903 unsigned int CPM_polling (
1904  void
1905  )
1906 {
1907  unsigned char b;
1908  unsigned int n = 0;
1909 
1910  CHIP_ON;
1911  outbits(CMD__RDSR, 1 << 7);
1912  do
1913  {
1914  b = inb();
1915  n++;
1916  }
1917  while((b & CPM) && n); //cancel on overflow
1918  CHIP_OFF;
1919  return n;
1920 }
1921 
1922 
1923 
1924 /******************************************************************/
1929 unsigned char SR_report (
1930  unsigned char regno
1931  )
1932 {
1933  char* p = chip.pspec->sr_bitnames[regno];
1934  unsigned char bitmask = chip.pspec->sr_wrmask[regno];
1935  unsigned char is_static = chip.pspec->sr_is_static[regno];
1936  char s[SIZE_STR_MESSAGE];
1937  unsigned char status;
1938 
1939  status = cmd_RDSR(regno);
1940  SR_intro(regno);
1941 
1942  //bit names and current status
1943  sprinti(s, "Bit No\t\t7\t6\t5\t4\t3\t2\t1\t0\r\n" \
1944  "Bitname\t\t%s\r\n" \
1945  "Status\t\t" \
1946  , p);
1947  outstr(s);
1948  for(int n = 0b10000000; n; n >>= 1)
1949  outstr((status & n) != 0 ? "1\t" : "0\t");
1950 
1951  //write access
1952  outstr( "\r\n" \
1953  "writable?\t" \
1954  );
1955  for(int n = 0b10000000; n; n >>= 1)
1956  outstr((bitmask & n) != 0 ? "w\t" : "-\t");
1957 
1958  //static bits
1959  outstr( "\r\n" \
1960  "volatile?\t" \
1961  );
1962  for(int n = 0b10000000; n; n >>= 1)
1963  outstr((is_static & n) != 0 ? "-\t" : "v\t");
1964  outstr("\r\n\n");
1965 
1966  return status;
1967 }
1968 
1969 
1970 
1971 inline unsigned char inb (
1972  void
1973  )
1974 {
1975  return inbits(1 << 7);
1976 }
1977 
1978 
1979 
1980 unsigned int inbits (
1981  unsigned int msbit
1982  )
1983 {
1984  unsigned int in = 0;
1985  while(msbit) {
1986  CLOCK_LOW; tCLQV;
1987  if(INA & BIT_MISO)
1988  in |= msbit;
1989  CLOCK_HIGH;
1990  msbit >>= 1;
1991  }
1992  return in;
1993 }
1994 
1995 
1996 
1997 void outbits (
1998  const unsigned int value,
1999  unsigned int msbit
2000  )
2001 {
2002  while(msbit) {
2003  CLOCK_LOW;
2004  if(value & msbit) {
2005  SO_HIGH;
2006  }
2007  else {
2008  SO_LOW;
2009  }
2010  CLOCK_HIGH;
2011  msbit >>= 1;
2012  }
2013 }
2014 
2015 
2016 
2017 void cmd (
2018  const unsigned char cmd,
2019  const unsigned int value,
2020  unsigned char bits
2021  )
2022 {
2023  outbits(cmd, 1 << 7);
2024  outbits(value, 1 << --bits);
2025 }
2026 
2027 
2028 
2030  void
2031  )
2032 {
2033  int id_JEDEC;
2034  CHIP_ON;
2035  outbits(CMD__RDID, 1 << 7);
2036  id_JEDEC = inbits(1 << 23);
2037  if(chip.pspec->cmdset & (1 << X00_NOP)) //for SST25VF016B only?
2038  outbits(CMD__NOP, 1 << 7);
2039  CHIP_OFF;
2040  return id_JEDEC;
2041 }
2042 
2043 
2044 
2045 void cmd_DP (
2046  void
2047  )
2048 {
2049  int dt = (CLKFREQ / 1000000) * 10;
2050 
2051  CHIP_ON;
2052  outbits(CMD__DP, 1 << 7);
2053  CHIP_OFF;
2054  //Macronix Datasheet:
2055  //now wait about 10µs for tDP(2)
2056  waitcnt(CNT + dt);
2057 }
2058 
2059 
2060 
2061 /******************************************************************/
2069 unsigned char cmd_RDSR (
2070  unsigned char regno
2071  )
2072 {
2073  unsigned char buf;
2074 
2075  CHIP_ON;
2076  switch(regno) {
2077  case 2:
2078  outbits(CMD__RDSR3, 1 << 7);
2079  break;
2080 
2081  case 1:
2082  outbits(CMD__RDSR2, 1 << 7);
2083  break;
2084 
2085  case 0:
2086  default:
2087  outbits(CMD__RDSR, 1 << 7);
2088  break;
2089  }
2090  buf = inb();
2091  CHIP_OFF;
2092 
2093  return buf;
2094 }
2095 
2096 
2097 
2098 void cmd_WRDI (
2099  void
2100  )
2101 {
2102  CHIP_ON;
2103  outbits(CMD__WRDI, 1 << 7);
2104  CHIP_OFF;
2105 }
2106 
2107 
2108 
2109 /******************************************************************/
2121 void SPI_ini (
2122  void
2123  )
2124 {
2125  //entry condition: all outputs are tristate.
2126 
2127  //adjust pins
2128  WPn_LOW;
2129  HOLDn_HIGH;
2130  SO_LOW;
2131 
2132  //prepare all clock pin output registers
2133  if(spimode == mode_0)
2134  OUTA &= ~SCLK_AVAIL;
2135  else
2136  OUTA |= SCLK_AVAIL;
2137 
2138  //apply SPI power and let it come up together with PIN_CEn
2139  if(!(DIRA & BIT_PNP_DEVICE)) {
2140  DIRA |= BIT_PNP_DEVICE; //enable pnp device
2141  usleep(POWERUP_SPI * 1000); //used for chips within motherboards
2142  }
2143 
2144  //activate output of selected pins
2145  DIRA |= (SCLK_ACTIVE | BIT_WPn | BIT_HOLDn | BIT_MOSI);
2146 
2147  //give lines some time to settle
2148  //Note this is essential for the GA-G41M-ES2L!
2149  usleep(POWERUP_SPILINES * 1000);
2150 }
2151 
2152 
2153 
2154 /******************************************************************/
2166 void SPI_off (
2167  int mode
2168  )
2169 {
2170  int is_static = chip.pspec->sr_is_static[0] | \
2171  chip.pspec->sr_is_static[1] | \
2172  chip.pspec->sr_is_static[2];
2173 
2174  switch(mode) {
2175  case MODE_FORCE_SPI_OFF:
2176  is_static = 1;
2177 
2178  case MODE_SPI_OFF:
2179  if(is_static && (chip.pspec->cmdset & (1 << XB9_DP)))
2180  cmd_DP(); //enter deep power down as a security feature
2181  DIRA &= ~SPI_BUS; //pins go tristate
2182 
2183  case MODE_SPI_POWEROFF:
2184  /*
2185  * NOTE
2186  * This case must not be used without a preceding MODE_SPI_OFF!
2187  *
2188  */
2189  if(is_static)
2190  DIRA &= ~BIT_PNP_DEVICE; //disable pnp device
2191  break;
2192  }
2193 }
2194 
2195 
2196 
2197 /******************************************************************/
2209 int hex2bin (
2210  unsigned char a,
2211  unsigned char b
2212  )
2213 {
2214  signed char hnib;
2215  signed char lnib;
2216 
2217  hnib = hexdigit2bin(a);
2218  lnib = hexdigit2bin(b);
2219 
2220  if(hnib == -1 || lnib == -1)
2221  return -1; //no true hex
2222  return (hnib << 4) | lnib;
2223 }
2224 
2225 
2226 
2227 
2229  enum tag_cmdstat * cmdstat,
2230  unsigned char odd_tracker
2231  )
2232 {
2233  switch(*cmdstat) {
2234  case cmd_off:
2235  return; //nothing to do
2236 
2237  case cmd_on:
2238  CHIP_OFF; //force pgm-cycle, if any
2239  WIP_polling(); //detect end of write cycle
2240  break;
2241 
2242  case cmd_CP:
2243  if(odd_tracker)
2244  outbits(0xff, 1 << 7); //send dummy byte which does not contain any zero bits
2245  CHIP_OFF; //force pgm-cycle, if any
2246  WIP_polling(); //detect end of write cycle
2247  cmd_WRDI();
2248  CPM_polling();
2249  break;
2250  }
2251  *cmdstat = cmd_off;
2252 }
2253 
2254 
2255 
2256 /******************************************************************/
2266 void ledstat()
2267 {
2268  int statcycle = 0;
2269  int timestamp;
2270  struct {
2271  int phases;
2272  int phase;
2273  int ison;
2274  } led = { 0, 0, 0 };
2275 
2276  while(1) {
2277  //get timestamp
2278  timestamp = CNT;
2279 
2280  //report xcog1.inlevel status
2281  if(!statcycle) {
2282  statcycle = STATUS_CYCLE;
2283  led.ison = 1;
2284  led.phase = LED_PHASE;
2285  led.phases = xcog1.inlevel << 1;
2286  if(led.phases)
2287  led.phases--;
2288  }
2289  else {
2290  statcycle--;
2291  if(led.phases) {
2292  if(!led.phase) {
2293  led.ison ^= 1;
2294  led.phase = LED_PHASE;
2295  led.phases--;
2296  }
2297  else {
2298  led.phase--;
2299  }
2300  }
2301  }
2302 
2303  //control LED_GREEN
2304  if(xcog1.green && led.ison) {
2305  high(LED_GREEN);
2306  }
2307  else {
2308  low(LED_GREEN);
2309  }
2310 
2311  //control LED_ORANGE
2312  if(xcog1.orange)
2313  high(LED_ORANGE);
2314  else
2315  low(LED_ORANGE);
2316 
2317  //keep monitoring adapter plug
2318  if(xcog1.yellow) {
2319  if(input(PIN_PLUGTESTn)) {
2320  //TODO: SPI power should be shutdown here.
2321  high(LED_YELLOW);
2322  }
2323  else
2324  low(LED_YELLOW);
2325  }
2326 
2327  //loop resolution
2328  waitcnt(timestamp + LOOP_RES);
2329  }
2330 }
2331 
2332 
2333 
2334 /******************************************************************/
2349 void burn()
2350 {
2351  int space = 0;
2352  int spacectr = 0;
2353  int queue = 0;
2354  unsigned char odd_tracker = 0;
2355  unsigned int addr = 0;
2356  enum tag_cmdstat cmdstat = cmd_off;
2357  enum {
2358  check_flags,
2359  check_queue,
2360  load_data,
2361  load_lineaddr,
2362  gooff,
2363  spioff
2364  } runctrl = 0;
2365 
2366  SPI_ON; //main cog should have left the SPI chip powered!
2367  WPn_HIGH; //disable hardware write protection
2368  while(1) {
2369  switch(runctrl) {
2370  case check_flags:
2371  if(xcog0.rq_spioff) {
2372  runctrl = gooff; //jump
2373  break;
2374  }
2375  else if(xcog0.rq_lineaddr) {
2376  runctrl = load_lineaddr; //jump
2377  break;
2378  }
2379 
2380  case check_queue:
2381  queue = xcog0.offwr - xcog0.offrd;
2382  if(queue) {
2383  xcog0.queue_empty = 0;
2384  if(cmdstat != cmd_off) {
2385  runctrl = load_data; //jump
2386  break;
2387  }
2388  }
2389  else {
2390  xcog0.queue_empty = 1;
2391  runctrl = check_flags; //jump
2392  break;
2393  }
2394 
2395  //set_space:
2396  space = spacectr = xcog0.psize - (addr & (xcog0.psize - 1));
2397 
2398  //start_cmd:
2399  if(cmdstat == cmd_CP) {
2400  CHIP_ON; //continue
2401  outbits(CMD__CP, 1 << 7);
2402  }
2403  else {
2404  cmd_WREN(); //set Write Enable Latch Bit
2405  CHIP_ON; //start
2406  if(xcog0.cmd == CMD__CP) {
2407  if(addr & 1) {
2408  cmd(xcog0.cmd, addr - 1, xcog0.abits);
2409  outbits(0xff, 1 << 7); //dummy byte without zero bits
2410  odd_tracker ^= 1;
2411  }
2412  else
2413  cmd(xcog0.cmd, addr, xcog0.abits);
2414  cmdstat = cmd_CP;
2415  }
2416  else {
2417  cmd(xcog0.cmd, addr, xcog0.abits);
2418  cmdstat = cmd_on;
2419  }
2420  }
2421 
2422  case load_data:
2423  while(spacectr && queue) {
2424  outbits(*(xcog0.pbuf + (xcog0.offrd++ & (xcog0.bufsize - 1))), 1 << 7);
2425  queue--;
2426  spacectr--;
2427  odd_tracker ^= 1;
2428  }
2429 
2430  //check_spacectr:
2431  if(!spacectr) {
2432  PGM_cycle(&cmdstat, odd_tracker);
2433  addr += space;
2434  }
2435  runctrl = check_flags; //jump
2436  break;
2437 
2438  case load_lineaddr:
2439  if(addr != xcog0.lineaddr) {
2440  PGM_cycle(&cmdstat, odd_tracker); //in case cmdstat != cmd_off
2441  addr = xcog0.lineaddr; //update addr
2442  odd_tracker = 0; //initialize odd_tracker
2443  }
2444  xcog0.rq_lineaddr = 0;
2445  runctrl = check_queue; //jump
2446  break;
2447 
2448  case gooff:
2449  PGM_cycle(&cmdstat, odd_tracker); //in case cmdstat != cmd_off
2450  WPn_LOW; //enable hardware write protection
2452  xcog0.rq_spioff = 0;
2453  runctrl = spioff; //final step, hang up
2454 
2455  case spioff:
2456  break;
2457  }
2458  }
2459 }
2460 
2461 
2462 
2463 /******************************************************************/
2482  union tag_typeS * typeS
2483  )
2484 {
2485  if(!typeS->bf.addrlen) { //calculate bf members based on member num
2486  char num = typeS->bf.num;
2487 
2488  typeS->mem = 0;
2489 
2490  if(num < 1) {
2491  typeS->bf.addrlen = 2;
2492  typeS->bf.start = 1;
2493  }
2494  else if(num < 4) {
2495  typeS->bf.addrlen = num + 1;
2496  typeS->bf.data = 1;
2497  }
2498  else if(num < 5) {
2499  typeS->bf.none = 1;
2500  }
2501  else if(num < 7) {
2502  typeS->bf.addrlen = num - 3;
2503  typeS->bf.linecount = 1;
2504  }
2505  else if(num < 10) {
2506  typeS->bf.addrlen = 11 - num;
2507  typeS->bf.startexec = 1;
2508  }
2509  else {
2510  typeS->bf.none = 1;
2511  }
2512  typeS->bf.num = num;
2513  }
2514  else { //calculate member num based on bf members
2515  if(typeS->bf.start)
2516  typeS->bf.num = 0;
2517  else if(typeS->bf.data)
2518  typeS->bf.num = typeS->bf.addrlen - 1;
2519  else if(typeS->bf.linecount)
2520  typeS->bf.num = typeS->bf.addrlen == 2 ? 5 : 6;
2521  else if(typeS->bf.startexec)
2522  typeS->bf.num = 11 - typeS->bf.addrlen;
2523  else {
2524  typeS->bf.num = 4; //not a valid type
2525  typeS->bf.none = 1;
2526  }
2527  }
2528 }
2529 
2530 
2531 
2532 /******************************************************************/
2544  struct tag_xcog0 * px,
2545  unsigned int * lines
2546  )
2547 {
2548  unsigned int pwr;
2549  char errcode;
2550  enum {
2551  rx_lineaddr,
2552  rx_firstspace,
2553  rx_data,
2554  rx_le,
2555  rx_done
2556  } rx = rx_lineaddr;
2557  unsigned char x, n;
2558  unsigned char cmax;
2559  unsigned char c[9]; //enough space to fetch address bytes in one go
2560  int16_t vbin;
2561  unsigned int lineaddr;
2562 
2563  errcode = ERRC__SUCCESS;
2564  pwr = px->offwr; //setup a local copy of global pointer
2565  lineaddr = 0;
2566  x = 0;
2567  n = 0;
2568  cmax = 1;
2569  do {
2570  GET_CHAR_GROUP(cmax);
2571  switch(rx) {
2572  case rx_lineaddr:
2573  if(c[0] == '#') {
2574  rx = rx_le;
2575  n = 127; //maximum of allowed garbage characters
2576  break;
2577  }
2578  if(x > 8) {
2579  errcode = ERRC__HEXDUMP_PARSING_ERROR;
2580  break;
2581  }
2582  if(c[0] != ':') {
2583  vbin = hexdigit2bin(c[0]);
2584  if(vbin == -1) {
2585  errcode = ERRC__NO_HEX_DIGIT;
2586  break;
2587  }
2588  c[1 + x++] = vbin;
2589  }
2590  else {
2591  unsigned char k = 0; //byte selector
2592  unsigned char t = 0; //nibble selector
2593  rx = rx_firstspace;
2594  while(x--) {
2595  vbin = c[1 + x] << (t << 2);
2596  lineaddr |= vbin << (k << 3);
2597  k += t;
2598  t ^= 1;
2599  }
2600  px->lineaddr = lineaddr;
2601  px->rq_lineaddr = 1;
2602  }
2603  break;
2604 
2605  case rx_firstspace:
2606  if(c[0] != ' ') {
2607  errcode = ERRC__HEXDUMP_PARSING_ERROR;
2608  break;
2609  }
2610  rx = rx_data;
2611  cmax = 3;
2612  break;
2613 
2614  case rx_data:
2615  if(n > xcog0.bufsize) {
2616  errcode = ERRC__LINE_TOO_LONG; //?!
2617  break;
2618  }
2619  if(c[0] == ' ' && (c[1] == '#' || c[1] == ' ')) {
2620  n -= 2; //maximum of allowed garbage characters
2621  cmax = 1;
2622  rx = rx_le;
2623  break;
2624  }
2625  vbin = hex2bin(c[0], c[1]);
2626  if(vbin == -1) {
2627  errcode = ERRC__NO_HEX_DIGIT;
2628  break;
2629  }
2630  if((errcode = queue(px, vbin, &pwr)))
2631  break;
2632  if(c[2] == CLIM_HEXDUMP) {
2633  rx = rx_done;
2634  cmax = 0; //don't read more chars!
2635  break;
2636  }
2637  if(c[2] != ' ') {
2638  errcode = ERRC__HEXDUMP_PARSING_ERROR;
2639  break;
2640  }
2641  break;
2642 
2643  case rx_le:
2644  n--;
2645  if(n < 0) {
2646  errcode = ERRC__LINE_TOO_LONG;
2647  break;
2648  }
2649  if(c[0] == CLIM_HEXDUMP) {
2650  *lines += 1;
2651  }
2652  else
2653  break;
2654 
2655  case rx_done:
2656  px->offwr = pwr;
2657  return(errcode);
2658  }
2659  } while(!errcode);
2660  return(errcode);
2661 }
2662 
2663 
2664 
2665 /******************************************************************/
2679  struct tag_xcog0 * px,
2680  unsigned int * lines,
2681  int hexmode
2682  )
2683 {
2684  char errcode;
2685  enum {
2686  rx_S,
2687  rx_type,
2688  rx_len,
2689  rx_lineaddr,
2690  rx_data,
2691  rx_chksum
2692  } rx = rx_S;
2693  unsigned int pwr;
2694  union tag_typeS typeS;
2695  unsigned int lineaddr;
2696  unsigned char x = 0; //counts address bytes
2697  unsigned char n = 0; //counts data bytes
2698  unsigned char sum = 0;
2699  int16_t vbin;
2700  unsigned char cmax; //0: no char; 1: one char; 2: two chars etc.
2701  unsigned char c[2] = { 0, 0 }; //enough space to fetch a byte in one go
2702 
2703  errcode = ERRC__SUCCESS;
2704  pwr = px->offwr; //setup a local copy of global pointer
2705  typeS.mem = 0;
2706  lineaddr = 0;
2707  cmax = 1;
2708  do {
2709  GET_CHAR_GROUP(cmax);
2710  switch(rx) {
2711  case rx_S:
2712  if(c[0] != 'S') {
2713  errcode = ERRC__NO_MOT;
2714  break;
2715  }
2716  rx = rx_type;
2717  break;
2718 
2719  case rx_type:
2720  vbin = hexdigit2bin(c[0]);
2721  if(vbin == -1) {
2722  errcode = ERRC__NO_HEX_DIGIT;
2723  break;
2724  }
2725  typeS.bf.num = vbin;
2726  MOT_typeS_fillup(&typeS);
2727  if(typeS.bf.none) {
2728  errcode = ERRC__NO_MOT;
2729  break;
2730  }
2731  x = typeS.bf.addrlen;
2732  rx = rx_len;
2733  cmax = 2;
2734  break;
2735 
2736  case rx_len:
2737  vbin = hex2bin(c[0], c[1]);
2738  if(vbin == -1) {
2739  errcode = ERRC__NO_HEX_DIGIT;
2740  break;
2741  }
2742  sum = vbin;
2743  n = vbin - x - 1;
2744  if(typeS.bf.data) {
2745 #ifndef ERROR_MSG__LINE_TOO_LONG
2746  //reallocate buffer (this seems to work fine)
2747  if(n > px->bufsize) {
2748  free(px->pbuf);
2749  px->pbuf = malloc(n);
2750  px->bufsize = n;
2751  }
2752 #else
2753  //safe workaround:
2754  if(n > px->bufsize) {
2755  errcode = ERRC__LINE_TOO_LONG;
2756  break;
2757  }
2758 #endif
2759  }
2760  rx = rx_lineaddr;
2761  break;
2762 
2763  case rx_lineaddr:
2764  if(x) {
2765  x--;
2766  vbin = hex2bin(c[0], c[1]);
2767  if(vbin == -1) {
2768  errcode = ERRC__NO_HEX_DIGIT;
2769  break;
2770  }
2771  sum += vbin;
2772  lineaddr |= vbin << (x << 3);
2773  }
2774  if(!x) {
2775  if(typeS.bf.linecount || typeS.bf.startexec)
2776  rx = rx_chksum;
2777  else {
2778  rx = rx_data;
2779  px->lineaddr = lineaddr;
2780  px->rq_lineaddr = 1;
2781  cmax = hexmode ? 2 : 1;
2782  }
2783  }
2784  break;
2785 
2786  case rx_data:
2787  if(n) {
2788  n--;
2789  vbin = hexmode ? hex2bin(c[0], c[1]) : c[0];
2790  if(vbin == -1) {
2791  errcode = ERRC__NO_HEX_DIGIT;
2792  break;
2793  }
2794  sum += vbin;
2795  if(typeS.bf.data) {
2796  if((errcode = queue(px, vbin, &pwr)))
2797  break;
2798  }
2799  }
2800  if(!n) {
2801  rx = rx_chksum;
2802  cmax = 2;
2803  }
2804  break;
2805 
2806  case rx_chksum:
2807  vbin = hex2bin(c[0], c[1]);
2808  if(vbin == -1) {
2809  errcode = ERRC__NO_HEX_DIGIT;
2810  break;
2811  }
2812  if(vbin != (~sum & 0xff)) {
2813  errcode = ERRC__CHECKSUM_MISMATCH;
2814  break;
2815  }
2816  if(typeS.bf.linecount && *lines != lineaddr) {
2817  errcode = ERRC__LINE_COUNT_MISMATCH;
2818  break;
2819  }
2820  if(typeS.bf.data)
2821  *lines += 1;
2822  px->offwr = pwr;
2823  return(errcode);
2824  }
2825  } while(!errcode);
2826  return(errcode);
2827 }
2828 
2829 
2830 
2831 char queue (
2832  struct tag_xcog0 * px,
2833  unsigned char vbin,
2834  unsigned int * pwr
2835  )
2836 {
2837  if((*pwr - px->offrd) >= px->bufsize)
2838  return ERRC__BUFFER_OVERRUN;
2839  else {
2840  *(px->pbuf + (*pwr & (px->bufsize - 1))) = vbin; //access volatile globals
2841  (*pwr)++;
2842  return ERRC__SUCCESS;
2843  }
2844 }
2845 
2846 
2847 
2849  char reported_err
2850  )
2851 {
2852  if(reported_err != 0) {
2853  outstr("Error Code: ");
2854  outfifo(reported_err + 48);
2855  outstr("\r\n");
2856  }
2857 }
2858 
2859 
2860 
2862  struct tag_xcog0 * px,
2863  char screen_output
2864  )
2865 {
2866  enum tag_rxstep {
2867  rx_stx_or_eot,
2868  rx_error,
2869  send_nak,
2870  rx_done
2871  } rx = rx_stx_or_eot;
2872  char errcode = ERRC__SUCCESS;
2873  unsigned int lines = 0;
2874  char a = 0;
2875 
2876  //cog setup
2878  px->pbuf = malloc(px->bufsize);
2879  if(chip.pspec->cmdset & (1 << X02_PP)) {
2880  px->cmd = CMD__PP;
2881  px->psize = chip.pspec->pagesize;
2882  }
2883  else if(chip.pspec->cmdset & (1 << XAD_CP)) {
2884  px->cmd = CMD__CP;
2885  px->psize = 2;
2886  }
2887  else if(chip.pspec->cmdset & (1 << X02_BP)) {
2888  px->cmd = CMD__BP;
2889  px->psize = 1;
2890  }
2891  px->offrd = 0;
2892  px->offwr = 0;
2893  px->lineaddr = 0;
2894  px->rq_spioff = 0;
2895  px->queue_empty = 1;
2896  px->abits = chip.addrlen_in_bits;
2897  px->pcog = cog_run(&burn, STACK_BURNBUF);
2898 
2899  //send header
2900  outfifo(SOH);
2901  if(screen_output)
2903  else
2905  outfifo(pfspec->format);
2906 
2907  while(1) {
2908  switch(rx) {
2909  case rx_stx_or_eot:
2910  do
2911  a = getChar();
2912  while(a != EOT && a != STX);
2913  if(a == EOT) {
2914  rx = rx_done;
2915  break;
2916  }
2917  outfifo(a); //feedback
2918  switch(pfspec->format) {
2919  case MOTBIN:
2920  errcode = MOT_rxline(px, &lines, BINMODE);
2921  break;
2922 
2923  case HEXDUMP:
2924  errcode = HEXDUMP_rxline(px, &lines);
2925  break;
2926  }
2927  if(errcode) {
2928  rx = rx_error;
2929  break;
2930  }
2931 
2932  //rx_etx_or_can:
2933  a = getChar(); //fetch ETX
2934  if(a == CAN) {
2935  errcode = ERRC__JOB_CANCELLATION;
2936  rx = send_nak;
2937  break;
2938  }
2939  /*
2940  * NOTE connect is NOT sending any line ending characters except:
2941  * - ETX for MOT format
2942  * - CLIM_HEXDUMP + ETX for HEXDUMP format, but the
2943  * received CLIM_HEXDUMP has already been processed by HEXDUMP_rxline().
2944  *
2945  */
2946 
2947  //send_LE:
2948  /*
2949  * NOTE: HEXDUMP_rxline uses CLIM_HEXDUMP for detection of line ending,
2950  * and this character, i.e. a Carriage Return, has already been sent
2951  * as feedback.
2952  *
2953  */
2954  PUTCHAR_CR;
2955  PUTCHAR_NL;
2956 
2957  //wait_burn:
2958  while(!px->queue_empty);
2959 
2960  //send_ack:
2961  outfifo(ACK);
2962  rx = rx_stx_or_eot;
2963  break;
2964 
2965  case rx_error:
2966  if(errcode != ERRC__JOB_CANCELLATION)
2967  do
2968  a = outfifo(getChar()); //feedback
2969  while(a != ETX && a != CAN); //CAN?! Yes, user may hit 'q' after error occured and transmission will then end with CAN
2970 
2971  case send_nak:
2972  outfifo(NAK);
2973  outfifo(errcode); //send error code
2974  rx = rx_stx_or_eot;
2975  break;
2976 
2977  case rx_done:
2978  px->rq_spioff = 1;
2979  while(px->rq_spioff);
2980  cog_end(px->pcog);
2981  free(px->pbuf);
2983  report_err(errcode);
2984  return;
2985  }
2986  }
2987 }
2988 
2989 
2990 
2991 
2992 /******************************************************************/
3001  void
3002  )
3003 {
3004  char s[SIZE_STR_MESSAGE];
3005 
3006  WPn_HIGH;
3007  cmd_WREN(); //send WREN instruction
3008  CHIP_ON;
3009  outbits(cmd_CE, 1 << 7);
3010  CHIP_OFF;
3011  WPn_LOW;
3012  sprinti(s, "WIP_polling: %d\r\n", WIP_polling());
3013  outstr(s);
3014 }
3015 
filespec.c
EXIT_CHAR_A
#define EXIT_CHAR_A
First char of Parallax' exit sequence.
Definition: serial-codes.h:71
connected
void connected(void)
Definition: kick.c:182
CMD__CE_0XC7
#define CMD__CE_0XC7
Full Chip Erase (0xc7)
Definition: SPI-command-set.h:64
X20_SE
#define X20_SE
Definition: chipspec.h:121
menu
void menu(unsigned char mode)
Put the chipflasher menu on screen and invoke key_polling().
Definition: kick.c:866
CAN
#define CAN
Ascii 'cancel'.
Definition: serial-codes.h:58
MSG_DONE
#define MSG_DONE
Definition: kick.h:107
greeting
void greeting()
Put a small headline on terminal screen that helps to identify the program.
Definition: kick.c:1711
main
int main(void)
This is main() of kick, the firmware.
Definition: kick.c:116
SPI-flash-bits.h
Common Bit Names of important SPI Flash Registers.
LED_PHASE
#define LED_PHASE
Definition: kick.h:92
CMD__RDSR2
#define CMD__RDSR2
Read Status Register 2.
Definition: SPI-command-set.h:54
X39_US
#define X39_US
Definition: chipspec.h:148
FILE_TO_CHIP
#define FILE_TO_CHIP
Send data to propeller and write to chip.
Definition: serial-codes.h:76
tag_filespec::payload_default
unsigned char payload_default
Pure data bytes per line.
Definition: filespec.h:58
MOT_rxline
char MOT_rxline(struct tag_xcog0 *px, unsigned int *lines, int hexmode)
Receive and parse a line in Motorola S-Record format. This func finishes successfully after having pa...
Definition: kick.c:2678
CMD__RDID
#define CMD__RDID
Read JEDEC Device ID.
Definition: SPI-command-set.h:57
cmd_off
@ cmd_off
Definition: kick.h:115
KEYID_S
#define KEYID_S
Definition: key-enable-bits.h:42
SIZE_STRBUF
#define SIZE_STRBUF
Definition: kick.h:67
SPI_BUS
#define SPI_BUS
Definition: proppins.h:91
SIZE_LINEBUF
#define SIZE_LINEBUF
Definition: kick.h:68
mirror
void mirror(char *keymsg)
Definition: kick.c:193
POWERUP_SPI
#define POWERUP_SPI
Give the attached system board some time to power up. Time in milliseconds.
Definition: kick.h:71
MODE_0XFF
#define MODE_0XFF
KEYID_B
#define KEYID_B
Definition: key-enable-bits.h:47
CMD__SE
#define CMD__SE
Sector Erase (4K)
Definition: SPI-command-set.h:60
CMD__RDSR3
#define CMD__RDSR3
Read Status Register 3.
Definition: SPI-command-set.h:55
cmd_WREN
void cmd_WREN(void)
Set Write Enable Latch bit.
Definition: kick.c:1727
tag_linedat::startaddr
unsigned int startaddr
Line’s startaddress.
Definition: kick.h:171
chipspec.h
putChar
void putChar(char c)
Definition: putChar.c:46
CMD__READ
#define CMD__READ
Read (at up to 25MHz)
Definition: SPI-command-set.h:58
KEYBIT_X
#define KEYBIT_X
Definition: key-enable-bits.h:86
KEYBIT_q
#define KEYBIT_q
Definition: key-enable-bits.h:63
CMD__RDSR
#define CMD__RDSR
Read Status Register 1.
Definition: SPI-command-set.h:53
MODE_CONNECT
#define MODE_CONNECT
Definition: kick.h:82
key-enable-bits.h
Entities that help to configure allowed key input. With these keys associated are predefined strings ...
KEYID_C
#define KEYID_C
Definition: key-enable-bits.h:49
MODE_SPLIT
#define MODE_SPLIT
Definition: filespec.h:43
yes_no
unsigned char yes_no(char *question, unsigned char level_rst)
This function allows to put a question which expects true or false.
Definition: kick.c:1303
CMD__CP
#define CMD__CP
Continuous Program.
Definition: SPI-command-set.h:67
GET_CHAR_GROUP
#define GET_CHAR_GROUP(n)
Definition: kick.h:103
global_sector_protect
void global_sector_protect(unsigned char pswitch)
Method to globally protect/unprotect all sectors.
Definition: kick.c:387
tag_xcog0::queue_empty
volatile unsigned char queue_empty
Flag to indicate that the data queue is empty.
Definition: kick.h:213
HAS_NOT_BEEN_CUT_YET
#define HAS_NOT_BEEN_CUT_YET
IS_0XFF
#define IS_0XFF
KEYBIT_c
#define KEYBIT_c
Definition: key-enable-bits.h:75
X60_CE
#define X60_CE
Definition: chipspec.h:124
X35_RDSR2
#define X35_RDSR2
Definition: chipspec.h:151
CMD__WRSR
#define CMD__WRSR
Write Status Register 1.
Definition: SPI-command-set.h:49
cmd
void cmd(const unsigned char cmd, const unsigned int value, unsigned char bits)
Definition: kick.c:2017
tag_chip
Struct that characterizes a chip.
Definition: kick.h:227
STACK_LEDSTAT
#define STACK_LEDSTAT
Stack size for ledstat().
Definition: kick.h:77
KEYBIT_S
#define KEYBIT_S
Definition: key-enable-bits.h:69
ERRC__NO_HEX_DIGIT
#define ERRC__NO_HEX_DIGIT
Definition: serial-codes.h:95
mode_0
@ mode_0
Definition: kick.h:121
cmd_RDID_JEDEC
int cmd_RDID_JEDEC(void)
Definition: kick.c:2029
SCLK_AVAIL
#define SCLK_AVAIL
Definition: proppins.h:90
CMD__PS
#define CMD__PS
Protect Sector.
Definition: SPI-command-set.h:74
SR_intro
void SR_intro(unsigned char regno)
Provide each bit listing of an status register with a short header.
Definition: kick.c:369
tag_xcog0::abits
unsigned char abits
addrbits.
Definition: kick.h:206
tag_xcog1::yellow
volatile unsigned char yellow
Switch for yellow LED usage.
Definition: kick.h:184
DATA_START
#define DATA_START
KEYID_K
#define KEYID_K
Definition: key-enable-bits.h:44
_cfg_modeterminal
int _cfg_modeterminal
configured through propeller-load
Definition: kick.c:73
ACK
#define ACK
Ascii 'acknoledge'.
Definition: serial-codes.h:52
MODE_SCREEN_OUTPUT
#define MODE_SCREEN_OUTPUT
Definition: filespec.h:45
menu_options
void menu_options(void)
Put menu options on terminal screen.
Definition: kick.c:1071
KEYBIT_p
#define KEYBIT_p
Definition: key-enable-bits.h:66
outstr
int outstr(char *s)
Definition: kick.c:1629
cmd_CP
@ cmd_CP
Definition: kick.h:117
X50_EWSR
#define X50_EWSR
Definition: chipspec.h:132
CHIP_TO_FILE_NOSCREEN
#define CHIP_TO_FILE_NOSCREEN
Send data to terminal and save on disk, without feedback on screen.
Definition: serial-codes.h:75
keymsg
char * keymsg[]
Definition: key-enable-bits.h:99
hr
void hr(char c, int n, char nl)
Put a horizontal line on screen.
Definition: kick.c:919
tag_linedat::rd
unsigned int rd
Read pointer.
Definition: kick.h:169
NEW_LINE
#define NEW_LINE
Ascii LF "\n" 'line feed'.
Definition: serial-codes.h:53
spimode
enum tag_spimode spimode
SPI mode to be used through the whole program.
Definition: kick.c:81
STATUS_CYCLE
#define STATUS_CYCLE
Definition: kick.h:91
tag_xcog0::psize
int psize
Page size.
Definition: kick.h:208
tag_xcog1::green
volatile unsigned char green
Switch for green LED usage.
Definition: kick.h:183
X9F_RDID
#define X9F_RDID
Definition: chipspec.h:140
ARRAY_CHIPSPEC
#define ARRAY_CHIPSPEC
Number of entries in chipspec database.
Definition: chipspec.h:69
ID_NONE
#define ID_NONE
Definition: key-enable-bits.h:60
ERRC__JOB_CANCELLATION
#define ERRC__JOB_CANCELLATION
Definition: serial-codes.h:93
tag_chipspec::name
char name[15]
chip's name, i.e. MX25L1605D
Definition: chipspec.h:167
KEYBIT_r
#define KEYBIT_r
Definition: key-enable-bits.h:81
ERRC__LINE_TOO_LONG
#define ERRC__LINE_TOO_LONG
Definition: serial-codes.h:98
KEYBIT_K
#define KEYBIT_K
Definition: key-enable-bits.h:71
tag_blocksize
tag_blocksize
Definition: kick.h:131
HOLDn_HIGH
#define HOLDn_HIGH
Definition: fast-SPI.h:118
KEYBIT_C
#define KEYBIT_C
Definition: key-enable-bits.h:76
inb
unsigned char inb(void)
Definition: kick.c:1971
CLIM_NL
#define CLIM_NL
Definition: serial-codes.h:68
MODE_SPI_POWEROFF
#define MODE_SPI_POWEROFF
Definition: kick.h:87
PIN_RX
#define PIN_RX
Definition: proppins.h:69
tag_type_of_addrlen
tag_type_of_addrlen
Definition: kick.h:125
LOOP_RES
#define LOOP_RES
Definition: kick.h:90
HEXDUMP
@ HEXDUMP
Definition: filespec.h:54
APPLY_CUT
#define APPLY_CUT
MOT_summary
void MOT_summary(unsigned int lines, char *linebuf)
Definition: kick.c:1280
get_addrlen
unsigned char get_addrlen(enum tag_type_of_addrlen type_of_addrlen, unsigned int addr)
Auxiliary function that returns the length of an address for different situations.
Definition: kick.c:939
SPI_OFF
#define SPI_OFF(mode)
Definition: kick.h:110
tag_linedat
Struct that characterizes a data line.
Definition: kick.h:166
KEYREG_DEFAULT
#define KEYREG_DEFAULT
Definition: key-enable-bits.h:89
KEYBIT_k
#define KEYBIT_k
Definition: key-enable-bits.h:70
HEADER_KICK
#define HEADER_KICK
Definition: kick.h:65
chipspec
struct tag_chipspec chipspec[ARRAY_CHIPSPEC]
Database of supported chips. These chips are usually found on motherboards, which are compatible with...
Definition: chipspec.c:33
EXIT_CHAR_B
#define EXIT_CHAR_B
Second char of Parallax' exit sequence.
Definition: serial-codes.h:72
INLINE_0XFF
#define INLINE_0XFF
BLOCK_32K
@ BLOCK_32K
Definition: kick.h:133
BIT_WPn
#define BIT_WPn
Definition: proppins.h:80
tag_xcog0::cmd
unsigned char cmd
Command to be used for writing.
Definition: kick.h:205
outfifo
char outfifo(char c)
Definition: kick.c:1615
tag_typeS::bf
struct tag_typeS::@0 bf
X05_RDSR
#define X05_RDSR
Definition: chipspec.h:134
strpos
int strpos(char *str, char c)
Report the position of a character in a string.
Definition: kick.c:1214
kick.h
KEYBIT_B
#define KEYBIT_B
Definition: key-enable-bits.h:74
LED_YELLOW
#define LED_YELLOW
Attached board or chip is powered.
Definition: proppins.h:65
SIZE_HEADER
#define SIZE_HEADER
Definition: filespec.h:33
check_dryrun
void check_dryrun(void)
Checks wether a write fail should be expected. A function with very basic and poor functionality.
Definition: kick.c:820
MENUWIDTH
#define MENUWIDTH
width of menu headlines (in chars)
Definition: common.h:42
ERRC__HEXDUMP_PARSING_ERROR
#define ERRC__HEXDUMP_PARSING_ERROR
Definition: serial-codes.h:100
hex2bin
int hex2bin(unsigned char a, unsigned char b)
Converts a pair of hexadecimal chars into binary value.
Definition: kick.c:2209
xcog1
struct tag_xcog1 xcog1
Cog parameters for ledstat().
Definition: kick.c:80
XC7_CE
#define XC7_CE
Definition: chipspec.h:125
PIN_PLUGTESTn
#define PIN_PLUGTESTn
This pin is used detect an adapter plug.
Definition: proppins.h:62
keyreg
unsigned int keyreg
Definition: key-enable-bits.h:91
tag_chipspec::chipsize
const unsigned int chipsize
Size of the chip.
Definition: chipspec.h:169
SO_LOW
#define SO_LOW
Definition: fast-SPI.h:99
hexdigit2bin
signed char hexdigit2bin(unsigned char hexdigit)
Convert a hexadecimal digit into a binary value.
Definition: hexdigit2bin.c:39
LED_ORANGE
#define LED_ORANGE
SPI pins are actively driven, do not remove board's power.
Definition: proppins.h:66
SO_HIGH
#define SO_HIGH
Definition: fast-SPI.h:93
CMD__WRSR2
#define CMD__WRSR2
Write Status Register 2.
Definition: SPI-command-set.h:50
CMD__CE_0X60
#define CMD__CE_0X60
Full Chip Erase (0x60)
Definition: SPI-command-set.h:63
tag_xcog0::rq_spioff
volatile unsigned char rq_spioff
Flag to request SPI off.
Definition: kick.h:214
KEYBIT_I
#define KEYBIT_I
Definition: key-enable-bits.h:78
CMD__BE64K
#define CMD__BE64K
Block Erase (64K)
Definition: SPI-command-set.h:62
FF_START
#define FF_START
tag_typeS::start
unsigned int start
Definition: kick.h:150
tag_typeS::num
unsigned int num
Definition: kick.h:155
CLIM_HEXDUMP
#define CLIM_HEXDUMP
Definition: serial-codes.h:69
tag_typeS
Motorola S-Record Type Infos.
Definition: kick.h:146
KEYID_d
#define KEYID_d
Definition: key-enable-bits.h:37
MOT_typeS_fillup
void MOT_typeS_fillup(union tag_typeS *typeS)
Generating and parsing a Motorola S-record line needs to have some specs available about the line in ...
Definition: kick.c:2481
menu_line
void menu_line(unsigned int k1, char *k1msg, unsigned int k2, char *k2msg, unsigned int k3, char *k3msg)
Put a menu line with selected menu options on terminal screen.
Definition: kick.c:1040
cmd_CE
unsigned char cmd_CE
Global chip erase command, may be overridden by key_config().
Definition: kick.c:78
CMD__EWSR
#define CMD__EWSR
Enable Write Status Register.
Definition: SPI-command-set.h:48
KEYID_X
#define KEYID_X
Definition: key-enable-bits.h:58
chipspec.c
PUTCHAR_CR
#define PUTCHAR_CR
Definition: kick.h:95
ERRC__LINE_COUNT_MISMATCH
#define ERRC__LINE_COUNT_MISMATCH
Definition: serial-codes.h:97
OFF
#define OFF
Definition: common.h:41
_cfg_rstdisable
int _cfg_rstdisable
configured through propeller-load
Definition: kick.c:74
bin2hexdigit.c
putChar.c
Function to print a char to the default terminal. This modified version does not prepend "\r" if "\n"...
tag_xcog0::lineaddr
unsigned int lineaddr
startaddress of data line.
Definition: kick.h:207
ledstat
void ledstat()
This function controls board LEDs. To be used with extra cog, to be stopped externally.
Definition: kick.c:2266
WPn_HIGH
#define WPn_HIGH
Definition: fast-SPI.h:69
X52_BE32K
#define X52_BE32K
Definition: chipspec.h:122
WIP
#define WIP
Write In Progress.
Definition: SPI-flash-bits.h:41
MOT_header
void MOT_header(char *header, char *linebuf)
This function invokes MOT_mkline(), but initializes parameters first with apropriate header data.
Definition: kick.c:1237
tag_spimode
tag_spimode
Definition: kick.h:120
X03_READ
#define X03_READ
Definition: chipspec.h:118
HEXDUMP_rxline
char HEXDUMP_rxline(struct tag_xcog0 *px, unsigned int *lines)
Parse a Hexdump line.
Definition: kick.c:2543
tag_xcog1::orange
volatile unsigned char orange
Switch for orange LED usage.
Definition: kick.h:185
fast-SPI.h
Inline Code Macros with Assembler, that provide fast SPI Bus access.
chip_rxfile
void chip_rxfile(struct tag_xcog0 *px, char screen_output)
Definition: kick.c:2861
cmd_WRSR
void cmd_WRSR(const unsigned char regno, const unsigned char byte)
Write to Status Registers.
Definition: kick.c:1743
cmd_RDSR
unsigned char cmd_RDSR(unsigned char regno)
Read the status register.
Definition: kick.c:2069
KEYID_r
#define KEYID_r
Definition: key-enable-bits.h:54
CMD__BE32K
#define CMD__BE32K
Block Erase (32K)
Definition: SPI-command-set.h:61
KEYBIT_t
#define KEYBIT_t
Definition: key-enable-bits.h:65
KEYBIT_s
#define KEYBIT_s
Definition: key-enable-bits.h:68
PIN_TX
#define PIN_TX
Definition: proppins.h:70
XAD_CP
#define XAD_CP
Definition: chipspec.h:127
X15_RDSR3
#define X15_RDSR3
Definition: chipspec.h:152
ADDRLEN_MOT
@ ADDRLEN_MOT
Definition: kick.h:127
tag_xcog0::offrd
volatile unsigned int offrd
Buffer read pointer offset.
Definition: kick.h:211
CMD__NOP
#define CMD__NOP
No Operation.
Definition: SPI-command-set.h:47
CHIPSPEC_DEFAULT
#define CHIPSPEC_DEFAULT
Definition: chipspec.h:70
CMD__WREN
#define CMD__WREN
Write Enable.
Definition: SPI-command-set.h:56
BLOCK_64K
@ BLOCK_64K
Definition: kick.h:134
MOT_mkline
void MOT_mkline(struct tag_linedat *linedat, union tag_typeS *typeS, char *linebuf)
This function wraps a binary payload into a Motorola S-record frame.
Definition: kick.c:1162
STX
#define STX
Ascii 'start of text'.
Definition: serial-codes.h:48
tag_xcog0::rq_lineaddr
volatile unsigned char rq_lineaddr
Flag to request the next line address.
Definition: kick.h:215
X02_BP
#define X02_BP
Definition: chipspec.h:128
SIZE_256
#define SIZE_256
Usual page size.
Definition: chipspec.h:86
tag_xcog0::pbuf
unsigned char * pbuf
Pointer to ringbuffer.
Definition: kick.h:209
tag_filespec::format
enum tag_format format
Definition: filespec.h:59
tag_typeS::none
unsigned int none
Definition: kick.h:149
BIT_MISO
#define BIT_MISO
Definition: proppins.h:81
SIZE_64K
#define SIZE_64K
Size of 64K-block.
Definition: chipspec.h:91
tag_linedat::wr
unsigned int wr
Write pointer.
Definition: kick.h:170
chip_ini
void chip_ini(unsigned char new_index)
Definition: kick.c:1331
option_readblock
void option_readblock(const enum tag_blocksize blocksize)
Definition: kick.c:204
SCANNING_FF
#define SCANNING_FF
CMD__WRSR3
#define CMD__WRSR3
Write Status Register 3.
Definition: SPI-command-set.h:51
SIZE_STR_MESSAGE
#define SIZE_STR_MESSAGE
Definition: kick.h:66
tag_chipspec::pagesize
const int pagesize
If not applicable or unknown, clear cmdset.X02_PP.
Definition: chipspec.h:170
tCLQV
#define tCLQV
CE# Low to Output valid.
Definition: fast-SPI.h:47
proppins.h
Propeller Pin Usage and predefined Bit Values.
tag_typeS::addrlen
unsigned int addrlen
Definition: kick.h:154
cmd_DP
void cmd_DP(void)
Definition: kick.c:2045
pfspec
struct tag_filespec * pfspec
Pointer to specifications that are associated with selected format type.
Definition: kick.c:83
SPI_ON
#define SPI_ON
Definition: kick.h:109
tag_chipspec::sr_is_static
const unsigned char sr_is_static[3]
True, if Status Register is not initialized during Power-Up.
Definition: chipspec.h:173
tag_typeS::startexec
unsigned int startexec
Definition: kick.h:153
KEYID_f
#define KEYID_f
Definition: key-enable-bits.h:52
KEYID_W
#define KEYID_W
Definition: key-enable-bits.h:56
KEYBIT_b
#define KEYBIT_b
Definition: key-enable-bits.h:73
key_polling
void key_polling(unsigned char *key_is_valid, unsigned char *quit)
Essential function. Scans stdin for configured keys and issues the apropriate actions....
Definition: kick.c:420
exit_sequence
void exit_sequence(const char status)
Tell terminal to exit listening mode.
Definition: kick.c:1862
MOTBIN
@ MOTBIN
Definition: filespec.h:53
outbits
void outbits(const unsigned int value, unsigned int msbit)
Definition: kick.c:1997
filespec.h
CLOCK_HIGH
#define CLOCK_HIGH
Definition: fast-SPI.h:81
MODE_TERMINAL
#define MODE_TERMINAL
Definition: kick.h:81
CPM
#define CPM
Continously Program Mode.
Definition: SPI-flash-bits.h:35
X01_WRSR
#define X01_WRSR
Definition: chipspec.h:135
ETX
#define ETX
Ascii 'end of text'.
Definition: serial-codes.h:49
KEYID_q
#define KEYID_q
Definition: key-enable-bits.h:36
X31_WRSR2
#define X31_WRSR2
Definition: chipspec.h:153
range_error
void range_error(void)
Reports an Out-of-Range user input error and resets xcog1.inlevel.
Definition: kick.c:275
KEYBIT_f
#define KEYBIT_f
Definition: key-enable-bits.h:79
filespec
struct tag_filespec filespec[2]
Definition: filespec.c:30
BAUDRATE_DEFAULT
#define BAUDRATE_DEFAULT
propeller-load default baudrate
Definition: kick.h:69
xcog0
struct tag_xcog0 xcog0
Cog parameters for burn().
Definition: kick.c:79
STACK_BURNBUF
#define STACK_BURNBUF
Stack size for burn().
Definition: kick.h:76
tag_typeS::linecount
unsigned int linecount
Definition: kick.h:152
EOT
#define EOT
Ascii 'end of transmission'.
Definition: serial-codes.h:50
KEYID_I
#define KEYID_I
Definition: key-enable-bits.h:51
linebuf_out
signed char linebuf_out(char *linebuf)
Put a formatted data line onto tty.
Definition: kick.c:1592
SCLK_ACTIVE
#define SCLK_ACTIVE
Definition: proppins.h:102
common.h
This file is useful for both, kick and connect.
tag_xcog1
Cog parameters for ledstat().
Definition: kick.h:182
POWERUP_EXTRA
#define POWERUP_EXTRA
If chip detection fails, how often shall we retry?
Definition: kick.h:73
chip_erase
void chip_erase(void)
This function calls the global chip erase command.
Definition: kick.c:3000
tag_chipspec::cmdset
const int cmdset
selected commands
Definition: chipspec.h:172
ERRC__BUFFER_OVERRUN
#define ERRC__BUFFER_OVERRUN
Definition: serial-codes.h:99
SPI_ini
void SPI_ini(void)
Initialize SPI bus; activate hardware write protection.
Definition: kick.c:2121
WPn_LOW
#define WPn_LOW
Definition: fast-SPI.h:75
queue
char queue(struct tag_xcog0 *px, unsigned char vbin, unsigned int *pwr)
Definition: kick.c:2831
chip_txfile
void chip_txfile(struct tag_filespec *filespec, unsigned char addrlen_in_bits, unsigned int firstloc, unsigned int memsize, unsigned char screenmode)
Definition: kick.c:1507
SIZE_128MBIT
#define SIZE_128MBIT
Chipsize 128Mbit.
Definition: chipspec.h:97
KEYID_s
#define KEYID_s
Definition: key-enable-bits.h:41
tag_chip::pages
int pages
Number of pages (on a paged chip).
Definition: kick.h:231
hexdigit2bin.c
CHIP_ON
#define CHIP_ON
Definition: fast-SPI.h:57
ERRC__NO_MOT
#define ERRC__NO_MOT
Definition: serial-codes.h:94
cmd_WRDI
void cmd_WRDI(void)
Definition: kick.c:2098
HEADER
#define HEADER
Definition: filespec.h:31
tag_cmdstat
tag_cmdstat
Definition: kick.h:114
BIT_HOLDn
#define BIT_HOLDn
Definition: proppins.h:84
PAYLOAD_DEFAULT
#define PAYLOAD_DEFAULT
report_err
void report_err(char reported_err)
Definition: kick.c:2848
tag_chip::pspec
struct tag_chipspec * pspec
Pointer into chipspec database.
Definition: kick.h:229
MAX_POLLING
#define MAX_POLLING
Set a timeout value for the WIP polling routine.
Definition: kick.h:78
BLOCK_4K
@ BLOCK_4K
Definition: kick.h:132
mode_3
@ mode_3
Definition: kick.h:122
SIZE_4K
#define SIZE_4K
Size of 4K-sector.
Definition: chipspec.h:88
MODE_SPI_OFF
#define MODE_SPI_OFF
Definition: kick.h:85
tag_chip::addrlen_in_bits
unsigned char addrlen_in_bits
Number of bits that are used feed an address into the SPI-bus.
Definition: kick.h:230
tag_chipspec::id_JEDEC
const int id_JEDEC
If not applicable or unknown, clear cmdset.X9F_RDID.
Definition: chipspec.h:168
KEYID_c
#define KEYID_c
Definition: key-enable-bits.h:48
MOT_data
void MOT_data(struct tag_linedat *linedat, char *linebuf)
Definition: kick.c:1263
option_batchblockerase
void option_batchblockerase(const enum tag_blocksize blocksize, const unsigned char blockcmd)
Versatile block erase function, which allows erasing of multiple blocks of different sizes,...
Definition: kick.c:291
tag_xcog1::inlevel
volatile unsigned char inlevel
Current menu input level.
Definition: kick.h:186
X02_PP
#define X02_PP
Definition: chipspec.h:126
tag_typeS::mem
unsigned int mem
Definition: kick.h:147
ERRC__CHECKSUM_MISMATCH
#define ERRC__CHECKSUM_MISMATCH
Definition: serial-codes.h:102
CMD__PP
#define CMD__PP
Page Program.
Definition: SPI-command-set.h:66
CMD__DP
#define CMD__DP
Deep Powerdown.
Definition: SPI-command-set.h:68
X00_NOP
#define X00_NOP
Definition: chipspec.h:138
tag_xcog0::offwr
volatile unsigned int offwr
Buffer write pointer offset.
Definition: kick.h:212
BINMODE
#define BINMODE
Definition: common.h:47
tag_filespec
Definition: filespec.h:57
ON
#define ON
Definition: common.h:40
putChar.h
SR_report
unsigned char SR_report(unsigned char regno)
Put status register's content on screen.
Definition: kick.c:1929
FILE_TO_CHIP_NOSCREEN
#define FILE_TO_CHIP_NOSCREEN
Send data to propeller and write to chip, without output on screen.
Definition: serial-codes.h:77
RST_DISABLE
#define RST_DISABLE
Definition: proppins.h:68
KEYBIT_m
#define KEYBIT_m
Definition: key-enable-bits.h:84
plug_detect
int plug_detect(void)
Check if an SPI-Plug is detected and put a message on screen.
Definition: kick.c:845
CARR_RET
#define CARR_RET
Ascii CR "\r" 'carriage return'.
Definition: serial-codes.h:54
NAK
#define NAK
Ascii 'neg. acknoledge'.
Definition: serial-codes.h:55
XB9_DP
#define XB9_DP
Definition: chipspec.h:141
do__WIP_polling
int do__WIP_polling(void)
Invoking WIP_polling() usually is accompanied by some checks and messages.
Definition: kick.c:251
SCANNING_DATA
#define SCANNING_DATA
KEYBIT_W
#define KEYBIT_W
Definition: key-enable-bits.h:83
tag_chipspec::sr_wrmask
const unsigned char sr_wrmask[3]
maskout unwritable bits of the status register
Definition: chipspec.h:174
CHIP_OFF
#define CHIP_OFF
Definition: fast-SPI.h:63
ENQ
#define ENQ
Ascii 'enquiry'.
Definition: serial-codes.h:51
BIT_PNP_DEVICE
#define BIT_PNP_DEVICE
Definition: proppins.h:88
PUTCHAR_NL
#define PUTCHAR_NL
Definition: kick.h:99
tag_filespec::mode_0xff
unsigned char mode_0xff
Definition: filespec.h:60
LED_GREEN
#define LED_GREEN
SPI pins are tristate, you can safely attach/detach board.
Definition: proppins.h:67
tag_linedat::mask
unsigned int mask
Mask for read and write pointers.
Definition: kick.h:168
burn
void burn()
Wite data to chip.
Definition: kick.c:2349
CMD__WRDI
#define CMD__WRDI
Write Disable.
Definition: SPI-command-set.h:52
serial-codes.h
tag_filespec::format_name
char * format_name
Definition: filespec.h:61
tag_chip::index
unsigned char index
Definition: kick.h:228
CLOCK_LOW
#define CLOCK_LOW
Definition: fast-SPI.h:87
MODE_STRIP
#define MODE_STRIP
Definition: filespec.h:44
SPI-command-set.h
Known SPI commands, one byte.
verify_0xff
unsigned char verify_0xff(unsigned int firstloc, unsigned int memsize)
This function scans the specified chip memory for values different than 0xff. If a value different to...
Definition: kick.c:1122
NOT_APPLICABLE
#define NOT_APPLICABLE
some chipspec members may not make sense for some chips
Definition: kick.h:70
inbits
unsigned int inbits(unsigned int msbit)
Definition: kick.c:1980
tag_xcog0::bufsize
unsigned char bufsize
Size of ringbuffer.
Definition: kick.h:210
CPM_polling
unsigned int CPM_polling(void)
Poll CPM bit.
Definition: kick.c:1903
CLIM_CR
#define CLIM_CR
Definition: serial-codes.h:67
MODE_FORCE_SPI_OFF
#define MODE_FORCE_SPI_OFF
Definition: kick.h:86
cmd_on
@ cmd_on
Definition: kick.h:116
CMD__BP
#define CMD__BP
Byte Program.
Definition: SPI-command-set.h:65
KEYBIT_G
#define KEYBIT_G
Definition: key-enable-bits.h:80
POWERUP_OFFTIME
#define POWERUP_OFFTIME
Separate multiple chip detections, time in µ-seconds.
Definition: kick.h:74
ERRC__SUCCESS
#define ERRC__SUCCESS
Error codes.
Definition: serial-codes.h:92
_cfg_baudrate
int _cfg_baudrate
configured through propeller-load
Definition: kick.c:75
POWERUP_SPILINES
#define POWERUP_SPILINES
Give SPI lines some time to power up (i.e. GA-G41M-ES2L).
Definition: kick.h:72
XD8_BE64K
#define XD8_BE64K
Definition: chipspec.h:123
KEYID_k
#define KEYID_k
Definition: key-enable-bits.h:43
KEYID_p
#define KEYID_p
Definition: key-enable-bits.h:39
tag_xcog0
Cog parameters for burn().
Definition: kick.h:203
tag_xcog0::pcog
int * pcog
Cog info pointer, used by cog_end().
Definition: kick.h:204
tag_linedat::buf
char * buf
Pointer to buffer, that holds the data.
Definition: kick.h:167
X36_PS
#define X36_PS
Definition: chipspec.h:147
chip
struct tag_chip chip
Definition: kick.c:82
PGM_cycle
void PGM_cycle(enum tag_cmdstat *cmdstat, unsigned char odd_tracker)
Definition: kick.c:2228
KEYID_G
#define KEYID_G
Definition: key-enable-bits.h:53
tag_chipspec
Chip specifications, provided within the source code.
Definition: chipspec.h:166
tag_linedat::payload
unsigned char payload
Number of payload bytes.
Definition: kick.h:172
ADDRLEN_IN_BITS
@ ADDRLEN_IN_BITS
Definition: kick.h:128
KEYID_b
#define KEYID_b
Definition: key-enable-bits.h:46
tag_chipspec::sr_bitnames
char * sr_bitnames[3]
Status Register 0 Bit Names.
Definition: chipspec.h:175
chip_read
signed char chip_read(struct tag_filespec *filespec, unsigned int firstloc, unsigned int memsize, unsigned int *lines, char *linebuf)
Definition: kick.c:1345
tag_typeS::data
unsigned int data
Definition: kick.h:151
filespec_ini
void filespec_ini(int chipsize)
Definition: filespec.c:66
HEXDUMP_mkline
void HEXDUMP_mkline(struct tag_linedat *linedat, char *linebuf_orig)
This function transforms a binary payload into a row of ascii chars including line ending characters ...
Definition: kick.c:1660
CHIP_TO_FILE
#define CHIP_TO_FILE
Send data to terminal and save on disk.
Definition: serial-codes.h:74
KEYID_t
#define KEYID_t
Definition: key-enable-bits.h:38
key_config
void key_config(void)
Enable menu keys according to chip specs.
Definition: kick.c:971
CMD__US
#define CMD__US
Unprotect Sector.
Definition: SPI-command-set.h:75
SPI_off
void SPI_off(int mode)
Switch SPI bus off.
Definition: kick.c:2166
BIT_MOSI
#define BIT_MOSI
Definition: proppins.h:85
page_write
void page_write(const unsigned int addr, unsigned char *buffer)
Write a page buffer to chip.
Definition: kick.c:1806
WIP_polling
int WIP_polling(void)
Determine end of write cycle by polling the WIP bit.
Definition: kick.c:1878
KEYBIT_d
#define KEYBIT_d
Definition: key-enable-bits.h:64
KEYID_m
#define KEYID_m
Definition: key-enable-bits.h:57
SOH
#define SOH
Ascii 'start of header'.
Definition: serial-codes.h:47