Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sub.hpp
- Committer:
- nagasm
- Date:
- 2014-12-09
- Revision:
- 0:14c6afea35c7
File content as of revision 0:14c6afea35c7:
unsigned char rxFIFO[256], txFIFO[256], raw_data[6];
unsigned char rx_top, rx_end, tx_top, tx_end, phase;
int timer_value[6];
RawSerial xbee(PA_2, PA_3);
Ticker timer_setup;
AnalogIn analog_value0(A0);
AnalogIn analog_value1(A1);
AnalogIn analog_value2(A2);
AnalogIn analog_value3(A3);
DigitalOut myled(LED1);
void common_setup(){
rx_top = rx_end = tx_top = tx_end = phase = 0;
}
void timer_interrupt(){
int i;
for (i=0; i<6; i++) ++timer_value[i] &= 65535;
}
void tx_fifo_check(){
if(xbee.writeable() == 1){
if(tx_top != tx_end){
xbee.putc(txFIFO[tx_end]);
++tx_end &= 255;
}
}
}
int rx_fifo_check(){
unsigned char data;
if(rx_top != rx_end){
data = rxFIFO[rx_end];
++rx_end &= 255;
if (data < 33){
phase = 0;
return(1);
}
raw_data[phase] = data;
if(++phase > 5) phase = 0;
return(0);
}
return(0);
}
void rx_fifoset(void){
rxFIFO[rx_top] = xbee.getc();
++rx_top &= 255;
}
void tx_fifoset(unsigned char data){
txFIFO[tx_top] = data;
++tx_top &= 255;
}
unsigned char hex_conv(unsigned char data){
data &= 15;
if(data < 10) return(data+48);
else return(data+55);
}
unsigned char conv_hex(unsigned char data){
if((data > 47) && (data < 58)) return(data-48);
else if((data > 64) && (data < 71)) return(data-55);
return(0);
}
void tx_message(int data){
int i;
for (i=0; i<6; i++) tx_fifoset(hex_conv((data>>(4*(5-i))) & 15));
tx_fifoset(13);
}