summaryrefslogtreecommitdiff
path: root/contrib/FreeRTOS_Library/demo_code/consoleprint.c
blob: 569a7a1c27a0158422f0934f236cdc9543f2da3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//*****************************************************************************
//   +--+
//   | ++----+
//   +-++    |
//     |     |
//   +-+--+  |
//   | +--+--+
//   +----+    Copyright (c) 2009 Code Red Technologies Ltd.
//
// consoleprint.c - provides a "print string to console" function that uses
//                  the CodeRed semihosting debug channel functionality.
//
// Software License Agreement
//
// The software is owned by Code Red Technologies and/or its suppliers, and is
// protected under applicable copyright laws.  All rights are reserved.  Any
// use in violation of the foregoing restrictions may subject the user to criminal
// sanctions under applicable laws, as well as to civil liability for the breach
// of the terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT
// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH
// CODE RED TECHNOLOGIES LTD.
//
//*****************************************************************************

#include <stdio.h>
#include <string.h>
#include "consoleprint.h"

/*
 * Prototype for Code Red library stub function that carries out
 * semihosting "SYS_WRITE" operation. Note that Code Red makes no
 * guarantees that the interface to this stub function will not
 * change in future versions of the tools.
 */
#if (defined(__NEWLIB__))
#define LIBSTUB_SYS_WRITE _swiwrite
#else // __REDLIB__
#define LIBSTUB_SYS_WRITE __write
#endif
int LIBSTUB_SYS_WRITE (int, char *, int);

/*
 * consoleprint() -  provides a "print string to console" function that uses
 * the CodeRed semihosting debug channel functionality. Because this can
 * send a full string in one operation, rather than a single character (as
 * using printf will) this will provide faster prints to the console.
 *
 * Input - pointer to zero-terminated character string
 * Returns 0 if successful
 *
 * Note that in order to consoleprint() to actually display to the console,
 * the semihosting interface using stdout must have been setup. The easiest
 * way to do this is to call printf() once at the start of your application
 */
int consoleprint(char *cpstring)
{
	 int slen, res;
	 // Calculate length of string
	 slen = strlen (cpstring);
	 // Call function to carry out semihosting "SYS_WRITE" operation
	 res = LIBSTUB_SYS_WRITE (0, cpstring,slen);	// Note that '0' represents stdout
	 return res;
}