RTEMS 7.0-rc1
Loading...
Searching...
No Matches
m93cxx.h
1/*
2 * RTEMS generic MPC5200 BSP
3 *
4 * This file contains definitions for the M93Cxx EEPROM devices.
5 *
6 * M93C46 is a serial microwire EEPROM which contains
7 * 1Kbit (128 bytes/64 words) of non-volatile memory.
8 * The device can be configured for byte- or word-
9 * access. The driver provides a file-like interface
10 * to this memory.
11 *
12 * MPC5x00 PIN settings:
13 *
14 * PSC3_6 (output) -> MC93C46 serial data in (D)
15 * PSC3_7 (input) -> MC93C46 serial data out (Q)
16 * PSC3_8 (output) -> MC93C46 chip select input (S)
17 * PSC3_9 (output) -> MC93C46 serial clock (C)
18 */
19
20/*
21 * Copyright (C) 2005 embedded brains GmbH & Co. KG
22 * Copyright (C) 2003 IPR Engineering
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGE.
44 */
45
46#ifndef __M93CXX_H__
47#define __M93CXX_H__
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53static void m93cxx_enable_write(void);
54static void m93cxx_disable_write(void);
55static void m93cxx_write_byte(uint32_t, uint8_t);
56static uint8_t m93cxx_read_byte(uint32_t);
57void wait_usec(unsigned long);
58
59#define M93CXX_MODE_WORD
60/*#define M93C46_MODE_BYTE*/
61#define M93C46
62#define M93C46_NVRAM_SIZE 128
63
64#define GPIO_PSC3_6 (1 << 12)
65#define GPIO_PSC3_7 (1 << 13)
66#define GPIO_PSC3_8 (1 << 26)
67#define GPIO_PSC3_9 (1 << 26)
68
69#define START_BIT 0x1
70#define EWDS_OPCODE 0x0
71#define WRAL_OPCODE 0x1
72#define ERAL_OPCODE 0x2
73#define EWEN_OPCODE 0x3
74#define WRITE_OPCODE 0x4
75#define READ_OPCODE 0x8
76#define ERASE_OPCODE 0xC
77
78#define WAIT(i) wait_usec(i)
79
80#define ENABLE_CHIP_SELECT mpc5200.gpiosido |= GPIO_PSC3_8
81#define DISABLE_CHIP_SELECT mpc5200.gpiosido &= ~GPIO_PSC3_8
82#define SET_DATA_BIT_HIGH mpc5200.gpiosdo |= GPIO_PSC3_6
83#define SET_DATA_BIT_LOW mpc5200.gpiosdo &= ~GPIO_PSC3_6
84
85#ifdef M93CXX_MODE_BYTE
86#define GET_DATA_BYTE_SHIFT(val) ((val) |= ((mpc5200.gpiosdi & GPIO_PSC3_7) >> 13)); \
87 ((val) <<= 1)
88#define SET_DATA_BYTE_SHIFT(val) (((val) & 0x80) ? (mpc5200.gpiosdo |= GPIO_PSC3_6) : (mpc5200.gpiosdo &= ~GPIO_PSC3_6)); \
89 ((val) <<= 1)
90#else
91#define GET_DATA_WORD_SHIFT(val) ((val) |= ((mpc5200.gpiosdi & GPIO_PSC3_7) >> 13)); \
92 ((val) <<= 1)
93#define SET_DATA_WORD_SHIFT(val) (((val) & 0x8000) ? (mpc5200.gpiosdo |= GPIO_PSC3_6) : (mpc5200.gpiosdo &= ~GPIO_PSC3_6)); \
94 ((val) <<= 1)
95#endif
96
97#define MASK_HEAD_SHIFT(head) ((((head) & 0x80000000) >> 31) ? (mpc5200.gpiosdo |= GPIO_PSC3_6) : (mpc5200.gpiosdo &= ~GPIO_PSC3_6)); \
98 ((head) <<= 1)
99#define DO_CLOCK_CYCLE mpc5200.gpiowdo |= GPIO_PSC3_9; \
100 WAIT(1000); \
101 mpc5200.gpiowdo &= ~GPIO_PSC3_9
102#define CHECK_WRITE_BUSY while(!(mpc5200.gpiosdi & GPIO_PSC3_7))
103
104
105#ifdef M93CXX_MODE_BYTE
106#ifdef M93C46
107#define M93C46_EWDS ((START_BIT << 31) | (EWDS_OPCODE << 27))
108#define M93C46_WRAL ((START_BIT << 31) | (WRAL_OPCODE << 27))
109#define M93C46_ERAL ((START_BIT << 31) | (ERAL_OPCODE << 27))
110#define M93C46_EWEN ((START_BIT << 31) | (EWEN_OPCODE << 27))
111#define M93C46_READ(addr) ((START_BIT << 31) | (READ_OPCODE << 27) | ((addr) << 22))
112#define M93C46_WRITE(addr) ((START_BIT << 31) | (WRITE_OPCODE << 27) | ((addr) << 22))
113#define M93C46_ERASE(addr) ((START_BIT << 31) | (ERASE_OPCODE << 27) | ((addr) << 22))
114#define M93C46_CLOCK_CYCLES 10
115#endif
116#else
117#ifdef M93C46
118#define M93C46_EWDS ((START_BIT << 31) | (EWDS_OPCODE << 27))
119#define M93C46_WRAL ((START_BIT << 31) | (WRAL_OPCODE << 27))
120#define M93C46_ERAL ((START_BIT << 31) | (ERAL_OPCODE << 27))
121#define M93C46_EWEN ((START_BIT << 31) | (EWEN_OPCODE << 27))
122#define M93C46_READ(addr) ((START_BIT << 31) | (READ_OPCODE << 27) | ((addr) << 23))
123#define M93C46_WRITE(addr) ((START_BIT << 31) | (WRITE_OPCODE << 27) | ((addr) << 23))
124#define M93C46_ERASE(addr) ((START_BIT << 31) | (ERASE_OPCODE << 27) | ((addr) << 23))
125#define M93C46_CLOCK_CYCLES 9
126#endif
127#endif
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* __M93CXX_H__ */