Contiki 3.x
flash.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Eistec AB.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This file is part of the Mulle platform port of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Flash device driver header file for the Mulle platform.
36  *
37  * \author
38  * Simon Aittamaa <simon.aittamaa@ltu.se>
39  *
40  */
41 
42 #ifndef FLASH_H_
43 #define FLASH_H_
44 
45 #include <stddef.h>
46 #include <stdint.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 typedef enum flash_id {
53  FLASH_ID0 = 0x4,
54 } flash_id_t;
55 
56 typedef enum flash_metrics {
57  FLASH_PAGE_SIZE = 256,
58  FLASH_SECTOR_SIZE = 256 * FLASH_PAGE_SIZE,
59  FLASH_SECTORS = 32,
60  FLASH_SIZE = FLASH_SECTOR_SIZE * FLASH_SECTORS,
61 } flash_metrics_t;
62 
63 typedef enum flash_flags {
64  FLASH_WAIT = (1 << 0),
65  FLASH_FINISH = (1 << 1),
66  FLASH_BLOCKING = FLASH_WAIT | FLASH_FINISH,
67 } flash_flags_t;
68 
69 typedef enum flash_error {
70  E_FLASH_OK = 0,
71  E_FLASH_INVALID_STATUS,
72  E_FLASH_UNKNOWN,
73  E_FLASH_BUSY,
74  E_FLASH_QUEUE_FULL,
75  E_FLASH_QUEUE_EMPTY,
76  E_FLASH_ERASE_FAILED,
77  E_FLASH_WRITE_FAILED,
78 } flash_error_t;
79 
80 typedef uint32_t flash_addr_t;
81 
82 flash_error_t flash_init(void);
83 
84 flash_error_t flash_status(const flash_id_t);
85 
86 flash_error_t flash_read(const flash_id_t, const flash_addr_t, uint8_t *, const uint32_t, const flash_flags_t);
87 /* Read data inverted (~data) */
88 flash_error_t flash_readi(const flash_id_t, const flash_addr_t, uint8_t *, const uint32_t, const flash_flags_t);
89 flash_error_t flash_write(const flash_id_t, const flash_addr_t, const uint8_t *, const uint32_t, const flash_flags_t);
90 /* Write data inverted (~data) */
91 flash_error_t flash_writei(const flash_id_t, const flash_addr_t, const uint8_t *, const uint32_t, const flash_flags_t);
92 
93 flash_error_t flash_write_queue(const flash_id_t, const flash_addr_t, const uint8_t *, const uint32_t, const flash_flags_t);
94 flash_error_t flash_write_process(const flash_flags_t);
95 
96 flash_error_t flash_erase_sector(const flash_id_t, const uint32_t, const flash_flags_t);
97 flash_error_t flash_erase_chip(const flash_id_t, const flash_flags_t);
98 
99 flash_error_t flash_sleep(const flash_id_t, const flash_flags_t);
100 flash_error_t flash_wakeup(const flash_id_t, const flash_flags_t);
101 
102 /* Indended for debugging purposes _ONLY_ -- Simon */
103 flash_error_t flash_dump(const flash_id_t, void (*)(const uint8_t));
104 
105 #ifdef __cplusplus
106 } /* extern "C" */
107 #endif
108 
109 #endif /* !defined(FLASH_H_) */
void flash_write(unsigned short *ptr, unsigned short word)
Write a 16-bit word to flash ROM.
Definition: flash.c:98