| 1014 | #endif |
| 1015 | |
| 1016 | static void _bus_in_entry(void *param) |
| 1017 | { |
| 1018 | rt_sem_init(&_bus_in_sem, "vbus", 0, RT_IPC_FLAG_FIFO); |
| 1019 | rt_event_init(&_bus_in_event, "vbus", RT_IPC_FLAG_FIFO); |
| 1020 | rt_memset(_bus_in_action, 0, sizeof(_bus_in_action)); |
| 1021 | |
| 1022 | while (rt_sem_take(&_bus_in_sem, |
| 1023 | RT_WAITING_FOREVER) == RT_EOK) |
| 1024 | { |
| 1025 | rt_uint32_t event_set = 0; |
| 1026 | |
| 1027 | /* while(not empty) */ |
| 1028 | while (RT_VBUS_IN_RING->get_idx != RT_VBUS_IN_RING->put_idx) |
| 1029 | { |
| 1030 | unsigned int id, nxtidx; |
| 1031 | rt_size_t size; |
| 1032 | struct rt_vbus_data *act; |
| 1033 | |
| 1034 | rt_vbus_smp_rmb(); |
| 1035 | size = RT_VBUS_IN_RING->blks[RT_VBUS_IN_RING->get_idx].len; |
| 1036 | id = RT_VBUS_IN_RING->blks[RT_VBUS_IN_RING->get_idx].id; |
| 1037 | |
| 1038 | vbus_debug("vmm bus in: chnr %d, size %d\n", id, size); |
| 1039 | |
| 1040 | /* Suspended channel can still recv data. */ |
| 1041 | if (id > RT_VBUS_CHANNEL_NR || !_chn_connected(id)) |
| 1042 | { |
| 1043 | vbus_error("drop on invalid chn %d\n", id); |
| 1044 | /* drop the invalid packet */ |
| 1045 | _ring_add_get_bnr(RT_VBUS_IN_RING, LEN2BNR(size)); |
| 1046 | continue; |
| 1047 | } |
| 1048 | |
| 1049 | if (id == 0) |
| 1050 | { |
| 1051 | if (size > 60) |
| 1052 | vbus_error("too big(%d) packet on chn0\n", size); |
| 1053 | else |
| 1054 | _chn0_actor(RT_VBUS_IN_RING->blks[RT_VBUS_IN_RING->get_idx].data, size); |
| 1055 | _ring_add_get_bnr(RT_VBUS_IN_RING, LEN2BNR(size)); |
| 1056 | continue; |
| 1057 | } |
| 1058 | |
| 1059 | #ifdef RT_VBUS_STATISTICS |
| 1060 | _total_data_sz += size; |
| 1061 | #endif |
| 1062 | |
| 1063 | act = rt_malloc(sizeof(*act) + size); |
| 1064 | if (act == RT_NULL) |
| 1065 | { |
| 1066 | //vbus_error("drop on OOM (%d, %d)\n", id, size); |
| 1067 | /* drop the packet on malloc fall */ |
| 1068 | _ring_add_get_bnr(RT_VBUS_IN_RING, LEN2BNR(size)); |
| 1069 | continue; |
| 1070 | } |
| 1071 | |
| 1072 | act->size = size; |
| 1073 | act->next = RT_NULL; |
nothing calls this directly
no test coverage detected