|
|
View previous topic :: View next topic |
Author |
Message |
katmani1
Joined: 26 Nov 2015 Posts: 8
|
typedef void (* ble_cmd_handler) (const void *); |
Posted: Thu Nov 26, 2015 7:16 am |
|
|
Hello Frients
I use the module BLE112. I want to connect it to the PIC18F46J50. Through BGLIB API for RS232. By using the compiler CCS C PIC Compiler 5.049.
When you compile error is issued in the following line:
typedef void (* ble_cmd_handler) (const void *);
The compiler refuses to understand it.
"Expecting an identifier"
"Expecting a declaration"
What can be done to use BGLIB API and the CCS C PIC Compiler 5.049?
I did the test program, and it gives the compiler error:
newmain22.c:
Code: |
#include <18F46J50.h>
typedef void (*ble_cmd_handler)(const void*);
void main(void) {
int a, b, c;
a=2;
b=2;
c=a+b;
}
|
"C:\Alex\PROGRAMS\PICC5049\CCSCON.exe" out="build/default/production" newmain22.c +FH +DF +CC +Y=9 +EA +DF +LN +T +A +M +J +EA +Z -P #__18F46J50=1
C:\Alex\MPLAB_PRJ_PCC\test_struct\test_struct.X\newmain22.c:3:59: Error#28 Expecting an identifier
C:\Alex\MPLAB_PRJ_PCC\test_struct\test_struct.X\newmain22.c:3:64: Error#43 Expecting a declaration
C:\Alex\MPLAB_PRJ_PCC\test_struct\test_struct.X\newmain22.c:3:65: Error#43 Expecting a declaration
3 Errors, 0 Warnings.
Build Failed. |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Nov 26, 2015 8:03 am |
|
|
Its a function pointer definiton. The problem, in your test program, is that ble_cmd_handler has not already been defined. The parameter is a pointer, but a pointer to what? Or more to the point, its a function pointer, probably, but a fucntion with what return type? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19492
|
|
Posted: Thu Nov 26, 2015 8:18 am |
|
|
Also get rid of the const. Or select ANSI.
By default in CCS, a 'const', is a ROM type to which a pointer can't be constructed. In ANSI C, a const is a variable in RAM, that is protected (if the hardware has such protection), against being modified. If ANSI is selected CCS attempts to switch the definition (but personally it is safer just to get rid of const). So:
Code: |
#include <18F2620.h>
#device ANSI //switch const meaning
#device ADC=10
#use delay(crystal=20000000)
typedef int32 ble_cmd_handler; //define ble_cmd_handler
//obviously the real definition will have to be what is needed
typedef void (*ble_cmd_handler)(const void*);
void main()
{
while(TRUE)
{
//TODO: User Code
}
}
|
|
|
|
katmani1
Joined: 26 Nov 2015 Posts: 8
|
|
Posted: Thu Nov 26, 2015 8:44 am |
|
|
Thank you!
this line is to remove all the errors:
#device ANSI // switch const meaning |
|
|
katmani1
Joined: 26 Nov 2015 Posts: 8
|
|
Posted: Wed Dec 02, 2015 8:59 am |
|
|
The problem did not end with the compiler.
New error: "Error#43 Expecting a declaration"
I minimize the program to select a piece with the error:
Code: |
#include <18F46J50.h>
#device ANSI
#device ADC=10
#use delay(clock=8MHz,crystal=12MHz,USB_FULL)
#pin_select TX2=PIN_D6
#pin_select RX2=PIN_D5
#use rs232(baud=115200,parity=N,UART2,bits=8,stream=PORT1,RECEIVE_BUFFER=16,RTS=PIN_E0,CTS=PIN_E1,RTS_LEVEL=LOW,CTS_LEVEL=LOW,TIMEOUT=5)
//--------------------------------
#define uint8 unsigned char
#define uint16 unsigned long
#define uint32 unsigned long long
enum ble_dev_types { ble_dev_type_ble=0x00 };
enum ble_msg_types { ble_msg_type_cmd=0x00 };
enum ble_classes { ble_cls_system };
enum ble_command_ids { ble_cmd_system_reset_id=0, ble_cmd_system_hello_id=1 };
typedef void (*ble_cmd_handler)(const void*);
void ble_default(const void*);
struct ble_header
{
uint8 type_hilen;
uint8 lolen;
uint8 cls;
uint8 command;
};
struct ble_msg
{
struct ble_header hdr;
uint32 params;
ble_cmd_handler handler;
};
static const struct ble_msg apis[]={
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_cmd|0x0,0x1,ble_cls_system,ble_cmd_system_reset_id}, 0x2,(ble_cmd_handler)ble_default},
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_cmd|0x0,0x0,ble_cls_system,ble_cmd_system_hello_id}, 0x0,(ble_cmd_handler)ble_default},
{{0,0,0,0}, 0, 0}};
//--------------------------------
void main(void) {
while(1)
{
}
} |
The compiler Microchip XC8 v1.35, the compilation is successful.
Why do these errors occur when using CCS C Pic Compiler 5.049?
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Wed Dec 02, 2015 9:06 am |
|
|
OK, maybe I can't see it BUT where is' PLLEN' that the first error reports on in the program you've posted?? |
|
|
katmani1
Joined: 26 Nov 2015 Posts: 8
|
|
Posted: Wed Dec 02, 2015 9:40 am |
|
|
temtronic wrote: | OK, maybe I can't see it BUT where is' PLLEN' that the first error reports on in the program you've posted?? |
Error PLLEN also in line 38.
I do not understand where does PLLEN. And why the error invalid type conversion. |
|
|
katmani1
Joined: 26 Nov 2015 Posts: 8
|
|
Posted: Thu Dec 03, 2015 5:02 am |
|
|
I use standart bluegiga bluetooth smart bglib-API for module BLE112.
This is a problem in CCS C PIC Compiler? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Dec 03, 2015 6:41 am |
|
|
The error is being thrown at the cast. The reference to PLLEN appears to be some kind of default thing in the compiler, "PLLEN" has nothing to do with it.
There's acually no reason to cast it. Instead of "(ble_cmd_handler) ble_default", "&ble_default" (my preference) or simply "ble_default" is perfectly acceptable syntax. Indeed with either of these your example compiles. The compiler warns that ble_default is not called (it isn't of course, merely pointed to) and that apis is not used, but that's okay. |
|
|
katmani1
Joined: 26 Nov 2015 Posts: 8
|
|
Posted: Fri Dec 04, 2015 2:16 am |
|
|
RF_Developer wrote: | ".... &ble_default..... " |
It helped, but not everywhere :(
Code: |
#include <18F46J50.h>
#device ANSI
#device ADC=10
#use delay(clock=8MHz,crystal=12MHz,USB_FULL)
#pin_select TX2=PIN_D6
#pin_select RX2=PIN_D5
#use rs232(baud=115200,parity=N,UART2,bits=8,stream=PORT1,RECEIVE_BUFFER=16,RTS=PIN_E0,CTS=PIN_E1,RTS_LEVEL=LOW,CTS_LEVEL=LOW,TIMEOUT=5)
//--------------------------------
#define uint8 unsigned char
#define uint16 unsigned long
#define uint32 unsigned long long
enum ble_dev_types { ble_dev_type_ble=0x00 };
enum ble_msg_types { ble_msg_type_cmd=0x00 , ble_msg_type_rsp=0x00 };
enum ble_classes { ble_cls_system };
enum ble_command_ids { ble_cmd_system_reset_id=0, ble_cmd_system_hello_id=1 , ble_cmd_system_address_get_id=2};
typedef void (*ble_cmd_handler)(const void*);
void ble_default(const void*);
void ble_rsp_system_address_get(const struct ble_msg_system_address_get_rsp_t *msg);
struct ble_header {
uint8 type_hilen;
uint8 lolen;
uint8 cls;
uint8 command;
};
struct ble_msg { struct ble_header hdr; uint32 params; ble_cmd_handler handler; };
static const struct ble_msg apis[]={
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_cmd|0x0,0x1,ble_cls_system,ble_cmd_system_reset_id},0x2,
&ble_default},
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_cmd|0x0,0x0,ble_cls_system,ble_cmd_system_hello_id},0x0,
&ble_default},
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_rsp|0x0,0x6,ble_cls_system,ble_cmd_system_address_get_id},0xa,
&ble_rsp_system_address_get},
{{0,0,0,0}, 0, 0}};
void ble_default(const void*v)
{
}
void ble_rsp_system_address_get(const struct ble_msg_system_address_get_rsp_t *msg)
{
}
//--------------------------------
void main(void) {
while(1){}
}
|
Original Bluegiga BGLIB API string:
Code: |
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_rsp|0x0,0x6,ble_cls_system,ble_cmd_system_address_get_id}, 0xa, (ble_cmd_handler)ble_rsp_system_address_get},
|
|
|
|
katmani1
Joined: 26 Nov 2015 Posts: 8
|
|
Posted: Fri Dec 04, 2015 4:52 am |
|
|
I think more and more that this is a problem in the CCS C PIC Compiler.
It is interesting to developers CCS C PIC Compiler reading this forum? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19492
|
|
Posted: Fri Dec 04, 2015 5:10 am |
|
|
Not really.
The point is that you are trying to use code written for another compiler.
Now no two compilers are ever 'the same'. They can be very similar, and the core parts of a language can be the same, but they will all have individual differences. These need to be adjusted to by the programmer....
With the ANSI option, CCS attempts to pretty closely accept ANSI C99 code. However C99, not the later ANSI variants. Even at C99, it still has some small differences. However as an example, I recently ported about 10000 lines of Microchip code into CCS, and once I had done the defines, only had to tweak some data definitions, the initialisation, and the syntax of a few of the specific I/O functions. Probably less than 10% of the lines.
The point is that you do have to rewrite the code to suit the compiler. This is true even on mainstream compiler (try moving some Linux C to Microsoft sometime). You cannto just take code and plug it into any compiler without learning the specific features of the compiler.
CCS has some very specific differences, that actually allow it to optimise better to the chip than many of the other compilers, but the programmer has to adjust to these.
If you want to use CCS C, _you_ have to actually try to learn the language, rather than expecting to plug code straight in. What the code is doing, is what you should be looking at, and whether there is a different way that this should be done in CCS.
CCS, is CCS C, not any other C. It actually keeps remarkably closely to the original K&R definitions. Out of every code line in the original first edition K&R, I can't think of any that cannot be made to work pretty much 'as is' in CCS C. |
|
|
katmani1
Joined: 26 Nov 2015 Posts: 8
|
|
Posted: Fri Dec 04, 2015 5:23 am |
|
|
CCS C PIC Compiler I really like. Under it it has been written a lot of code.
I will try to further alter the code BGAPI under the CCS C PIC Compiler.
But I do not know how to do it :( |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Fri Dec 04, 2015 6:01 am |
|
|
Two problems with your example code: first, you haven't defined ble_msg_system_address_get_rsp_t, so you get an error at line 16. Second, the parameter type of ble_msg_system_address_get_rsp_t doesn't match const void* and so the compiler throws an error at line 26. Now, this is arguably wrong, as a void pointer should match any other type of pointer - in C terms void* is simply an address and can point to anything. However the CCS C compiler appears to be more picky about the types.
All this stems from the fact that most Cs run on processors with one address space, shared by code and data. The PICs are Harvard architechture, which has different memory spaces for code and for data. That means a function pointer, which is a pointer into code memory, has to be treated very differently to a data pointer, which points into data memory.
CCS C didn't even allow function pointers at all until fairly recently (late in version 4), and there are still restrictions on them. I beleive you can't assign them at run time, they must be resolveable at compile time. The problem in your example is not the function pointer itself, but the parameters to the function. There's another problem with that, and that it that most PICs don't have a data stack (i.e. no pushes or pops), and so the parameter passing mechanism used by most Cs, passing the parameters on the stack, is not possible. This, in turn, restricts the compiler as to how it deals with parameters for functions called via pointers. This may lie at the root of the compiler wanting the types of the parameters to match precisely, which is more associated with the behaviour of C++ or C# than C.
The reason for this may be that with a function pointer, the compiler can't know what routine will actually be called, and therefore where to put the parameters. That means it can deal with function pointers to functions with no parameters okay, but anything else is tricky.
How to solve the problem? I've managed to get it to compile, but I really don't know whether this will work at run time. I've declared ble_msg_system_address_get_rsp_t and changed ble_rsp_system_address_get to take a void pointer and in effect cast it inside the routine to what's required:
Code: | #include <18F46J50.h>
#device ANSI
#device ADC=10
#use delay(clock=8MHz,crystal=12MHz,USB_FULL)
#pin_select TX2=PIN_D6
#pin_select RX2=PIN_D5
#use rs232(baud=115200,parity=N,UART2,bits=8,stream=PORT1,RECEIVE_BUFFER=16,RTS=PIN_E0,CTS=PIN_E1,RTS_LEVEL=LOW,CTS_LEVEL=LOW,TIMEOUT=5)
//--------------------------------
#define uint8 unsigned char
#define uint16 unsigned long
#define uint32 unsigned long long
enum ble_dev_types { ble_dev_type_ble=0x00 };
enum ble_msg_types { ble_msg_type_cmd=0x00 , ble_msg_type_rsp=0x00 };
enum ble_classes { ble_cls_system };
enum ble_command_ids { ble_cmd_system_reset_id=0, ble_cmd_system_hello_id=1 , ble_cmd_system_address_get_id=2};
typedef struct ble_msg_system_address_get_rsp_t {
int Whatever;
}ble_msg_system_address_get_rsp_t;
typedef void (*ble_cmd_handler)(const void*);
void ble_default(const void*);
//void ble_rsp_system_address_get(const struct ble_msg_system_address_get_rsp_t *msg);
void ble_rsp_system_address_get(const void*);
struct ble_header {
uint8 type_hilen;
uint8 lolen;
uint8 cls;
uint8 command;
};
struct ble_msg { struct ble_header hdr; uint32 params; ble_cmd_handler handler; };
static const struct ble_msg apis[]={
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_cmd|0x0,0x1,ble_cls_system,ble_cmd_system_reset_id},0x2,
&ble_default},
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_cmd|0x0,0x0,ble_cls_system,ble_cmd_system_hello_id},0x0,
&ble_default},
{{(uint8)ble_dev_type_ble|(uint8)ble_msg_type_rsp|0x0,0x6,ble_cls_system,ble_cmd_system_address_get_id},0xa,
&ble_rsp_system_address_get},
{{0,0,0,0}, 0, 0}};
void ble_default(const void*)
{
}
//void ble_rsp_system_address_get(const struct ble_msg_system_address_get_rsp_t *msg)
void ble_rsp_system_address_get(const void* v)
{
// assign the void pointer - an address, to something we can use.
struct ble_msg_system_address_get_rsp_t *msg = v;
}
//--------------------------------
void main(void) {
while(1){}
} |
PS: Ttelmah, don't you mean CCS C nearly matches C90, not C99? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19492
|
|
Posted: Fri Dec 04, 2015 9:20 am |
|
|
Oh God. Another decade gone....
|
|
|
|
|
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
|