20080320 release
authorKevin Rosenberg <kevin@rosenberg.net>
Fri, 21 Mar 2008 21:14:04 +0000 (15:14 -0600)
committerKevin Rosenberg <kevin@rosenberg.net>
Fri, 21 Mar 2008 21:14:04 +0000 (15:14 -0600)
ChangeLog
README
cv_c/serial_lcd.prj
serial_lcd.c
serial_lcd.h

index aaf43bba6131f1fb9d6d4a7020002e2d75f19ef2..2ca0c15040e6cbe1267f2776fa70c6926c679295 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-22  Kevin Rosenberg <kevin@rosenberg.net>\r
+       * serial_lcd.c: Add note about processing data overrun flag\r
+\r
+2008-03-21  Kevin Rosenberg <kevin@rosenberg.net>\r
+       * serial_lcd.c: Fix typo for ICC and CV compilers and add USART RX\r
+       framing error check. Added protection against size optimization on\r
+       timed sequences for CV.  Thanks to Lee Theusch for the these ideas.\r
+       \r
 2008-03-20  Kevin Rosenberg <kevin@rosenberg.net>\r
        * serial_lcd.h, serial_lcd.c: Switch to using native delay\r
        and sleep functions for Codevision. \r
 2008-03-20  Kevin Rosenberg <kevin@rosenberg.net>\r
        * serial_lcd.h, serial_lcd.c: Switch to using native delay\r
        and sleep functions for Codevision. \r
diff --git a/README b/README
index 018a7b64501871e771fcfcbf35943cf4226e14f8..b2704c320e105cf0e1f676e29e644d7510b6e0c7 100644 (file)
--- a/README
+++ b/README
@@ -43,12 +43,12 @@ Code/Data Sizes (for 20080320 release)
 \r
 Compiler               Code  Data  Notes\r
 ---------              ----  ----  -----\r
 \r
 Compiler               Code  Data  Notes\r
 ---------              ----  ----  -----\r
-IAR 5.10A C             622    48  Size optimization high (+ 64 bytes stack)\r
-AVR-GCC 4.2.2 C         716    48  -Os\r
+IAR 5.10A C             626    48  Size optimization high (+ 64 bytes stack)\r
+AVR-GCC 4.2.2 C         720    48  -Os\r
 IAR 5.10A C++           762    49  Size optimization high (+ 64 bytes stack)\r
 IAR 5.10A C++           762    49  Size optimization high (+ 64 bytes stack)\r
-Codevision 2.02.6       792    48  Maximum size optimization\r
+Codevision 2.02.6       796    48  Maximum size optimization\r
 AVR-GCC 4.2.2 C++       806    50  -Os\r
 AVR-GCC 4.2.2 C++       806    50  -Os\r
-ImageCraft 7.16 Pro C   808    48  Full optimizations (-O24)\r
+ImageCraft 7.16 Pro C   806    48  Full optimizations (-O24)\r
 AVR-GCC 4.2.2 C++ Obj  1574    72  -Os\r
 IAR 5.10A C++ Obj      1112    65  Size optimization high (+ 63 bytes stack)\r
 \r
 AVR-GCC 4.2.2 C++ Obj  1574    72  -Os\r
 IAR 5.10A C++ Obj      1112    65  Size optimization high (+ 63 bytes stack)\r
 \r
index ac3eea814c42c0dcd99186f48ada666f99289e46..fc1ab0dd7a066e12cb2d0cfb7ce0e0b0984fc95b 100644 (file)
@@ -7,11 +7,11 @@ Top0=430
 Left0=711\r
 Height0=339\r
 Width0=497\r
 Left0=711\r
 Height0=339\r
 Width0=497\r
-Active0=1\r
+Active0=0\r
 State0=0\r
 OF1=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.c\r
 State0=0\r
 OF1=C:\home\kevin\pub\src\avr_serial_lcd\serial_lcd.c\r
-Top1=258\r
-Left1=269\r
+Top1=232\r
+Left1=43\r
 Height1=337\r
 Width1=495\r
 Row1=0\r
 Height1=337\r
 Width1=495\r
 Row1=0\r
