00001 //============================================================================= 00002 // 00003 // hal_diag.c 00004 // 00005 // HAL diagnostic output code 00006 // 00007 //============================================================================= 00008 //####ECOSGPLCOPYRIGHTBEGIN#### 00009 // ------------------------------------------- 00010 // This file is part of eCos, the Embedded Configurable Operating System. 00011 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. 00012 // 00013 // eCos is free software; you can redistribute it and/or modify it under 00014 // the terms of the GNU General Public License as published by the Free 00015 // Software Foundation; either version 2 or (at your option) any later version. 00016 // 00017 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY 00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or 00019 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00020 // for more details. 00021 // 00022 // You should have received a copy of the GNU General Public License along 00023 // with eCos; if not, write to the Free Software Foundation, Inc., 00024 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00025 // 00026 // As a special exception, if other files instantiate templates or use macros 00027 // or inline functions from this file, or you compile this file and link it 00028 // with other works to produce a work based on this file, this file does not 00029 // by itself cause the resulting work to be covered by the GNU General Public 00030 // License. However the source code for this file must still be made available 00031 // in accordance with section (3) of the GNU General Public License. 00032 // 00033 // This exception does not invalidate any other reasons why a work based on 00034 // this file might be covered by the GNU General Public License. 00035 // 00036 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. 00037 // at http://sources.redhat.com/ecos/ecos-license/ 00038 // ------------------------------------------- 00039 //####ECOSGPLCOPYRIGHTEND#### 00040 //============================================================================= 00041 //#####DESCRIPTIONBEGIN#### 00042 // 00043 // Author(s): ysato 00044 // Contributors: ysato, Uwe Kindler 00045 // Date: 2003-12-06 00046 // Purpose: HAL diagnostic output 00047 // Description: Implementations of HAL diagnostic output support. 00048 // 00049 //####DESCRIPTIONEND#### 00050 // 00051 //============================================================================= 00052 00053 00054 //============================================================================= 00055 // DOXYGEN FILE HEADER 00062 //============================================================================= 00063 00064 00065 //============================================================================= 00066 // INCLUDES 00067 //============================================================================= 00068 #include <pkgconf/hal.h> 00069 00070 #include <cyg/hal/hal_diag.h> 00071 #include <cyg/hal/var_intr.h> 00072 #include <cyg/hal/h8s_sci.h> 00073 00074 00075 //=========================================================================== 00076 // DEFINES 00077 //=========================================================================== 00078 00079 00080 //=========================================================================== 00081 // GLOBALS 00082 //=========================================================================== 00083 //-------------------------------------------------------------------------- 00084 // These macros simplify entries into hal_int_conf_tbl[] 00085 // 00086 #define CHAN_TBL_ENTRY(base, timeout, baud, vect) \ 00087 {(cyg_uint8 *)base, (cyg_uint32)timeout, baud, vect} 00088 00089 00090 // 00091 // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG 00092 // 00093 // Virtual vector support allows the HAL to let the ROM monitor handle 00094 // certain operations. The virtual vector table defines a calling interface 00095 // between applications running in RAM and the ROM monitor. 00096 // 00097 #if defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG) 00098 //============================================================================ 00099 // INITIALIZE SERIAL VIRTUAL VECTOR COMM CHANNEL 00107 //============================================================================ 00108 void hal_console_comm_init(channel_data_t *pchan, cyg_uint8 chan_no) 00109 { 00110 hal_virtual_comm_table_t *pvcomm_tbl; 00111 int cur; 00112 00113 // 00114 // first save the current console channel settings 00115 // 00116 cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); 00117 // 00118 // Now we we initailise the channel an store there patrameters into 00119 // tom COMM tables of the virtual vector calling interface 00120 // 00121 HAL_INTERRUPT_MASK(pchan->isr_vector); // Disable interrupts 00122 hal_sci_init_channel((void *)pchan); // Init channel 00123 // 00124 // Setup procs in the vector table 00125 // Initialize channel procs 00126 // 00127 CYGACC_CALL_IF_SET_CONSOLE_COMM(chan_no); 00128 pvcomm_tbl = CYGACC_CALL_IF_CONSOLE_PROCS(); 00129 CYGACC_COMM_IF_CH_DATA_SET(*pvcomm_tbl, pchan); 00130 CYGACC_COMM_IF_WRITE_SET(*pvcomm_tbl, hal_sci_write); 00131 CYGACC_COMM_IF_READ_SET(*pvcomm_tbl, hal_sci_read); 00132 CYGACC_COMM_IF_PUTC_SET(*pvcomm_tbl, hal_sci_putc); 00133 CYGACC_COMM_IF_GETC_SET(*pvcomm_tbl, hal_sci_getc); 00134 CYGACC_COMM_IF_CONTROL_SET(*pvcomm_tbl, hal_sci_control); 00135 CYGACC_COMM_IF_DBG_ISR_SET(*pvcomm_tbl, hal_sci_isr); 00136 CYGACC_COMM_IF_GETC_TIMEOUT_SET(*pvcomm_tbl, hal_sci_getc_timeout); 00137 // 00138 // Now we restore the original console which was saved previously 00139 // 00140 CYGACC_CALL_IF_SET_CONSOLE_COMM(cur); 00141 } 00142 #endif // #if defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG) 00143 00144 // 00145 // When vector table console code is not used, the we must map the 00146 // HAL_DIAG_INIT, HAL_DIAG_WRITE_CHAR and HAL_DIAG_READ_CHAR macros 00147 // directly to the low-level IO functions, hardwired to use at compile-time 00148 // configured channel. 00149 // 00150 #if !defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG) || defined(CYGBLD_HAL_H8S_ADDITIONAL_DIAG_CODE) 00151 static channel_data_t *pchannel; // points to hardwired serial channel provided by platform 00152 00153 //============================================================================= 00154 // INITIALIZE DIAGNOSTIC DEVICE 00161 //============================================================================= 00162 void hal_diag_init(channel_data_t *pchan_arg) 00163 { 00164 pchannel = pchan_arg; 00165 hal_sci_init_channel((void *)pchannel); 00166 } 00167 00168 00169 //============================================================================= 00170 // WRITE CHAR TO DIAGNOSTIC DEVICE 00177 //============================================================================= 00178 void hal_diag_write_char(char c ) 00179 { 00180 hal_sci_putc((void *)pchannel, c); 00181 } 00182 00183 00184 //============================================================================= 00185 // READ CHAR FROM DIAGNOSTIC DEVICE 00192 //============================================================================= 00193 void hal_diag_read_char(char *c) 00194 { 00195 *c = (char) hal_sci_getc((void *)pchannel); 00196 } 00197 00198 00199 //============================================================================ 00200 // SEND BUFFER 00208 //============================================================================ 00209 int hal_diag_put_buf(const char *pbuf_in, int len_in) 00210 { 00211 unsigned char sum; 00212 00213 00214 sum = 0; 00215 while (len_in--) 00216 { 00217 sum += *(unsigned char*)pbuf_in; 00218 hal_diag_write_char(*pbuf_in++); 00219 } 00220 00221 return sum; 00222 } 00223 00224 00225 //============================================================================ 00226 // SEND ZERO TERMINATED STRING 00231 //============================================================================ 00232 void hal_diag_put_string (unsigned char *pstr_in) 00233 { 00234 while (*pstr_in != '\0') // repeat until detection of terminating zero 00235 { 00236 hal_diag_write_char(*pstr_in++); 00237 } 00238 } 00239 00240 00241 //============================================================================ 00242 // SEND LONG 00249 //============================================================================ 00250 void hal_diag_put_long(unsigned long l_in) 00251 { 00252 unsigned char charbuf[10]; 00253 unsigned char i; 00254 00255 00256 // 00257 // A zero value is a special case - we send zero char and leave 00258 // 00259 if (l_in == 0) 00260 { 00261 hal_diag_write_char('0'); 00262 return; 00263 } 00264 00265 // 00266 // Here we calculate the entries for the char buffer. We start with 00267 // the least significant number and devide by 10 until l_in = zero. 00268 // An ASCII offset is added to get a char from a numeric value. 00269 // 00270 i = 9; 00271 while (l_in > 0) 00272 { 00273 charbuf[i] = (l_in % 10) + '0'; 00274 i--; 00275 l_in = l_in / 10; 00276 } 00277 00278 // 00279 // This part sends the content of the charbuffer out through serial 00280 // interface 00281 // 00282 i++; 00283 while (i < 10) 00284 { 00285 hal_diag_write_char(charbuf[i]); 00286 i++; 00287 } 00288 } 00289 00290 00291 //============================================================================ 00292 // CONVERT LOW NIBBLE OF BYTE TO HEX CHAR 00299 //============================================================================ 00300 static char hal_lnibble_to_hex(char n_in) 00301 { 00302 static const char lnibble_to_hex_tbl[] = "0123456789abcdef"; 00303 00304 return lnibble_to_hex_tbl[n_in & 0xf]; 00305 } 00306 00307 00308 //============================================================================ 00309 // CONVERT LONG INTO HEX STRING 00317 //============================================================================ 00318 static unsigned char hal_long_to_hexbuf(long l_in, char *phexbuf_out) 00319 { 00320 typedef union 00321 { 00322 long lbuf; 00323 short sbuf; 00324 char cbuf[sizeof(long)]; 00325 } lsc_buf_t; 00326 00327 lsc_buf_t lscbuf; 00328 unsigned char ret; 00329 unsigned char i; 00330 00331 00332 ret = 0; 00333 lscbuf.lbuf = l_in; 00334 // 00335 // Now we convert the value in lscbuf into hex chars and store 00336 // them into phexbuf_out 00337 // 00338 for (i = 0; i < sizeof(long); i++) 00339 { 00340 *phexbuf_out++ = hal_lnibble_to_hex(lscbuf.cbuf[i] >> 4); // high nibble 00341 *phexbuf_out++ = hal_lnibble_to_hex(lscbuf.cbuf[i]); // low nibble 00342 ret += 2; // inc. counter for chars in buf 00343 } 00344 00345 return ret; 00346 } 00347 00348 00349 //============================================================================ 00350 // SEND LONG AS ASCII STRING 00355 //============================================================================ 00356 void hal_diag_put_long_hex(long l_in) 00357 { 00358 unsigned char hexbuf[10] = "0x"; 00359 unsigned char len = 2; 00360 00361 00362 len += hal_long_to_hexbuf(l_in, &hexbuf[2]); 00363 hal_diag_put_buf(hexbuf, len); 00364 } 00365 00366 #endif // #if !defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG) || defined(CYGBLD_HAL_ADDITIONAL_DIAG_CODE) 00367 00368 //---------------------------------------------------------------------------- 00369 // EOF hal_diag.c
1.3.5