- unsigned char iDirection = 0;
- int speed = abs(msg->speed);
-
- if (msg->speed > 0) iDirection = 0x1;
- else if (msg->speed < 0) iDirection = 0x2;
-
- transfer_area->M_Main &= ~(3<<(msg->num-1)*2);
- transfer_area->M_Main |= iDirection<<(msg->num-1)*2;
- transfer_area->MPWM_Main[(msg->num-1)*2] = speed;
- transfer_area->MPWM_Main[(msg->num-1)*2 + 1] = speed;
+ pthread_mutex_lock(&pwm_mutex);
+ if (msg->speed > 0) {
+ pwm_next[msg->num*2] = msg->speed;
+ pwm_next[msg->num*2+1] = 0;
+ } else {
+ pwm_next[msg->num*2] = 0;
+ pwm_next[msg->num*2+1] = msg->speed;
+ }
+ pthread_mutex_unlock(&pwm_mutex);