⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 esd_pc104_200_cfg.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
字号:
/* esd_can_pc104_200cfg.c - */

/* Copyright 2001 Wind River Systems, Inc. */

/* 
modification history 
--------------------
01b,09dec04,lsg  fixed problem with writing to a const string with strtok_r.
01a,20dec01,dnb written

*/

/* 

 DESCRIPTION
 
*/

/* includes */
#include <vxWorks.h>
#include <errnoLib.h>
#include <intLib.h>
#include <iv.h>
#include <sysLib.h>
#include <string.h> /* for strtok_r */

#include <CAN/wnCAN.h>
#include <CAN/canController.h>
#include <CAN/canBoard.h>
#include <CAN/canFixedLL.h>
#include <CAN/i82527.h>
#include <CAN/sja1000.h>
#include <CAN/private/esd_can_pc104_200.h>

/* Check board compatibility */
#if (CPU == SH7750)
#error ESD PC104 CAN board unsupported on SH7750
#endif

/* special macros to expand configuration macros */ 
#define XSTR(s) STR(s)
#define STR(s) #s

#define INCLUDE_WNCAN_SHOW

#define INCLUDE_WNCAN_DEVIO
#define ESD_CAN_PC104_200_DEVIO_NAME  "/can/sja1000"

#define MAX_ESD_CAN_PC104_200_BOARDS 1 /*最大控制器数量*/

#ifdef INCLUDE_WNCAN_DEVIO
#include "CAN/wncanDevIO.h"
#endif

/* reserve memory for the requisite data structures */
static struct ESD_CAN_PC104_200_DeviceEntry
esd_can_pc104_200_cfg_DeviceArray[MAX_ESD_CAN_PC104_200_BOARDS];

/* external references */
#if 0
extern STATUS esd_can_pc104_200_establishLinks(struct WNCAN_Device *pDev);
extern STATUS esd_can_pc104_200_close(struct WNCAN_Device *pDev);
extern struct WNCAN_Device *esd_can_pc104_200_open(UINT brdNdx, UINT ctrlNdx);
extern STATUS esd_can_pc104_200_new(ULONG ioAddress,UINT irq);
extern ULONG  stringToUlong(const char *pStr);
#endif

extern UINT max_esd_can_pc104_200_boards;
extern struct ESD_CAN_PC104_200_DeviceEntry *esd_can_pc104_200_DeviceArray;

/* forward references */
void esd_can_pc104_200_show(void);
#ifdef INCLUDE_WNCAN_DEVIO
LOCAL void esd_can_pc104_200_devio_init(unsigned int*, unsigned long*);
#endif

/* global variables */
LOCAL BoardLLNode esd_can_pc104_200_LLNode;

/************************************************************************
*
* wn_can_esd_pc104_200_init
*
* RETURNS: N/A
*   
* ERRNO: N/A
*
*/ 
int wncan_esd_pc104_200_init(void)
{
    char *pCurAddr;   
    char *pLastAddr=NULL;
    char *pCurIrq;
    char *pLastIrq=NULL;
    
    unsigned int i;
    unsigned long ioAddr[MAX_ESD_CAN_PC104_200_BOARDS];
    unsigned int  irq[MAX_ESD_CAN_PC104_200_BOARDS];
    char sep[] = " \"";
    char* origAddr=NULL;
    char* copyAddr=NULL;
    char* origIrq=NULL;
    char* copyIrq=NULL;
	int status = OK;
	
    sysPciConfigWrite(0,0,0,0xf6,2,0x0620); /*MCCR2 (mpc107)
                                                                bit28-25 :0b0011 (3 clocks) AS rise time
									bit24-21 :0b0001 (1 clocks) AS fall time*/
																	
	
    max_esd_can_pc104_200_boards = MAX_ESD_CAN_PC104_200_BOARDS;
    esd_can_pc104_200_DeviceArray = esd_can_pc104_200_cfg_DeviceArray;
    
    /* Add this board into linked list of boards */
    esd_can_pc104_200_LLNode.key = WNCAN_ESD_PC104_200;
    esd_can_pc104_200_LLNode.nodedata.boarddata.establinks_fn = esd_can_pc104_200_establishLinks;
    esd_can_pc104_200_LLNode.nodedata.boarddata.close_fn      = esd_can_pc104_200_close;
    esd_can_pc104_200_LLNode.nodedata.boarddata.open_fn       = esd_can_pc104_200_open;
#ifdef INCLUDE_WNCAN_SHOW
    esd_can_pc104_200_LLNode.nodedata.boarddata.show_fn       = esd_can_pc104_200_show;
#else
    esd_can_pc104_200_LLNode.nodedata.boarddata.show_fn       = NULL;
#endif
    
    BOARDLL_ADD( &esd_can_pc104_200_LLNode );
    
    /* register the possible controllers for this board */
    sja1000_registration();
	
	/*ioaddr = 0xffa00000,irq = 0x4*/
	status=esd_can_pc104_200_new(0xffa00000,0x4);

#ifdef INCLUDE_WNCAN_DEVIO
    /* Initialize the DevIO interface */
    esd_can_pc104_200_devio_init(irq, ioAddr); 
#endif
    
    return status;
}

