1 /* most of this is taken from the file */
2 /* hal/powerpc/cogent/current/src/hal_diag.c in the */
3 /* Cygnus eCos source. Here is the copyright notice: */
5 /*============================================================================= */
9 /* HAL diagnostic output code */
11 /*============================================================================= */
12 /*####COPYRIGHTBEGIN#### */
14 /* ------------------------------------------- */
15 /* The contents of this file are subject to the Cygnus eCos Public License */
16 /* Version 1.0 (the "License"); you may not use this file except in */
17 /* compliance with the License. You may obtain a copy of the License at */
18 /* http://sourceware.cygnus.com/ecos */
20 /* Software distributed under the License is distributed on an "AS IS" */
21 /* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the */
22 /* License for the specific language governing rights and limitations under */
25 /* The Original Code is eCos - Embedded Cygnus Operating System, released */
26 /* September 30, 1998. */
28 /* The Initial Developer of the Original Code is Cygnus. Portions created */
29 /* by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. */
30 /* ------------------------------------------- */
32 /*####COPYRIGHTEND#### */
33 /*============================================================================= */
34 /*#####DESCRIPTIONBEGIN#### */
36 /* Author(s): nickg, jskov */
37 /* Contributors: nickg, jskov */
38 /* Date: 1999-03-23 */
39 /* Purpose: HAL diagnostic output */
40 /* Description: Implementations of HAL diagnostic output support. */
42 /*####DESCRIPTIONEND#### */
44 /*============================================================================= */
46 /*----------------------------------------------------------------------------- */
47 /* Cogent board specific LCD code */
51 #include <board/cogent/lcd.h>
53 static char lines
[2][LCD_LINE_LENGTH
+1];
56 static int heartbeat_active
;
57 /* make the next two strings exactly LCD_LINE_LENGTH (16) chars long */
58 /* pad to the right with spaces if necessary */
59 static char init_line0
[LCD_LINE_LENGTH
+1] = "U-Boot Cogent ";
60 static char init_line1
[LCD_LINE_LENGTH
+1] = "mjj, 11 Aug 2000";
62 static inline unsigned char
63 lcd_read_status(cma_mb_lcd
*clp
)
65 /* read the Busy Status Register */
66 return (cma_mb_reg_read(&clp
->lcd_bsr
));
70 lcd_wait_not_busy(cma_mb_lcd
*clp
)
74 * Note: It seems that the LCD isn't quite ready to process commands
75 * when it clears the BUSY flag. Reading the status address an extra
76 * time seems to give it enough breathing room.
79 while (lcd_read_status(clp
) & LCD_STAT_BUSY
)
82 (void)lcd_read_status(clp
);
86 lcd_write_command(cma_mb_lcd
*clp
, unsigned char cmd
)
88 lcd_wait_not_busy(clp
);
90 /* write the Command Register */
91 cma_mb_reg_write(&clp
->lcd_cmd
, cmd
);
95 lcd_write_data(cma_mb_lcd
*clp
, unsigned char data
)
97 lcd_wait_not_busy(clp
);
99 /* write the Current Character Register */
100 cma_mb_reg_write(&clp
->lcd_ccr
, data
);
104 lcd_dis(int addr
, char *string
)
106 cma_mb_lcd
*clp
= (cma_mb_lcd
*)CMA_MB_LCD_BASE
;
109 linelen
= LCD_LINE_LENGTH
;
110 if (heartbeat_active
&& addr
== LCD_LINE0
)
113 lcd_write_command(clp
, LCD_CMD_ADD
+ addr
);
114 for (pos
= 0; *string
!= '\0' && pos
< linelen
; pos
++)
115 lcd_write_data(clp
, *string
++);
121 cma_mb_lcd
*clp
= (cma_mb_lcd
*)CMA_MB_LCD_BASE
;
124 /* configure the lcd for 8 bits/char, 2 lines and 5x7 dot matrix */
125 lcd_write_command(clp
, LCD_CMD_MODE
);
127 /* turn the LCD display on */
128 lcd_write_command(clp
, LCD_CMD_DON
);
133 for (i
= 0; i
< LCD_LINE_LENGTH
; i
++) {
134 lines
[0][i
] = init_line0
[i
];
135 lines
[1][i
] = init_line1
[i
];
138 lines
[0][LCD_LINE_LENGTH
] = lines
[1][LCD_LINE_LENGTH
] = 0;
140 lcd_dis(LCD_LINE0
, lines
[0]);
141 lcd_dis(LCD_LINE1
, lines
[1]);
143 printf("HD44780 2 line x %d char display\n", LCD_LINE_LENGTH
);
147 lcd_write_char(const char c
)
155 linelen
= LCD_LINE_LENGTH
;
156 if (heartbeat_active
&& curline
== 0)
160 lcd_dis(LCD_LINE0
, &lines
[curline
^1][0]);
161 lcd_dis(LCD_LINE1
, &lines
[curline
][0]);
165 linelen
= LCD_LINE_LENGTH
;
166 if (heartbeat_active
&& curline
== 0)
170 for (i
= 0; i
< linelen
; i
++)
171 lines
[curline
][i
] = ' ';
176 /* Only allow to be output if there is room on the LCD line */
177 if (linepos
< linelen
)
178 lines
[curline
][linepos
++] = c
;
184 lcd_dis(LCD_LINE1
, &lines
[curline
][0]);
188 lcd_write_string(const char *s
)
192 for (p
= (char *)s
; *p
!= '\0'; p
++)
197 lcd_printf(const char *fmt
, ...)
200 char buf
[CFG_PBSIZE
];
203 (void)vsprintf(buf
, fmt
, args
);
206 lcd_write_string(buf
);
212 cma_mb_lcd
*clp
= (cma_mb_lcd
*)CMA_MB_LCD_BASE
;
214 static char rotchars
[] = { '|', '/', '-', '\\' };
216 /* HD44780 Rom Code A00 has no backslash */
217 static char rotchars
[] = { '|', '/', '-', '\315' };
219 static int rotator_index
= 0;
221 heartbeat_active
= 1;
223 /* write the address */
224 lcd_write_command(clp
, LCD_CMD_ADD
+ LCD_LINE0
+ (LCD_LINE_LENGTH
- 1));
226 /* write the next char in the sequence */
227 lcd_write_data(clp
, rotchars
[rotator_index
]);
229 if (++rotator_index
>= (sizeof rotchars
/ sizeof rotchars
[0]))
233 #ifdef CONFIG_SHOW_ACTIVITY
234 void board_show_activity (ulong timestamp
)
236 #ifdef CONFIG_STATUS_LED
237 if ((timestamp
% (CFG_HZ
/ 2) == 0)
242 void show_activity(int arg
)