URL: <http://savannah.nongnu.org/patch/?8563>
Summary: Generalize power reduction macros in power.h by removing hard coded device names Project: AVR C Runtime Library Submitted by: pitchumani Submitted on: Tue 04 Nov 2014 09:52:19 AM GMT Category: None Priority: 6 Status: In Progress Privacy: Public Assigned to: pitchumani Originator Email: Open/Closed: Open Discussion Lock: Any _______________________________________________________ Details: power.h is one of header files in avr-libc that hard codes device name, needs an update for every new device. Attached patches generalizes the power reduction macros in power.h and adds required conditional macros in device header files. power.h: Power reduction macros are enabled conditionally based on specific macro for power reduction register (instead of device name macro). Eg. #if defined(__AVR_HAVE_PRR_PRADC) #define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC)) #define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC)) #endif Macro '__AVR_HAVE_PRR_PRADC' shall be defined in the device header file along with power reduction register and bitfields. To enable/ disable all following function shall be used. static __inline void __attribute__ ((__always_inline__)) __power_all_enable() { #ifdef __AVR_HAVE_PRR PRR &= (uint8_t)~(__AVR_HAVE_PRR); #endif #ifdef __AVR_HAVE_PRR0 PRR0 &= (uint8_t)~(__AVR_HAVE_PRR0); #endif #ifdef __AVR_HAVE_PRR1 PRR1 &= (uint8_t)~(__AVR_HAVE_PRR1); #endif #ifdef __AVR_HAVE_PRR2 PRR2 &= (uint8_t)~(__AVR_HAVE_PRR2); #endif #ifdef __AVR_HAVE_PRGEN PR_PRGEN &= (uint8_t)~(__AVR_HAVE_PRGEN); #endif #ifdef __AVR_HAVE_PRPA PR_PRPA &= (uint8_t)~(__AVR_HAVE_PRPA); #endif #ifdef __AVR_HAVE_PRPB PR_PRPB &= (uint8_t)~(__AVR_HAVE_PRPB); #endif #ifdef __AVR_HAVE_PRPC PR_PRPC &= (uint8_t)~(__AVR_HAVE_PRPC); #endif #ifdef __AVR_HAVE_PRPD PR_PRPD &= (uint8_t)~(__AVR_HAVE_PRPD); #endif #ifdef __AVR_HAVE_PRPE PR_PRPE &= (uint8_t)~(__AVR_HAVE_PRPE); #endif #ifdef __AVR_HAVE_PRPF PR_PRPF &= (uint8_t)~(__AVR_HAVE_PRPF); #endif } where __AVR_HAVE_PRR, __AVR_HAVE_PRGEN etc expands to sum of bitfields in respective register/port (defined in device header). In this case, we don't have to power reduction macros for new devices, it is automatically derived from the device header file. power.h may require update only for exceptional cases like new power reduction register/ ports/ bitfields. device header files: Adds macros for each power reduction register and its bitfields. Eg: iom1284.h #define __AVR_HAVE_PRR0 ((1<<PRADC)|(1<<PRSPI)|(1<<PRTIM1)|(1<<PRUSART0)|(1<<PRUSART1)|(1<<PRTIM0)|(1<<PRTIM2)|(1<<PRTWI)) #define __AVR_HAVE_PRR0_PRADC #define __AVR_HAVE_PRR0_PRSPI #define __AVR_HAVE_PRR0_PRTIM1 #define __AVR_HAVE_PRR0_PRUSART0 #define __AVR_HAVE_PRR0_PRUSART1 #define __AVR_HAVE_PRR0_PRTIM0 #define __AVR_HAVE_PRR0_PRTIM2 #define __AVR_HAVE_PRR0_PRTWI --- Thanks to Joern Rennecke (Embecosm) who proposed this idea to make power reduction macros generic. _______________________________________________________ File Attachments: ------------------------------------------------------- Date: Tue 04 Nov 2014 09:52:19 AM GMT Name: generalize-power-reduction-macros.patch Size: 116kB By: pitchumani <http://savannah.nongnu.org/patch/download.php?file_id=32362> ------------------------------------------------------- Date: Tue 04 Nov 2014 09:52:19 AM GMT Name: power-reduction-macros-mega.patch Size: 45kB By: pitchumani <http://savannah.nongnu.org/patch/download.php?file_id=32363> ------------------------------------------------------- Date: Tue 04 Nov 2014 09:52:19 AM GMT Name: power-reduction-macros-xmega.patch Size: 74kB By: pitchumani <http://savannah.nongnu.org/patch/download.php?file_id=32364> ------------------------------------------------------- Date: Tue 04 Nov 2014 09:52:19 AM GMT Name: power-reduction-macros-others.patch Size: 24kB By: pitchumani <http://savannah.nongnu.org/patch/download.php?file_id=32365> _______________________________________________________ Reply to this item at: <http://savannah.nongnu.org/patch/?8563> _______________________________________________ Message sent via/by Savannah http://savannah.nongnu.org/ _______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-libc-dev