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 | * |
adamdunkels | ec4ca33 | 2003-11-27 15:58:05 +0000 | [diff] [blame] | 32 | * $Id: msp430.c,v 1.3 2003/11/27 15:58:05 adamdunkels Exp $ |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 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 | |
adamdunkels | ec4ca33 | 2003-11-27 15:58:05 +0000 | [diff] [blame] | 71 | #define INTERVAL_5MS 52288U // 12288 cycles @ 2,4756MHz = 5 ms |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 72 | |
| 73 | |
| 74 | static u16_t addr[2]; |
adamdunkels | ec4ca33 | 2003-11-27 15:58:05 +0000 | [diff] [blame] | 75 | static ek_clock_t count; |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 76 | |
adamdunkels | ec4ca33 | 2003-11-27 15:58:05 +0000 | [diff] [blame] | 77 | interrupt(TIMERA1_VECTOR) timera1 (void) { |
| 78 | |
| 79 | if(TAIV == 2) { |
| 80 | CCR1 += INTERVAL_5MS; |
| 81 | ++count; |
| 82 | P2OUT ^= 4; |
| 83 | } |
| 84 | } |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 85 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | ec4ca33 | 2003-11-27 15:58:05 +0000 | [diff] [blame] | 86 | ek_clock_t |
| 87 | ek_clock(void) |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 88 | { |
adamdunkels | ec4ca33 | 2003-11-27 15:58:05 +0000 | [diff] [blame] | 89 | return count; |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 90 | } |
| 91 | /*-----------------------------------------------------------------------------------*/ |
| 92 | void |
| 93 | beep(void) |
| 94 | { |
| 95 | unsigned int i, j; |
| 96 | |
| 97 | /* Beep. */ |
| 98 | P2OUT &= 0xFE; |
| 99 | P2OUT |= 8; |
| 100 | for(i = 0; i < 100; ++i) { |
| 101 | j = j * j; |
| 102 | } |
| 103 | P2OUT &= 0xf7; |
| 104 | P2OUT |= 0x01; |
| 105 | } |
| 106 | /*-----------------------------------------------------------------------------------*/ |
| 107 | void |
| 108 | blink(void) |
| 109 | { |
| 110 | unsigned int i, j; |
| 111 | |
| 112 | /* Blink yellow LED. */ |
| 113 | P2OUT &= 0xFB; |
| 114 | for(i = 0; i < 140; ++i) { |
| 115 | j = j * j; |
| 116 | } |
| 117 | P2OUT |= 0x04; |
| 118 | } |
| 119 | /*-----------------------------------------------------------------------------------*/ |
| 120 | void |
| 121 | rs232_print(char *cptr) |
| 122 | { |
| 123 | while(*cptr != 0) { |
| 124 | rs232_put(*cptr); |
| 125 | ++cptr; |
| 126 | } |
| 127 | } |
| 128 | /*-----------------------------------------------------------------------------------*/ |
| 129 | void |
adamdunkels | ec4ca33 | 2003-11-27 15:58:05 +0000 | [diff] [blame] | 130 | msp430_timer_init(void) |
| 131 | { |
| 132 | TACTL = TASSEL1 | TACLR | ID_3; // select SMCLK (2.4576MHz), clear TAR |
| 133 | |
| 134 | // init ccr1 to create the 5 ms interval |
| 135 | TACCTL1 = CCIE; // CCR1 interrupt enabled, interrupt occurs when timer equals CCR1 |
| 136 | TACCR1 = INTERVAL_5MS; // interrupt after 5ms |
| 137 | |
| 138 | TACTL |= MC1; // Start Timer_A in continuous mode |
| 139 | |
| 140 | eint(); /* Enable interrupts. */ |
| 141 | |
| 142 | |
| 143 | } |
| 144 | /*-----------------------------------------------------------------------------------*/ |
| 145 | void |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 146 | msp430_init(void) |
| 147 | { |
| 148 | ////////// Port 1 //// |
| 149 | P1SEL = 0x00; |
| 150 | P1DIR = 0x81; // Outputs: P10=IRSend, P17=RS232RTS |
| 151 | // Inputs: P11=Light, P12=IRRec, P13=PIR, P14=Vibration, |
| 152 | // P15=Clockalarm, P16=RS232CTS |
| 153 | P1OUT = 0x00; |
| 154 | |
| 155 | ////////// Port 2 //// |
| 156 | P2SEL = 0x00; // No Sels |
| 157 | P2DIR = 0x7F; // Outpus: P20..P23=Leds+Beeper, P24..P26=Poti |
| 158 | // Inputs: P27=Taster |
| 159 | P2OUT = 0x77; |
| 160 | |
| 161 | ////////// Port 3 //// |
| 162 | P3SEL = 0xE0; // Sels for P34..P37 to activate UART, |
| 163 | P3DIR = 0x5F; // Inputs: P30..P33=CON4, P35/P37=RXD Transceiver/RS232 |
| 164 | // OutPuts: P36/P38=TXD Transceiver/RS232 |
| 165 | P3OUT = 0xE0; // Output a Zero on P34(TXD Transceiver) and turn SELECT off when receiving!!! |
| 166 | |
| 167 | ////////// Port 4 //// |
| 168 | P4SEL = 0x00; // CON5 Stecker |
| 169 | P4DIR = 0xFF; |
| 170 | P4OUT = 0x00; |
| 171 | |
| 172 | ////////// Port 5 //// |
| 173 | P5SEL = 0x00; // P50/P51= Clock SDA/SCL, P52/P53/P54=EEPROM SDA/SCL/WP |
| 174 | P5DIR = 0xDA; // P56/P57=Transceiver CNTRL0/1 |
| 175 | P5OUT = 0x0F; |
| 176 | |
| 177 | ////////// Port 6 //// |
| 178 | P6SEL = 0x00; // P60=Microphone, P61=PIR digital (same as P13), P62=PIR analog |
| 179 | P6DIR = 0x00; // P63=extern voltage, P64=battery voltage, P65=Receive power |
| 180 | P6OUT = 0x00; |
| 181 | |
adamdunkels | ec4ca33 | 2003-11-27 15:58:05 +0000 | [diff] [blame] | 182 | |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 183 | /* Red led on */ |
| 184 | P2OUT &= 0xfd; |
| 185 | |
adamdunkels | 573bc29 | 2003-10-01 08:04:03 +0000 | [diff] [blame] | 186 | beep(); |
| 187 | } |
| 188 | /*-----------------------------------------------------------------------------------*/ |