adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2003, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote |
| 15 | * products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | * |
| 30 | * This file is part of the Contiki desktop environment |
| 31 | * |
| 32 | * $Id: msp430.c,v 1.2 2003/10/01 08:04:03 adamdunkels Exp $ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | #include <io.h> |
| 37 | #include <signal.h> |
| 38 | |
| 39 | |
| 40 | #include "ctk.h" |
| 41 | #include "ctk-draw.h" |
| 42 | #include "ctk-vncserver.h" |
| 43 | #include "dispatcher.h" |
| 44 | |
| 45 | |
| 46 | #include "uip_main.h" |
| 47 | #include "uip.h" |
| 48 | #include "uip_arp.h" |
| 49 | #include "resolv.h" |
| 50 | |
| 51 | #include "webserver.h" |
| 52 | #include "program-handler.h" |
| 53 | #include "about-dsc.h" |
| 54 | #include "netconf-dsc.h" |
| 55 | #include "processes-dsc.h" |
| 56 | #include "www-dsc.h" |
| 57 | #include "webserver-dsc.h" |
| 58 | |
| 59 | #include "sensorview-dsc.h" |
| 60 | |
| 61 | #include "sensors.h" |
| 62 | |
| 63 | #include "uip.h" |
| 64 | #include "uip_arp.h" |
| 65 | |
| 66 | |
| 67 | #include "rs232.h" |
| 68 | void slip_drv_init(char *arg); |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | static u16_t addr[2]; |
| 74 | static unsigned short count; |
| 75 | |
| 76 | /*-----------------------------------------------------------------------------------*/ |
| 77 | unsigned short |
| 78 | clock(void) |
| 79 | { |
| 80 | return count++; |
| 81 | } |
| 82 | /*-----------------------------------------------------------------------------------*/ |
| 83 | void |
| 84 | beep(void) |
| 85 | { |
| 86 | unsigned int i, j; |
| 87 | |
| 88 | /* Beep. */ |
| 89 | P2OUT &= 0xFE; |
| 90 | P2OUT |= 8; |
| 91 | for(i = 0; i < 100; ++i) { |
| 92 | j = j * j; |
| 93 | } |
| 94 | P2OUT &= 0xf7; |
| 95 | P2OUT |= 0x01; |
| 96 | } |
| 97 | /*-----------------------------------------------------------------------------------*/ |
| 98 | void |
| 99 | blink(void) |
| 100 | { |
| 101 | unsigned int i, j; |
| 102 | |
| 103 | /* Blink yellow LED. */ |
| 104 | P2OUT &= 0xFB; |
| 105 | for(i = 0; i < 140; ++i) { |
| 106 | j = j * j; |
| 107 | } |
| 108 | P2OUT |= 0x04; |
| 109 | } |
| 110 | /*-----------------------------------------------------------------------------------*/ |
| 111 | void |
| 112 | rs232_print(char *cptr) |
| 113 | { |
| 114 | while(*cptr != 0) { |
| 115 | rs232_put(*cptr); |
| 116 | ++cptr; |
| 117 | } |
| 118 | } |
| 119 | /*-----------------------------------------------------------------------------------*/ |
| 120 | void |
| 121 | msp430_init(void) |
| 122 | { |
| 123 | ////////// Port 1 //// |
| 124 | P1SEL = 0x00; |
| 125 | P1DIR = 0x81; // Outputs: P10=IRSend, P17=RS232RTS |
| 126 | // Inputs: P11=Light, P12=IRRec, P13=PIR, P14=Vibration, |
| 127 | // P15=Clockalarm, P16=RS232CTS |
| 128 | P1OUT = 0x00; |
| 129 | |
| 130 | ////////// Port 2 //// |
| 131 | P2SEL = 0x00; // No Sels |
| 132 | P2DIR = 0x7F; // Outpus: P20..P23=Leds+Beeper, P24..P26=Poti |
| 133 | // Inputs: P27=Taster |
| 134 | P2OUT = 0x77; |
| 135 | |
| 136 | ////////// Port 3 //// |
| 137 | P3SEL = 0xE0; // Sels for P34..P37 to activate UART, |
| 138 | P3DIR = 0x5F; // Inputs: P30..P33=CON4, P35/P37=RXD Transceiver/RS232 |
| 139 | // OutPuts: P36/P38=TXD Transceiver/RS232 |
| 140 | P3OUT = 0xE0; // Output a Zero on P34(TXD Transceiver) and turn SELECT off when receiving!!! |
| 141 | |
| 142 | ////////// Port 4 //// |
| 143 | P4SEL = 0x00; // CON5 Stecker |
| 144 | P4DIR = 0xFF; |
| 145 | P4OUT = 0x00; |
| 146 | |
| 147 | ////////// Port 5 //// |
| 148 | P5SEL = 0x00; // P50/P51= Clock SDA/SCL, P52/P53/P54=EEPROM SDA/SCL/WP |
| 149 | P5DIR = 0xDA; // P56/P57=Transceiver CNTRL0/1 |
| 150 | P5OUT = 0x0F; |
| 151 | |
| 152 | ////////// Port 6 //// |
| 153 | P6SEL = 0x00; // P60=Microphone, P61=PIR digital (same as P13), P62=PIR analog |
| 154 | P6DIR = 0x00; // P63=extern voltage, P64=battery voltage, P65=Receive power |
| 155 | P6OUT = 0x00; |
| 156 | |
| 157 | /* Red led on */ |
| 158 | P2OUT &= 0xfd; |
| 159 | |
| 160 | eint(); /* Enable interrupts. */ |
| 161 | |
| 162 | beep(); |
| 163 | } |
| 164 | /*-----------------------------------------------------------------------------------*/ |