Hi All, I am running into problem, where I could not pass sbit variables to a function. Here's an example: My SBIT definitions: sbit OLD_JTAG_TCK = 0xB0+3; sbit NEW_JTAG_TCK = 0x80+7; My Function: void Pulse_TCK(bit sbJTAG_TCK) { sbJTAG_TCK = 1; } My Main code: if (old_hardware) { Pulse_TCK(OLD_JTAG_TCK) } else { Pulse_TCK(NEW_JTAG_TCK) } For some reason, the above code does not work as I dont see any activity on the TCK pins. Can anyone please help me how to resolve this issue?. Note that I had used the type bit in my function parameter instead of sbit as the later gives syntax error.
could not pass sbit variables to a function. That's because sbit objects aren't really variables, in the C sense. They're more like asssembly language "EQU"s, or macros. The Pulse_TCK function is wrong, too, because you've mixed up pass-by-value and pass-by-reference here. Worse yet, this error can't be fixed, because C51 'bit' variables can't be passed by reference at all. The '51 can't support pointers to bits. So to sum it all up, what you're trying can't be done. The closest you could come to it is having a macro that gets the sbit you want to modify passed by name, rather than by reference. For the snippet as shown, the solution is obvious:
if (old_hardware) OLD_JTAG_TCK = 1; else NEW_JTAG_TCK = 1;
For the snippet as shown, the solution is obvious: if (old_hardware) OLD_JTAG_TCK = 1; else NEW_JTAG_TCK = 1; If this is in "a million" places, do as I do, make a macro Erik
My main problem is that IF condition would increase the number of instructions it takes to shift a bit. When the firmware enumerates, I know whether I am in a new hardware or a old hardware and I want to that PIN selection only once during the startup. Having an IF condition for every shift will almost double my time to shift in the entire data. I am talking about a million of bits that gets shifted into the FPGA.
My main problem is that IF condition would increase the number of instructions it takes to shift a bit Not compared to the original code you showed here --- that conditional was already present there. But yes, if speed is a major issue for this routine, you'll want to move this 'if' as far out of the central loops as possible. Possibly as far as having two copies of the entire "shift data into FPGA" function:
if (old_hardware) shift_data_into_FPGA_old_hardware(); else shift_data_into_FPGA_new_hardware();
I tried making entirely 2 different copies of those, but unfortunately they both dont fit into the memory.
If you are extremely tight for memory you may need to do something a little less "pretty" You can make two versions based on a flag
#define NEW_HW // comment this out if compiling for old hardware #ifdef NEW_HW shift_data_into_FPGA_new_hardware(); #else shift_data_into_FPGA_old_hardware(); #endif
they both dont fit into the memory. Well, I did say you "could possibly" go all this far, not that you absolutely should do that. You just found the reason for that caution. If you can't afford two complete copies, you can't move the conditional all this far out of the main loops --- so don't do that. Move it up only to a byte-level or block-level writing routine, or whatever other subdivision size fits your protocol.
#ifdef NEW_HW
My issue is I want to have a single driver that would work for both the hardwares. Having a compiler switch would force me to do 2 different drivers which kind of defeats the whole purpose. On a given system, they can use both the hardwares and we are trying to comeup with a unified driver that would support both.
Take a look at the following knowledgebase article: http://www.keil.com/support/docs/98.htm Jon
Having a compiler switch would force me to do 2 different drivers which kind of defeats the whole purpose agreed, as I said you may need to do something a little less "pretty" I merely mentioned it to show that (unpleasant) possibility. there is somewhat convoluted way to do what you want
My Function: void Pulse_TCK(bit sbJTAG_TCK) { sbJTAG_TCK = 1; } instead void Pulse_TCK(old_hardware) { if (old_hardware) OLD_JTAG_TCK = 1; else NEW_JTAG_TCK = 1; }