📄 hal_diag.c
字号:
/*=============================================================================//// hal_diag.c//// HAL diagnostic output code////=============================================================================//####COPYRIGHTBEGIN####// // ------------------------------------------- // The contents of this file are subject to the Red Hat eCos Public License // Version 1.1 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://www.redhat.com/ // // Software distributed under the License is distributed on an "AS IS" // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the // License for the specific language governing rights and limitations under // the License. // // The Original Code is eCos - Embedded Configurable Operating System, // released September 30, 1998. // // The Initial Developer of the Original Code is Red Hat. // Portions created by Red Hat are // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. // All Rights Reserved. // ------------------------------------------- // //####COPYRIGHTEND####//=============================================================================//#####DESCRIPTIONBEGIN####//// Author(s): hmt// Contributors: hmt// Date: 2000-02-14// Purpose: HAL diagnostic output// Description: Implementations of HAL diagnostic output support.////####DESCRIPTIONEND####////===========================================================================*/#include <pkgconf/hal.h>#include <pkgconf/system.h>#include CYGBLD_HAL_PLATFORM_H#include <cyg/infra/cyg_type.h> // base types#include <cyg/infra/cyg_trac.h> // tracing macros#include <cyg/infra/cyg_ass.h> // assertion macros#include <cyg/hal/hal_arch.h> // basic machine info#include <cyg/hal/hal_intr.h> // interrupt macros#include <cyg/hal/hal_io.h> // IO macros#include <cyg/hal/hal_diag.h>void hal_diag_init(void){ // All done}// these are misnamed, of course, but fit in with the usual structure of// eCos diag channel packages:static bool hal_diag_read_serial(char *c){ char cc; asm volatile ( "mov r0, #0x06;" /* SYS_READC */ ".word 0xE7DEAD1A;" /* magic op to "do" SWI emulation in CoySim */ /* "swi 0x123456;" */ "nop;" "mov %0, r0;" /* char returned in r0, move to output reg */ : "=r"(cc) : : "r0" ); *c = cc; return true;}static void hal_diag_write_char_serial(char c){ asm volatile ( "mov r0, #0x03;" /* SYS_WRITEC */ "mov r1, %0;" /* address of char */ ".word 0xE7DEAD1A;" /* magic op to "do" SWI emulation in CoySim */ /* "swi 0x123456;" */ "nop;" : : "r"(&c) : "r0","r1" );}// ------------------------------------------------------------------------void hal_diag_read_char(char *c){ while (!hal_diag_read_serial(c)) ;}void hal_diag_write_char(char c){ static char line[100]; static int pos = 0; // No need to send CRs if( c == '\r' ) return; line[pos++] = c; if( c == '\n' || pos == sizeof(line) ) { CYG_INTERRUPT_STATE old; int i; // Disable interrupts. This ensures a whole diagnostic line escapes // thus giving more useful information: HAL_DISABLE_INTERRUPTS(old); for( i = 0; i < pos; i++ ) { char ch = line[i]; hal_diag_write_char_serial(ch); } pos = 0; // And re-enable interrupts HAL_RESTORE_INTERRUPTS(old); }}/*---------------------------------------------------------------------------*//* End of hal_diag.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -