CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

3.204 & 3.205 Bug (part 1)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
xpercad



Joined: 27 Jun 2004
Posts: 12
Location: MÉXICO

View user's profile Send private message

3.204 & 3.205 Bug (part 1)
PostPosted: Mon Jul 12, 2004 8:04 am     Reply with quote

1) I am using PIC18F252 with external I2C FRAM memory. I2C signals are software generated.

2) Two weeks ago I was using PCWH 3.180 and had no problems with reading/writting the FRAM memories but was running out of code space.

3) I switched to PCWH 3.202 and obtained big code reduction. The program malfunctioned from time to time and I found out it was related with FRAM access.

4) I switched to PCWH 3.204 and the program malfunctioned 100% of the times. Switched to PCWH 3.205 and same story.

5) I wrote a small diagnostic routine that writes and then reads from the FRAM memory and left some global declarations from the original application. I found out that with the global declaration int buffer_ibutton[4]; the diagnostic signals no error with the FRAM memory 99% of the times I run it. If I change the global declaration to int buffer_ibutton[8]; the diagnostic routine always signals an error with the FRAM memory. The global variable int buffer_ibutton[n]; is never used.

6) In part 2 of this topic you can find the file OK.C which includes the global declaration int buffer_ibutton[4] and the corresponding OK.lst file. In part 3 of this topic I am including the file NOK.C which includes the global declaration int buffer_ibutton[8] and the corresponding NOK.lst file. The generated code for each case is different.

Can anybody confirm if this is a compiler bug ???

Thanks in advance,

Aaron
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jul 12, 2004 11:00 am     Reply with quote

Edit: Remark obsolete and removed.

Last edited by ckielstra on Tue Jul 13, 2004 1:33 am; edited 1 time in total
xpercad



Joined: 27 Jun 2004
Posts: 12
Location: MÉXICO

View user's profile Send private message

PostPosted: Mon Jul 12, 2004 11:09 am     Reply with quote

Edit: Remark obsolete and removed.

Last edited by xpercad on Tue Jul 13, 2004 8:54 am; edited 1 time in total
xpercad



Joined: 27 Jun 2004
Posts: 12
Location: MÉXICO

View user's profile Send private message

3.204 & 3.205 Bug (part 2)
PostPosted: Mon Jul 12, 2004 11:18 am     Reply with quote

Code:

/* OK.c */

#include <18f252.h>

#use delay(clock=40000000, RESTART_WDT)

#priority EXT,TIMER0


#fuses H4,PROTECT,NOOSCSEN,BROWNOUT,WDT128,WDT,BORV45,PUT,CCP2C1,STVREN,NODEBUG,NOLVP,WRT,NOWRTD,WRTB,WRTC,CPD,CPB,EBTR,EBTRB

//#ORG 0x1F00,0x1FFF {}

#define VERSION         "3"
#define DIAG         1

#include <stdlib.h>

/* MACROS */

#define hi(x)  (*(&x+1))
#define lo(x)  (*(&x))


// Bus I2C (FRAM)
#define EEPROM_SCL     PIN_A3
#define EEPROM_SDA     PIN_A2

// Leds
#define LED_STATUS      PIN_C0

// Salidas binarias
#define RELAY_1         PIN_B2
#define RELAY_2         PIN_B3
#define RELAY_3         PIN_A5

/* Tamano memoria FRAM externa */
#define EEPROM_SIZE    16384

/* DIMENSIONES ESTRUCTURAS DE DATOS */

/* Tamano del buffer en RAM para Rx de mensajes */
#define SIZE_RAM_RX         768

/* maximo numero de cadenas predefinidas */
#define MAX_CADENAS         64

/* maximo numero de paquetes en un mensaje compuesto */
#define MAX_PTRS_PCKTS      64


/* ESTRUCTURAS Y VARIABLES GLOBALES */

/* estructura para manejo de paquetes recibidos */

