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

Subversion Repositories s6soc

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

Go to most recent revision | 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
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
26
//
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 "asmstartup.h"
50
#include "board.h"
51
 
52
const char msg[] = "Hello, world!\r\n";
53
 
54
void entry(void) {
55
        register IOSPACE        *sys = (IOSPACE *)IOADDR;
56
        int     ledset = 0;
57
 
58
        sys->io_spio = 0x0f0;
59
 
60
        /// Turn off timer B
61
        sys->io_timb = 0;
62
 
63
        while(1) {
64
                const char      *ptr;
65
                sys->io_tima = TM_ONE_SECOND; // Ticks per second, 80M
66
                sys->io_pic  = 0x07fffffff; // Acknowledge and turn off all ints
67
 
68
                ptr = msg;
69
                while(*ptr) {
70
                        // Wait while our transmitter is busy
71
                        while((sys->io_pic & INT_UARTTX)==0)
72
                                ;
73
                        sys->io_uart = *ptr++; // Transmit our character
74
                        sys->io_pic  = INT_UARTTX; // Clear the int flag
75
                }
76
 
77
                // Now, wait for the top of the second
78
                while((sys->io_pic & INT_TIMA)==0)
79
                        ;
80
 
81
                ledset <<= 1;
82
                ledset &= 15;
83
                if (ledset == 0)
84
                        ledset = 1;
85
                ledset |= 0xf0;
86
 
87
                int     btn = sys->io_spio;
88
                if (btn&0x10)
89
                        sys->io_spio = ledset^0x0f;
90
                else if (btn&0x20)
91
                        sys->io_spio = ledset&0x0f5;
92
                else
93
                        sys->io_spio = ledset;
94
        }
95
}
96
 

powered by: WebSVN 2.1.0

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