blink.c

Description | Download | Table of Contents | Modules | Compound List | File List | Functions


Overview
Compiler
Documentation
Examples
Misc
Help
IDE & Tools

Download
Install

Links
Projects






00001 /* blink.c -- Blink program for Christmas trees
00002    Copyright 2000, 2001 Free Software Foundation, Inc.
00003    Written by Stephane Carrez (stcarrez@worldnet.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 ();
00101 
00102 void
00103 _start()
00104 {
00105   set_bus_expanded ();
00106 
00107   main ();
00108 }
00109 
00110 #define TABLE_SIZE(X) ((sizeof X) / sizeof (X[0]))
00111 
00112 /* Speed is defined as a delay and a repetition counter.
00113 
00114    SPEED(200,4) means 4 blinking at 200ms
00115 
00116    Delay and counter are stored using 4-bits each.
00117 */
00118 #define SPEED(T,CNT) ((((T)/100) & 0x0F) | ((CNT) & 0x0F)<<4)
00119 
00120 static const unsigned char speeds[] = {
00121   SPEED(200,4),
00122   SPEED(500,2),
00123   SPEED(300,1),
00124   SPEED(500,5),
00125   SPEED(800,3),
00126   SPEED(200,4),
00127   SPEED(100,6),
00128   SPEED(500,4),
00129 
00130   SPEED(200,3),
00131   SPEED(600,4),
00132   SPEED(100,2),
00133   SPEED(400,6),
00134   SPEED(800,2),
00135   SPEED(100,1),
00136   SPEED(900,1),
00137   SPEED(100,2),
00138   SPEED(900,1),
00139   SPEED(100,2),
00140   SPEED(900,1),
00141 
00142   SPEED(800,4),
00143   SPEED(100,1),
00144   SPEED(800,4),
00145   SPEED(100,2),
00146   SPEED(800,3),
00147   SPEED(100,4),
00148   SPEED(800,2),
00149   SPEED(100,8),
00150   SPEED(800,1),
00151 
00152   SPEED(1500,2)
00153 };
00154 
00155 /* Wait 'ms' milliseconds (not accurate (:- (:-), hand adjusted
00156    and based on human time accuracy (understand, SCz feeling).  */
00157 void
00158 delay_ms (unsigned ms)
00159 {
00160   unsigned short tcnt;
00161 
00162   while (ms > 0)
00163     {
00164       unsigned i;
00165       
00166       for (i = 100; --i != 0;)
00167         tcnt = get_timer_counter ();
00168 
00169       ms--;
00170     }
00171 }
00172 
00173 int
00174 main ()
00175 {
00176   unsigned short i;
00177   unsigned short dt;
00178   short j;
00179   
00180   i = 0;
00181   while (1)
00182     {
00183       dt = speeds[i];
00184       j = (short) (speeds[i] >> 4);
00185       dt = (unsigned short) ((speeds[i] & (char) 0x0F) * (char) 100);
00186 
00187       do {
00188         /* Turn on the light.  */
00189         _io_ports[M6811_PORTA] |= EBCS_CMD_FAN | EBCS_CMD_LIGHT;
00190 
00191         /* Pause the delay specified in the speeds table.  */
00192         delay_ms (dt);
00193 
00194         /* Turn off the light.  */
00195         _io_ports[M6811_PORTA] &= ~(EBCS_CMD_FAN | EBCS_CMD_LIGHT);
00196 
00197         /* Pause again and repeat according to speeds table.  */
00198         delay_ms (dt);
00199       } while (--j >= 0);
00200 
00201       /* Pick next blinking rate (wrap to beginning if we reach the end).  */
00202       i++;
00203       if (i > TABLE_SIZE (speeds))
00204         i = 0;
00205     }
00206 }
00207 

Description | Download | Table of Contents | Modules | Compound List | File List | Functions

    Last modified,
    Apr 16, 2001
[ Copying ]     [ Feedback to Stephane.Carrez@worldnet.fr ]