typedef struct {
   
   unsigned int n_pckt;   /* Numero de Paquete */
   unsigned int pos;      /* Posicion de llegada */

} PCKT;

PCKT ptrs_pckt[MAX_PTRS_PCKTS];   /*   Arreglo de apuntadores a apuntadores de paquetes
                           recibidos en mensajes compuestos */

int   opc_rs232;            /*   Indica si la opcion RS232 esta instalada */

int   opc_switch;            /*   Indica si la opcion SWITCH esta instalada */

int   opc_ibtn;            /*   Indica si la opcion iBUTTON esta instalada */

int   opc_buzzer;            /*   Indica si la opcion BUZZER esta instalada */

int lst_sencillo_id[6];      /* Identificador del ultimo mensaje sencillo recibido */

int lst_compuesto_id[6];   /* Identificador del ultimo mensaje compuesto recibido */

int bitmap_rx[8];         /* Bit map de paquetes recibidos (64 bits) */

int pckts_rx;            /* Numero de paquetes recibidos (mensajes compuestos) */

int tot_pckts_rx;         /* Numero de total de paquetes a recibir (mensajes compuestos) */

int n_pckt;               /* Indicador de numero de paquete activo p/rd_pckts.c */

long dir_n_pckt;         /* Siguiente direccion a leer p/rd_pckts.c */

long n_bytes_leidos;      /* Numero de bytes leidos del paquete activo p/rd_pckts.c */

long int pckt_size;       /* Tamano del paquete activo p/rd_pckts.c */

long ptr_fram_rx_w;         /* Apuntador para escrituras en buffer FRAM_RX */

long int lst_fram_address;   /* Ultima localidad en FRAM accesada por R/W sequenciales */

int fram_status;         /* Estado FRAM

                        0: Cerrada
                        1: Abierta p/Lectura Sequencial
                        2: Abierta p/Escritura Sequencial
                     */

int hi_nibble_address;      /* Nibble alto del ultimo banco de FRAM accesado por R/W sequenciales */

long int ptr_nxt_cadena;   /* Apuntador a direccion disponible para carga de CADENAS */

int   aplicacion;            /* indica si la aplicacion es AUOMOTRIZ o CONTROL_REMOTO */

int rx_en_proceso;         /*   Bandera que indica si hay
                        recepcion POCSAG en proceso
                     */
                     
int   rx_decoder[4];         /*   Buffer para depositar los 4
                        bytes que se leen del POCSAG Decoder
                     */
                     
int capcode_rx;            /*   CAPCODE logico (0..7) en el que
                        se esta recibiendo mensaje POCSAG
                     */
                     
int fbits_rx;            /*   Function Bits del mensaje POCSAG
                        que se esta recibiendo
                     */
                     
int   func_rx;            /*   Funcion (1: Alfa  0: Numerico) que corresponde
                        al CAPCODE y Function Bits del mensaje
                        POCSAG que se esta recibiendo
                     */
                     
int   caracter;            /*   Contiene el caracter del mensaje POCSAG
                        que se esta recibiendo
                        
                     */
                     
int   bit_caracter;         /*   Contiene el numero de bit del caracter
                        del mensaje POCSAG que se esta recibiendo
                     */

int   ciclo_paralizacion;      /*   Bandera que indica si el ciclo de
                        paralizacion esta activo
                     */

int   num_beeps;            /*   Numero de beeps para beep_offline() */

int   delay_beep;            /*   Retardo en mS entre beeps para beep_offline() */

int   delay_beep_buzzer;      /*   Retardo en mS entre beeps buzzer */

int   num_beeps_buzzer;      /*   Numero de beeps buzzer */


/* Arreglos para manejo de secuencias */

int      sec_flag[3];      // Indica secuencia activa
long   sec_cont[3];      // Contador del periodo activo
int      sec_edo[3];         // Estado de la salida
int      sec_cont_activo[3];   // Indica contador de periodo activo
long   sec_periodo_1[3];   // Valor periodo 1
long   sec_periodo_2[3];   // Valor periodo 2
long   sec_num_tran[3];   // Numero de transiciones de la secuencia

int buffer_ibutton[4];      /* Esta declaracion genera error int buffer_ibutton[8]; */

                     /* A partir de [6] inclusive se genera el error */



#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL, FAST, RESTART_WDT)

void init_ext_eeprom(void) {
   
   output_float(eeprom_scl);
   output_float(eeprom_sda);
   
} /* void init_ext_eeprom(void) */

void write_ext_eeprom(int16 address, byte data) {

byte cmd;

   cmd = hi(address);
   cmd >>= 4;
   cmd &= 0xFE;
   cmd |= 0xa0;
   
   i2c_start();
   i2c_write(cmd);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   
} /* end void write_ext_eeprom(int16 address, byte data) */


byte read_ext_eeprom(long int address) {

byte data, cmd;

   if (address < EEPROM_SIZE) {
      
      cmd = hi(address);
      cmd >>= 4;
      cmd &= 0xFE;
      cmd |= 0xa0;

      i2c_start();
      i2c_write(cmd);
      i2c_write(hi(address));
      i2c_write(address);
      i2c_start();

      cmd |= 0x01;

      i2c_write(cmd);
      data=i2c_read(0);
      i2c_stop();

   } /* end    if (address < EEPROM_SIZE) */

   return(data);

} /* end byte read_ext_eeprom(long int address) */






void diagnostico(void) {

int32 serie;
int  buff[11],error, lectura;
int16 cont;

   disable_interrupts(GLOBAL);
   
   for (cont=0; cont<10; cont++) {
   
      write_ext_eeprom(cont,lo(cont));
      
      restart_wdt();

   } /* end for (cont=0; cont<10; cont++) */
   
   error = 0x00;

   for (cont=0; cont<10; cont++) {
   
      lectura = read_ext_eeprom(cont);
   
      if (lectura != lo(cont)) {
      
         error = 0xFF;
         
         break;
         
      }
      
      restart_wdt();
      
   } /* end for (cont=0; cont<10; cont++) */
   
   
   for (cont=0; cont<16384; cont++) {
   
      write_ext_eeprom(cont,0xFF);
      restart_wdt();

   } /* end for (cont=0; cont<16384; cont++) */

   while(1) {
   
      if (error) {
      
         output_low(LED_STATUS);
         delay_ms(125);
         output_high(LED_STATUS);
         delay_ms(125);
         
         restart_wdt();
         
      }
      
      else {
      
         output_low(LED_STATUS);
         restart_wdt();
         
      } /* end if (error) */

   } /* end while(1) */

} /* end void diagnostico(void) */




void main(void) {

   setup_adc_ports(NO_ANALOGS);

   port_b_pullups(0xFF);
   
   init_ext_eeprom();
         
   /* Para evitar transitorios */
   
   output_low(RELAY_1);
   output_low(RELAY_2);
   output_low(RELAY_3);


   diagnostico();
   
   while(1);

}  /* end void main(void) */
xpercad



Joined: 27 Jun 2004
Posts: 12
Location: MÉXICO

View user's profile Send private message

3.204 & 3.205 Bug (part 3)
PostPosted: Mon Jul 12, 2004 11:20 am     Reply with quote

Code:

/* NOK.C */

#include <18f252.h>

#use delay(clock=40000000, RESTART_WDT)

#priority EXT,TIMER0


#fuses H4,PROTECT,NOOSCSEN,BROWNOUT,WDT128,WDT,BORV45,PUT,CCP2C1,STVREN,NODEBUG,NOLVP,WRT,NOWRTD,WRTB,WRTC,CPD,CPB,EBTR,EBTRB

//#ORG 0x1F00,0x1FFF {}

#define VERSION         "3"
#define DIAG         1

#include <stdlib.h>

/* MACROS */

#define hi(x)  (*(&x+1))
#define lo(x)  (*(&x))


// Bus I2C (FRAM)
#define EEPROM_SCL     PIN_A3
#define EEPROM_SDA     PIN_A2

