move bitswap inside epcq_controller driver

This commit is contained in:
marqs 2018-10-09 23:16:37 +03:00
parent 9777fe8e66
commit 055a794b5e
11 changed files with 7437 additions and 7315 deletions

View File

@ -43,6 +43,7 @@
ALT_INLINE alt_32 static alt_epcq_validate_read_write_arguments(alt_epcq_controller_dev *flash_info,alt_u32 offset, alt_u32 length);
alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_flash_info);
ALT_INLINE unsigned char static bitswap8(unsigned char v);
/*
* Public API
@ -334,6 +335,10 @@ int alt_epcq_controller_write_block
/* prepare the word to be written */
memcpy((((void*)&word_to_write)) + padding, ((void*)data) + buffer_offset, bytes_to_copy);
// Bit-reverse bytes for flash
for (int i=0; i<bytes_to_copy; i++)
*((unsigned char*)&word_to_write+i) = bitswap8(*((unsigned char*)&word_to_write+i));
/* update offset and length variables */
buffer_offset += bytes_to_copy;
remaining_length -= bytes_to_copy;
@ -508,6 +513,10 @@ int alt_epcq_controller_read
if(0 == ret_code)
{
memcpy(dest_addr, (alt_u8*)epcq_flash_info->data_base + offset, length);
// Bit-reverse bytes read from flash
for (int i=0; i<length; i++)
*((unsigned char*)dest_addr+i) = bitswap8(*((unsigned char*)dest_addr+i));
}
return ret_code;
@ -794,4 +803,10 @@ alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_
return 0;
}
ALT_INLINE unsigned char static bitswap8(unsigned char v)
{
return ((v * 0x0802LU & 0x22110LU) |
(v * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}

View File

@ -134,7 +134,7 @@
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<Target Name="diy-audio-debug">make ENABLE_AUDIO=y APP_CFLAGS_DEBUG_LEVEL="-DDEBUG"</Target>
<Target Name="diy-audio-debug">make ENABLE_AUDIO=y APP_CFLAGS_DEBUG_LEVEL="-DDEBUG" generate_hex</Target>
<Target Name="Ack BSP update">cd ../sys_controller_bsp &amp;&amp; touch public.mk Makefile</Target>
<RebuildCommand/>
<CleanCommand>make clean</CleanCommand>

File diff suppressed because it is too large Load Diff

View File

@ -49,9 +49,6 @@ int read_flash(alt_u32 offset, alt_u32 length, alt_u8 *dstbuf)
if (retval != 0)
return -FLASH_READ_ERROR;
for (i=0; i<length; i++)
dstbuf[i] = bitswap8(dstbuf[i]);
return 0;
}
@ -69,10 +66,6 @@ int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum)
}
}
// Bit-reverse bytes for flash
for (i=0; i<length; i++)
pagedata[i] = bitswap8(pagedata[i]);
retval = alt_epcq_controller_write_block(&epcq_controller_dev->dev, (pagenum/PAGES_PER_SECTOR)*PAGES_PER_SECTOR*PAGESIZE, pagenum*PAGESIZE, pagedata, length);
if (retval != 0) {
@ -83,7 +76,7 @@ int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum)
return 0;
}
int write_flash(alt_u8 *buf, alt_u32 length, alt_u32 pagenum, alt_u8 *tmpbuf)
int write_flash(alt_u8 *buf, alt_u32 length, alt_u32 pagenum)
{
int retval;
alt_u32 bytes_to_w;
@ -91,13 +84,7 @@ int write_flash(alt_u8 *buf, alt_u32 length, alt_u32 pagenum, alt_u8 *tmpbuf)
while (length > 0) {
bytes_to_w = (length > PAGESIZE) ? PAGESIZE : length;
// Use a temporary buffer if one was given.
// This is to avoid the original buffer from
// being overwritten by write_flash_page().
if (tmpbuf)
memcpy(tmpbuf, buf, bytes_to_w);
retval = write_flash_page(tmpbuf ? tmpbuf : buf, bytes_to_w, pagenum);
retval = write_flash_page(buf, bytes_to_w, pagenum);
if (retval != 0)
return retval;

View File

@ -44,7 +44,7 @@ int read_flash(alt_u32 offset, alt_u32 length, alt_u8 *dstbuf);
int write_flash_page(alt_u8 *pagedata, alt_u32 length, alt_u32 pagenum);
int write_flash(alt_u8 *buf, alt_u32 length, alt_u32 pagenum, alt_u8 *tmpbuf);
int write_flash(alt_u8 *buf, alt_u32 length, alt_u32 pagenum);
int verify_flash(alt_u32 offset, alt_u32 length, alt_u32 golden_crc, alt_u8 *tmpbuf);

View File

@ -51,7 +51,7 @@ int copy_sd_to_flash(alt_u32 sd_blknum, alt_u32 flash_pagenum, alt_u32 length, a
return -retval;
}
retval = write_flash(tmpbuf, bytes_to_rw, flash_pagenum, NULL);
retval = write_flash(tmpbuf, bytes_to_rw, flash_pagenum);
if (retval != 0)
return retval;

View File

@ -25,6 +25,6 @@
#include "sd_io.h"
int check_sdcard(alt_u8 *databuf);
int copy_sd_to_flash(alt_u32 sd_offset, alt_u32 flash_offset, alt_u32 length, alt_u8 *tmpbuf);
int copy_sd_to_flash(alt_u32 sd_blknum, alt_u32 flash_pagenum, alt_u32 length, alt_u8 *tmpbuf);
#endif /* SDCARD_H_ */

View File

@ -94,7 +94,7 @@ int write_userdata(alt_u8 entry)
// then write the rest
if (vm_to_write > 0)
write_flash((alt_u8*)video_modes+srcoffset, vm_to_write, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + 1, databuf);
write_flash((alt_u8*)video_modes+srcoffset, vm_to_write, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + 1);
printf("Profile %u data written (%u bytes)\n", entry, sizeof(avconfig_t)+VIDEO_MODES_SIZE);
break;
@ -236,17 +236,17 @@ int import_userdata()
}
if (strncmp(header.userdata_key, "USRDATA", 8)) {
printf("Not an userdata entry at %u\n", profile);
printf("Not an userdata entry at 0x%x\n", 512+n*SECTORSIZE);
continue;
}
if ((header.version_major != FW_VER_MAJOR) || (header.version_minor != FW_VER_MINOR)) {
printf("Data version %u.%u does not match fw\n", header->version_major, header->version_minor);
printf("Data version %u.%u does not match fw\n", header.version_major, header.version_minor);
continue;
}
if (header.type > UDE_PROFILE) {
printf("Unknown userdata entry\n", header->type);
printf("Unknown userdata entry type %u\n", header.type);
continue;
}

View File

@ -21,12 +21,6 @@
#include "system.h"
#include "io.h"
unsigned char bitswap8(unsigned char v)
{
return ((v * 0x0802LU & 0x22110LU) |
(v * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}
alt_u32 bswap32(alt_u32 w)
{
return (((w << 24) & 0xff000000) |

View File

@ -43,6 +43,7 @@
ALT_INLINE alt_32 static alt_epcq_validate_read_write_arguments(alt_epcq_controller_dev *flash_info,alt_u32 offset, alt_u32 length);
alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_flash_info);
ALT_INLINE unsigned char static bitswap8(unsigned char v);
/*
* Public API
@ -334,6 +335,10 @@ int alt_epcq_controller_write_block
/* prepare the word to be written */
memcpy((((void*)&word_to_write)) + padding, ((void*)data) + buffer_offset, bytes_to_copy);
// Bit-reverse bytes for flash
for (int i=0; i<bytes_to_copy; i++)
*((unsigned char*)&word_to_write+i) = bitswap8(*((unsigned char*)&word_to_write+i));
/* update offset and length variables */
buffer_offset += bytes_to_copy;
remaining_length -= bytes_to_copy;
@ -508,6 +513,10 @@ int alt_epcq_controller_read
if(0 == ret_code)
{
memcpy(dest_addr, (alt_u8*)epcq_flash_info->data_base + offset, length);
// Bit-reverse bytes read from flash
for (int i=0; i<length; i++)
*((unsigned char*)dest_addr+i) = bitswap8(*((unsigned char*)dest_addr+i));
}
return ret_code;
@ -794,4 +803,10 @@ alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_
return 0;
}
ALT_INLINE unsigned char static bitswap8(unsigned char v)
{
return ((v * 0x0802LU & 0x22110LU) |
(v * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}