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 CCS Technical Support

Pointer to Function - Important BUG

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



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

Pointer to Function - Important BUG
PostPosted: Thu Jan 01, 2004 6:36 pm     Reply with quote

I have implemented a function pointer for drive my commands, but I have a big problem the command function that the compiler put in the ROM > 0x010000 (example AM_TMTST), NOT WORK!!!!.
Is possible that when assign the command function to my array of function pointer not understan memory > 0x010000 or ROM page 1 ???.

How to find a solution for this????

Please help me that my project is STOPPED for this.

Thank you very much!!


.................... ////////////////////////////////////////////////////////////////////////////
.................... //
.................... // Funcion: void AM_CmdHandlerInit( void )
.................... //
.................... // Retorna: void
.................... //
.................... // Descripcion: Inicializa el vector de punteros a funciones
.................... //
.................... // Parametros: void
.................... //
.................... ////////////////////////////////////////////////////////////////////////////
.................... void AM_CmdHandlerInit( void )
.................... {
.................... //
.................... // Inicializo array de puntero a funciones
.................... //
.................... //pfCmd = AM_NULL;
.................... pfAMCmd[ 0 ] = AM_CEAP;
*
327E: MOVLW 66
3280: MOVWF 03
3282: MOVLW 9C
3284: MOVLB 5
3286: MOVWF x36
3288: MOVLB 0
328A: MOVFF 03,537
.................... pfAMCmd[ 1 ] = AM_CEAV;
328E: MOVLW 69
3290: MOVWF 03
3292: MOVLW 4C
3294: MOVLB 5
3296: MOVWF x38
3298: MOVLB 0
329A: MOVFF 03,539
.................... pfAMCmd[ 2 ] = AM_CIAP1;
329E: MOVLW 6B
32A0: MOVWF 03
32A2: MOVLW FC
32A4: MOVLB 5
32A6: MOVWF x3A
32A8: MOVLB 0
32AA: MOVFF 03,53B
.................... pfAMCmd[ 3 ] = AM_CIAP2;
32AE: MOVLW 70
32B0: MOVWF 03
32B2: MOVLW 70
32B4: MOVLB 5
32B6: MOVWF x3C
32B8: MOVLB 0
32BA: MOVFF 03,53D
.................... pfAMCmd[ 4 ] = AM_CEAP2;
32BE: MOVLW 8E
32C0: MOVWF 03
32C2: MOVLW E0
32C4: MOVLB 5
32C6: MOVWF x3E
32C8: MOVLB 0
32CA: MOVFF 03,53F
.................... pfAMCmd[ 5 ] = AM_CAT1;
32CE: MOVLW 91
32D0: MOVWF 03
32D2: MOVLW 76
32D4: MOVLB 5
32D6: MOVWF x40
32D8: MOVLB 0
32DA: MOVFF 03,541
.................... pfAMCmd[ 6 ] = AM_CAT2;
32DE: MOVLW 93
32E0: MOVWF 03
32E2: MOVLW 5A
32E4: MOVLB 5
32E6: MOVWF x42
32E8: MOVLB 0
32EA: MOVFF 03,543
.................... pfAMCmd[ 7 ] = AM_CLSE;
32EE: MOVLW 9C
32F0: MOVWF 03
32F2: MOVLW B2
32F4: MOVLB 5
32F6: MOVWF x44
32F8: MOVLB 0
32FA: MOVFF 03,545
.................... pfAMCmd[ 8 ] = AM_CGSE;
32FE: MOVLW 9F
3300: MOVWF 03
3302: MOVLW 5C
3304: MOVLB 5
3306: MOVWF x46
3308: MOVLB 0
330A: MOVFF 03,547
.................... pfAMCmd[ 9 ] = AM_CTT;
330E: MOVLW A5
3310: MOVWF 03
3312: MOVLW 58
3314: MOVLB 5
3316: MOVWF x48
3318: MOVLB 0
331A: MOVFF 03,549
.................... pfAMCmd[ 10 ] = AM_CTT2;
331E: MOVLW A9
3320: MOVWF 03
3322: MOVLW B4
3324: MOVLB 5
3326: MOVWF x4A
3328: MOVLB 0
332A: MOVFF 03,54B
.................... pfAMCmd[ 11 ] = AM_CSTA;
332E: MOVLW C1
3330: MOVWF 03
3332: MOVLW 34
3334: MOVLB 5
3336: MOVWF x4C
3338: MOVLB 0
333A: MOVFF 03,54D
.................... pfAMCmd[ 12 ] = AM_CCME;
333E: MOVLW F0
3340: MOVWF 03
3342: MOVLW 40
3344: MOVLB 5
3346: MOVWF x4E
3348: MOVLB 0
334A: MOVFF 03,54F
.................... pfAMCmd[ 13 ] = AM_TMTST;
334E: MOVLW 0C
3350: MOVWF 03
3352: MOVLW 02
3354: MOVLB 5
3356: MOVWF x50
3358: MOVLB 0
335A: MOVFF 03,551
....................
.................... }
335E: GOTO 4B82 (RETURN)



.................... ////////////////////////////////////////////////////////////////////////////
.................... //
.................... // Funcion: void AM_TMTST( int iPtrAMCmd, char *sData, int16 lDataLen )
.................... //
.................... // Retorna: void
.................... //
.................... // Descripcion: Tarjeta Multivia de Test
.................... //
.................... // Parametros: iPtrAMCmd Puntero a la posicion del array de structura
.................... // *sData Data recibido del mensaje
.................... // iDataLen Largo del Data
.................... //
.................... ////////////////////////////////////////////////////////////////////////////
.................... void AM_TMTST( int iPtrAMCmd, char *sData, int iDataLen )
.................... {
.................... int iOpCode, iPosMapping, iSector, iRet, iPtr, iLenByte;
.................... int iDay, iMonth, iYear;
.................... int16 lAux;
.................... int32 dAux;
.................... char sMSG_Response[ 2 ] = { 0x90, 0x00 };
*
10C02: MOVLW 90
10C04: MOVLB 6
10C06: MOVWF x71
10C08: CLRF x72
.................... char sKeyFF[ 6 ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
10C0A: MOVLW FF
10C0C: MOVWF x73
10C0E: MOVWF x74
10C10: MOVWF x75
10C12: MOVWF x76
10C14: MOVWF x77
10C16: MOVWF x78
.................... char sBufferMF[ MF_BLOCK_DATA_LEN_HEX ];

Code:
PicFan



Joined: 01 Jan 2004
Posts: 11
Location: Indianapolis (Go Colts!)

View user's profile Send private message

Pointer to Function - Important BUG
PostPosted: Thu Jan 01, 2004 10:06 pm     Reply with quote

From the FAQ...

How do I make a pointer to a function?

The compiler does not permit pointers to functions so that the compiler can know at compile time the complete call tree. This is used to allocate memory for full RAM re-use. Functions that could not be in execution at the same time will use the same RAM locations. In addition since there is no data stack in the PIC, function parameters are passed in a special way that requires knowledge at compile time of what function is being called. Calling a function via a pointer will prevent knowing both of these things at compile time. Users sometimes will want function pointers to create a state machine. The following is an example of how to do this without pointers:


enum tasks {taskA, taskB, taskC};

run_task(tasks task_to_run) {

switch(task_to_run) {
case taskA : taskA_main(); break;
case taskB : taskB_main(); break;
case taskC : taskC_main(); break;
}

}


Best Regards,
PicFan
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Fri Jan 02, 2004 12:19 am     Reply with quote

How to assign pointer to function in compile time??

I make this

Code:
//
// Definicion para los punteros a funciones
//
typedef void (*tdCmdFunction) ( int iPtrAMCmd, char *sData, int iDataLen );

static tdCmdFunction pfAMCmd[ AM_CMD_MAX_RECORD ];


and then in the startup call this

Code:

void AM_CmdHandlerInit( void )
{
   //
   // Inicializo array de puntero a funciones
   //
   //pfCmd        = AM_NULL;
   pfAMCmd[  0 ] = AM_CEAP;
   pfAMCmd[  1 ] = AM_CEAV;
   pfAMCmd[  2 ] = AM_CIAP1;
   pfAMCmd[  3 ] = AM_CIAP2;
   pfAMCmd[  4 ] = AM_CEAP2;
   pfAMCmd[  5 ] = AM_CAT1;
   pfAMCmd[  6 ] = AM_CAT2;
   pfAMCmd[  7 ] = AM_CLSE;
   pfAMCmd[  8 ] = AM_CGSE;
   pfAMCmd[  9 ] = AM_CTT;
   pfAMCmd[ 10 ] = AM_CTT2;
   pfAMCmd[ 11 ] = AM_CSTA;
   pfAMCmd[ 12 ] = AM_CCME;
   pfAMCmd[ 13 ] = AM_TMTST;

}


This code work ok, always the address function not >= 0x010000.

You have any idea??
Ttelmah
Guest







Re: Pointer to Function - Important BUG
PostPosted: Fri Jan 02, 2004 3:23 am     Reply with quote

PicFan wrote:
From the FAQ...

How do I make a pointer to a function?

The compiler does not permit pointers to functions so that the compiler can know at compile time the complete call tree. This is used to allocate memory for full RAM re-use. Functions that could not be in execution at the same time will use the same RAM locations. In addition since there is no data stack in the PIC, function parameters are passed in a special way that requires knowledge at compile time of what function is being called. Calling a function via a pointer will prevent knowing both of these things at compile time. Users sometimes will want function pointers to create a state machine. The following is an example of how to do this without pointers:


enum tasks {taskA, taskB, taskC};

run_task(tasks task_to_run) {

switch(task_to_run) {
case taskA : taskA_main(); break;
case taskB : taskB_main(); break;
case taskC : taskC_main(); break;
}

}


Best Regards,
PicFan

Incorrect.
If you look at the 'features now supported' list, the following line appears:
"3.160 Pointers to functions are now supported"

The manual, and comments have not been updated to reflect this change.

The poster has code, correctly showing that the does work, _but_ is seeing problems when the pointer is into the second ROM page. There were similar faults in the past, with the RAM pointers, sometimes returning a variable that was smaller than the size needed for the pointer.
In the past, I found that I could make the RAM pointers work round the similar problem, by manually forcing the use of the larger variable type, with code like:

int32 pointer_store;

pointer_store=(int32)function_name;

It may be that the similar bodge will work in this case.
Generally though, I'd expect that the problem is that the code by default treats all pointers as an int16, and a message to CCS will be necessary.

Best Wishes
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Fri Jan 02, 2004 9:27 am     Reply with quote

That is the problem!!!, not support address > 0x010000 o second ROM page. I make a report to CCS support and wait the answer.
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