blink.c Source File






Misc >
Help >
FAQ >


Links >



blink.c

00001 /* blink.c -- Blink program for Christmas trees
00002 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
00003 Written by Stephane Carrez (stcarrez@nerim.fr)
00004 
00005 This file is part of GTAM.
00006 
00007 GTAM is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2, or (at your option)
00010 any later version.
00011 
00012 GTAM is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with GTAM; see the file COPYING. If not, write to
00019 the Free Software Foundation, 59 Temple Place - Suite 330,
00020 Boston, MA 02111-1307, USA. */
00021 
00055 #include <sys/ports.h>
00056 
00057 #define BIT_0 (1<<0)
00058 #define BIT_1 (1<<1)
00059 #define BIT_2 (1<<2)
00060 #define BIT_3 (1<<3)
00061 #define BIT_4 (1<<4)
00062 #define BIT_5 (1<<5)
00063 #define BIT_6 (1<<6)
00064 #define BIT_7 (1<<7)
00065 
00066 /* Port D */
00067 #define BOARD_RX (BIT_0)
00068 #define BOARD_TX (BIT_1)
00069 #define BOARD_LCD_0 (BIT_2)
00070 #define BOARD_LCD_1 (BIT_3)
00071 #define BOARD_LCD_2 (BIT_4)
00072 #define BOARD_LCD_3 (BIT_5)
00073 
00074 /* Port A */
00075 #define BOARD_KEY_0 (BIT_0)
00076 #define BOARD_KEY_1 (BIT_1)
00077 #define BOARD_KEY_2 (BIT_2)
00078 #define BOARD_ROM_DIS (BIT_3)
00079 #define BOARD_LCD_4 (BIT_4)
00080 #define BOARD_LCD_5 (BIT_5)
00081 #define BOARD_LCD_6 (BIT_6)
00082 #define BOARD_KEY_3 (BIT_7)
00083 
00084 /* Port E */
00085 #define BOARD_PEB_0 (BIT_0)
00086 #define BOARD_PEB_1 (BIT_1)
00087 #define BOARD_PEB_2 (BIT_2)
00088 #define BOARD_PEB_3 (BIT_3)
00089 #define BOARD_PEB_4 (BIT_4)
00090 #define BOARD_PEB_5 (BIT_5)
00091 #define BOARD_PEB_6 (BIT_6)
00092 #define BOARD_PEB_7 (BIT_7)
00093 
00094 /* Control of Fan, Light and mains detection on Port A. */
00095 #define EBCS_CMD_FAN (BOARD_LCD_5)
00096 #define EBCS_CMD_LIGHT (BOARD_LCD_6)
00097 #define EBCS_SENSE_LIGHT (BOARD_KEY_0)
00098 #define EBCS_SENSE_MAINS (BOARD_PE2)
00099 
00100 int __attribute__((noreturn)) main (void);
00101 void _start (void);
00102 void delay_ms (unsigned ms);
00103 
00104 void
00105 _start()
00106 {
00107 set_bus_expanded ();
00108 
00109 main ();
00110 }
00111 
00112 #define TABLE_SIZE(X) ((sizeof X) / sizeof (X[0]))
00113 
00114 /* Speed is defined as a delay and a repetition counter.
00115 
00116 SPEED(200,4) means 4 blinking at 200ms
00117 
00118 Delay and counter are stored using 4-bits each.
00119 */
00120 #define SPEED(T,CNT) ((((T)/100) & 0x0F) | ((CNT) & 0x0F)<<4)
00121 
00122 static const unsigned char speeds[] = {
00123 SPEED(200,4),
00124 SPEED(500,2),
00125 SPEED(300,1),
00126 SPEED(500,5),
00127 SPEED(800,3),
00128 SPEED(200,4),
00129 SPEED(100,6),
00130 SPEED(500,4),
00131 
00132 SPEED(200,3),
00133 SPEED(600,4),
00134 SPEED(100,2),
00135 SPEED(400,6),
00136 SPEED(800,2),
00137 SPEED(100,1),
00138 SPEED(900,1),
00139 SPEED(100,2),
00140 SPEED(900,1),
00141 SPEED(100,2),
00142 SPEED(900,1),
00143 
00144 SPEED(800,4),
00145 SPEED(100,1),
00146 SPEED(800,4),
00147 SPEED(100,2),
00148 SPEED(800,3),
00149 SPEED(100,4),
00150 SPEED(800,2),
00151 SPEED(100,8),
00152 SPEED(800,1),
00153 
00154 SPEED(1500,2)
00155 };
00156 
00157 /* Wait 'ms' milliseconds (not accurate (:- (:-), hand adjusted
00158 and based on human time accuracy (understand, SCz feeling). */
00159 void
00160 delay_ms (unsigned ms)
00161 {
00162 unsigned short tcnt;
00163 
00164 while (ms > 0)
00165 {
00166 unsigned i;
00167 
00168 for (i = 100; --i != 0;)
00169 tcnt = get_timer_counter ();
00170 
00171 ms--;
00172 }
00173 }
00174 
00175 int
00176 main ()
00177 {
00178 unsigned short i;
00179 unsigned short dt;
00180 short j;
00181 
00182 i = 0;
00183 while (1)
00184 {
00185 dt = speeds[i];
00186 j = (short) (speeds[i] >> 4);
00187 dt = (unsigned short) ((speeds[i] & (char) 0x0F) * (char) 100);
00188 
00189 do {
00190 /* Turn on the light. */
00191 _io_ports[M6811_PORTA] |= EBCS_CMD_FAN | EBCS_CMD_LIGHT;
00192 
00193 /* Pause the delay specified in the speeds table. */
00194 delay_ms (dt);
00195 
00196 /* Turn off the light. */
00197 _io_ports[M6811_PORTA] &= ~(EBCS_CMD_FAN | EBCS_CMD_LIGHT);
00198 
00199 /* Pause again and repeat according to speeds table. */
00200 delay_ms (dt);
00201 } while (--j >= 0);
00202 
00203 /* Pick next blinking rate (wrap to beginning if we reach the end). */
00204 i++;
00205 if (i > TABLE_SIZE (speeds))
00206 i = 0;
00207 }
00208 }
00209 

Copyright (C) 1999, 2000, 2001, 2002, 2003 Stéphane Carrez, France
Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.


AltStyle によって変換されたページ (->オリジナル) /