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

Subversion Repositories s6soc

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

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

powered by: WebSVN 2.1.0

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