2001-10-15 02:46:59 +00:00
|
|
|
/*
|
2003-02-08 04:17:25 +00:00
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
2003-02-06 19:54:46 +00:00
|
|
|
* Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean <bsd@bsdhome.com>
|
2001-10-15 02:46:59 +00:00
|
|
|
*
|
2003-02-06 19:54:46 +00:00
|
|
|
* 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2001-10-15 02:46:59 +00:00
|
|
|
*
|
2003-02-06 19:54:46 +00:00
|
|
|
* 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.
|
2001-10-15 02:46:59 +00:00
|
|
|
*
|
2003-02-06 19:54:46 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-10-15 02:46:59 +00:00
|
|
|
*/
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
/* $Id$ */
|
2003-02-11 21:27:06 +00:00
|
|
|
%{
|
|
|
|
|
2003-02-14 20:34:03 +00:00
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
2003-02-11 21:27:06 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "lists.h"
|
2003-02-13 19:27:50 +00:00
|
|
|
#include "par.h"
|
2003-02-11 21:27:06 +00:00
|
|
|
#include "pindefs.h"
|
|
|
|
#include "ppi.h"
|
|
|
|
#include "pgm.h"
|
|
|
|
#include "stk500.h"
|
|
|
|
#include "avr.h"
|
|
|
|
|
|
|
|
extern char * progname;
|
|
|
|
|
|
|
|
int yylex(void);
|
|
|
|
int yyerror(char * errmsg);
|
|
|
|
|
2003-02-12 09:08:10 +00:00
|
|
|
static int assign_pin(int pinno, TOKEN * v);
|
|
|
|
static int which_opcode(TOKEN * opcode);
|
|
|
|
static int parse_cmdbits(OPCODE * op);
|
|
|
|
|
2003-02-11 21:27:06 +00:00
|
|
|
%}
|
2001-10-14 23:17:26 +00:00
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
%token K_READ
|
|
|
|
%token K_WRITE
|
|
|
|
%token K_READ_LO
|
|
|
|
%token K_READ_HI
|
|
|
|
%token K_WRITE_LO
|
|
|
|
%token K_WRITE_HI
|
|
|
|
%token K_LOADPAGE_LO
|
|
|
|
%token K_LOADPAGE_HI
|
|
|
|
%token K_WRITEPAGE
|
|
|
|
%token K_CHIP_ERASE
|
|
|
|
%token K_PGM_ENABLE
|
|
|
|
|
|
|
|
%token K_MEMORY
|
|
|
|
|
2001-10-16 23:32:30 +00:00
|
|
|
%token K_PAGE_SIZE
|
2001-11-21 02:46:55 +00:00
|
|
|
%token K_PAGED
|
2003-02-20 14:11:34 +00:00
|
|
|
|
|
|
|
%token K_BS2
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_BUFF
|
|
|
|
%token K_CHIP_ERASE_DELAY
|
2003-02-20 14:11:34 +00:00
|
|
|
%token K_DEDICATED
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_DESC
|
2002-12-01 04:30:01 +00:00
|
|
|
%token K_DEVICECODE
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_EEPROM
|
|
|
|
%token K_ERRLED
|
|
|
|
%token K_FLASH
|
|
|
|
%token K_ID
|
2003-02-20 14:11:34 +00:00
|
|
|
%token K_IO
|
2001-10-16 23:32:30 +00:00
|
|
|
%token K_LOADPAGE
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_MAX_WRITE_DELAY
|
|
|
|
%token K_MIN_WRITE_DELAY
|
|
|
|
%token K_MISO
|
|
|
|
%token K_MOSI
|
2001-10-16 23:32:30 +00:00
|
|
|
%token K_NUM_PAGES
|
2003-02-20 14:11:34 +00:00
|
|
|
%token K_PAGEL
|
2003-02-13 19:27:50 +00:00
|
|
|
%token K_PAR
|
2003-02-20 19:46:23 +00:00
|
|
|
%token K_PARALLEL
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_PART
|
|
|
|
%token K_PGMLED
|
|
|
|
%token K_PROGRAMMER
|
2003-02-20 19:46:23 +00:00
|
|
|
%token K_PSEUDO
|
2002-11-30 14:09:12 +00:00
|
|
|
%token K_PWROFF_AFTER_WRITE
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_RDYLED
|
|
|
|
%token K_READBACK_P1
|
|
|
|
%token K_READBACK_P2
|
2001-10-16 23:32:30 +00:00
|
|
|
%token K_READMEM
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_RESET
|
2003-02-20 19:46:23 +00:00
|
|
|
%token K_SERIAL
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_SCK
|
|
|
|
%token K_SIZE
|
2002-11-30 14:09:12 +00:00
|
|
|
%token K_STK500
|
|
|
|
%token K_TYPE
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_VCC
|
|
|
|
%token K_VFYLED
|
2001-10-16 23:32:30 +00:00
|
|
|
%token K_WRITEPAGE
|
|
|
|
|
|
|
|
%token K_NO
|
2001-10-14 23:17:26 +00:00
|
|
|
%token K_YES
|
|
|
|
|
|
|
|
%token TKN_COMMA
|
|
|
|
%token TKN_EQUAL
|
|
|
|
%token TKN_SEMI
|
|
|
|
%token TKN_NUMBER
|
|
|
|
%token TKN_STRING
|
|
|
|
%token TKN_ID
|
|
|
|
|
|
|
|
%start config
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
|
|
config :
|
|
|
|
def |
|
|
|
|
config def
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
def :
|
|
|
|
prog_def TKN_SEMI |
|
|
|
|
part_def TKN_SEMI
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
prog_def :
|
|
|
|
K_PROGRAMMER
|
2002-11-30 14:09:12 +00:00
|
|
|
{ current_prog = pgm_new(); }
|
2001-10-14 23:17:26 +00:00
|
|
|
prog_parms
|
|
|
|
{
|
|
|
|
if (lsize(current_prog->id) == 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at %s:%d: required parameter id not specified\n",
|
|
|
|
progname, infile, lineno);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-11-30 14:09:12 +00:00
|
|
|
if (current_prog->type[0] == 0) {
|
|
|
|
fprintf(stderr, "%s: error at %s:%d: programmer type not specified\n",
|
|
|
|
progname, infile, lineno);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-10-14 23:17:26 +00:00
|
|
|
ladd(programmers, current_prog);
|
|
|
|
current_prog = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
part_def :
|
|
|
|
K_PART
|
|
|
|
{ current_part = avr_new_part(); }
|
2001-10-16 02:47:55 +00:00
|
|
|
part_parms
|
2001-10-14 23:17:26 +00:00
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
LNODEID ln;
|
|
|
|
AVRMEM * m;
|
2001-10-16 23:32:30 +00:00
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
if (current_part->id[0] == 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at %s:%d: required parameter id not specified\n",
|
|
|
|
progname, infile, lineno);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-10-16 02:47:55 +00:00
|
|
|
|
|
|
|
/*
|
2001-10-16 23:34:07 +00:00
|
|
|
* perform some sanity checking, and compute the number of bits
|
|
|
|
* to shift a page for constructing the page address for
|
|
|
|
* page-addressed memories.
|
2001-10-16 02:47:55 +00:00
|
|
|
*/
|
2001-11-21 02:46:55 +00:00
|
|
|
for (ln=lfirst(current_part->mem); ln; ln=lnext(ln)) {
|
|
|
|
m = ldata(ln);
|
|
|
|
if (m->paged) {
|
|
|
|
if (m->page_size == 0) {
|
2001-10-16 02:47:55 +00:00
|
|
|
fprintf(stderr,
|
2001-10-16 23:32:30 +00:00
|
|
|
"%s: error at %s:%d: must specify page_size for paged "
|
2001-10-16 02:47:55 +00:00
|
|
|
"memory\n",
|
|
|
|
progname, infile, lineno);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
if (m->num_pages == 0) {
|
2001-10-16 02:47:55 +00:00
|
|
|
fprintf(stderr,
|
2001-10-16 23:32:30 +00:00
|
|
|
"%s: error at %s:%d: must specify num_pages for paged "
|
2001-10-16 02:47:55 +00:00
|
|
|
"memory\n",
|
|
|
|
progname, infile, lineno);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
if (m->size != m->page_size * m->num_pages) {
|
2001-10-16 02:47:55 +00:00
|
|
|
fprintf(stderr,
|
2001-10-16 23:32:30 +00:00
|
|
|
"%s: error at %s:%d: page size (%u) * num_pages (%u) = "
|
2001-10-16 02:47:55 +00:00
|
|
|
"%u does not match memory size (%u)\n",
|
|
|
|
progname, infile, lineno,
|
2001-11-21 02:46:55 +00:00
|
|
|
m->page_size,
|
|
|
|
m->num_pages,
|
|
|
|
m->page_size * m->num_pages,
|
|
|
|
m->size);
|
2001-10-16 02:47:55 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
|
2001-10-16 02:47:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
ladd(part_list, current_part);
|
|
|
|
current_part = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
string_list :
|
|
|
|
TKN_STRING { ladd(string_list, $1); } |
|
|
|
|
string_list TKN_COMMA TKN_STRING { ladd(string_list, $3); }
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
num_list :
|
|
|
|
TKN_NUMBER { ladd(number_list, $1); } |
|
|
|
|
num_list TKN_COMMA TKN_NUMBER { ladd(number_list, $3); }
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
prog_parms :
|
|
|
|
prog_parm TKN_SEMI |
|
|
|
|
prog_parms prog_parm TKN_SEMI
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
prog_parm :
|
|
|
|
K_ID TKN_EQUAL string_list {
|
|
|
|
{
|
|
|
|
TOKEN * t;
|
|
|
|
while (lsize(string_list)) {
|
|
|
|
t = lrmv_n(string_list, 1);
|
|
|
|
ladd(current_prog->id, dup_string(t->value.string));
|
|
|
|
free_token(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
|
|
|
2003-02-13 19:27:50 +00:00
|
|
|
K_TYPE TKN_EQUAL K_PAR {
|
2002-11-30 14:09:12 +00:00
|
|
|
{
|
2003-02-13 19:27:50 +00:00
|
|
|
par_initpgm(current_prog);
|
2002-11-30 14:09:12 +00:00
|
|
|
}
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_TYPE TKN_EQUAL K_STK500 {
|
|
|
|
{
|
2002-12-01 04:30:01 +00:00
|
|
|
stk500_initpgm(current_prog);
|
2002-11-30 14:09:12 +00:00
|
|
|
}
|
|
|
|
} |
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
K_DESC TKN_EQUAL TKN_STRING {
|
|
|
|
strncpy(current_prog->desc, $3->value.string, PGM_DESCLEN);
|
|
|
|
current_prog->desc[PGM_DESCLEN-1] = 0;
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_VCC TKN_EQUAL num_list {
|
|
|
|
{
|
|
|
|
TOKEN * t;
|
|
|
|
int pin;
|
|
|
|
|
|
|
|
current_prog->pinno[PPI_AVR_VCC] = 0;
|
|
|
|
|
|
|
|
while (lsize(number_list)) {
|
|
|
|
t = lrmv_n(number_list, 1);
|
|
|
|
pin = t->value.number;
|
|
|
|
if ((pin < 2) || (pin > 9)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at line %d of %s: VCC must be one or more "
|
|
|
|
"pins from the range 2-9\n",
|
|
|
|
progname, lineno, infile);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
current_prog->pinno[PPI_AVR_VCC] |= (1 << (pin-2));
|
|
|
|
|
|
|
|
free_token(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
|
|
|
2001-12-29 21:37:20 +00:00
|
|
|
K_BUFF TKN_EQUAL num_list {
|
|
|
|
{
|
|
|
|
TOKEN * t;
|
|
|
|
int pin;
|
|
|
|
|
|
|
|
current_prog->pinno[PPI_AVR_BUFF] = 0;
|
|
|
|
|
|
|
|
while (lsize(number_list)) {
|
|
|
|
t = lrmv_n(number_list, 1);
|
|
|
|
pin = t->value.number;
|
|
|
|
if ((pin < 2) || (pin > 9)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at line %d of %s: BUFF must be one or more "
|
|
|
|
"pins from the range 2-9\n",
|
|
|
|
progname, lineno, infile);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
current_prog->pinno[PPI_AVR_BUFF] |= (1 << (pin-2));
|
|
|
|
|
|
|
|
free_token(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
K_RESET TKN_EQUAL TKN_NUMBER { assign_pin(PIN_AVR_RESET, $3); } |
|
|
|
|
K_SCK TKN_EQUAL TKN_NUMBER { assign_pin(PIN_AVR_SCK, $3); } |
|
|
|
|
K_MOSI TKN_EQUAL TKN_NUMBER { assign_pin(PIN_AVR_MOSI, $3); } |
|
|
|
|
K_MISO TKN_EQUAL TKN_NUMBER { assign_pin(PIN_AVR_MISO, $3); } |
|
|
|
|
K_ERRLED TKN_EQUAL TKN_NUMBER { assign_pin(PIN_LED_ERR, $3); } |
|
|
|
|
K_RDYLED TKN_EQUAL TKN_NUMBER { assign_pin(PIN_LED_RDY, $3); } |
|
|
|
|
K_PGMLED TKN_EQUAL TKN_NUMBER { assign_pin(PIN_LED_PGM, $3); } |
|
|
|
|
K_VFYLED TKN_EQUAL TKN_NUMBER { assign_pin(PIN_LED_VFY, $3); }
|
|
|
|
;
|
|
|
|
|
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
opcode :
|
|
|
|
K_READ |
|
|
|
|
K_WRITE |
|
|
|
|
K_READ_LO |
|
|
|
|
K_READ_HI |
|
|
|
|
K_WRITE_LO |
|
|
|
|
K_WRITE_HI |
|
|
|
|
K_LOADPAGE_LO |
|
|
|
|
K_LOADPAGE_HI |
|
|
|
|
K_WRITEPAGE |
|
|
|
|
K_CHIP_ERASE |
|
|
|
|
K_PGM_ENABLE
|
|
|
|
;
|
|
|
|
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
part_parms :
|
|
|
|
part_parm TKN_SEMI |
|
|
|
|
part_parms part_parm TKN_SEMI
|
|
|
|
;
|
|
|
|
|
|
|
|
|
2003-02-20 14:11:34 +00:00
|
|
|
reset_disposition :
|
|
|
|
K_DEDICATED | K_IO
|
|
|
|
;
|
|
|
|
|
2003-02-20 19:46:23 +00:00
|
|
|
parallel_modes :
|
|
|
|
yesno | K_PSEUDO
|
|
|
|
;
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
part_parm :
|
|
|
|
K_ID TKN_EQUAL TKN_STRING
|
|
|
|
{
|
|
|
|
strncpy(current_part->id, $3->value.string, AVR_IDLEN);
|
|
|
|
current_part->id[AVR_IDLEN-1] = 0;
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_DESC TKN_EQUAL TKN_STRING
|
|
|
|
{
|
|
|
|
strncpy(current_part->desc, $3->value.string, AVR_DESCLEN);
|
|
|
|
current_part->desc[AVR_DESCLEN-1] = 0;
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
2002-12-01 04:30:01 +00:00
|
|
|
K_DEVICECODE TKN_EQUAL TKN_NUMBER {
|
|
|
|
{
|
|
|
|
current_part->devicecode = $3->value.number;
|
|
|
|
free_token($3);
|
|
|
|
}
|
|
|
|
} |
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
K_CHIP_ERASE_DELAY TKN_EQUAL TKN_NUMBER
|
|
|
|
{
|
|
|
|
current_part->chip_erase_delay = $3->value.number;
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
2003-02-20 14:11:34 +00:00
|
|
|
K_PAGEL TKN_EQUAL TKN_NUMBER
|
|
|
|
{
|
|
|
|
current_part->pagel = $3->value.number;
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_BS2 TKN_EQUAL TKN_NUMBER
|
|
|
|
{
|
|
|
|
current_part->bs2 = $3->value.number;
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_RESET TKN_EQUAL reset_disposition
|
|
|
|
{
|
|
|
|
if ($3->primary == K_DEDICATED)
|
|
|
|
current_part->reset_disposition = RESET_DEDICATED;
|
|
|
|
else if ($3->primary == K_IO)
|
|
|
|
current_part->reset_disposition = RESET_IO;
|
|
|
|
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
2003-02-20 19:46:23 +00:00
|
|
|
K_SERIAL TKN_EQUAL yesno
|
|
|
|
{
|
|
|
|
if ($3->primary == K_YES)
|
|
|
|
current_part->flags |= AVRPART_SERIALOK;
|
|
|
|
else if ($3->primary == K_NO)
|
|
|
|
current_part->flags &= ~AVRPART_SERIALOK;
|
|
|
|
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_PARALLEL TKN_EQUAL parallel_modes
|
|
|
|
{
|
|
|
|
if ($3->primary == K_YES) {
|
|
|
|
current_part->flags |= AVRPART_PARALLELOK;
|
|
|
|
current_part->flags &= ~AVRPART_PSEUDOPARALLEL;
|
|
|
|
}
|
|
|
|
else if ($3->primary == K_NO) {
|
|
|
|
current_part->flags &= ~AVRPART_PARALLELOK;
|
|
|
|
current_part->flags &= ~AVRPART_PSEUDOPARALLEL;
|
|
|
|
}
|
|
|
|
else if ($3->primary == K_PSEUDO) {
|
|
|
|
current_part->flags |= AVRPART_PARALLELOK;
|
|
|
|
current_part->flags |= AVRPART_PSEUDOPARALLEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
/*
|
2001-10-14 23:17:26 +00:00
|
|
|
K_EEPROM { current_mem = AVR_M_EEPROM; }
|
|
|
|
mem_specs |
|
|
|
|
|
|
|
|
K_FLASH { current_mem = AVR_M_FLASH; }
|
2001-11-21 02:46:55 +00:00
|
|
|
mem_specs |
|
|
|
|
*/
|
|
|
|
|
|
|
|
K_MEMORY TKN_STRING
|
|
|
|
{
|
|
|
|
current_mem = avr_new_memtype();
|
|
|
|
strcpy(current_mem->desc, strdup($2->value.string));
|
|
|
|
free_token($2);
|
|
|
|
}
|
|
|
|
mem_specs
|
|
|
|
{
|
|
|
|
ladd(current_part->mem, current_mem);
|
|
|
|
current_mem = NULL;
|
|
|
|
} |
|
|
|
|
|
|
|
|
opcode TKN_EQUAL string_list {
|
|
|
|
{
|
|
|
|
int opnum;
|
|
|
|
OPCODE * op;
|
|
|
|
|
|
|
|
opnum = which_opcode($1);
|
|
|
|
op = avr_new_opcode();
|
|
|
|
parse_cmdbits(op);
|
|
|
|
current_part->op[opnum] = op;
|
|
|
|
|
|
|
|
free_token($1);
|
|
|
|
}
|
|
|
|
}
|
2001-10-14 23:17:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
yesno :
|
|
|
|
K_YES | K_NO
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
mem_specs :
|
|
|
|
mem_spec TKN_SEMI |
|
|
|
|
mem_specs mem_spec TKN_SEMI
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
mem_spec :
|
2001-10-16 23:32:30 +00:00
|
|
|
K_PAGED TKN_EQUAL yesno
|
2001-10-14 23:17:26 +00:00
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
current_mem->paged = $3->primary == K_YES ? 1 : 0;
|
2001-10-14 23:17:26 +00:00
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_SIZE TKN_EQUAL TKN_NUMBER
|
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
current_mem->size = $3->value.number;
|
2001-10-14 23:17:26 +00:00
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
2001-10-16 23:32:30 +00:00
|
|
|
K_PAGE_SIZE TKN_EQUAL TKN_NUMBER
|
2001-10-14 23:17:26 +00:00
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
current_mem->page_size = $3->value.number;
|
2001-10-14 23:17:26 +00:00
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
2001-10-16 23:32:30 +00:00
|
|
|
K_NUM_PAGES TKN_EQUAL TKN_NUMBER
|
2001-10-14 23:17:26 +00:00
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
current_mem->num_pages = $3->value.number;
|
2001-10-14 23:17:26 +00:00
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_MIN_WRITE_DELAY TKN_EQUAL TKN_NUMBER
|
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
current_mem->min_write_delay = $3->value.number;
|
2001-10-14 23:17:26 +00:00
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_MAX_WRITE_DELAY TKN_EQUAL TKN_NUMBER
|
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
current_mem->max_write_delay = $3->value.number;
|
2001-10-14 23:17:26 +00:00
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
2002-02-14 03:04:22 +00:00
|
|
|
K_PWROFF_AFTER_WRITE TKN_EQUAL yesno
|
2002-02-14 02:48:07 +00:00
|
|
|
{
|
2002-02-14 03:04:22 +00:00
|
|
|
current_mem->pwroff_after_write = $3->primary == K_YES ? 1 : 0;
|
2002-02-14 02:48:07 +00:00
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
2001-10-14 23:17:26 +00:00
|
|
|
K_READBACK_P1 TKN_EQUAL TKN_NUMBER
|
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
current_mem->readback[0] = $3->value.number;
|
2001-10-14 23:17:26 +00:00
|
|
|
free_token($3);
|
|
|
|
} |
|
|
|
|
|
|
|
|
K_READBACK_P2 TKN_EQUAL TKN_NUMBER
|
|
|
|
{
|
2001-11-21 02:46:55 +00:00
|
|
|
current_mem->readback[1] = $3->value.number;
|
2001-10-14 23:17:26 +00:00
|
|
|
free_token($3);
|
2001-11-21 02:46:55 +00:00
|
|
|
} |
|
|
|
|
|
|
|
|
opcode TKN_EQUAL string_list {
|
|
|
|
{
|
|
|
|
int opnum;
|
|
|
|
OPCODE * op;
|
|
|
|
|
|
|
|
opnum = which_opcode($1);
|
|
|
|
op = avr_new_opcode();
|
|
|
|
parse_cmdbits(op);
|
|
|
|
current_mem->op[opnum] = op;
|
|
|
|
|
|
|
|
free_token($1);
|
2001-10-14 23:17:26 +00:00
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
}
|
2001-10-14 23:17:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static char * vtypestr(int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case V_NUM : return "NUMERIC";
|
|
|
|
case V_STR : return "STRING";
|
|
|
|
default:
|
|
|
|
return "<UNKNOWN>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static int assign_pin(int pinno, TOKEN * v)
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
|
|
|
|
value = v->value.number;
|
|
|
|
|
|
|
|
if ((value <= 0) || (value >= 18)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at line %d of %s: pin must be in the "
|
|
|
|
"range 1-17\n",
|
|
|
|
progname, lineno, infile);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
current_prog->pinno[pinno] = value;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-11-21 02:46:55 +00:00
|
|
|
|
|
|
|
static int which_opcode(TOKEN * opcode)
|
|
|
|
{
|
|
|
|
switch (opcode->primary) {
|
|
|
|
case K_READ : return AVR_OP_READ; break;
|
|
|
|
case K_WRITE : return AVR_OP_WRITE; break;
|
|
|
|
case K_READ_LO : return AVR_OP_READ_LO; break;
|
|
|
|
case K_READ_HI : return AVR_OP_READ_HI; break;
|
|
|
|
case K_WRITE_LO : return AVR_OP_WRITE_LO; break;
|
|
|
|
case K_WRITE_HI : return AVR_OP_WRITE_HI; break;
|
|
|
|
case K_LOADPAGE_LO : return AVR_OP_LOADPAGE_LO; break;
|
|
|
|
case K_LOADPAGE_HI : return AVR_OP_LOADPAGE_HI; break;
|
|
|
|
case K_WRITEPAGE : return AVR_OP_WRITEPAGE; break;
|
|
|
|
case K_CHIP_ERASE : return AVR_OP_CHIP_ERASE; break;
|
|
|
|
case K_PGM_ENABLE : return AVR_OP_PGM_ENABLE; break;
|
|
|
|
default :
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at %s:%d: invalid opcode\n",
|
|
|
|
progname, infile, lineno);
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int parse_cmdbits(OPCODE * op)
|
|
|
|
{
|
|
|
|
TOKEN * t;
|
|
|
|
int bitno;
|
|
|
|
char ch;
|
|
|
|
char * e;
|
|
|
|
char * q;
|
|
|
|
int len;
|
2001-11-21 05:50:59 +00:00
|
|
|
char * s, *brkt;
|
2001-11-21 02:46:55 +00:00
|
|
|
|
2001-11-21 05:50:59 +00:00
|
|
|
bitno = 32;
|
2001-11-21 02:46:55 +00:00
|
|
|
while (lsize(string_list)) {
|
|
|
|
|
|
|
|
t = lrmv_n(string_list, 1);
|
|
|
|
|
2001-11-21 05:50:59 +00:00
|
|
|
s = strtok_r(t->value.string, " ", &brkt);
|
|
|
|
while (s != NULL) {
|
2001-11-21 02:46:55 +00:00
|
|
|
|
2001-11-21 05:50:59 +00:00
|
|
|
bitno--;
|
|
|
|
if (bitno < 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at %s:%d: too many opcode bits for instruction\n",
|
|
|
|
progname, infile, lineno);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
|
2001-11-21 05:50:59 +00:00
|
|
|
len = strlen(s);
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at %s:%d: invalid bit specifier \"\"\n",
|
|
|
|
progname, infile, lineno);
|
|
|
|
exit(1);
|
2001-11-21 02:46:55 +00:00
|
|
|
}
|
2001-11-21 05:50:59 +00:00
|
|
|
|
|
|
|
ch = s[0];
|
|
|
|
|
|
|
|
if (len == 1) {
|
|
|
|
switch (ch) {
|
|
|
|
case '1':
|
|
|
|
op->bit[bitno].type = AVR_CMDBIT_VALUE;
|
|
|
|
op->bit[bitno].value = 1;
|
|
|
|
op->bit[bitno].bitno = bitno % 8;
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
op->bit[bitno].type = AVR_CMDBIT_VALUE;
|
|
|
|
op->bit[bitno].value = 0;
|
|
|
|
op->bit[bitno].bitno = bitno % 8;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
op->bit[bitno].type = AVR_CMDBIT_IGNORE;
|
|
|
|
op->bit[bitno].value = 0;
|
|
|
|
op->bit[bitno].bitno = bitno % 8;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
op->bit[bitno].type = AVR_CMDBIT_ADDRESS;
|
|
|
|
op->bit[bitno].value = 0;
|
|
|
|
op->bit[bitno].bitno = 8*(bitno/8) + bitno % 8;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
op->bit[bitno].type = AVR_CMDBIT_INPUT;
|
|
|
|
op->bit[bitno].value = 0;
|
|
|
|
op->bit[bitno].bitno = bitno % 8;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
op->bit[bitno].type = AVR_CMDBIT_OUTPUT;
|
|
|
|
op->bit[bitno].value = 0;
|
|
|
|
op->bit[bitno].bitno = bitno % 8;
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at %s:%d: invalid bit specifier '%c'\n",
|
|
|
|
progname, infile, lineno, ch);
|
|
|
|
exit(1);
|
|
|
|
break;
|
2001-11-21 02:46:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-11-21 05:50:59 +00:00
|
|
|
if (ch == 'a') {
|
|
|
|
q = &s[1];
|
|
|
|
op->bit[bitno].bitno = strtol(q, &e, 0);
|
|
|
|
if ((e == q)||(*e != 0)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at %s:%d: can't parse bit number from \"%s\"\n",
|
|
|
|
progname, infile, lineno, q);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
op->bit[bitno].type = AVR_CMDBIT_ADDRESS;
|
|
|
|
op->bit[bitno].value = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: error at %s:%d: invalid bit specifier \"%s\"\n",
|
|
|
|
progname, infile, lineno, s);
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-21 02:46:55 +00:00
|
|
|
}
|
2001-11-21 05:50:59 +00:00
|
|
|
|
|
|
|
s = strtok_r(NULL, " ", &brkt);
|
2001-11-21 02:46:55 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 05:50:59 +00:00
|
|
|
free_token(t);
|
2001-11-21 02:46:55 +00:00
|
|
|
|
|
|
|
} /* while */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|