@@ -108,7 +108,7 @@ WarningDataStackUsage=1
 WarningDataStackRecursion=1\r
 WarningHardwareStackLow=1\r
 DebugBootLoader=0\r
 WarningDataStackRecursion=1\r
 WarningHardwareStackLow=1\r
 DebugBootLoader=0\r
-Build=20\r
+Build=25\r
 UseEEPROMLocation0=1\r
 IncludePath0=\r
 IncludePath1=\r
 UseEEPROMLocation0=1\r
 IncludePath0=\r
 IncludePath1=\r
index 75983d2d2b033b1952daba674a4b5576cf026a72..899e945bcbef5eb56803e48875bcf9d5eb76aaa1 100644 (file)
@@ -105,12 +105,12 @@ REGISTER_VAR(unsigned char ledPwmCycling, "r7", 12);
 #define ledPwmPattern GPIOR0\r
 #if defined(REGISTER_BIT)\r
 #define BIT_led_on REGISTER_BIT(GPIOR1,0)\r
 #define ledPwmPattern GPIOR0\r
 #if defined(REGISTER_BIT)\r
 #define BIT_led_on REGISTER_BIT(GPIOR1,0)\r
-#define BACKLIGHT_STATUS() BIT_led_on\r
+#define IS_BACKLIGHT_ON() BIT_led_on\r
 #define BACKLIGHT_OFF() BIT_led_on = 0\r
 #define BACKLIGHT_ON() BIT_led_on = 1\r
 #else\r
 #define BACKLIGHT_OFF() BIT_led_on = 0\r
 #define BACKLIGHT_ON() BIT_led_on = 1\r
 #else\r
-#define BACKLIGHT_STATUS() (GPIOR1 & 0x01)\r
-#define BACKLIGHT_OFF() GPIOR1 &=~ ~0x01\r
+#define IS_BACKLIGHT_ON() (GPIOR1 & 0x01)\r
+#define BACKLIGHT_OFF() GPIOR1 &= ~0x01\r
 #define BACKLIGHT_ON() GPIOR1 |= 0x01\r
 #endif\r
 \r
 #define BACKLIGHT_ON() GPIOR1 |= 0x01\r
 #endif\r
 \r
