This is the firmware for the base version of the OpenSTEM Ranging Board hardware.

Dependencies:   Servo USBDevice mbed

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
matthewgascoyne
Date:
Wed Aug 10 08:01:00 2016 +0000
Revision:
10:d74124f266cb
base version of OpenSTEM Ranging Board Firmware

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matthewgascoyne 10:d74124f266cb 1 // This header file is for the core firmware functions
matthewgascoyne 10:d74124f266cb 2 // associated with the mbed daughter board.
matthewgascoyne 10:d74124f266cb 3
matthewgascoyne 10:d74124f266cb 4 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 5 // "boot_msg" : Function to send a bootup message via the
matthewgascoyne 10:d74124f266cb 6 // usb serial link.
matthewgascoyne 10:d74124f266cb 7 void boot_msg(void);
matthewgascoyne 10:d74124f266cb 8 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 9
matthewgascoyne 10:d74124f266cb 10 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 11 // "scan_1s" : Function to check the recieve buffer
matthewgascoyne 10:d74124f266cb 12 // periodically (1s) to make sure there are no dormant
matthewgascoyne 10:d74124f266cb 13 // commands left in there.
matthewgascoyne 10:d74124f266cb 14 void scan_1s(void);
matthewgascoyne 10:d74124f266cb 15 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 16
matthewgascoyne 10:d74124f266cb 17 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 18 // "command_clean" : Function to clean a command from the
matthewgascoyne 10:d74124f266cb 19 // recieve buffer quickly.
matthewgascoyne 10:d74124f266cb 20 void command_clean(uint8_t t_pnt, uint8_t c_pnt);
matthewgascoyne 10:d74124f266cb 21 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 22
matthewgascoyne 10:d74124f266cb 23 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 24 // "diag_reply" : Function to send diagnostics info back
matthewgascoyne 10:d74124f266cb 25 // to the host PC via the USB serial.
matthewgascoyne 10:d74124f266cb 26 void diag_reply(void);
matthewgascoyne 10:d74124f266cb 27 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 28
matthewgascoyne 10:d74124f266cb 29 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 30 // "dshift_out" : Function to shift data out via the
matthewgascoyne 10:d74124f266cb 31 // shift register.
matthewgascoyne 10:d74124f266cb 32 // This will effect the digital shift outputs and the
matthewgascoyne 10:d74124f266cb 33 // multiplexer configuration.
matthewgascoyne 10:d74124f266cb 34 void dshift_out(uint16_t sdata_out);
matthewgascoyne 10:d74124f266cb 35 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 36
matthewgascoyne 10:d74124f266cb 37 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 38 // "freq_reply" : Function send a reply message back to
matthewgascoyne 10:d74124f266cb 39 // the host PC to say which frequency was detected on
matthewgascoyne 10:d74124f266cb 40 // the directsync pin. This will have been applied to the
matthewgascoyne 10:d74124f266cb 41 // motordrive also.
matthewgascoyne 10:d74124f266cb 42 void freq_reply(int freq, uint8_t command);
matthewgascoyne 10:d74124f266cb 43 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 44
matthewgascoyne 10:d74124f266cb 45 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 46 // "volts_IR" : Function reads the analogue input voltage
matthewgascoyne 10:d74124f266cb 47 // present on the directsync_in pin
matthewgascoyne 10:d74124f266cb 48 void volts_IR(void);
matthewgascoyne 10:d74124f266cb 49 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 50
matthewgascoyne 10:d74124f266cb 51 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 52 // "ultra_range" : Function performs an ultrasonic range
matthewgascoyne 10:d74124f266cb 53 // measurement and outputs the duration of the sensor
matthewgascoyne 10:d74124f266cb 54 // output pulse.
matthewgascoyne 10:d74124f266cb 55 void ultra_range(void);
matthewgascoyne 10:d74124f266cb 56 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 57
matthewgascoyne 10:d74124f266cb 58 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 59 // "directsync" : Function read the input frequency on
matthewgascoyne 10:d74124f266cb 60 // the direct sync pin. This frequency should then be
matthewgascoyne 10:d74124f266cb 61 // applied to the motor drive. This routine will then
matthewgascoyne 10:d74124f266cb 62 // return the frequency it applied.
matthewgascoyne 10:d74124f266cb 63 int directsync(void);
matthewgascoyne 10:d74124f266cb 64 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 65
matthewgascoyne 10:d74124f266cb 66 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 67 // "get_disc_freq" : Function read the frequency of the
matthewgascoyne 10:d74124f266cb 68 // spinning disc. This routine will then
matthewgascoyne 10:d74124f266cb 69 // return the frequency measured.
matthewgascoyne 10:d74124f266cb 70 int get_disc_freq(void);
matthewgascoyne 10:d74124f266cb 71 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 72
matthewgascoyne 10:d74124f266cb 73 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 74 // "set_servo" : Function sets the servo speed as a
matthewgascoyne 10:d74124f266cb 75 // floating point fraction of 100%.
matthewgascoyne 10:d74124f266cb 76 void set_servo(uint8_t servo, float speedval);
matthewgascoyne 10:d74124f266cb 77 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 78
matthewgascoyne 10:d74124f266cb 79 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 80 // "rotate_scene_cont" : Function to turn ranging scene
matthewgascoyne 10:d74124f266cb 81 // to the left or the right by a small amount
matthewgascoyne 10:d74124f266cb 82 void rotate_scene_cont(uint8_t direction);
matthewgascoyne 10:d74124f266cb 83 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 84
matthewgascoyne 10:d74124f266cb 85 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 86 // "rotate_scene" : Function to turn ranging scene
matthewgascoyne 10:d74124f266cb 87 // to the left or the right by a small amount
matthewgascoyne 10:d74124f266cb 88 void rotate_scene(uint8_t direction);
matthewgascoyne 10:d74124f266cb 89 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 90
matthewgascoyne 10:d74124f266cb 91 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 92 // "set_discfreq" : Function attempts to set the disc
matthewgascoyne 10:d74124f266cb 93 // rpm to the defined value. When rpm is reached it stops
matthewgascoyne 10:d74124f266cb 94 // trying.
matthewgascoyne 10:d74124f266cb 95 void set_discfreq(int discrpm);
matthewgascoyne 10:d74124f266cb 96 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 97
matthewgascoyne 10:d74124f266cb 98 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 99 // "dshift_combine" : Function to combine all shift reg
matthewgascoyne 10:d74124f266cb 100 // elements into a single 16bit variable, for shifting.
matthewgascoyne 10:d74124f266cb 101 // This will return the 16bit variable.
matthewgascoyne 10:d74124f266cb 102 uint16_t dshift_combine(void);
matthewgascoyne 10:d74124f266cb 103 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 104
matthewgascoyne 10:d74124f266cb 105 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 106 // "set_mux_chan" : Function to configure one of the five
matthewgascoyne 10:d74124f266cb 107 // daughter board multiplexers. (0 to 4). Each multiplexer
matthewgascoyne 10:d74124f266cb 108 // can select channels 1,2,3 or high-impedance (0).
matthewgascoyne 10:d74124f266cb 109 // This will effect the multiplexer configuration.
matthewgascoyne 10:d74124f266cb 110 void set_mux_chan(uint8_t mux, uint8_t chan);
matthewgascoyne 10:d74124f266cb 111 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 112
matthewgascoyne 10:d74124f266cb 113 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 114 // "print_array" : Function to send all character bytes
matthewgascoyne 10:d74124f266cb 115 // from an array out through the serial port.
matthewgascoyne 10:d74124f266cb 116 void print_array(char *array, uint8_t size);
matthewgascoyne 10:d74124f266cb 117 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 118
matthewgascoyne 10:d74124f266cb 119 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 120 // "stan_reply" : Function to send a standard reply from
matthewgascoyne 10:d74124f266cb 121 // the mBed to the Host PC. A standard reply is one that
matthewgascoyne 10:d74124f266cb 122 // confirms that the message sent by the host has been
matthewgascoyne 10:d74124f266cb 123 // actioned.
matthewgascoyne 10:d74124f266cb 124 void stan_reply(char command);
matthewgascoyne 10:d74124f266cb 125 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 126
matthewgascoyne 10:d74124f266cb 127 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 128 // "fdigi_out" : Function to assert digital outputs
matthewgascoyne 10:d74124f266cb 129 // attached directly to the mbed pins p29 and p30.
matthewgascoyne 10:d74124f266cb 130 void fdigi_out(uint8_t pin, bool pinval);
matthewgascoyne 10:d74124f266cb 131 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 132
matthewgascoyne 10:d74124f266cb 133 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 134 // "sdigi_out" : Function to assert digital outputs
matthewgascoyne 10:d74124f266cb 135 // attached to the daughter board shift register.
matthewgascoyne 10:d74124f266cb 136 // digi channels a, b, c, d, e and f.
matthewgascoyne 10:d74124f266cb 137 // This will effect the digital shift outputs only.
matthewgascoyne 10:d74124f266cb 138 void sdigi_out(char digi_ch, bool pinval);
matthewgascoyne 10:d74124f266cb 139 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 140
matthewgascoyne 10:d74124f266cb 141 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 142 // "check_usb_rec_flg" : Function to see if any bytes
matthewgascoyne 10:d74124f266cb 143 // have come in, on the USB serial. Returns the
matthewgascoyne 10:d74124f266cb 144 // usb_receive_flg.
matthewgascoyne 10:d74124f266cb 145 bool check_usb_rec_flg(void);
matthewgascoyne 10:d74124f266cb 146 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 147
matthewgascoyne 10:d74124f266cb 148 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 149 // "clr_usb_rec_flg" : Function to clear the
matthewgascoyne 10:d74124f266cb 150 // usb_receive_flg.
matthewgascoyne 10:d74124f266cb 151 void clr_usb_rec_flg(void);
matthewgascoyne 10:d74124f266cb 152 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 153
matthewgascoyne 10:d74124f266cb 154 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 155 // "usb_serial_r" : Function to deal with serial bytes
matthewgascoyne 10:d74124f266cb 156 // being received via USB serial. When a byte is rec'd
matthewgascoyne 10:d74124f266cb 157 // it is copied to a circular buffer and then a rec'd
matthewgascoyne 10:d74124f266cb 158 // flag is asserted to show that action is needed.
matthewgascoyne 10:d74124f266cb 159 void usb_serial_r (void);
matthewgascoyne 10:d74124f266cb 160 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 161
matthewgascoyne 10:d74124f266cb 162 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 163 // "usb_serial_t" : Function to send array of characters
matthewgascoyne 10:d74124f266cb 164 // to the host PC via the usb serial. Returns the number
matthewgascoyne 10:d74124f266cb 165 // of characters written to the USB serial.
matthewgascoyne 10:d74124f266cb 166 uint8_t usb_serial_t (char txstring[]);
matthewgascoyne 10:d74124f266cb 167 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 168
matthewgascoyne 10:d74124f266cb 169 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 170 // "c_lookchk" : Function to check to see if the command
matthewgascoyne 10:d74124f266cb 171 // byte exists in any of the lookup tables. If it does
matthewgascoyne 10:d74124f266cb 172 // then true is returned.
matthewgascoyne 10:d74124f266cb 173 bool c_lookchk (uint8_t command);
matthewgascoyne 10:d74124f266cb 174 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 175
matthewgascoyne 10:d74124f266cb 176 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 177 // "c_looklen" : Function to lookup the defined length of
matthewgascoyne 10:d74124f266cb 178 // the given command's data bytes. Returns the number of
matthewgascoyne 10:d74124f266cb 179 // data bytes that should exist.
matthewgascoyne 10:d74124f266cb 180 uint8_t c_looklen (uint8_t command);
matthewgascoyne 10:d74124f266cb 181 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 182
matthewgascoyne 10:d74124f266cb 183 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 184 // "check_msg" : That generates the final check byte from
matthewgascoyne 10:d74124f266cb 185 // the message found between tmp_pnt and chk_pnt. If the
matthewgascoyne 10:d74124f266cb 186 // check byte matches then true is returned.
matthewgascoyne 10:d74124f266cb 187 bool check_msg(uint8_t tmp_pnt, uint8_t chk_pnt);
matthewgascoyne 10:d74124f266cb 188 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 189
matthewgascoyne 10:d74124f266cb 190 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 191 // "usb_serial_bufscan" : Function to check the INPUT
matthewgascoyne 10:d74124f266cb 192 // BUFFER to see if a valid command has been received. If
matthewgascoyne 10:d74124f266cb 193 // so then the function returns with the command ID.
matthewgascoyne 10:d74124f266cb 194 uint8_t usb_serial_bufscan (void);
matthewgascoyne 10:d74124f266cb 195 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 196
matthewgascoyne 10:d74124f266cb 197 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 198 // "usb_serial_setup" : Function to set up the USB serial
matthewgascoyne 10:d74124f266cb 199 // interface.
matthewgascoyne 10:d74124f266cb 200 void usb_serial_setup (void);
matthewgascoyne 10:d74124f266cb 201 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 202
matthewgascoyne 10:d74124f266cb 203 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 204 // "dio_setup" : Function to set up the standard digi IO
matthewgascoyne 10:d74124f266cb 205 void dio_setup (void);
matthewgascoyne 10:d74124f266cb 206 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 207
matthewgascoyne 10:d74124f266cb 208 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 209 // "servo_setup" : Function to set up the standard servos
matthewgascoyne 10:d74124f266cb 210 void servo_setup (void);
matthewgascoyne 10:d74124f266cb 211 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 212
matthewgascoyne 10:d74124f266cb 213 /////////////////////////////////////////////////////////
matthewgascoyne 10:d74124f266cb 214 // "startup_config" : Function to set up all the defaults
matthewgascoyne 10:d74124f266cb 215 // for the system.
matthewgascoyne 10:d74124f266cb 216 void startup_config (void);
matthewgascoyne 10:d74124f266cb 217 /////////////////////////////////////////////////////////