- 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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "libsys.h"
#include "cfiflash.h" #include "cfiflash.h"
UINT32 cfi_get_status(flash_t *pObj) uint32_t cfi_get_status(flash_t *pObj)
{ {
volatile UINT32 *pF; volatile uint32_t *pF;
UINT32 status; uint32_t status;
pF = (UINT32*)pObj->pBase; pF = (uint32_t*)pObj->pBase;
*pF = 0x00700070; *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; int i;
UINT8 *pInfo; uint8_t *pInfo;
UINT32 endian; uint32_t endian;
UINT8 *pEndian; uint8_t *pEndian;
pObj->pBase = (void*)base_addr; pObj->pBase = (void*)base_addr;
pInfo = (UINT8*)&pObj->info; pInfo = (uint8_t*)&pObj->info;
for (i=0; i < sizeof(flash_info_t); i++) for (i=0; i < sizeof(flash_info_t); i++)
{ {
pInfo[i] = 0; pInfo[i] = 0;
} }
pObj->eb = 0; pObj->eb = 0;
endian = 0x12345678; endian = 0x12345678;
pEndian = (UINT8*)&endian; pEndian = (uint8_t*)&endian;
if (*pEndian == 0x12) if (*pEndian == 0x12)
{ {
pObj->eb = 1; 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; int i;
volatile UINT32 *pF; volatile uint32_t *pF;
volatile UINT16 *pF16; volatile uint16_t *pF16;
// UINT8 qry_ref[12] = {0x51, 0x00, 0x51, 0x00, 0x52, 0x00, 0x52, 0x00, 0x59, 0x00, 0x59, 0x00}; // uint8_t qry_ref[12] = {0x51, 0x00, 0x51, 0x00, 0x52, 0x00, 0x52, 0x00, 0x59, 0x00, 0x59, 0x00};
UINT32 size; uint32_t size;
pF = (UINT32*)pObj->pBase; pF = (uint32_t*)pObj->pBase;
pF16 = (UINT16*)pObj->pBase; pF16 = (uint16_t*)pObj->pBase;
// Look for flash // Look for flash
*pF = 0x00980098; *pF = 0x00980098;
// for (i=0; i < sizeof(qry_ref); i++) // 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; // return (UINT32)-1;
*pF = 0x00FF00FF; *pF = 0x00FF00FF;
@@ -81,31 +80,31 @@ UINT32 cfi_find(flash_t *pObj)
*/ */
pObj->info.num_flash = 2; pObj->info.num_flash = 2;
pObj->info.if_width = 32; pObj->info.if_width = 32;
size = (UINT32)pF16[2*0x27]; size = (uint32_t)pF16[2*0x27];
pObj->info.flashsize = pObj->info.num_flash; pObj->info.flashsize = pObj->info.num_flash;
for (i=0; i < size; i++) for (i=0; i < size; i++)
pObj->info.flashsize *= 2; 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; pObj->info.wbuf_size = pObj->info.num_flash;
for (i=0; i < size; i++) for (i=0; i < size; i++)
pObj->info.wbuf_size *= 2; pObj->info.wbuf_size *= 2;
pObj->info.nblocks = (UINT32)(pF16[2*0x2E] << 8 | pF16[2*0x2D]) + 1; pObj->info.nblocks = (uint32_t)(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.blocksize = pObj->info.num_flash * ((uint32_t)(pF16[2*0x30] << 8 | pF16[2*0x2F]) * 256);
*pF = 0x00FF00FF; *pF = 0x00FF00FF;
return 0; 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; volatile uint32_t *pF;
UINT32 status, block_index, block_mask; uint32_t status, block_index, block_mask;
UINT32 error; uint32_t error;
pF = (UINT32*)pObj->pBase; pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4)) if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM; return CFI_ERR_INVPARAM;
@@ -115,19 +114,19 @@ UINT32 cfi_block_is_locked(flash_t *pObj, UINT32 word_index)
*pF = 0x00900090; *pF = 0x00900090;
error = ((UINT32)pF[block_index+2] & 0x00010001) != 0; error = ((uint32_t)pF[block_index+2] & 0x00010001) != 0;
*pF = 0x00FF00FF; *pF = 0x00FF00FF;
return error; 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; volatile uint32_t *pF;
UINT32 status, block_index, block_mask; uint32_t status, block_index, block_mask;
UINT32 error; uint32_t error;
pF = (UINT32*)pObj->pBase; pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4)) if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM; return CFI_ERR_INVPARAM;
@@ -155,13 +154,13 @@ UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index)
return error; 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; volatile uint32_t *pF;
UINT32 status, block_index, block_mask; uint32_t status, block_index, block_mask;
UINT32 error; uint32_t error;
pF = (UINT32*)pObj->pBase; pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4)) if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM; return CFI_ERR_INVPARAM;
@@ -189,13 +188,13 @@ UINT32 cfi_block_lock(flash_t *pObj, UINT32 word_index)
return error; 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; volatile uint32_t *pF;
UINT32 status, block_index, block_mask; uint32_t status, block_index, block_mask;
UINT32 error; uint32_t error;
pF = (UINT32*)pObj->pBase; pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4)) if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM; return CFI_ERR_INVPARAM;
@@ -223,12 +222,12 @@ UINT32 cfi_block_unlock(flash_t *pObj, UINT32 word_index)
return error; 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; volatile uint32_t *pF;
UINT32 status, error; uint32_t status, error;
pF = (UINT32*)pObj->pBase; pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4)) if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM; 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; int i, j, k;
volatile UINT32 *pF; volatile uint32_t *pF;
UINT32 status, bcurr, bnext, block_mask, nblock_write, nbuf_write; uint32_t status, bcurr, bnext, block_mask, nblock_write, nbuf_write;
UINT32 error; uint32_t error;
pF = (UINT32*)pObj->pBase; pF = (uint32_t*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4)) if (word_index >= (pObj->info.flashsize/4))
return CFI_ERR_INVPARAM; return CFI_ERR_INVPARAM;
@@ -322,7 +321,7 @@ UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT3
pF[bcurr] = 0x00FF00FF; pF[bcurr] = 0x00FF00FF;
} }
if (IS_ERROR(error)) if (CFI_IS_ERROR(error))
{ {
pF[bcurr] = 0x00FF00FF; pF[bcurr] = 0x00FF00FF;
break; 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); cfi_init(pObj, base_addr);
return cfi_find(pObj); 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; int i;
UINT32 offset_end, error; uint32_t offset_end, error;
if (size % 4) if (size % 4)
size = 4*(size/4 + 1); 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)) if (cfi_block_is_locked(pObj, i/4))
{ {
error = cfi_block_unlock(pObj, i/4); error = cfi_block_unlock(pObj, i/4);
if (IS_ERROR(error)) if (CFI_IS_ERROR(error))
break; break;
} }
error = cfi_block_erase(pObj, i/4); error = cfi_block_erase(pObj, i/4);
if (IS_ERROR(error)) if (CFI_IS_ERROR(error))
break; 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) if (size % 4)
size = 4*(size/4 + 1); 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; int i;
UINT8 *pF; uint8_t *pF;
pF = (UINT8*)(pObj->pBase + offset); pF = (uint8_t*)(pObj->pBase + offset);
for (i=0; i < size; i++) for (i=0; i < size; i++)
if (pF[i] != pData[i]) if (pF[i] != pData[i])
@@ -389,9 +388,9 @@ UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size)
return 0; 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; blocknum = offset/pObj->info.blocksize;
if (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; 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) if (blocknum >= pObj->info.nblocks)
blocknum = pObj->info.nblocks - 1; 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; 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; return flash_get_blocknum_by_offset(pObj, offset) * pObj->info.blocksize;
} }
+25 -24
View File
@@ -2,7 +2,7 @@
#ifndef CFIFLASH_H #ifndef CFIFLASH_H
#define CFIFLASH_H #define CFIFLASH_H
#include "libsys.h" #include <stdint.h>
#define SR_BIT_DPS 0x00020002 #define SR_BIT_DPS 0x00020002
#define SR_BIT_PSS 0x00040004 #define SR_BIT_PSS 0x00040004
@@ -12,7 +12,8 @@
#define SR_BIT_ESS 0x00400040 #define SR_BIT_ESS 0x00400040
#define SR_BIT_ISMS 0x00800080 #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_GENERAL (CFI_ERR_BASE + 0)
#define CFI_ERR_NOTFOUND (CFI_ERR_BASE + 1) #define CFI_ERR_NOTFOUND (CFI_ERR_BASE + 1)
#define CFI_ERR_INVPARAM (CFI_ERR_BASE + 2) #define CFI_ERR_INVPARAM (CFI_ERR_BASE + 2)
@@ -21,38 +22,38 @@
typedef struct _sflash_info_t typedef struct _sflash_info_t
{ {
UINT32 flashsize; uint32_t flashsize;
UINT32 blocksize; uint32_t blocksize;
UINT32 nblocks; uint32_t nblocks;
UINT32 wbuf_size; uint32_t wbuf_size;
UINT32 if_width; uint32_t if_width;
UINT32 num_flash; uint32_t num_flash;
} flash_info_t; } flash_info_t;
typedef struct _sflash_t typedef struct _sflash_t
{ {
void *pBase; void *pBase;
UINT32 eb; uint32_t eb;
flash_info_t info; flash_info_t info;
} flash_t; } flash_t;
void cfi_init(flash_t *pObj, UINT32 base_addr); void cfi_init(flash_t *pObj, uint32_t base_addr);
UINT32 cfi_find(flash_t *pObj); uint32_t cfi_find(flash_t *pObj);
UINT32 cfi_block_is_locked(flash_t *pObj, UINT32 word_index); uint32_t cfi_block_is_locked(flash_t *pObj, uint32_t word_index);
UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index); uint32_t cfi_block_erase(flash_t *pObj, uint32_t word_index);
UINT32 cfi_block_lock(flash_t *pObj, UINT32 word_index); uint32_t cfi_block_lock(flash_t *pObj, uint32_t word_index);
UINT32 cfi_block_unlock(flash_t *pObj, UINT32 word_index); uint32_t cfi_block_unlock(flash_t *pObj, uint32_t word_index);
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);
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);
UINT32 flash_get_offset_by_blocknum(flash_t *pObj, UINT32 blocknum); uint32_t flash_get_offset_by_blocknum(flash_t *pObj, uint32_t blocknum);
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 flash_get_offset_blockaligned(flash_t *pObj, UINT32 offset); uint32_t flash_get_offset_blockaligned(flash_t *pObj, uint32_t offset);
UINT32 flash_find(flash_t *pObj, UINT32 base_addr); uint32_t flash_find(flash_t *pObj, uint32_t base_addr);
UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size); uint32_t flash_erase(flash_t *pObj, uint32_t offset, uint32_t 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);
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);
#endif // CFIFLASH_H #endif // CFIFLASH_H