From 86855bce3598f21f1b1c81329f98cdc434edfa7d Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Sat, 21 Apr 2012 16:58:09 +0200 Subject: digital/beacon: use different debug files for simu or avr mode --- digital/beacon/src/calibration.c | 2 +- digital/beacon/src/codewheel.c | 2 +- digital/beacon/src/debug.c | 226 --------------------------------------- digital/beacon/src/debug.h | 113 -------------------- digital/beacon/src/debug_avr.c | 226 +++++++++++++++++++++++++++++++++++++++ digital/beacon/src/debug_avr.h | 70 ++++++++++++ digital/beacon/src/debug_simu.h | 75 +++++++++++++ digital/beacon/src/formula.c | 2 +- digital/beacon/src/laser.c | 2 +- digital/beacon/src/main_avr.c | 2 +- digital/beacon/src/network.c | 2 +- digital/beacon/src/position.c | 2 +- digital/beacon/src/recovery.c | 2 +- digital/beacon/src/servo.c | 2 +- digital/beacon/src/trust.c | 2 +- digital/beacon/src/update.c | 2 +- 16 files changed, 382 insertions(+), 350 deletions(-) delete mode 100644 digital/beacon/src/debug.c delete mode 100644 digital/beacon/src/debug.h create mode 100644 digital/beacon/src/debug_avr.c create mode 100644 digital/beacon/src/debug_avr.h create mode 100644 digital/beacon/src/debug_simu.h (limited to 'digital/beacon/src') diff --git a/digital/beacon/src/calibration.c b/digital/beacon/src/calibration.c index 75e33fba..fe661407 100644 --- a/digital/beacon/src/calibration.c +++ b/digital/beacon/src/calibration.c @@ -24,7 +24,7 @@ * }}} */ #include -#include "debug.h" +#include "debug_avr.h" #include "servo.h" #include "calibration.h" diff --git a/digital/beacon/src/codewheel.c b/digital/beacon/src/codewheel.c index efcd9931..32b45b37 100644 --- a/digital/beacon/src/codewheel.c +++ b/digital/beacon/src/codewheel.c @@ -25,7 +25,7 @@ #include #include -#include "debug.h" +#include "debug_avr.h" #include "codewheel.h" diff --git a/digital/beacon/src/debug.c b/digital/beacon/src/debug.c deleted file mode 100644 index fb2cf589..00000000 --- a/digital/beacon/src/debug.c +++ /dev/null @@ -1,226 +0,0 @@ -/* debug.c */ -/* Beacon debug interface. {{{ - * - * Copyright (C) 2012 Florent Duchon - * - * APBTeam: - * Web: http://apbteam.org/ - * Email: team AT apbteam DOT org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * }}} */ -#include -#include -#include -#include "configuration.h" -#include "calibration.h" -#include "debug.h" -#include "servo.h" -#include "codewheel.h" -#include "laser.h" -#include "network.h" - -HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack) -HAL_AppTimer_t debugTimer; // TIMER descripor used by the DEBUG task -HAL_AppTimer_t wheelTimer; // TIMER descripor used by the DEBUG task - -uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer -uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer - -TUSART_buffer_level TXbuffer_level = EMPTY; // TX buffer state -TUSART_bus_state TXbus_state = FREE; // TX line state - -uint16_t start_offset = 0; // Start offset for TX buffer -uint16_t end_offset = 0; // Stop offset for TX buffer - - - -/* This function initializes the USART interface for debugging on avr */ - void initSerialInterface(void) - { - appUsartDescriptor.tty = USART_CHANNEL; - appUsartDescriptor.mode = USART_MODE_ASYNC; - appUsartDescriptor.baudrate = USART_BAUDRATE_38400; - appUsartDescriptor.dataLength = USART_DATA8; - appUsartDescriptor.parity = USART_PARITY_EVEN; - appUsartDescriptor.stopbits = USART_STOPBIT_1; - appUsartDescriptor.rxBuffer = usartRxBuffer; - appUsartDescriptor.rxBufferLength = sizeof(usartRxBuffer); - appUsartDescriptor.txBuffer = NULL; // use callback mode - appUsartDescriptor.txBufferLength = 0; - appUsartDescriptor.rxCallback = usartRXCallback; - appUsartDescriptor.txCallback = usartTXCallback; - appUsartDescriptor.flowControl = USART_FLOW_CONTROL_NONE; - OPEN_USART(&appUsartDescriptor); - } - -/* TX USART Callback */ -void usartTXCallback(void) -{ - /* If buffer is not empty continue to send via USART line */ - if(TXbuffer_level != EMPTY) - { - WRITE_USART(&appUsartDescriptor,usartTxBuffer+start_offset,end_offset); - TXbuffer_level = FILLED; - } - else - { - /* Bus is free so reset variables and flags */ - memset(usartTxBuffer,0,APP_USART_TX_BUFFER_SIZE); - start_offset = 0; - end_offset = 0; - TXbus_state = FREE; - } -} - -/* RX USART Callback */ -void usartRXCallback(uint16_t bytesToRead) -{ - uint8_t rxBuffer; - - /* Read RX buffer from HAL */ - READ_USART(&appUsartDescriptor,&rxBuffer,bytesToRead); - - switch(rxBuffer) - { - case 'o': - /* Increase servo 1 angle */ - uprintf("SERVO_1 = %d\r\n",servo_angle_increase(SERVO_1)); - break; - case 'l': - /* Decrease servo 1 angle */ - uprintf("SERVO_1 = %d\r\n",servo_angle_decrease(SERVO_1)); - break; - case 'p': - /* Increase servo 2 angle */ - uprintf("SERVO_2 = %d\r\n",servo_angle_increase(SERVO_2)); - break; - case 'm': - /* Decrease servo 2 angle */ - uprintf("SERVO_2 = %d\r\n",servo_angle_decrease(SERVO_2)); - break; - case 'a': - uprintf("CodeWheel Value = %d\r\n",codewheel_get_value()); - break; - case 'd': - debug_start_stop_task(); - break; - case 'z': - codewheel_reset(); - break; - case 'c': - calibration_start_stop_task(); - break; - case 'q': - calibration_set_laser_flag(SET); - break; - case 'w': -// wheel_start_stop_task(); -// uprintf("TCNT3 = %d\r\n",TCNT3); - TIMSK3 &= ~(1< -#include "configuration.h" - -#define OPEN_USART HAL_OpenUsart -#define CLOSE_USART HAL_CloseUsart -#define WRITE_USART HAL_WriteUsart -#define READ_USART HAL_ReadUsart -#define USART_CHANNEL APP_USART_CHANNEL -#define DEBUG_TASK_PERIOD 700L -#define WHEEL_TASK_PERIOD 1000L - -// #define DEBUG_POSITION_ENABLE -// #define DEBUG_UPDATE_ENABLE -// #define DEBUG_RECOVERY_ENABLE -// #define DEBUG_FORMULA_INFO_ENABLE -// #define DEBUG_FORMULA_ERROR_ENABLE -// #define DEBUG_TRUST_ENABLE - - -#ifdef DEBUG_POSITION_ENABLE - #define DEBUG_POSITION(f, s...) fprintf(stderr,"[position.c:%d] => " f,__LINE__, ## s) -#else - #define DEBUG_POSITION(f,s...) ((void)0) -#endif - -#ifdef DEBUG_UPDATE_ENABLE - #define DEBUG_UPDATE(f, s...) fprintf(stderr,"[update.c:%d] => " f,__LINE__, ## s) -#else - #define DEBUG_UPDATE(f,s...) ((void)0) -#endif - -#ifdef DEBUG_RECOVERY_ENABLE - #define DEBUG_RECOVERY(f, s...) fprintf(stderr,"[recovery.c:%d] => " f,__LINE__, ## s) -#else - #define DEBUG_RECOVERY(f,s...) ((void)0) -#endif - -#ifdef DEBUG_FORMULA_INFO_ENABLE - #define DEBUG_FORMULA_INFO(f, s...) fprintf(stderr,"[formula.c:%d] => " f,__LINE__, ## s) -#else - #define DEBUG_FORMULA_INFO(f,s...) ((void)0) -#endif - -#ifdef DEBUG_FORMULA_ERROR_ENABLE - #define DEBUG_FORMULA_ERROR(f, s...) fprintf(stderr,"[formula.c:%d] => " f,__LINE__, ## s) -#else - #define DEBUG_FORMULA_ERROR(f,s...) ((void)0) -#endif - -#ifdef DEBUG_TRUST_ENABLE - #define DEBUG_TRUST(f, s...) fprintf(stderr,"[trust.c:%d] => " f,__LINE__, ## s) -#else - #define DEBUG_TRUST(f,s...) ((void)0) -#endif - -typedef enum -{ - FREE, - BUSY -} TUSART_bus_state; - -typedef enum -{ - EMPTY, - FILLED -} TUSART_buffer_level; - -/* This function initializes the USART interface for debugging on avr */ -void initSerialInterface(void); - -/* TX USART Callback */ -void usartTXCallback(void); - -/* RX USART Callback */ -void usartRXCallback(uint16_t bytesToRead); - -/* This function sends data string via the USART interface */ -void uprintf(char *format, ...); - -/* This function starts the debug task */ -void debug_start_stop_task(void); - -/* Debug task callback */ -void debug_task(void); - -#endif diff --git a/digital/beacon/src/debug_avr.c b/digital/beacon/src/debug_avr.c new file mode 100644 index 00000000..50dcb1f6 --- /dev/null +++ b/digital/beacon/src/debug_avr.c @@ -0,0 +1,226 @@ +/* debug.c */ +/* Beacon debug interface. {{{ + * + * Copyright (C) 2012 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include +#include +#include +#include "configuration.h" +#include "calibration.h" +#include "debug_avr.h" +#include "servo.h" +#include "codewheel.h" +#include "laser.h" +#include "network.h" + +HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack) +HAL_AppTimer_t debugTimer; // TIMER descripor used by the DEBUG task +HAL_AppTimer_t wheelTimer; // TIMER descripor used by the DEBUG task + +uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer +uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer + +TUSART_buffer_level TXbuffer_level = EMPTY; // TX buffer state +TUSART_bus_state TXbus_state = FREE; // TX line state + +uint16_t start_offset = 0; // Start offset for TX buffer +uint16_t end_offset = 0; // Stop offset for TX buffer + + + +/* This function initializes the USART interface for debugging on avr */ + void initSerialInterface(void) + { + appUsartDescriptor.tty = USART_CHANNEL; + appUsartDescriptor.mode = USART_MODE_ASYNC; + appUsartDescriptor.baudrate = USART_BAUDRATE_38400; + appUsartDescriptor.dataLength = USART_DATA8; + appUsartDescriptor.parity = USART_PARITY_EVEN; + appUsartDescriptor.stopbits = USART_STOPBIT_1; + appUsartDescriptor.rxBuffer = usartRxBuffer; + appUsartDescriptor.rxBufferLength = sizeof(usartRxBuffer); + appUsartDescriptor.txBuffer = NULL; // use callback mode + appUsartDescriptor.txBufferLength = 0; + appUsartDescriptor.rxCallback = usartRXCallback; + appUsartDescriptor.txCallback = usartTXCallback; + appUsartDescriptor.flowControl = USART_FLOW_CONTROL_NONE; + OPEN_USART(&appUsartDescriptor); + } + +/* TX USART Callback */ +void usartTXCallback(void) +{ + /* If buffer is not empty continue to send via USART line */ + if(TXbuffer_level != EMPTY) + { + WRITE_USART(&appUsartDescriptor,usartTxBuffer+start_offset,end_offset); + TXbuffer_level = FILLED; + } + else + { + /* Bus is free so reset variables and flags */ + memset(usartTxBuffer,0,APP_USART_TX_BUFFER_SIZE); + start_offset = 0; + end_offset = 0; + TXbus_state = FREE; + } +} + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead) +{ + uint8_t rxBuffer; + + /* Read RX buffer from HAL */ + READ_USART(&appUsartDescriptor,&rxBuffer,bytesToRead); + + switch(rxBuffer) + { + case 'o': + /* Increase servo 1 angle */ + uprintf("SERVO_1 = %d\r\n",servo_angle_increase(SERVO_1)); + break; + case 'l': + /* Decrease servo 1 angle */ + uprintf("SERVO_1 = %d\r\n",servo_angle_decrease(SERVO_1)); + break; + case 'p': + /* Increase servo 2 angle */ + uprintf("SERVO_2 = %d\r\n",servo_angle_increase(SERVO_2)); + break; + case 'm': + /* Decrease servo 2 angle */ + uprintf("SERVO_2 = %d\r\n",servo_angle_decrease(SERVO_2)); + break; + case 'a': + uprintf("CodeWheel Value = %d\r\n",codewheel_get_value()); + break; + case 'd': + debug_start_stop_task(); + break; + case 'z': + codewheel_reset(); + break; + case 'c': + calibration_start_stop_task(); + break; + case 'q': + calibration_set_laser_flag(SET); + break; + case 'w': +// wheel_start_stop_task(); +// uprintf("TCNT3 = %d\r\n",TCNT3); + TIMSK3 &= ~(1< +#include "configuration.h" + +#define OPEN_USART HAL_OpenUsart +#define CLOSE_USART HAL_CloseUsart +#define WRITE_USART HAL_WriteUsart +#define READ_USART HAL_ReadUsart +#define USART_CHANNEL APP_USART_CHANNEL +#define DEBUG_TASK_PERIOD 700L +#define WHEEL_TASK_PERIOD 1000L + +typedef enum +{ + FREE, + BUSY +} TUSART_bus_state; + +typedef enum +{ + EMPTY, + FILLED +} TUSART_buffer_level; + +/* This function initializes the USART interface for debugging on avr */ +void initSerialInterface(void); + +/* TX USART Callback */ +void usartTXCallback(void); + +/* RX USART Callback */ +void usartRXCallback(uint16_t bytesToRead); + +/* This function sends data string via the USART interface */ +void uprintf(char *format, ...); + +/* This function starts the debug task */ +void debug_start_stop_task(void); + +/* Debug task callback */ +void debug_task(void); + +#endif diff --git a/digital/beacon/src/debug_simu.h b/digital/beacon/src/debug_simu.h new file mode 100644 index 00000000..35c7b346 --- /dev/null +++ b/digital/beacon/src/debug_simu.h @@ -0,0 +1,75 @@ +/* debug.h */ +/* Macro for debug traces. {{{ + * + * Copyright (C) 2011 Florent Duchon + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#ifndef _DEBUG_SIMU_H +#define _DEBUG_SIMU_H + +#include + +// #define DEBUG_POSITION_ENABLE +// #define DEBUG_UPDATE_ENABLE +// #define DEBUG_RECOVERY_ENABLE +// #define DEBUG_FORMULA_INFO_ENABLE +// #define DEBUG_FORMULA_ERROR_ENABLE +// #define DEBUG_TRUST_ENABLE + + +#ifdef DEBUG_POSITION_ENABLE + #define DEBUG_POSITION(f, s...) fprintf(stderr,"[position.c:%d] => " f,__LINE__, ## s) +#else + #define DEBUG_POSITION(f,s...) ((void)0) +#endif + +#ifdef DEBUG_UPDATE_ENABLE + #define DEBUG_UPDATE(f, s...) fprintf(stderr,"[update.c:%d] => " f,__LINE__, ## s) +#else + #define DEBUG_UPDATE(f,s...) ((void)0) +#endif + +#ifdef DEBUG_RECOVERY_ENABLE + #define DEBUG_RECOVERY(f, s...) fprintf(stderr,"[recovery.c:%d] => " f,__LINE__, ## s) +#else + #define DEBUG_RECOVERY(f,s...) ((void)0) +#endif + +#ifdef DEBUG_FORMULA_INFO_ENABLE + #define DEBUG_FORMULA_INFO(f, s...) fprintf(stderr,"[formula.c:%d] => " f,__LINE__, ## s) +#else + #define DEBUG_FORMULA_INFO(f,s...) ((void)0) +#endif + +#ifdef DEBUG_FORMULA_ERROR_ENABLE + #define DEBUG_FORMULA_ERROR(f, s...) fprintf(stderr,"[formula.c:%d] => " f,__LINE__, ## s) +#else + #define DEBUG_FORMULA_ERROR(f,s...) ((void)0) +#endif + +#ifdef DEBUG_TRUST_ENABLE + #define DEBUG_TRUST(f, s...) fprintf(stderr,"[trust.c:%d] => " f,__LINE__, ## s) +#else + #define DEBUG_TRUST(f,s...) ((void)0) +#endif + +#endif diff --git a/digital/beacon/src/formula.c b/digital/beacon/src/formula.c index 8391b8f8..03f34dd4 100644 --- a/digital/beacon/src/formula.c +++ b/digital/beacon/src/formula.c @@ -24,7 +24,7 @@ * }}} */ #include -#include "debug.h" +#include "debug_simu.h" #include "position.h" #include "formula.h" diff --git a/digital/beacon/src/laser.c b/digital/beacon/src/laser.c index 9d9d1fe0..585e5739 100644 --- a/digital/beacon/src/laser.c +++ b/digital/beacon/src/laser.c @@ -25,7 +25,7 @@ #include #include -#include "debug.h" +#include "debug_avr.h" #include "laser.h" diff --git a/digital/beacon/src/main_avr.c b/digital/beacon/src/main_avr.c index 7e38a6f3..0e4b1d3e 100644 --- a/digital/beacon/src/main_avr.c +++ b/digital/beacon/src/main_avr.c @@ -31,7 +31,7 @@ #include "network.h" #include "position.h" #include "laser.h" -#include "debug.h" +#include "debug_avr.h" #include "servo.h" #include "led.h" #include "twi.h" diff --git a/digital/beacon/src/network.c b/digital/beacon/src/network.c index 723a6abb..0b8785c1 100644 --- a/digital/beacon/src/network.c +++ b/digital/beacon/src/network.c @@ -28,7 +28,7 @@ #include #include "configuration.h" #include "network.h" -#include "debug.h" +#include "debug_avr.h" #include "led.h" diff --git a/digital/beacon/src/position.c b/digital/beacon/src/position.c index ca98b7b5..96bfb5e6 100644 --- a/digital/beacon/src/position.c +++ b/digital/beacon/src/position.c @@ -24,7 +24,7 @@ * }}} */ #include "position.h" -#include "debug.h" +#include "debug_simu.h" #include "recovery.h" #include "update.h" #include "formula.h" diff --git a/digital/beacon/src/recovery.c b/digital/beacon/src/recovery.c index a090b32c..891e35ed 100644 --- a/digital/beacon/src/recovery.c +++ b/digital/beacon/src/recovery.c @@ -27,7 +27,7 @@ #include "position.h" #include "recovery.h" #include "trust.h" -#include "debug.h" +#include "debug_simu.h" /* This function is used to calculate all obstacle positions from sractch */ TRecoveryStatus recovery(coord_s * new_point,opponent_s opp[MAX_OBSTACLE]) diff --git a/digital/beacon/src/servo.c b/digital/beacon/src/servo.c index 2d590c3d..24e502ce 100644 --- a/digital/beacon/src/servo.c +++ b/digital/beacon/src/servo.c @@ -26,7 +26,7 @@ #include #include #include "servo.h" -#include "debug.h" +#include "debug_avr.h" servo_s servo1; servo_s servo2; diff --git a/digital/beacon/src/trust.c b/digital/beacon/src/trust.c index 340a82bd..23823ef8 100644 --- a/digital/beacon/src/trust.c +++ b/digital/beacon/src/trust.c @@ -25,7 +25,7 @@ #include "position.h" #include "trust.h" -#include "debug.h" +#include "debug_simu.h" extern opponent_s opponent[MAX_OBSTACLE]; diff --git a/digital/beacon/src/update.c b/digital/beacon/src/update.c index 7a6805b0..aa1614cf 100644 --- a/digital/beacon/src/update.c +++ b/digital/beacon/src/update.c @@ -26,7 +26,7 @@ #include "position.h" #include "trust.h" #include "update.h" -#include "debug.h" +#include "debug_simu.h" /* Globals Declaration */ extern opponent_s opponent[MAX_OBSTACLE]; -- cgit v1.2.3