X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=simavr%2Fsim%2Fsim_regbit.h;h=4852b562fc564286becdee64b49a0eb4d72751d5;hb=8ded5cfec51670bd535f1db09403dc894979e31b;hp=11700c89fa92e6d6f3de5d4e865db204182d4e0f;hpb=24c5c6069017010fd7d27eda7585e38b5fff7a4b;p=simavr diff --git a/simavr/sim/sim_regbit.h b/simavr/sim/sim_regbit.h index 11700c8..4852b56 100644 --- a/simavr/sim/sim_regbit.h +++ b/simavr/sim/sim_regbit.h @@ -24,22 +24,17 @@ #include "sim_avr.h" +#ifdef __cplusplus +extern "C" { +#endif + #define ARRAY_SIZE(_aa) (sizeof(_aa) / sizeof((_aa)[0])) -/* - * this 'structure' is a packed representation of an IO register 'bit' - * (or consecutive bits). This allows a way to set/get/clear them. - * gcc is happy passing these as register value, so you don't need to - * use a pointer when passing them along to functions. - */ -typedef struct avr_regbit_t { - unsigned long reg : 8, bit : 3, mask : 8; -} avr_regbit_t; /* * These accessors are inlined and are used to perform the operations on * avr_regbit_t definitions. This is the "official" way to access bits into registers - * The small footorint costs brings much better versatility for functions/bits that are + * The small footprint costs brings much better versatility for functions/bits that are * not always defined in the same place on real AVR cores */ /* @@ -65,6 +60,19 @@ static inline uint8_t avr_regbit_setto(avr_t * avr, avr_regbit_t rb, uint8_t v) return (avr->data[a] >> rb.bit) & rb.mask; } +/* + * Set the 'raw' bits, if 'v' is the unshifted value of the bits + */ +static inline uint8_t avr_regbit_setto_raw(avr_t * avr, avr_regbit_t rb, uint8_t v) +{ + uint8_t a = rb.reg; + if (!a) + return 0; + uint8_t m = rb.mask << rb.bit; + avr_core_watch_write(avr, a, (avr->data[a] & ~(m)) | ((v) & m)); + return (avr->data[a]) & (rb.mask << rb.bit); +} + static inline uint8_t avr_regbit_get(avr_t * avr, avr_regbit_t rb) { uint8_t a = rb.reg; @@ -74,6 +82,18 @@ static inline uint8_t avr_regbit_get(avr_t * avr, avr_regbit_t rb) return (avr->data[a] >> rb.bit) & rb.mask; } +/* + * Return the bit(s) 'in position' instead of zero based + */ +static inline uint8_t avr_regbit_get_raw(avr_t * avr, avr_regbit_t rb) +{ + uint8_t a = rb.reg; + if (!a) + return 0; + //uint8_t m = rb.mask << rb.bit; + return (avr->data[a]) & (rb.mask << rb.bit); +} + static inline uint8_t avr_regbit_clear(avr_t * avr, avr_regbit_t rb) { uint8_t a = (rb.reg); @@ -102,5 +122,8 @@ static inline uint8_t avr_regbit_get_array(avr_t * avr, avr_regbit_t *rb, int co #define AVR_IO_REGBIT(_io, _bit) { . reg = (_io), .bit = (_bit), .mask = 1 } #define AVR_IO_REGBITS(_io, _bit, _mask) { . reg = (_io), .bit = (_bit), .mask = (_mask) } +#ifdef __cplusplus +}; +#endif #endif /* __SIM_REGBIT_H__ */