硬汉嵌入式论坛

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

[ThreadX全家桶] ThreadX专门为IAR的C库函数做的互斥接口文件,通过宏定义TX_ENABLE_IAR_LIBRARY_SUPPORT可以使能

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
发表于 2020-8-11 10:44:56 | 显示全部楼层 |阅读模式


程序在ThreadX内核代码的6.0.1里面有,对应文件tx_iar.c

http://www.armbbs.cn/forum.php?mod=viewthread&tid=97925

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
  4. /*                                                                        */
  5. /*       This software is licensed under the Microsoft Software License   */
  6. /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
  7. /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
  8. /*       and in the root directory of this software.                      */
  9. /*                                                                        */
  10. /**************************************************************************/


  11. /**************************************************************************/
  12. /**************************************************************************/
  13. /**                                                                       */
  14. /** ThreadX Component                                                     */
  15. /**                                                                       */
  16. /**   IAR Multithreaded Library Support                                   */
  17. /**                                                                       */
  18. /**************************************************************************/
  19. /**************************************************************************/

  20. #define TX_SOURCE_CODE


  21. /* Define IAR library for tools prior to version 8.  */

  22. #if (__VER__ < 8000000)


  23. /* IAR version 7 and below.  */

  24. /* Include necessary system files.  */

  25. #include "tx_api.h"
  26. #include "tx_initialize.h"
  27. #include "tx_thread.h"
  28. #include "tx_mutex.h"


  29. /* This implementation requires that the following macros are defined in the
  30.    tx_port.h file and <yvals.h> is included with the following code segments:
  31.    
  32. #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
  33. #include <yvals.h>
  34. #endif

  35. #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
  36. #define TX_THREAD_EXTENSION_2           VOID    *tx_thread_iar_tls_pointer;         
  37. #else
  38. #define TX_THREAD_EXTENSION_2         
  39. #endif

  40. #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
  41. #define TX_THREAD_CREATE_EXTENSION(thread_ptr)                      thread_ptr -> tx_thread_iar_tls_pointer =  __iar_dlib_perthread_allocate();                                 
  42. #define TX_THREAD_DELETE_EXTENSION(thread_ptr)                      __iar_dlib_perthread_deallocate(thread_ptr -> tx_thread_iar_tls_pointer); \
  43.                                                                     thread_ptr -> tx_thread_iar_tls_pointer =  TX_NULL;            
  44. #define TX_PORT_SPECIFIC_PRE_SCHEDULER_INITIALIZATION               __iar_dlib_perthread_access(0);
  45. #else
  46. #define TX_THREAD_CREATE_EXTENSION(thread_ptr)                                 
  47. #define TX_THREAD_DELETE_EXTENSION(thread_ptr)                                 
  48. #endif

  49.     This should be done automatically if TX_ENABLE_IAR_LIBRARY_SUPPORT is defined while building the ThreadX library and the
  50.     application.  

  51.     Finally, the project options General Options -> Library Configuration should have the "Enable thread support in library" box selected.
  52. */

  53. #ifdef TX_ENABLE_IAR_LIBRARY_SUPPORT

  54. #include <yvals.h>


  55. #if _MULTI_THREAD

  56. TX_MUTEX    __tx_iar_system_lock_mutexes[_MAX_LOCK];
  57. UINT        __tx_iar_system_lock_next_free_mutex =  0;


  58. /* Define error counters, just for debug purposes.  */

  59. UINT        __tx_iar_system_lock_no_mutexes;
  60. UINT        __tx_iar_system_lock_internal_errors;
  61. UINT        __tx_iar_system_lock_isr_caller;


  62. /* Define the TLS access function for the IAR library.  */

  63. void _DLIB_TLS_MEMORY *__iar_dlib_perthread_access(void _DLIB_TLS_MEMORY *symbp)
  64. {

  65. char _DLIB_TLS_MEMORY   *p = 0;
  66.    
  67.     /* Is there a current thread?  */
  68.     if (_tx_thread_current_ptr)
  69.       p = (char _DLIB_TLS_MEMORY *) _tx_thread_current_ptr -> tx_thread_iar_tls_pointer;
  70.     else
  71.       p = (void _DLIB_TLS_MEMORY *) __segment_begin("__DLIB_PERTHREAD");
  72.     p += __IAR_DLIB_PERTHREAD_SYMBOL_OFFSET(symbp);
  73.     return (void _DLIB_TLS_MEMORY *) p;
  74. }


  75. /* Define mutexes for IAR library.  */

  76. void __iar_system_Mtxinit(__iar_Rmtx *m)
  77. {

  78. UINT        i;
  79. UINT        status;
  80. TX_MUTEX    *mutex_ptr;


  81.     /* First, find a free mutex in the list.  */
  82.     for (i = 0; i < _MAX_LOCK; i++)
  83.     {

  84.         /* Setup a pointer to the start of the next free mutex.  */
  85.         mutex_ptr =  &__tx_iar_system_lock_mutexes[__tx_iar_system_lock_next_free_mutex++];
  86.    
  87.         /* Check for wrap-around on the next free mutex.  */
  88.         if (__tx_iar_system_lock_next_free_mutex >= _MAX_LOCK)
  89.         {
  90.         
  91.             /* Yes, set the free index back to 0.  */
  92.             __tx_iar_system_lock_next_free_mutex =  0;
  93.         }
  94.    
  95.         /* Is this mutex free?  */
  96.         if (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)
  97.         {
  98.         
  99.             /* Yes, this mutex is free, get out of the loop!  */
  100.             break;
  101.         }
  102.     }

  103.     /* Determine if a free mutex was found.   */
  104.     if (i >= _MAX_LOCK)
  105.     {
  106.    
  107.         /* Error!  No more free mutexes!  */
  108.         
  109.         /* Increment the no mutexes error counter.  */
  110.         __tx_iar_system_lock_no_mutexes++;
  111.         
  112.         /* Set return pointer to NULL.  */
  113.         *m =  TX_NULL;
  114.         
  115.         /* Return.  */
  116.         return;
  117.     }
  118.    
  119.     /* Now create the ThreadX mutex for the IAR library.  */
  120.     status =  _tx_mutex_create(mutex_ptr, "IAR System Library Lock", TX_NO_INHERIT);
  121.    
  122.     /* Determine if the creation was successful.  */
  123.     if (status == TX_SUCCESS)
  124.     {
  125.    
  126.         /* Yes, successful creation, return mutex pointer.  */
  127.         *m =  (VOID *) mutex_ptr;
  128.     }
  129.     else
  130.     {
  131.    
  132.         /* Increment the internal error counter.  */
  133.         __tx_iar_system_lock_internal_errors++;
  134.    
  135.         /* Return a NULL pointer to indicate an error.  */
  136.         *m =  TX_NULL;
  137.     }
  138. }

  139. void __iar_system_Mtxdst(__iar_Rmtx *m)
  140. {

  141.     /* Simply delete the mutex.  */
  142.     _tx_mutex_delete((TX_MUTEX *) *m);
  143. }

  144. void __iar_system_Mtxlock(__iar_Rmtx *m)
  145. {

  146. UINT    status;


  147.     /* Determine the caller's context. Mutex locks are only available from initialization and
  148.        threads.  */
  149.     if ((_tx_thread_system_state == 0) || (_tx_thread_system_state >= TX_INITIALIZE_IN_PROGRESS))
  150.     {
  151.    
  152.         /* Get the mutex.  */
  153.         status =  _tx_mutex_get((TX_MUTEX *) *m, TX_WAIT_FOREVER);

  154.         /* Check the status of the mutex release.  */
  155.         if (status)
  156.         {
  157.         
  158.             /* Internal error, increment the counter.  */
  159.             __tx_iar_system_lock_internal_errors++;
  160.         }
  161.     }
  162.     else
  163.     {
  164.         
  165.         /* Increment the ISR caller error.  */
  166.         __tx_iar_system_lock_isr_caller++;
  167.     }
  168. }

  169. void __iar_system_Mtxunlock(__iar_Rmtx *m)
  170. {

  171. UINT    status;


  172.     /* Determine the caller's context. Mutex unlocks are only available from initialization and
  173.        threads.  */
  174.     if ((_tx_thread_system_state == 0) || (_tx_thread_system_state >= TX_INITIALIZE_IN_PROGRESS))
  175.     {
  176.    
  177.         /* Release the mutex.  */
  178.         status =  _tx_mutex_put((TX_MUTEX *) *m);
  179.         
  180.         /* Check the status of the mutex release.  */
  181.         if (status)
  182.         {
  183.         
  184.             /* Internal error, increment the counter.  */
  185.             __tx_iar_system_lock_internal_errors++;
  186.         }
  187.     }
  188.     else
  189.     {
  190.         
  191.         /* Increment the ISR caller error.  */
  192.         __tx_iar_system_lock_isr_caller++;
  193.     }
  194. }


  195. #if _DLIB_FILE_DESCRIPTOR

  196. TX_MUTEX    __tx_iar_file_lock_mutexes[_MAX_FLOCK];
  197. UINT        __tx_iar_file_lock_next_free_mutex =  0;


  198. /* Define error counters, just for debug purposes.  */

  199. UINT        __tx_iar_file_lock_no_mutexes;
  200. UINT        __tx_iar_file_lock_internal_errors;
  201. UINT        __tx_iar_file_lock_isr_caller;


  202. void __iar_file_Mtxinit(__iar_Rmtx *m)
  203. {

  204. UINT        i;
  205. UINT        status;
  206. TX_MUTEX    *mutex_ptr;


  207.     /* First, find a free mutex in the list.  */
  208.     for (i = 0; i < _MAX_FLOCK; i++)
  209.     {

  210.         /* Setup a pointer to the start of the next free mutex.  */
  211.         mutex_ptr =  &__tx_iar_file_lock_mutexes[__tx_iar_file_lock_next_free_mutex++];
  212.    
  213.         /* Check for wrap-around on the next free mutex.  */
  214.         if (__tx_iar_file_lock_next_free_mutex >= _MAX_LOCK)
  215.         {
  216.         
  217.             /* Yes, set the free index back to 0.  */
  218.             __tx_iar_file_lock_next_free_mutex =  0;
  219.         }
  220.    
  221.         /* Is this mutex free?  */
  222.         if (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)
  223.         {
  224.         
  225.             /* Yes, this mutex is free, get out of the loop!  */
  226.             break;
  227.         }
  228.     }

  229.     /* Determine if a free mutex was found.   */
  230.     if (i >= _MAX_LOCK)
  231.     {
  232.    
  233.         /* Error!  No more free mutexes!  */
  234.         
  235.         /* Increment the no mutexes error counter.  */
  236.         __tx_iar_file_lock_no_mutexes++;
  237.         
  238.         /* Set return pointer to NULL.  */
  239.         *m =  TX_NULL;
  240.         
  241.         /* Return.  */
  242.         return;
  243.     }
  244.    
  245.     /* Now create the ThreadX mutex for the IAR library.  */
  246.     status =  _tx_mutex_create(mutex_ptr, "IAR File Library Lock", TX_NO_INHERIT);
  247.    
  248.     /* Determine if the creation was successful.  */
  249.     if (status == TX_SUCCESS)
  250.     {
  251.    
  252.         /* Yes, successful creation, return mutex pointer.  */
  253.         *m =  (VOID *) mutex_ptr;
  254.     }
  255.     else
  256.     {
  257.    
  258.         /* Increment the internal error counter.  */
  259.         __tx_iar_file_lock_internal_errors++;
  260.    
  261.         /* Return a NULL pointer to indicate an error.  */
  262.         *m =  TX_NULL;
  263.     }
  264. }

  265. void __iar_file_Mtxdst(__iar_Rmtx *m)
  266. {

  267.     /* Simply delete the mutex.  */
  268.     _tx_mutex_delete((TX_MUTEX *) *m);
  269. }

  270. void __iar_file_Mtxlock(__iar_Rmtx *m)
  271. {

  272. UINT    status;


  273.     /* Determine the caller's context. Mutex locks are only available from initialization and
  274.        threads.  */
  275.     if ((_tx_thread_system_state == 0) || (_tx_thread_system_state >= TX_INITIALIZE_IN_PROGRESS))
  276.     {
  277.    
  278.         /* Get the mutex.  */
  279.         status =  _tx_mutex_get((TX_MUTEX *) *m, TX_WAIT_FOREVER);

  280.         /* Check the status of the mutex release.  */
  281.         if (status)
  282.         {
  283.         
  284.             /* Internal error, increment the counter.  */
  285.             __tx_iar_file_lock_internal_errors++;
  286.         }
  287.     }
  288.     else
  289.     {
  290.         
  291.         /* Increment the ISR caller error.  */
  292.         __tx_iar_file_lock_isr_caller++;
  293.     }
  294. }

  295. void __iar_file_Mtxunlock(__iar_Rmtx *m)
  296. {

  297. UINT    status;


  298.     /* Determine the caller's context. Mutex unlocks are only available from initialization and
  299.        threads.  */
  300.     if ((_tx_thread_system_state == 0) || (_tx_thread_system_state >= TX_INITIALIZE_IN_PROGRESS))
  301.     {
  302.    
  303.         /* Release the mutex.  */
  304.         status =  _tx_mutex_put((TX_MUTEX *) *m);
  305.         
  306.         /* Check the status of the mutex release.  */
  307.         if (status)
  308.         {
  309.         
  310.             /* Internal error, increment the counter.  */
  311.             __tx_iar_file_lock_internal_errors++;
  312.         }
  313.     }
  314.     else
  315.     {
  316.         
  317.         /* Increment the ISR caller error.  */
  318.         __tx_iar_file_lock_isr_caller++;
  319.     }
  320. }
  321. #endif  /* _DLIB_FILE_DESCRIPTOR */

  322. #endif  /* _MULTI_THREAD  */

  323. #endif  /* TX_ENABLE_IAR_LIBRARY_SUPPORT  */

  324. #else   /* IAR version 8 and above.  */


  325. /* Include necessary system files.  */

  326. #include "tx_api.h"
  327. #include "tx_initialize.h"
  328. #include "tx_thread.h"
  329. #include "tx_mutex.h"

  330. /* This implementation requires that the following macros are defined in the
  331.    tx_port.h file and <yvals.h> is included with the following code segments:
  332.    
  333. #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
  334. #include <yvals.h>
  335. #endif

  336. #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
  337. #define TX_THREAD_EXTENSION_2           VOID    *tx_thread_iar_tls_pointer;         
  338. #else
  339. #define TX_THREAD_EXTENSION_2         
  340. #endif

  341. #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
  342. void    *_tx_iar_create_per_thread_tls_area(void);
  343. void    _tx_iar_destroy_per_thread_tls_area(void *tls_ptr);
  344. void    __iar_Initlocks(void);

  345. #define TX_THREAD_CREATE_EXTENSION(thread_ptr)                      thread_ptr -> tx_thread_iar_tls_pointer =  __iar_dlib_perthread_allocate();                                 
  346. #define TX_THREAD_DELETE_EXTENSION(thread_ptr)                      do {__iar_dlib_perthread_deallocate(thread_ptr -> tx_thread_iar_tls_pointer); \
  347.                                                                         thread_ptr -> tx_thread_iar_tls_pointer =  TX_NULL; } while(0);
  348. #define TX_PORT_SPECIFIC_PRE_SCHEDULER_INITIALIZATION               do {__iar_Initlocks();} while(0);
  349. #else
  350. #define TX_THREAD_CREATE_EXTENSION(thread_ptr)                                 
  351. #define TX_THREAD_DELETE_EXTENSION(thread_ptr)                                 
  352. #endif

  353.     This should be done automatically if TX_ENABLE_IAR_LIBRARY_SUPPORT is defined while building the ThreadX library and the
  354.     application.  

  355.     Finally, the project options General Options -> Library Configuration should have the "Enable thread support in library" box selected.
  356. */

  357. #ifdef TX_ENABLE_IAR_LIBRARY_SUPPORT

  358. #include <DLib_threads.h>


  359. void * __aeabi_read_tp();

  360. void* _tx_iar_create_per_thread_tls_area();
  361. void _tx_iar_destroy_per_thread_tls_area(void *tls_ptr);

  362. #pragma section="__iar_tls$DATA"

  363. /* Define the TLS access function for the IAR library.  */
  364. void * __aeabi_read_tp(void)
  365. {
  366.   void *p = 0;
  367.   TX_THREAD *thread_ptr = _tx_thread_current_ptr;
  368.   if (thread_ptr)
  369.   {
  370.     p = thread_ptr->tx_thread_iar_tls_pointer;      
  371.   }
  372.   else
  373.   {
  374.     p = __section_begin("__iar_tls$DATA");
  375.   }
  376.   return p;
  377. }

  378. /* Define the TLS creation and destruction to use malloc/free.  */

  379. void* _tx_iar_create_per_thread_tls_area()
  380. {
  381.   UINT tls_size = __iar_tls_size();  
  382.   
  383.   /* Get memory for TLS.  */  
  384.   void *p = malloc(tls_size);

  385.   /* Initialize TLS-area and run constructors for objects in TLS */
  386.   __iar_tls_init(p);
  387.   return p;
  388. }

  389. void _tx_iar_destroy_per_thread_tls_area(void *tls_ptr)
  390. {
  391.   /* Destroy objects living in TLS */
  392.   __call_thread_dtors();
  393.   free(tls_ptr);  
  394. }

  395. #ifndef _MAX_LOCK
  396. #define _MAX_LOCK 4
  397. #endif

  398. static TX_MUTEX    __tx_iar_system_lock_mutexes[_MAX_LOCK];
  399. static UINT        __tx_iar_system_lock_next_free_mutex =  0;


  400. /* Define error counters, just for debug purposes.  */

  401. UINT        __tx_iar_system_lock_no_mutexes;
  402. UINT        __tx_iar_system_lock_internal_errors;
  403. UINT        __tx_iar_system_lock_isr_caller;


  404. /* Define mutexes for IAR library.  */

  405. void __iar_system_Mtxinit(__iar_Rmtx *m)
  406. {

  407. UINT        i;
  408. UINT        status;
  409. TX_MUTEX    *mutex_ptr;


  410.     /* First, find a free mutex in the list.  */
  411.     for (i = 0; i < _MAX_LOCK; i++)
  412.     {

  413.         /* Setup a pointer to the start of the next free mutex.  */
  414.         mutex_ptr =  &__tx_iar_system_lock_mutexes[__tx_iar_system_lock_next_free_mutex++];
  415.    
  416.         /* Check for wrap-around on the next free mutex.  */
  417.         if (__tx_iar_system_lock_next_free_mutex >= _MAX_LOCK)
  418.         {
  419.         
  420.             /* Yes, set the free index back to 0.  */
  421.             __tx_iar_system_lock_next_free_mutex =  0;
  422.         }
  423.    
  424.         /* Is this mutex free?  */
  425.         if (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)
  426.         {
  427.         
  428.             /* Yes, this mutex is free, get out of the loop!  */
  429.             break;
  430.         }
  431.     }

  432.     /* Determine if a free mutex was found.   */
  433.     if (i >= _MAX_LOCK)
  434.     {
  435.    
  436.         /* Error!  No more free mutexes!  */
  437.         
  438.         /* Increment the no mutexes error counter.  */
  439.         __tx_iar_system_lock_no_mutexes++;
  440.         
  441.         /* Set return pointer to NULL.  */
  442.         *m =  TX_NULL;
  443.         
  444.         /* Return.  */
  445.         return;
  446.     }
  447.    
  448.     /* Now create the ThreadX mutex for the IAR library.  */
  449.     status =  _tx_mutex_create(mutex_ptr, "IAR System Library Lock", TX_NO_INHERIT);
  450.    
  451.     /* Determine if the creation was successful.  */
  452.     if (status == TX_SUCCESS)
  453.     {
  454.    
  455.         /* Yes, successful creation, return mutex pointer.  */
  456.         *m =  (VOID *) mutex_ptr;
  457.     }
  458.     else
  459.     {
  460.    
  461.         /* Increment the internal error counter.  */
  462.         __tx_iar_system_lock_internal_errors++;
  463.    
  464.         /* Return a NULL pointer to indicate an error.  */
  465.         *m =  TX_NULL;
  466.     }
  467. }

  468. void __iar_system_Mtxdst(__iar_Rmtx *m)
  469. {

  470.     /* Simply delete the mutex.  */
  471.     _tx_mutex_delete((TX_MUTEX *) *m);
  472. }

  473. void __iar_system_Mtxlock(__iar_Rmtx *m)
  474. {
  475.   if (*m)
  476.   {  
  477.     UINT    status;

  478.     /* Determine the caller's context. Mutex locks are only available from initialization and
  479.        threads.  */
  480.     if ((_tx_thread_system_state == 0) || (_tx_thread_system_state >= TX_INITIALIZE_IN_PROGRESS))
  481.     {
  482.    
  483.         /* Get the mutex.  */
  484.         status =  _tx_mutex_get((TX_MUTEX *) *m, TX_WAIT_FOREVER);

  485.         /* Check the status of the mutex release.  */
  486.         if (status)
  487.         {
  488.         
  489.             /* Internal error, increment the counter.  */
  490.             __tx_iar_system_lock_internal_errors++;
  491.         }
  492.     }
  493.     else
  494.     {
  495.         
  496.         /* Increment the ISR caller error.  */
  497.         __tx_iar_system_lock_isr_caller++;
  498.     }
  499.   }
  500. }

  501. void __iar_system_Mtxunlock(__iar_Rmtx *m)
  502. {
  503.   if (*m)
  504.   {
  505.     UINT    status;

  506.     /* Determine the caller's context. Mutex unlocks are only available from initialization and
  507.        threads.  */
  508.     if ((_tx_thread_system_state == 0) || (_tx_thread_system_state >= TX_INITIALIZE_IN_PROGRESS))
  509.     {
  510.    
  511.         /* Release the mutex.  */
  512.         status =  _tx_mutex_put((TX_MUTEX *) *m);
  513.         
  514.         /* Check the status of the mutex release.  */
  515.         if (status)
  516.         {
  517.         
  518.             /* Internal error, increment the counter.  */
  519.             __tx_iar_system_lock_internal_errors++;
  520.         }
  521.     }
  522.     else
  523.     {
  524.         
  525.         /* Increment the ISR caller error.  */
  526.         __tx_iar_system_lock_isr_caller++;
  527.     }
  528.   }
  529. }


  530. #if _DLIB_FILE_DESCRIPTOR

  531. #include <stdio.h>                        /* Added to get access to FOPEN_MAX */
  532. #ifndef _MAX_FLOCK
  533. #define _MAX_FLOCK FOPEN_MAX              /* Define _MAX_FLOCK as the maximum number of open files */
  534. #endif


  535. TX_MUTEX    __tx_iar_file_lock_mutexes[_MAX_FLOCK];
  536. UINT        __tx_iar_file_lock_next_free_mutex =  0;


  537. /* Define error counters, just for debug purposes.  */

  538. UINT        __tx_iar_file_lock_no_mutexes;
  539. UINT        __tx_iar_file_lock_internal_errors;
  540. UINT        __tx_iar_file_lock_isr_caller;


  541. void __iar_file_Mtxinit(__iar_Rmtx *m)
  542. {

  543. UINT        i;
  544. UINT        status;
  545. TX_MUTEX    *mutex_ptr;


  546.     /* First, find a free mutex in the list.  */
  547.     for (i = 0; i < _MAX_FLOCK; i++)
  548.     {

  549.         /* Setup a pointer to the start of the next free mutex.  */
  550.         mutex_ptr =  &__tx_iar_file_lock_mutexes[__tx_iar_file_lock_next_free_mutex++];
  551.    
  552.         /* Check for wrap-around on the next free mutex.  */
  553.         if (__tx_iar_file_lock_next_free_mutex >= _MAX_LOCK)
  554.         {
  555.         
  556.             /* Yes, set the free index back to 0.  */
  557.             __tx_iar_file_lock_next_free_mutex =  0;
  558.         }
  559.    
  560.         /* Is this mutex free?  */
  561.         if (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)
  562.         {
  563.         
  564.             /* Yes, this mutex is free, get out of the loop!  */
  565.             break;
  566.         }
  567.     }

  568.     /* Determine if a free mutex was found.   */
  569.     if (i >= _MAX_LOCK)
  570.     {
  571.    
  572.         /* Error!  No more free mutexes!  */
  573.         
  574.         /* Increment the no mutexes error counter.  */
  575.         __tx_iar_file_lock_no_mutexes++;
  576.         
  577.         /* Set return pointer to NULL.  */
  578.         *m =  TX_NULL;
  579.         
  580.         /* Return.  */
  581.         return;
  582.     }
  583.    
  584.     /* Now create the ThreadX mutex for the IAR library.  */
  585.     status =  _tx_mutex_create(mutex_ptr, "IAR File Library Lock", TX_NO_INHERIT);
  586.    
  587.     /* Determine if the creation was successful.  */
  588.     if (status == TX_SUCCESS)
  589.     {
  590.    
  591.         /* Yes, successful creation, return mutex pointer.  */
  592.         *m =  (VOID *) mutex_ptr;
  593.     }
  594.     else
  595.     {
  596.    
  597.         /* Increment the internal error counter.  */
  598.         __tx_iar_file_lock_internal_errors++;
  599.    
  600.         /* Return a NULL pointer to indicate an error.  */
  601.         *m =  TX_NULL;
  602.     }
  603. }

  604. void __iar_file_Mtxdst(__iar_Rmtx *m)
  605. {

  606.     /* Simply delete the mutex.  */
  607.     _tx_mutex_delete((TX_MUTEX *) *m);
  608. }

  609. void __iar_file_Mtxlock(__iar_Rmtx *m)
  610. {

  611. UINT    status;


  612.     /* Determine the caller's context. Mutex locks are only available from initialization and
  613.        threads.  */
  614.     if ((_tx_thread_system_state == 0) || (_tx_thread_system_state >= TX_INITIALIZE_IN_PROGRESS))
  615.     {
  616.    
  617.         /* Get the mutex.  */
  618.         status =  _tx_mutex_get((TX_MUTEX *) *m, TX_WAIT_FOREVER);

  619.         /* Check the status of the mutex release.  */
  620.         if (status)
  621.         {
  622.         
  623.             /* Internal error, increment the counter.  */
  624.             __tx_iar_file_lock_internal_errors++;
  625.         }
  626.     }
  627.     else
  628.     {
  629.         
  630.         /* Increment the ISR caller error.  */
  631.         __tx_iar_file_lock_isr_caller++;
  632.     }
  633. }

  634. void __iar_file_Mtxunlock(__iar_Rmtx *m)
  635. {

  636. UINT    status;


  637.     /* Determine the caller's context. Mutex unlocks are only available from initialization and
  638.        threads.  */
  639.     if ((_tx_thread_system_state == 0) || (_tx_thread_system_state >= TX_INITIALIZE_IN_PROGRESS))
  640.     {
  641.    
  642.         /* Release the mutex.  */
  643.         status =  _tx_mutex_put((TX_MUTEX *) *m);
  644.         
  645.         /* Check the status of the mutex release.  */
  646.         if (status)
  647.         {
  648.         
  649.             /* Internal error, increment the counter.  */
  650.             __tx_iar_file_lock_internal_errors++;
  651.         }
  652.     }
  653.     else
  654.     {
  655.         
  656.         /* Increment the ISR caller error.  */
  657.         __tx_iar_file_lock_isr_caller++;
  658.     }
  659. }
  660. #endif  /* _DLIB_FILE_DESCRIPTOR */

  661. #endif  /* TX_ENABLE_IAR_LIBRARY_SUPPORT  */

  662. #endif /* IAR version 8 and above.  */
复制代码


回复

使用道具 举报

13

主题

190

回帖

229

积分

高级会员

积分
229
发表于 2024-3-15 10:51:26 | 显示全部楼层
本帖最后由 zhang0352505 于 2024-3-15 10:53 编辑

这个奇怪的支持,需要在编译设置中打开iar的thread support library。
刚开始老是要报错,不明白为什么,报错如下
编译报错.png
然后试了一些设置,最后打开如下设置才编译成功
IAR设置.png
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
 楼主| 发表于 2024-3-16 09:54:39 | 显示全部楼层
zhang0352505 发表于 2024-3-15 10:51
这个奇怪的支持,需要在编译设置中打开iar的thread support library。
刚开始老是要报错,不明白为什么, ...

谢谢分享,我都没测试过这个。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-28 11:49 , Processed in 0.183242 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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