BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
m25p.h
Go to the documentation of this file.
1 /* Copyright 2013-2014, Peter A. Bigot
2  *
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 are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
68 #ifndef BSP430_UTILITY_M25P_H
69 #define BSP430_UTILITY_M25P_H
70 
71 #include <bsp430/core.h>
72 #include <bsp430/serial.h>
73 #include <bsp430/periph/port.h>
74 
88 #ifndef configBSP430_PLATFORM_M25P
89 #define configBSP430_PLATFORM_M25P 0
90 #endif /* configBSP430_PLATFORM_M25P */
91 
110 #if defined(BSP430_DOXYGEN)
111 #define BSP430_PLATFORM_M25P include <bsp430/platform.h>
112 #endif /* BSP430_DOXYGEN */
113 
114 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_PLATFORM_M25P_SPI_CTL0_BYTE)
115 
129 #define BSP430_PLATFORM_M25P_SPI_CTL0_BYTE BSP430_SERIAL_ADJUST_CTL0_INITIALIZER(UCCKPL | UCMSB | UCMST)
130 #endif /* BSP430_PLATFORM_M25P_SPI_CTL0_BYTE */
131 
132 #if defined(BSP430_DOXYGEN)
133 
136 #define BSP430_PLATFORM_M25P_SPI_PERIPH_HANDLE include <bsp430/platform.h>
137 
141 #define BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE include <bsp430/platform.h>
142 
146 #define BSP430_PLATFORM_M25P_PWR_PORT_BIT include <bsp430/platform.h>
147 
151 #define BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE include <bsp430/platform.h>
152 
156 #define BSP430_PLATFORM_M25P_RSTn_PORT_BIT include <bsp430/platform.h>
157 
161 #define BSP430_PLATFORM_M25P_CSn_PORT_PERIPH_HANDLE include <bsp430/platform.h>
162 
166 #define BSP430_PLATFORM_M25P_CSn_PORT_BIT include <bsp430/platform.h>
167 
172 #define BSP430_PLATFORM_M25P_SUPPORTS_PE include <bsp430/platform.h>
173 
181 #define BSP430_PLATFORM_M25P_SUPPORTS_PW include <bsp430/platform.h>
182 
186 #define BSP430_PLATFORM_M25P_SECTOR_SIZE include <bsp430/platform.h>
187 
194 #define BSP430_PLATFORM_M25P_SUBSECTOR_SIZE include <bsp430/platform.h>
195 
199 #define BSP430_PLATFORM_M25P_SECTOR_COUNT include <bsp430/platform.h>
200 
201 #endif /* BSP430_DOXYGEN */
202 
206 typedef struct sBSP430m25p {
219  uint8_t csn_bit;
222  uint8_t rstn_bit;
223 } sBSP430m25p;
224 
227 
229 #define BSP430_M25P_CMD_WREN 0x06
230 
231 #define BSP430_M25P_CMD_WRDI 0x04
232 
233 #define BSP430_M25P_CMD_RDID 0x9f
234 
235 #define BSP430_M25P_CMD_RDSR 0x05
236 
237 #define BSP430_M25P_CMD_WRSR 0x01
238 
239 #define BSP430_M25P_CMD_WRLR 0xe5
240 
241 #define BSP430_M25P_CMD_RDLR 0xe8
242 
243 #define BSP430_M25P_CMD_READ 0x03
244 
245 #define BSP430_M25P_CMD_FAST_READ 0x0b
246 
247 #define BSP430_M25P_CMD_PW 0x0a
248 
249 #define BSP430_M25P_CMD_PP 0x02
250 
251 #define BSP430_M25P_CMD_PE 0xdb
252 
255 #define BSP430_M25P_CMD_SSE 0x20
256 
257 #define BSP430_M25P_CMD_SE 0xd8
258 
259 #define BSP430_M25P_CMD_BE 0xc7
260 
261 #define BSP430_M25P_CMD_DP 0xb9
262 
263 #define BSP430_M25P_CMD_RELDP 0xab
264 
265 #define BSP430_M25P_CMD_RES 0xab
266 
268 #define BSP430_M25P_SR_WIP 0x01
269 
270 #define BSP430_M25P_SR_WEL 0x02
271 
273 #define BSP430_M25P_SR_BP0 0x04
274 
276 #define BSP430_M25P_SR_BP1 0x08
277 
279 #define BSP430_M25P_SR_SRWD 0x80
280 
282 #define BSP430_M25P_RESET_SET(dev_) do { \
283  if (NULL != (dev_)->rstn_port) { \
284  (dev_)->rstn_port->out &= ~(dev_)->rstn_bit; \
285  } \
286  } while (0)
287 
289 #define BSP430_M25P_RESET_CLEAR(dev_) do { \
290  if (NULL != (dev_)->rstn_port) { \
291  (dev_)->rstn_port->out |= (dev_)->rstn_bit; \
292  } \
293  } while (0)
294 
297 #define BSP430_M25P_CS_ASSERT(dev_) do { \
298  (dev_)->csn_port->out &= ~(dev_)->csn_bit; \
299  } while (0)
300 
302 #define BSP430_M25P_CS_DEASSERT(dev_) do { \
303  (dev_)->csn_port->out |= (dev_)->csn_bit; \
304  } while (0)
305 
306 
331  unsigned char ctl0_byte,
332  unsigned char ctl1_byte,
333  unsigned int prescaler);
334 
348 
354 static BSP430_CORE_INLINE
356 {
358  int rv;
359 
361  rv = iBSP430m25pStatus_rh(dev);
363  return rv;
364 }
365 
383  uint8_t cmd);
384 
405  uint8_t cmd,
406  unsigned long addr);
407 
430  uint8_t cmd);
431 
456  uint8_t cmd,
457  unsigned long addr);
458 
479  const uint8_t * tx_data,
480  size_t tx_len,
481  size_t rx_len,
482  uint8_t * rx_data);
483 
484 #endif /* BSP430_UTILITY_M25P_H */
#define BSP430_CORE_RESTORE_INTERRUPT_STATE(state_)
Definition: core.h:731
int iBSP430m25pStrobeAddressCommand_rh(hBSP430m25p dev, uint8_t cmd, unsigned long addr)
hBSP430m25p hBSP430m25pInitialize(hBSP430m25p dev, unsigned char ctl0_byte, unsigned char ctl1_byte, unsigned int prescaler)
Common header included by all BSP430 leaf headers.
Definition: serial_.h:193
int iBSP430m25pInitiateCommand_rh(hBSP430m25p dev, uint8_t cmd)
#define BSP430_CORE_INLINE
Definition: core.h:439
#define BSP430_CORE_SAVED_INTERRUPT_STATE(var_)
Definition: core.h:719
int iBSP430m25pCompleteTxRx_rh(hBSP430m25p dev, const uint8_t *tx_data, size_t tx_len, size_t rx_len, uint8_t *rx_data)
Declarations for abstracted serial interface.
int iBSP430m25pStrobeCommand_rh(hBSP430m25p dev, uint8_t cmd)
volatile sBSP430hplPORT * rstn_port
Definition: m25p.h:216
int iBSP430m25pStatus_rh(hBSP430m25p dev)
sBSP430m25p * hBSP430m25p
Definition: m25p.h:226
hBSP430halSERIAL spi
Definition: m25p.h:209
Definition: port.h:529
Hardware presentation/abstraction for Digital I/O Port (PORT#/PORT#_R)
volatile sBSP430hplPORT * csn_port
Definition: m25p.h:212
#define BSP430_CORE_DISABLE_INTERRUPT()
Definition: core.h:762
static BSP430_CORE_INLINE int iBSP430m25pStatus(hBSP430m25p dev)
Definition: m25p.h:355
uint8_t rstn_bit
Definition: m25p.h:222
Definition: m25p.h:206
struct sBSP430m25p sBSP430m25p
uint8_t csn_bit
Definition: m25p.h:219
int iBSP430m25pInitiateAddressCommand_rh(hBSP430m25p dev, uint8_t cmd, unsigned long addr)