<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to canlib</title><link>https://sourceforge.net/p/mergcbus/wiki/canlib/</link><description>Recent changes to canlib</description><atom:link href="https://sourceforge.net/p/mergcbus/wiki/canlib/feed" rel="self"/><language>en</language><lastBuildDate>Thu, 22 May 2014 09:52:40 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/mergcbus/wiki/canlib/feed" rel="self" type="application/rss+xml"/><item><title>canlib modified by Mike Johnson</title><link>https://sourceforge.net/p/mergcbus/wiki/canlib/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="canlib"&gt;CANLIB&lt;/h1&gt;
&lt;p&gt;Library or example code that may be useful in writting other modules. &lt;/p&gt;
&lt;p&gt;Common ECAN, EEPROM, Program Flash memory, FLiM routines An attempt to reduce the amount of editing when a change is made or bug fixed by having a library of common stuff. &lt;/p&gt;
&lt;p&gt;Processor type P2480 or P4580 must be defined before including "lib.h" lib.c does this by defining macros in the workspace. Uses 4 MHz resonator and PLL for 16 MHz clock CAN bit rate of 125 Kbits/sec, Standard frame only, 4-12 bytes, 256-768 usec per frame ECAN in mode 2, 3 transmit buffers and 8 receive buffers &lt;/p&gt;
&lt;h3 id="some-simple-types-and-operations"&gt;Some simple types and operations&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;BOOL A variable which can be set TRUE or FALSE. &lt;/li&gt;
&lt;li&gt;BYTE An unsigned char. &lt;/li&gt;
&lt;li&gt;LO(n) The low byte of a 16 or 32 bit variable. &lt;/li&gt;
&lt;li&gt;HI(n) The 2nd byte of a 16 or 32 bit variable. &lt;/li&gt;
&lt;li&gt;UP(n) The 3rd byte of a 24 or 32 bit variable. &lt;/li&gt;
&lt;li&gt;LOHI(n) The 3rd byte of a 24 or 32 bit variable. &lt;/li&gt;
&lt;li&gt;HIHI(n) The 4th byte of a 32 bit variable. &lt;/li&gt;
&lt;li&gt;LOWD(n) The first 16 bits starting at the address. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="ecan-global-variables"&gt;ECAN global variables&lt;/h3&gt;
&lt;p&gt;BYTE CB_canid&lt;br /&gt;
     7 bit CBUS node number &lt;/p&gt;
&lt;p&gt;BYTE CB_priority&lt;br /&gt;
     4 bit CBUS priority &lt;/p&gt;
&lt;p&gt;BYTE CB_data[[8]](/apps/trac/mergcbus/changeset/8)&lt;br /&gt;
     up to 8 bytes of data &lt;/p&gt;
&lt;p&gt;BYTE CB_datalen&lt;br /&gt;
     length of data &lt;/p&gt;
&lt;p&gt;ECAN_MSG_FLAGS CB_msgFlags&lt;br /&gt;
     message flags or'ed together &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ECAN_STD_FRAME = 0b00000000, &lt;/li&gt;
&lt;li&gt;ECAN_RTR_FRAME = 0b01000000, &lt;/li&gt;
&lt;li&gt;ECAN_OVERFLOW = 0b00001000, &lt;/li&gt;
&lt;li&gt;ECAN_INVALID_MSG = 0b00010000 &lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="routines-in-the-library"&gt;Routines in the library&lt;/h3&gt;
&lt;p&gt;void wait(BYTE t)&lt;br /&gt;
     A loop to wait t msec. &lt;/p&gt;
&lt;p&gt;void ECANInitialize(void)&lt;br /&gt;
     Initializes the ECAN hardware. &lt;/p&gt;
&lt;p&gt;BYTE far * ECANBufferEmpty(void)&lt;br /&gt;
     Checks for an empty transmit buffer. &lt;/p&gt;
&lt;p&gt;BOOL ECANSendMessage(void)&lt;br /&gt;
     Send an ECAN buffer from global variables. BYTE CB_canid; // 7 bit CBUS node number BYTE CB_priority; // 4 bit CBUS priority BYTE CB_data[[8]](/apps/trac/mergcbus/changeset/8); // up to 8 bytes of data BYTE CB_datalen; // length of data ECAN_MSG_FLAGS CB_msgFlags; // message flags or'ed together ECAN_STD_FRAME = 0b00000000, ECAN_RTR_FRAME = 0b01000000, ECAN_OVERFLOW = 0b00001000, ECAN_INVALID_MSG = 0b00010000 &lt;/p&gt;
&lt;p&gt;BOOL ECANReceiveMessage(void)&lt;br /&gt;
     Receives an ECAN packet into the global variables. &lt;/p&gt;
&lt;p&gt;BYTE EEPROMRead(unsigned int adr)&lt;br /&gt;
     Reads from the EEPROM, allows for larger chips with more than 256 bytes. &lt;/p&gt;
&lt;p&gt;void EEPROMWrite(unsigned int adr, BYTE data)&lt;br /&gt;
     Write to EEPROM. &lt;/p&gt;
&lt;p&gt;void ProgramMemoryRead?(unsigned long adr, BYTE len, BYTE * far buffer)&lt;br /&gt;
     Reads a block of up to 255 bytes from program memory. &lt;/p&gt;
&lt;p&gt;void ProgramMemoryWrite?(unsigned long adr, BYTE len, BYTE * far buffer)&lt;br /&gt;
     Erase and Write an aligned block of up to 64 bytes, the length must be a multiple of 8 bytes. &lt;/p&gt;
&lt;p&gt;void GetNewCANID(void)&lt;br /&gt;
     Used by FlimSetup? to get a new CANID. &lt;/p&gt;
&lt;p&gt;void FlimSetup?(BYTE callstate)&lt;br /&gt;
     Called to initialize the nodenumber or after a duplicate CANID or nodenumber is detected. Callstate = 0 after reset, = 1 for setup button pushed, =2 for canid or nodenumber conflict. &lt;/p&gt;
&lt;h3 id="routines-used-by-the-library"&gt;Routines used by the library&lt;/h3&gt;
&lt;p&gt;void main(void)&lt;br /&gt;
     Main entry point code &lt;/p&gt;
&lt;p&gt;void hpinterrupt(void)&lt;br /&gt;
     high priority interrupt routine &lt;/p&gt;
&lt;p&gt;void lpinterrupt(void)&lt;br /&gt;
     low priority interrupt routine &lt;/p&gt;
&lt;p&gt;void GreenLED(BOOL on)&lt;br /&gt;
     Turn on or off the green led &lt;/p&gt;
&lt;p&gt;void YellowLED(BOOL on)&lt;br /&gt;
     Turn on or off the yellow led &lt;/p&gt;
&lt;p&gt;BOOL SetupButtonDown?(void)&lt;br /&gt;
     Detect the setup button pushed &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mike Johnson</dc:creator><pubDate>Thu, 22 May 2014 09:52:40 -0000</pubDate><guid>https://sourceforge.netdfa5035318621220a75cbdeb8e9e6d4ebdb7d71a</guid></item></channel></rss>