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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [dev/] [helloworld.c] - Blame information for rev 53

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    helloworld.c
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     A very simple program.  This program tests the LEDs, buttons,
8
//              and UART.  Specifically, if run, this program will cycle through
9
//      the LEDs at one change per second.  If one button is pressed, it will
10
//      cycle through turning one LED off once per second while turning the 
11
//      rest on.  If the other button is pressed, two LED's will never turn on.
12
//
13
//      To test the UART, the message "Hello, world!" will be sent to the UART
14
//      at the top of each second.
15
//
16
//      This program is simple.  Although it uses the interrupt controller,
17
//      interrupts are disabled throughout the program.  The interrupt
18
//      controller is only used to determine when events have taken place.
19
//
20
// Creator:     Dan Gisselquist, Ph.D.
21
//              Gisselquist Technology, LLC
22
//
23
////////////////////////////////////////////////////////////////////////////////
24
//
25 45 dgisselq
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
26 12 dgisselq
//
27
// This program is free software (firmware): you can redistribute it and/or
28
// modify it under the terms of  the GNU General Public License as published
29
// by the Free Software Foundation, either version 3 of the License, or (at
30
// your option) any later version.
31
//
32
// This program is distributed in the hope that it will be useful, but WITHOUT
33
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
34
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35
// for more details.
36
//
37
// You should have received a copy of the GNU General Public License along
38
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
39
// target there if the PDF file isn't present.)  If not, see
40
// <http://www.gnu.org/licenses/> for a copy.
41
//
42
// License:     GPL, v3, as defined and found on www.gnu.org,
43
//              http://www.gnu.org/licenses/gpl.html
44
//
45
//
46
////////////////////////////////////////////////////////////////////////////////
47
//
48
//
49
#include "board.h"
50
 
51
const char msg[] = "Hello, world!\r\n";
52
 
53
void entry(void) {
54 45 dgisselq
        volatile IOSPACE *const sys = (IOSPACE *)IOADDR;
55 12 dgisselq
        int     ledset = 0;
56
 
57 53 dgisselq
        sys->io_pic  = 0x07fffffff; // Acknowledge and turn off all ints
58 12 dgisselq
 
59 53 dgisselq
// sys->io_watchdog = TM_ONE_SECOND * 2;
60
_scope->s_ctrl = 2 | WBSCOPE_NO_RESET;
61
 
62
        sys->io_spio = 0x0fc;
63
 
64 12 dgisselq
        /// Turn off timer B
65 45 dgisselq
        sys->io_watchdog = 0;
66 12 dgisselq
 
67
        while(1) {
68
                const char      *ptr;
69 45 dgisselq
                sys->io_timer = TM_ONE_SECOND; // Ticks per second, 80M
70 12 dgisselq
                sys->io_pic  = 0x07fffffff; // Acknowledge and turn off all ints
71 53 dgisselq
                sys->io_pic  = INT_ENABLEV(INT_BUTTON);
72 12 dgisselq
 
73
                ptr = msg;
74
                while(*ptr) {
75 45 dgisselq
                        unsigned iv = *(unsigned char *)ptr++;
76
 
77 12 dgisselq
                        // Wait while our transmitter is busy
78
                        while((sys->io_pic & INT_UARTTX)==0)
79
                                ;
80 53 dgisselq
 
81 45 dgisselq
                        sys->io_uart = iv; // Transmit our character
82 12 dgisselq
                        sys->io_pic  = INT_UARTTX; // Clear the int flag
83
                }
84
 
85
                // Now, wait for the top of the second
86 45 dgisselq
                while((sys->io_pic & INT_TIMER)==0)
87 12 dgisselq
                        ;
88
 
89
                ledset <<= 1;
90
                ledset &= 15;
91
                if (ledset == 0)
92
                        ledset = 1;
93
                ledset |= 0xf0;
94
 
95
                int     btn = sys->io_spio;
96
                if (btn&0x10)
97
                        sys->io_spio = ledset^0x0f;
98
                else if (btn&0x20)
99
                        sys->io_spio = ledset&0x0f5;
100
                else
101
                        sys->io_spio = ledset;
102 53 dgisselq
sys->io_watchdog = 0;
103 12 dgisselq
        }
104
}
105
 

powered by: WebSVN 2.1.0

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