[PATCH 2/2] bsp/tms570 Use bitfields instead of hard-coded values
Premysl Houdek
kom541000 at gmail.com
Fri Jul 17 15:04:06 UTC 2015
Signed-off-by: Premysl Houdek <kom541000 at gmail.com>
---
c/src/lib/libbsp/arm/tms570/clock/clock.c | 31 +++++++++++++++-----
.../lib/libbsp/arm/tms570/console/printk-support.c | 4 +--
c/src/lib/libbsp/arm/tms570/console/tms570-sci.c | 34 ++++++++++++----------
c/src/lib/libbsp/arm/tms570/pom/tms570-pom.c | 15 +++++-----
4 files changed, 52 insertions(+), 32 deletions(-)
diff --git a/c/src/lib/libbsp/arm/tms570/clock/clock.c b/c/src/lib/libbsp/arm/tms570/clock/clock.c
index 1d887af..45da093 100644
--- a/c/src/lib/libbsp/arm/tms570/clock/clock.c
+++ b/c/src/lib/libbsp/arm/tms570/clock/clock.c
@@ -85,23 +85,39 @@ static void tms570_clock_driver_support_initialize_hardware( void )
/* Hardware specific initialize */
TMS570_RTI.GCTRL = 0;
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.COMPCTRL = 0;
/* set counter to zero */
TMS570_RTI.CNT[0].UCx = 0;
TMS570_RTI.CNT[0].FRCx = 0;
/* clear interrupts*/
- TMS570_RTI.CLEARINTENA = 0x00070f0f;
- TMS570_RTI.INTFLAG = 0x0007000f;
+ TMS570_RTI.CLEARINTENA = TMS570_RTI_CLEARINTENA_CLEAROVL1INT |
+ 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 */
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.CMP[0].UDCPx = tc_increments_per_tick;
/* enable interupt */
- TMS570_RTI.SETINTENA = 0x1;
+ TMS570_RTI.SETINTENA = TMS570_RTI_SETINTENA_SETINT0;
/* enable timer */
- TMS570_RTI.GCTRL = 1;
+ TMS570_RTI.GCTRL = TMS570_RTI_GCTRL_CNT0EN;
/* set timecounter */
tms570_rti_tc.tc_get_timecount = tms570_rti_get_timecount;
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 )
{
- 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 )
{
/* 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 \
diff --git a/c/src/lib/libbsp/arm/tms570/console/printk-support.c b/c/src/lib/libbsp/arm/tms570/console/printk-support.c
index ed33d98..77e4f1a 100644
--- a/c/src/lib/libbsp/arm/tms570/console/printk-support.c
+++ b/c/src/lib/libbsp/arm/tms570/console/printk-support.c
@@ -41,7 +41,7 @@ static void tms570_putc(char ch)
rtems_interrupt_level 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);
}
driver_context_table[0].regs->TD = ch;
@@ -74,7 +74,7 @@ static void tms570_uart_output(char c)
*/
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;
} else {
return -1;
diff --git a/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
index 44b53f5..54c1b69 100644
--- a/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
+++ b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
@@ -155,7 +155,7 @@ static int tms570_sci_read_received_chars(
*/
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)
{
- 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);
- 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->FORMAT = 0x7;
+ ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_STOP; /*one stop bit*/
+ ctx->regs->FORMAT = TMS570_SCI_FORMAT_CHAR(0x7);
switch ( t->c_cflag & ( PARENB|PARODD ) ) {
case ( PARENB|PARODD ):
/* Odd parity */
- ctx->regs->GCR1 &= ~(1<<3);
- ctx->regs->GCR1 |= (1<<2);
+ ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_PARITY;
+ ctx->regs->GCR1 |= TMS570_SCI_GCR1_PARITY_ENA;
break;
case PARENB:
/* Even parity */
- ctx->regs->GCR1 |= (1<<3);
- ctx->regs->GCR1 |= (1<<2);
+ ctx->regs->GCR1 |= TMS570_SCI_GCR1_PARITY;
+ ctx->regs->GCR1 |= TMS570_SCI_GCR1_PARITY_ENA;
break;
default:
case 0:
case PARODD:
/* No Parity */
- ctx->regs->GCR1 &= ~(1<<2);
+ ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_PARITY_ENA;
}
/* Baud rate */
@@ -247,7 +248,8 @@ static bool tms570_sci_set_attributes(
bauddiv = (BSP_PLL_OUT_CLOCK + baudrate / 2) / baudrate;
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);
@@ -274,7 +276,7 @@ static void tms570_sci_interrupt_handler(void * arg)
/*
* 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);
if ( n > 0 ) {
/* 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.
*/
- 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);
if ( n > 0 ) {
/*
@@ -355,7 +357,7 @@ static void tms570_sci_poll_write(
/* Write */
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];
@@ -375,7 +377,7 @@ static int TMS570_sci_can_read_char(
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);
/* 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 */
}
diff --git a/c/src/lib/libbsp/arm/tms570/pom/tms570-pom.c b/c/src/lib/libbsp/arm/tms570/pom/tms570-pom.c
index 6514368..749dd9d 100644
--- a/c/src/lib/libbsp/arm/tms570/pom/tms570-pom.c
+++ b/c/src/lib/libbsp/arm/tms570/pom/tms570-pom.c
@@ -35,19 +35,20 @@ void tms570_pom_remap(void)
{
int i;
uint32_t vec_overlay_start = 0x08000000;
+ uint32_t temp = 0;
memcpy((void*)vec_overlay_start, bsp_start_vector_table_begin, 64);
TMS570_POM.GLBCTRL = 0;
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].OVLSTART = vec_overlay_start & TMS570_POM_REGADDRMASK;
- TMS570_POM.REG[0].REGSIZE = TMS570_POM_REGSIZE_64B;
-
- TMS570_POM.GLBCTRL = TMS570_POM_GLBCTRL_ENABLE |
- (vec_overlay_start & ~TMS570_POM_REGADDRMASK);
+ TMS570_POM.REG[0].PROGSTART = TMS570_POM_PROGSTART_STARTADDRESS(0);
+ TMS570_POM.REG[0].OVLSTART = TMS570_POM_OVLSTART_STARTADDRESS(vec_overlay_start);
+ 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_ETO(0xa) |
+ (TMS570_POM_GLBCTRL_OTADDR(~0) & vec_overlay_start);
}
--
1.9.1
More information about the devel
mailing list