#include "FPGA_peripherals.h"
#include "armperipherals.h"
#include "omap30.h"
#include "omap30_arminth.h"
#include "omap1510_inth2.h"
#include "omap1510_inth_mapping.h"
#include "omap1510.h"
#include "swi.h"
void OMAP1510Mode(void);
int ReadUART1(unsigned char* Buffer, unsigned int Length) {
struct UART_struct *pUART1 = (struct UART_struct*)0xFFFB0000;
while(Length--) {
while( !(pUART1->LSR & 0x01) );
*Buffer++ = pUART1->RHR_THR_DLL;
}
return 0;
}
int WriteUART1(unsigned char* Buffer, unsigned int Length) {
struct UART_struct *pUART1 = (struct UART_struct*)0xFFFB0000;
while(Length--) {
while( !(pUART1->LSR & (0x01<<5)) );
pUART1->RHR_THR_DLL = *Buffer++;
}
return 0;
}
int ReadUART2(unsigned char* Buffer, unsigned int Length) {
struct UART_struct *pUART1 = (struct UART_struct*)0xFFFB0800;
while(Length--) {
while( !(pUART1->LSR & 0x01) );
*Buffer++ = pUART1->RHR_THR_DLL;
}
return 0;
}
int WriteUART2(unsigned char* Buffer, unsigned int Length) {
struct UART_struct *pUART1 = (struct UART_struct*)0xFFFB0800;
while(Length--) {
// while( !(pUART1->LSR & (0x01<<5)) );
pUART1->RHR_THR_DLL = *Buffer++;
}
return 0;
}
int SetupUART1(unsigned int BaudRate) {
struct UART_struct *pUART1 = (struct UART_struct*)0xFFFB0000;
int i;
/* The default TIPB configuration seems enough to operate normally.
* Will do performance tuning later. Nov, 6 2001 Zhu,Yaozong. */
/* Default is enough for 60MHz MPU operation. 100MHz is now tested. So... */
if ( BaudRate != 115200 ) {
printf("Only 115200 UART baud rate is supported now.\n");
return -1;
}
/* use 48MHz clock for UART1 */
/* *(int *)0xfffe1080 |= 1<<29; */
/* MCR[7:5], FCR[5:4], and IER[7:4] can only be written when EFR[4] = 1.
* Transmission control register (TCR) and trigger level register (TLR) are accessible only when EFR[4] = 1 and MCR[6] = 1.
*/
pUART1->LCR = 0xBF;
pUART1->IIR_FCR_EFR |= 1<<4|1<<6|1<<7; /* bit6 Enable auto-nRTS and bit7 enable auto-nCTS. */
pUART1->LCR = 0x80;
pUART1->MCR |= 1<<6; /*Enables access to the TCR and TLR registers */
// pUART1->IIR_FCR_EFR |= 1;
pUART1->SCR |= 1<<6; /*Enables the granularity of 1 for trigger TX level */
pUART1->SPR_TLR = 0x11;
pUART1->IIR_FCR_EFR &= 0x0f; /*Sets the trigger level for the RX FIFO,Sets the trigger level for the TX FIFO */
pUART1->MSR_TCR = 0x0F; /* This is the default value. 100% empty and full. */
//pUART1->SPR_TLR = 0x22; /* 8 and 8. */
/* pUART1->IIR_FCR_EFR = ...; */
pUART1->LCR = 0xBF;
pUART1->IIR_FCR_EFR &= ~(1<<4);
pUART1->LCR &= ~(1<<7);
pUART1->MCR &= ~(1<<6); /*Disables access to the TCR and TLR registers */
pUART1->LCR = 0x03<<0|0x00<<1|0x00<<3; /* 8 bits; 1 stop bit; No parity; */
pUART1->LCR |= 1<<7;
//pUART1->OSC_12M_SEL |= 1<<0; /* 115200bps */
pUART1->RHR_THR_DLL = 0x4e;
pUART1->IER_DLH = 0; /* Set baud rate to 57600. */
pUART1->LCR &= ~(1<<7);
// pUART1->IER_DLH |= 1<<0|1<<1; /* Enable the RHR and THR interrupts. */
pUART1->MDR1 &= 0xf8; /* Enable UART1 without autobauding. */
return 0;
}
void UART1_interrupt(void)
{
char buf[2];
unsigned char status;
struct UART_struct *pUART1 = (struct UART_struct*)0xFFFB0000;
// printf("enter UART1_interrupt...\n");
printf("IIR: 0x%02x\n",pUART1->IIR_FCR_EFR);
status = pUART1->LSR;
printf("LSR: 0x%02x\n",status);
if(status & 0x20) {
pUART1->IER_DLH &= ~(1<<1); /* Disable THR interrupts. */
}
if(status & 0x01) {
ReadUART1(buf,1);
printf("read out char: %c\n",buf[0]);
WriteUART1(buf,1);
}
}
void OMAP1510Mode(void)
{
MultiplexPinControl *COMP_MODE_CTRL_0=(MultiplexPinControl*)0xFFFE100C;
*COMP_MODE_CTRL_0 = 0x0000eaef;
}
int UARTtest(void)
{ int i = 0;
char buf[2]="a";
unsigned char status;
struct UART_struct *pUART1 = (struct UART_struct*)0xFFFB0000;
SetupUART1(115200);
/* Interrupt from i2c mapped on irq of the interrupt handler 2 */
INTH2_InitLevel(HEL_UART_BT,INTH_IRQ,INTH_HIGHEST_PRIORITY,INTH_LOW_LEVEL_SENSITIVE);
/* Valid the interrupt */
INTH2_EnableOneIT(HEL_UART_BT,INTH_IRQ);
pUART1->LCR &= ~(1<<7);
/// Enable the RHR and THR interrupts.
pUART1->IER_DLH |= (1<<0)|(1<<1);
//printf("IIR: 0x%02x\n",pUART1->IIR_FCR_EFR);
status = pUART1->LSR;
//printf("LSR: 0x%02x\n",status);
if(status & 0x01) {
printf("read out 0x%02x\n",pUART1->RHR_THR_DLL);
}
printf("press any key on pc console of com1....\n ");
ReadUART1(buf,1);
printf("read out %c ",buf[0]);
printf("LSR: 0x%02x\n",pUART1->LSR);
do{ i++;}while(i < 500000);
INTH2_DisableOneIT(HEL_UART_BT);
printf("UART1 Interrupt handler masked \n ");
return 0;
}