Re: NutEnterCritical vs NutEnterCriticalAccess()

Uwe Bonnes <bon-1JbLm1bU5j5ZIx36JBfelj3+ndqKAYMe9FMPySWZwLkb1SvskN2V4Q@public.gmane.org>
Newsgroups gmane.comp.hardware.microcontrollers.ethernut
Message-ID <[email protected]>
>>>>> "Nathan" == Nathan Moore <[email protected]> writes:

    Nathan> How about something like the following for each target cpu?
    Nathan> #define NutCriticalUpdate( VARIABLE, VALUE) \ do { \ size_t sz_
    Nathan> = sizeof(typeof(VARIABLE)); \ size_t sza_ =
    Nathan> sizeof(sig_atomic_t); \ typeof(VARIABLE) * VP_ = &(VARIABLE); \
    Nathan> typeof(VALUE) VAL_ = (VALUE); \ if (sz_ == sza_ &&
    Nathan> is_alligned(VP_) { \ *VP_ = VAL_; \ } else if (sz_ < sza) { \ /*
    Nathan> special consideration for cpu */ \ } else { \
    Nathan> NutEnterCritical(); \ *VP_ = VAL_; \ NutExitCritical(); \ } \ }
    Nathan> while (0) _______________________________________________

Nathan,

can you explain why you use do not use:

#define NutCriticalUpdate( VARIABLE, VALUE)               \
     do {                                                 \
              size_t sz_ = sizeof(typeof(VARIABLE));      \
              size_t sza_ = sizeof(sig_atomic_t);         \
              typeof(VARIABLE) * VP_ = &(VARIABLE);       \
              typeof(VALUE) VAL_ = (VALUE);               \
              if (sz_ <= sza_ && is_alligned(VP_)  {      \
                     *VP_ = VAL_;                         \
              } else {                                    \
                   NutEnterCritical();                    \
                   *VP_ = VAL_;                           \
                   NutExitCritical();                     \
              }                                           \
       } while (0)

Thanks
-- 
Uwe Bonnes                bon-1JbLm1bU5j5ZIx36JBfelj3+ndqKAYMe9FMPySWZwLkb1SvskN2V4Q@public.gmane.org

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.