2013-03-15 15:14:09 +00:00
|
|
|
/**
|
2013-07-12 07:53:53 +00:00
|
|
|
* \addtogroup mbxxx-platform
|
2013-03-15 15:14:09 +00:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-11-10 11:20:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010, STMicroelectronics.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Coffee architecture-dependent header for the STM32W108-based mb851
|
2013-03-15 15:14:09 +00:00
|
|
|
* platform. STM32W108 has 128KB of program flash.
|
2010-11-10 11:20:44 +00:00
|
|
|
* \author
|
|
|
|
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CFS_COFFEE_ARCH_H
|
|
|
|
#define CFS_COFFEE_ARCH_H
|
|
|
|
|
|
|
|
#include "contiki-conf.h"
|
|
|
|
|
|
|
|
#include "hal/error.h"
|
|
|
|
#include "hal/micro/cortexm3/flash.h"
|
|
|
|
|
2013-03-15 15:14:09 +00:00
|
|
|
/*
|
|
|
|
* STM32W108 has 128KB of program flash in 128 pages of 1024 bytes each = 128KB.
|
2010-11-10 11:20:44 +00:00
|
|
|
* The smallest erasable unit is one page and the smallest writable
|
|
|
|
* unit is an aligned 16-bit half-word.
|
|
|
|
*/
|
2013-03-15 15:14:09 +00:00
|
|
|
/* Byte page size, starting address on page boundary, and size of file system */
|
2010-11-10 11:20:44 +00:00
|
|
|
#define FLASH_START 0x8000000
|
|
|
|
/* Minimum erasable unit. */
|
|
|
|
#define FLASH_PAGE_SIZE 1024
|
|
|
|
/* Last 3 pages reserved for NVM. */
|
|
|
|
#define FLASH_PAGES 125
|
|
|
|
|
|
|
|
/* Minimum reservation unit for Coffee. It can be changed by the user. */
|
|
|
|
#define COFFEE_PAGE_SIZE (FLASH_PAGE_SIZE/4)
|
|
|
|
|
2013-03-15 15:14:09 +00:00
|
|
|
/*
|
|
|
|
* If using IAR, COFFEE_ADDRESS reflects the static value in the linker script
|
|
|
|
* iar-cfg-coffee.icf, so it can't be passed as a parameter for Make.
|
|
|
|
*/
|
2010-11-10 11:20:44 +00:00
|
|
|
#ifdef __ICCARM__
|
2011-03-21 12:11:52 +00:00
|
|
|
#define COFFEE_ADDRESS 0x8010c00
|
2010-11-10 11:20:44 +00:00
|
|
|
#endif
|
2013-03-15 15:14:09 +00:00
|
|
|
#if (COFFEE_ADDRESS & 0x3FF) != 0
|
|
|
|
#error "COFFEE_ADDRESS not aligned to a 1024-bytes page boundary."
|
2010-12-15 15:01:00 +00:00
|
|
|
#endif
|
2013-03-15 15:14:09 +00:00
|
|
|
|
|
|
|
#define COFFEE_PAGES ((FLASH_PAGES*FLASH_PAGE_SIZE- \
|
|
|
|
(COFFEE_ADDRESS-FLASH_START))/COFFEE_PAGE_SIZE)
|
2010-11-10 11:20:44 +00:00
|
|
|
#define COFFEE_START (COFFEE_ADDRESS & ~(COFFEE_PAGE_SIZE-1))
|
|
|
|
#define COFFEE_SIZE (COFFEE_PAGES*COFFEE_PAGE_SIZE)
|
|
|
|
|
|
|
|
/* These must agree with the parameters passed to makefsdata */
|
|
|
|
#define COFFEE_SECTOR_SIZE FLASH_PAGE_SIZE
|
|
|
|
#define COFFEE_NAME_LENGTH 20
|
|
|
|
|
2013-03-15 15:14:09 +00:00
|
|
|
/* These are used internally by the AVR flash read routines */
|
|
|
|
/* Word reads are faster but take 130 bytes more PROGMEM */
|
|
|
|
/* #define FLASH_WORD_READS 1 */
|
|
|
|
/*
|
|
|
|
* 1 = Slower reads, but no page writes after erase and 18 bytes less PROGMEM.
|
|
|
|
* Best for dynamic file system
|
|
|
|
*/
|
|
|
|
/* #define FLASH_COMPLEMENT_DATA 0 */
|
2010-11-10 11:20:44 +00:00
|
|
|
|
|
|
|
/* These are used internally by the coffee file system */
|
|
|
|
#define COFFEE_MAX_OPEN_FILES 4
|
|
|
|
#define COFFEE_FD_SET_SIZE 8
|
|
|
|
#define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE*1)
|
2013-03-15 15:14:09 +00:00
|
|
|
/* Micro logs are not needed for single page sectors */
|
2010-11-10 11:20:44 +00:00
|
|
|
#define COFFEE_MICRO_LOGS 0
|
2013-03-15 15:14:09 +00:00
|
|
|
#define COFFEE_LOG_TABLE_LIMIT 16 /* It doesnt' matter as */
|
|
|
|
#define COFFEE_LOG_SIZE 128 /* COFFEE_MICRO_LOGS is 0. */
|
2010-11-10 11:20:44 +00:00
|
|
|
|
2011-03-21 12:11:52 +00:00
|
|
|
#if COFFEE_PAGES <= 127
|
|
|
|
#define coffee_page_t int8_t
|
|
|
|
#elif COFFEE_PAGES <= 0x7FFF
|
|
|
|
#define coffee_page_t int16_t
|
2010-11-10 11:20:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define COFFEE_WRITE(buf, size, offset) \
|
|
|
|
stm32w_flash_write(COFFEE_START + offset, buf, size)
|
|
|
|
|
|
|
|
#define COFFEE_READ(buf, size, offset) \
|
|
|
|
stm32w_flash_read(COFFEE_START + offset, buf, size)
|
|
|
|
|
|
|
|
#define COFFEE_ERASE(sector) \
|
|
|
|
stm32w_flash_erase(sector)
|
|
|
|
|
|
|
|
|
2013-03-15 15:14:09 +00:00
|
|
|
void stm32w_flash_read(uint32_t address, void *data, uint32_t length);
|
|
|
|
|
|
|
|
void stm32w_flash_write(uint32_t address, const void *data, uint32_t length);
|
|
|
|
|
|
|
|
void stm32w_flash_erase(uint8_t sector);
|
2010-11-10 11:20:44 +00:00
|
|
|
|
|
|
|
int coffee_file_test(void);
|
|
|
|
|
|
|
|
#endif /* !COFFEE_ARCH_H */
|
2013-03-15 15:14:09 +00:00
|
|
|
/** @} */
|