AnsweredAssumed Answered

Why are all the pointers to peripheral structure definitions in MKE06Z4.h marked Volatile in MKE06Z4.h?

Question asked by Sean Beatty on Apr 19, 2016
Latest reply on Apr 21, 2016 by Sean Beatty

I'm using version 1.3 of MKE06Z4.h, which is what's generated when I build a new bareboard project with Codewarrior 10.6. All of the peripheral register structures define a pointer to the structure, and qualify it with the volatile keyword. For example, here's the definition of the ADC:


/** ADC - Peripheral register structure */

typedef struct ADC_MemMap {

  uint32_t SC1;                                    /**< Status and Control Register 1, offset: 0x0 */

  uint32_t SC2;                                    /**< Status and Control Register 2, offset: 0x4 */

  uint32_t SC3;                                    /**< Status and Control Register 3, offset: 0x8 */

  uint32_t SC4;                                    /**< Status and Control Register 4, offset: 0xC */

  uint32_t R;                                      /**< Conversion Result Register, offset: 0x10 */

  uint32_t CV;                                     /**< Compare Value Register, offset: 0x14 */

  uint32_t APCTL1;                                 /**< Pin Control 1 Register, offset: 0x18 */

  uint32_t SC5;                                    /**< Status and Control Register 5, offset: 0x1C */

} volatile *ADC_MemMapPtr;


This defines the pointer ADC_MemMapPtr as volatile. Why? There's only one ADC on the device - once that pointer is initialized, it won't likely be changed to point at anything else.


On the other hand, the individual registers in the ADC_MemMap structure likely will change without the compiler knowing about it (for example, the Conversion_Complete flag). Shouldn't the volatile keyword be applied to the structure members, not the pointer to the structure?


I noted that this was not the case in version 1.0 of this file, which is used by many of example projects. The volatile keyword doesn't appear in MKE06Z4.h version 1.0.


Any thoughts?