Skip to content

Commit

Permalink
[rt_paparazzi] cleanup
Browse files Browse the repository at this point in the history
Based on @flixr's comments
1) [i2c|uart|spi]_pprzi.c renamed to _pprz.c
2) fixed doxygen comments, cleaned up code style
3) cleaned ms5611 periph to be more better integrated with ChibiOS
4) ImuEvent moved into main_chibios.c
5) main_chibios.c cleaned
6) supressed warnings for unused arguments in arch functions
7) fixed callback for threads (see example with GPS thread)
8) uart_receive_x macro changed into a function (look at GPS thread)
9) defined SPI_VOLATILE qualifier for SPI volatile buffers
  • Loading branch information
podhrmic authored and flixr committed Nov 26, 2013
1 parent f2ef433 commit f3ed335
Show file tree
Hide file tree
Showing 33 changed files with 555 additions and 497 deletions.
5 changes: 2 additions & 3 deletions conf/firmwares/rotorcraft_rt.makefile
Expand Up @@ -43,7 +43,6 @@ ROTORCRAFT_INC = -I$(SRC_FIRMWARE) -I$(SRC_BOARD)
ap.ARCHDIR = $(ARCH)

#we are using normal rotorcraft firmware, just different arch
$(TARGET).CFLAGS += -DFIRMWARE=ROTORCRAFT
$(TARGET).CFLAGS += -DUSE_CHIBIOS_RTOS
ap.CFLAGS += $(ROTORCRAFT_INC)
ap.CFLAGS += -DBOARD_CONFIG=$(BOARD_CFG) -DPERIPHERALS_AUTO_INIT
Expand Down Expand Up @@ -91,12 +90,12 @@ endif
ap.srcs += subsystems/settings.c

#ap.srcs += mcu_periph/uart.c -> two file problem, see: http://www.cplusplus.com/forum/general/35718/
ap.srcs += mcu_periph/uart_pprzi.c
ap.srcs += mcu_periph/uart_pprz.c
ap.srcs += $(SRC_ARCH)/mcu_periph/uart_arch.c

# I2C
ifeq ($(TARGET), ap)
$(TARGET).srcs += mcu_periph/i2c_pprzi.c
$(TARGET).srcs += mcu_periph/i2c_pprz.c
$(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.c
endif

Expand Down
2 changes: 1 addition & 1 deletion conf/firmwares/subsystems/shared/spi_master.makefile
Expand Up @@ -6,7 +6,7 @@ SPI_INCLUDED = 1

#generic spi master driver
SPI_CFLAGS = -DUSE_SPI -DSPI_MASTER
SPI_SRCS = mcu_periph/spi_pprzi.c $(SRC_ARCH)/mcu_periph/spi_arch.c
SPI_SRCS = mcu_periph/spi_pprz.c $(SRC_ARCH)/mcu_periph/spi_arch.c

ap.CFLAGS += $(SPI_CFLAGS)
ap.srcs += $(SPI_SRCS)
Expand Down
10 changes: 7 additions & 3 deletions sw/airborne/arch/chibios/STM32F107xC.ld
Expand Up @@ -25,11 +25,15 @@
for full details of how and when the exception can be applied.
*/

/*
* ST32F107xC memory setup.
/**
* @file arch/chibios/STM32F107xC.ld
* ST32F107xC memory setup and linker script
*
* Modified by Michal Podhradsky, 2013
* Flash addr is shifted by 8kb (luftboot)
* Flash address is shifted by 8kb (Luftboot)
* Note: probably not the cleanest solution, but it works
*
* __process_stack_size__ determines stack size of main() thread
*/
__main_stack_size__ = 0x0400;
__process_stack_size__ = 0x0400;
Expand Down
5 changes: 3 additions & 2 deletions sw/airborne/arch/chibios/led_hw.h
Expand Up @@ -24,7 +24,8 @@
* Boston, MA 02111-1307, USA.
*/
/**
* @brief chibios arch dependant led manipulation macros
* @file arch/chibios/led_hw.h
* Led macro implementation for ChibiOS arch
*/
#ifndef LED_HW_H
#define LED_HW_H
Expand All @@ -35,7 +36,7 @@
#include "hal.h"

/*
* Regular GPIO driven LEDs
* Regular GPIO driven LEDs
*/
#define _LED_GPIO(i) i
#define _LED_GPIO_PIN(i) i
Expand Down
8 changes: 5 additions & 3 deletions sw/airborne/arch/chibios/mcu_arch.c
Expand Up @@ -24,9 +24,11 @@
* Boston, MA 02111-1307, USA.
*/
/**
* @brief chibios arch dependant microcontroller initialisation functions.
* @details Mostly empty defines, because Chibios takes
* care of mcu initialization
* @file arch/chibios/mcu_arch.c
* Microcontroller initialization function for ChibiOS
*
* ChibiOS initialized peripherals by itself, only interrupt
* vector has to be relocated for Luftboot
*/
#include "mcu.h"
#include "ch.h"
Expand Down
8 changes: 5 additions & 3 deletions sw/airborne/arch/chibios/mcu_arch.h
Expand Up @@ -24,9 +24,11 @@
* Boston, MA 02111-1307, USA.
*/
/**
* @brief chibios arch dependant microcontroller initialisation functions.
* @details Mostly empty defines, because Chibios takes
* care of mcu initialization
* @file arch/chibios/mcu_arch.h
* Microcontroller initialization function for ChibiOS
*
* ChibiOS initialized peripherals by itself, hence empty
* functions for Paparazzi compatibility.
*/
#ifndef CHIBIOS_MCU_ARCH_H
#define CHIBIOS_MCU_ARCH_H
Expand Down
4 changes: 2 additions & 2 deletions sw/airborne/arch/chibios/mcu_periph/adc_arch.h
Expand Up @@ -37,11 +37,11 @@
#include "hal.h"


/// ADC error flags
// ADC error flags
extern uint8_t adc_error_flag;
extern ADCDriver* adcp_err;

/// NB_ADCx_CHANNELS
// NB_ADCx_CHANNELS
enum adc1_channels {
#if USE_AD1_1
ADC1_C1,
Expand Down
6 changes: 2 additions & 4 deletions sw/airborne/arch/chibios/mcu_periph/gpio_arch.c
Expand Up @@ -24,9 +24,7 @@
* Boston, MA 02111-1307, USA.
*/
/**
* @brief chibios arch dependant gpio functions
* @details In Chibios palSet/Clear/Toggle(port, pin)
* replaces gpio functions
*
* @file arch/chibios/mcu_periph/gpio_arch.c
* gpio functions implemented for ChibiOS arch
*/
#include "mcu_periph/gpio.h"
6 changes: 2 additions & 4 deletions sw/airborne/arch/chibios/mcu_periph/gpio_arch.h
Expand Up @@ -24,10 +24,8 @@
* Boston, MA 02111-1307, USA.
*/
/**
* @brief chibios arch dependant gpio functions
* @details In Chibios palSet/Clear/Toggle(port, pin)
* replaces gpio functions
*
* @file arch/chibios/mcu_periph/gpio_arch.h
* gpio functions implemented for ChibiOS arch
*/
#ifndef GPIO_ARCH_H
#define GPIO_ARCH_H
Expand Down
67 changes: 33 additions & 34 deletions sw/airborne/arch/chibios/mcu_periph/i2c_arch.c
Expand Up @@ -89,10 +89,7 @@ void i2c_event(void){}
* Empty, for paparazzi compatibility only. Bitrate is already
* set in i2cX_hw_init()
*/
void i2c_setbitrate(struct i2c_periph* p, int bitrate){
(void) p;
(void) bitrate;
}
void i2c_setbitrate(struct i2c_periph* p __attribute__((unused)), int bitrate __attribute__((unused))){}

/**
* i2c_submit() function
Expand All @@ -104,6 +101,10 @@ void i2c_setbitrate(struct i2c_periph* p, int bitrate){
* Note that we are using the same buffer for transmit and recevive. It is
* OK because in i2c transaction is Tx always before Rx.
*
* I2C calls are synchronous, timeout is set to 1/PERIODIC_FREQUENCY seconds
* TODO: Note that on STM32F1xx such as Lia board I2C bus can easily hang in
* an interrupt (see issue #531). Use I2C bus with care and caution.
*
* @param[in] p pointer to a @p i2c_periph struct
* @param[in] t pointer to a @p i2c_transaction struct
*/
Expand All @@ -117,50 +118,48 @@ bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t){
i2cReleaseBus((I2CDriver*)p->reg_addr);

if (status != RDY_OK) {
t->status = I2CTransFailed;
static i2cflags_t errors = 0;
errors = i2cGetErrors((I2CDriver*)p->reg_addr);
if (errors & I2CD_BUS_ERROR) {
p->errors->miss_start_stop_cnt++;
}
if (errors & I2CD_ARBITRATION_LOST) {
p->errors->arb_lost_cnt++;
}
if (errors & I2CD_ACK_FAILURE) {
p->errors->ack_fail_cnt++;
}
if (errors & I2CD_OVERRUN) {
p->errors->over_under_cnt++;
}
if (errors & I2CD_PEC_ERROR) {
p->errors->pec_recep_cnt++;
}
if (errors & I2CD_TIMEOUT) {
p->errors->timeout_tlow_cnt++;
}
if (errors & I2CD_SMB_ALERT) {
p->errors->smbus_alert_cnt++;
}
return FALSE;
t->status = I2CTransFailed;
static i2cflags_t errors = 0;
errors = i2cGetErrors((I2CDriver*)p->reg_addr);
if (errors & I2CD_BUS_ERROR) {
p->errors->miss_start_stop_cnt++;
}
if (errors & I2CD_ARBITRATION_LOST) {
p->errors->arb_lost_cnt++;
}
if (errors & I2CD_ACK_FAILURE) {
p->errors->ack_fail_cnt++;
}
if (errors & I2CD_OVERRUN) {
p->errors->over_under_cnt++;
}
if (errors & I2CD_PEC_ERROR) {
p->errors->pec_recep_cnt++;
}
if (errors & I2CD_TIMEOUT) {
p->errors->timeout_tlow_cnt++;
}
if (errors & I2CD_SMB_ALERT) {
p->errors->smbus_alert_cnt++;
}
return FALSE;
}
else {
t->status = I2CTransSuccess;
return TRUE;
t->status = I2CTransSuccess;
return TRUE;
}
#else
(void) p;
(void) t;
return FALSE;
#endif

}

/**
* i2c_idle() function
*
* Empty, for paparazzi compatibility only
*/
bool_t i2c_idle(struct i2c_periph* p){
(void) p;
bool_t i2c_idle(struct i2c_periph* p __attribute__((unused))){
return FALSE;
}

0 comments on commit f3ed335

Please sign in to comment.