Main Page | Modules | Data Structures | File List | Data Fields | Globals

main.c

Go to the documentation of this file.
00001 /* BeeOS v0.1. Created: 2003/08/10 Modified: 2004/03/03
00002  * Copyright (C) 2004 Paul Harvey - ROMA, Australia.
00003  * csirac@users.sourceforge.net
00004  */
00005 
00006 /*   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  * 
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  * 
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with this program; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /* DBUG12 monitor functions, eg. printf(), SetUserVector()*/
00022 #include "../include/beeos.h"
00023 #include "../include/bctype.h"
00024 #include "../include/bbit.h"
00025 #include "../include/bstring.h"
00026 #include "../include/bmalloc.h"
00027 #include "../include/exec.h"
00028 #include "../include/sci.h"
00029 #include "../include/ect.h"
00030 #include <stdarg.h>
00031 #include "../include/bprintf.h"
00032 #ifndef HOSTED_BUILD
00033 #include "../include/asm/vectors.h"
00034 #include "../include/asm/ports.h"
00035 #else
00036 #include <stdio.h>
00037 #endif
00038 
00039 /* defines */
00040 
00041 /* typedefs */
00042 
00043 /*START GLOBALS of evil */
00044 bool toggle_scan_lk;
00045 uchar gbl_scani;
00046 uchar map_leds[8];
00047 uchar map_btns[8];
00048 /*END GLOBALS of evil */
00049 
00050 /*START PROTOTYPES (local only) */
00051 /*@-protoparamname@*/
00052 void lbdrv_chg (void);
00053 void misc (void);
00054 void btnscan_chk (void);
00055 /*@=protoparamname@*/
00056 /*END PROTOTYPES (local only) */
00057 
00058 /*@-isoreserved@*/
00059 /*@external@*/
00060     int _start(void) __attribute__ ((noreturn));
00061 /*@=isoreserved@*/
00062 
00063 #ifdef HOSTED_BUILD
00064 int main (void)
00065 #else
00066 int _start (void)
00067 #endif
00068 /*@globals internalState, undef tasks@*/
00069 /*@modifies internalState, tasks@*/
00070 {   /* _start(): BeeOS cold-start execution entry point. */
00071 #ifndef HOSTED_BUILD
00072     ASM_SEI;
00073     RTICTL = 0x00;
00074     COPCTL = 0x00;
00075     _sp = (void *)0x3FFF;
00076     RDRIV = 0xFF;
00077     DDRA = 0x00;    PORTA = 0x00;
00078     DDRB = 0x00;    PORTB = 0x00;
00079     DDRE = 0x00;    PORTE = 0x00;
00080     DDRK = 0x00;    PORTK = 0x00;
00081     RDRT = 0xFF;    PERT = 0xFF;    PPST = 0xFF;    DDRT = 0x00;    PTT = 0x00;
00082     RDRS = 0xFF;    PERS = 0x00;    PPSS = 0xFF;    WOMS = 0xFF;    DDRS = 0x00;    PTS = 0x00;
00083     RDRM = 0xFF;    PERM = 0xFF;    PPSM = 0xFF;    WOMM = 0xFF;    DDRM = 0x00;    PTM = 0x00;
00084     PIEP = 0X00;    RDRP = 0xFF;    PERP = 0xFF;    PPSP = 0xFF;    DDRP = 0xFF;    PTP = 0x01;
00085     PIEH = 0X00;    RDRH = 0xFF;    PERH = 0xFF;    PPSH = 0xFF;    DDRH = 0xFF;    PTH = 0x00;
00086     PIEJ = 0X00;    RDRJ = 0xFF;    PERJ = 0xFF;    PPSJ = 0xFF;    DDRJ = 0x00;    PTJ = 0x00;
00087     sci0_init(960);
00088 #endif
00089     lk_bputs = false;
00090     lk_putchar = false;
00091     bmallocinit();
00092     execprep();
00093     addtask(lbdrv_chg, (char) 1, (ushort) TOUSHORT(TCNT_H), 500);
00094     addtask(btnscan_chk, (char) 2, (ushort) TOUSHORT(TCNT_H) + MSEC2TCNT(10), 500);
00095     addtask(misc, (char) 3, (ushort) TOUSHORT(TCNT_H) + MSEC2TCNT(20), 500);
00096 /*  bprintf(10, "main(): exec() %04x.\r\n", (sshort)(_start));*/
00097     ect_init();
00098     ASM_CLI;
00099     ASM_SWI;        /* Run isr_exec. */
00100     while(1 == 1);  /* Necessary, otherwise compiler will ignore noreturn. */
00101     /*@-compdef@*/  /* The @sets clause does not support globals (for addTask).*/
00102 #ifdef HOSTED_BUILD /* splint detects that on return, not all the fields in */
00103     return 0;       /* tasks are necessarily defined, because of addTask's */
00104 #else               /* modifies list. */
00105 /*  return;*/
00106 #endif
00107     /*@=compdef@*/
00108 }
00109 
00110 /*void lbdrv_chg (void)
00111 {
00112     while (1 == 1) {
00113         putchar('L');
00114         putchar('\r');
00115         putchar('\n');
00116     }
00117 }*/
00118 
00119 void lbdrv_chg (void)
00120 {
00121     while (1 == 1) {
00122         while (true != toggle_scan_lk);
00126         __asm__ __volatile__ ("inc %0" : "=m" (gbl_scani));
00127         if (7 < gbl_scani) gbl_scani = 0;
00128         PTP = 0x1 << gbl_scani;
00129         PTH = 0xFF & ~map_leds[gbl_scani];
00130         toggle_scan_lk = false;
00131 
00132         PORTA ^= BIT5;
00133         bsleep(3);
00134     }
00135     
00136     return;
00137 }
00138 
00139 /*
00140 void btnscan_chk (void)
00141 {
00142 while (1 == 1) {
00143         bprintf(0, "btnscan_chk().\r\n");
00144         putchar('B');
00145         putchar('\r');
00146         putchar('\n');
00147     }
00148     
00149     return;
00150 }*/
00151 
00152 void btnscan_chk (void)
00153 {
00154     uchar row_bit, ptt_bit, i;
00155     uchar ptt, scani, *row;
00156     uchar btni;
00157 
00158     bmemset((char *)map_btns, '\0', sizeof(uchar) * 8);
00159     while (1 == 1) {
00160         while (true == toggle_scan_lk);
00161         ASM_MOVW_MM(PTT, ptt);
00162         ASM_MOVW_MM(gbl_scani, scani);
00163         toggle_scan_lk = true;
00164         row = &(map_btns[scani]);
00165         
00166         if (*row != ptt) {
00167             /*bprintf(20, "scani: %i, row: %'08B, ptt: %'08B, PTT: %'08B.\r\n", (sshort) scani, (sshort) *row, (sshort) ptt, (sshort) PTT);*/
00168             for (i = 0; i < 8; i++) {
00169                 row_bit = bitncheck(row, i);
00170                 ptt_bit = bitncheck((uchar *)&(ptt), i);
00171                 if (row_bit != ptt_bit) {
00172                     btni = 8*scani + i;
00173                     if (row_bit < ptt_bit) 
00174                         bprintf(0, "Key pressed:  %02x.\r\n", (sshort) btni);
00175                     else    bprintf(0, "Key released: %02x.\r\n", (sshort) btni);
00176                 }
00177             }
00178             /*ASM_NOP;
00179             __asm__ __volatile__ (
00180             "ldaa %0\
00181             \n\tldx %1\
00182             \n\tstaa 0,X" : "=m" (*row) : "m" (ptt) : "%ccr", "%a", "%x");
00183             *row = ptt;
00184             __asm__ __volatile__ ("movb %1, %0" : "=m" (*row) : "m" (ptt));
00185             ASM_NOP;*/
00186             *row = ptt;
00187             /*bprintf(20, "scani: %i, row: %'08B, ptt: %'08B.\r\n", (sshort) scani, (sshort) *row, (sshort) ptt);*/
00188         }
00189         PORTA ^= BIT6;
00190 
00191         bsleep(50);
00192     }
00193     
00194     return;
00195 }
00196 
00197 void misc (void)
00198 {
00199     while (1 == 1) {
00200         /*if (0 == !toggle++) bputs("misc     ().\r\n");
00201         else {
00202             putchar('m');
00203             putchar('\r');
00204             putchar('\n');
00205         }*/
00206         PORTA ^= BIT7;
00207 
00208         bsleep(500);
00209     }
00210 
00211     return;
00212 }

Generated on Sat Apr 10 17:08:02 2004 for BeeOS by doxygen 1.3.6-20040222