if (name == NULL)
return NULL;
- if (STRNCASECMP(proc_pos, "pic16", 5) == 0)
- proc_pos += 5;
-
- else if (STRNCASECMP(proc_pos, "p16", 3) == 0)
+ if (STRNCASECMP(proc_pos, "pic", 3) == 0)
proc_pos += 3;
+
+ else if (tolower(*proc_pos) == 'p')
+ proc_pos += 1;
- else if (STRNCASECMP(proc_pos, "16", 2) == 0)
- proc_pos += 2;
-
return proc_pos;
}
char *simple_pic_name = sanitise_processor_name(pic_name);
new_pic = Safe_calloc(1, sizeof(PIC_device));
- new_pic->name[0] = Safe_calloc(strlen(simple_pic_name)+3, sizeof(char));
- sprintf(new_pic->name[0], "16%s", simple_pic_name);
- new_pic->name[1] = Safe_calloc(strlen(simple_pic_name)+4, sizeof(char));
- sprintf(new_pic->name[1], "p16%s", simple_pic_name);
- new_pic->name[2] = Safe_calloc(strlen(simple_pic_name)+6, sizeof(char));
- sprintf(new_pic->name[2], "pic16%s", simple_pic_name);
- new_pic->name[3] = Safe_calloc(strlen(simple_pic_name)+1, sizeof(char));
- strcpy(new_pic->name[3], simple_pic_name);
+ new_pic->name = Safe_calloc(strlen(simple_pic_name)+1, sizeof(char));
+ strcpy(new_pic->name, simple_pic_name);
new_pic->defMaxRAMaddrs = maxram;
new_pic->bankMask = bankmsk;
char filename[512];
int len = 512;
+ /* allow abbreviations of the form "f877" - convert to "16f877" */
simple_pic_name = sanitise_processor_name(pic_name);
-
num_of_supported_PICS = 0;
/* open the piclist file */
!pic_file && dir;
dir = setNextItem(includeDirsSet))
{
- fprintf( stderr, "searching1 %s\n", dir );
+ //fprintf( stderr, "searching1 %s\n", dir );
SNPRINTF(&filename[0], len, "%s%s%s", dir, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
pic_file = fopen( filename, "rt" );
if (pic_file) break;
!pic_file && dir;
dir = setNextItem(userIncDirsSet))
{
- fprintf( stderr, "searching2 %s\n", dir );
+ //fprintf( stderr, "searching2 %s\n", dir );
SNPRINTF(&filename[0], len, "%s%s%s", dir, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
pic_file = fopen( filename, "rt" );
if (pic_file) break;
!pic_file && dir;
dir = setNextItem(libDirsSet))
{
- fprintf( stderr, "searching3 %s\n", dir );
+ //fprintf( stderr, "searching3 %s\n", dir );
SNPRINTF(&filename[0], len, "%s%s%s", dir, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
pic_file = fopen( filename, "rt" );
if (pic_file) break;
!pic_file && dir;
dir = setNextItem(libPathsSet))
{
- fprintf( stderr, "searching4 %s\n", dir );
+ //fprintf( stderr, "searching4 %s\n", dir );
SNPRINTF(&filename[0], len, "%s%s%s", dir, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
pic_file = fopen( filename, "rt" );
if (pic_file) break;
* list_alias - if non-zero, print all of the supported aliases
* for a device (e.g. F84, 16F84, etc...)
*-----------------------------------------------------------------*/
-void list_valid_pics(int ncols, int list_alias)
+void list_valid_pics(int ncols)
{
int col=0,longest;
- int i,j,k;
- int max_alias = 1;
+ int i,k,l;
if (num_of_supported_PICS == 0)
find_device(NULL); /* load all the definitions */
- if(list_alias)
- max_alias = PROCESSOR_NAMES;
-
/* decrement the column number if it's greater than zero */
ncols = (ncols > 1) ? ncols-1 : 4;
/* Find the device with the longest name */
for(i=0,longest=0; i<num_of_supported_PICS; i++) {
- for(j=0; j<max_alias; j++) {
- k = strlen(Pics[i]->name[j]);
- if(k>longest)
- longest = k;
- }
+ k = strlen(Pics[i]->name);
+ if(k>longest)
+ longest = k;
}
-#if 0
+#if 1
/* heading */
fprintf(stderr, "\nPIC14 processors and their characteristics:\n\n");
fprintf(stderr, " processor");
fprintf(stderr, "-----------------------------------------------------\n");
for(i=0; i < num_of_supported_PICS; i++) {
- fprintf(stderr," %s", Pics[i]->name[0]);
- l = longest + 2 - strlen(Pics[i]->name[0]);
+ fprintf(stderr," %s", Pics[i]->name);
+ l = longest + 2 - strlen(Pics[i]->name);
for(k=0; k<l; k++)
fputc(' ',stderr);
fprintf(stderr, "\nPIC14 processors supported:\n");
for(i=0; i < num_of_supported_PICS; i++) {
- for (j = 0; j<max_alias; j++) {
-
- fprintf(stderr,"%s", Pics[i]->name[j]);
- if(col<ncols) {
- l = longest + 2 - strlen(Pics[i]->name[j]);
- for(k=0; k<l; k++)
- fputc(' ',stderr);
+ fprintf(stderr,"%s", Pics[i]->name);
+ if(col<ncols) {
+ l = longest + 2 - strlen(Pics[i]->name);
+ for(k=0; k<l; k++)
+ fputc(' ',stderr);
- col++;
+ col++;
- } else {
- fputc('\n',stderr);
- col = 0;
- }
-
+ } else {
+ fputc('\n',stderr);
+ col = 0;
}
}
*-----------------------------------------------------------------*/
void init_pic(char *pic_type)
{
+ char long_name[PIC14_STRING_LEN];
+
pic = find_device(pic_type);
- if(!pic) {
- if(pic_type)
- fprintf(stderr, "'%s' was not found.\n", pic_type);
- else
- fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");
+ if (pic == NULL) {
+ /* check for shortened "16xxx" form */
+ sprintf(long_name, "16%s", pic_type);
+ pic = find_device(long_name);
+ if (pic == NULL) {
+ if(pic_type != NULL && pic_type[0] != '\0')
+ fprintf(stderr, "'%s' was not found.\n", pic_type);
+ else
+ fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");
- list_valid_pics(7,0);
- exit(1);
+ list_valid_pics(7);
+ exit(1);
+ }
}
}
if(!pic)
return NULL;
- return pic->name[1];
+ return pic->name;
}
/*-----------------------------------------------------------------*
}
+/* Keep track of whether we found an assignment to the __config words. */
+static int pic14_hasSetConfigWord = 0;
/*-----------------------------------------------------------------*
-* void assignConfigWordValue(int address, int value)
-*
-* Most midrange PICs have one config word at address 0x2007.
-* Newer PIC14s have a second config word at address 0x2008.
-* This routine will assign values to those addresses.
-*
-*-----------------------------------------------------------------*/
+ * void assignConfigWordValue(int address, int value)
+ *
+ * Most midrange PICs have one config word at address 0x2007.
+ * Newer PIC14s have a second config word at address 0x2008.
+ * This routine will assign values to those addresses.
+ *
+ *-----------------------------------------------------------------*/
-void assignConfigWordValue(int address, int value)
+void pic14_assignConfigWordValue(int address, int value)
{
if (CONFIG_WORD_ADDRESS == address)
config_word = value;
config2_word = value;
//fprintf(stderr,"setting config word 0x%x to 0x%x\n", address, value);
-
+ pic14_hasSetConfigWord = 1;
}
+
/*-----------------------------------------------------------------*
-* int getConfigWord(int address)
-*
-* Get the current value of a config word.
-*
-*-----------------------------------------------------------------*/
+ * int pic14_emitConfigWord (FILE * vFile)
+ *
+ * Emit the __config directives iff we found a previous assignment
+ * to the config word.
+ *-----------------------------------------------------------------*/
+extern char *iComments2;
+int pic14_emitConfigWord (FILE * vFile)
+{
+ if (pic14_hasSetConfigWord)
+ {
+ fprintf (vFile, "%s", iComments2);
+ fprintf (vFile, "; config word \n");
+ fprintf (vFile, "%s", iComments2);
+ if (pic14_getHasSecondConfigReg())
+ {
+ fprintf (vFile, "\t__config _CONFIG1, 0x%x\n", pic14_getConfigWord(0x2007));
+ fprintf (vFile, "\t__config _CONFIG2, 0x%x\n", pic14_getConfigWord(0x2008));
+ }
+ else
+ fprintf (vFile, "\t__config 0x%x\n", pic14_getConfigWord(0x2007));
+
+ return 1;
+ }
+ return 0;
+}
+
+/*-----------------------------------------------------------------*
+ * int pic14_getConfigWord(int address)
+ *
+ * Get the current value of a config word.
+ *
+ *-----------------------------------------------------------------*/
-int getConfigWord(int address)
+int pic14_getConfigWord(int address)
{
switch (address)
{
/*-----------------------------------------------------------------*
*
*-----------------------------------------------------------------*/
-unsigned getMaxRam(void)
+unsigned pic14_getMaxRam(void)
{
return pic->defMaxRAMaddrs;
}
* int getHasSecondConfigReg(void) - check if the device has a
* second config register, rather than just one.
*-----------------------------------------------------------------*/
-int getHasSecondConfigReg(void)
+int pic14_getHasSecondConfigReg(void)
{
if(!pic)
return 0;
int sharebankAddress = 0x7f;
/* If total RAM is less than 0x7f as with 16f84 then reduce
* sharebankAddress to fit */
- if ((unsigned)sharebankAddress > getMaxRam())
- sharebankAddress = (int)getMaxRam();
+ if ((unsigned)sharebankAddress > pic14_getMaxRam())
+ sharebankAddress = (int)pic14_getMaxRam();
return sharebankAddress;
}