HI Bob,
Sounds great!
I have started to cleanup some of my C code. For example moved all of my IO pin handling code into files (iopins.cpp/H), I have taken a first pass in converting all of your functions over to the tables. I also extended the tables, to include another byte per pin, One nibble is used to say if the pin has a pull-up control register associated with it (PUCR) and the lower nibble if it it has a Port Mode register associated with it(PMR). I then change the function input to take an optional parameter fPullup=false that allows the API to set the associated bit in PUCR. There are a couple of cases I have not gotten yet, that is that you can set a pull-up on Bap io in 8, but it is not on the primary pin we normally use. May add some special case code, but right now for example the function input looks like:
Code:
void input (u8 _bpin, bool fPullup)
{
// Lets use our table to do the work for us...
if (_bpin < (sizeof(g_PortTable)/sizeof(PORTITEM)))
{
// Ok lets get the port table item...
PORTITEM pi = g_PortTable[_bpin];
// Make sure it is a valid one...
if (pi.pPDR)
{
// See if there is a PMR register associated with this pin.
if ((pi.bPU_PM) & 0xf)
{
volatile register unsigned char *pPMR = &IO.PMR1.BYTE + (pi.bPU_PM & 0xf) - 1; // get the right PMR register
*pPMR &= ~(pi.bMask);
}
// Next lets update PDR/PCR...
u8 bIOPortIndex = (pi.pPDR - &IO.PDR1.BYTE);
volatile unsigned char *pPCR = &IO.PCR1 + bIOPortIndex;
bap_bpcrshadowregs[bIOPortIndex] &= ~(pi.bMask); // Update shadow mask to say that the pin is now an input pin
*pPCR = bap_bpcrshadowregs[bIOPortIndex];
// Now lets see if we have a PUCR register (pull-up) to update for this pin
if ((pi.bPU_PM) >> 4)
{
volatile register unsigned char *pPUCR = &IO.PUCR1.BYTE + (pi.bPU_PM >> 4) - 1; // get the right PUCR register
if (fPullup)
*pPUCR |= pi.bMask;
else
*pPUCR &= ~(pi.bMask);
}
}
}
}
I also redid the high, low and in functions to use the macros and I added the function toggle, as I do this a lot when I am debugging code.
Code:
void toggle (u8 _bpin)
{
// Lets use our table to do the work for us...
if (_bpin < (sizeof(g_PortTable)/sizeof(PORTITEM)))
{
// Ok lets get the port table item...
PORTITEM pi = g_PortTable[_bpin];
// Make sure it is a valid one...
if (pi.pPDR)
PI_TOGGLE(pi);
}
}
Currently I am playing with the code in hsio.cpp/h to add interrupt support, such that I will able to queue up both input and output data and process them in the background. My queues will probalby start off at 64 bytes each like I think they are in basic. Once I get this up and running I will port over my XBEE support to C...
Let me know if you want me to post up any more details/code before I finish this part (probably a few days).
Kurt