// Leds
#define LED_STATUS      PIN_C0

// Salidas binarias
#define RELAY_1         PIN_B2
#define RELAY_2         PIN_B3
#define RELAY_3         PIN_A5

/* Tamano memoria FRAM externa */
#define EEPROM_SIZE    16384

/* DIMENSIONES ESTRUCTURAS DE DATOS */

/* Tamano del buffer en RAM para Rx de mensajes */
#define SIZE_RAM_RX         768

/* maximo numero de cadenas predefinidas */
#define MAX_CADENAS         64

/* maximo numero de paquetes en un mensaje compuesto */
#define MAX_PTRS_PCKTS      64


/* ESTRUCTURAS Y VARIABLES GLOBALES */

/* estructura para manejo de paquetes recibidos */

typedef struct {
   
   unsigned int n_pckt;   /* Numero de Paquete */
   unsigned int pos;      /* Posicion de llegada */

} PCKT;

PCKT ptrs_pckt[MAX_PTRS_PCKTS];   /*   Arreglo de apuntadores a apuntadores de paquetes
                           recibidos en mensajes compuestos */

int   opc_rs232;            /*   Indica si la opcion RS232 esta instalada */

int   opc_switch;            /*   Indica si la opcion SWITCH esta instalada */

int   opc_ibtn;            /*   Indica si la opcion iBUTTON esta instalada */

int   opc_buzzer;            /*   Indica si la opcion BUZZER esta instalada */

int lst_sencillo_id[6];      /* Identificador del ultimo mensaje sencillo recibido */

int lst_compuesto_id[6];   /* Identificador del ultimo mensaje compuesto recibido */

int bitmap_rx[8];         /* Bit map de paquetes recibidos (64 bits) */

int pckts_rx;            /* Numero de paquetes recibidos (mensajes compuestos) */

int tot_pckts_rx;         /* Numero de total de paquetes a recibir (mensajes compuestos) */

int n_pckt;               /* Indicador de numero de paquete activo p/rd_pckts.c */

long dir_n_pckt;         /* Siguiente direccion a leer p/rd_pckts.c */

long n_bytes_leidos;      /* Numero de bytes leidos del paquete activo p/rd_pckts.c */

long int pckt_size;       /* Tamano del paquete activo p/rd_pckts.c */

long ptr_fram_rx_w;         /* Apuntador para escrituras en buffer FRAM_RX */

long int lst_fram_address;   /* Ultima localidad en FRAM accesada por R/W sequenciales */

int fram_status;         /* Estado FRAM

                        0: Cerrada
                        1: Abierta p/Lectura Sequencial
                        2: Abierta p/Escritura Sequencial
                     */

int hi_nibble_address;      /* Nibble alto del ultimo banco de FRAM accesado por R/W sequenciales */

long int ptr_nxt_cadena;   /* Apuntador a direccion disponible para carga de CADENAS */

int   aplicacion;            /* indica si la aplicacion es AUOMOTRIZ o CONTROL_REMOTO */

int rx_en_proceso;         /*   Bandera que indica si hay
                        recepcion POCSAG en proceso
                     */
                     
int   rx_decoder[4];         /*   Buffer para depositar los 4
                        bytes que se leen del POCSAG Decoder
                     */
                     
int capcode_rx;            /*   CAPCODE logico (0..7) en el que
                        se esta recibiendo mensaje POCSAG
                     */
                     
int fbits_rx;            /*   Function Bits del mensaje POCSAG
                        que se esta recibiendo
                     */
                     
int   func_rx;            /*   Funcion (1: Alfa  0: Numerico) que corresponde
                        al CAPCODE y Function Bits del mensaje
                        POCSAG que se esta recibiendo
                     */
                     
int   caracter;            /*   Contiene el caracter del mensaje POCSAG
                        que se esta recibiendo
                        
                     */
                     
int   bit_caracter;         /*   Contiene el numero de bit del caracter
                        del mensaje POCSAG que se esta recibiendo
                     */

int   ciclo_paralizacion;      /*   Bandera que indica si el ciclo de
                        paralizacion esta activo
                     */

int   num_beeps;            /*   Numero de beeps para beep_offline() */

int   delay_beep;            /*   Retardo en mS entre beeps para beep_offline() */

int   delay_beep_buzzer;      /*   Retardo en mS entre beeps buzzer */

int   num_beeps_buzzer;      /*   Numero de beeps buzzer */


/* Arreglos para manejo de secuencias */

int      sec_flag[3];      // Indica secuencia activa
long   sec_cont[3];      // Contador del periodo activo
int      sec_edo[3];         // Estado de la salida
int      sec_cont_activo[3];   // Indica contador de periodo activo
long   sec_periodo_1[3];   // Valor periodo 1
long   sec_periodo_2[3];   // Valor periodo 2
long   sec_num_tran[3];   // Numero de transiciones de la secuencia

int buffer_ibutton[8];      /* Esta declaracion genera error int buffer_ibutton[8]; */

                     /* A partir de [6] inclusive se genera el error */



#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL, FAST, RESTART_WDT)

void init_ext_eeprom(void) {
   
   output_float(eeprom_scl);
   output_float(eeprom_sda);
   
} /* void init_ext_eeprom(void) */

void write_ext_eeprom(int16 address, byte data) {

byte cmd;

   cmd = hi(address);
   cmd >>= 4;
   cmd &= 0xFE;
   cmd |= 0xa0;
   
   i2c_start();
   i2c_write(cmd);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   
} /* end void write_ext_eeprom(int16 address, byte data) */


byte read_ext_eeprom(long int address) {

byte data, cmd;

   if (address < EEPROM_SIZE) {
      
      cmd = hi(address);
      cmd >>= 4;
      cmd &= 0xFE;
      cmd |= 0xa0;

      i2c_start();
      i2c_write(cmd);
      i2c_write(hi(address));
      i2c_write(address);
      i2c_start();

      cmd |= 0x01;

      i2c_write(cmd);
      data=i2c_read(0);
      i2c_stop();

   } /* end    if (address < EEPROM_SIZE) */

   return(data);

} /* end byte read_ext_eeprom(long int address) */






void diagnostico(void) {

int32 serie;
int  buff[11],error, lectura;
int16 cont;

   disable_interrupts(GLOBAL);
   
   for (cont=0; cont<10; cont++) {
   
      write_ext_eeprom(cont,lo(cont));
      
      restart_wdt();

   } /* end for (cont=0; cont<10; cont++) */
   
   error = 0x00;

   for (cont=0; cont<10; cont++) {
   
      lectura = read_ext_eeprom(cont);
   
      if (lectura != lo(cont)) {
      
         error = 0xFF;
         
         break;
         
      }
      
      restart_wdt();
      
   } /* end for (cont=0; cont<10; cont++) */
   
   
   for (cont=0; cont<16384; cont++) {
   
      write_ext_eeprom(cont,0xFF);
      restart_wdt();

   } /* end for (cont=0; cont<16384; cont++) */

   while(1) {
   
      if (error) {
      
         output_low(LED_STATUS);
         delay_ms(125);
         output_high(LED_STATUS);
         delay_ms(125);
         
         restart_wdt();
         
      }
      
      else {
      
         output_low(LED_STATUS);
         restart_wdt();
         
      } /* end if (error) */

   } /* end while(1) */

} /* end void diagnostico(void) */




void main(void) {

   setup_adc_ports(NO_ANALOGS);

   port_b_pullups(0xFF);
   
   init_ext_eeprom();
         
   /* Para evitar transitorios */
   
   output_low(RELAY_1);
   output_low(RELAY_2);
   output_low(RELAY_3);


   diagnostico();
   
   while(1);

}  /* end void main(void) */

valemike
Guest







PostPosted: Mon Jul 12, 2004 11:21 am     Reply with quote

I am also using a PIC18F252 in one of my projects.

Using PCHW 3.187, all was fine, and my generated .hex file was at around 85%. When I tried using 3.202, I saw the generated code go down to 35% (?). My first thought was, "Wow! Pretty good."
Then when I tried running it, nothing worked.

So I rewinded back to 3.187 and it worked again. I haven't tried 3.204 on it, but I do know that 3.204 works fine for my 16F projects.

When my once-working code stops working for one reason or another, i usually make it a personal habit to rewind to a previous compiler version rather than pulling out my hair trying to inspect the code.
xpercad



Joined: 27 Jun 2004
Posts: 12
Location: MÉXICO

View user's profile Send private message

PostPosted: Mon Jul 12, 2004 11:34 am     Reply with quote

Thanks for your comments valemike !!!

Unfortunately, I can not go back to 3.180. The generated code won't fit in the PIC18F252 !!!

With the code generated by 3.205 I still have 12% of ROM to spare; bad news is it doesn't work.

Regards,

Aaron
C-H Wu
Guest







3.205 bug with pointer ? BSR bug again ! ? ?
PostPosted: Mon Jul 12, 2004 8:42 pm     Reply with quote

I compiled your code and found something strange, to make it short, here is my simple suggestion:

1. instead of using hi(x), try simpler code (int8)(x>>8)
2. instead of using lo(x), try simpler code (int8)(x)

The resulting code is not only shorter, but also more robust, i.e. less bug.

Best wishes

C-H Wu
-----------------
Here is the long story,

Regarding your NOK.c, here are some listing

