Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2005, Swedish Institute of Computer Science 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 * 00031 * @(#)$Id: ctsrts-sensor.c,v 1.4 2010/02/08 00:00:45 nifi Exp $ 00032 */ 00033 00034 /** 00035 * RTS/CTS (Request to Send/Clear to Send) are the signals used for hardware 00036 * flow control. By setting the RTS line to "ON" the host tells the connected 00037 * device that it is ready to receive data. Hardware flow control is not 00038 * implemented yet. This implementation is just so some application can use 00039 * the pins, it would also be possible for rs232.c to use it for hardware 00040 * handshake but as said, that is not implemented yet. 00041 */ 00042 00043 #include "dev/ctsrts-sensor.h" 00044 #include "dev/irq.h" 00045 #include "dev/hwconf.h" 00046 00047 const struct sensors_sensor ctsrts_sensor; 00048 00049 HWCONF_PIN(RS232RTS, 1, 7); 00050 00051 #define RS232CTS_IRQ() 6 00052 HWCONF_PIN(RS232CTS, 1, RS232CTS_IRQ()); 00053 HWCONF_IRQ(RS232CTS, 1, RS232CTS_IRQ()); 00054 00055 /*---------------------------------------------------------------------------*/ 00056 static int 00057 irq(void) 00058 { 00059 /* Change the flank triggering for the irq so we will detect next shift. */ 00060 if(RS232CTS_READ()) { 00061 RS232CTS_IRQ_EDGE_SELECTD(); 00062 } else { 00063 RS232CTS_IRQ_EDGE_SELECTU(); 00064 } 00065 sensors_changed(&ctsrts_sensor); 00066 return 1; 00067 } 00068 /*---------------------------------------------------------------------------*/ 00069 static int 00070 value(int type) 00071 { 00072 /* 00073 * Invert the bit and return. 00074 * This is strange, accordingly to the MSP430 manual section 9.2.1, Input 00075 * Register PxIN the bit should be low when input is low. In RealTerm on 00076 * the PC I set RTS which is coupled to the CTS on the esb and I read a 0. 00077 * Maybe RTS is defined active LOW on the PC? //Kalle 00078 */ 00079 return RS232CTS_READ() ? 0 : 1; 00080 } 00081 /*---------------------------------------------------------------------------*/ 00082 static int 00083 configure(int type, int value) 00084 { 00085 switch(type) { 00086 case SENSORS_HW_INIT: 00087 RS232RTS_SELECT(); 00088 RS232RTS_MAKE_OUTPUT(); 00089 RS232RTS_CLEAR(); 00090 RS232CTS_SELECT(); 00091 RS232CTS_MAKE_INPUT(); 00092 return 1; 00093 case SENSORS_ACTIVE: 00094 if(value) { 00095 if(!RS232CTS_IRQ_ENABLED()) { 00096 00097 /* 00098 * Check current status on the CTS pin and set IRQ flank so we 00099 * will detect a shift. 00100 */ 00101 if(RS232CTS_READ()) { 00102 RS232CTS_IRQ_EDGE_SELECTD(); 00103 } else { 00104 RS232CTS_IRQ_EDGE_SELECTU(); 00105 } 00106 00107 irq_port1_activate(RS232CTS_IRQ(), irq); 00108 RS232CTS_ENABLE_IRQ(); 00109 } 00110 } else { 00111 RS232CTS_DISABLE_IRQ(); 00112 irq_port1_deactivate(RS232CTS_IRQ()); 00113 } 00114 return 1; 00115 } 00116 return 0; 00117 } 00118 /*---------------------------------------------------------------------------*/ 00119 static int 00120 status(int type) 00121 { 00122 switch(type) { 00123 case SENSORS_ACTIVE: 00124 case SENSORS_READY: 00125 return RS232CTS_IRQ_ENABLED(); 00126 } 00127 return 0; 00128 } 00129 /*---------------------------------------------------------------------------*/ 00130 /** 00131 * Indicate to host/client we are NOT ready to receive data. Sets the RTS pin 00132 * to low. 00133 */ 00134 void ctsrts_rts_clear(void) { 00135 RS232RTS_CLEAR(); 00136 } 00137 /*---------------------------------------------------------------------------*/ 00138 /** 00139 * Request host/client to send data. Sets the RTS pin to high. 00140 */ 00141 void ctsrts_rts_set(void) { 00142 RS232RTS_SET(); 00143 } 00144 /*---------------------------------------------------------------------------*/ 00145 SENSORS_SENSOR(ctsrts_sensor, CTSRTS_SENSOR, 00146 value, configure, status);