- fixed data types

- removed dependency to libsys

git-svn-id: http://moon:8086/svn/mips@13 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2015-05-15 14:09:15 +00:00
parent 784dd70472
commit 0cbb93605c
2 changed files with 92 additions and 92 deletions
+67 -68
View File
@@ -1,14 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include "libsys.h"
#include "cfiflash.h"
UINT32 cfi_get_status(flash_t *pObj)
uint32_t cfi_get_status(flash_t *pObj)
{
volatile UINT32 *pF;
UINT32 status;
volatile uint32_t *pF;
uint32_t status;
pF = (UINT32*)pObj->pBase;
pF = (uint32_t*)pObj->pBase;
*pF = 0x00700070;
@@ -20,23 +19,23 @@ UINT32 cfi_get_status(flash_t *pObj)
}
void cfi_init(flash_t *pObj, UINT32 base_addr)
void cfi_init(flash_t *pObj, uint32_t base_addr)
{
int i;
UINT8 *pInfo;
UINT32 endian;
UINT8 *pEndian;
uint8_t *pInfo;
uint32_t endian;
uint8_t *pEndian;
pObj->pBase = (void*)base_addr;
pInfo = (UINT8*)&pObj->info;
pInfo = (uint8_t*)&pObj->info;
for (i=0; i < sizeof(flash_info_t); i++)
{
pInfo[i] = 0;
}
pObj->eb = 0;
endian = 0x12345678;
pEndian = (UINT8*)&endian;
pEndian = (uint8_t*)&endian;
if (*pEndian == 0x12)
{
pObj->eb = 1;
@@ -44,21 +43,21 @@ void cfi_init(flash_t *pObj, UINT32 base_addr)
}
UINT32 cfi_find(flash_t *pObj)
uint32_t cfi_find(flash_t *pObj)
{
int i;
volatile UINT32 *pF;
volatile UINT16 *pF16;
// UINT8 qry_ref[12] = {0x51, 0x00, 0x51, 0x00, 0x52, 0x00, 0x52, 0x00, 0x59, 0x00, 0x59, 0x00};
UINT32 size;
volatile uint32_t *pF;
volatile uint16_t *pF16;
// uint8_t qry_ref[12] = {0x51, 0x00, 0x51, 0x00, 0x52, 0x00, 0x52, 0x00, 0x59, 0x00, 0x59, 0x00};
uint32_t size;
pF = (UINT32*)pObj->pBase;
pF16 = (UINT16*)pObj->pBase;
pF = (uint32_t*)pObj->pBase;
pF16 = (uint16_t*)pObj->pBase;
// Look for flash
*pF = 0x00980098;
// for (i=0; i < sizeof(qry_ref); i++)
// if (((UINT8*)(&pF[0x10]))[i] != qry_ref[i])
// if (((uint8_t*)(&pF[0x10]))[i] != qry_ref[i])
// return (UINT32)-1;
*pF = 0x00FF00FF;
@@ -81,31 +80,31 @@ UINT32 cfi_find(flash_t *pObj)
*/
pObj->info.num_flash = 2;
pObj->info.if_width = 32;
size = (UINT32)pF16[2*0x27];
size = (uint32_t)pF16[2*0x27];
pObj->info.flashsize = pObj->info.num_flash;
for (i=0; i < size; i++)
pObj->info.flashsize *= 2;
size = (UINT32)(pF16[2*0x2B] << 8 | pF16[2*0x2A]);
size = (uint32_t)(pF16[2*0x2B] << 8 | pF16[2*0x2A]);
pObj->info.wbuf_size = pObj->info.num_flash;
for (i=0; i < size; i++)
pObj->info.wbuf_size *= 2;
pObj->info.nblocks = (UINT32)(pF16[2*0x2E] << 8 | pF16[2*0x2D]) + 1;
pObj->info.blocksize = pObj->info.num_flash * ((UINT32)(pF16[2*0x30] << 8 | pF16[2*0x2F]) * 256);
pObj->info.nblocks = (uint32_t)(pF16[2*0x2E] << 8 | pF16[2*0x2D]) + 1;
pObj->info.blocksize = pObj->info.num_flash * ((uint32_t)(pF16[2*0x30] << 8 | pF16[2*0x2F]) * 256);
*pF = 0x00FF00FF;
return 0;
}
UINT32 cfi_block_is_locked(flash_t *pObj, UINT32 word_index)
uint32_t cfi_block_is_locked(flash_t *pObj, uint32_t word_index)
{
volatile UINT32 *pF;
UINT32 status, block_index, block_mask;
UINT32 error;
volatile uint32_t *pF;
uint32_t status, block_index, block_mask;
uint32_t error;
pF = (UINT32*)pObj->pBase;
pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM;
@@ -115,19 +114,19 @@ UINT32 cfi_block_is_locked(flash_t *pObj, UINT32 word_index)
*pF = 0x00900090;
error = ((UINT32)pF[block_index+2] & 0x00010001) != 0;
error = ((uint32_t)pF[block_index+2] & 0x00010001) != 0;
*pF = 0x00FF00FF;
return error;
}
UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index)
uint32_t cfi_block_erase(flash_t *pObj, uint32_t word_index)
{
volatile UINT32 *pF;
UINT32 status, block_index, block_mask;
UINT32 error;
volatile uint32_t *pF;
uint32_t status, block_index, block_mask;
uint32_t error;
pF = (UINT32*)pObj->pBase;
pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM;
@@ -155,13 +154,13 @@ UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index)
return error;
}
UINT32 cfi_block_lock(flash_t *pObj, UINT32 word_index)
uint32_t cfi_block_lock(flash_t *pObj, uint32_t word_index)
{
volatile UINT32 *pF;
UINT32 status, block_index, block_mask;
UINT32 error;
volatile uint32_t *pF;
uint32_t status, block_index, block_mask;
uint32_t error;
pF = (UINT32*)pObj->pBase;
pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM;
@@ -189,13 +188,13 @@ UINT32 cfi_block_lock(flash_t *pObj, UINT32 word_index)
return error;
}
UINT32 cfi_block_unlock(flash_t *pObj, UINT32 word_index)
uint32_t cfi_block_unlock(flash_t *pObj, uint32_t word_index)
{
volatile UINT32 *pF;
UINT32 status, block_index, block_mask;
UINT32 error;
volatile uint32_t *pF;
uint32_t status, block_index, block_mask;
uint32_t error;
pF = (UINT32*)pObj->pBase;
pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM;
@@ -223,12 +222,12 @@ UINT32 cfi_block_unlock(flash_t *pObj, UINT32 word_index)
return error;
}
UINT32 cfi_program_single(flash_t *pObj, UINT32 word_index, UINT32 word)
uint32_t cfi_program_single(flash_t *pObj, uint32_t word_index, uint32_t word)
{
volatile UINT32 *pF;
UINT32 status, error;
volatile uint32_t *pF;
uint32_t status, error;
pF = (UINT32*)pObj->pBase;
pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM;
@@ -254,14 +253,14 @@ UINT32 cfi_program_single(flash_t *pObj, UINT32 word_index, UINT32 word)
}
UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT32 num_words)
uint32_t cfi_program_multi(flash_t *pObj, uint32_t word_index, uint32_t *pWords, uint32_t num_words)
{
int i, j, k;
volatile UINT32 *pF;
UINT32 status, bcurr, bnext, block_mask, nblock_write, nbuf_write;
UINT32 error;
volatile uint32_t *pF;
uint32_t status, bcurr, bnext, block_mask, nblock_write, nbuf_write;
uint32_t error;
pF = (UINT32*)pObj->pBase;
pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM;
@@ -322,7 +321,7 @@ UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT3
pF[bcurr] = 0x00FF00FF;
}
if (IS_ERROR(error))
if (CFI_IS_ERROR(error))
{
pF[bcurr] = 0x00FF00FF;
break;
@@ -334,16 +333,16 @@ UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT3
}
UINT32 flash_find(flash_t *pObj, UINT32 base_addr)
uint32_t flash_find(flash_t *pObj, uint32_t base_addr)
{
cfi_init(pObj, base_addr);
return cfi_find(pObj);
}
UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size)
uint32_t flash_erase(flash_t *pObj, uint32_t offset, uint32_t size)
{
int i;
UINT32 offset_end, error;
uint32_t offset_end, error;
if (size % 4)
size = 4*(size/4 + 1);
@@ -355,11 +354,11 @@ UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size)
if (cfi_block_is_locked(pObj, i/4))
{
error = cfi_block_unlock(pObj, i/4);
if (IS_ERROR(error))
if (CFI_IS_ERROR(error))
break;
}
error = cfi_block_erase(pObj, i/4);
if (IS_ERROR(error))
if (CFI_IS_ERROR(error))
break;
}
@@ -367,20 +366,20 @@ UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size)
}
UINT32 flash_program(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size)
uint32_t flash_program(flash_t *pObj, uint32_t offset, uint8_t *pData, uint32_t size)
{
if (size % 4)
size = 4*(size/4 + 1);
return cfi_program_multi(pObj, offset/4, (UINT32*)pData, size/4);
return cfi_program_multi(pObj, offset/4, (uint32_t*)pData, size/4);
}
UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size)
uint32_t flash_verify(flash_t *pObj, uint32_t offset, uint8_t *pData, uint32_t size)
{
int i;
UINT8 *pF;
uint8_t *pF;
pF = (UINT8*)(pObj->pBase + offset);
pF = (uint8_t*)(pObj->pBase + offset);
for (i=0; i < size; i++)
if (pF[i] != pData[i])
@@ -389,9 +388,9 @@ UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size)
return 0;
}
UINT32 flash_get_blocknum_by_offset(flash_t *pObj, UINT32 offset)
uint32_t flash_get_blocknum_by_offset(flash_t *pObj, uint32_t offset)
{
UINT32 blocknum;
uint32_t blocknum;
blocknum = offset/pObj->info.blocksize;
if (offset%pObj->info.blocksize)
@@ -400,7 +399,7 @@ UINT32 flash_get_blocknum_by_offset(flash_t *pObj, UINT32 offset)
return blocknum;
}
UINT32 flash_get_offset_by_blocknum(flash_t *pObj, UINT32 blocknum)
uint32_t flash_get_offset_by_blocknum(flash_t *pObj, uint32_t blocknum)
{
if (blocknum >= pObj->info.nblocks)
blocknum = pObj->info.nblocks - 1;
@@ -408,7 +407,7 @@ UINT32 flash_get_offset_by_blocknum(flash_t *pObj, UINT32 blocknum)
return blocknum*pObj->info.blocksize;
}
UINT32 flash_get_offset_blockaligned(flash_t *pObj, UINT32 offset)
uint32_t flash_get_offset_blockaligned(flash_t *pObj, uint32_t offset)
{
return flash_get_blocknum_by_offset(pObj, offset) * pObj->info.blocksize;
}
+25 -24
View File
@@ -2,7 +2,7 @@
#ifndef CFIFLASH_H
#define CFIFLASH_H
#include "libsys.h"
#include <stdint.h>
#define SR_BIT_DPS 0x00020002
#define SR_BIT_PSS 0x00040004
@@ -12,7 +12,8 @@
#define SR_BIT_ESS 0x00400040
#define SR_BIT_ISMS 0x00800080
#define CFI_ERR_BASE (LSYS_ERR_BASE + 0x00100000)
#define CFI_IS_ERROR(e) ((e & CFI_ERR_BASE) == CFI_ERR_BASE)
#define CFI_ERR_BASE (0x80000000 + 0x00100000)
#define CFI_ERR_GENERAL (CFI_ERR_BASE + 0)
#define CFI_ERR_NOTFOUND (CFI_ERR_BASE + 1)
#define CFI_ERR_INVPARAM (CFI_ERR_BASE + 2)
@@ -21,38 +22,38 @@
typedef struct _sflash_info_t
{
UINT32 flashsize;
UINT32 blocksize;
UINT32 nblocks;
UINT32 wbuf_size;
UINT32 if_width;
UINT32 num_flash;
uint32_t flashsize;
uint32_t blocksize;
uint32_t nblocks;
uint32_t wbuf_size;
uint32_t if_width;
uint32_t num_flash;
} flash_info_t;
typedef struct _sflash_t
{
void *pBase;
UINT32 eb;
uint32_t eb;
flash_info_t info;
} flash_t;
void cfi_init(flash_t *pObj, UINT32 base_addr);
UINT32 cfi_find(flash_t *pObj);
UINT32 cfi_block_is_locked(flash_t *pObj, UINT32 word_index);
UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index);
UINT32 cfi_block_lock(flash_t *pObj, UINT32 word_index);
UINT32 cfi_block_unlock(flash_t *pObj, UINT32 word_index);
UINT32 cfi_program_single(flash_t *pObj, UINT32 word_index, UINT32 word);
UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT32 num_words);
void cfi_init(flash_t *pObj, uint32_t base_addr);
uint32_t cfi_find(flash_t *pObj);
uint32_t cfi_block_is_locked(flash_t *pObj, uint32_t word_index);
uint32_t cfi_block_erase(flash_t *pObj, uint32_t word_index);
uint32_t cfi_block_lock(flash_t *pObj, uint32_t word_index);
uint32_t cfi_block_unlock(flash_t *pObj, uint32_t word_index);
uint32_t cfi_program_single(flash_t *pObj, uint32_t word_index, uint32_t word);
uint32_t cfi_program_multi(flash_t *pObj, uint32_t word_index, uint32_t *pWords, uint32_t num_words);
UINT32 flash_get_offset_by_blocknum(flash_t *pObj, UINT32 blocknum);
UINT32 flash_get_blocknum_by_offset(flash_t *pObj, UINT32 offset);
UINT32 flash_get_offset_blockaligned(flash_t *pObj, UINT32 offset);
UINT32 flash_find(flash_t *pObj, UINT32 base_addr);
UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size);
UINT32 flash_program(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size);
UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size);
uint32_t flash_get_offset_by_blocknum(flash_t *pObj, uint32_t blocknum);
uint32_t flash_get_blocknum_by_offset(flash_t *pObj, uint32_t offset);
uint32_t flash_get_offset_blockaligned(flash_t *pObj, uint32_t offset);
uint32_t flash_find(flash_t *pObj, uint32_t base_addr);
uint32_t flash_erase(flash_t *pObj, uint32_t offset, uint32_t size);
uint32_t flash_program(flash_t *pObj, uint32_t offset, uint8_t *pData, uint32_t size);
uint32_t flash_verify(flash_t *pObj, uint32_t offset, uint8_t *pData, uint32_t size);
#endif // CFIFLASH_H