# Apply Libcanard on ChibiOS using C language

**URL:** <https://forum.opencyphal.org/t/apply-libcanard-on-chibios-using-c-language/1204>\
**Category:** Libcanard\
**Created:** [April 21, 2021, 8:48am UTC](https://forum.opencyphal.org/t/apply-libcanard-on-chibios-using-c-language/1204 "2021-04-21T08:48:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jslee](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/j/278dde/32.png) [@jslee](https://forum.opencyphal.org/u/jslee)\
**Post date:** [April 21, 2021, 8:48am UTC](https://forum.opencyphal.org/t/apply-libcanard-on-chibios-using-c-language/1204/1 "2021-04-21T08:48:59Z")

</div>

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;  
> }  
> }  
> }

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [April 21, 2021, 4:05pm UTC](https://forum.opencyphal.org/t/apply-libcanard-on-chibios-using-c-language/1204/2 "2021-04-21T16:05:25Z")

</div>

> [@jslee](#):
>
> Is “canardPopTxQueue” function using uavcan?

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

[https://github.com/UAVCAN/libcanard/blob/legacy-v0/canard.h#L417-L423](https://github.com/UAVCAN/libcanard/blob/legacy-v0/canard.h#L417-L423)

---

<div class="post-metadata">

**Author:** ![jslee](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/j/278dde/32.png) [@jslee](https://forum.opencyphal.org/u/jslee)\
**Post date:** [April 27, 2021, 9:15am UTC](https://forum.opencyphal.org/t/apply-libcanard-on-chibios-using-c-language/1204/3 "2021-04-27T09:15:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [April 27, 2021, 9:22am UTC](https://forum.opencyphal.org/t/apply-libcanard-on-chibios-using-c-language/1204/4 "2021-04-27T09:22:50Z")

</div>

> [@jslee](#):
>
> Are there any chibios based uavcan examples using c language?

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

> **[Build software better, together](https://github.com/search?q=canardPopTxQueue&type=code)**
>
> GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
