[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paparazzi-commits] [5081] updates for using CAN
From: |
Paul Cox |
Subject: |
[paparazzi-commits] [5081] updates for using CAN |
Date: |
Tue, 20 Jul 2010 14:12:43 +0000 |
Revision: 5081
http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=5081
Author: paulcox
Date: 2010-07-20 14:12:43 +0000 (Tue, 20 Jul 2010)
Log Message:
-----------
updates for using CAN
Modified Paths:
--------------
paparazzi3/trunk/sw/airborne/beth/bench_sensors.c
paparazzi3/trunk/sw/airborne/beth/bench_sensors.h
paparazzi3/trunk/sw/airborne/beth/main_coders.c
paparazzi3/trunk/sw/airborne/beth/main_stm32.c
Modified: paparazzi3/trunk/sw/airborne/beth/bench_sensors.c
===================================================================
--- paparazzi3/trunk/sw/airborne/beth/bench_sensors.c 2010-07-20 14:11:43 UTC
(rev 5080)
+++ paparazzi3/trunk/sw/airborne/beth/bench_sensors.c 2010-07-20 14:12:43 UTC
(rev 5081)
@@ -1,6 +1,6 @@
#include "bench_sensors.h"
-struct BenchSensors bench_sensors;
+struct BenchSensors bench_sensors,bench_sensors2;
void bench_sensors_init(void) {
@@ -8,12 +8,27 @@
bench_sensors.i2c_done = TRUE;
}
+void bench_sensors2_init(void) {
+ bench_sensors2.status = BS_IDLE;
+ bench_sensors2.i2c_done = TRUE;
+}
+
void read_bench_sensors(void) {
- const uint8_t bench_addr = 0x30;
+ const uint8_t bench_addr = 0x40;
bench_sensors.status = BS_BUSY;
bench_sensors.i2c_done = FALSE;
i2c2_receive(bench_addr, 4, &bench_sensors.i2c_done);
}
+
+
+void read_bench_sensors2(void) {
+
+ const uint8_t bench_addr2 = 0x30;
+ bench_sensors2.status = BS_BUSY;
+ bench_sensors2.i2c_done = FALSE;
+ i2c2_receive(bench_addr2, 4, &bench_sensors2.i2c_done);
+
+}
Modified: paparazzi3/trunk/sw/airborne/beth/bench_sensors.h
===================================================================
--- paparazzi3/trunk/sw/airborne/beth/bench_sensors.h 2010-07-20 14:11:43 UTC
(rev 5080)
+++ paparazzi3/trunk/sw/airborne/beth/bench_sensors.h 2010-07-20 14:12:43 UTC
(rev 5081)
@@ -24,7 +24,7 @@
if (bench_sensors.status == BS_BUSY && bench_sensors.i2c_done) { \
bench_sensors.angle_1 = i2c2.buf[0] + (i2c2.buf[1] << 8);
\
bench_sensors.angle_2 = i2c2.buf[2] + (i2c2.buf[3] << 8);
\
- bench_sensors.status = IDLE; \
+ bench_sensors.status = BS_IDLE; \
_handler(); \
} \
}
Modified: paparazzi3/trunk/sw/airborne/beth/main_coders.c
===================================================================
--- paparazzi3/trunk/sw/airborne/beth/main_coders.c 2010-07-20 14:11:43 UTC
(rev 5080)
+++ paparazzi3/trunk/sw/airborne/beth/main_coders.c 2010-07-20 14:12:43 UTC
(rev 5081)
@@ -1,5 +1,6 @@
#include BOARD_CONFIG
#include "init_hw.h"
+#include "can.h"
#include "sys_time.h"
#include "downlink.h"
@@ -17,6 +18,7 @@
/*
*
* PC.01 (ADC Channel11) ext1-20 coder_values[1]
+Paul : using channel 10 instead of 14
* PC.04 (ADC Channel14) ext2-12 coder_values[0]
*
* PB.10 I2C2 SCL ext2-14
@@ -35,19 +37,23 @@
//void i2c2_er_irq_handler(void);
#define ADC1_DR_Address ((uint32_t)0x4001244C)
-static uint16_t coder_values[3];
+static uint16_t coder_values[2];
-#define I2C2_SLAVE_ADDRESS7 0x30
+//azimuth potentiometer board address is 0x30
+//#define I2C2_SLAVE_ADDRESS7 0x30
+//elevation and tilt pot board is 0x40
+#define I2C2_SLAVE_ADDRESS7 0x40
#define I2C2_ClockSpeed 200000
#define MY_I2C2_BUF_LEN 4
static uint8_t i2c2_idx;
static uint8_t i2c2_buf[MY_I2C2_BUF_LEN];
-int main(void) {
+int main(void) {
main_init();
+
while (1) {
if (sys_time_periodic())
main_periodic();
@@ -61,19 +67,24 @@
hw_init();
sys_time_init();
main_init_adc();
- // main_init_i2c2();
+ //main_init_i2c2();
+ //i2c2_init();
+ can_init();
int_enable();
}
-
static inline void main_periodic( void ) {
RunOnceEvery(10, {DOWNLINK_SEND_ALIVE(DefaultChannel, 16, MD5SUM);});
- RunOnceEvery(5, {DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, &coder_values[0],
&coder_values[1]);});
+ //RunOnceEvery(5, {DOWNLINK_SEND_ADC_GENERIC(DefaultChannel,
&coder_values[0], &coder_values[1]);});
+ //RunOnceEvery(5, {DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, &can1_status,
&can1_pending);});
+
+ //ID=2 for tilt/elevation board, ID=1 for azimuth board
+ //the CAN receiver (lisa) determines which board sent it values based on
this ID
+ can_transmit(2, 0, (uint8_t *)coder_values, 8);
-
}
@@ -81,62 +92,7 @@
}
-/*
- *
- * I2C2 : autopilot link
- *
- */
-void i2c2_init(void) {
- //static inline void main_init_i2c2(void) {
- /* System clocks configuration
---------------------------------------------*/
- /* Enable I2C2 clock */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
- /* Enable GPIOB clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
-
- /* NVIC configuration
------------------------------------------------------*/
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
- /* Configure and enable I2C2 event interrupt
-------------------------------*/
- NVIC_InitStructure.NVIC_IRQChannel = I2C2_EV_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Configure and enable I2C2 error interrupt
-------------------------------*/
- NVIC_InitStructure.NVIC_IRQChannel = I2C2_ER_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
- NVIC_Init(&NVIC_InitStructure);
-
-
- /* GPIO configuration
------------------------------------------------------*/
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure I2C2 pins: SCL and SDA
----------------------------------------*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- /* Enable I2C2
-------------------------------------------------------------*/
- I2C_Cmd(I2C2, ENABLE);
- /* I2C2 configuration
------------------------------------------------------*/
- I2C_InitTypeDef I2C_InitStructure;
- I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
- I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
- I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE_ADDRESS7;
- I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
- I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
- I2C_InitStructure.I2C_ClockSpeed = I2C2_ClockSpeed;
- I2C_Init(I2C2, &I2C_InitStructure);
-
- /* Enable I2C1 event and buffer interrupts */
- // I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_BUF, ENABLE);
- I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_ERR, ENABLE);
-
-}
-
-
void i2c2_ev_irq_handler(void) {
switch (I2C_GetLastEvent(I2C2))
{
@@ -165,16 +121,6 @@
}
-void i2c2_er_irq_handler(void) {
- /* Check on I2C2 AF flag and clear it */
- if (I2C_GetITStatus(I2C2, I2C_IT_AF)) {
- I2C_ClearITPendingBit(I2C2, I2C_IT_AF);
- }
-}
-
-
-
-
/*
*
* ADC : coders
@@ -229,7 +175,9 @@
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel14 configuration */
- ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5);
+ //ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1,
ADC_SampleTime_239Cycles5);
+ //Paul: Changing to use chan 10 instead
+ ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_239Cycles5);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
Modified: paparazzi3/trunk/sw/airborne/beth/main_stm32.c
===================================================================
--- paparazzi3/trunk/sw/airborne/beth/main_stm32.c 2010-07-20 14:11:43 UTC
(rev 5080)
+++ paparazzi3/trunk/sw/airborne/beth/main_stm32.c 2010-07-20 14:12:43 UTC
(rev 5081)
@@ -24,14 +24,15 @@
#include BOARD_CONFIG
#include "init_hw.h"
+#include "can.h"
#include "sys_time.h"
#include "downlink.h"
#include "booz/booz2_commands.h"
#include "booz/booz_actuators.h"
//#include "booz/booz_radio_control.h"
#include "booz/booz_imu.h"
-#include "lisa/lisa_overo_link.h"
-#include "beth/bench_sensors.h"
+//#include "lisa/lisa_overo_link.h"
+//#include "beth/bench_sensors.h"
static inline void main_init( void );
static inline void main_periodic( void );
@@ -42,14 +43,14 @@
static inline void main_on_overo_msg_received(void);
static inline void main_on_overo_link_lost(void);
-static inline void main_on_bench_sensors( void );
+//static inline void main_on_bench_sensors( void );
static int16_t my_cnt;
int main(void) {
-
main_init();
+
while (1) {
if (sys_time_periodic())
main_periodic();
@@ -61,33 +62,42 @@
static inline void main_init( void ) {
hw_init();
sys_time_init();
- actuators_init();
- // radio_control_init();
- // booz_imu_init();
- overo_link_init();
- bench_sensors_init();
+ //actuators_init();
+ //radio_control_init();
+ //booz_imu_init();
+ //overo_link_init();
+ //bench_sensors_init();
+ can_init();
}
+//hack to get beth angle values from CAN receive buffer
+extern uint16_t halfw1,halfw2,halfw3,halfw4;
+
static inline void main_periodic( void ) {
- // booz_imu_periodic();
- actuators_set(FALSE);
- OveroLinkPeriodic(main_on_overo_link_lost)
+ //booz_imu_periodic();
+ //actuators_set(FALSE);
+ //OveroLinkPeriodic(main_on_overo_link_lost)
+
RunOnceEvery(10, {LED_PERIODIC(); DOWNLINK_SEND_ALIVE(DefaultChannel, 16,
MD5SUM);});
- read_bench_sensors();
+ RunOnceEvery(5, {DOWNLINK_SEND_BETH(DefaultChannel, &halfw4,
&halfw1,&halfw2, &halfw3);});
+
+ //No longer needed as we switched from I2C to CAN
+ //read_bench_sensors();
}
static inline void main_event( void ) {
- // BoozImuEvent(on_gyro_accel_event, on_mag_event);
- OveroLinkEvent(main_on_overo_msg_received);
+ //BoozImuEvent(on_gyro_accel_event, on_mag_event);
+ //OveroLinkEvent(main_on_overo_msg_received);
- BenchSensorsEvent(main_on_bench_sensors);
+ //No longer needed as we switched from I2C to CAN
+ //BenchSensorsEvent(main_on_bench_sensors);
}
static inline void main_on_overo_msg_received(void) {
- struct AutopilotMessageBethUp* msg_out = (struct
AutopilotMessageBethUp*)overo_link.msg_out;
+/* struct AutopilotMessageBethUp* msg_out = (struct
AutopilotMessageBethUp*)overo_link.msg_out;
msg_out->gyro.x = booz_imu.gyro.p;
msg_out->gyro.y = booz_imu.gyro.q;
msg_out->gyro.z = booz_imu.gyro.r;
@@ -97,15 +107,13 @@
msg_out->bench_sensor.x = my_cnt;
msg_out->bench_sensor.y = my_cnt;
msg_out->bench_sensor.z = my_cnt;
- my_cnt++;
+ my_cnt++;*/
}
static inline void main_on_overo_link_lost(void) {
my_cnt = 0;
}
-
-
static inline void on_gyro_accel_event(void) {
BoozImuScaleGyro();
BoozImuScaleAccel();
@@ -162,9 +170,13 @@
static inline void main_on_bench_sensors( void ) {
+ /*
+ DOWNLINK_SEND_BETH(DefaultChannel, &halfw4, &halfw1,&halfw2, &halfw3);
+
&bench_sensors.angle_1,&bench_sensors.angle_2,&bench_sensors.angle_1,
+ &bench_sensors.angle_2);*/
+
+ //DOWNLINK_SEND_ADC_GENERIC(DefaultChannel,
&bench_sensors.angle_1,&bench_sensors.angle_2);
+ //DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, &can1_status, &can1_pending);
+ //DOWNLINK_SEND_ADC_GENERIC(DefaultChannel, &halfw1, &halfw2);
- DOWNLINK_SEND_ADC_GENERIC(DefaultChannel,
- &bench_sensors.angle_1,
- &bench_sensors.angle_2);
-
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paparazzi-commits] [5081] updates for using CAN,
Paul Cox <=