svghmi/svghmi.c
branchsvghmi
changeset 3295 0375d801fff7
parent 3294 e3db472b0dfb
child 3374 9a82918e063c
equal deleted inserted replaced
3294:e3db472b0dfb 3295:0375d801fff7
   135 }
   135 }
   136 
   136 
   137 static uint32_t send_session_index;
   137 static uint32_t send_session_index;
   138 static int send_iterator(uint32_t index, hmi_tree_item_t *dsc)
   138 static int send_iterator(uint32_t index, hmi_tree_item_t *dsc)
   139 {
   139 {
   140     while(AtomicCompareExchange(&dsc->wlock, 0, 1)) sched_yield();
   140     while(AtomicCompareExchange(&dsc->wlock, 0, 1))
       
   141         nRT_reschedule();
   141 
   142 
   142     if(dsc->wstate[send_session_index] == buf_tosend)
   143     if(dsc->wstate[send_session_index] == buf_tosend)
   143     {
   144     {
   144         uint32_t sz = __get_type_enum_size(dsc->type);
   145         uint32_t sz = __get_type_enum_size(dsc->type);
   145         if(sbufidx + sizeof(uint32_t) + sz <=  sizeof(sbuf))
   146         if(sbufidx + sizeof(uint32_t) + sz <=  sizeof(sbuf))
   186     return 0;
   187     return 0;
   187 }
   188 }
   188 
   189 
   189 void update_refresh_period(hmi_tree_item_t *dsc, uint32_t session_index, uint16_t refresh_period_ms)
   190 void update_refresh_period(hmi_tree_item_t *dsc, uint32_t session_index, uint16_t refresh_period_ms)
   190 {
   191 {
   191     while(AtomicCompareExchange(&dsc->wlock, 0, 1)) sched_yield();
   192     while(AtomicCompareExchange(&dsc->wlock, 0, 1)) 
       
   193         nRT_reschedule();
       
   194 
   192     if(refresh_period_ms) {
   195     if(refresh_period_ms) {
   193         if(!dsc->refresh_period_ms[session_index])
   196         if(!dsc->refresh_period_ms[session_index])
   194         {
   197         {
   195             dsc->wstate[session_index] = buf_new;
   198             dsc->wstate[session_index] = buf_new;
   196         }
   199         }
   222 
   225 
   223 int svghmi_continue_collect;
   226 int svghmi_continue_collect;
   224 
   227 
   225 int __init_svghmi()
   228 int __init_svghmi()
   226 {
   229 {
   227     bzero(rbuf,sizeof(rbuf));
   230     memset(rbuf,0,sizeof(rbuf));
   228     bzero(wbuf,sizeof(wbuf));
   231     memset(wbuf,0,sizeof(wbuf));
   229 
   232 
   230     svghmi_continue_collect = 1;
   233     svghmi_continue_collect = 1;
   231 
   234 
   232     /* create svghmi_pipe */
   235     /* create svghmi_pipe */
   233     svghmi_handle = create_RT_to_nRT_signal("SVGHMI_pipe");
   236     svghmi_handle = create_RT_to_nRT_signal("SVGHMI_pipe");
   345                     }
   348                     }
   346 
   349 
   347                     if((valptr + sz) <= end)
   350                     if((valptr + sz) <= end)
   348                     {
   351                     {
   349                         // rescheduling spinlock until free
   352                         // rescheduling spinlock until free
   350                         while(AtomicCompareExchange(&dsc->rlock, 0, 1)) sched_yield();
   353                         while(AtomicCompareExchange(&dsc->rlock, 0, 1)) 
       
   354                             nRT_reschedule();
   351 
   355 
   352                         memcpy(dst_p, valptr, sz);
   356                         memcpy(dst_p, valptr, sz);
   353                         dsc->rstate = buf_set;
   357                         dsc->rstate = buf_set;
   354 
   358 
   355                         AtomicCompareExchange(&dsc->rlock, 1, 0);
   359                         AtomicCompareExchange(&dsc->rlock, 1, 0);