/************************************************************************
*
* esd_can_pc104_200_link - links API definitions in wncan_api.c
*
* RETURNS: N/A
*   
* ERRNO: N/A
*
*/ 
#ifdef USE_CAN_FUNCTION_DEFS
void esd_can_pc104_200_link(void)
{
    BOOL flag = FALSE;
    struct WNCAN_Device *pDev;
    if (flag == TRUE)
    {
        pDev = CAN_Open(WNCAN_ESD_PC104_200,0,0);
        CAN_Close(pDev);
    }
    return;
}
#endif



#ifdef INCLUDE_WNCAN_SHOW
/************************************************************************
*
* esd_can_pc104_200_show - display board to stdout
*
* RETURNS: N/A
*   
* ERRNO: N/A
*
*/
void  esd_can_pc104_200_show(void)
{
    UINT i;
    
    printf("\n\tBoard Name: %s\n",
        esd_can_pc104_200_DeviceArray[0].canDevice[0].deviceName);
    
    for(i = 0 ; i < max_esd_can_pc104_200_boards ; i++)
    {
        if(esd_can_pc104_200_DeviceArray[i].inUse)
        {
            printf("\t\tBoard Index: %d\n", i);
            printf("\t\tI/O Address 0x%0lx", esd_can_pc104_200_DeviceArray[i].ioAddress);
            printf("\t\tInterrupt Number: 0x%0x\n",
                esd_can_pc104_200_DeviceArray[i].canDevice[0].pBrd->irq);
        }
    }
    
    return;
}
#endif



#ifdef INCLUDE_WNCAN_DEVIO
/************************************************************************
*
* esd_can_pc104_200_devio_init - initialize the DevIO interface 
*
* RETURNS: N/A
*   
* ERRNO: N/A
*
*/
LOCAL void esd_can_pc104_200_devio_init(unsigned int *irq, unsigned long *ioAddr)
{
    char*                  pCurBrdName = NULL;
    char*                  pLastBrdName = NULL;
    char                   sep[] = " \"";
    char*                  copyConstString; 
    int                    boardidx, ctrlidx;
    STATUS                 status;
    WNCAN_DEVIO_DRVINFO*   wncDrv = NULL;
    
    /* 
    Read list of DevIO board names from component properties; 
    extract first name 
    Make a copy of the devio name parameter before operating on it.
    */
    
    copyConstString = (char *) malloc(strlen(ESD_CAN_PC104_200_DEVIO_NAME) + 1);
    
    memcpy(copyConstString, ESD_CAN_PC104_200_DEVIO_NAME, (strlen(ESD_CAN_PC104_200_DEVIO_NAME) + 1));
    
    pCurBrdName = strtok_r(copyConstString, sep, &pLastBrdName);    
    
    /* Parse name list and initialize each controller */
 #if 0   
    for(boardidx=0; (pCurBrdName && (boardidx < MAX_ESD_CAN_PC104_200_BOARDS)); boardidx++)
    {
        /* skip if not used */
        if(ioAddr[boardidx] == 0 || irq[boardidx] == 0) continue;
        
        for(ctrlidx=0; ctrlidx < ESD_CAN_PC104_200_MAX_CONTROLLERS; ctrlidx++)
        {
            /* Construct DevIO name for each controller, /boardName/ctlrNum */
            status = wncDevIODevCreate(pCurBrdName, 
                WNCAN_ESD_PC104_200,
                boardidx, ctrlidx, &wncDrv);
            
            if( status == ERROR )
            {
                free(copyConstString);
                return;
            }
        }
       
        pCurBrdName = strtok_r(NULL, sep, &pLastBrdName);
    }
#endif 	
                /* Construct DevIO name for each controller, /boardName/ctlrNum */
            status = wncDevIODevCreate(pCurBrdName, 
                WNCAN_ESD_PC104_200,
                0, 0, &wncDrv);
            
            if( status == ERROR )
            {
                free(copyConstString);
                return;
            }
        pCurBrdName = strtok_r(NULL, sep, &pLastBrdName);

    free(copyConstString);
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -