Has anyone directly accessed the PSP remote control's uart? By direct access, I mean completely avoiding system calls, and only using the memory-mapped config registers.
If so, could you give me some sample code?
Thanks!!!
-Chris
Direct access of PSP remote control UART
-
- Posts: 80
- Joined: Wed Feb 22, 2006 4:43 am
-
- Posts: 80
- Joined: Wed Feb 22, 2006 4:43 am
I'm not sure, I'm trying to not use the SDK.
Well, here is some nice simple code to read and write from the serial port, assuming you are in kernel mode!
Well, here is some nice simple code to read and write from the serial port, assuming you are in kernel mode!
/*
* Chris Mulhearn
*
* PSP Serial port IO defs
*/
#ifndef SERIALPORT_H
#define SERIALPORT_H
struct serialport {
int * txbuf; // tx + rx same on psp, 0xbe50 0000, bits 7..0
int * rxbuf;
int * status;
#define serialport_txfull ((int)0x00000020)
#define serialport_rxempty ((int)0x00000010)
};
int serialport_write(struct serialport * port, char * buffer, int length, int timeout);
int serialport_read(struct serialport * port, char * buffer, int length, int timeout);
extern struct serialport psprc_serialport; // instantiated in serialport.c
#endif
Let me know if this is useful to anyone!/*
* Chris Mulhearn
*
* PSP serial port IO routines
*/
#include "serialport.h"
/* instantiate "serialport" that points to psp remote control serial port */
struct serialport psprc_serialport = {
.txbuf = (int*)0xbe500000,
.rxbuf = (int*)0xbe500000,
.status = (int*)0xbe500018,
};
int serialport_write(struct serialport * port, char * buffer, int length, int timeout) {
int tcnt, bcnt;
if(length <= 0) return 0;
bcnt = 0;
while(1) {
tcnt = 0;
while( (*(port->status)) & serialport_txfull) {
tcnt++;
if(tcnt > timeout) break;
}
if(tcnt > timeout) break;
/*if(buffer[bcnt])*/ *(port->txbuf) = buffer[bcnt];
/*else *(port->txbuf) = '.'; */
bcnt++;
if(bcnt == length) break;
}
return bcnt;
}
int serialport_read(struct serialport * port, char * buffer, int length, int timeout) {
int tcnt, bcnt;
if(length <= 0) return 0;
bcnt = 0;
while(1) {
tcnt = 0;
while(( (*(port->status)) & serialport_rxempty)) {
tcnt++;
if(tcnt > timeout) break;
}
if(tcnt > timeout) break;
buffer[bcnt] = *((char*)port->rxbuf);
bcnt++;
if(bcnt == length) break;
}
return bcnt;
}