zeroplus: Add support for additional memory sizes

The zeroplus can have up to a 8M SRAM. Avoid some extensive if/else
blocks by noting that all sizes except the first are related by their power
of 2.
This commit is contained in:
Russ Dill 2013-12-02 21:57:04 -08:00 committed by Bert Vermeulen
parent e93fb98b8a
commit 3e43da1f70
2 changed files with 35 additions and 9 deletions

View File

@ -43,10 +43,16 @@
#define STATUS_FLAG_READ 0x10
#define STATUS_FLAG_20 0x20
/* In bytes */
#define MEMORY_SIZE_8K 0x00
#define MEMORY_SIZE_64K 0x01
#define MEMORY_SIZE_128K 0x02
#define MEMORY_SIZE_256K 0x03
#define MEMORY_SIZE_512K 0x04
#define MEMORY_SIZE_1M 0x05
#define MEMORY_SIZE_2M 0x06
#define MEMORY_SIZE_4M 0x07
#define MEMORY_SIZE_8M 0x08
#define STATUS_BUSY 0x01 /* WTF / ??? */
#define STATUS_READY 0x02

View File

@ -23,16 +23,38 @@ SR_PRIV unsigned int get_memory_size(int type)
{
if (type == MEMORY_SIZE_8K)
return 8 * 1024;
else if (type == MEMORY_SIZE_64K)
return 64 * 1024;
else if (type == MEMORY_SIZE_128K)
return 128 * 1024;
else if (type == MEMORY_SIZE_512K)
return 512 * 1024;
else if (type <= MEMORY_SIZE_8M)
return (32 * 1024) << type;
else
return 0;
}
SR_PRIV int clz(unsigned int x)
{
int n = 0;
if (x == 0)
return 32;
if (!(x & 0xFFFF0000)) {
n = n + 16;
x = x << 16;
}
if (!(x & 0xFF000000)) {
n = n + 8;
x = x << 8;
}
if (!(x & 0xF0000000)) {
n = n + 4;
x = x << 4;
}
if (!(x & 0xC0000000)) {
n = n + 2;
x = x << 2;
}
if (!(x & 0x80000000))
n = n + 1;
return n;
}
SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples)
{
devc->limit_samples = samples;
@ -41,10 +63,8 @@ SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples)
devc->memory_size = MEMORY_SIZE_8K;
else if (samples <= 16 * 1024)
devc->memory_size = MEMORY_SIZE_64K;
else if (samples <= 32 * 1024 || devc->max_memory_size <= 32 * 1024)
devc->memory_size = MEMORY_SIZE_128K;
else
devc->memory_size = MEMORY_SIZE_512K;
devc->memory_size = 19 - clz(samples - 1);
sr_info("Setting memory size to %dK.",
get_memory_size(devc->memory_size) / 1024);