Implemented sleep and usleep syscalls.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
f6659c7958
commit
4164082074
|
@ -19,4 +19,12 @@ led_red.toggle # Toggle output
|
|||
```ruby
|
||||
ana_bg = Machine::ADC.new(52) # BandGap
|
||||
ana_bg.value
|
||||
```
|
||||
|
||||
```ruby
|
||||
1000.times do |_|
|
||||
puts "[#{Time.now}] BandGap voltage: #{'%.2f' % (ana_bg.value.to_f / 1000.0)}mV"
|
||||
led_red.toggle
|
||||
usleep(100 * 1000)
|
||||
end
|
||||
```
|
|
@ -1 +1 @@
|
|||
Subproject commit 6be5185d38c88b22a9681f4937d47d568651ab73
|
||||
Subproject commit 309be9522ba70fc1371ea50b3033b49f4428a01f
|
|
@ -300,4 +300,14 @@ int _kill(int pid, int sig) {
|
|||
|
||||
int _lseek(int file, int offset, int whence) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int sleep(unsigned int sec) {
|
||||
vTaskDelay(pdMS_TO_TICKS(sec * 1000));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usleep(useconds_t us) {
|
||||
vTaskDelay(pdMS_TO_TICKS(us / 1000));
|
||||
return 0;
|
||||
}
|
|
@ -77,6 +77,7 @@ static void mrb_machine_adc_impl_init_peripheral(void) {
|
|||
LPADC_DoAutoCalibration(ADC0);
|
||||
|
||||
NVIC_SetPriority(ADC0_IRQn, 5);
|
||||
EnableIRQ(ADC0_IRQn);
|
||||
}
|
||||
|
||||
int mrb_machine_adc_impl_config(uint32_t channel) {
|
||||
|
@ -143,8 +144,6 @@ int mrb_machine_adc_impl_read(uint32_t channel) {
|
|||
}
|
||||
|
||||
LPADC_EnableInterrupts(ADC0, kLPADC_FIFO0WatermarkInterruptEnable);
|
||||
EnableIRQ(ADC0_IRQn);
|
||||
|
||||
LPADC_DoSoftwareTrigger(ADC0, 1U);
|
||||
|
||||
if (xSemaphoreTake(s_adc_semaphore, pdMS_TO_TICKS(500)) != pdTRUE) {
|
||||
|
@ -169,11 +168,15 @@ int mrb_machine_adc_impl_read(uint32_t channel) {
|
|||
void ADC0_IRQHandler(void) {
|
||||
BaseType_t higher_priority_woken = pdFALSE;
|
||||
|
||||
DisableIRQ(ADC0_IRQn);
|
||||
uint32_t flags = LPADC_GetStatusFlags(ADC0);
|
||||
LPADC_ClearStatusFlags(ADC0, flags);
|
||||
|
||||
xSemaphoreGiveFromISR(s_adc_semaphore, &higher_priority_woken);
|
||||
if (flags & kLPADC_ResultFIFO0ReadyFlag) {
|
||||
LPADC_DisableInterrupts(ADC0, kLPADC_FIFO0WatermarkInterruptEnable);
|
||||
xSemaphoreGiveFromISR(s_adc_semaphore, &higher_priority_woken);
|
||||
|
||||
if (higher_priority_woken) {
|
||||
portYIELD_FROM_ISR(higher_priority_woken);
|
||||
if (higher_priority_woken) {
|
||||
portYIELD_FROM_ISR(higher_priority_woken);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue