Program to control an accelerometer, motors and a rangefinder using the ScmRTOS ported to mbed. (Work in progress and buggy)
Diff: Hexacopter/serial.h
- Revision:
- 0:9b057566f9ee
diff -r 000000000000 -r 9b057566f9ee Hexacopter/serial.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hexacopter/serial.h Mon Nov 01 20:39:01 2010 +0000 @@ -0,0 +1,97 @@ +#ifndef SERIAL_H +#define SERIAL_H +#include <channels.h> +#include <Mutexes.h> +#include <processes.h> + +#define UART1TX p9 +#define UART1RX p10 + +Serial USB(USBTX, USBRX); // tx, rx +Serial XB(UART1TX, UART1RX); // tx, rx +Serial *OUT = &USB; //intially set to USB + +extern BusOut leds; + void USB_serial() //signal RTOS event that RXinterrupt has been asserted +{ + OS::TISRW ISRW; + leds = 0x7; + //char count = 0; + //led3 = !led3; + char temp = 0; + + //leds = 0xa; + if(true)//!Serial_Mutex.IsLocked()) + { + //leds = 0xb; + //Serial_Mutex.Lock(); + leds = 0xc; + if(USB.readable()) + { + temp = USB.getc(); + leds = 0xd; + + if(RX_channel.get_free_size() >0 ) //only push a character onto the channel if there is free space + { + //OUT = &USB; + if(temp != '\n') + { + RX_channel.push(temp); + leds = 0xe; + } + else if(temp == '\n') + { + RX_channel.push('\0'); + } + } + else USB.getc(); //start discarding characters!*/ + leds = 0xf; + leds = 0xa; + } + leds = 0xb; + //Serial_Mutex.Unlock(); + //Serial_Mutex.Lock(); + //if(USB.writeable()) + //USB.putc(temp); + //Serial_Mutex.Unlock(); + leds = 0x1; + } + else USB.getc(); //start discarding characters! + + leds = 0x9; +} + +/*void XB_serial() +{ + //led4 = !led4; + char temp = 0; + OS::TISRW ISRW; + if(!XB_Mutex.IsLocked()) + { + XB_Mutex.Lock(); + while(XB.readable()) + { + temp = XB.getc(); + if(RX_channel.get_free_size() >0 ) //only push a character onto the channel if there is free space + { + OUT = &XB; + if(temp != '\n') + { + RX_channel.push(temp); + } + else if(temp == '\n') + { + OUT = &XB; + RX_channel.push('\0'); + } + } + else temp = XB.getc(); //otherwise, wait until another character is sent and try then + } + XB_Mutex.Unlock(); + } + + +}*/ + +#endif +