Fix code style

This commit is contained in:
George Oikonomou 2018-04-07 14:32:00 +01:00
parent f88b195de4
commit f6bd7ba47a
3 changed files with 39 additions and 47 deletions

View File

@ -113,13 +113,15 @@ static spi_device_t flash_spi_configuration_default = {
/**
* Get spi configuration, return default configuration if NULL
*/
static spi_device_t*
get_spi_conf(spi_device_t *conf) {
static spi_device_t *
get_spi_conf(spi_device_t *conf)
{
if(conf == NULL) {
return &flash_spi_configuration_default;
}
return conf;
}/*---------------------------------------------------------------------------*/
}
/*---------------------------------------------------------------------------*/
/**
* Clear external flash CSN line
*/
@ -334,7 +336,7 @@ ext_flash_open(spi_device_t *conf)
/* Put the part is standby mode */
power_standby(flash_spi_configuration);
if (verify_part(flash_spi_configuration) == VERIFY_PART_OK) {
if(verify_part(flash_spi_configuration) == VERIFY_PART_OK) {
return true;
}
@ -353,7 +355,7 @@ ext_flash_close(spi_device_t *conf)
/* Put the part in low power mode */
ret = power_down(flash_spi_configuration);
/* SPI is released no matter if power_down() succeeds or fails */
if(spi_release(flash_spi_configuration) != SPI_DEV_STATUS_OK) {
return false;
@ -474,7 +476,7 @@ ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length)
uint8_t wbuf[4];
uint32_t i, numsectors;
uint32_t endoffset = offset + length - 1;
spi_device_t *flash_spi_configuration;
flash_spi_configuration = get_spi_conf(conf);

View File

@ -43,44 +43,41 @@
#include "contiki-conf.h"
#include "dev/xmem.h"
/*** MX25R8035F Memory Organization
The memory is organized as:
8Mbit = 1048576 bytes (8 bits each)
256 sectors (32 Kbits, 4096 bytes each)
4096 pages (256 bytes each).
Each page can be individually programmed (bits are programmed from 1 to 0). The device is
sector or bulk erasable (bits are erased from 0 to 1) but not page erasable
*/
#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL //Total size of the External Flash Memory in the Z1
/*
* MX25R8035F Memory Organization
* The memory is organized as:
* 8Mbit = 1048576 bytes (8 bits each)
* 256 sectors (32 Kbits, 4096 bytes each)
* 4096 pages (256 bytes each).
* Each page can be individually programmed (bits are programmed from 1 to 0).
* The device is sector or bulk erasable (bits are erased from 0 to 1) but not
* page erasable
*/
#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL /* Total size of the External Flash Memory in the Z1 */
/* Coffee configuration parameters. */
#define COFFEE_SECTOR_SIZE 4096UL
#define COFFEE_SECTOR_SIZE 4096UL
#define COFFEE_PAGE_SIZE 256UL
#define COFFEE_START 0UL //COFFEE_SECTOR_SIZE
#define COFFEE_START 0UL /* COFFEE_SECTOR_SIZE */
#define COFFEE_SIZE (COFFEE_XMEM_TOTAL_SIZE_KB * 1024UL - COFFEE_START)
#define COFFEE_NAME_LENGTH 16
#define COFFEE_MAX_OPEN_FILES 6
#define COFFEE_FD_SET_SIZE 8
#define COFFEE_LOG_TABLE_LIMIT 256
#define COFFEE_DYN_SIZE 2*1024
#define COFFEE_DYN_SIZE 2 * 1024
#define COFFEE_LOG_SIZE 1024
#define COFFEE_MICRO_LOGS 1
/* Flash operations. */
#define COFFEE_WRITE(buf, size, offset) \
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))
#define COFFEE_WRITE(buf, size, offset) \
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))
#define COFFEE_READ(buf, size, offset) \
xmem_pread((char *)(buf), (size), COFFEE_START + (offset))
#define COFFEE_READ(buf, size, offset) \
xmem_pread((char *)(buf), (size), COFFEE_START + (offset))
#define COFFEE_ERASE(sector) \
xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE)
#define COFFEE_ERASE(sector) \
xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE)
/* Coffee types. */
typedef int16_t coffee_page_t;

View File

@ -49,21 +49,17 @@
#define XMEM_BUFF_LENGHT 128
#if 0
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...) do {} while (0)
#define PRINTF(...) do {} while(0)
#endif
void
xmem_init(void)
{
ext_flash_open(NULL);
}
int
xmem_pread(void *_p, int size, unsigned long addr)
{
@ -80,21 +76,20 @@ xmem_pread(void *_p, int size, unsigned long addr)
}
rv = ext_flash_read(NULL, addr, size, _p);
for (i = 0; i < size; i++){
for(i = 0; i < size; i++) {
x = ~*((uint8_t *)_p + i);
*((uint8_t *)_p+i) = x;
*((uint8_t *)_p + i) = x;
}
ext_flash_close(NULL);
if(rv)
if(rv) {
return size;
}
PRINTF("Could not read flash memory!\n");
return -1;
}
}
int
xmem_pwrite(const void *_buf, int size, unsigned long addr)
{
@ -112,13 +107,13 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
return -1;
}
for (remain = size, j = 0; remain > 0; remain -= XMEM_BUFF_LENGHT, j += XMEM_BUFF_LENGHT) {
for(remain = size, j = 0; remain > 0; remain -= XMEM_BUFF_LENGHT, j += XMEM_BUFF_LENGHT) {
int to_write = MIN(XMEM_BUFF_LENGHT, remain);
for (i = 0; i < to_write; i++) {
for(i = 0; i < to_write; i++) {
tmp_buf[i] = ~*((uint8_t *)_buf + j + i);
}
rv = ext_flash_write(NULL, addr + j, to_write, tmp_buf);
if (!rv) {
if(!rv) {
PRINTF("Could not write flash memory!\n");
return size - remain;
}
@ -128,8 +123,6 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
return size;
}
int
xmem_erase(long size, unsigned long addr)
{
@ -137,7 +130,6 @@ xmem_erase(long size, unsigned long addr)
rv = ext_flash_open(NULL);
if(!rv) {
PRINTF("Could not open flash to save config\n");
ext_flash_close(NULL);
@ -160,8 +152,9 @@ xmem_erase(long size, unsigned long addr)
watchdog_periodic();
if(rv)
if(rv) {
return size;
}
PRINTF("Could not erase flash memory\n");
return -1;