Hello Zoltan,
Thank you so much and sorry for the late response,
The situation has become more confusing.
In order to use EventFlags, I upgraded my mbed os version from os2 to os6.
I used this idea to transplant RawSerial, the base class of BusSerial_new.
But unfortunately, I could not apply EventFlags to all my interrupt points.
When I tried to apply it to entire my program, it raises RTOS event flags error.
Below is my updated code.
#include "mbed.h"
#include "MotorControler.h"
#include "QEI_speed.h"
#include "QEI_angle.h"
#include "calculation.h"
#include "defines.h"
#include "BusSerial_new.h"
#include <stdint.h>
*
* *************/
Timer timer0, timer1;// Serial pc(USBTX, USBRX);
BusSerial_new BS(PA_0, PA_1, &timer1);
// bool RX_COMP_F = false; // bool RX_COMP_F_2 = false;
BusSerial_new BS_gyro(PC_12, PD_2, &timer1);
Ticker sampling_period;
/***************
*
* *
* *************/
void classSetting();
void init();
void ang_encoder_reset();
void input();
void calc_auto();
void calc_manual();
void calc_wheel_params(coordinate, double);
void output();
void debug();
void control();
void ISR_rx_main();
void ISR_tx_main();
void ISR_rx_gyro();
void time_out();
const int data_num = 12;
const int data_num_gyro = 8;
comm_data ReceiveData[data_num];
comm_data ReceiveData_2[data_num_gyro];
uint8_t receive_data[data_num];
uint8_t receive_data_2[data_num_gyro];
const int NUM_TX_DATA = 7;
#define MAIN_ID 252
uint8_t send_data[NUM_TX_DATA];
uint8_t debug_box = 0;
// bool timer_fires = false;
bool zero_complete = false;
/* eventflags */
// const uint32_t RX_COMP_F = 1UL << 0; // use bit 0 as signal channel for this flag
// const uint32_t RX_COMP_F_2 = 1UL << 1; // use bit 1 as signal channel for this flag
const uint32_t TIMER_FIRES = 1UL << 2; // use bit 2 as signal channel for this flag
EventFlags eventFlags;
static bool RX_COMP_F = false;
static bool RX_COMP_F_2 = false;
/****************
*
*
*
* **************/
int main()
{
init();
while (1)
{
input();
if (ZERO_ADJ && !zero_complete)
{
printf("adj\n");
ang_encoder_reset();
}
else
zero_complete = false;
// if (TIMER_FIRES)
// {
// TIMER_FIRES = false;
eventFlags.wait_all(TIMER_FIRES);
if (OPERATE_MODE == AUTO)
{
calc_auto();
}
else
{
RGB[0] = 1;
calc_manual();
RGB[0] = 0;
}
// }
output();
debug();
}
}
/*---------------------------------------------- -------------------------------------------------*/
void init()
{
printf("boot\n");
classSetting();
ang_encoder_reset();
sampling_period.attach_us(&control, PERIOD);
}
/*-----------------------
*
* ---------------------*/
void input()
{
/* */
if (RX_COMP_F)
{
for (int i = 0; i < data_num; i++)
{
ReceiveData[i].all = receive_data[i];
printf("%d ", ReceiveData[i].all);
}
printf("\n");
RX_COMP_F = false;
}
/* */
if (RX_COMP_F_2)
{
for (int i = 0; i < data_num_gyro; i++)
{
ReceiveData_2[i].all = receive_data_2[i];
printf("%d ", receive_data_2[i]);
}
RX_COMP_F_2 = false;
}
}
void calc_auto()
{
}
void calc_manual()
{
}
void calc_wheel_params(coordinate tar_vel_xy, double tar_robo_ang_vel)
{
}
void output()
{
}
void debug()
{
send_data[1] = ANG_ENC[0].getDegree() / decel_ratio;
send_data[2] = CURR_POS_X_UPPER;
send_data[3] = CURR_POS_X_LOWER;
send_data[4] = CURR_POS_Y_UPPER;
send_data[5] = CURR_POS_Y_LOWER;
/**------------------ ------------------------------*/
// UART4->CR1 |= USART_CR1_TXEIE;
BS.sendBusSerial_new(&send_data[0], NUM_TX_DATA);
}
void classSetting()
{
BS.baud(115200);
BS_gyro.baud(115200);
BS.attach(ISR_rx_main, SerialBase::RxIrq);
// BS.attach(ISR_tx_main, SerialBase::TxIrq);
BS_gyro.attach(ISR_rx_gyro, SerialBase::RxIrq);
// eventFlags.set(RX_COMP_F);
// eventFlags.set(TIMER_FIRES);
// eventFlags.set(RX_COMP_F_2);
NVIC_SetPriority(UART4_IRQn, 4);
NVIC_SetPriority(UART5_IRQn, 5);
NVIC_SetPriority(TIM3_IRQn, 6);
}
/**-------------------------
------------------------*/
void control(void)
{
eventFlags.set(TIMER_FIRES);
// TIMER_FIRES = true;
// RGB[0] = !RGB[0]; /* */
return;
}
/* */
void ISR_rx_main()
{
rx_cnt_main = 0;
char data;
bool result = false;
data = BS.getc();
if (!RX_COMP_F)
{
// eventFlags.wait_all(!RX_COMP_F);
result = BS.store_data(data, receive_data, HeadNum, foot_num, data_num - 1);
if (result == true)
{
RGB[1] = !RGB[1];
RX_COMP_F = true;
// BS_gyro.attach(ISR_rx_gyro, SerialBase::RxIrq);
// eventFlags.set(RX_COMP_F);
}
}
return;
}
void ISR_rx_gyro()
{
rx_cnt_gyro = 0;
char data1;
bool res = false;
RGB[2] = !RGB[2];
data1 = BS_gyro.getc();
if (!RX_COMP_F_2)
{
res = BS_gyro.store_data(data1, receive_data_2, HeadNum, foot_num, data_num_gyro - 1);
if (res == true)
{
/* */
RX_COMP_F_2 = true;
// RGB[2] = !RGB[2];
// BS.attach(ISR_rx_main, SerialBase::RxIrq);
}
}
return;
}
Then the serial monitor raises HardFaultError or stops frequently.
Is my program too heavy?
Any idea would help me…
Thank you, Aoi