Hi Please, How i implement this code in CARM? ///////////////////////////////////////////// typedef struct _AT91S_RTC { AT91_REG RTC_CR; // Control Register AT91_REG RTC_MR; // Mode Register AT91_REG RTC_TIMR; // Time Register AT91_REG RTC_CALR; // Calendar Register AT91_REG RTC_TIMALR; // Time Alarm Register AT91_REG RTC_CALALR; // Calendar Alarm Register AT91_REG RTC_SR; // Status Register AT91_REG RTC_SCCR; // Status Clear Command Register AT91_REG RTC_IER; // Interrupt Enable Register AT91_REG RTC_IDR; // Interrupt Disable Register AT91_REG RTC_IMR; // Interrupt Mask Register AT91_REG RTC_VER; // Valid Entry Register } AT91S_RTC, *AT91PS_RTC; #define AT91C_BASE_MC ((AT91PS_MC) 0xFFFFFF00) // (MC) Base Address #define AT91C_BASE_RTC ((AT91PS_RTC) 0xFFFFFE00) // (RTC) Base Address ///////////////////////////////////////////// I need access SFR whit structures For example I tried this: ////////////////////////////////// typedef struct { at91_reg PS_CR; /* Control Register */ at91_reg PS_PCER ; /* Peripheral Clock Enable Register */ at91_reg PS_PCDR ; /* Peripheral Clock Disable Register */ at91_reg PS_PCSR ; /* Peripheral Clock Status Register */ }StructPS; StructPS *PS_BASE __at 0xFFFF4000; //////////////////////////// When i try change the PS_PCER value: PS_BASE->PS_PCER = 0x04; The 0xFFFF4004 (PS_PCER) value not is affected (I saw this in Simulator). What's wrong? can you help me? Thank's Eduardo
Ask yourself: Does a pointer to a structure exist at 0xFFFF4000, or does a group of registers organized like a structure exist at 0xFFFF4000? Having answered that, then ask yourself: Why am I attempting to use an extension to the C language to access these registers instead of using a bog-standard means similar to that in the example which utilizes the preprocessor (#define)?
Hi Dan, I'm trying this because i'm converting GNU code to Keil code. Some places in my GNU code use that pointer. Now i don't know what's the problem, or where. Could you help me whit this? Thanks Eduardo
StructPS *PS_BASE __at 0xFFFF4000;
"I'm trying this because i'm converting GNU code to Keil code. Some places in my GNU code use that pointer." In my opinion, this would be an area that does not require porting. Knowing that AT91_REG is:
typedef volatile unsigned int AT91_REG;
/* AT91 Register type */ typedef volatile unsigned int at91_reg ;
The 0xFFFF4004 (PS_PCER) value not is affected (I saw this in Simulator).
"Now i don't know, where is the problem" Look at the pointer definition; answer the question...
Attempting to use a pointer and that "__at" language extension is sure giving you problems. Let's try changing it around to use Standard C:
typedef struct { at91_reg PS_CR; /* Control Register */ at91_reg PS_PCER; /* Peripheral Clock Enable Register */ at91_reg PS_PCDR; /* Peripheral Clock Disable Register */ at91_reg PS_PCSR; /* Peripheral Clock Status Register */ } StructPS, *StructPS_P; #define PS_BASE ((StructPS_P)0xFFFF4000) PS_BASE->PCER = 0x04;
Oh, Andy Sorry... I understood. But i tried another combinations One of them:
StructPS *PS_BASE; StructPS PS_BASE1 __at 0xFFFF4000; PS_BASE=&PS_BASE1;
Nothing.. The problem remains @0xFFFF4004 there are no changes still with 0x00 00 00 00
In the derivative I use, PCER is write-only.
Sorry Dan, I don't understand. Where you defined PS_PCER write-only?
I didn't. Atmel did (for my derivative -- AT91RM9200). Says so in the datasheet.
Oh... Sure, sorry Maybe the problem is simulator config, because remains Now i create a new project only for test, there are:
#define PS_BASES 0xFFFF4000 /* Power Saving */ #define PS_TESTE (*((volatile unsigned int *)(PS_BASES + 0x04))) /* Peripheral Clock Enable Register */
PS_TESTE=0x04;
"Maybe the problem is simulator config..." If the simulator enforces the write-only semantics (assuming PCER is write-only for your derivative too), perhaps it always returns 0. That aside, you could inspect the compiler-generated code (compile to assembly source code) or disassemble and convince yourself that you are accessing the correct address.
Thanks Dan!! Now I understood! Thanks
I am happy to hear that, Eduardo. Cheers