Hi, I’ve tried to compile a drivre for a UART on the TMS470R1B1M part of
the driver ( the write function is shown below):
static int uart_write( struct _file_descriptor* fd, const void*
write_buf, int num_bytes )
{
volatile int bytes_written = -1;
volatile SCI_TypeDef* SCIx;
if( ( is_valid_handle( fd ) ) &&
( write_buf != NULL ) &&
( num_bytes > 0 ) )
{
SCIx = ( ( SCI_TypeDef* )( fd->fd_priv_data ) );
if( ( fd->mode & O_RDONLY ) != O_RDONLY )
{
bytes_written = 0;
while( bytes_written < num_bytes )
{
/* Determine if the transmitter is ready to
transmit a byte */
while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 )
asm("nop;");
SCIx->TXBUF =
( ( char* )( write_buf )
)[bytes_written++];
}
}
}
return bytes_written;
}
When complied with gcc arm-elf 4.2.0 I’ve got the following output:
static int uart_write( struct _file_descriptor* fd,
const void* write_buf,
int num_bytes )
{
uart_wri:mov r12,r13
stmdb r13!,{r11-r12,r14,pc}
sub r11,r12,#0x4
sub r13,r13,#0x14
str r0,[r11,#-0x18]
str r1,[r11,#-0x1C]
str r2,[r11,#-0x20]
volatile int bytes_written = -1;
mvn r3,#0x0
str r3,[r11,#-0x14]
volatile SCI_TypeDef* SCIx;
if( ( is_valid_handle( fd ) ) &&
( write_buf != NULL ) &&
( num_bytes > 0 ) )
ldr r0,[r11,#-0x18]
bl 0x11180 ; is_valid_handle
mov r3,r0
cmp r3,#0x0
beq 0x11540
ldr r3,[r11,#-0x1C]
cmp r3,#0x0
beq 0x11540
ldr r3,[r11,#-0x20]
cmp r3,#0x0
ble 0x11540
{
SCIx = ( ( SCI_TypeDef* )( fd->fd_priv_data ) );
ldr r3,[r11,#-0x18]
ldr r3,[r3,#0x1C]
str r3,[r11,#-0x10]
while( bytes_written < num_bytes )
{
/* Determine if the transmitter is ready to transmit a byte */
while( ( SCIx->CTL2 & SCI_TXRDY ) != 0 ) asm("nop;");
SCIx->TXBUF = ( ( char* )( write_buf ) )[bytes_written++];
}
}
return bytes_written;
ldr r3,[r11,#-0x14]
mov r0,r3
sub r13,r11,#0x0C
ldmia r13,{r11,r13,pc}
}
As can be seen no assembly code is generated for the while loop. These
are the flags used for gcc
CFLAGS += -mbig-endian -mcpu=arm7tdmi -mapcs-frame -gdwarf-2
-I$(PROJECTROOT)
AFLAGS = -mcpu=arm7tdmi --warn -EB -mfpu=softfpa -mapcs-32 --gdwarf2
LDFLAGS = --script=$(TMS470R1B1MDIR)ldscript -EB
-Map=$(OUTPUTDIR)/main.map --cref --gc-sections
ODFLAGS = --wide --source --all-headers --reloc --syms --disassemble -t
LDFLAGS += -L /cygdrive/c/GNUARM/arm-elf/lib/be/
LIBS = $(SYSTEMLIBSDIR)libgcc.a
LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libc.a
LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libg.a
LIBS += /cygdrive/c/GNUARM/arm-elf/lib/be/libm.a
Any suggestion I can try to get the complier to generate the assembly
code for the while loop?
Thanks