在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

RT-Thread動態模塊mo調試設備驅動小結

冬至子 ? 來源:黑海大白鯊 ? 作者:黑海大白鯊 ? 2023-08-07 14:46 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

前言
動態驅動模塊的調試可以減少燒錄過程,對于調試來說是一件很快樂的事情。
rtt中有動態模塊概念,而且和linux中的命名類似為分為mo和so,其中mo在筆者淺顯的理解即類似于linux中的elf,即可執行文件。同時linux中的ko也是elf文件一種,所以想rtt中的mo和linux中的ko是否可以實現同樣的功能。以下以uart串口驅動模塊的動態加載調試作為示例講解整個操作流程。

正文
準備步驟
首先是準備步驟:搭建環境,編譯生成mo。這里可以參考RT_Thread編程指南中的28節 動態模塊章節,使用過程中注意linux環境中也需要設置環境變量(RTT_ROOT、BSP_ROOT)。
我這里使用的是github倉庫中的hello模塊。編譯生成hello.mo,在msh中執行hello,輸出hello,這一步工作完成。

編譯驅動mo
接下來是編譯生成uart的設備驅動,并且注冊到rtt的設備驅動管理框架中。
以下是hello.c中的代碼,代碼比較多,截取了主要部分,因為針對于不同平臺的串口初始化函數是不一樣的。
在main中調用rt_hw_uart_init();實現對串口驅動的注冊。

int rt_hw_uart_init(void)
{
struct rt_serial_device *serial;
struct device_uart *uart;
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
static struct rt_serial_device serial1;
static struct device_uart uart1;
serial = &serial1;
uart = &uart1;
serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 115200;
rt_hw_serial_register(serial,
"uart1",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
return 0;
}
int main(int argc, char *argv[])
{
printf("hello world from RTT::dynamic modulen");
rt_hw_uart_init();
return 0;
}
這里會出現兩個問題:

問題一:動態模塊加載缺少函數符號問題

問題二:動態驅動模塊加載報錯【rt_object_init】是否存在bug?

以上是針對兩個問題的解決方式。

針對問題二做一下補充說明

#ifdef RT_USING_MODULE
if (module)
{
if(rt_strcmp(object->name,"uart1") == 0)
{
rt_list_insert_after(&(information->object_list), &(object->list));
object->module_id = (void *)module;
}
else
{
rt_list_insert_after(&(module->object_list), &(object->list));
object->module_id = (void )module;
}
}
else
#endif /
RT_USING_MODULE /
{
/
insert object into information object list */
rt_list_insert_after(&(information->object_list), &(object->list));
}

這里 if(rt_strcmp(object->name,”uart1”) == 0)比較的設備是uart1,如果你的hello.c中的注冊設備是其他記得修改

這里,同時這里也是一個極其不合理的存在。正在思考如何修改

編譯執行完后,在msh執行hello.c,使用指令list_device可以觀察到存在uart1設備,說明運行成功。

1.jpg

測試驅動是否正常
編寫串口測試程序

/*

Program list: This is a uart device usage routine
The routine exports the uart_sample command to the control terminal
Format of command: uart_sample uart2
Command explanation: the second parameter of the command is the name of the uart device. If it is null, the default uart device wil be used
Program function: output the string "hello RT-Thread!" through the serial port, and then malposition the input character
/
#include
#define SAMPLE_UART_NAME "uart1"
/
Semaphore used to receive messages /
static struct rt_semaphore rx_sem;
static rt_device_t serial;
/
Receive data callback function /
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
{
/
After the uart device receives the data, it generates an interrupt, calls this callback function, and then sends the received semaphore. */
rt_sem_release(&rx_sem);
return RT_EOK;
}
static void serial_thread_entry(void parameter)
{
char ch;
while (1)
{
/
Read a byte of data from the serial port and wait for the receiving semaphore if it is not read /
while (rt_device_read(serial, -1, &ch, 1) != 1)
{
/
Being Suspended and waiting for the semaphore /
rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
}
/
Read the data from the serial port and output through dislocation */
ch = ch + 1;
rt_device_write(serial, 0, &ch, 1);
}
}
static int uart_sample(int argc, char argv[])
{
rt_err_t ret = RT_EOK;
char uart_name[RT_NAME_MAX];
char str[] = "hello RT-Thread!rn";
if (argc == 2)
{
rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
}
else
{
rt_strncpy(uart_name, SAMPLE_UART_NAME, RT_NAME_MAX);
}
/
Find uart devices in the system /
serial = rt_device_find(uart_name);
if (!serial)
{
rt_kprintf("find %s failed!n", uart_name);
return RT_ERROR;
}
/
Initialize the semaphore /
rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
/
Open the uart device in interrupt receive and polling send mode /
rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
/
Set the receive callback function /
rt_device_set_rx_indicate(serial, uart_input);
/
Send string /
rt_device_write(serial, 0, str, (sizeof(str) - 1));
/
Create a serial thread /
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024, 25, 10);
/
Start the thread successfully /
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
ret = RT_ERROR;
}
return ret;
}
/
Export to the msh command list */
MSH_CMD_EXPORT(uart_sample, uart device sample);

在msh中輸入uart_sample,驅動打開,初始化正常。觀察uart1工作是否正常。正常說明驅動加載運行正常。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 調試器
    +關注

    關注

    1

    文章

    312

    瀏覽量

    24262
  • 串口驅動
    +關注

    關注

    2

    文章

    86

    瀏覽量

    19082
  • LINUX內核
    +關注

    關注

    1

    文章

    317

    瀏覽量

    22330
  • RT-Thread
    +關注

    關注

    32

    文章

    1395

    瀏覽量

    41745
  • Uart串口
    +關注

    關注

    0

    文章

    29

    瀏覽量

    7120
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    RT-Thread記錄(九、RTT中斷處理與階段小結

    RT-Thread 內核部分最后一個點 中斷管理,順帶著對前面所學知識做個小結
    的頭像 發表于 06-24 10:25 ?6828次閱讀
    <b class='flag-5'>RT-Thread</b>記錄(九、RTT中斷處理與階段<b class='flag-5'>小結</b>)

    RT-Thread ssd1306驅動

    RT-Thread 驅動ssd1306
    的頭像 發表于 04-21 10:08 ?26.5w次閱讀
    <b class='flag-5'>RT-Thread</b> ssd1306<b class='flag-5'>驅動</b>

    RT-Thread設備驅動開發指南基礎篇—以先楫bsp的hwtimer設備為例

    RT-Thread設備驅動開發指南》書籍是RT-thread官方出品撰寫,系統講解RT-thread IO
    的頭像 發表于 02-20 16:01 ?2512次閱讀
    <b class='flag-5'>RT-Thread</b><b class='flag-5'>設備</b><b class='flag-5'>驅動</b>開發指南基礎篇—以先楫bsp的hwtimer<b class='flag-5'>設備</b>為例

    RT-Thread Studio驅動SD卡

    RT-Thread Studio驅動SD卡前言一、創建基本工程1、創建Bootloader2、創建項目工程二、配置RT-Thread Settings三、代碼分析1.引入庫2.讀入數據四、效果驗證
    發表于 12-27 19:13 ?20次下載
    <b class='flag-5'>RT-Thread</b> Studio<b class='flag-5'>驅動</b>SD卡

    RT-Thread文檔_RT-Thread 簡介

    RT-Thread文檔_RT-Thread 簡介
    發表于 02-22 18:22 ?5次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>RT-Thread</b> 簡介

    RT-Thread文檔_RT-Thread SMP 介紹與移植

    RT-Thread文檔_RT-Thread SMP 介紹與移植
    發表于 02-22 18:31 ?9次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>RT-Thread</b> SMP 介紹與移植

    RT-Thread文檔_UART 設備

    RT-Thread文檔_UART 設備
    發表于 02-22 18:32 ?4次下載
    <b class='flag-5'>RT-Thread</b>文檔_UART <b class='flag-5'>設備</b>

    RT-Thread文檔_CAN 設備

    RT-Thread文檔_CAN 設備
    發表于 02-22 18:34 ?0次下載
    <b class='flag-5'>RT-Thread</b>文檔_CAN <b class='flag-5'>設備</b>

    RT-Thread文檔_PWM 設備

    RT-Thread文檔_PWM 設備
    發表于 02-22 18:35 ?2次下載
    <b class='flag-5'>RT-Thread</b>文檔_PWM <b class='flag-5'>設備</b>

    RT-Thread文檔_SPI 設備

    RT-Thread文檔_SPI 設備
    發表于 02-22 18:36 ?3次下載
    <b class='flag-5'>RT-Thread</b>文檔_SPI <b class='flag-5'>設備</b>

    RT-Thread文檔_WATCHDOG 設備

    RT-Thread文檔_WATCHDOG 設備
    發表于 02-22 18:36 ?1次下載
    <b class='flag-5'>RT-Thread</b>文檔_WATCHDOG <b class='flag-5'>設備</b>

    RT-Thread文檔_SENSOR 設備

    RT-Thread文檔_SENSOR 設備
    發表于 02-22 18:37 ?0次下載
    <b class='flag-5'>RT-Thread</b>文檔_SENSOR <b class='flag-5'>設備</b>

    RT-Thread文檔_AUDIO 設備

    RT-Thread文檔_AUDIO 設備
    發表于 02-22 18:38 ?1次下載
    <b class='flag-5'>RT-Thread</b>文檔_AUDIO <b class='flag-5'>設備</b>

    RT-Thread文檔_Pulse Encoder 設備

    RT-Thread文檔_Pulse Encoder 設備
    發表于 02-22 18:39 ?1次下載
    <b class='flag-5'>RT-Thread</b>文檔_Pulse Encoder <b class='flag-5'>設備</b>

    淺析RT-Thread設備驅動框架

    RT-Thread 設備框架屬于組件和服務層,是基于 RT-Thread 內核之上的上層軟件。設備框架是針對某一類外設,抽象出來的一套統一的操作方法及接入標準,可以屏蔽硬件差異,為應用
    的頭像 發表于 08-07 15:39 ?2550次閱讀
    主站蜘蛛池模板: 国产黄大片在线观看 | 色天天综合网色鬼综合 | 天堂视频免费在线观看 | 日日操天天操夜夜操 | 91正在播放 | 深爱开心激情 | 天堂网在线最新版www中文网 | 女的扒开尿口让男人桶爽 | 黄色片香蕉视频 | 视频1区 | 簧片视频在线观看 | 成人一二| 国产成人啪午夜精品网站男同 | 日本口工禁漫画无遮挡全彩 | 欧美视频精品在线 | www.色多多 | 色综合亚洲 | 四虎影院在线观看免费 | www.日本免费 | 色拍拍拍 | 特黄特色大片免费播放器9 特黄特色大片免费视频播放 | 天天看天天爽 | 国产日韩精品欧美一区色 | 亚洲小便| 日本午夜大片免费观看视频 | 日韩毛片高清在线看 | 曰本性l交片视频视频 | 三级黄色短视频 | 日本加勒比视频在线观看 | 久久这里只有精品免费播放 | 国产大片91精品免费观看不卡 | 中国女人a毛片免费全部播放 | 污夜影院 | 色网综合| 亚洲欧美国产视频 | 日韩三级中文 | cum4k在线| 男人j进女人j的一进一出视频 | 天天操人人 | 欧美天天爽 | 免费特黄一区二区三区视频一 |