summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/src/smartmedia.hcc
blob: 5c547cc61c3278e027e60439666f1fe26928567b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*! \file smartmedia.hcc
 *
 * \section generic	Here we interface with the SmartMedia card.
 *
 * \section project Project information.
 * Project Graphic Equalizer\n
 * \author O.M. Schinagl
 * \date 20041110
 * \version 0.1
 *
 * \section copyright Copyright
 * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved
 *
 * \section history Change history
 * 20041110: O.M. Schinagl\n	Initial version
 *
 ********************************************************************/

/******** System Includes *************/
#include <stdlib.hch>

#include "pal_master.hch"

/******** Application Includes ********/
#include "configuration.hch"
#include "smartmedia.hch"

#if HAVE_DEBUG
	#include "debug.hch"
#endif



/*! \fn		void smartmedia_init(void);
 * \brief	We here initialize the Smart Media card and verify wether the
 *		card is inserted and such.
 * 
 * \param	void	None.
 *
 * \return	We return 0 on success, 1 on error.
 * \retval	unsigned 1
 */
unsigned 1 smartmedia_init(void) {
	unsigned 1 retval;

	/*
	 * Firstly we enable both the CPLD and the SmartMedia.
	 */
	RC200CPLDEnable();
	RC200SmartMediaInit(&retval);

	/*
	 * In the case of initialization failing, we try to reset the
	 * SmartMedia.
	 */
	if (retval) {
		RC200SmartMediaReset(&retval);
	}

	return retval;	
} /* --- smartmedia_init() --- */



/*! \fn		void smartmedia_loaddata(RAM_BANK0);
 * \brief	We load our memory with skin and help data from the smartmedia.
 * 
 * \param	RAM_BANK0	Handle to RAM_BANK0
 *
 * \return	void
 * \retval	void
 */
macro proc smartmedia_loaddata(RAM_BANK0) {
	/*
	 * Setup RAM Handle, and determin maximum Data and Address widths
	 */
	macro expr DW = PalPL2RAMGetMaxDataWidthCT();
	macro expr AW = PalPL2RAMGetMaxAddressWidthCT();

	unsigned DW data;
	unsigned 27 smartmedia_address, smartmedia_address_mask;
	unsigned AW address;
	unsigned 8 mask, r, g, b;
	unsigned 1 result;

#if HAVE_DEBUG
	/*
	 * Print some nice stats about data loading.
	 */
	print_eol();
	print_hex_value(0);
#endif
	/*
	 * Before we enter our loop to fill our memory with valid data, we have
	 * to set the startup positions for the SmartMedia.
	 */
	smartmedia_address = SMARTMEDIA_ADDRESS_SKIN_START;
	smartmedia_address_mask = SMARTMEDIA_ADDRESS_SKINMASK_START;
	/*
	 * We start with the address of the skin, and do the loop until we have
	 * done the end of the help.
	 */
	for (address = ADDRESS_SKIN_START; address != (ADDRESS_HELP_END +1); address++) {
		/*
		 * Once we are done with the loading of our skin, we need to
		 * change the smartmedia start addresses.
		 */
		if (address == ADDRESS_HELP_START) {
			smartmedia_address = SMARTMEDIA_ADDRESS_HELP_START;
			smartmedia_address_mask = SMARTMEDIA_ADDRESS_HELPMASK_START;
		}

		/*
		 * Before reading our data from the smartmedia we set our
		 * address pointer to the address from our loop.
		 */
		PalPL2RAMSetWriteAddress(RAM_BANK0, address);

		/*
		 * SmartMedia data is read one byte per call. Because we want
		 * to store the mask + the rgb values in one variable for later
		 * useage we need to read those 4 bytes from the smartmedia
		 * before storing it as one.
		 */
#if HAVE_SMARTMEDIA
		/*
		 * FIXME: Due to a bug in the DK2 smartmedia libraries we need
		 * stop reading after each byte with OperationEnd call. This is
		 * VERY slow and must be changed.
		 */
	#if !USE_MASK_ONLY
		RC200SmartMediaSetAddress(READ, smartmedia_address);
		RC200SmartMediaRead(&r, TRUE);
		RC200SmartMediaOperationEnd(&result);
		RC200SmartMediaSetAddress(READ, (smartmedia_address +1));
		RC200SmartMediaRead(&g, TRUE);
		RC200SmartMediaOperationEnd(&result);
		RC200SmartMediaSetAddress(READ, (smartmedia_address +2));
		RC200SmartMediaRead(&b, TRUE);
		RC200SmartMediaOperationEnd(&result);
	#endif
		RC200SmartMediaSetAddress(READ, smartmedia_address_mask);
		RC200SmartMediaRead(&mask, TRUE);
		RC200SmartMediaOperationEnd(&result);

		data = 0 @ mask @ r @ g @ b;
#else
		data = 0xff000f00;
#endif
		/*
		 * Now that we have gathered all pixel data, store it in ram.
		 */
		PalPL2RAMWrite(RAM_BANK0, data);

#if HAVE_DEBUG
		/*
		 * Print some nice stats about data loading.
		 */
		if (!address[11:0]) {
			print_cr();
			print_hex_value(0 @ (address \\ 12));
			print_string(" / 00000096 | data: ");
			print_hex_value(data <- 32);
		}
#endif

		/*
		 * Finally increase al our indexes approperiatly.
		 */
		smartmedia_address += 3;
		smartmedia_address_mask++;
	}
} /* --- smartmedia_loaddata() --- */