⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 retarget.c

📁 周立功arm7(lpc2104)的工程模板
💻 C
字号:

// *********************************
// LPC2000 SYSTEM WITHOUT OS
// FILE:     RETARGET.C
// MODIFIED: ZPCYP 2005-3-16 20:16
// *********************************

/*
** This implements a 'retarget' layer for low-level IO.  Typically, this
** would contain your own target-dependent implementations of fputc(),
** ferror(), etc.
**
** This example provides implementations of fputc(), ferror(),
** _sys_exit(), _ttywrch() and __user_initial_stackheap().
**
** To output characters from the serial port, use:
**
**     #define USE_SERIAL_PORT
**
** or compile with
**
**     -DUSE_SERIAL_PORT
*/

#define   USE_SERIAL_PORT


#include <stdio.h>
#include <rt_misc.h>
#include "serial.h"


// Ensure no functions that use semihosting SWIs are linked in from the C library
#pragma import(__use_no_semihosting_swi)


struct __FILE { int handle;   /* Add whatever you need here */};
FILE __stdout;
FILE __stdin;


extern unsigned int Bottom_Heap;        /* defined in heap.s */


int fputc(int ch, FILE *f)
{
    /* Place your implementation of fputc here     */
    /* e.g. write a character to a UART, or to the */
    /* debugger console with SWI WriteC            */
    char tempch = ch;
#ifdef USE_SERIAL_PORT
    sendchar( &tempch );
#endif
    return ch;
}


int ferror(FILE *f)
{   /* Your implementation of ferror */
    return EOF;
}


int fgetc(FILE *f) {               // scanf familly need this
#ifdef USE_SERIAL_PORT
    return receivechar();
#else
    return EOF;
#endif
}


void _sys_exit(int return_code)
{
label:  goto label; /* endless loop */
}


void _ttywrch(int ch)
{
    char tempch = ch;
#ifdef USE_SERIAL_PORT
    sendchar( &tempch );
#endif
}


__value_in_regs struct __initial_stackheap __user_initial_stackheap(
        unsigned R0, unsigned SP, unsigned R2, unsigned SL)
{
    struct __initial_stackheap config;

    config.heap_base = (unsigned int)&Bottom_Heap;    // defined in heap.s
                                                      // placed by scatterfile
    config.stack_base = SP;   // inherit SP from the execution environment

    return config;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -