Homepage GitHub

Apply Libcanard on ChibiOS using C language

Hello. I’m new about UAVCAN.
I’m trying implementation UAVCAN on ChibiOS using C language.
I found that I need to apply “libcanard” for C language.
I’m reading UAVCAN_Specification depending on the text “RTFM at [url]” on Ardupilot FW. It’s so hard to me.
My plan is using “ardupilo/Tools/AP_Periph/can.cpp”, change to C language.

In “if grammer” below source, I know “canTransmit” function use CAN BUS.
Is “canardPopTxQueue” function using uavcan?

static void processTx(void)
{
static uint8_t fail_count;
for (const CanardCANFrame* txf = NULL; (txf = canardPeekTxQueue(&canard)) != NULL;) {
CANTxFrame txmsg {};
txmsg.DLC = txf->data_len;
memcpy(txmsg.data8, txf->data, 8);
txmsg.EID = txf->id & CANARD_CAN_EXT_ID_MASK;
txmsg.IDE = 1;
txmsg.RTR = 0;
if (canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, TIME_IMMEDIATE) == MSG_OK) {
canardPopTxQueue(&canard);
fail_count = 0;
} else {
// just exit and try again later. If we fail 8 times in a row
// then start discarding to prevent the pool filling up
if (fail_count < 8) {
fail_count++;
} else {
canardPopTxQueue(&canard);
}
return;
}
}
}

This function comes from libcanard v0 (branch legacy-v0):

Thank you @pavel.kirienko
The problem is that it’s still difficult to me…
Can I change the question?
Are there any chibios based uavcan examples using c language?

There appear to be some on GitHub if you use the search: