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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_AT91SAM3U256_IAR/] [AT91Lib/] [peripherals/] [dbgu/] [dbgu.c] - Blame information for rev 580

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 580 jeremybenn
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 *
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright notice,
12
 * this list of conditions and the disclaimer below.
13
 *
14
 * Atmel's name may not be used to endorse or promote products derived from
15
 * this software without specific prior written permission.
16
 *
17
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * ----------------------------------------------------------------------------
28
 */
29
 
30
//------------------------------------------------------------------------------
31
//         Headers
32
//------------------------------------------------------------------------------
33
 
34
#include "dbgu.h"
35
#include <stdarg.h>
36
#include <board.h>
37
 
38
//------------------------------------------------------------------------------
39
//         Global functions
40
//------------------------------------------------------------------------------
41
//------------------------------------------------------------------------------
42
/// Initializes the DBGU with the given parameters, and enables both the
43
/// transmitter and the receiver. The mode parameter contains the value of the
44
/// DBGU_MR register.
45
/// Value DBGU_STANDARD can be used for mode to get the most common configuration
46
/// (i.e. aysnchronous, 8bits, no parity, 1 stop bit, no flow control).
47
/// \param mode  Operating mode to configure.
48
/// \param baudrate  Desired baudrate (e.g. 115200).
49
/// \param mck  Frequency of the system master clock in Hz.
50
//------------------------------------------------------------------------------
51
void DBGU_Configure(
52
    unsigned int mode,
53
    unsigned int baudrate,
54
    unsigned int mck)
55
{
56
    // Reset & disable receiver and transmitter, disable interrupts
57
    AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
58
    AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF;
59
 
60
    // Configure baud rate
61
    AT91C_BASE_DBGU->DBGU_BRGR = mck / (baudrate * 16);
62
 
63
    // Configure mode register
64
    AT91C_BASE_DBGU->DBGU_MR = mode;
65
 
66
    // Disable DMA channel
67
    AT91C_BASE_DBGU->DBGU_PTCR = AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS;
68
 
69
    // Enable receiver and transmitter
70
    AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RXEN | AT91C_US_TXEN;
71
}
72
 
73
//------------------------------------------------------------------------------
74
/// Outputs a character on the DBGU line.
75
/// \note This function is synchronous (i.e. uses polling).
76
/// \param c  Character to send.
77
//------------------------------------------------------------------------------
78
void DBGU_PutChar(unsigned char c)
79
{
80
    // Wait for the transmitter to be ready
81
    while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY) == 0);
82
 
83
    // Send character
84
    AT91C_BASE_DBGU->DBGU_THR = c;
85
 
86
    // Wait for the transfer to complete
87
    while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY) == 0);
88
}
89
 
90
//------------------------------------------------------------------------------
91
/// Return 1 if a character can be read in DBGU
92
//------------------------------------------------------------------------------
93
unsigned int DBGU_IsRxReady()
94
{
95
    return (AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY);
96
}
97
 
98
//------------------------------------------------------------------------------
99
/// Reads and returns a character from the DBGU.
100
/// \note This function is synchronous (i.e. uses polling).
101
/// \return Character received.
102
//------------------------------------------------------------------------------
103
unsigned char DBGU_GetChar(void)
104
{
105
    while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY) == 0);
106
    return AT91C_BASE_DBGU->DBGU_RHR;
107
}
108
 
109
#ifndef NOFPUT
110
#include <stdio.h>
111
 
112
//------------------------------------------------------------------------------
113
/// \exclude
114
/// Implementation of fputc using the DBGU as the standard output. Required
115
/// for printf().
116
/// \param c  Character to write.
117
/// \param pStream  Output stream.
118
/// \param The character written if successful, or -1 if the output stream is
119
/// not stdout or stderr.
120
//------------------------------------------------------------------------------
121
signed int fputc(signed int c, FILE *pStream)
122
{
123
    if ((pStream == stdout) || (pStream == stderr)) {
124
 
125
        DBGU_PutChar(c);
126
        return c;
127
    }
128
    else {
129
 
130
        return EOF;
131
    }
132
}
133
 
134
//------------------------------------------------------------------------------
135
/// \exclude
136
/// Implementation of fputs using the DBGU as the standard output. Required
137
/// for printf(). Does NOT currently use the PDC.
138
/// \param pStr  String to write.
139
/// \param pStream  Output stream.
140
/// \return Number of characters written if successful, or -1 if the output
141
/// stream is not stdout or stderr.
142
//------------------------------------------------------------------------------
143
signed int fputs(const char *pStr, FILE *pStream)
144
{
145
    signed int num = 0;
146
 
147
    while (*pStr != 0) {
148
 
149
        if (fputc(*pStr, pStream) == -1) {
150
 
151
            return -1;
152
        }
153
        num++;
154
        pStr++;
155
    }
156
 
157
    return num;
158
}
159
 
160
#undef putchar
161
 
162
//------------------------------------------------------------------------------
163
/// \exclude
164
/// Outputs a character on the DBGU.
165
/// \param c  Character to output.
166
/// \return The character that was output.
167
//------------------------------------------------------------------------------
168
signed int putchar(signed int c)
169
{
170
    return fputc(c, stdout);
171
}
172
 
173
#endif //#ifndef NOFPUT
174
 

powered by: WebSVN 2.1.0

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