mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-21 17:21:04 +03:00
usbcan_relay: add standalone buttons reactions
This commit is contained in:
0
F0-nolib/CANbus_stepper/src/canstepper.bin
Executable file → Normal file
0
F0-nolib/CANbus_stepper/src/canstepper.bin
Executable file → Normal file
0
F0-nolib/Chiller/chiller.bin
Executable file → Normal file
0
F0-nolib/Chiller/chiller.bin
Executable file → Normal file
0
F0-nolib/F0_testbrd/pl2303.bin
Executable file → Normal file
0
F0-nolib/F0_testbrd/pl2303.bin
Executable file → Normal file
0
F0-nolib/QuadEncoder/encoder.bin
Executable file → Normal file
0
F0-nolib/QuadEncoder/encoder.bin
Executable file → Normal file
0
F0-nolib/Servo/servo.bin
Executable file → Normal file
0
F0-nolib/Servo/servo.bin
Executable file → Normal file
0
F0-nolib/Socket_fans/sockfans.bin
Executable file → Normal file
0
F0-nolib/Socket_fans/sockfans.bin
Executable file → Normal file
0
F0-nolib/TM1637/tm1637.bin
Executable file → Normal file
0
F0-nolib/TM1637/tm1637.bin
Executable file → Normal file
0
F0-nolib/USBHID/usbhid.bin
Executable file → Normal file
0
F0-nolib/USBHID/usbhid.bin
Executable file → Normal file
0
F0-nolib/USB_pl2303_snippet/usb.bin
Executable file → Normal file
0
F0-nolib/USB_pl2303_snippet/usb.bin
Executable file → Normal file
0
F0-nolib/blink/blink.bin
Normal file → Executable file
0
F0-nolib/blink/blink.bin
Normal file → Executable file
0
F0-nolib/canbus/src/canbus.bin
Executable file → Normal file
0
F0-nolib/canbus/src/canbus.bin
Executable file → Normal file
0
F0-nolib/htu21d_nucleo/usart.bin
Executable file → Normal file
0
F0-nolib/htu21d_nucleo/usart.bin
Executable file → Normal file
@@ -1 +1 @@
|
||||
/home/eddy/Yandex.Disk/Projects/stm32samples/F0-nolib/inc/Fx
|
||||
Fx
|
||||
@@ -453,7 +453,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
|
||||
{
|
||||
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
|
||||
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack));
|
||||
}
|
||||
|
||||
|
||||
|
||||
0
F0-nolib/morze/morze.bin
Executable file → Normal file
0
F0-nolib/morze/morze.bin
Executable file → Normal file
0
F0-nolib/pl2303/pl2303.bin
Executable file → Normal file
0
F0-nolib/pl2303/pl2303.bin
Executable file → Normal file
0
F0-nolib/tsys01_nucleo/tsys01.bin
Executable file → Normal file
0
F0-nolib/tsys01_nucleo/tsys01.bin
Executable file → Normal file
0
F0-nolib/uart_blink/uartblink.bin
Executable file → Normal file
0
F0-nolib/uart_blink/uartblink.bin
Executable file → Normal file
0
F0-nolib/uart_blink_dma/uartblink.bin
Executable file → Normal file
0
F0-nolib/uart_blink_dma/uartblink.bin
Executable file → Normal file
0
F0-nolib/uart_nucleo/usart.bin
Executable file → Normal file
0
F0-nolib/uart_nucleo/usart.bin
Executable file → Normal file
@@ -48,14 +48,25 @@ CAN_status CAN_get_status(){
|
||||
#ifdef EBUG
|
||||
if(st == CAN_FIFO_OVERRUN) MSG("fifo 0 overrun\n");
|
||||
#endif
|
||||
if(st == CAN_FIFO_OVERRUN) can_status = CAN_READY;
|
||||
if(st == CAN_FIFO_OVERRUN){
|
||||
SEND("FIFO overrun\n");
|
||||
can_status = CAN_READY;
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
// push next message into buffer; return 1 if buffer overfull
|
||||
static int CAN_messagebuf_push(CAN_message *msg){
|
||||
//MSG("Try to push\n");
|
||||
if(first_free_idx == first_nonfree_idx) return 1; // no free space
|
||||
#ifdef EBUG
|
||||
SEND("push\n");
|
||||
#endif
|
||||
if(first_free_idx == first_nonfree_idx){
|
||||
#ifdef EBUG
|
||||
SEND("INBUF OVERFULL\n");
|
||||
#endif
|
||||
return 1; // no free space
|
||||
}
|
||||
if(first_nonfree_idx < 0) first_nonfree_idx = 0; // first message in empty buffer
|
||||
memcpy(&messages[first_free_idx++], msg, sizeof(CAN_message));
|
||||
// need to roll?
|
||||
@@ -155,7 +166,7 @@ void CAN_setup(uint16_t speed){
|
||||
CAN->sFilterRegister[0].FR1 = (1<<21)|(1<<5); // all odd IDs
|
||||
CAN->FFA1R = 2; // filter 1 for FIFO1, filter 0 - for FIFO0
|
||||
CAN->sFilterRegister[1].FR1 = (1<<21); // all even IDs
|
||||
CAN->FMR &=~ CAN_FMR_FINIT; /* (12) */
|
||||
CAN->FMR &= ~CAN_FMR_FINIT; /* (12) */
|
||||
CAN->IER |= CAN_IER_ERRIE | CAN_IER_FOVIE0 | CAN_IER_FOVIE1; /* (13) */
|
||||
|
||||
/* Configure IT */
|
||||
@@ -202,8 +213,8 @@ void can_proc(){
|
||||
case 7: errmsg = "(set by software)"; break;
|
||||
}
|
||||
SEND(errmsg); SEND(" error\n");
|
||||
if(CAN->ESR & CAN_ESR_BOFF) SEND("Bus off");
|
||||
if(CAN->ESR & CAN_ESR_EPVF) SEND("Passive error limit");
|
||||
if(CAN->ESR & CAN_ESR_BOFF) SEND("Bus off ");
|
||||
if(CAN->ESR & CAN_ESR_EPVF) SEND("Passive error limit ");
|
||||
if(CAN->ESR & CAN_ESR_EWGF) SEND("Error counter limit");
|
||||
NL();
|
||||
// request abort for all mailboxes
|
||||
@@ -287,6 +298,9 @@ static void can_process_fifo(uint8_t fifo_num){
|
||||
LED_on(LED1); // Turn on LED1 - message received
|
||||
CAN_FIFOMailBox_TypeDef *box = &CAN->sFIFOMailBox[fifo_num];
|
||||
volatile uint32_t *RFxR = (fifo_num) ? &CAN->RF1R : &CAN->RF0R;
|
||||
#ifdef EBUG
|
||||
printu(*RFxR & CAN_RF0R_FMP0); SEND(" messages in FIFO\n");
|
||||
#endif
|
||||
// read all
|
||||
while(*RFxR & CAN_RF0R_FMP0){ // amount of messages pending
|
||||
// CAN_RDTxR: (16-31) - timestamp, (8-15) - filter match index, (0-3) - data length
|
||||
@@ -334,6 +348,13 @@ static void can_process_fifo(uint8_t fifo_num){
|
||||
}
|
||||
|
||||
void cec_can_isr(){
|
||||
/*
|
||||
if(CAN->RF0R & CAN_RF0R_FOVR0){
|
||||
can_process_fifo(0);
|
||||
}
|
||||
if(CAN->RF1R & CAN_RF1R_FOVR1){
|
||||
can_process_fifo(1);
|
||||
}*/
|
||||
if(CAN->RF0R & CAN_RF0R_FOVR0){ // FIFO overrun
|
||||
CAN->RF0R &= ~CAN_RF0R_FOVR0;
|
||||
can_status = CAN_FIFO_OVERRUN;
|
||||
|
||||
@@ -76,7 +76,9 @@ int main(void){
|
||||
USB_setup();
|
||||
CAN_setup(100);
|
||||
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
|
||||
#ifndef EBUG
|
||||
iwdg_setup();
|
||||
#endif
|
||||
|
||||
while (1){
|
||||
IWDG->KR = IWDG_REFRESH; // refresh watchdog
|
||||
@@ -90,22 +92,23 @@ int main(void){
|
||||
SEND("CAN bus fifo overrun occured!\n");
|
||||
sendbuf();
|
||||
}
|
||||
can_mesg = CAN_messagebuf_pop();
|
||||
if(can_mesg && isgood(can_mesg->ID)){
|
||||
LED_on(LED0);
|
||||
lastT = Tms;
|
||||
if(!lastT) lastT = 1;
|
||||
if(ShowMsgs){ // new data in buff
|
||||
IWDG->KR = IWDG_REFRESH;
|
||||
len = can_mesg->length;
|
||||
printu(Tms);
|
||||
SEND(" #");
|
||||
printuhex(can_mesg->ID);
|
||||
for(ctr = 0; ctr < len; ++ctr){
|
||||
SEND(" ");
|
||||
printuhex(can_mesg->data[ctr]);
|
||||
while((can_mesg = CAN_messagebuf_pop())){
|
||||
if(can_mesg && isgood(can_mesg->ID)){
|
||||
LED_on(LED0);
|
||||
lastT = Tms;
|
||||
if(!lastT) lastT = 1;
|
||||
if(ShowMsgs){ // new data in buff
|
||||
IWDG->KR = IWDG_REFRESH;
|
||||
len = can_mesg->length;
|
||||
printu(Tms);
|
||||
SEND(" #");
|
||||
printuhex(can_mesg->ID);
|
||||
for(ctr = 0; ctr < len; ++ctr){
|
||||
SEND(" ");
|
||||
printuhex(can_mesg->data[ctr]);
|
||||
}
|
||||
newline(); sendbuf();
|
||||
}
|
||||
newline(); sendbuf();
|
||||
}
|
||||
}
|
||||
if((txt = get_USB())){
|
||||
|
||||
Binary file not shown.
@@ -19,3 +19,13 @@ Pinout:
|
||||
- PB12..15 - LED0..3 outputs (direct outputs without any protection!!!)
|
||||
|
||||
The pins LEDr0 and LEDr1 are indicated relay works (12V through 2.2kOhm resistor)
|
||||
|
||||
|
||||
### Buttons standalone
|
||||
|
||||
BTN1 - switch relay1
|
||||
|
||||
BTN2 - switch relay 2
|
||||
|
||||
BTN3 - change PWM0: hold to turn ON or turn OFF; press shortly BTN1/BTN2 to increase/decrease PWM0 to 1,
|
||||
hold BTN1/BTN2 to inc/dec PWM0 to 25 (do as many presses as need).
|
||||
@@ -27,6 +27,8 @@ typedef struct{
|
||||
|
||||
static keybase allkeys[BTNSNO] = {0}; // array for buttons' states
|
||||
|
||||
uint32_t lastUnsleep = 0; // last keys activity time
|
||||
|
||||
void process_keys(){
|
||||
static uint32_t lastT = 0;
|
||||
if(Tms == lastT) return;
|
||||
@@ -61,6 +63,7 @@ void process_keys(){
|
||||
}
|
||||
if(e != k->event){
|
||||
k->lastTms = Tms;
|
||||
lastUnsleep = Tms;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,3 +82,9 @@ keyevent keystate(uint8_t k, uint32_t *T){
|
||||
if(T) *T = allkeys[k].lastTms;
|
||||
return evt;
|
||||
}
|
||||
|
||||
// getter of keyevent for allkeys[]
|
||||
keyevent keyevt(uint8_t k){
|
||||
if(k >= BTNSNO) return EVT_NONE;
|
||||
return allkeys[k].event;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ extern uint32_t lastUnsleep; // last keys activity time
|
||||
|
||||
void process_keys();
|
||||
keyevent keystate(uint8_t k, uint32_t *T);
|
||||
keyevent keyevt(uint8_t k);
|
||||
|
||||
#define BUTTONS_H__
|
||||
#endif // BUTTONS_H__
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
static CAN_message messages[CAN_INMESSAGE_SIZE];
|
||||
static uint8_t first_free_idx = 0; // index of first empty cell
|
||||
static int8_t first_nonfree_idx = -1; // index of first data cell
|
||||
static uint16_t oldspeed = 100; // speed of last init
|
||||
static uint16_t oldspeed = DEFAULT_CAN_SPEED; // speed of last init
|
||||
|
||||
#ifdef EBUG
|
||||
static uint32_t last_err_code = 0;
|
||||
@@ -42,10 +42,6 @@ static CAN_message *flood_msg = NULL; // == loc_flood_msg - to flood
|
||||
|
||||
CAN_status CAN_get_status(){
|
||||
CAN_status st = can_status;
|
||||
// give overrun message only once
|
||||
#ifdef EBUG
|
||||
if(st == CAN_FIFO_OVERRUN) MSG("fifo 0 overrun\n");
|
||||
#endif
|
||||
if(st == CAN_FIFO_OVERRUN) can_status = CAN_READY;
|
||||
return st;
|
||||
}
|
||||
@@ -214,9 +210,7 @@ CAN_status can_send(uint8_t *msg, uint8_t len, uint16_t target_id){
|
||||
if(CAN->TSR & (CAN_TSR_TME)){
|
||||
mailbox = (CAN->TSR & CAN_TSR_CODE) >> 24;
|
||||
}else{ // no free mailboxes
|
||||
#ifdef EBUG
|
||||
MSG("No free mailboxes"); NL();
|
||||
#endif
|
||||
//SEND("No free mailboxes"); NL();
|
||||
return CAN_BUSY;
|
||||
}
|
||||
#ifdef EBUG
|
||||
@@ -313,7 +307,7 @@ static void can_process_fifo(uint8_t fifo_num){
|
||||
}
|
||||
}
|
||||
if(msg.ID == CANID) parseCANcommand(&msg);
|
||||
else if(CAN_messagebuf_push(&msg)) return; // error: buffer is full, try later
|
||||
if(CAN_messagebuf_push(&msg)) return; // error: buffer is full, try later
|
||||
*RFxR |= CAN_RF0R_RFOM0; // release fifo for access to next message
|
||||
}
|
||||
//if(*RFxR & CAN_RF0R_FULL0) *RFxR &= ~CAN_RF0R_FULL0;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
* CAN_CMD_LED: data[1] = LEDs state (bits 0..3 for LEDs number 0..3)
|
||||
* CAN_CMD_MCU: data[2,3] = int16_t MCUT*10, data[4,5] = uint16_t Vdd*100 (LITTLE endian!)
|
||||
* CAN_CMD_PWM: data[1..3] = pwm value for each channel (0..2)
|
||||
* CAN_CMD_RELAY: data[0] = (bits 0 & 1) - state of relay N]
|
||||
* CAN_CMD_RELAY: data[1] = (bits 0 & 1) - state of relay N]
|
||||
* CAN_CMD_TMS: data[4..7] = Tms (LITTLE endian!)
|
||||
*/
|
||||
|
||||
@@ -56,13 +56,19 @@ TRUE_INLINE uint8_t ADCget(uint8_t values[8]){
|
||||
|
||||
TRUE_INLINE void BTNSget(uint8_t values[8]){
|
||||
uint32_t T;
|
||||
for(uint8_t i = 0; i < BTNSNO; ++i){
|
||||
uint8_t start = 0, stop = BTNSNO;
|
||||
if(values[1] < BTNSNO){ // check only one button
|
||||
start = values[1]; stop = start + 1;
|
||||
}
|
||||
for(uint8_t i = start; i < stop; ++i){
|
||||
values[1] = i;
|
||||
values[2] = keystate(i, &T);
|
||||
values[3] = 0;
|
||||
*((uint32_t*)&values[4]) = T;
|
||||
int N = 1000;
|
||||
while(CAN_BUSY == can_send(values, 8, OUTPID)) if(--N == 0) break;
|
||||
T = Tms;
|
||||
while(CAN_BUSY == can_send(values, 8, OUTPID)){
|
||||
if(Tms - T > 5) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,22 +147,24 @@ void parseCANcommand(CAN_message *msg){
|
||||
len = ADCget(outpdata);
|
||||
break;
|
||||
case CAN_CMD_BTNS:
|
||||
if(msg->length == 2) outpdata[1] = msg->data[1]; // check only one button
|
||||
else outpdata[1] = BTNSNO;
|
||||
BTNSget(outpdata);
|
||||
return;
|
||||
break;
|
||||
case CAN_CMD_LED:
|
||||
if(setter) LEDSset(msg->data);
|
||||
if(setter && msg->length > 1) LEDSset(msg->data);
|
||||
len = LEDSget(outpdata);
|
||||
break;
|
||||
case CAN_CMD_MCU:
|
||||
len = MCUget(outpdata);
|
||||
break;
|
||||
case CAN_CMD_PWM:
|
||||
if(setter) PWMset(msg->data);
|
||||
if(setter && msg->length > 3) PWMset(msg->data);
|
||||
len = PWMget(outpdata);
|
||||
break;
|
||||
case CAN_CMD_RELAY:
|
||||
if(setter) Rset(msg->data);
|
||||
if(setter && msg->length > 1) Rset(msg->data);
|
||||
len = Rget(outpdata);
|
||||
break;
|
||||
case CAN_CMD_TMS:
|
||||
|
||||
@@ -40,7 +40,7 @@ typedef enum{
|
||||
} CAN_commands;
|
||||
|
||||
// output messages identifier
|
||||
#define OUTPID (CANID + 0x100)
|
||||
#define OUTPID (CANID)
|
||||
|
||||
void parseCANcommand(CAN_message *msg);
|
||||
|
||||
|
||||
67
F0-nolib/usbcan_relay/custom_buttons.c
Normal file
67
F0-nolib/usbcan_relay/custom_buttons.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of the canrelay project.
|
||||
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// custom standalone buttons reaction
|
||||
|
||||
#include <stm32f0.h>
|
||||
#include "buttons.h"
|
||||
#include "custom_buttons.h"
|
||||
#include "hardware.h"
|
||||
|
||||
|
||||
/*
|
||||
* check buttons, on long press of button:
|
||||
* 1 - switch relay1
|
||||
* 2 - switch relay2
|
||||
* 3 - work with PWM out 0 (when btn3 pressed, btn1 increased & btn2 decreased PWM width)
|
||||
* press once btn2/3 to change PWM @1, hold to change @25 (repeat as many times as need)
|
||||
*/
|
||||
void custom_buttons_process(){
|
||||
static uint32_t lastT = 0;
|
||||
static uint8_t pwmval = 127;
|
||||
static uint8_t trig = 0; // == 1 if given btn3 was off
|
||||
if(lastUnsleep == lastT) return; // no buttons activity
|
||||
lastT = lastUnsleep;
|
||||
if(keyevt(3) == EVT_HOLD){ // PWM
|
||||
if(keyevt(2) == EVT_HOLD){ // decrease PWM by 25
|
||||
if(pwmval > 25) pwmval -= 25;
|
||||
else pwmval = 0;
|
||||
}else if(keyevt(2) == EVT_PRESS){ // decrease PWM by 1
|
||||
if(pwmval > 0) --pwmval;
|
||||
}else if(keyevt(1) == EVT_HOLD){ // increase PWM by 25
|
||||
if(pwmval < 230) pwmval += 25;
|
||||
else pwmval = 255;
|
||||
}else if(keyevt(1) == EVT_PRESS){
|
||||
if(pwmval < 254) ++pwmval;
|
||||
}
|
||||
if(trig == 0){ // first hold after release
|
||||
if(TIM1->CCR1) TIM1->CCR1 = 0; // turn off if was ON
|
||||
else{
|
||||
TIM1->CCR1 = pwmval;
|
||||
trig = 1;
|
||||
}
|
||||
}else TIM1->CCR1 = pwmval;
|
||||
return;
|
||||
}else trig = 0;
|
||||
if(keyevt(1) == EVT_HOLD){ // relay1
|
||||
Relay_TGL(0);
|
||||
}
|
||||
if(keyevt(2) == EVT_HOLD){ // relay2
|
||||
Relay_TGL(1);
|
||||
}
|
||||
}
|
||||
25
F0-nolib/usbcan_relay/custom_buttons.h
Normal file
25
F0-nolib/usbcan_relay/custom_buttons.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of the canrelay project.
|
||||
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef CUSTOM_BUTTONS_H__
|
||||
#define CUSTOM_BUTTONS_H__
|
||||
|
||||
void custom_buttons_process();
|
||||
|
||||
#endif // CUSTOM_BUTTONS_H__
|
||||
@@ -22,6 +22,9 @@
|
||||
|
||||
#include <stm32f0.h>
|
||||
|
||||
// default CAN bus speed in kbaud
|
||||
#define DEFAULT_CAN_SPEED (250)
|
||||
|
||||
#define SYSMEM03x 0x1FFFEC00
|
||||
#define SYSMEM04x 0x1FFFC400
|
||||
#define SYSMEM05x 0x1FFFEC00
|
||||
@@ -55,6 +58,7 @@ extern GPIO_TypeDef *R_ports[RelaysNO];
|
||||
extern const uint32_t R_pins[RelaysNO];
|
||||
#define Relay_ON(x) do{pin_set(R_ports[x], R_pins[x]);}while(0)
|
||||
#define Relay_OFF(x) do{pin_clear(R_ports[x], R_pins[x]);}while(0)
|
||||
#define Relay_TGL(x) do{pin_toggle(R_ports[x], R_pins[x]);}while(0)
|
||||
#define Relay_chk(x) (pin_read(R_ports[x], R_pins[x]))
|
||||
|
||||
// Buttons amount
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "adc.h"
|
||||
#include "buttons.h"
|
||||
#include "can.h"
|
||||
#include "custom_buttons.h"
|
||||
#include "hardware.h"
|
||||
#include "proto.h"
|
||||
#include "usb.h"
|
||||
@@ -74,32 +75,34 @@ int main(void){
|
||||
adc_setup();
|
||||
tim1_setup();
|
||||
USB_setup();
|
||||
CAN_setup(100);
|
||||
CAN_setup(DEFAULT_CAN_SPEED);
|
||||
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
|
||||
iwdg_setup();
|
||||
|
||||
while (1){
|
||||
IWDG->KR = IWDG_REFRESH; // refresh watchdog
|
||||
process_keys();
|
||||
custom_buttons_process();
|
||||
can_proc();
|
||||
usb_proc();
|
||||
if(CAN_get_status() == CAN_FIFO_OVERRUN){
|
||||
SEND("CAN bus fifo overrun occured!\n");
|
||||
sendbuf();
|
||||
}
|
||||
can_mesg = CAN_messagebuf_pop();
|
||||
if(can_mesg && isgood(can_mesg->ID)){
|
||||
if(ShowMsgs){ // new data in buff
|
||||
IWDG->KR = IWDG_REFRESH;
|
||||
len = can_mesg->length;
|
||||
printu(Tms);
|
||||
SEND(" #");
|
||||
printuhex(can_mesg->ID);
|
||||
for(ctr = 0; ctr < len; ++ctr){
|
||||
SEND(" ");
|
||||
printuhex(can_mesg->data[ctr]);
|
||||
while((can_mesg = CAN_messagebuf_pop())){
|
||||
if(can_mesg && isgood(can_mesg->ID)){
|
||||
if(ShowMsgs){ // new data in buff
|
||||
IWDG->KR = IWDG_REFRESH;
|
||||
len = can_mesg->length;
|
||||
printu(Tms);
|
||||
SEND(" #");
|
||||
printuhex(can_mesg->ID);
|
||||
for(ctr = 0; ctr < len; ++ctr){
|
||||
SEND(" ");
|
||||
printuhex(can_mesg->data[ctr]);
|
||||
}
|
||||
newline(); sendbuf();
|
||||
}
|
||||
newline(); sendbuf();
|
||||
}
|
||||
}
|
||||
if((txt = get_USB())){
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user