summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/src/main.hcc
blob: ba3d22c4224203ff14be1d5ceae2a7950c06d0ed (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
/*! \file main.hcc
 *
 * \section generic Message build up information and more
 *
 * \section project Project information.
 * Project Graphic Equalizer\n
 * \author O.M. Schinagl
 * \date 20041011
 * \version 0.1
 *
 * \section copyright Copyright
 * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved
 *
 * \section history Change history
 * 20041011: O.M. Schinagl\n	Initial version
 *
 *****************************************************************************/

/*
 * Set the Clock rate for this domain. 25.175 Mhz is required for the Video output.
 */
#define PAL_TARGET_CLOCK_RATE 25175000

/******** System Includes *************/
#include "pal_master.hch"

/******** Application Includes ********/
#include "configuration.hch"
#include "audio.hch"
#include "mouse_shared.hch"
#include "eventhandler_shared.hch"
#include "display_shared.hch"
#include "mouse.hch"
#include "eventhandler.hch"
#include "display.hch"
#include "smartmedia.hch"

#include "fft.hch"
#include "runfft.hch"

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

/*! \fn		void main(void);
 * \brief	Main Application Loop.
 * 
 * \return	void
 * \retval	void
 */
void main(void) {
	/*
	 * Set VideoOut, Audio I/O and Ram Handles and set clockrate.
	 */
	macro expr ClockRate = PAL_ACTUAL_CLOCK_RATE;
	macro expr VideoOut = PalVideoOutOptimalCT(ClockRate);
	macro expr AudioIn  = PalAudioInCT(0);
	macro expr AudioOut = PalAudioOutCT(0);
	macro expr RAM_BANK0 = PalPL2RAMCT(0);

	mousedata_t mousedata;
	events_t events;
	audiodata_t audiodata;
	skindata_t skindata;
	unsigned 1 result;

	/*
	 * Check library versions and Request various hardware functionality.
	 * We need at least Major Version 1. For Audio purposes we need atleast
	 * minor version 2.
	 */
	PalVersionRequire(1, 2);
	PalVideoOutRequire(1);
	PalAudioInRequire(1);
	PalAudioOutRequire(1);
	PalPL2RAMRequire(1);

	/*
	 * We verify some datawidths here at compile time. This to ensure
	 * successfull operation.
	 */
	assert (PalVideoOutGetColorWidthCT(VideoOut) == 24, 0, 
		"We need a 24-bit color Display.");
	assert (PalPL2RAMGetDataWidthCT(RAM_BANK0) >= 32, 0, 
		"We can't work with anything less then 32 bits wide ram.");

	/*
	 * Run The Following main tasks in parallel.
	 */
	par {
		/*
		 * Primary task is to 'Run' several hardware simultaniously.
		 */
		PalVideoOutRun(VideoOut, ClockRate);
		MouseRun(ClockRate);
		PalAudioInRun(AudioIn, ClockRate);
		PalAudioOutRun(AudioOut, ClockRate);
		PalPL2RAMRun(RAM_BANK0, ClockRate);
#if HAVE_SMARTMEDIA
		/*
		 * The smartmedia device needs the CPLD to run also.
		 */
		CPLDRun(ClockRate);
		SmartMediaRun(ClockRate);
#endif
#if HAVE_DEBUG
		RC200RS232Run(RC200RS232_115200Baud, RC200RS232ParityNone,
			RC200RS232FlowControlNone, ClockRate);
#endif
		
		/*
		 * Parallel to our Primary tasks we run the application.
		 */
		seq {
			/*
			 * But first we need to initialize Video and Audio.
			 * We also load the data from the SmartMedia card
			 * into the ram.
			 */
#if HAVE_DEBUG
			print_eol();
			print_string("Graphic Equalizer 2");
			print_eol();
#endif
			PalVideoOutEnable(VideoOut);
			PalAudioInEnable(AudioIn);
			PalAudioOutEnable(AudioOut);
			audio_init(LINE_IN, SR_44100, AudioIn, AudioOut);
#if HAVE_SMARTMEDIA
			/*
			 * Once we properly setup the SmartMedia we load our
			 * data folowed by our main program loop.
			 */
			result = smartmedia_init();
			if (!result) {
#endif
				smartmedia_loaddata(&skindata);

				/*
				 * Main application starts here!
				 */
				par {
					/*
					 * From here we run the mouse driver, audio
					 * and display in parallel. None of these
					 * should ever return.
					 */
					mouse_main(&mousedata);
					display_main(&skindata, &audiodata, &events, &mousedata);
					eventhandler_main(&audiodata, &events, &mousedata, &skindata);
					audio_main(audiodata, AudioIn, AudioOut);
				}
#if HAVE_SMARTMEDIA
			} else {
#if HAVE_DEBUG
				print_string("Error Initializing SmartMedia");
#endif
			}
#endif
		}
	}

} /* --- main() --- */