i don't have a smart comment except:

- on msp430 it's perfectly possible to read-modify-write to peripherals.
  that's what the original 3.2.3 code was doing on all volatiles. Dmitry
  implemented an optimization so that bis/bic instructions are emitted
  where possible.

- except for the watchdog and flash controller... where the example they
  are showing in the paper would never be used by a developer.
  WATCHDOG=WATCHDOG is nonsense as the MSP430 watchdog by design reads a
  different value that it is required to write, causing the WDTPW to be
  wrong. so even if GCC would read the register and write it back, it
  would still reset.

- volatile access only disables caching, it doesn't protect against
  incomplete data for larger data types. that is, if one function reads
  a 32 bit value while the interrupt function modifies that data, it can
  read intermediate values. the correct thing to do is to disable
  interrupts during the data structure access. that's easiest done with
  a separate access function, marked with the "critical" attribute.
  (see ringbuffer in libmspgcc for an example)

- if there is a bug, it's open source feel free to provide patches ;-)

chris

John Porubek schrieb:
> Not sure if this has been discussed previously, but it's worth a
> mention if not. This is not MSP430 specific (although the referenced
> paper does mention the GCC port to the MSP430), but applies to anybody
> using C or C++ for development. A colleague showed me an item in the
> February 2009 issue of Embedded Systems Design magazine written by
> Jack Ganssle that is both interesting and scary. In a nutshell,
> compilers sometimes miscompile code using "volatile" qualifiers. See:
> 
> http://preview.tinyurl.com/cb3sk2
> 
> It references a paper that discusses the problem in detail. URL here
> for convenience:
> 
> http://preview.tinyurl.com/6pmr42
> 
> It would be interesting to hear the viewpoints on this of the compiler
> vendors who follow this group.
> 
> John
> 
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
> 


Reply via email to