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

I have a question about can_putd() function in pic18xxx8.c

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



Joined: 03 Dec 2008
Posts: 45

View user's profile Send private message

I have a question about can_putd() function in pic18xxx8.c
PostPosted: Thu Apr 23, 2009 3:52 pm     Reply with quote

The question is when it want to set tx mask it use can_set_id(TXRXBaID, id, ext) but TXRXBaID is 0xF64h that is the register RXB0EIDL according
pic18xxx8.h. why it need to set tx mask? what is the use for? Thanks for anybody's help!!!
Code:

int1 can_putd(int32 id, int * data, int len, int priority, int1 ext, int1 rtr) {
   int i;
   int * txd0;
   int port;

   txd0=&TXRXBaD0;

    // find emtpy transmitter
    //map access bank addresses to empty transmitter
   if (!TXB0CON.txreq) {
      CANCON.win=CAN_WIN_TX0;
      port=0;
   }
   else if (!TXB1CON.txreq) {
      CANCON.win=CAN_WIN_TX1;
      port=1;
   }
   else if (!TXB2CON.txreq) {
      CANCON.win=CAN_WIN_TX2;
      port=2;
   }
   else {
      #if CAN_DO_DEBUG
         can_debug("\r\nCAN_PUTD() FAIL: NO OPEN TX BUFFERS\r\n");
      #endif
      return(0);
   }

   //set priority.
   TXBaCON.txpri=priority;

   //set tx mask
   can_set_id(TXRXBaID, id, ext);

   //set tx data count
   TXBaDLC=len;
   TXBaDLC.rtr=rtr;

    for (i=0; i<len; i++) {
      *txd0=*data;
      txd0++;
      data++;
    }

   //enable transmission
   TXBaCON.txreq=1;

   CANCON.win=CAN_WIN_RX0;

   #if CAN_DO_DEBUG
            can_debug("\r\nCAN_PUTD(): BUFF=%U ID=%LX LEN=%U PRI=%U EXT=%U RTR=%U\r\n", port, id, len, priority, ext, rtr);
            if ((len)&&(!rtr)) {
               data-=len;
               can_debug("  DATA = ");
               for (i=0;i<len;i++) {
                  can_debug("%X ",*data);
                  data++;
               }
               can_debug("\r\n");
            }
   #endif

   return(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 5:32 pm     Reply with quote

It's possibly a bug in the code.

Here is the code from the mcp2510 driver. It loads the extended ID
into the Transmit Buffer 'n' Extended ID register (lsb byte). Note how
when it sets the tx mask, it's writing to the TXB0EIDL register. This
is the transmitter routine, can_putc(), and it writes the mask to the
transmit mask register.

can-mcp2510.c
Quote:
if (!b_TXB0CTRL.txreq) {
TXRXBaD0=TXB0D0;
TXBaCTRL=TXB0CTRL;
TXRXBaEIDL=TXB0EIDL;
TXBaDLC=TXB0DLC;
port=0;

//set tx mask
can_set_id(TXRXBaEIDL, id, ext);


can-mcp2510.h
Quote:
//transmit buffer n extended identifier
#define TXB0EIDH 0x33
#define TXB0EIDL 0x34
#define TXB1EIDH 0x43
#define TXB1EIDL 0x44
#define TXB2EIDH 0x53
#define TXB2EIDL 0x54


But in the can-18xxx8.c driver, CCS is using 0xF64 as the address for the
TXB0EIDL register in the can_putd() function. But 0xF64 is a "Rx" ID
register. The correct address for the "Tx" ID register is 0xF44.
So it looks like a bug in the code.
cchappyboy



Joined: 03 Dec 2008
Posts: 45

View user's profile Send private message

PostPosted: Thu Apr 30, 2009 10:39 am     Reply with quote

Thanks you so much.
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