static void new_osc_sample(const measure_data_t* data) { int channel = ch_generic2internal(data->ch); int i; xSemaphoreTake(lcdLock, portMAX_DELAY); interrupt_off(); /* first we clear the old line */ GLCD_setTextColor(White); for(i=0;i<CONFIG_SAMPLE_BUFFER_SIZE;i++) { display_show_analog( (display_buffer_index[channel]+i) % DISPLAY_BUFF_SIZE, display_buffer[(display_buffer_index[channel]+i) % DISPLAY_BUFF_SIZE][channel]); } GLCD_setTextColor(osc_color[channel]); for(i=0;i<CONFIG_SAMPLE_BUFFER_SIZE;i++) { display_show_analog(display_index(channel), data->data[i]); // Update buffer display_buffer[display_index(channel)][channel] = data->data[i]; display_buffer_index[channel]++; } interrupt_on(); xSemaphoreGive(lcdLock); }
void sema_down (struct semaphore* sema) { ASSERT (sema != NULL); enum interrupt_state state = interrupt_off (); /* All accesses to this semaphore must be synchronized using the semaphore's internal spinlock. */ spinlock_acquire (&sema->sync); /* If the semaphore's value is at 0, then we must block the thread */ while (sema->val == 0) { list_push_back (&sema->waiters, &thread_current ()->elem); // spinlock_release (&sema->sync); thread_block (); // spinlock_acquire (&sema->sync); } /* Decrement the semaphore's value */ sema->val--; spinlock_release (&sema->sync); interrupt_restore (state); interrupt_on (); };
void sema_up (struct semaphore* sema) { ASSERT (sema != NULL); enum interrupt_state state = interrupt_off (); // spinlock_acquire (&sema->sync); sema->val++; struct thread* t = LIST_ENTRY ( list_pop_back (&sema->waiters), struct thread, elem); // spinlock_release (&sema->sync); thread_unblock (t); interrupt_restore (state); };
bool sema_try_down (struct semaphore* sema) { bool result = true; ASSERT (sema != NULL); enum interrupt_state state = interrupt_off (); // spinlock_acquire (&sema->sync); result = (sema->val > 0); if (result) { sema->val--; } // spinlock_release (&sema->sync); interrupt_restore (state); return result; };