Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Merging up_memcpy.S from the PX4/Nuttx repository to fix GCC 4.7 bug #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
32 changes: 16 additions & 16 deletions nuttx/arch/arm/src/armv7-m/up_memcpy.S
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ memcpy:
/* Quickly check for very short copies */

cmp r2, #4
blt MEM_DataCopyBytes
blt.n MEM_DataCopyBytes

and r14, r0, #3 /* Get destination alignment bits */
bfi r14, r1, #2, #2 /* Get source alignment bits */
Expand Down Expand Up @@ -199,7 +199,7 @@ MEM_DataCopy0:
/* Check for short word-aligned copy */

cmp r2, #0x28
blt MEM_DataCopy0_2
blt.n MEM_DataCopy0_2

/* Bulk copy loop */

Expand All @@ -208,7 +208,7 @@ MEM_DataCopy0_1:
stmia r0!, {r3-r12}
sub r2, r2, #0x28
cmp r2, #0x28
bge MEM_DataCopy0_1
bge.n MEM_DataCopy0_1

/* Copy remaining long words */

Expand All @@ -224,28 +224,28 @@ MEM_DataCopy0_2:
MEM_LongCopyJump:
ldr.w r3, [r1], #0x04 /* 4 bytes remain */
str.w r3, [r0], #0x04
b MEM_LongCopyEnd
b.n MEM_LongCopyEnd
ldmia.w r1!, {r3-r4} /* 8 bytes remain */
stmia.w r0!, {r3-r4}
b MEM_LongCopyEnd
b.n MEM_LongCopyEnd
ldmia.w r1!, {r3-r5} /* 12 bytes remain */
stmia.w r0!, {r3-r5}
b MEM_LongCopyEnd
b.n MEM_LongCopyEnd
ldmia.w r1!, {r3-r6} /* 16 bytes remain */
stmia.w r0!, {r3-r6}
b MEM_LongCopyEnd
b.n MEM_LongCopyEnd
ldmia.w r1!, {r3-r7} /* 20 bytes remain */
stmia.w r0!, {r3-r7}
b MEM_LongCopyEnd
b.n MEM_LongCopyEnd
ldmia.w r1!, {r3-r8} /* 24 bytes remain */
stmia.w r0!, {r3-r8}
b MEM_LongCopyEnd
b.n MEM_LongCopyEnd
ldmia.w r1!, {r3-r9} /* 28 bytes remain */
stmia.w r0!, {r3-r9}
b MEM_LongCopyEnd
b.n MEM_LongCopyEnd
ldmia.w r1!, {r3-r10} /* 32 bytes remain */
stmia.w r0!, {r3-r10}
b MEM_LongCopyEnd
b.n MEM_LongCopyEnd
ldmia.w r1!, {r3-r11} /* 36 bytes remain */
stmia.w r0!, {r3-r11}

Expand Down Expand Up @@ -308,7 +308,7 @@ MEM_DataCopy13:

MEM_DataCopy2:
cmp r2, #0x28
blt MEM_DataCopy2_1
blt.n MEM_DataCopy2_1

/* Save regs */

Expand Down Expand Up @@ -345,18 +345,18 @@ MEM_DataCopy2_2:

sub r2, r2, #0x28
cmp r2, #0x28
bge MEM_DataCopy2_2
bge.n MEM_DataCopy2_2
pop {r4-r12}

MEM_DataCopy2_1: /* Read longs and write 2 x half words */
cmp r2, #4
blt MEM_DataCopyBytes
blt.n MEM_DataCopyBytes
ldr r3, [r1], #0x04
strh r3, [r0], #0x02
lsr r3, r3, #0x10
strh r3, [r0], #0x02
sub r2, r2, #0x04
b MEM_DataCopy2
b.n MEM_DataCopy2

/* Bits: Src=01, Dst=00 - Byte before half word to long
* Bits: Src=01, Dst=10 - Byte before half word to half word
Expand Down Expand Up @@ -410,7 +410,7 @@ MEM_DataCopy3:
lsr r3, r3, #0x10
strb r3, [r0], #0x01
sub r2, r2, #0x04
b MEM_DataCopy3
b.n MEM_DataCopy3

.size memcpy, .-memcpy
.end
15 changes: 13 additions & 2 deletions nuttx/drivers/mtd/at24xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,17 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
uint8_t buf[2];
buf[1] = offset & 0xff;
buf[0] = (offset >> 8) & 0xff;
uint8_t tries = 100;

while (I2C_WRITE(priv->dev, buf, 2) < 0)
while (I2C_WRITE(priv->dev, buf, 2) < 0 && tries-- > 0)
{
fvdbg("wait\n");
usleep(1000);
}
if (tries == 0) {
fdbg("timed out reading at offset %u\n", (unsigned)offset);
return 0;
}

I2C_READ(priv->dev, buffer, priv->pagesize);
startblock++;
Expand Down Expand Up @@ -286,11 +291,17 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
while (blocksleft-- > 0)
{
uint16_t offset = startblock * priv->pagesize;
while (I2C_WRITE(priv->dev, (uint8_t *)&offset, 2) < 0)
uint8_t tries = 100;

while (I2C_WRITE(priv->dev, (uint8_t *)&offset, 2) < 0 && tries-- > 0)
{
fvdbg("wait\n");
usleep(1000);
}
if (tries == 0) {
fdbg("timed out writing at offset %u\n", (unsigned)offset);
return 0;
}

buf[1] = offset & 0xff;
buf[0] = (offset >> 8) & 0xff;
Expand Down
Loading