Date: Jan, 5.2005 a SYBERA product
1 Introduction... 3 1.1 SHA... 3 1.2 Supported Platforms... 3 1.3 Installation... 4 2 CAN RealtimeCore Library... 5 3 Software Licensing... 6 3.1 Certificate of License... 6 3.1.1 Product Enabling Code (PEC)... 6 3.1.2 Certification Label... 6 3.2 Software Lizenzierung (German)... 7 3.3 Lizenznachweis... 7 3.3.1 Product Enabling Code (PEC)... 7 3.3.2 Zertifizierungsmarke... 7 4 SHA CAN RealtimeCore Interface... 8 4.1 ShaCanCreate... 8 4.2 ShaCanDestroy... 10 4.3 ShaResetTransmission... 10 4.4 ShaCheckStatus... 10 4.5 ShaTransmitFrame... 10 4.6 ShaReceiveFrame... 10 4.7 Sample program:... 12 5 SHA CAN Support Driver Installation... 15 SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 2
1 Introduction The idea of further interface abstruction of the SHA X-Realtime for several fieldbus systems, like serial communication, CANBUS, ProfiBus, Ethernet (TCP/IP),... is realized by SYBERA AddOn Software Libraries, so called RealtimeCores. All RealtimeCores are based on the SHA X-Realtime system. The RealtimeCores are intended to fullfill Realtime- Level-1, which means collecting and buffering data in realtime without loss of data. Thus the RealtimeCores usually require simple passive harware. 1.1 SHA The CAN RealtimeCore allows handling of SJA1000 based communication data. Incoming and outgoing data will be collected and stored in a Ringbuffer for CAN-Frames. The CAN RealtimeCore is delivered with two sample programs called CORESNDTST for sending data and CORERCVTST for receiving data. 1.2 Supported Platforms SHA was build to support serveral development platforms. Currently following platforms are supported: Visual C++ (from Version 5.0) Borland C++Builder (from Version 4.0) (under construction Visual Basic (from Version 5.0)) (under construction Borland Delphi (from Version 5.0)) SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 3
1.3 Installation For installation on Windows (NT, 2000, XP, Embedded) following steps are required: 1. First plug in your CAN adapter 2. Install the SHA CAN support driver (see chapter 5) 3. Install SHA (Run the program SYSETUP from the SHA directory) 4. Reboot your system 5. Install CANCore (Run the program SYSETUP from the CANCore directory) 6. Build your program with SHA CAN RealtimeCore Interface (Library and Header Files) 7. Run your program After start of SYSETUP the user name, company and keycode information must be entered. The keycode for the demo version is: 00001111-22223333 Note: After finishing installation, you must reboot your PC before!!! (this is only for the SHA demoversion and SHA installation without the dynamic load/unload module). For further installation notes see README.TXT. After installation check following registry keys: [HKEY_LOCAL_MACHINE\SOFTWARE\SYBERA\CAC SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 4
2 CAN RealtimeCore Library The interface functions of the SHA CAN RealtimeCore are exported by a static link library. Following files are required: SHACANCORE.LIB SHACANCORE.H CANCOREDEF.H Sample Project: SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 5
3 Software Licensing SYBERA distributes software through Developer-Licenses and Runtime-Licenses. A Developer-License authorize to the installation of the corresponding SYBERA software product on one (1) workstation. Any publishing or distribution of a compiled application or driver with SYBERA software require the purchase of corresponding Runtime-Licenses. A Runtime-License authorize to exclusive distribution of the SYBERA runtime (*.DLL and *.SYS) files which incorporate with a compiled application or driver on one (1) computing device or system and require at least the purchase of one (1) Developer- License. As unlimited declared Runtime-Licenses refer exclusively to a specified application or driver and require at least the purchase of one (1) Developer-License.. The use of the SYBERA software with further applications requires additional Runtime-Licenses. 3.1 Certificate of License The SYBERA software licenses are valid only in combination with all required license attributes. The SYBERA software licenses are certificated by following attributes: 3.1.1 Product Enabling Code (PEC) The PEC information consist of three parts exclusively generated by SYBERA. The KEYCODE is required for product enabling on the corresponding computing device. The KEYCODE identifies the product and has to be entered at installation with the corresponding USERNAME and COMPANY information. 3.1.2 Certification Label The certification label consist a serial number issued to a corresponding hardware. A valid license requires the direct attachment of the certification on the hardware. Sample Label: If there is any uncertainty about the correctness of the certification information, please contact SYBERA. SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 6
3.2 Software Lizenzierung (German) SYBERA vertreibt Software mit Entwickler-Lizenzen und Laufzeit- (Runtime-) Lizenzen. Eine Entwickler-Lizenz autorisiert zur Installation des entsprechenden SYBERA Software-Produkts auf einer (1) Workstation. Jede Weiterverbreitung oder jeder Verkauf einer kompilierten Applikation oder eines Treibers mit SYBERA Software erfordert den Erwerb von zugehörigen Runtime-Lizenzen. Eine Runtime-Lizenz autorisiert zur ausschließlichen Weitergabe der SYBERA Runtime-Dateien (*.DLL and *.SYS), die zum Betrieb mit einer Applikation oder mit einem Treiber auf einem (1) Computer oder einem System erforderlich sind und setzen mindenstens den Erwerb einer (1) Entwickler-Lizenz voraus. Als unbegrenzt deklarierte Runtime-Lizenzen beziehen sich ausschließlich auf eine bestimmte Applikation oder auf einen bestimmten Treiber und setzen mindestens den Erwerb einer (1) Entwickler-Lizenz voraus. Der Einsatz der SYBERA Software mit anderen Applikationen oder Treibern erfordert den Erwerb weiterer Runtime-Lizenzen. 3.3 Lizenznachweis Die SYBERA Software Lizenzen sind nur in Verbindung mit allen dafür vorgesehenen Lizenz-Attributen gültig. Die SYBERA Software-Lizenzen sind durch folgende Attribute gekennzeichnet: 3.3.1 Product Enabling Code (PEC) Die PEC-Daten bestehen aus drei Teilen und werden ausschließlich von SYBERA erstellt. Der KEYCODE wird für die Produktaktivierung auf dem entsprechenden Computersystem benötigt. Der KEYCODE identifiziert das Produkt und muß zusammen mit den USERNAME und COMPANY Daten bei der Installation eingetragen werden. 3.3.2 Zertifizierungsmarke Die Zertifizierungsmarke besitzt eine Seriennummer und wird für eine entsprechende Hardware ausgestellt. Für eine gültige Lizenzierung muß die Zertifizierungsmarke direkt an der Hardware angebracht werden. Muster: Bitte kontaktieren Sie SYBERA, falls Unklarheit bei der Lizenzierung besteht. SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 7
4 SHA CAN RealtimeCore Interface In the following all function prototypes will be discussed by samples. Since all platforms have their own syntax and dependencies, therefore the topics for the different platforms are marked as follow: VC : Visual C++, embedded VC and Borland C++ Builder VB : Visual Basic DP : Borland Delphi 4.1 ShaCanCreate This function opens the CAN port and installs the realtime ringbuffer system. On success the returning value is ERROR_SUCCESS, otherwise the returning value corresponds to that from GetLastError(). VC ULONG ShaCanCreate(CAN_PARAMS); Structure CAN Parameters (see CANCOREDEF.H): typedef struct _CAN_PARAMS ULONG dev_index; //PCI device index UCHAR dev_type; //PCI controller type UCHAR mode; //SJA CAN mode TYPE32 accr; //Acceptance code TYPE32 acmr; //Acceptance mask CAN_BUSTIMING0 btr0; //Bus timing0 CAN_BUSTIMING1 btr1; //Bus timing1 CAN_OUTCTRL ocr; //Output control CAN_CLOCKDIV cdr; //Clock divider //Output parameters CAN_STATUS sr; //Status CAN_ARBLOSTCAP alcr; //Arbitration lost comtrol CAN_ERRCODECAP eccr; //Error code control //Input - Output parameters CAN_FRAME frame; //CAN Frame CAN_PARAMS, *PCAN_PARAMS; SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 8
[dev_index] : Number of desired PCI adapter (starting with 1) [dev_type] : PCI controller type (PLX_DEVICE or PITA_DEVICE) [mode] : SJA CAN mode (BASECAN or PELICAN) [accr] union : Acceptance code (see SJA1000 datasheet) [acmr] union : Acceptance mask union (see SJA1000 datasheet) [btr0] union : Bus timing0 union (see SJA1000 datasheet) [btr1] union : Bus timing1 union (see SJA1000 datasheet) [ocr] union : Output control union (see SJA1000 datasheet) [cdr] union : Clock divider (see SJA1000 datasheet) [sr] union : Status (see SJA1000 datasheet) [alcr] union : Arbitration lost capture (see SJA1000 datasheet) [eccr] union : Error code capture (see SJA1000 datasheet) [frame] union : CAN Frame, max. 13 Bytes (see SJA1000 datasheet) Sample: //Set CAN mode CanParams.mode = BASECAN; //Set clock divider register CanParams.cdr.bit8 = 0; CanParams.cdr.bits.cd = 0; CanParams.cdr.bits.clockoff = FALSE; CanParams.cdr.bits.rxinten = 0; CanParams.cdr.bits.cbp = TRUE; CanParams.cdr.bits.canmode = FALSE; //Fosc/2 //CLKOUT enabled //RX interrupt on TX1 disabled //Comperator bypass active //Basic CAN //Set accept code and mask register CanParams.accr.bit8[0] = 0x00; CanParams.acmr.bit8[0] = 0xFF; //Set bustiming registers CanParams.btr0.bit8 = 0; CanParams.btr0.bits.brp = 0x02; CanParams.btr0.bits.sjw = 0x03; CanParams.btr1.bit8 = 0; CanParams.btr1.bits.tseg = 0x49; CanParams.btr1.bits.sam = FALSE; //Set output control register CanParams.ocr.bit8 = 0; CanParams.ocr.bits.ocmode = 0x02; CanParams.ocr.bits.ocpol0 = FALSE; CanParams.ocr.bits.octn0 = TRUE; CanParams.ocr.bits.octp0 = TRUE; CanParams.ocr.bits.ocpol1 = FALSE; CanParams.ocr.bits.octn1 = FALSE; CanParams.ocr.bits.octp1 = FALSE; //Init CAN Error = ShaCanCreate(CanParams); SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 9
4.2 ShaCanDestroy This function closes the CAN port and releases all resources for communication. VC void ShaCanDestroy(void); 4.3 ShaResetTransmission This function resets the SJA1000 and releases all resources for communication. VC void ShaResetTransmission(void); 4.4 ShaCheckStatus This function gets the status of the SJA1000. VC void ShaCheckStatus(PCAN_PARAMS); 4.5 ShaTransmitFrame This function gets a the frame from top of stack VC BOOLEAN ShaTransmitFrame(PCAN_PARAMS); 4.6 ShaReceiveFrame This function gets a the frame from top of stack VC BOOLEAN ShaReceiveFrame(PCAN_PARAMS); SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 10
Sample: //Receive frame if available while (!ShaReceiveFrame(&CanParams)) char szframe[max_path]; char szdata[max_path]; int ByteNum = pcanparams->frame.bc.id.dlc; //Print ID information sprintf(szframe, "ID:[%02x][%02x] Data:", pcanparams->frame.bit8[0], pcanparams->frame.bit8[1]); //Print data information for (int i=0; i<bytenum; i++) sprintf(szdata, "[%02x]", pcanparams->frame.bc.data[i]); strcat(szframe, szdata); SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 11
4.7 Sample program: #include <windows.h> #include <stdio.h> #include <conio.h> #include "c:\cac\shacancore.h" #include "c:\sha\shaexp.h" //Must be included last!!! void PrintFrameInfo( char* szprefix, PCAN_PARAMS pcanparams) char szframe[max_path]; char szdata[max_path]; int ByteNum = pcanparams->frame.bc.id.dlc; //Print ID information into buffer sprintf(szframe, "ID:[%02x][%02x] Data:", pcanparams->frame.bit8[0], pcanparams->frame.bit8[1]); //Print ID information into buffer for (int i=0; i<bytenum; i++) sprintf(szdata, "[%02x]", pcanparams->frame.bc.data[i]); strcat(szframe, szdata); printf("%s %s ByteNum: %i\n", szprefix, szframe, ByteNum); void main(void) CAN_PARAMS CanParams; char szprefix[max_path]; DWORD Error; UCHAR i = 0; UCHAR c = '\\'; printf("\n*** CAN Core Receive Test ***\n\n"); //Print driver and DLL version printf( "DRV Version: %.2f, DLL Version: %.2f\n", ddrvversion, ddllversion); //Reset parameters memset(&canparams, 0, sizeof(can_params)); //Get device index printf("\nenter DeviceIndex: "); scanf("%i", &CanParams.dev_index); SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 12
printf("\n"); //Set CAN mode CanParams.mode = BASECAN; //Set clock divider register CanParams.cdr.bit8 = 0; CanParams.cdr.bits.cd = 0; CanParams.cdr.bits.clockoff = FALSE; CanParams.cdr.bits.rxinten = 0; CanParams.cdr.bits.cbp = TRUE; CanParams.cdr.bits.canmode = FALSE; //Fosc/2 //CLKOUT enabled //RX interrupt on TX1 disabled //Comperator bypass active //Basic CAN //Set accept code and mask register CanParams.accr.bit8[0] = 0x00; CanParams.acmr.bit8[0] = 0xFF; //Set bustiming registers CanParams.btr0.bit8 = 0; CanParams.btr0.bits.brp = 0x02; CanParams.btr0.bits.sjw = 0x03; CanParams.btr1.bit8 = 0; CanParams.btr1.bits.tseg = 0x49; CanParams.btr1.bits.sam = FALSE; //Set output control register CanParams.ocr.bit8 = 0; CanParams.ocr.bits.ocmode = 0x02; CanParams.ocr.bits.ocpol0 = FALSE; CanParams.ocr.bits.octn0 = TRUE; CanParams.ocr.bits.octp0 = TRUE; CanParams.ocr.bits.ocpol1 = FALSE; CanParams.ocr.bits.octn1 = FALSE; CanParams.ocr.bits.octp1 = FALSE; //Init CAN Error = ShaCanCreate(CanParams); if (ERROR_SUCCESS == Error) printf("press any key...\n"); while (!kbhit()) //Receive frame if available while ((!ShaReceiveFrame(&CanParams)) && (!kbhit())) //Print active char c = (c == '\\')? '/' : '\\'; printf("[%c]\r", c); //Print frame information sprintf(szprefix, "RX Frame %5i ", i); PrintFrameInfo(szPrefix, &CanParams); //Check for errors if (i!= CanParams.frame.bc.data[0]) ShaCheckStatus(&CanParams); SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 13
i++; printf("\n*** Status: [%02x] ***\n\n", CanParams.sr.bit8); break; //Cleanup CAN ShaCanDestroy(); SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 14
5 SHA CAN Support Driver Installation The SHA CAN Support Driver will be installed through the Hardware Wizard of Windows 2000 / XP. The SHA CAN Support Driver may be included several times, if more CAN devices are installed. Windows will ask for a PNP device driver. For installation of the Support Driver follow the Hardware Wizard. On installation ignore any setup warnings, since these depend on several device groups. For installing the SHA CAN Support Driver Choose the WDM directory of the CAN Core installation disk. SYBERA e.k., Hohenzollernstr. 2, 71088 Holzgerlingen, Germany, Tel: +49-7031-411-781 Page 15