|
59 | 59 | #define EVTTASK_NAME "lteevt_task"
|
60 | 60 | #define LAPIEVT_QNAME "/lapievt"
|
61 | 61 |
|
| 62 | +#define clr_evtcb(info) reg_evtcb(info, 0, NULL) |
| 63 | +#define search_free_evtcb() search_evtcb(0) |
| 64 | + |
62 | 65 | /****************************************************************************
|
63 | 66 | * Private Function Prototypes
|
64 | 67 | ****************************************************************************/
|
@@ -1692,6 +1695,73 @@ static uint64_t alt1250_evt_search(uint32_t cmdid)
|
1692 | 1695 | return evtbitmap;
|
1693 | 1696 | }
|
1694 | 1697 |
|
| 1698 | +/**************************************************************************** |
| 1699 | + * Name: reg_evtcb |
| 1700 | + ****************************************************************************/ |
| 1701 | + |
| 1702 | +static int reg_evtcb(struct cbinfo_s *info, uint32_t cmdid, FAR void *cb) |
| 1703 | +{ |
| 1704 | + if (info == NULL) |
| 1705 | + { |
| 1706 | + return ERROR; |
| 1707 | + } |
| 1708 | + |
| 1709 | + info->cmdid = cmdid; |
| 1710 | + info->cb = cb; |
| 1711 | + |
| 1712 | + return OK; |
| 1713 | +} |
| 1714 | + |
| 1715 | +/**************************************************************************** |
| 1716 | + * Name: search_evtcb |
| 1717 | + ****************************************************************************/ |
| 1718 | + |
| 1719 | +static struct cbinfo_s *search_evtcb(uint32_t cmdid) |
| 1720 | +{ |
| 1721 | + int i; |
| 1722 | + |
| 1723 | + for (i = 0; i < ARRAY_SZ(g_cbtable); i++) |
| 1724 | + { |
| 1725 | + if (g_cbtable[i].cmdid == cmdid) |
| 1726 | + { |
| 1727 | + return &g_cbtable[i]; |
| 1728 | + } |
| 1729 | + } |
| 1730 | + |
| 1731 | + return NULL; |
| 1732 | +} |
| 1733 | + |
| 1734 | +/**************************************************************************** |
| 1735 | + * Name: register_evtcb |
| 1736 | + ****************************************************************************/ |
| 1737 | + |
| 1738 | +static int register_evtcb(uint32_t cmdid, FAR void *cb) |
| 1739 | +{ |
| 1740 | + if (search_evtcb(cmdid) == NULL) |
| 1741 | + { |
| 1742 | + if (reg_evtcb(search_free_evtcb(), cmdid, cb) == ERROR) |
| 1743 | + { |
| 1744 | + return -EBUSY; |
| 1745 | + } |
| 1746 | + |
| 1747 | + return OK; |
| 1748 | + } |
| 1749 | + else |
| 1750 | + { |
| 1751 | + return IS_REPORT_API(cmdid) ? -EALREADY : -EINPROGRESS; |
| 1752 | + } |
| 1753 | +} |
| 1754 | + |
| 1755 | +/**************************************************************************** |
| 1756 | + * Name: clear_evtcb |
| 1757 | + ****************************************************************************/ |
| 1758 | + |
| 1759 | +static int clear_evtcb(uint32_t cmdid) |
| 1760 | +{ |
| 1761 | + clr_evtcb(search_evtcb(cmdid)); |
| 1762 | + return OK; |
| 1763 | +} |
| 1764 | + |
1695 | 1765 | /****************************************************************************
|
1696 | 1766 | * Public Functions
|
1697 | 1767 | ****************************************************************************/
|
@@ -1723,68 +1793,17 @@ int alt1250_evtdatadestroy(void)
|
1723 | 1793 |
|
1724 | 1794 | int alt1250_regevtcb(uint32_t cmdid, FAR void *cb)
|
1725 | 1795 | {
|
1726 |
| - int ret = OK; |
1727 |
| - int i; |
1728 |
| - bool is_clear = (cb == NULL); |
1729 |
| - int myidx = -1; |
1730 |
| - int freeidx = -1; |
| 1796 | + int ret; |
1731 | 1797 |
|
1732 | 1798 | sem_wait(&g_cbtablelock);
|
1733 | 1799 |
|
1734 |
| - for (i = 0; i < ARRAY_SZ(g_cbtable); i++) |
1735 |
| - { |
1736 |
| - if (g_cbtable[i].cmdid == 0) |
1737 |
| - { |
1738 |
| - freeidx = i; |
1739 |
| - } |
1740 |
| - |
1741 |
| - if (g_cbtable[i].cmdid == cmdid) |
1742 |
| - { |
1743 |
| - myidx = i; |
1744 |
| - break; |
1745 |
| - } |
1746 |
| - } |
1747 |
| - |
1748 |
| - if (!is_clear) |
| 1800 | + if (cb == NULL) |
1749 | 1801 | {
|
1750 |
| - /* Found my ID */ |
1751 |
| - |
1752 |
| - if (myidx != -1) |
1753 |
| - { |
1754 |
| - if (IS_REPORT_API(cmdid)) |
1755 |
| - { |
1756 |
| - ret = -EALREADY; |
1757 |
| - } |
1758 |
| - else |
1759 |
| - { |
1760 |
| - ret = -EINPROGRESS; |
1761 |
| - } |
1762 |
| - } |
1763 |
| - |
1764 |
| - /* No free index at table? */ |
1765 |
| - |
1766 |
| - else if (freeidx == -1) |
1767 |
| - { |
1768 |
| - ret = -EBUSY; |
1769 |
| - } |
1770 |
| - |
1771 |
| - /* Not found my ID, but found a free index. */ |
1772 |
| - |
1773 |
| - else |
1774 |
| - { |
1775 |
| - g_cbtable[freeidx].cmdid = cmdid; |
1776 |
| - g_cbtable[freeidx].cb = cb; |
1777 |
| - } |
| 1802 | + ret = clear_evtcb(cmdid); |
1778 | 1803 | }
|
1779 | 1804 | else
|
1780 | 1805 | {
|
1781 |
| - /* Found my ID */ |
1782 |
| - |
1783 |
| - if (myidx != -1) |
1784 |
| - { |
1785 |
| - g_cbtable[myidx].cmdid = 0; |
1786 |
| - g_cbtable[myidx].cb = NULL; |
1787 |
| - } |
| 1806 | + ret = register_evtcb(cmdid, cb); |
1788 | 1807 | }
|
1789 | 1808 |
|
1790 | 1809 | sem_post(&g_cbtablelock);
|
|
0 commit comments