32 #include "pprzlink/messages.h"
39 #include "generated/airframe.h"
47 #define ADC_BIT_RES 12
51 #define ADC_VREF 3300.0 //mV
54 #define ADC_VREF_MULT ADC_VREF/(1<<ADC_BIT_RES)
57 #define ADC_VGAIN 1.5 // 1k1 and 2k2 (5V->3.3V)
59 #define DAC_BUFFER_SIZE 1//360
81 .datamode = DAC_DHRM_12BIT_RIGHT
86 .datamode = DAC_DHRM_12BIT_RIGHT
134 CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
135 CAN_BTR_SJW(0) | CAN_BTR_TS2(1) |
136 CAN_BTR_TS1(8) | CAN_BTR_BRP(6)
150 chRegSetThreadName(
"receiver");
151 chEvtRegister(&cip->
canp->rxfull_event, &el, 0);
152 while(!chThdShouldTerminateX()) {
153 if (chEvtWaitAnyTimeout(ALL_EVENTS, TIME_MS2I(100)) == 0)
155 while (canReceive(cip->
canp, CAN_ANY_MAILBOX,
156 &rxmsg, TIME_IMMEDIATE) == MSG_OK) {
162 chEvtUnregister(&cip->
canp->rxfull_event, &el);
174 chRegSetThreadName(
"transmitter");
175 txmsg.IDE = CAN_IDE_EXT;
176 txmsg.EID = 0x01234567;
177 txmsg.RTR = CAN_RTR_DATA;
179 txmsg.data32[0] = 0x55AA55AA;
180 txmsg.data32[1] = 0x00FF00FF;
182 while (!chThdShouldTerminateX()) {
184 canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg, TIME_MS2I(100));
185 chThdSleepMilliseconds(500);
217 canStart(&CAND1, &
cancfg);
218 canStart(&CAND2, &
cancfg);
225 chThdCreateStatic(can_rx1_wa,
sizeof(can_rx1_wa), NORMALPRIO + 7,
226 can_rx, (
void *)&can1);
227 chThdCreateStatic(can_rx2_wa,
sizeof(can_rx2_wa), NORMALPRIO + 7,
228 can_rx, (
void *)&can2);
229 chThdCreateStatic(can_tx_wa,
sizeof(can_tx_wa), NORMALPRIO + 7,
237 palSetPadMode(
GPIOA, 4, PAL_MODE_INPUT_ANALOG);
238 palSetPadMode(
GPIOA, 5, PAL_MODE_INPUT_ANALOG);
296 static bool flag =
false;
static THD_FUNCTION(can_rx, p)
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
static const struct can_instance can1
Some architecture independent helper functions for GPIOs.
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
void vms_ecu_demo_downlink(void)
static const struct can_instance can2
static const DACConfig dac1cfg2
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
static const DACConfig dac1cfg1
Viking Motorsports Engine Control Unit demo module see https://wiki.paparazziuav.org/wiki/VMS_ECU for...
static const CANConfig cancfg
static THD_WORKING_AREA(can_rx1_wa, 256)
void vms_ecu_demo_UpdateDac2(uint16_t val)
Common code for AP and FBW telemetry.
void vms_ecu_demo_periodic(void)
#define DEFAULT_AV_NB_SAMPLE
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
void vms_ecu_demo_init(void)
void vms_ecu_demo_UpdateDac1(uint16_t val)
Reset sweep number.