retarget.c
资源名称:str711USB.rar [点击查看]
上传用户:yyyd609
上传日期:2022-07-18
资源大小:183k
文件大小:3k
源码类别:
微处理器开发
开发平台:
C/C++
- /*
- * Copyright (C) ARM Limited, 1999. All rights reserved.
- */
- /*
- 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().
- Here, semi-hosting SWIs are used to display text onto the console of the host debugger.
- This mechanism is portable across ARMulator, Angel, Multi-ICE and EmbeddedICE.
- Alternatively, to output characters from the serial port of an ARM Development (PID) Board
- (see serial.c), use '#define USE_SERIAL_PORT' or compile with '-DUSE_SERIAL_PORT'.
- */
- #include <stdio.h>
- #include "71x_conf.h"
- /* #define USE_SERIAL_PORT */
- #ifdef __thumb
- /* Thumb Semihosting SWI */
- #define SemiSWI 0xAB
- #else
- /* ARM Semihosting SWI */
- #define SemiSWI 0x123456
- #endif
- /* Write a character */
- __swi(SemiSWI) void _WriteC(unsigned op, char *c);
- #define WriteC(c) _WriteC (0x3,c)
- /* Exit */
- __swi(SemiSWI) void _Exit(unsigned op, unsigned except);
- #define Exit() _Exit (0x18,0x20026)
- struct __FILE { int handle; /* Add whatever you need here */};
- FILE __stdout;
- extern void sendchar( char *ch ); /* in serial.c */
- 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 );
- #else
- WriteC( &tempch );
- #endif
- return ch;
- }
- int ferror(FILE *f)
- { /* Your implementation of ferror */
- return EOF;
- }
- void _sys_exit(int return_code)
- {
- Exit(); /* for debugging */
- label: goto label; /* endless loop */
- }
- void _ttywrch(int ch)
- {
- char tempch = ch;
- #ifdef USE_SERIAL_PORT
- sendchar( &tempch );
- #else
- WriteC( &tempch );
- #endif
- }
- __value_in_regs struct R0_R3 {unsigned heap_base, stack_base, heap_limit, stack_limit;}
- __user_initial_stackheap(unsigned int R0, unsigned int SP, unsigned int R2, unsigned int SL)
- {
- struct R0_R3 config;
- config.heap_base = 0x00030000;
- config.stack_base = SP;
- /*
- To place heap_base directly above the ZI area, use:
- extern unsigned int Image$$ZI$$Limit;
- config.heap_base = (unsigned int)&Image$$ZI$$Limit;
- (or &Image$$region_name$$ZI$$Limit for scatterloaded images)
- To specify the limits for the heap & stack, use e.g:
- config.heap_limit = SL;
- config.stack_limit = SL;
- */
- return config;
- }