avr-libc
avr-libc copied to clipboard
[bug #27198] avr/iox128a1.h is missing definitions for calibration signature indexes
Fri 07 Aug 2009 03:27:14 AM CEST
There are no #defines or enums defining an index for each possible production/calibration signature row entry/register. This index has to be loaded into ZL when using LPM on the NVM to load production signature entries.
It could look like:
typedef enum NVM_PROD_SIG_IDX_enum { NVM_PROD_SIG_IDX_RCOSC2M = 0x00, NVM_PROD_SIG_IDX_RCOSC32K = 0x02, NVM_PROD_SIG_IDX_RCOSC32M = 0x03, NVM_PROD_SIG_IDX_LOTNUM0 = 0x08, NVM_PROD_SIG_IDX_LOTNUM1 = 0x09, NVM_PROD_SIG_IDX_LOTNUM2 = 0x0A, NVM_PROD_SIG_IDX_LOTNUM3 = 0x0B, NVM_PROD_SIG_IDX_LOTNUM4 = 0x0C, NVM_PROD_SIG_IDX_LOTNUM5 = 0x0D, NVM_PROD_SIG_IDX_WAFNUM = 0x10, NVM_PROD_SIG_IDX_COORDX0 = 0x12, NVM_PROD_SIG_IDX_COORDX1 = 0x13, NVM_PROD_SIG_IDX_COORDY0 = 0x14, NVM_PROD_SIG_IDX_COORDY1 = 0x15, NVM_PROD_SIG_IDX_ADCACAL0 = 0x20, NVM_PROD_SIG_IDX_ADCACAL1 = 0x21, NVM_PROD_SIG_IDX_ADCBCAL0 = 0x24, NVM_PROD_SIG_IDX_ADCBCAL1 = 0x25, NVM_PROD_SIG_IDX_TEMPSENSE0 = 0x2E, NVM_PROD_SIG_IDX_TEMPSENSE1 = 0x2F, NVM_PROD_SIG_IDX_DACAOFFCAL = 0x30, NVM_PROD_SIG_IDX_DACAINCAL = 0x31, NVM_PROD_SIG_IDX_DACBOFFCAL = 0x32, NVM_PROD_SIG_IDX_DACBINCAL = 0x33 } NVM_PROD_SIG_IDX_t
a function for reading the signature data could look like: /* static inline */ uint8_t SystemReadCalibrationByte(NVM_PROD_SIG_IDX_t Index) { uint8_t Result;
asm volatile ( "mov r30, %[Idx]" "nt" "ldi r31, 0" "nt" "ldi %[Idx], %[Rd]" "nt" "sts %[Cmd], %[Idx]" "nt" "lpm %[Res], Z" "nt" : [Res] "=r" (Result) : [Idx] "a" ((uint8_t) Index), [Rd] "M" (NVM_CMD_READ_CALIB_ROW_gc), [Cmd] "m" (NVM_CMD) );
return Result; }
file #18535: signaturerow.txt file #18537: signaturerow2.txt
This issue was migrated from https://savannah.nongnu.org/bugs/?27198
Simon Kueppers
Maybe r30 and r31 have to get clobbered. Im not so much into inline-assembler. I also appended the code as a text file.
Eric Weddington
Yes Z (r30,r31) would have to be clobbered.
You have to change your "nt" to "\n\t" to truly get newline and tab characters.
I have doubts about this line: "ldi %[Idx], %[Rd]" "nt" I'm not sure what you're trying to do there.
And you probably need to double check your constraints that you're using.
But the work that you've done so far is very appreciated! :-) Would you be willing to keep working on the inline assembly and get it working and tested? You can look at other inline assembly constructs in avr-libc for working examples.
Simon Kueppers
First, as I already said Im not so much into inline-assembler.
What comes to the nt's I don't know who converted it from \n\t to nt on the long way of copy and pasting. In the text file it's correct.
I also haven't found a way to use ZH/ZL instead of r30, r31.
In this line "ldi %[Idx], %[Rd]" I just needed a temporary Register to copy the NVM_CMD_READ_CALIB_ROW_gc. So i used this register. I almost believe that there is a better solution, which is easier to understand.
The constraints I got from a German page (http://www.rn-wissen.de/index.php/Inline-Assembler_in_avr-gcc). It says "r" for any register, M for an 8 Bit Constant, m for a memory address (I believe?) and d for an upper register. So I think anything should be fine, but Im open to tips or hints.
I've already tested the assembly within the attached text-file and it works so far. I can read all calibration row entries.
Simon Kueppers
Maybe this one is better. It works fine as far as I can test it (Just reading LOTNUM3).
See signaturerow2.txt