MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_vbus_request_chn

Function rt_vbus_request_chn

components/vbus/vbus.c:895–973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

893}
894
895int rt_vbus_request_chn(struct rt_vbus_request *req,
896 int timeout)
897{
898 int i, chnr, err;
899 size_t plen = rt_strlen(req->name) + 2;
900 unsigned char *pbuf;
901 rt_base_t level;
902
903 level = rt_hw_interrupt_disable();
904 for (i = 0; i < ARRAY_SIZE(_sess); i++)
905 {
906 if (_sess[i].st == SESSIOM_AVAILABLE)
907 break;
908 }
909 if (i == ARRAY_SIZE(_sess))
910 {
911 rt_hw_interrupt_enable(level);
912 return -RT_ERROR;
913 }
914
915 rt_completion_init(&_sess[i].cmp);
916 _sess[i].req = req;
917
918 if (req->is_server)
919 {
920 _sess[i].st = SESSIOM_LISTENING;
921 rt_hw_interrupt_enable(level);
922
923 vbus_debug("request listening %s on %d\n", req->name, i);
924
925 /* always wait on the condition */
926 err = RT_EOK;
927 goto _waitforcmp;
928 }
929
930 pbuf = rt_malloc(plen);
931 if (!pbuf)
932 {
933 rt_hw_interrupt_enable(level);
934 return -RT_ENOMEM;
935 }
936
937 _sess[i].st = SESSIOM_ESTABLISHING;
938 rt_hw_interrupt_enable(level);
939
940 pbuf[0] = RT_VBUS_CHN0_CMD_ENABLE;
941 rt_memcpy(pbuf+1, req->name, plen-1);
942 vbus_verbose("%s --> remote\n", dump_cmd_pkt(pbuf, plen));
943
944 err = _chn0_post(pbuf, plen, RT_WAITING_FOREVER);
945 rt_free(pbuf);
946
947_waitforcmp:
948 if (err == RT_EOK)
949 err = rt_completion_wait(&_sess[i].cmp, timeout);
950
951 vbus_debug("request wait cmp done %d, chnr %d\n", err, _sess[i].chnr);
952

Callers 1

_openFunction · 0.85

Calls 10

rt_strlenFunction · 0.85
rt_mallocFunction · 0.85
rt_memcpyFunction · 0.85
dump_cmd_pktFunction · 0.85
_chn0_postFunction · 0.85
rt_freeFunction · 0.85
rt_completion_waitFunction · 0.85
rt_hw_interrupt_disableFunction · 0.50
rt_hw_interrupt_enableFunction · 0.50
rt_completion_initFunction · 0.50

Tested by

no test coverage detected