[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [microblaze-uclinux] serial comunication in petalinux
Jim Law wrote:
> I had worked thru some Linux docs and been using termios and
> signal methods
> to access serial ports, but your posting looks like a
> smoother path. So I
> thought I'd play with what you describe, but the
> "serial_channel_xuartlite.h" file seems to not be around to
> include. Is
> there a option in menuconfig that needs to be turned on too?
>
> Thanks,
> Jim
Sorry, it was code I once found anywhere in the net. Here we go:
typedef struct _SerialPort_XUartLite {
bool portOpen;
} SerialPort_XUartLite;
#define NUM_XUARTLITE 1
SerialPort_XUartLite s_xuartLite[NUM_XUARTLITE];
/*----------------------------------------------------------------------------*/
int io_serial_xuartlite_openPort(unsigned char portNo)
{
if (portNo >= NUM_XUARTLITE) {
return 0;
}
s_xuartLite[portNo].portOpen = true;
return 1;
}
/*----------------------------------------------------------------------------*/
void io_serial_xuartlite_closePort(unsigned char portNo)
{
s_xuartLite[portNo].portOpen = false;
}
/*----------------------------------------------------------------------------*/
int io_serial_xuartlite_readBlock(unsigned char portNo, char *data, int maxlen)
{
int recvBytes = 0;
if (s_xuartLite[portNo].portOpen) {
while (recvBytes < maxlen) {
if (XUartLite_mIsReceiveEmpty(STDIN_BASEADDRESS)) {
return recvBytes;
}
*data = (Xuint8)XIo_In32(STDIN_BASEADDRESS + XUL_RX_FIFO_OFFSET);
data++;
recvBytes++;
}
}
return recvBytes;
}
/*----------------------------------------------------------------------------*/
int io_serial_xuartlite_writeBlock(unsigned char portNo, const char *data, int len)
{
int retVal = 0;
if (s_xuartLite[portNo].portOpen) {
int i;
char* p = (char*)data;
for (i = 0; i < len; i++) {
while (XUartLite_mIsTransmitFull(STDOUT_BASEADDRESS));
XIo_Out32(STDOUT_BASEADDRESS + XUL_TX_FIFO_OFFSET, *p);
p++;
}
retVal = len;
}
return retVal;
}
/*----------------------------------------------------------------------------*/
bool io_serial_xuartlite_byteAvailable(unsigned char portNo)
{
if (s_xuartLite[portNo].portOpen) {
return XUartLite_mIsReceiveEmpty(STDIN_BASEADDRESS) ? false : true;
}
return false;
}
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/