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

Function Pointer BUG??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
CristianC72
Guest







Function Pointer BUG??
PostPosted: Tue Feb 17, 2009 10:24 am     Reply with quote

I must use function pointer but I have a several problem.
If I make a project with a single module es. 'main.c' all work, if I make a
project with multiple modules function pointer doesn't work.

This is the Working code with single module:
Code:

//MAIN.C
#include "main.h"

void Task1(void)
{
    printf("Start Task 1\r\n");   
}

void Task2(void)
{
    printf("Start Task 2\r\n");   
}

typedef void (*_fptr)(void);

void main(void)
{
    _fptr        fprt[2] = {Task1, Task2};
   

    for (;;)
    {
      (*fprt[0])();
        (*fprt[1])();
        delay_ms(1000);
    }
}


// MAIN.H
#include <18F4685.H>


#FUSES NOWDT                     // No Watch Dog Timer
#FUSES WDT128                    // Watch Dog Timer uses 1:128 Postscale
#FUSES H4                        // High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT                 // Code not protected from reading
#FUSES NOBROWNOUT                // No brownout reset
#FUSES BORV20                    // Brownout reset at 2.0V
#FUSES NOPUT                     // No Power Up Timer
#FUSES NOCPD                     // No EE protection
#FUSES NOSTVREN                    // Stack full/underflow will cause reset
#FUSES NODEBUG                   // No Debug mode for ICD
#FUSES NOLVP                       // Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                     // Program memory not write protected
#FUSES NOWRTD                    // Data EEPROM not write protected
#FUSES IESO                      // Internal External Switch Over mode enabled
#FUSES FCMEN                     // Fail-safe clock monitor enabled
#FUSES NOPBADEN                  // PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                    // configuration not registers write protected
#FUSES NOWRTB                    // Boot block not write protected
#FUSES NOEBTR                    // Memory not protected from table reads
#FUSES NOEBTRB                   // Boot block not protected from table reads
#FUSES NOCPB                     // No Boot Block code protection
#FUSES LPT1OSC                   // Timer1 configured for low-power operation
#FUSES MCLR                      // Master Clear pin enabled
#FUSES NOXINST                   // Extended set extension and Indexed Addressing mode disabled (Legacy mode)


#use delay(clock = 40000000)   
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)



This is the result in the assembler file


Code:

....................     for (;;)
....................     {
....................       (*fprt[0])();
000EE:  CLRF   FEA
000F0:  MOVLW  06
000F2:  MOVWF  FE9
000F4:  RCALL  004C     <----Call function
....................         (*fprt[1])();
000F6:  CLRF   FEA
000F8:  MOVLW  0A
000FA:  MOVWF  FE9
000FC:  RCALL  004C
....................         delay_ms(1000);
000FE:  MOVLW  04
00100:  MOVWF  0E
00102:  MOVLW  FA
00104:  MOVWF  0F
00106:  BRA    0086
00108:  DECFSZ 0E,F
0010A:  BRA    0102
....................     }
0010C:  BRA    00EE
.................... }


If I insert another file and now i compile with 2 module i have this assembler instruction

Code:

....................     for (;;)
....................     {
....................       (*fprt[0])();
000E6:  CLRF   FEA
000E8:  MOVLW  06
000EA:  MOVWF  FE9 <----RCALL MISSED!!!!!!
....................         (*fprt[1])();
00114:  CLRF   FEA
00116:  MOVLW  0A
00118:  MOVWF  FE9
....................         delay_ms(1000);
00140:  MOVLW  04
00142:  MOVWF  0E
00144:  MOVLW  FA
00146:  MOVWF  0F
00148:  BRA    007C
0014A:  DECFSZ 0E,F
0014C:  BRA    0144
....................     }
0014E:  BRA    00E6
.................... }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 17, 2009 1:24 pm     Reply with quote

I don't think CCS officially says that function pointers work. I think they
work unofficially or as "beta". My suggestion is, if they don't work
with Multiple Compilation Units, then just use the "one big source file"
method.
Guest








PostPosted: Wed Feb 18, 2009 3:46 am     Reply with quote

Yes,

I have try this way and work, but I prefer have multiply modules

Txh

Cristian
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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