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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [dev/] [txfns.c] - Blame information for rev 51

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

Line No. Rev Author Line
1 47 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    txfns.c
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015-2017, 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 "board.h"
39
#include "txfns.h"
40
 
41
void    txchr(char ch);
42
void    txval(int val);
43
void    txstr(const char *str);
44
 
45
void    txchr(char val) {
46
        volatile IOSPACE *const sys = _sys;
47
        unsigned v = (unsigned char)val;
48
 
49
        // To read whether or not the transmitter is ready, you must first
50
        // clear the interrupt bit.
51
        sys->io_pic = INT_UARTTX;
52
        // If the interrupt bit sets itself again immediately, the transmitter
53
        // is ready.  Otherwise, wait until the transmitter becomes ready.
54
        while((sys->io_pic&INT_UARTTX)==0)
55
                ;
56
        sys->io_uart = (v&0x0ff);
57
        // Give the transmitter a chance to finish, and then to create an
58
        // interrupt when done
59
        sys->io_pic = INT_UARTTX;
60
}
61
 
62
void    txstr(const char *str) {
63
        const   char *ptr = str;
64
        while(*ptr)
65
                txchr(*ptr++);
66
}
67
 
68
void    txval(int val) {
69
        txstr("\r\n0x");
70
        for(int i=28; i>=0; i-=4) {
71
                int ch = ((val>>i)&0x0f)+'0';
72
                if (ch > '9')
73
                        ch = ch - '0'+'A'-10;
74
                txchr(ch);
75
        }
76
}
77
 
78
void    txhex(int val) {
79
        for(int i=28; i>=0; i-=4) {
80
                int ch = ((val>>i)&0x0f)+'0';
81
                if (ch > '9')
82
                        ch = ch - '0'+'A'-10;
83
                txchr(ch);
84
        }
85
        txstr("\r\n");
86
}
87
 

powered by: WebSVN 2.1.0

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