Files
vxWorks/bsps/ls2k1000/MyDebug.c
2025-08-21 11:21:20 +08:00

135 lines
2.9 KiB
C

#include <vxWorks.h>
#include <vxBusLib.h>
#include <hwif/vxbus/vxBus.h>
#include <hwif/vxbus/hwConf.h>
#include <config.h>
#include <string.h>
#define MY_DEBUG
/*#undef MY_DEBUG*/
IMPORT STATUS pciConfigInLong
(
int busNo, /* bus number */
int deviceNo, /* device number */
int funcNo, /* function number */
int address, /* address of the configuration space */
int * pData /* data read from the address */
);
#ifdef MY_DEBUG
static int baseAddr = 0; /*Uart Base Addr*/
static UINT32 regInterval = 0;
static const UINT16 STATUS_LSR_TXRDY = 0x20;
#define LSR 0x05 /* line status register */
#endif
struct vxbPciUartID
{
int unitNumber;
int pciDevBus;
int pciDevDev;
int pciDevFunc;
int regInterval;
};
LOCAL struct vxbPciUartID pciDevListsa[] ={
{0, 0, 2, 0, 1},
};
/**/
STATUS uartResourceGet(void)
{
HCF_DEVICE * pHcf;
UINT32 i =0;
UINT32 retval = ERROR;
for ( i = 0 ; i < hcfDeviceNum ; i++ )
{
if ( (hcfDeviceList[i].devUnit == CONSOLE_TTY) && (strcmp(hcfDeviceList[i].devName, "ns16550") == 0))
{
pHcf = &hcfDeviceList[i];
devResourceGet (pHcf, "regBase", HCF_RES_INT,(void *)&baseAddr);
devResourceGet (pHcf, "regInterval", HCF_RES_INT,(void *)&regInterval);
retval = OK;
return retval;
}
}
if (baseAddr == 0){
for (i = 0;i < (sizeof (pciDevListsa) / sizeof (pciDevListsa [0])); i++){
if (CONSOLE_TTY == pciDevListsa[i].unitNumber) {
pciConfigInLong(pciDevListsa[i].pciDevBus,pciDevListsa[i].pciDevDev,pciDevListsa[i].pciDevFunc,0x10,&baseAddr);
baseAddr = (baseAddr & 0xfffffff0);
regInterval = pciDevListsa[i].regInterval;
retval = OK;
}
}
}
return retval;
}
STATUS printstr(char *s)
{
#ifdef MY_DEBUG
/*nonsupport pci UART*/
uartResourceGet();
#if 0
if (baseAddr == 0 || regInterval == 0){
if (uartResourceGet() != OK)
return ERROR;
}
#endif
while (*s) {
while (((*(volatile unsigned char*)(baseAddr+LSR*regInterval)) & STATUS_LSR_TXRDY)==0);
*(unsigned char*)baseAddr = *s;
s++;
}
while (((*(volatile unsigned char*)(baseAddr+LSR*regInterval)) & STATUS_LSR_TXRDY)==0);
#endif
return OK;
}
STATUS printnum(unsigned long long n)
{
#ifdef MY_DEBUG
int i = 0;
int j = 0;
unsigned char a[40];
uartResourceGet();
#if 0
if (baseAddr == 0 || regInterval == 0){
if (uartResourceGet() != OK)
return ERROR;
}
#endif
do {
a[i] = n % 16;
n = n / 16;
i++;
}while(n);
for (j=i-1;j>=0;j--) {
if (a[j]>=10) {
while (((*(volatile unsigned char*)(baseAddr+LSR*regInterval)) & STATUS_LSR_TXRDY)==0);
*(unsigned char*)baseAddr = 'a' + a[j] - 10;
}else{
while (((*(volatile unsigned char*)(baseAddr+LSR*regInterval)) & STATUS_LSR_TXRDY)==0);
*(unsigned char*)baseAddr = '0' + a[j];
}
}
/*printstr("\r\n");*/
#endif
return OK;
}