OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [dev/] [kptest.c] - Blame information for rev 29

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    kptest.c
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     To test and demonstrate that the keypad works.
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
#include "asmstartup.h"
39
#include "board.h"
40
#include "keypad.h"
41
 
42
void    txchr(char v) {
43
        volatile IOSPACE        *sys = (IOSPACE *)IOADDR;
44
        if (v < 10)
45
                return;
46
        v &= 0x07f;
47
        sys->io_pic = INT_UARTTX;
48
        while((sys->io_pic&INT_UARTTX)==0)
49
                ;
50
        sys->io_uart = v;
51
}
52
 
53
void    txstr(const char *str) {
54
        const char *ptr = str;
55
        while(*ptr) {
56
                txchr(*ptr++);
57
        }
58
}
59
 
60
void entry(void) {
61
        register IOSPACE        *sys = (IOSPACE *)0x0100;
62
 
63
        sys->io_pic = 0x07fffffff; // Acknowledge and turn off all interrupts
64
        sys->io_spio = 0x0f0;
65
        sys->io_tima = 100000 | TM_REPEAT;
66
 
67
        txstr("Press any keypad button for test.\r\n");
68
 
69
        while(1) {
70
                int     ch;
71
                while(0 == (sys->io_pic & INT_KEYPAD))
72
                        ;
73
                sys->io_pic = INT_KEYPAD | INT_TIMA;
74
                // Wait 5 ms
75
                for(int i=0; i<5; i++) {
76
                        while(0 == (sys->io_pic & INT_TIMA))
77
                                ;
78
                }
79
                sys->io_spio = 0x011;
80
                ch = keypadread();
81
                if (ch < 0)
82
                        ; // txstr("Unknown key pressed or error\n");
83
                else if (ch < 10)
84
                        txchr(ch+'0');
85
                else if (ch == 15)
86
                        txstr("F\r\n");
87
                else if (ch < 15)
88
                        txchr(ch+'A'-10);
89
                else txstr("Unknown key pressed\n");
90
                keypad_wait_for_release();
91
                sys->io_spio = 0x010;
92
        }
93
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.