-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new functions (#1570): get_vtarget, get_varef, get_fosc, get_sck_period #1574
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4444ca8
new functions (#1570): get_vtarget, get_varef, get_fosc, get_sck_period
Ho-Ro 29a315c
fix memory access error, provide 4 get_ functions for stk50v2
Ho-Ro c5e117d
get_sck_period() and get_vtarget() for JTAG1
Ho-Ro d3a1429
fix sck typo wrong parameter
Ho-Ro 42a7f67
fosc / sck test for most stk500v2 based programmer (except mk3?)
Ho-Ro 64c82fd
fosc / sck test for most stk500v2 based programmer (except mk3?)
Ho-Ro 2ec638f
variable xtal setting; formatting
Ho-Ro b438ba5
update stk500v1 sck display
Ho-Ro aaa26d9
Last (?) tidying according review from MCUdude and stefanrueger
Ho-Ro af22682
parms spacing correction (jtagmkI); parms sequence correction (stk500v2)
Ho-Ro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1190,13 +1190,29 @@ static int stk500_set_vtarget(const PROGRAMMER *pgm, double v) { | |
|
||
if (uaref > utarg) { | ||
pmsg_warning("reducing V[aref] from %.1f to %.1f\n", uaref / 10.0, v); | ||
if ((rc = stk500_setparm(pgm, Parm_STK_VADJUST, utarg)) != 0) | ||
if ((rc = stk500_setparm(pgm, Parm_STK_VADJUST, utarg)) != 0) { | ||
pmsg_error("cannot set V[aref]\n"); | ||
return rc; | ||
} | ||
} | ||
return stk500_setparm(pgm, Parm_STK_VTARGET, utarg); | ||
} | ||
|
||
|
||
static int stk500_get_vtarget(const PROGRAMMER *pgm, double *v) { | ||
unsigned utarg = 0; | ||
int rv; | ||
|
||
if ((rv = stk500_getparm(pgm, Parm_STK_VTARGET, &utarg)) != 0) { | ||
pmsg_error("cannot obtain V[target]\n"); | ||
return rv; | ||
} | ||
|
||
*v = utarg / 10.0; | ||
return 0; | ||
} | ||
|
||
|
||
static int stk500_set_varef(const PROGRAMMER *pgm, unsigned int chan /* unused */, | ||
double v) | ||
{ | ||
|
@@ -1214,7 +1230,25 @@ static int stk500_set_varef(const PROGRAMMER *pgm, unsigned int chan /* unused * | |
"V[target] = %.1f\n", utarg/10.0); | ||
return -1; | ||
} | ||
return stk500_setparm(pgm, Parm_STK_VADJUST, uaref); | ||
|
||
if ((rc = stk500_setparm(pgm, Parm_STK_VADJUST, uaref)) < 0) | ||
pmsg_error("cannot set V[aref]\n"); | ||
return rc; | ||
} | ||
|
||
|
||
static int stk500_get_varef(const PROGRAMMER *pgm, unsigned int chan /* unused */, | ||
double *v) { | ||
unsigned uaref = 0; | ||
int rv; | ||
|
||
if ((rv = stk500_getparm(pgm, Parm_STK_VADJUST, &uaref)) != 0) { | ||
pmsg_error("cannot obtain V[aref]\n"); | ||
return rv; | ||
} | ||
|
||
*v = uaref / 10.0; | ||
return 0; | ||
} | ||
|
||
|
||
|
@@ -1224,7 +1258,7 @@ static int stk500_set_fosc(const PROGRAMMER *pgm, double v) { | |
1, 8, 32, 64, 128, 256, 1024 | ||
}; | ||
size_t idx; | ||
int rc; | ||
int rc = 0; | ||
|
||
prescale = cmatch = 0; | ||
if (v > 0.0) { | ||
|
@@ -1252,15 +1286,45 @@ static int stk500_set_fosc(const PROGRAMMER *pgm, double v) { | |
} | ||
} | ||
if (idx == sizeof(ps) / sizeof(ps[0])) { | ||
pmsg_warning("f = %u Hz too low, %u Hz min\n", fosc, PDATA(pgm)->xtal / (256 * 1024 * 2)); | ||
return -1; | ||
pmsg_warning("f = %u Hz too low, using %u Hz\n", fosc, PDATA(pgm)->xtal / (256 * 1024 * 2)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good thinking! I like that the code does the nearest best and warns |
||
prescale = idx; | ||
cmatch = 255; | ||
} | ||
} | ||
|
||
if ((rc = stk500_setparm(pgm, Parm_STK_OSC_PSCALE, prescale)) != 0 | ||
|| (rc = stk500_setparm(pgm, Parm_STK_OSC_CMATCH, cmatch)) != 0) | ||
if ((rc = stk500_setparm(pgm, Parm_STK_OSC_PSCALE, prescale)) != 0 ) { | ||
pmsg_error("cannot set Parm_STK_OSC_PSCALE\n"); | ||
return rc; | ||
|
||
} | ||
|
||
if ((rc = stk500_setparm(pgm, Parm_STK_OSC_CMATCH, cmatch)) != 0) { | ||
pmsg_error("cannot set Parm_STK_OSC_CMATCH\n"); | ||
return rc; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
||
static int stk500_get_fosc(const PROGRAMMER *pgm, double *v) { | ||
unsigned prescale=0, cmatch=0; | ||
static unsigned ps[] = { | ||
1, 8, 32, 64, 128, 256, 1024 | ||
}; | ||
int rc; | ||
|
||
if ((rc = stk500_getparm(pgm, Parm_STK_OSC_PSCALE, &prescale)) != 0) { | ||
pmsg_error("cannot get Parm_STK_OSC_PSCALE\n"); | ||
return rc; | ||
} | ||
|
||
if ((rc = stk500_getparm(pgm, Parm_STK_OSC_CMATCH, &cmatch)) != 0) { | ||
pmsg_error("cannot get Parm_STK_OSC_CMATCH\n"); | ||
return rc; | ||
} | ||
|
||
*v = !prescale ? 0 : PDATA(pgm)->xtal / ((cmatch + 1) * 2 * ps[prescale - 1]); | ||
|
||
return 0; | ||
} | ||
|
||
|
@@ -1275,11 +1339,12 @@ static int stk500_set_fosc(const PROGRAMMER *pgm, double v) { | |
static int stk500_set_sck_period(const PROGRAMMER *pgm, double v) { | ||
int dur; | ||
double min, max; | ||
int rv = 0; | ||
|
||
min = 8.0 / PDATA(pgm)->xtal; | ||
max = 255 * min; | ||
dur = v / min + 0.5; | ||
|
||
if (v < min) { | ||
dur = 1; | ||
pmsg_warning("p = %.1f us too small, using %.1f us\n", | ||
|
@@ -1289,8 +1354,25 @@ static int stk500_set_sck_period(const PROGRAMMER *pgm, double v) { | |
pmsg_warning("p = %.1f us too large, using %.1f us\n", | ||
v/1e-6, dur*min/1e-6); | ||
} | ||
|
||
return stk500_setparm(pgm, Parm_STK_SCK_DURATION, dur); | ||
|
||
if ((rv = stk500_setparm(pgm, Parm_STK_SCK_DURATION, dur)) < 0) { | ||
pmsg_error("cannot set Parm_STK_SCK_DURATION\n"); | ||
return rv; | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
static int stk500_get_sck_period(const PROGRAMMER *pgm, double *v) { | ||
unsigned dur; | ||
int rv = 0; | ||
|
||
if ((rv = stk500_getparm(pgm, Parm_STK_SCK_DURATION, &dur)) < 0) { | ||
pmsg_error("cannot obtain Parm_STK_SCK_DURATION\n"); | ||
return rv; | ||
} | ||
*v = dur * 8.0 / PDATA(pgm)->xtal; | ||
return 0; | ||
} | ||
|
||
|
||
|
@@ -1535,6 +1617,7 @@ void stk500_initpgm(PROGRAMMER *pgm) { | |
pgm->paged_load = stk500_paged_load; | ||
pgm->print_parms = stk500_print_parms; | ||
pgm->set_sck_period = stk500_set_sck_period; | ||
pgm->get_sck_period = stk500_get_sck_period; | ||
pgm->parseextparams = stk500_parseextparms; | ||
pgm->setup = stk500_setup; | ||
pgm->teardown = stk500_teardown; | ||
|
@@ -1545,8 +1628,14 @@ void stk500_initpgm(PROGRAMMER *pgm) { | |
*/ | ||
if (pgm->extra_features & HAS_VTARG_ADJ) | ||
pgm->set_vtarget = stk500_set_vtarget; | ||
if (pgm->extra_features & HAS_VAREF_ADJ) | ||
if (pgm->extra_features & HAS_VTARG_READ) | ||
pgm->get_vtarget = stk500_get_vtarget; | ||
if (pgm->extra_features & HAS_VAREF_ADJ) { | ||
pgm->set_varef = stk500_set_varef; | ||
if (pgm->extra_features & HAS_FOSC_ADJ) | ||
pgm->get_varef = stk500_get_varef; | ||
} | ||
if (pgm->extra_features & HAS_FOSC_ADJ) { | ||
pgm->set_fosc = stk500_set_fosc; | ||
pgm->get_fosc = stk500_get_fosc; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually my mistake. I just realized that the two lines (in jtagmkI.c):
has an incorrect amount of spaces. Would you mind removing two spaces for each of them, so they'll look like this instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick thought: Let the computer do this nasty work. Could a format like this help to maintain an uniform appearance more easily instead of manual space counting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. We should probably have done this in the first place.
However, I think this should be done at a global scale, and as its very own PR.
Adding "dumb" spaces is sufficient for the time being. Maybe I'll look into fixing it after 7.3 has been released.