mirror of https://github.com/joan2937/pigpio
Fix #357 Multithreaded PWM.
This commit is contained in:
parent
c88c5c9e4e
commit
f077c61882
5
pigpio.c
5
pigpio.c
|
@ -8828,6 +8828,7 @@ static void stopHardwarePWM(void)
|
||||||
int gpioSetMode(unsigned gpio, unsigned mode)
|
int gpioSetMode(unsigned gpio, unsigned mode)
|
||||||
{
|
{
|
||||||
int reg, shift, old_mode;
|
int reg, shift, old_mode;
|
||||||
|
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
DBG(DBG_USER, "gpio=%d mode=%d", gpio, mode);
|
DBG(DBG_USER, "gpio=%d mode=%d", gpio, mode);
|
||||||
|
|
||||||
|
@ -8839,6 +8840,8 @@ int gpioSetMode(unsigned gpio, unsigned mode)
|
||||||
if (mode > PI_ALT3)
|
if (mode > PI_ALT3)
|
||||||
SOFT_ERROR(PI_BAD_MODE, "gpio %d, bad mode (%d)", gpio, mode);
|
SOFT_ERROR(PI_BAD_MODE, "gpio %d, bad mode (%d)", gpio, mode);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mutex);
|
||||||
|
|
||||||
reg = gpio/10;
|
reg = gpio/10;
|
||||||
shift = (gpio%10) * 3;
|
shift = (gpio%10) * 3;
|
||||||
|
|
||||||
|
@ -8853,6 +8856,8 @@ int gpioSetMode(unsigned gpio, unsigned mode)
|
||||||
|
|
||||||
gpioReg[reg] = (gpioReg[reg] & ~(7<<shift)) | (mode<<shift);
|
gpioReg[reg] = (gpioReg[reg] & ~(7<<shift)) | (mode<<shift);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue