bsp/tms570 Use bitfields instead of hard-coded values

Signed-off-by: Premysl Houdek <kom541000@gmail.com>
This commit is contained in:
Premysl Houdek
2015-07-17 17:04:06 +02:00
committed by Chris Johns
parent 9a84f98372
commit 49c1d25dc2
4 changed files with 52 additions and 32 deletions

View File

@@ -85,23 +85,39 @@ static void tms570_clock_driver_support_initialize_hardware( void )
/* Hardware specific initialize */ /* Hardware specific initialize */
TMS570_RTI.GCTRL = 0; TMS570_RTI.GCTRL = 0;
TMS570_RTI.CNT[0].CPUCx = tc_prescaler - 1; TMS570_RTI.CNT[0].CPUCx = tc_prescaler - 1;
TMS570_RTI.TBCTRL = 2; TMS570_RTI.TBCTRL = TMS570_RTI_TBCTRL_INC;
TMS570_RTI.CAPCTRL = 0; TMS570_RTI.CAPCTRL = 0;
TMS570_RTI.COMPCTRL = 0; TMS570_RTI.COMPCTRL = 0;
/* set counter to zero */ /* set counter to zero */
TMS570_RTI.CNT[0].UCx = 0; TMS570_RTI.CNT[0].UCx = 0;
TMS570_RTI.CNT[0].FRCx = 0; TMS570_RTI.CNT[0].FRCx = 0;
/* clear interrupts*/ /* clear interrupts*/
TMS570_RTI.CLEARINTENA = 0x00070f0f; TMS570_RTI.CLEARINTENA = TMS570_RTI_CLEARINTENA_CLEAROVL1INT |
TMS570_RTI.INTFLAG = 0x0007000f; TMS570_RTI_CLEARINTENA_CLEAROVL0INT |
TMS570_RTI_CLEARINTENA_CLEARTBINT |
TMS570_RTI_CLEARINTENA_CLEARDMA3 |
TMS570_RTI_CLEARINTENA_CLEARDMA2 |
TMS570_RTI_CLEARINTENA_CLEARDMA1 |
TMS570_RTI_CLEARINTENA_CLEARDMA0 |
TMS570_RTI_CLEARINTENA_CLEARINT3 |
TMS570_RTI_CLEARINTENA_CLEARINT2 |
TMS570_RTI_CLEARINTENA_CLEARINT1 |
TMS570_RTI_CLEARINTENA_CLEARINT0;
TMS570_RTI.INTFLAG = TMS570_RTI_INTFLAG_OVL1INT |
TMS570_RTI_INTFLAG_OVL0INT |
TMS570_RTI_INTFLAG_TBINT |
TMS570_RTI_INTFLAG_INT3 |
TMS570_RTI_INTFLAG_INT2 |
TMS570_RTI_INTFLAG_INT1 |
TMS570_RTI_INTFLAG_INT0;
/* set timer */ /* set timer */
TMS570_RTI.CMP[0].COMPx = TMS570_RTI.CNT[0].FRCx + tc_increments_per_tick; TMS570_RTI.CMP[0].COMPx = TMS570_RTI.CNT[0].FRCx + tc_increments_per_tick;
TMS570_RTI.COMP0CLR = TMS570_RTI.CMP[0].COMPx + tc_increments_per_tick / 2; TMS570_RTI.COMP0CLR = TMS570_RTI.CMP[0].COMPx + tc_increments_per_tick / 2;
TMS570_RTI.CMP[0].UDCPx = tc_increments_per_tick; TMS570_RTI.CMP[0].UDCPx = tc_increments_per_tick;
/* enable interupt */ /* enable interupt */
TMS570_RTI.SETINTENA = 0x1; TMS570_RTI.SETINTENA = TMS570_RTI_SETINTENA_SETINT0;
/* enable timer */ /* enable timer */
TMS570_RTI.GCTRL = 1; TMS570_RTI.GCTRL = TMS570_RTI_GCTRL_CNT0EN;
/* set timecounter */ /* set timecounter */
tms570_rti_tc.tc_get_timecount = tms570_rti_get_timecount; tms570_rti_tc.tc_get_timecount = tms570_rti_get_timecount;
tms570_rti_tc.tc_counter_mask = 0xffffffff; tms570_rti_tc.tc_counter_mask = 0xffffffff;
@@ -117,7 +133,7 @@ static void tms570_clock_driver_support_initialize_hardware( void )
*/ */
static void tms570_clock_driver_support_at_tick( void ) static void tms570_clock_driver_support_at_tick( void )
{ {
TMS570_RTI.INTFLAG = 0x00000001; TMS570_RTI.INTFLAG = TMS570_RTI_INTFLAG_INT0;
} }
/** /**
@@ -156,7 +172,8 @@ static void tms570_clock_driver_support_install_isr(
static void tms570_clock_driver_support_shutdown_hardware( void ) static void tms570_clock_driver_support_shutdown_hardware( void )
{ {
/* turn off the timer interrupts */ /* turn off the timer interrupts */
TMS570_RTI.CLEARINTENA = 0x20000; TMS570_RTI.CLEARINTENA = TMS570_RTI_CLEARINTENA_CLEAROVL0INT |
TMS570_RTI_CLEARINTENA_CLEARINT0;
} }
#define Clock_driver_support_initialize_hardware \ #define Clock_driver_support_initialize_hardware \

View File

@@ -41,7 +41,7 @@ static void tms570_putc(char ch)
rtems_interrupt_level level; rtems_interrupt_level level;
rtems_interrupt_disable(level); rtems_interrupt_disable(level);
while ( ( driver_context_table[0].regs->FLR & 0x100 ) == 0) { while ( ( driver_context_table[0].regs->FLR & TMS570_SCI_FLR_TXRDY ) == 0) {
rtems_interrupt_flash(level); rtems_interrupt_flash(level);
} }
driver_context_table[0].regs->TD = ch; driver_context_table[0].regs->TD = ch;
@@ -74,7 +74,7 @@ static void tms570_uart_output(char c)
*/ */
static int tms570_uart_input( void ) static int tms570_uart_input( void )
{ {
if ( driver_context_table[0].regs->FLR & (1<<9) ) { if ( driver_context_table[0].regs->FLR & TMS570_SCI_FLR_RXRDY ) {
return driver_context_table[0].regs->RD; return driver_context_table[0].regs->RD;
} else { } else {
return -1; return -1;

View File

@@ -155,7 +155,7 @@ static int tms570_sci_read_received_chars(
*/ */
static void tms570_sci_enable_interrupts(tms570_sci_context * ctx) static void tms570_sci_enable_interrupts(tms570_sci_context * ctx)
{ {
ctx->regs->SETINT = (1<<9); ctx->regs->SETINT = TMS570_SCI_SETINT_SET_RX_INT;
} }
/** /**
@@ -169,7 +169,7 @@ static void tms570_sci_enable_interrupts(tms570_sci_context * ctx)
*/ */
static void tms570_sci_disable_interrupts(tms570_sci_context * ctx) static void tms570_sci_disable_interrupts(tms570_sci_context * ctx)
{ {
ctx->regs->CLEARINT = (1<<9); ctx->regs->CLEARINT = TMS570_SCI_CLEARINT_CLR_RX_INT;
} }
/** /**
@@ -216,29 +216,30 @@ static bool tms570_sci_set_attributes(
rtems_termios_device_lock_acquire(base, &lock_context); rtems_termios_device_lock_acquire(base, &lock_context);
ctx->regs->GCR1 &= ~( (1<<7) | (1<<25) | (1<<24) ); ctx->regs->GCR1 &= ~( TMS570_SCI_GCR1_SWnRST | TMS570_SCI_GCR1_TXENA |
TMS570_SCI_GCR1_RXENA );
ctx->regs->GCR1 &= ~(1<<4); /*one stop bit*/ ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_STOP; /*one stop bit*/
ctx->regs->FORMAT = 0x7; ctx->regs->FORMAT = TMS570_SCI_FORMAT_CHAR(0x7);
switch ( t->c_cflag & ( PARENB|PARODD ) ) { switch ( t->c_cflag & ( PARENB|PARODD ) ) {
case ( PARENB|PARODD ): case ( PARENB|PARODD ):
/* Odd parity */ /* Odd parity */
ctx->regs->GCR1 &= ~(1<<3); ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_PARITY;
ctx->regs->GCR1 |= (1<<2); ctx->regs->GCR1 |= TMS570_SCI_GCR1_PARITY_ENA;
break; break;
case PARENB: case PARENB:
/* Even parity */ /* Even parity */
ctx->regs->GCR1 |= (1<<3); ctx->regs->GCR1 |= TMS570_SCI_GCR1_PARITY;
ctx->regs->GCR1 |= (1<<2); ctx->regs->GCR1 |= TMS570_SCI_GCR1_PARITY_ENA;
break; break;
default: default:
case 0: case 0:
case PARODD: case PARODD:
/* No Parity */ /* No Parity */
ctx->regs->GCR1 &= ~(1<<2); ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_PARITY_ENA;
} }
/* Baud rate */ /* Baud rate */
@@ -247,7 +248,8 @@ static bool tms570_sci_set_attributes(
bauddiv = (BSP_PLL_OUT_CLOCK + baudrate / 2) / baudrate; bauddiv = (BSP_PLL_OUT_CLOCK + baudrate / 2) / baudrate;
ctx->regs->BRS = bauddiv; ctx->regs->BRS = bauddiv;
ctx->regs->GCR1 |= (1<<7) | (1<<25) | (1<<24); ctx->regs->GCR1 |= TMS570_SCI_GCR1_SWnRST | TMS570_SCI_GCR1_TXENA |
TMS570_SCI_GCR1_RXENA;
rtems_termios_device_lock_release(base, &lock_context); rtems_termios_device_lock_release(base, &lock_context);
@@ -274,7 +276,7 @@ static void tms570_sci_interrupt_handler(void * arg)
/* /*
* Check if we have received something. * Check if we have received something.
*/ */
if ( (ctx->regs->FLR & (1<<9) ) == (1<<9) ) { if ( (ctx->regs->FLR & TMS570_SCI_FLR_RXRDY ) == TMS570_SCI_FLR_RXRDY ) {
n = tms570_sci_read_received_chars(ctx, buf, TMS570_SCI_BUFFER_SIZE); n = tms570_sci_read_received_chars(ctx, buf, TMS570_SCI_BUFFER_SIZE);
if ( n > 0 ) { if ( n > 0 ) {
/* Hand the data over to the Termios infrastructure */ /* Hand the data over to the Termios infrastructure */
@@ -284,7 +286,7 @@ static void tms570_sci_interrupt_handler(void * arg)
/* /*
* Check if we have something transmitted. * Check if we have something transmitted.
*/ */
if ( (ctx->regs->FLR & (1<<8) ) == (1<<8) ) { if ( (ctx->regs->FLR & TMS570_SCI_FLR_TXRDY ) == TMS570_SCI_FLR_TXRDY ) {
n = tms570_sci_transmitted_chars(ctx); n = tms570_sci_transmitted_chars(ctx);
if ( n > 0 ) { if ( n > 0 ) {
/* /*
@@ -355,7 +357,7 @@ static void tms570_sci_poll_write(
/* Write */ /* Write */
for ( i = 0; i < n; ++i ) { for ( i = 0; i < n; ++i ) {
while ( (ctx->regs->FLR & (1<<11) ) == 0) { while ( (ctx->regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0) {
; ;
} }
ctx->regs->TD = buf[i]; ctx->regs->TD = buf[i];
@@ -375,7 +377,7 @@ static int TMS570_sci_can_read_char(
tms570_sci_context * ctx tms570_sci_context * ctx
) )
{ {
return ctx->regs->FLR & (1<<9); return ctx->regs->FLR & TMS570_SCI_FLR_RXRDY;
} }
/** /**
@@ -530,7 +532,7 @@ static void tms570_sci_interrupt_last_close(
rtems_termios_device_lock_release(base, &lock_context); rtems_termios_device_lock_release(base, &lock_context);
/* Flush device */ /* Flush device */
while ( ( ctx->regs->FLR & (1<<11) ) > 0 ) { while ( ( ctx->regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) > 0 ) {
;/* Wait until all data has been sent */ ;/* Wait until all data has been sent */
} }

View File

@@ -35,19 +35,20 @@ void tms570_pom_remap(void)
{ {
int i; int i;
uint32_t vec_overlay_start = 0x08000000; uint32_t vec_overlay_start = 0x08000000;
uint32_t temp = 0;
memcpy((void*)vec_overlay_start, bsp_start_vector_table_begin, 64); memcpy((void*)vec_overlay_start, bsp_start_vector_table_begin, 64);
TMS570_POM.GLBCTRL = 0; TMS570_POM.GLBCTRL = 0;
for ( i = 0; i < TMS570_POM_REGIONS; ++i ) { for ( i = 0; i < TMS570_POM_REGIONS; ++i ) {
TMS570_POM.REG[i].REGSIZE = TMS570_POM_REGSIZE_DISABLED; TMS570_POM.REG[i].REGSIZE = TMS570_POM_REGSIZE_SIZE(TMS570_POM_REGSIZE_DISABLED);
} }
TMS570_POM.REG[0].PROGSTART = 0x0 & TMS570_POM_REGADDRMASK; TMS570_POM.REG[0].PROGSTART = TMS570_POM_PROGSTART_STARTADDRESS(0);
TMS570_POM.REG[0].OVLSTART = vec_overlay_start & TMS570_POM_REGADDRMASK; TMS570_POM.REG[0].OVLSTART = TMS570_POM_OVLSTART_STARTADDRESS(vec_overlay_start);
TMS570_POM.REG[0].REGSIZE = TMS570_POM_REGSIZE_64B; TMS570_POM.REG[0].REGSIZE = TMS570_POM_REGSIZE_SIZE(TMS570_POM_REGSIZE_64B);
TMS570_POM.GLBCTRL = TMS570_POM_GLBCTRL_ON_OFF(0xa) |
TMS570_POM.GLBCTRL = TMS570_POM_GLBCTRL_ENABLE | TMS570_POM_GLBCTRL_ETO(0xa) |
(vec_overlay_start & ~TMS570_POM_REGADDRMASK); (TMS570_POM_GLBCTRL_OTADDR(~0) & vec_overlay_start);
} }