@@ -159,7 +159,7 @@ static inline void LedPwmSetBrightness (unsigned char brightness) {
   unsigned char ledPwmPos;\r
 \r
   if (brightness == 0) { // turn backlight off for 0 brightness\r
   unsigned char ledPwmPos;\r
 \r
   if (brightness == 0) { // turn backlight off for 0 brightness\r
-    if (BACKLIGHT_STATUS()) {\r
+    if (IS_BACKLIGHT_ON()) {\r
       LedTimerStop();\r
       ledPwmPattern = 0;\r
       ledPwmCycling = 0;\r
       LedTimerStop();\r
       ledPwmPattern = 0;\r
       ledPwmCycling = 0;\r
@@ -178,12 +178,12 @@ static inline void LedPwmSetBrightness (unsigned char brightness) {
   ledPwmCycling = ledPwmPattern;\r
   if (ledPwmPos >= LED_BRIGHTNESS_LEVELS-1) { // maximum brightness\r
     // don't need PWM for continuously on\r
   ledPwmCycling = ledPwmPattern;\r
   if (ledPwmPos >= LED_BRIGHTNESS_LEVELS-1) { // maximum brightness\r
     // don't need PWM for continuously on\r
-    if (BACKLIGHT_STATUS()) {\r
+    if (IS_BACKLIGHT_ON()) {\r
       LedTimerStop();\r
       LED_PORT |= (1<<LED_PIN);\r
     }\r
   } else {\r
       LedTimerStop();\r
       LED_PORT |= (1<<LED_PIN);\r
     }\r
   } else {\r
-    if (BACKLIGHT_STATUS()) {\r
+    if (IS_BACKLIGHT_ON()) {\r
       LedTimerStart();\r
     }\r
   }\r
       LedTimerStart();\r
     }\r
   }\r
@@ -304,8 +304,14 @@ MAIN_FUNC() {
   MCUSR = 0; // clear all reset flags\r
 \r
   wdt_reset();\r
   MCUSR = 0; // clear all reset flags\r
 \r
   wdt_reset();\r
+#if defined(__CODEVISIONAVR__)\r
+#pragma optsize-\r
+#endif\r
   WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
   WDTCSR = (1<<WDE)|(1<<WDP3)|(1<<WDP0); // 1024K cycles, 8.0sec\r
   WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
   WDTCSR = (1<<WDE)|(1<<WDP3)|(1<<WDP0); // 1024K cycles, 8.0sec\r
+#if defined(__CODEVISIONAVR__) && defined(_OPTIMIZE_SIZE_)\r
+#pragma optsize+\r
+#endif\r
   MCUCR &= ~((1<<SM1)|(1<<SM0)); // use idle sleep mode\r
 \r
   LedPwmInit ();\r
   MCUCR &= ~((1<<SM1)|(1<<SM0)); // use idle sleep mode\r
 \r
   LedPwmInit ();\r
@@ -340,8 +346,16 @@ MAIN_FUNC() {
       cli();\r
       wdt_reset();\r
       MCUSR &= ~(1<<WDRF); // clear any watchdog interrupt flags\r
       cli();\r
       wdt_reset();\r
       MCUSR &= ~(1<<WDRF); // clear any watchdog interrupt flags\r
+\r
+#if defined(__CODEVISIONAVR__)\r
+#pragma optsize-\r
+#endif\r
       WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
       WDTCSR &= ~(1<<WDE); // watchdog timer off\r
       WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
       WDTCSR &= ~(1<<WDE); // watchdog timer off\r
+#if defined(__CODEVISIONAVR__) && defined(_OPTIMIZE_SIZE_)\r
+#pragma optsize+\r
+#endif\r
+\r
       sei();\r
 \r
       sleep_enable();\r
       sei();\r
 \r
       sleep_enable();\r
@@ -350,8 +364,16 @@ MAIN_FUNC() {
 \r
       cli();\r
       wdt_reset();\r
 \r
       cli();\r
       wdt_reset();\r
+\r
+#if defined(__CODEVISIONAVR__)\r
+#pragma optsize-\r
+#endif\r
       WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
       WDTCSR &= ~(1<<WDCE);\r
       WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence (keep old prescaler)\r
       WDTCSR &= ~(1<<WDCE);\r
+#if defined(__CODEVISIONAVR__) && defined(_OPTIMIZE_SIZE_)\r
+#pragma optsize+\r
+#endif\r
+\r
       sei();\r
     }\r
   }\r
       sei();\r
     }\r
   }\r
@@ -361,11 +383,11 @@ MAIN_FUNC() {
 void LcdWriteCmd (unsigned char Cmd) {\r
   LcdBusyWait();\r
   LCD_DATA_PORT = Cmd;  // BusyWait leaves RS low in "Register mode"\r
 void LcdWriteCmd (unsigned char Cmd) {\r
   LcdBusyWait();\r
   LCD_DATA_PORT = Cmd;  // BusyWait leaves RS low in "Register mode"\r
-   NOP();\r
+  NOP();\r
   LCD_CONTROL_PORT |= (1<<LCD_E);\r
   ENABLE_WAIT();\r
   LCD_CONTROL_PORT &= ~(1<<LCD_E);\r
   LCD_CONTROL_PORT |= (1<<LCD_E);\r
   ENABLE_WAIT();\r
   LCD_CONTROL_PORT &= ~(1<<LCD_E);\r
-   NOP();\r
+  NOP();\r
   LCD_CONTROL_PORT |= (1<<LCD_RS); // Set display to "Character mode"\r
 }\r
 \r
   LCD_CONTROL_PORT |= (1<<LCD_RS); // Set display to "Character mode"\r
 }\r
 \r
@@ -373,7 +395,7 @@ void LcdWriteData (unsigned char c) {
   LcdBusyWait();\r
   LCD_CONTROL_PORT |= (1<<LCD_RS); // Set display to "Character Mode"\r
   LCD_DATA_PORT = c;\r
   LcdBusyWait();\r
   LCD_CONTROL_PORT |= (1<<LCD_RS); // Set display to "Character Mode"\r
   LCD_DATA_PORT = c;\r
-   NOP();\r
+  NOP();\r
   LCD_CONTROL_PORT |= (1<<LCD_E);\r
   ENABLE_WAIT();\r
   LCD_CONTROL_PORT &= ~(1<<LCD_E);\r
   LCD_CONTROL_PORT |= (1<<LCD_E);\r
   ENABLE_WAIT();\r
   LCD_CONTROL_PORT &= ~(1<<LCD_E);\r
@@ -384,9 +406,9 @@ unsigned char LcdBusyWait (void) {
   LCD_DATA_DIR = 0x00; // Set LCD data port to inputs\r
   LCD_CONTROL_PORT &= ~(1<<LCD_RS); // Set display to "Register mode"\r
   LCD_CONTROL_PORT |= (1<<LCD_RW); // Put the display in the read mode\r
   LCD_DATA_DIR = 0x00; // Set LCD data port to inputs\r
   LCD_CONTROL_PORT &= ~(1<<LCD_RS); // Set display to "Register mode"\r
   LCD_CONTROL_PORT |= (1<<LCD_RW); // Put the display in the read mode\r
-   NOP();\r
+  NOP();\r
   do {\r
   do {\r
-      wdt_reset();\r
+    wdt_reset();\r
     LCD_CONTROL_PORT |= (1<<LCD_E);\r
     ENABLE_WAIT();\r
     LCDStatus = LCD_DATA_PIN_REG;\r
     LCD_CONTROL_PORT |= (1<<LCD_E);\r
     ENABLE_WAIT();\r
     LCDStatus = LCD_DATA_PIN_REG;\r
@@ -404,9 +426,23 @@ void usart_rx_handler(void)
 ISR(USART_RX_vect)\r
 #endif\r
 {\r
 ISR(USART_RX_vect)\r
 #endif\r
 {\r
-  unsigned char rx = UDR;\r
+  unsigned char rx, tmphead;\r
+\r
+  if (UCSRA & (1<<FE)) {\r
+    // framing error. Currrently, this is silently ignored\r
+    // real applications may wish to output information to LCD to indicate\r
+    // erroroneous byte received\r
+    return;\r
+  }\r
+#if HANDLE_DATA_OVER_RUN_ERROR\r
+  if (UCSRA & (1<<DOR)) {\r
+    // some applications may benefit from addind error notification for serial port data overruns\r
+  }\r
+#endif\r
+  \r
+  rx = UDR;\r
   // Calculate next buffer position.\r
   // Calculate next buffer position.\r
-  unsigned char tmphead = sUartRxHead;\r
+  tmphead = sUartRxHead;\r
   if (tmphead == UART_RX_BUFFER_SIZE-1)\r
     tmphead = 0;\r
   else\r
   if (tmphead == UART_RX_BUFFER_SIZE-1)\r
     tmphead = 0;\r
   else\r
@@ -443,7 +479,7 @@ static unsigned char WaitRxChar (void) {
 #if USE_CTS\r
   // turn off interrupts so that if UART char ready to be stored, then storage\r
   // will occur after CTS pin is set active. This allows UART ISR to set\r
 #if USE_CTS\r
   // turn off interrupts so that if UART char ready to be stored, then storage\r
   // will occur after CTS pin is set active. This allows UART ISR to set\r
-  //  CTS inactive if byte fills buffer after we remove current byte\r
+  // CTS inactive if byte fills buffer after we remove current byte\r
   cli();\r
 #endif\r
 \r
   cli();\r
 #endif\r
 \r
index 91d1137de59cc2fd036c62f7c64dce2fec00784e..ae4a58e7bcff48e1eb2b42d05c554bd1acf04200 100644 (file)
@@ -139,6 +139,8 @@ typedef __flash unsigned int prog_uint32_t;
   #define UCSZ1   2\r
   #define TXEN    3\r
   #define RXEN    4\r
   #define UCSZ1   2\r
   #define TXEN    3\r
   #define RXEN    4\r
+  #define DOR     3\r
+  #define FE      4\r
   #define RXC    7\r
   #define RXCIE   7\r
   #define PD1     1\r
   #define RXC    7\r
   #define RXCIE   7\r
   #define PD1     1\r