| 1 |
12 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: doorbell.c
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
| 6 |
|
|
//
|
| 7 |
|
|
// Purpose: To test the PWM device by playing a doorbell sound every five
|
| 8 |
|
|
// seconds.
|
| 9 |
|
|
//
|
| 10 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
| 11 |
|
|
// Gisselquist Technology, LLC
|
| 12 |
|
|
//
|
| 13 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 14 |
|
|
//
|
| 15 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
| 16 |
|
|
//
|
| 17 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 18 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 19 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 20 |
|
|
// your option) any later version.
|
| 21 |
|
|
//
|
| 22 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 23 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 24 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 25 |
|
|
// for more details.
|
| 26 |
|
|
//
|
| 27 |
|
|
// You should have received a copy of the GNU General Public License along
|
| 28 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
| 29 |
|
|
// target there if the PDF file isn't present.) If not, see
|
| 30 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
| 31 |
|
|
//
|
| 32 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 33 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 34 |
|
|
//
|
| 35 |
|
|
//
|
| 36 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 37 |
|
|
//
|
| 38 |
|
|
//
|
| 39 |
|
|
#include "asmstartup.h"
|
| 40 |
|
|
#include "board.h"
|
| 41 |
|
|
|
| 42 |
|
|
#include "samples.c"
|
| 43 |
|
|
|
| 44 |
|
|
const char msg[] = "Doorbell!\r\n\r\n";
|
| 45 |
|
|
|
| 46 |
|
|
void entry(void) {
|
| 47 |
|
|
register IOSPACE *sys = (IOSPACE *)0x0100;
|
| 48 |
|
|
|
| 49 |
|
|
sys->io_timb = 0;
|
| 50 |
|
|
sys->io_pic = 0x07fffffff; // Acknowledge and turn off all interrupts
|
| 51 |
|
|
|
| 52 |
|
|
sys->io_spio = 0x0f4;
|
| 53 |
|
|
sys->io_pwm_audio = 0x0110000;
|
| 54 |
|
|
while(1) {
|
| 55 |
|
|
int seconds = 0, pic;
|
| 56 |
|
|
const int *ptr;
|
| 57 |
|
|
const char *mptr = msg;
|
| 58 |
|
|
sys->io_tima = TM_ONE_SECOND | TM_REPEAT; // Ticks per second, 80M
|
| 59 |
|
|
|
| 60 |
|
|
sys->io_spio = 0x0f0;
|
| 61 |
|
|
ptr = sound_data;
|
| 62 |
|
|
sys->io_pwm_audio = 0x0310000;
|
| 63 |
|
|
if (ptr == sound_data)
|
| 64 |
|
|
sys->io_spio = 0x0f1;
|
| 65 |
|
|
while(ptr < &sound_data[NSAMPLE_WORDS]) {
|
| 66 |
|
|
sys->io_spio = 0x022;
|
| 67 |
|
|
do {
|
| 68 |
|
|
pic = sys->io_pic;
|
| 69 |
|
|
if (pic & INT_TIMA)
|
| 70 |
|
|
seconds++;
|
| 71 |
|
|
if ((pic & INT_UARTTX)&&(*mptr))
|
| 72 |
|
|
sys->io_uart = *mptr++;
|
| 73 |
|
|
sys->io_pic = (pic & 0x07fff);
|
| 74 |
|
|
} while((pic & INT_AUDIO)==0);
|
| 75 |
|
|
sys->io_pwm_audio = (*ptr >> 16)&0x0ffff;
|
| 76 |
|
|
// Now, turn off the audio interrupt since it doesn't
|
| 77 |
|
|
// reset itself ...
|
| 78 |
|
|
sys->io_pic = INT_AUDIO;
|
| 79 |
|
|
|
| 80 |
|
|
do {
|
| 81 |
|
|
pic = sys->io_pic;
|
| 82 |
|
|
if (pic & INT_TIMA)
|
| 83 |
|
|
seconds++;
|
| 84 |
|
|
if ((pic & INT_UARTTX)&&(*mptr))
|
| 85 |
|
|
sys->io_uart = *mptr++;
|
| 86 |
|
|
sys->io_pic = (pic & 0x07fff);
|
| 87 |
|
|
} while((pic & INT_AUDIO)==0);
|
| 88 |
|
|
sys->io_pwm_audio = (*ptr++) & 0x0ffff;
|
| 89 |
|
|
|
| 90 |
|
|
// and turn off the audio interrupt again ...
|
| 91 |
|
|
sys->io_pic = INT_AUDIO;
|
| 92 |
|
|
} if (ptr >= &sound_data[NSAMPLE_WORDS])
|
| 93 |
|
|
sys->io_spio = 0x044;
|
| 94 |
|
|
|
| 95 |
|
|
sys->io_spio = 0x088;
|
| 96 |
|
|
sys->io_pwm_audio = 0;
|
| 97 |
|
|
while(seconds < 10) {
|
| 98 |
|
|
pic = sys->io_pic;
|
| 99 |
|
|
if (pic & INT_TIMA)
|
| 100 |
|
|
seconds++;
|
| 101 |
|
|
sys->io_pic = (pic & 0x07fff);
|
| 102 |
|
|
}
|
| 103 |
|
|
sys->io_spio = 0x0ff;
|
| 104 |
|
|
}
|
| 105 |
|
|
}
|
| 106 |
|
|
|