硬汉嵌入式论坛

 找回密码
 立即注册
查看: 5529|回复: 5
收起左侧

[ThreadX全家桶] threadx碰到一段代码没有懂,希望各位大佬能帮忙指导一下

[复制链接]

2

主题

4

回帖

10

积分

新手上路

积分
10
发表于 2021-5-10 13:41:24 | 显示全部楼层 |阅读模式
在观看threadx源码时,碰到一段代码没有懂,希望各位大佬能帮忙指导一下。    RSEG    FREE_MEM:DATA
    PUBLIC  __tx_free_memory_start
__tx_free_memory_start
    DS32    4
上面部分代码没有看懂,首先RSEG    FREE_MEM:DATA是定义一个数据段;但是含义是未使用内存起始地址。数据段中不是还有全局变量和静态变量么?
按照我的想法这个应该定义到链接文件的.bss段以后呀,类似于如下:
[color=rgb(0, 153, 0) !important].bss : { *([color=rgb(0, 153, 0) !important].bss) }
.align32
__tx_free_memory_start = .
希望大佬们帮忙解释一下,感谢感谢(我使用的是IAR)


回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115807
QQ
发表于 2021-5-11 08:20:35 | 显示全部楼层
看了下map文件,ThreadX这么定义不对,要放到bss末尾
这么定义是个bug。

QQ截图20210511082556.png


回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115807
QQ
发表于 2021-5-11 08:38:57 | 显示全部楼层
解决办法比较简单,设置下IAR的ICF的文件

place in RAM_region    { last section FREE_MEM};
回复

使用道具 举报

2

主题

4

回帖

10

积分

新手上路

积分
10
 楼主| 发表于 2021-5-11 08:55:00 | 显示全部楼层
eric2013 发表于 2021-5-11 08:38
解决办法比较简单,设置下IAR的ICF的文件

place in RAM_region    { last section FREE_MEM};

感谢感谢,我找例程发现这个参数并没有使用,我自己也没想到这个参数可以使用的场景,在使用内存时,直接分配或者直接用静态、全局,感觉不需要用这个first_unused_memory,可不可以举例一下?
回复

使用道具 举报

1

主题

20

回帖

23

积分

新手上路

积分
23
发表于 2021-5-11 08:59:27 | 显示全部楼层
Keil的工程也变成这样了 _tx_initialize_unused_memory 也不在内存最后的位置了,thread_0_stack~thread_5_stack的内存地址也在这个后面。最早的threadx版本都是用_tx_initialize_unused_memory地址来一块一块的增加的,分配给每个线程或者消息队列等。demo例程里直接把thread_0_stack~thread_5_stack等定义成全局数组了,没有使用_tx_initialize_unused_memory地址。在这个函数中tx_application_define(void *first_unused_memory)传递进去的参数都没使用。
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115807
QQ
发表于 2021-5-11 09:03:34 | 显示全部楼层
zjjjjj 发表于 2021-5-11 08:55
感谢感谢,我找例程发现这个参数并没有使用,我自己也没想到这个参数可以使用的场景,在使用内存时,直接 ...

对,没有使用这个,并不觉得方便。

官方的玩法是这样:
  1. /* Define what the initial system looks like.  */

  2. void    tx_application_define(void *first_unused_memory)
  3. {

  4. CHAR    *pointer = TX_NULL;


  5.     /* Create a byte memory pool from which to allocate the thread stacks.  */
  6.     tx_byte_pool_create(&byte_pool_0, "byte pool 0", memory_area, DEMO_BYTE_POOL_SIZE);

  7.     /* Put system definition stuff in here, e.g. thread creates and other assorted
  8.        create information.  */

  9.     /* Allocate the stack for thread 0.  */
  10.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

  11.     /* Create the main thread.  */
  12.     tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,  
  13.             pointer, DEMO_STACK_SIZE,
  14.             1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);


  15.     /* Allocate the stack for thread 1.  */
  16.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

  17.     /* Create threads 1 and 2. These threads pass information through a ThreadX
  18.        message queue.  It is also interesting to note that these threads have a time
  19.        slice.  */
  20.     tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,  
  21.             pointer, DEMO_STACK_SIZE,
  22.             16, 16, 4, TX_AUTO_START);

  23.     /* Allocate the stack for thread 2.  */
  24.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

  25.     tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,  
  26.             pointer, DEMO_STACK_SIZE,
  27.             16, 16, 4, TX_AUTO_START);

  28.     /* Allocate the stack for thread 3.  */
  29.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

  30.     /* Create threads 3 and 4.  These threads compete for a ThreadX counting semaphore.  
  31.        An interesting thing here is that both threads share the same instruction area.  */
  32.     tx_thread_create(&thread_3, "thread 3", thread_3_and_4_entry, 3,  
  33.             pointer, DEMO_STACK_SIZE,
  34.             8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);

  35.     /* Allocate the stack for thread 4.  */
  36.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

  37.     tx_thread_create(&thread_4, "thread 4", thread_3_and_4_entry, 4,  
  38.             pointer, DEMO_STACK_SIZE,
  39.             8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);

  40.     /* Allocate the stack for thread 5.  */
  41.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

  42.     /* Create thread 5.  This thread simply pends on an event flag which will be set
  43.        by thread_0.  */
  44.     tx_thread_create(&thread_5, "thread 5", thread_5_entry, 5,  
  45.             pointer, DEMO_STACK_SIZE,
  46.             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);

  47.     /* Allocate the stack for thread 6.  */
  48.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

  49.     /* Create threads 6 and 7.  These threads compete for a ThreadX mutex.  */
  50.     tx_thread_create(&thread_6, "thread 6", thread_6_and_7_entry, 6,  
  51.             pointer, DEMO_STACK_SIZE,
  52.             8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);

  53.     /* Allocate the stack for thread 7.  */
  54.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

  55.     tx_thread_create(&thread_7, "thread 7", thread_6_and_7_entry, 7,  
  56.             pointer, DEMO_STACK_SIZE,
  57.             8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);

  58.     /* Allocate the message queue.  */
  59.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT);

  60.     /* Create the message queue shared by threads 1 and 2.  */
  61.     tx_queue_create(&queue_0, "queue 0", TX_1_ULONG, pointer, DEMO_QUEUE_SIZE*sizeof(ULONG));

  62.     /* Create the semaphore used by threads 3 and 4.  */
  63.     tx_semaphore_create(&semaphore_0, "semaphore 0", 1);

  64.     /* Create the event flags group used by threads 1 and 5.  */
  65.     tx_event_flags_create(&event_flags_0, "event flags 0");

  66.     /* Create the mutex used by thread 6 and 7 without priority inheritance.  */
  67.     tx_mutex_create(&mutex_0, "mutex 0", TX_NO_INHERIT);

  68.     /* Allocate the memory for a small block pool.  */
  69.     tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_BLOCK_POOL_SIZE, TX_NO_WAIT);

  70.     /* Create a block memory pool to allocate a message buffer from.  */
  71.     tx_block_pool_create(&block_pool_0, "block pool 0", sizeof(ULONG), pointer, DEMO_BLOCK_POOL_SIZE);

  72.     /* Allocate a block and release the block memory.  */
  73.     tx_block_allocate(&block_pool_0, (VOID **) &pointer, TX_NO_WAIT);

  74.     /* Release the block back to the pool.  */
  75.     tx_block_release(pointer);
  76. }
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-20 09:03 , Processed in 0.363956 second(s), 29 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表