|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
Porting WizPro to CCS |
Posted: Wed Mar 31, 2021 11:17 am |
|
|
One of the first snags you will hit when porting the WizPro ethernet code over to CCS is how they pass in function pointers. The code works fine on a standard C compiler, but not with the CCS architecture and you get a "Param#1" error like this:
Quote: | *** Error 29 "\PIC\FnPtrTest\FnPtrTest.c" Line 8(26,27): Function definition different from previous definition test_function Param#1 |
In case it helps others, here is a very simple example showing how to make it work with a minor change to their code (see original commented out).
NOTE: Since I am using typedef to make an UPPERCASE version of what would be their function name, you MUST have "#case" in your project else it will fail due to being non-case sensative.
Code: | #include <24FJ128GA006.h>
#device ICSP=1
#use delay(crystal=20000000)
#FUSES NOWDT //No Watch Dog Timer
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#case
|
Code: |
#include <FnPtrTest.h>
// Function pointer defines.
typedef void (*CRS_EN)(void);
typedef void (*CRS_EX)(void);
// Prototypes
// Old
//void test_function ( void(*crs_en)(void), void(*crs_ex)(void) );
// New
void test_function (CRS_EN crs_en, CRS_EX crs_ex);
void crs_en (void);
void crs_ex (void);
// Functions
void crs_en (void)
{
// Some function
}
void crs_ex (void)
{
// Some other function
}
//void test_function ( void(*crs_en)(void), void(*crs_ex)(void) )
void test_function (CRS_EN crs_en, CRS_EX crs_ex)
{
crs_en ();
crs_ex ();
}
void main()
{
test_function (crs_en, crs_ex);
while(TRUE)
{
//TODO: User Code
}
} |
It's not a pretty example, but hopefully gives someone else a quick start. Basically, instead of:
void test_function ( void(*crs_en)(void), void(*crs_ex)(void) );
...which will not compile, you make a typedef for each function (technically you just need one for each "type" based on the params and return type, but making a separate one makes the code read cleaner). I chose the same name but in UPPERCASE:
typedef void (*CRS_EN)(void);
typedef void (*CRS_EX)(void);
...and then change the function from the original with the fPtr inside the params to use the typedef:
void test_function (CRS_EN crs_en, CRS_EX crs_ex);
Good luck! _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Apr 16, 2021 9:33 am |
|
|
We completed our Wizpro I/O library port to CCS, and above were really the main changes to their code we needed to make.
Beyond that, it was just setting up the function to do slave select toggle, and wrappers for the SPI I/O.
We are not using the calls that pass in functions as parameters -- instead, just adding them to a config table so they are there on startup.
We have made it Common code so we only make small mods to one file that then includes the rest, and we are using it on two different PIC24 boards right now. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
|
|
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
|