Code:
0000                01930 .................... void write_ext_eeprom(int16 address, byte data)
0000                01931 .................... {
0000                01932 ....................    byte cmd;
0000                01933 ....................    cmd = hi(address);
0080 0E01           01934 MOVLW  01
0082 CFE8 FFEA      01935 MOVFF  FE8,FEA
0086 0E02           01936 MOVLW  02
0088 6EE9           01937 MOVWF  FE9
008A CFEF F104      01938 MOVFF  FEF,104
0000                01939 ....................
0000                01940 ....................    cmd >>= 4;
008E 3B04           01941 SWAPF  x04,F <--- BSR is '1' or '0' ????
0090 0E0F           01942 MOVLW  0F
0092 1704           01943 ANDWF  x04,F
0000                01944 ....................    cmd &= 0xFE;
0094 9104           01945 BCF    x04.0

the BSR (Bank Select Register) setting is missing ! the variable 'cmd' is located at 0x104, however, BSR was set to 0 before calling write_ext_eeprom, as a result, the instruction cmd >>=4 did not work on 0x104 but actually work on 0x04 ! this is the BUG !
Code:
0000                02201 ....................       write_ext_eeprom(cont,0xFF);
02B6 C0FF F102      02202 MOVFF  FF,102
02BA C0FE F101      02203 MOVFF  FE,101
02BE 0EFF           02204 MOVLW  FF
02C0 0101           02205 MOVLB  1
02C2 6F03           02206 MOVWF  x03
02C4 0100           02207 MOVLB  0  <-- set BSR to 0 before calling write_ext_eeprom
02C6 DEDC           02208 RCALL  0080
0000                02209 ....................       restart_wdt();


Let's workaround the bug by using ... cmd = (int8)(address>>8);
now, everything is fine ! Razz and the code is shorter than pointer operation Very Happy
Code:
0000                01930 .................... void write_ext_eeprom(int16 address, byte data)
0000                01931 .................... {
0000                01932 ....................    byte cmd;
0000                01933 .................... // cmd = hi(address);
0000                01934 ....................    cmd = (int8)(address>>8);
0080 0101           01935 MOVLB  1 <--- set BSR to '1'
0082 5102           01936 MOVF   x02,W
0084 6A03           01937 CLRF   03
0086 6F04           01938 MOVWF  x04
0000                01939 ....................    cmd >>= 4;
0088 3B04           01940 SWAPF  x04,F
008A 0E0F           01941 MOVLW  0F
008C 1704           01942 ANDWF  x04,F
0000                01943 ....................    cmd &= 0xFE;
008E 9104           01944 BCF    x04.0


The reason why setting buffer_ibutton[8] crash the code while int buffer_ibutton[4] works fine can be found from the .SYM file, with buffer_ibutton[8], write_ext_eeprom.cmd is located at 0x104, which will require BSR switching,
Code:
104     @I2C_READ_1_31747_31746_40000000.P1
104     write_ext_eeprom.cmd
104     read_ext_eeprom.@SCRATCH


with buffer_ibutton[2], write_ext_eeprom.cmd is located at 0xFE, which will _NOT_ require BSR switching,
Code:
0FD     read_ext_eeprom.cmd
0FE     @I2C_READ_1_31747_31746_40000000.P1
0FE     write_ext_eeprom.cmd
0FE     read_ext_eeprom.@SCRATCH


The button line is, keep your code simple, don't use pointer unless you really need it.

Best wishes

C-H Wu
C-H Wu
Guest







3.205 Bug report ... BSR with pointer operation ...
PostPosted: Mon Jul 12, 2004 10:26 pm     Reply with quote

To whom it may concern:

The following code is a simplified version base on xpercad's code,
this program demonstrate BSR setting is missing in case of mixed pointer operation ...

Code:
// bug_3205_BSR_pointer     by C-H Wu         2004/07/13
//
#include <18F458.H>
#fuses HS, PUT, NOLVP, NODEBUG

#use delay ( clock = 20000000 )
#use rs232 ( baud  = 115200, xmit=PIN_C6, rcv=PIN_C7 )

#define  hi(x)  (*(&x+1))

#reserve 0x08 : 0xf0          // This line bring out the BSR BUG !

int16    x_int16[4];   
int8     x_int8 [8];   

void buggy(int16 address, int8 data)
{
   int8  cmd, tmp;

// cmd = (int8)(address>>8);  // no bug if using this simple code to ...
                              // replace the following ... cmd = hi(...)   
   cmd = hi(address);         
   
   tmp = cmd << 4;            // BUG! if BSR change is required
                              // BSR setting is missing, due to ...
                              // the pointer operation in ... cmd = hi(...)

   printf("address= 0x%04LX, cmd= 0x%02LX, tmp= 0x%02X\r\n",address,cmd,tmp);
}

void main(void)
{
   int16 addr = 0x0123;
   int8  val  = 0x45;

   printf("\r\n\nBSR bug hunter . . \r\n");

   x_int16[0] = 0x6789;
     
   buggy ( x_int16[0], val );
   buggy ( addr, val );       
   
   while(1);


the result of the instruction tmp = cmd << 4; is _NOT_ correct, variable 'tmp' remain unchanged. Evil or Very Mad

Code:
0000                00464 .................... void buggy(int16 address, int8 data)
0000                00465 .................... {
0000                00466 ....................    int8  cmd, tmp;
0000                00467 ....................
0000                00468 .................... // cmd = (int8)(address>>8);  // no bug if using this simple code to ...
0000                00469 ....................                               // replace the following ... cmd = hi(...)
0000                00470 ....................    cmd = hi(address);
00B6 0E01           00471 MOVLW  01
00B8 CFE8 FFEA      00472 MOVFF  FE8,FEA
00BC 0E05           00473 MOVLW  05
00BE 6EE9           00474 MOVWF  FE9
00C0 CFEF F107      00475 MOVFF  FEF,107
0000                00476 ....................
0000                00477 ....................    tmp = cmd << 4;            // BUG! if BSR change is required
00C4 3907           00478 SWAPF  x07,W  <-- BSR change is missing !
00C6 6F08           00479 MOVWF  x08
00C8 0EF0           00480 MOVLW  F0
00CA 1708           00481 ANDWF  x08,F
0000                00482 ....................                               // BSR setting is missing, due to ...
0000                00483 ....................                               // the pointer operation in ... cmd = hi(...)
0000                00484 ....................
0000                00485 ....................    printf("address= 0x%04LX, cmd= 0x%02LX, tmp= 0x%02X\r\n",address,cmd,tmp);

Comment: in case of frequent RAM bank selection and switching is required, say, heavy RAM usage, using simple code like cmd = (int8)(address>>8); instead of pointer operation cmd = *(&address+1); avoid this kind of tricky bug.

Best wishes

C-H Wu

p.s. I will e-mail CCS to report this bug later and wait for 3.206
C-H Wu
Guest







Re: 3.205 Bug
PostPosted: Mon Jul 12, 2004 10:42 pm     Reply with quote

lower optimization level, #opt 8, with PCH 3.205, does not have this bug.

it is related to level 9, #opt 9, the default optimization level.

Someone said long long time ago, whenever you see 'optimization improved' in CCS's current version information page, then, be prepared, there will be a line 'optimization bug fixed' coming out later. Cool

Best wishes

C-H Wu
C-H Wu
Guest







To xpercad: 3.187 vs. 3.205
PostPosted: Mon Jul 12, 2004 11:51 pm     Reply with quote

Hi, xpercad:

PCWH 3.187 with #opt 10, the beta optimization, does not have this bug.

3.188 ~ 3.205, including the base line version 3.191 for download, have a lot of this kind BSR bugs.

PCWH 3.187 with #opt 10 wight reduce code space to the level you need, roughly 10 ~ 15% reduction compared with 3.180.

Best wishes

C-H Wu

By the way, thanks for your sample code, I decided to go back to 3.187 + #opt 10 instead of 3.205.
Guest








what bug have you found...
PostPosted: Mon Jul 12, 2004 11:53 pm     Reply with quote

We cannot spend hours reading 100's of lines of code.

Give us 5 lines of C code and the LST showing the bug...
C-H Wu
Guest







Re: what bug have you found...
PostPosted: Tue Jul 13, 2004 12:04 am     Reply with quote

Hi, Guest:

bug identified, however, 5 lines of code can not demo the bug.

please read and/or run my demo code in my previous post "3.205 Bug report ... BSR with pointer operation ... ", I hope 50 lines is too much.

I am grateful to his finding and post regarding this BSR bug.

C-H Wu
Guest








Re: what bug have you found...
PostPosted: Tue Jul 13, 2004 7:12 am     Reply with quote

C-H Wu wrote:
Hi, Guest:

bug identified, however, 5 lines of code can not demo the bug.

please read and/or run my demo code in my previous post "3.205 Bug report ... BSR with pointer operation ... ", I hope 50 lines is too much.

I am grateful to his finding and post regarding this BSR bug.

C-H Wu

I started to scrol down and gave up.....Thanks for condensing this..

The big question : HAS IT BEEN REPORTED TO CCS ?
Guest








PostPosted: Tue Jul 13, 2004 7:34 am     Reply with quote

Hi C-H Wu,

I can't thank you enough for your time and interest !!!

I reported the bug to CCS yesterday and the reply was:

This message is a reply to CCS e-mail id: 4G2360

I did not spot any problem differences in the code.

Try #opt 5 and see if that makes it start working.

You could also try changing your macros to this:

#define hi(x) (x>>8)
#define lo(x) (x&0xff)

Let me know if either corrects your problem.


I did make the changes and the program worked with either of them or with both. But I surely remained very hesitant because not knowing what exactly the problem was, makes me think I might run into trouble somewhere else in the code. With the insight you have provided I can now feel better.

Using #opt 5 does not work for me because my application will not fit, so I am using the other trick.

Just to wrap things up, I was aware of the pointer complication of using the macros:

#define hi(x) (*(&x+1))
#define lo(x) (*(&x))

the benefit is that you can use them either on the left or right side of an expression indiferently.

Best Wishes and once again Thank You
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group