# AWK program to parse CSV into C header # # (c) 2014 protological.com\CLI Systems LLC clisystems.com # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . function redefine(from, to) { printf("#ifdef __%s__\n#define __%s__\n#endif\n",from,to) } BEGIN{ FS = ","; #print "Proc, Flash KBytes, RAM Bytes, EEPROM bytes"; i = 0; DEBUG = 0 print "///////////////////////////////////////////////////////////////////////////////////////////\n \ // PIC selection header, do not modify\n \ // Copyright 2014\n \ //\n \ ///////////////////////////////////////////////////////////////////////////////////////////" print "#ifndef __PIC__" print "#define __PIC__" print "\n//Some parts are 5volt 'V' versions of 3.3volt parts" redefine("PIC24FV16KA301","PIC24F16KA301") redefine("PIC24FV16KA302","PIC24F16KA302") redefine("PIC24FV16KA303","PIC24F16KA303") redefine("PIC24FV16KA304","PIC24F16KA304") redefine("PIC24FV32KA301","PIC24F32KA301") redefine("PIC24FV32KA302","PIC24F32KA302") redefine("PIC24FV32KA303","PIC24F32KA303") redefine("PIC24FV32KA304","PIC24F32KA304") print "\n// Setup the values for the part" } { if(i>0) { gsub(/\"/, "", $1); # Handle the first case if(i == 1) print "#if defined(__" $1 "__)"; else print "#elif defined(__" $1 "__)"; # This defines the processor family if(substr($1, 1, 5)=="dsPIC") print " #define " substr($1, 1, 8) else print " #define " substr($1, 1, 6) #// 66K bytes flash, 22K instruction, 4096 bytes RAM, 1024 bytes eeprom #// Max address = (instructions *1024 *2) = 0xB000 # print out the definitions per processor gsub(/\"/, "", $5); maxaddr = (($5/3)*1024 *2) #print " #include p" $1 ".h" printf(" #define FLASH_MAX_ADDRESS 0x%05X\n" , maxaddr) printf(" #define FLASH_BYTES %d\n" , ($5*1024)) gsub(/\"/, "", $7); printf(" #define RAM_BYTES %d // 0x%06X\n", $7, $7) gsub(/\"/, "", $8); printf(" #define EEPROM_BYTES %d // 0x%06X\n", $8, $8) # DEBUG if(DEBUG) { print " #warning \"Selected processor " $1 ", " $5 ", " $7 ", " $8 "\"" #print $1 "," $5 "," $7 "," $8; } } i = i+1; } END{ print "#else" print "#error \"Error, no processor defined\"" print "#endif\n"; # Don't support E processors? #print "#if defined(dsPIC33E) || defined(PIC24E)\n#error \"PIC24E/dsPIC33E devices not supported at this time\"\n#endif" print "#ifdef dsPIC30F" if(DEBUG) print "\n#warning \"dsPIC30F Family\"" print "#define USER_SPACE_START 0x100\n#endif" print "#ifdef dsPIC33F" if(DEBUG) print "#warning \"dsPIC33F Family\"" print "#define USER_SPACE_START 0x200\n#endif" print "#ifdef dsPIC33E" if(DEBUG) print "#warning \"dsPIC33E Family\"" print "#define USER_SPACE_START 0x200\n#endif" print "#ifdef PIC24F" if(DEBUG) print "#warning \"PIC24F Family\"" print "#define USER_SPACE_START 0x200\n#endif" print "#ifdef PIC24H" if(DEBUG) "#warning \"PIC24H Family\"" print "#define USER_SPACE_START 0x200\n#endif" print "#ifdef PIC24E" if(DEBUG) "#warning \"PIC24E Family\"" print "#define USER_SPACE_START 0x200\n#endif" # Include guard" print "\n#endif // End include guard" }