source: rtems/c/src/lib/libbsp/arm/nds/coproc/coproc.c @ ef4c461

4.115
Last change on this file since ef4c461 was ef4c461, checked in by Joel Sherrill <joel.sherrill@…>, on 10/09/14 at 20:35:10

arm/nds: Warning clean up

This patch eliminates most of the warnings in this BSP but attempts
very little clean up. This BSP includes copies of a lot of code
from free NDS libraries and modifications should be kept to a minimum.

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*---------------------------------------------------------------------------------
2
3        default ARM7 core
4
5        Copyright (C) 2005
6                Michael Noland (joat)
7                Jason Rogers (dovoto)
8                Dave Murphy (WinterMute)
9
10        This software is provided 'as-is', without any express or implied
11        warranty.  In no event will the authors be held liable for any
12        damages arising from the use of this software.
13
14        Permission is granted to anyone to use this software for any
15        purpose, including commercial applications, and to alter it and
16        redistribute it freely, subject to the following restrictions:
17
18        1.      The origin of this software must not be misrepresented; you
19                must not claim that you wrote the original software. If you use
20                this software in a product, an acknowledgment in the product
21                documentation would be appreciated but is not required.
22        2.      Altered source versions must be plainly marked as such, and
23                must not be misrepresented as being the original software.
24        3.      This notice may not be removed or altered from any source
25                distribution.
26
27---------------------------------------------------------------------------------*/
28#include <nds.h>
29#include "../include/my_ipc.h"
30
31#ifdef ENABLE_WIFI
32#include <dswifi7.h>
33#endif
34
35//---------------------------------------------------------------------------------
36void startSound(int sampleRate, const void* data, u32 bytes, u8 channel, u8 vol,  u8 pan, u8 format) {
37//---------------------------------------------------------------------------------
38        SCHANNEL_TIMER(channel)  = SOUND_FREQ(sampleRate);
39        SCHANNEL_SOURCE(channel) = (u32)data;
40        SCHANNEL_LENGTH(channel) = bytes >> 2 ;
41        SCHANNEL_CR(channel)     = SCHANNEL_ENABLE | SOUND_ONE_SHOT | SOUND_VOL(vol) | SOUND_PAN(pan) | (format==1?SOUND_8BIT:SOUND_16BIT);
42}
43
44//---------------------------------------------------------------------------------
45s32 getFreeSoundChannel() {
46//---------------------------------------------------------------------------------
47        int i;
48        for (i=0; i<16; i++) {
49                if ( (SCHANNEL_CR(i) & SCHANNEL_ENABLE) == 0 ) return i;
50        }
51        return -1;
52}
53
54
55touchPosition first,tempPos;
56
57//---------------------------------------------------------------------------------
58void VcountHandler() {
59//---------------------------------------------------------------------------------
60        static int lastbut = -1;
61
62        uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;
63
64        but = REG_KEYXY;
65
66        if (!( (but ^ lastbut) & (1<<6))) {
67
68                tempPos = touchReadXY();
69
70                if ( tempPos.x == 0 || tempPos.y == 0 ) {
71                        but |= (1 <<6);
72                        lastbut = but;
73                } else {
74                        x = tempPos.x;
75                        y = tempPos.y;
76                        xpx = tempPos.px;
77                        ypx = tempPos.py;
78                        z1 = tempPos.z1;
79                        z2 = tempPos.z2;
80                }
81
82        } else {
83                lastbut = but;
84                but |= (1 <<6);
85        }
86        IPC->touchX                     = x;
87        IPC->touchY                     = y;
88        IPC->touchXpx           = xpx;
89        IPC->touchYpx           = ypx;
90        IPC->touchZ1            = z1;
91        IPC->touchZ2            = z2;
92        IPC->buttons            = but;
93
94}
95
96//---------------------------------------------------------------------------------
97void VblankHandler(void) {
98//---------------------------------------------------------------------------------
99  static u8 is_recording = 0;
100        u32 i;
101
102        //sound code  :)
103        TransferSound *snd = IPC->soundData;
104        IPC->soundData = 0;
105
106        if (0 != snd) {
107
108                for (i=0; i<snd->count; i++) {
109                        s32 chan = getFreeSoundChannel();
110
111                        if (chan >= 0) {
112                                startSound(snd->data[i].rate, snd->data[i].data, snd->data[i].len, chan, snd->data[i].vol, snd->data[i].pan, snd->data[i].format);
113                        }
114                }
115        }
116
117        // microphone code
118        if (!is_recording && my_IPC->record)
119          {
120            StartRecording((u8 *)my_IPC->record_buffer, my_IPC->record_length_max);
121            is_recording = 1;
122          }
123
124        if (is_recording && !my_IPC->record)
125          {
126            my_IPC->recorded_length = 1 + StopRecording();
127            is_recording = 0;
128          }
129
130#ifdef ENABLE_WIFI
131        Wifi_Update(); // update wireless in vblank
132#endif
133}
134
135#ifdef ENABLE_WIFI
136// callback to allow wifi library to notify arm9
137void arm7_synctoarm9() { // send fifo message
138   REG_IPC_FIFO_TX = 0x87654321;
139}
140// interrupt handler to allow incoming notifications from arm9
141void arm7_fifo() { // check incoming fifo messages
142   u32 msg = REG_IPC_FIFO_RX;
143   if(msg==0x87654321) Wifi_Sync();
144}
145#endif
146
147//---------------------------------------------------------------------------------
148int main(int argc, char ** argv) {
149//---------------------------------------------------------------------------------
150#ifdef ENABLE_WIFI
151  REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; // enable & prepare
152                                                           // fifo asap
153#endif
154
155  // read User Settings from firmware
156  readUserSettings();
157
158  //enable sound
159  powerON(POWER_SOUND);
160  writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP );
161  SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F);
162
163  irqInit();
164
165  // Start the RTC tracking IRQ
166  initClockIRQ();
167
168  SetYtrigger(80);
169  irqSet(IRQ_VCOUNT, VcountHandler);
170  irqSet(IRQ_VBLANK, VblankHandler);
171  irqSet(IRQ_TIMER0, ProcessMicrophoneTimerIRQ);
172
173  irqEnable(IRQ_VBLANK | IRQ_VCOUNT | IRQ_TIMER0);
174
175#ifdef ENABLE_WIFI
176  irqSet(IRQ_WIFI, Wifi_Interrupt); // set up wifi interrupt
177  irqEnable(IRQ_WIFI);
178
179  // sync with arm9 and init wifi
180  u32 fifo_temp;
181
182  while (1)
183    { // wait for magic number
184      while (REG_IPC_FIFO_CR & IPC_FIFO_RECV_EMPTY)
185        swiWaitForVBlank();
186      fifo_temp = REG_IPC_FIFO_RX;
187      if (fifo_temp == 0x12345678)
188        break;
189    }
190  while (REG_IPC_FIFO_CR & IPC_FIFO_RECV_EMPTY)
191    swiWaitForVBlank();
192  fifo_temp = REG_IPC_FIFO_RX;
193  Wifi_Init(fifo_temp);
194
195  irqSet(IRQ_FIFO_NOT_EMPTY,arm7_fifo); // set up fifo irq
196  irqEnable(IRQ_FIFO_NOT_EMPTY);
197  REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ;
198
199  Wifi_SetSyncHandler(arm7_synctoarm9); // allow wifi lib to notify arm9
200#endif
201  // Keep the ARM7 mostly idle
202  while (1) {
203    swiWaitForVBlank();
204  }
205}
206
207
Note: See TracBrowser for help on using the repository browser.