📄 sysproteus.c
字号:
/* sysProteus.c - Wind River PROTEUS FPGA board driver *//* Copyright 1984-2001 Wind River Systems, Inc. *//*modification history--------------------01a,22nov01,g_h created.*//*DESCRIPTIONThis library contains routines to load the Wind River FPGA card (PROTEUS).*//* includes */#include "vxWorks.h"#include "stdlib.h"#include "stdio.h"#include "string.h"#include "ctype.h"#include "ioLib.h"#include "iosLib.h"#include "memLib.h"#include "sys/stat.h"#include "sysProteus.h"/*********************************************************************** ** sysProteusLoad - read FPGA bit file from the file system and load it** This routine read FPGA bit file from the file system and load is to* the FPGA device on the Wind River PROTEUS card.** RETURNS: OK or ERROR** SEE ALSO: sysProteusLoadImage()*/STATUS sysProteusLoad ( char fileName[32] ) { UINT32 count; UINT32 fileSize; UINT8 * pMemory; UINT fileHandle; struct stat fs; /* open file */ fileHandle = open (fileName, 0, 0); if ((fileHandle == 0xFFFFFFFF) || (fileHandle == 0)) { printf ("Error: Specified File %s not found\n", fileName); return(ERROR); } /* get the file size */ fstat (fileHandle, &fs); fileSize = fs.st_size; /* malloc an area to allow processing of data */ pMemory = (UINT8 *)malloc(fileSize); if (pMemory == NULL) { close (fileHandle); printf ("Error: Allocating memory\n"); return (ERROR); } /* read file to buffer */ count = read (fileHandle, (char *)pMemory, fileSize); printf ("%d bytes read from file!\n", count); /* Configure FPGA with image */ sysProteusLoadImage (pMemory); /* close file and free memory buffer */ close (fileHandle); free (pMemory); /* Print info */ printf ("Success: FPGA Configured and Initialized!\n"); return (OK); }/*********************************************************************** ** sysProteusLoadImage - get FPGA bit image and load it to the FPGA** This routine get FPGA bit image and load it to the FPGA on the * Wind River PROTEUS card.** RETURNS: N/A** SEE ALSO: sysProteusLoad()*/void sysProteusLoadImage ( UINT8 * pImage ) { UINT8 * pFpgaData; UINT8 * pFpgaCtrl; UINT8 * pFpgaStatus; UINT32 count; UINT32 index; UINT8 stat; UINT8 syncByte; UINT32 * cntPtr; syncByte = 0xaa; pFpgaData = (UINT8 *)0xf0000009; pFpgaCtrl = (UINT8 *)0xf0000008; pFpgaStatus = (UINT8 *)0xf000000a; /* search for syncByte 0xAA in FPGA bit file */ for (;;pImage++) { if (*pImage == syncByte) break; } /* get the size of the actual data */ cntPtr = (UINT32 *)(pImage - 8); count = *cntPtr; /* toggle the Program pin of the FPGA */ *pFpgaCtrl = 0xc; *pFpgaCtrl = 0x8; /* Wait for FPGA to be ready to receive new configuration */ for (;;) { stat = *pFpgaStatus; if (stat & 0x20) break; } /* configure the FPGA by reading from RAM to the FPGA data register */ for (index=0; index < count; index++,pImage++) { *pFpgaData = *pImage; } }/*********************************************************************** ** sysProteusSwitchLedsDemo - demo switch leds control done by the FPGA** This routine demo switch leds control done by the PROTEUS FPGA** RETURNS: N/A*/void sysProteusSwitchLedsDemo ( void ) { UINT8 * pSwitch; UINT8 * pLeds; pSwitch = (UINT8 *)0x7080000C; /* SBC405GP SW3 address in the FPGA */ pLeds = (UINT8 *)0x70800008; /* SBC405GP D13-D21 address in the FPGA */ /* set default led pattern */ *pLeds = 0xA; printf ("End application by applying pattern 10101010=0xAA to switches...\n"); taskDelay(10); for (;;) { *pLeds = *pSwitch; if (*pSwitch == 0xAA) { *pLeds = *pSwitch; break; } } printf("\nSwitchleds program done!\n"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -