Extend const args to avr_set_*() and developer_opts.c

... and print programming modes for -p*/d
This commit is contained in:
Stefan Rueger 2022-08-23 16:57:09 +01:00
parent c6ef6a9b9b
commit 5f910580b7
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
3 changed files with 71 additions and 48 deletions

View File

@ -69,8 +69,7 @@ int intlog2(unsigned int n) {
* *
* Set instruction bits in the specified command based on the opcode. * Set instruction bits in the specified command based on the opcode.
*/ */
int avr_set_bits(OPCODE * op, unsigned char * cmd) int avr_set_bits(const OPCODE *op, unsigned char *cmd) {
{
int i, j, bit; int i, j, bit;
unsigned char mask; unsigned char mask;
@ -96,8 +95,7 @@ int avr_set_bits(OPCODE * op, unsigned char * cmd)
* Set address bits in the specified command based on the opcode, and * Set address bits in the specified command based on the opcode, and
* the address. * the address.
*/ */
int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr) int avr_set_addr(const OPCODE *op, unsigned char *cmd, unsigned long addr) {
{
int i, j, bit; int i, j, bit;
unsigned long value; unsigned long value;
unsigned char mask; unsigned char mask;
@ -128,7 +126,7 @@ int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr)
* opcode) or, if positive, bn+1 where bn is bit number of the highest * opcode) or, if positive, bn+1 where bn is bit number of the highest
* necessary bit that the opcode does not provide. * necessary bit that the opcode does not provide.
*/ */
int avr_set_addr_mem(AVRMEM *mem, int opnum, unsigned char *cmd, unsigned long addr) { int avr_set_addr_mem(const AVRMEM *mem, int opnum, unsigned char *cmd, unsigned long addr) {
int ret, isflash, lo, hi, memsize, pagesize; int ret, isflash, lo, hi, memsize, pagesize;
OPCODE *op; OPCODE *op;
@ -220,8 +218,7 @@ int avr_set_addr_mem(AVRMEM *mem, int opnum, unsigned char *cmd, unsigned long a
* Set input data bits in the specified command based on the opcode, * Set input data bits in the specified command based on the opcode,
* and the data byte. * and the data byte.
*/ */
int avr_set_input(OPCODE * op, unsigned char * cmd, unsigned char data) int avr_set_input(const OPCODE *op, unsigned char *cmd, unsigned char data) {
{
int i, j, bit; int i, j, bit;
unsigned char value; unsigned char value;
unsigned char mask; unsigned char mask;
@ -858,7 +855,7 @@ const char *opcodename(int opnum) {
// Unique string representation of an opcode // Unique string representation of an opcode
char *opcode2str(OPCODE *op, int opnum, int detailed) { char *opcode2str(const OPCODE *op, int opnum, int detailed) {
char cb, space[1024], *sp = space; char cb, space[1024], *sp = space;
int compact = 1; int compact = 1;

View File

@ -54,7 +54,7 @@
#include "developer_opts_private.h" #include "developer_opts_private.h"
// Return 0 if op code would encode (essentially) the same SPI command // Return 0 if op code would encode (essentially) the same SPI command
static int opcodecmp(OPCODE *op1, OPCODE *op2, int opnum) { static int opcodecmp(const OPCODE *op1, const OPCODE *op2, int opnum) {
char *opstr1, *opstr2, *p; char *opstr1, *opstr2, *p;
int cmp; int cmp;
@ -86,7 +86,7 @@ static int opcodecmp(OPCODE *op1, OPCODE *op2, int opnum) {
} }
static void printopcode(AVRPART *p, const char *d, OPCODE *op, int opnum) { static void printopcode(const AVRPART *p, const char *d, const OPCODE *op, int opnum) {
unsigned char cmd[4]; unsigned char cmd[4];
int i; int i;
@ -103,51 +103,77 @@ static void printopcode(AVRPART *p, const char *d, OPCODE *op, int opnum) {
} }
} }
static void printallopcodes(AVRPART *p, const char *d, OPCODE **opa) { static void printallopcodes(const AVRPART *p, const char *d, OPCODE * const *opa) {
for(int i=0; i<AVR_OP_MAX; i++) for(int i=0; i<AVR_OP_MAX; i++)
printopcode(p, d, opa[i], i); printopcode(p, d, opa[i], i);
} }
// Mnemonic characterisation of flags // Programming modes
static char *parttype(AVRPART *p) { static char *prog_modes(const AVRPART *p) {
static char type[1024]; static char type[1024];
*type = 0;
if(!(p->flags & AVRPART_HAS_TPI) // TPI devices don't have the SPM opcode
&& strcmp(p->id, "t4") // Nor have these early ones
&& strcmp(p->id, "t5")
&& strcmp(p->id, "t9")
&& strcmp(p->id, "t10")
&& strcmp(p->id, "t11")
&& strcmp(p->id, "t12")
&& strcmp(p->id, "t15")
&& strcmp(p->id, "t20")
&& strcmp(p->id, "t26")
&& strcmp(p->id, "t28")
&& strcmp(p->id, "t40"))
strcpy(type, "PM_SPM");
switch(p->flags & (AVRPART_HAS_PDI | AVRPART_AVR32 | AVRPART_HAS_TPI | AVRPART_HAS_UPDI)) { switch(p->flags & (AVRPART_HAS_PDI | AVRPART_AVR32 | AVRPART_HAS_TPI | AVRPART_HAS_UPDI)) {
case 0: strcpy(type, "ISP"); break; case AVRPART_HAS_TPI: // AVR8L family
case AVRPART_HAS_PDI: strcpy(type, "PDI"); break; strcat(type, "|PM_TPI");
case AVRPART_AVR32: strcpy(type, "AVR32"); break; break;
case AVRPART_HAS_TPI: strcpy(type, "TPI"); break; case 0: // AVR8 family, "classic" parts
case AVRPART_HAS_UPDI: strcpy(type, "UPDI"); break; if(p->flags & AVRPART_SERIALOK) // ATmega406 has no ISP
default: strcpy(type, "UNKNOWN"); break; strcat(type, "|PM_ISP");
break;
case AVRPART_HAS_PDI: // AVR8_XMEGA family
strcat(type, "|PM_PDI");
break;
case AVRPART_HAS_UPDI: // AVR8X family
strcat(type, "|PM_UPDI");
break;
case AVRPART_AVR32: // AVR32 family
strcat(type, "|PM_aWire");
break;
default:
strcat(type, "|PM_UNKNOWN");
} }
if((p->flags & AVRPART_SERIALOK) == 0) switch(p->ctl_stack_type) {
strcat(type, "|NOTSERIAL"); case CTL_STACK_PP:
if((p->flags & AVRPART_PARALLELOK) == 0) strcat(type, "|PM_HVPP");
strcat(type, "|NOTPARALLEL"); break;
if(p->flags & AVRPART_PSEUDOPARALLEL) case CTL_STACK_HVSP:
strcat(type, "|PSEUDOPARALLEL"); strcat(type, "|PM_HVSP");
if(p->flags & AVRPART_IS_AT90S1200) break;
strcat(type, "|IS_AT90S1200"); default:
break;
}
if(p->flags & AVRPART_HAS_DW) if(p->flags & AVRPART_HAS_DW)
strcat(type, "|DW"); strcat(type, "|PM_debugWIRE");
if(p->flags & AVRPART_HAS_JTAG) if(p->flags & AVRPART_HAS_JTAG)
strcat(type, "|JTAG"); strcat(type, "|PM_JTAG");
if(p->flags & AVRPART_ALLOWFULLPAGEBITSTREAM)
strcat(type, "|PAGEBITSTREAM");
if((p->flags & AVRPART_ENABLEPAGEPROGRAMMING) == 0)
strcat(type, "|NOPAGEPROGRAMMING");
return type; return type + (*type == '|');
} }
// Check whether address bits are where they should be in ISP commands // Check whether address bits are where they should be in ISP commands
static void checkaddr(int memsize, int pagesize, int opnum, OPCODE *op, AVRPART *p, AVRMEM *m) { static void checkaddr(int memsize, int pagesize, int opnum, const OPCODE *op, const AVRPART *p, const AVRMEM *m) {
int i, lo, hi; int i, lo, hi;
const char *opstr = opcodename(opnum); const char *opstr = opcodename(opnum);
@ -293,7 +319,7 @@ static int dev_part_strct_entry(bool tsv, // Print as spreadsheet?
} }
static const char *dev_controlstack_name(AVRPART *p) { static const char *dev_controlstack_name(const AVRPART *p) {
return return
p->ctl_stack_type == CTL_STACK_PP? "pp_controlstack": p->ctl_stack_type == CTL_STACK_PP? "pp_controlstack":
p->ctl_stack_type == CTL_STACK_HVSP? "hvsp_controlstack": p->ctl_stack_type == CTL_STACK_HVSP? "hvsp_controlstack":
@ -302,7 +328,7 @@ static const char *dev_controlstack_name(AVRPART *p) {
} }
static void dev_stack_out(bool tsv, AVRPART *p, const char *name, unsigned char *stack, int ns) { static void dev_stack_out(bool tsv, const AVRPART *p, const char *name, const unsigned char *stack, int ns) {
if(!strcmp(name, "NULL")) { if(!strcmp(name, "NULL")) {
name = "pp_controlstack"; name = "pp_controlstack";
ns = 0; ns = 0;
@ -362,7 +388,7 @@ static int avrmem_deep_copy(AVRMEMdeep *d, const AVRMEM *m) {
return 0; return 0;
} }
static int memorycmp(AVRMEM *m1, AVRMEM *m2) { static int memorycmp(const AVRMEM *m1, const AVRMEM *m2) {
AVRMEMdeep dm1, dm2; AVRMEMdeep dm1, dm2;
if(!m1 && !m2) if(!m1 && !m2)
@ -478,7 +504,7 @@ static char *opsnm(const char *pre, int opnum) {
return ret; return ret;
} }
static void dev_part_raw(AVRPART *part) { static void dev_part_raw(const AVRPART *part) {
AVRPARTdeep dp; AVRPARTdeep dp;
int di = avrpart_deep_copy(&dp, part); int di = avrpart_deep_copy(&dp, part);
@ -499,7 +525,7 @@ static void dev_part_raw(AVRPART *part) {
} }
static void dev_part_strct(AVRPART *p, bool tsv, AVRPART *base) { static void dev_part_strct(const AVRPART *p, bool tsv, const AVRPART *base) {
char *descstr = cfg_escape(p->desc); char *descstr = cfg_escape(p->desc);
COMMENT *cp; COMMENT *cp;
@ -966,7 +992,7 @@ void dev_output_part_defs(char *partdesc) {
nfuses, nfuses,
ok, ok,
p->flags, p->flags,
parttype(p), prog_modes(p),
p->config_file, p->lineno p->config_file, p->lineno
); );
} }
@ -1008,7 +1034,7 @@ void dev_output_part_defs(char *partdesc) {
} }
static void dev_pgm_raw(PROGRAMMER *pgm) { static void dev_pgm_raw(const PROGRAMMER *pgm) {
PROGRAMMER dp; PROGRAMMER dp;
int len, idx; int len, idx;
char *id = ldata(lfirst(pgm->id)); char *id = ldata(lfirst(pgm->id));
@ -1070,7 +1096,7 @@ static const char *connstr(conntype_t conntype) {
} }
} }
static void dev_pgm_strct(PROGRAMMER *pgm, bool tsv, PROGRAMMER *base) { static void dev_pgm_strct(const PROGRAMMER *pgm, bool tsv, const PROGRAMMER *base) {
char *id = ldata(lfirst(pgm->id)); char *id = ldata(lfirst(pgm->id));
LNODEID ln; LNODEID ln;
COMMENT *cp; COMMENT *cp;

View File

@ -323,16 +323,16 @@ int intlog2(unsigned int n);
/* Functions for OPCODE structures */ /* Functions for OPCODE structures */
OPCODE * avr_new_opcode(void); OPCODE * avr_new_opcode(void);
void avr_free_opcode(OPCODE * op); void avr_free_opcode(OPCODE * op);
int avr_set_bits(OPCODE * op, unsigned char * cmd); int avr_set_bits(const OPCODE *op, unsigned char *cmd);
int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr); int avr_set_addr(const OPCODE *op, unsigned char *cmd, unsigned long addr);
int avr_set_addr_mem(AVRMEM *mem, int opnum, unsigned char *cmd, unsigned long addr); int avr_set_addr_mem(const AVRMEM *mem, int opnum, unsigned char *cmd, unsigned long addr);
int avr_set_input(OPCODE * op, unsigned char * cmd, unsigned char data); int avr_set_input(const OPCODE *op, unsigned char *cmd, unsigned char data);
int avr_get_output(const OPCODE *op, const unsigned char *res, unsigned char *data); int avr_get_output(const OPCODE *op, const unsigned char *res, unsigned char *data);
int avr_get_output_index(const OPCODE *op); int avr_get_output_index(const OPCODE *op);
char cmdbitchar(CMDBIT cb); char cmdbitchar(CMDBIT cb);
char *cmdbitstr(CMDBIT cb); char *cmdbitstr(CMDBIT cb);
const char *opcodename(int opnum); const char *opcodename(int opnum);
char *opcode2str(OPCODE *op, int opnum, int detailed); char *opcode2str(const OPCODE *op, int opnum, int detailed);
/* Functions for AVRMEM structures */ /* Functions for AVRMEM structures */
AVRMEM * avr_new_memtype(void); AVRMEM * avr_new_memtype(void);