code petit robot pour homologation

Fork of CRAC-Strat_2017_V2 by CRAC Team

Committer:
antbig
Date:
Wed Apr 13 22:04:54 2016 +0000
Revision:
0:ad97421fb1fb
Ajout interruption fin de match

Who changed what in which revision?

UserRevisionLine numberNew contents of line
antbig 0:ad97421fb1fb 1 /* mbed Microcontroller Library - SerialHalfDuplex
antbig 0:ad97421fb1fb 2 * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
antbig 0:ad97421fb1fb 3 */
antbig 0:ad97421fb1fb 4
antbig 0:ad97421fb1fb 5 #ifndef MBED_SERIALHALFDUPLEX_H
antbig 0:ad97421fb1fb 6 #define MBED_SERIALHALFDUPLEX_H
antbig 0:ad97421fb1fb 7
antbig 0:ad97421fb1fb 8 #include "device.h"
antbig 0:ad97421fb1fb 9
antbig 0:ad97421fb1fb 10 #if DEVICE_SERIAL
antbig 0:ad97421fb1fb 11
antbig 0:ad97421fb1fb 12 #include "Serial.h"
antbig 0:ad97421fb1fb 13 #include "PinNames.h"
antbig 0:ad97421fb1fb 14 #include "PeripheralNames.h"
antbig 0:ad97421fb1fb 15
antbig 0:ad97421fb1fb 16 namespace mbed {
antbig 0:ad97421fb1fb 17
antbig 0:ad97421fb1fb 18 /* Class: SerialHalfDuplex
antbig 0:ad97421fb1fb 19 * A serial port (UART) for communication with other devices using
antbig 0:ad97421fb1fb 20 * Half-Duplex, allowing transmit and receive on a single
antbig 0:ad97421fb1fb 21 * shared transmit and receive line. Only one end should be transmitting
antbig 0:ad97421fb1fb 22 * at a time.
antbig 0:ad97421fb1fb 23 *
antbig 0:ad97421fb1fb 24 * Both the tx and rx pin should be defined, and wired together.
antbig 0:ad97421fb1fb 25 * This is in addition to them being wired to the other serial
antbig 0:ad97421fb1fb 26 * device to allow both read and write functions to operate.
antbig 0:ad97421fb1fb 27 *
antbig 0:ad97421fb1fb 28 * Example:
antbig 0:ad97421fb1fb 29 * > // Send a byte to a second HalfDuplex device, and read the response
antbig 0:ad97421fb1fb 30 * >
antbig 0:ad97421fb1fb 31 * > #include "mbed.h"
antbig 0:ad97421fb1fb 32 * >
antbig 0:ad97421fb1fb 33 * > // p9 and p10 should be wired together to form "a"
antbig 0:ad97421fb1fb 34 * > // p28 and p27 should be wired together to form "b"
antbig 0:ad97421fb1fb 35 * > // p9/p10 should be wired to p28/p27 as the Half Duplex connection
antbig 0:ad97421fb1fb 36 * >
antbig 0:ad97421fb1fb 37 * > SerialHalfDuplex a(p9, p10);
antbig 0:ad97421fb1fb 38 * > SerialHalfDuplex b(p28, p27);
antbig 0:ad97421fb1fb 39 * >
antbig 0:ad97421fb1fb 40 * > void b_rx() { // second device response
antbig 0:ad97421fb1fb 41 * > b.putc(b.getc() + 4);
antbig 0:ad97421fb1fb 42 * > }
antbig 0:ad97421fb1fb 43 * >
antbig 0:ad97421fb1fb 44 * > int main() {
antbig 0:ad97421fb1fb 45 * > b.attach(&b_rx);
antbig 0:ad97421fb1fb 46 * > for(int c = 'A'; c < 'Z'; c++) {
antbig 0:ad97421fb1fb 47 * > a.putc(c);
antbig 0:ad97421fb1fb 48 * > printf("sent [%c]\n", c);
antbig 0:ad97421fb1fb 49 * > wait(0.5); // b should respond
antbig 0:ad97421fb1fb 50 * > if(a.readable()) {
antbig 0:ad97421fb1fb 51 * > printf("received [%c]\n", a.getc());
antbig 0:ad97421fb1fb 52 * > }
antbig 0:ad97421fb1fb 53 * > }
antbig 0:ad97421fb1fb 54 * > }
antbig 0:ad97421fb1fb 55 *
antbig 0:ad97421fb1fb 56 * For Simplex and Full-Duplex Serial communication, see <Serial>
antbig 0:ad97421fb1fb 57 */
antbig 0:ad97421fb1fb 58 class SerialHalfDuplex : public Serial {
antbig 0:ad97421fb1fb 59
antbig 0:ad97421fb1fb 60 public:
antbig 0:ad97421fb1fb 61 /* Constructor: SerialHalfDuplex
antbig 0:ad97421fb1fb 62 * Create a half-duplex serial port, connected to the specified transmit
antbig 0:ad97421fb1fb 63 * and receive pins.
antbig 0:ad97421fb1fb 64 *
antbig 0:ad97421fb1fb 65 * These pins should be wired together, as well as to the target device
antbig 0:ad97421fb1fb 66 *
antbig 0:ad97421fb1fb 67 * Variables:
antbig 0:ad97421fb1fb 68 * tx - Transmit pin
antbig 0:ad97421fb1fb 69 * rx - Receive pin
antbig 0:ad97421fb1fb 70 */
antbig 0:ad97421fb1fb 71 SerialHalfDuplex(PinName tx, PinName rx, const char *name = NULL);
antbig 0:ad97421fb1fb 72
antbig 0:ad97421fb1fb 73 #if 0 // Inherited from Serial class, for documentation
antbig 0:ad97421fb1fb 74 /* Function: baud
antbig 0:ad97421fb1fb 75 * Set the baud rate of the serial port
antbig 0:ad97421fb1fb 76 *
antbig 0:ad97421fb1fb 77 * Variables:
antbig 0:ad97421fb1fb 78 * baudrate - The baudrate of the serial port (default = 9600).
antbig 0:ad97421fb1fb 79 */
antbig 0:ad97421fb1fb 80 void baud(int baudrate);
antbig 0:ad97421fb1fb 81
antbig 0:ad97421fb1fb 82 enum Parity {
antbig 0:ad97421fb1fb 83 None = 0
antbig 0:ad97421fb1fb 84 , Odd
antbig 0:ad97421fb1fb 85 , Even
antbig 0:ad97421fb1fb 86 , Forced1
antbig 0:ad97421fb1fb 87 , Forced0
antbig 0:ad97421fb1fb 88 };
antbig 0:ad97421fb1fb 89
antbig 0:ad97421fb1fb 90 /* Function: format
antbig 0:ad97421fb1fb 91 * Set the transmission format used by the Serial port
antbig 0:ad97421fb1fb 92 *
antbig 0:ad97421fb1fb 93 * Variables:
antbig 0:ad97421fb1fb 94 * bits - The number of bits in a word (5-8; default = 8)
antbig 0:ad97421fb1fb 95 * parity - The parity used (Serial::None, Serial::Odd,
antbig 0:ad97421fb1fb 96 Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None)
antbig 0:ad97421fb1fb 97 * stop - The number of stop bits (1 or 2; default = 1)
antbig 0:ad97421fb1fb 98 */
antbig 0:ad97421fb1fb 99 void format(int bits = 8, Parity parity = Serial::None, int stop_bits
antbig 0:ad97421fb1fb 100 = 1);
antbig 0:ad97421fb1fb 101
antbig 0:ad97421fb1fb 102 /* Function: putc
antbig 0:ad97421fb1fb 103 * Write a character
antbig 0:ad97421fb1fb 104 *
antbig 0:ad97421fb1fb 105 * Variables:
antbig 0:ad97421fb1fb 106 * c - The character to write to the serial port
antbig 0:ad97421fb1fb 107 */
antbig 0:ad97421fb1fb 108 int putc(int c);
antbig 0:ad97421fb1fb 109
antbig 0:ad97421fb1fb 110 /* Function: getc
antbig 0:ad97421fb1fb 111 * Read a character
antbig 0:ad97421fb1fb 112 *
antbig 0:ad97421fb1fb 113 * Read a character from the serial port. This call will block
antbig 0:ad97421fb1fb 114 * until a character is available. For testing if a character is
antbig 0:ad97421fb1fb 115 * available for reading, see <readable>.
antbig 0:ad97421fb1fb 116 *
antbig 0:ad97421fb1fb 117 * Variables:
antbig 0:ad97421fb1fb 118 * returns - The character read from the serial port
antbig 0:ad97421fb1fb 119 */
antbig 0:ad97421fb1fb 120 int getc();
antbig 0:ad97421fb1fb 121
antbig 0:ad97421fb1fb 122 /* Function: printf
antbig 0:ad97421fb1fb 123 * Write a formated string
antbig 0:ad97421fb1fb 124 *
antbig 0:ad97421fb1fb 125 * Variables:
antbig 0:ad97421fb1fb 126 * format - A printf-style format string, followed by the
antbig 0:ad97421fb1fb 127 * variables to use in formating the string.
antbig 0:ad97421fb1fb 128 */
antbig 0:ad97421fb1fb 129 int printf(const char* format, ...);
antbig 0:ad97421fb1fb 130
antbig 0:ad97421fb1fb 131 /* Function: scanf
antbig 0:ad97421fb1fb 132 * Read a formated string
antbig 0:ad97421fb1fb 133 *
antbig 0:ad97421fb1fb 134 * Variables:
antbig 0:ad97421fb1fb 135 * format - A scanf-style format string,
antbig 0:ad97421fb1fb 136 * followed by the pointers to variables to store the results.
antbig 0:ad97421fb1fb 137 */
antbig 0:ad97421fb1fb 138 int scanf(const char* format, ...);
antbig 0:ad97421fb1fb 139
antbig 0:ad97421fb1fb 140 /* Function: readable
antbig 0:ad97421fb1fb 141 * Determine if there is a character available to read
antbig 0:ad97421fb1fb 142 *
antbig 0:ad97421fb1fb 143 * Variables:
antbig 0:ad97421fb1fb 144 * returns - 1 if there is a character available to read, else 0
antbig 0:ad97421fb1fb 145 */
antbig 0:ad97421fb1fb 146 int readable();
antbig 0:ad97421fb1fb 147
antbig 0:ad97421fb1fb 148 /* Function: writeable
antbig 0:ad97421fb1fb 149 * Determine if there is space available to write a character
antbig 0:ad97421fb1fb 150 *
antbig 0:ad97421fb1fb 151 * Variables:
antbig 0:ad97421fb1fb 152 * returns - 1 if there is space to write a character, else 0
antbig 0:ad97421fb1fb 153 */
antbig 0:ad97421fb1fb 154 int writeable();
antbig 0:ad97421fb1fb 155
antbig 0:ad97421fb1fb 156 /* Function: attach
antbig 0:ad97421fb1fb 157 * Attach a function to call whenever a serial interrupt is generated
antbig 0:ad97421fb1fb 158 *
antbig 0:ad97421fb1fb 159 * Variables:
antbig 0:ad97421fb1fb 160 * fptr - A pointer to a void function, or 0 to set as none
antbig 0:ad97421fb1fb 161 */
antbig 0:ad97421fb1fb 162 void attach(void (*fptr)(void));
antbig 0:ad97421fb1fb 163
antbig 0:ad97421fb1fb 164 /* Function: attach
antbig 0:ad97421fb1fb 165 * Attach a member function to call whenever a serial interrupt is generated
antbig 0:ad97421fb1fb 166 *
antbig 0:ad97421fb1fb 167 * Variables:
antbig 0:ad97421fb1fb 168 * tptr - pointer to the object to call the member function on
antbig 0:ad97421fb1fb 169 * mptr - pointer to the member function to be called
antbig 0:ad97421fb1fb 170 */
antbig 0:ad97421fb1fb 171 template<typename T>
antbig 0:ad97421fb1fb 172 void attach(T* tptr, void (T::*mptr)(void));
antbig 0:ad97421fb1fb 173
antbig 0:ad97421fb1fb 174 #endif
antbig 0:ad97421fb1fb 175
antbig 0:ad97421fb1fb 176 protected:
antbig 0:ad97421fb1fb 177 PinName _txpin;
antbig 0:ad97421fb1fb 178
antbig 0:ad97421fb1fb 179 virtual int _putc(int c);
antbig 0:ad97421fb1fb 180 virtual int _getc(void);
antbig 0:ad97421fb1fb 181
antbig 0:ad97421fb1fb 182 }; // End class SerialHalfDuplex
antbig 0:ad97421fb1fb 183
antbig 0:ad97421fb1fb 184 } // End namespace
antbig 0:ad97421fb1fb 185
antbig 0:ad97421fb1fb 186 #endif
antbig 0:ad97421fb1fb 187
antbig 0:ad97421fb1fb 188 #endif