From 8147823cf64e37f6f43838ffa9e056ea48e30c32 Mon Sep 17 00:00:00 2001 From: Kevin Rosenberg Date: Wed, 19 Mar 2008 12:45:49 -0600 Subject: [PATCH] 20080319 release: CV support --- ChangeLog | 3 + Makefile | 2 + README | 7 +- cv_c/Makefile | 15 ++ cv_c/{serlcd_cv.prj => serial_lcd.prj} | 58 ++++++-- icc_c/Makefile | 2 +- serial_lcd.c | 188 ++++++++++++++++++++++--- serial_lcd.h | 79 ++++++----- 8 files changed, 278 insertions(+), 76 deletions(-) create mode 100644 cv_c/Makefile rename cv_c/{serlcd_cv.prj => serial_lcd.prj} (72%) diff --git a/ChangeLog b/ChangeLog index 8c13117..9dad81f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2008-03-18 Kevin Rosenberg + * Add Codevision port + 2008-03-15 Kevin Rosenberg * serial_lcd.c: Add 4-bit interface mode * serial_lcd.h: Move LCD control codes here with renaming. Use diff --git a/Makefile b/Makefile index 688d777..bbbb7ef 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ date := $(shell date +"%Y%m%d") .PHONY: all all: build +PROJECT := serial_lcd tester := tester/serial_lcd_tester tester-build: $(tester).exe @@ -45,6 +46,7 @@ clean: $(MAKE) -C iar_cpp_obj clean $(MAKE) -C iar_cpp_obj clean $(MAKE) -C icc_c clean + @rm -f *~ .PHONY: distclean distclean: diff --git a/README b/README index 1c15365..1db3974 100644 --- a/README +++ b/README @@ -38,18 +38,19 @@ The code can be modified and redistributed as governed by the terms of the accompaning LICENSE file. -Code/Data Sizes (for 20080316 release) +Code/Data Sizes (for 20080318 release) ====================================== Compiler Code Data Notes --------- ---- ---- ----- -AVR-GCC C 718 48 -Os +AVR-GCC C 716 48 -Os AVR-GCC C++ 806 50 -Os AVR-GCC Obj 1574 72 -Os +CV 2.02.6 808 48 Maximum size optimization IAR C 622 48 Size optimization high (+ 64 bytes stack) IAR C++ 762 49 Size optimization high (+ 64 bytes stack) IAR Obj 1112 65 Size optimization high (+ 63 bytes stack) -ICC7 C 818 48 Full optimizations +ICC7 C Pro 812 48 Full optimizations (-O24) I would appreciate submissions of suggestions, improvements, or bug fixes. diff --git a/cv_c/Makefile b/cv_c/Makefile new file mode 100644 index 0000000..4c6d9e1 --- /dev/null +++ b/cv_c/Makefile @@ -0,0 +1,15 @@ +PROJECT := serial_lcd + +.PHONY: clean +clean: + @rm -rf $(PROJECT).str1 $(PROJECT).sym[0-9] $(PROJECT).cof \ + $(PROJECT).a $(PROJECT).o *~ Obj Linker +# Clean up Codevision files in source directory + @rm -f ../$(PROJECT).c@ ../$(PROJECT).c! ../$(PROJECT).h! \ + ../$(PROJECT).i ../$(PROJECT).inc ../$(PROJECT).sym \ + ../$(PROJECT).hdr $(PROJECT).txt *~ $(PROJECT).fct + +.PHONY: distclean +distclean: clean + @rm -rf $(PROJECT).map Exe List + diff --git a/cv_c/serlcd_cv.prj b/cv_c/serial_lcd.prj similarity index 72% rename from cv_c/serlcd_cv.prj rename to cv_c/serial_lcd.prj index 2a35dbe..78eab68 100644 --- a/cv_c/serlcd_cv.prj +++ b/cv_c/serial_lcd.prj @@ -2,32 +2,31 @@ Toolset=AVR FormatVersion=2 Files=1 -OpenedFiles=3 +OpenedFiles=0 Top0=430 Left0=711 Height0=339 Width0=497 -Active0=0 +Active0=1 State0=0 -OF1=c:\home\kevin\src\avr\serial_lcd\serial_lcd.c -Top1=151 -Left1=84 -Height1=509 -Width1=614 -Row1=135 +OF1=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.c +Top1=257 +Left1=268 +Height1=339 +Width1=497 +Row1=0 Collumn1=0 Active1=0 State1=0 -OF2=C:\home\kevin\src\avr\serial_lcd\serial_lcd.h +OF2=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.h Top2=257 Left2=268 Height2=339 Width2=497 -Row2=0 -Collumn2=0 -Active2=0 +Row2=114 +Collumn2=21 +Active2=1 State2=0 -F1=C:\home\kevin\src\avr\serial_lcd\serial_lcd.c OF3=c:\cvavreval\inc\tiny2313.h Top3=197 Left3=133 @@ -37,6 +36,12 @@ Row3=84 Collumn3=3 Active3=1 State3=0 +OutputListFilesDirectory=List +OutputObjectFilesDirectory=Obj +OutputExecutableFilesDirectory=Exe +OutputLinkerFilesDirectory=Linker +AllowDisplayFunctionCallTree=0 +F1=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.c [Compiler] Chip=ATtiny2313 CPUClock=14745600 @@ -66,7 +71,7 @@ WordAlignFLASHStructMembers=0 PreprocessorOutput=1 ExternalStartupFile=0 ExternalStartupFileWarning=0 -BitVariablesSize=8 +BitVariablesSize=24 UseHiGPIORbit=0 StackEndMarkers=0 Warnings=1 @@ -103,7 +108,7 @@ WarningDataStackUsage=1 WarningDataStackRecursion=1 WarningHardwareStackLow=1 DebugBootLoader=0 -Build=5 +Build=4 UseEEPROMLocation0=1 IncludePath0= IncludePath1= @@ -169,6 +174,29 @@ LibraryPath28= LibraryPath29= LibraryPath30= LibraryPath31= +RebuildAll=0 +LinkageInformationPresent=1 +GlobalConstInFlash=1 +ClearGlobalVarsStartup=0 +WarningFunctionParameterName=1 +WarningLocalVariableSetNotUsed=1 +WarningVariableUsedNotSet=1 +WarningTypeQualifierMeaningless=1 +WarningExplicitTypeMissing=1 +WarningEnumType=1 +WarningTypedefName=1 +WarningTypedefRedeclared=1 +WarningExtraBraces=1 +WarningIncompatibleAssignment=1 +WarningIncompatibleInit=1 +WarningIncompatibleOperandsTernary=1 +WarningIncompatibleFunctionArgument=1 +WarningIncompatibleFunctionReturn=1 +WarningMemoryAttributeIgnored=1 +WarningPragmaVector=1 +WarningCOFFArrayDim=1 +WarningCOFFDataComplex=1 +LinkerWarnings=1 [DefinedSymbols] Count=0 [Assembler] diff --git a/icc_c/Makefile b/icc_c/Makefile index 05bb2e1..cbdf209 100644 --- a/icc_c/Makefile +++ b/icc_c/Makefile @@ -9,7 +9,7 @@ CC = iccavr OBJECTS = $(PROJECT).o ## Compile options common for all C compilation units. -CFLAGS = -e -D__ICC_VERSION="7.16A" -DATtiny2313 -l -A -A -g -Wf-r20_23 +CFLAGS = -e -D__ICC_VERSION="7.16A" -DATtiny2313 -l -A -A -g -Wf-r20_23 -O24 ## Linker flags LDFLAGS = -g -e:0x0800 -bfunc_lit:0x26.0x800 -dram_end:0xdf -bdata:0x60.0xdf -dhwstk_size:30 -beeprom:0.128 -fihx_coff -S2 diff --git a/serial_lcd.c b/serial_lcd.c index 0c8bb10..1235c7b 100644 --- a/serial_lcd.c +++ b/serial_lcd.c @@ -11,8 +11,9 @@ ** ** Compilers supported: ** - WinAVR-20071221 (includes avr-libc 1.6 required for proper _delay_us) -** - IAR AVR 4.30 -** - Imagecraft AVR 7 +** - IAR AVR 4.30 and 5.10 +** - Imagecraft AVR 7.16 +** - Codevision AVR 2.02.06 ** ** LICENSE ** See accompaning LICENSE file @@ -30,7 +31,7 @@ FUSES = { .extended = EFUSE_DEFAULT, }; #endif - + // Number of PWM brightness levels supported #define LED_BRIGHTNESS_LEVELS 8 @@ -93,6 +94,12 @@ static FLASH_DECLARE(const unsigned char ledPwmPatterns[]) = #pragma global_register ledPwmCount:20 sUartRxHead:21 sUartRxTail:22 ledPwmCycling:23 unsigned char ledPwmCount, sUartRxHead, sUartRxTail, ledPwmCycling; +#elif defined(__CODEVISIONAVR__) +#pragma regalloc- +register unsigned char ledPwmCount, sUartRxHead, sUartRxTail, ledPwmCycling; +#pragma regalloc+ + +// Use avr_compat register variables #else REGISTER_VAR(unsigned char ledPwmCount, "r4", 15); REGISTER_VAR(unsigned char sUartRxHead, "r5", 14); @@ -101,8 +108,16 @@ REGISTER_VAR(unsigned char ledPwmCycling, "r7", 12); #endif #define ledPwmPattern GPIOR0 -#define ledStatus GPIOR1 +#if defined(REGISTER_BIT) #define BIT_led_on REGISTER_BIT(GPIOR1,0) +#define BACKLIGHT_STATUS() BIT_led_on +#define BACKLIGHT_OFF() BIT_led_on = 0 +#define BACKLIGHT_ON() BIT_led_on = 1 +#else +#define BACKLIGHT_STATUS() (GPIOR1 & 0x01) +#define BACKLIGHT_OFF() GPIOR1 &=~ ~0x01 +#define BACKLIGHT_ON() GPIOR1 |= 0x01 +#endif // Function declarations void LcdWriteCmd (unsigned char); @@ -110,8 +125,8 @@ void LcdWriteData (unsigned char); unsigned char LcdBusyWait (void); static unsigned char WaitRxChar (void); -// ImageCraft doesn't support inline functions, so use preprocessor -#if defined(__IMAGECRAFT__) +// ImageCraft/Codevision don't support inline functions, so use preprocessor +#if defined(__IMAGECRAFT__) || defined(__CODEVISIONAVR__) #define LedTimerStop() TCCR0B = 0 // Start with 256 prescaler #define LedTimerStart() TCCR0B = (1<> 8; + ledPwmPos = (brightness * (LED_BRIGHTNESS_LEVELS-1) + (unsigned int) 127) >> 8; // Below is probably not required, but ensures we don't exceed array if (ledPwmPos > LED_BRIGHTNESS_LEVELS - 1) ledPwmPos = LED_BRIGHTNESS_LEVELS - 1; @@ -168,12 +183,12 @@ static inline void LedPwmSetBrightness (unsigned char brightness) { ledPwmCycling = ledPwmPattern; if (ledPwmPos >= LED_BRIGHTNESS_LEVELS-1) { // maximum brightness // don't need PWM for continuously on - if (BIT_led_on) { + if (BACKLIGHT_STATUS()) { LedTimerStop(); LED_PORT |= (1<bit##bt #define FLASH_DECLARE(x) const x __attribute__((progmem)) #define NO_INIT_DECLARE(x) x __attribute__((section (".noinit"))) #define INLINE_FUNC_DECLARE(x) inline x __attribute__((always_inline)) #define PGM_READ_BYTE(x) pgm_read_byte(x) #define NOP() asm volatile("nop"); -#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)_SFR_MEM_ADDR(rg))->bit##bt #define REGISTER_VAR(V,GNU,IAR) register volatile V asm(GNU) #define NO_RETURN_FUNC(fn) fn __attribute__((noreturn)); \ fn @@ -104,22 +104,11 @@ typedef __flash unsigned int prog_uint32_t; // Below #include requires ICC v7.16+ #include -typedef struct { - unsigned bit0:1; - unsigned bit1:1; - unsigned bit2:1; - unsigned bit3:1; - unsigned bit4:1; - unsigned bit5:1; - unsigned bit6:1; - unsigned bit7:1; -} _io_reg; #define NOP() asm("nop"); // ImageCraft does not support inline functions #define inline #define INLINE_FUNC_DECLARE(x) x -#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)&rg)->bit##bt #define NO_RETURN_FUNC(fn) fn #define MAIN_FUNC() void main(void) #define MAIN_FUNC_LAST() @@ -136,44 +125,64 @@ typedef struct { // CodeVision Compiler #elif defined(__CODEVISIONAVR__) + +#if __CODEVISIONAVR__ >= 2 #include +#else +#include +#endif -typedef struct { - unsigned bit0:1; - unsigned bit1:1; - unsigned bit2:1; - unsigned bit3:1; - unsigned bit4:1; - unsigned bit5:1; - unsigned bit6:1; - unsigned bit7:1; -} _io_reg; +#if defined(_CHIP_ATTINY2313_) || defined(_CHIP_ATTINY2313V_) + #if !defined(WDTCSR) + #define WDTCSR WDTCR + #endif +// Below are bit position definitions for the ATtiny2313 + #define UCSZ0 1 + #define UCSZ1 2 + #define TXEN 3 + #define RXEN 4 + #define RXC 7 + #define RXCIE 7 + #define PD1 1 + #define PD2 2 + #define PD3 3 + #define PD4 4 + #define PD5 5 + #define PD6 6 + #define PB7 7 + #define CS02 2 + #define WGM01 1 + #define OCIE0A 0 + #define WDP0 0 + #define WDP1 1 + #define WDP2 2 + #define WDE 3 + #define WDCE 4 + #define WDP3 5 + #define WDRF 3 + #define SM0 4 + #define SM1 6 + #define SE 5 + #define sleep_enable() MCUCR |= (1<bit##bt #define NEAR_VAR(x) x #define NO_RETURN_FUNC(fn) fn -#define MAIN_FUNC(fn) fn #define MAIN_FUNC() void main(void) #define MAIN_FUNC_LAST() +#define PGM_READ_BYTE(x) (*(x)) -// 2007/11/29 - ImageCraft states they will support _Pragma() like IAR -// in a "few months". At that point, REGISTER_VAR and NO_INIT_DECLARE can -// be supported. REGISTER_VAR will need to be expanded with 4th variable to -// hold register number for ImageCraft. -// noinit for ImageCraft requires #pragma data:noinit -//#define NO_INIT_DECLARE(x) _Pragma(data:noinit); x; _Pragma(data:data); #define NO_INIT_DECLARE(x) x -//#define REGISTER_VAR(V,GNUR,IAR,ICC) _Pragma(global_register V ## : ## ICC) -#define REGISTER_VAR(V,GNUR,IAR) V +#define REGISTER_VAR(V,GNUR,IAR) register V -#define cli() asm("cli") -#define sei() asm("sei") -#define wdt_reset() asm("wdr") +#define ISR(vec) interrupt [ ## vec ## ] void vec ## _handler(void) #else #error Unsupported compiler -- 2.34.1