static void usart_rx_interrupt_handler(struct usart_config const *config) { intptr_t base = config->hw->base; int32_t status = STM32_USART_SR(base); /* * We have to check and clear the overrun error flag on STM32L because * we can't disable it. */ if (status & STM32_USART_SR_ORE) { /* * In the unlikely event that the overrun error bit was set but * the RXNE bit was not (possibly because a read was done from * RDR without first reading the status register) we do a read * here to clear the overrun error bit. */ if (!(status & STM32_USART_SR_RXNE)) (void)STM32_USART_RDR(config->hw->base); atomic_add(&config->state->rx_overrun, 1); } if (status & STM32_USART_SR_RXNE) { uint8_t byte = STM32_USART_RDR(base); if (!queue_add_unit(config->producer.queue, &byte)) atomic_add(&config->state->rx_dropped, 1); } }
void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data, struct motion_sensor_t *sensor, int valid_data) { struct ec_response_motion_sensor_data vector; int i; data->sensor_num = sensor - motion_sensors; mutex_lock(&g_sensor_mutex); if (queue_space(&motion_sense_fifo) == 0) { queue_remove_unit(&motion_sense_fifo, &vector); motion_sense_fifo_lost++; motion_sensors[vector.sensor_num].lost++; if (vector.flags & MOTIONSENSE_SENSOR_FLAG_FLUSH) CPRINTS("Lost flush for sensor %d", vector.sensor_num); } for (i = 0; i < valid_data; i++) sensor->xyz[i] = data->data[i]; mutex_unlock(&g_sensor_mutex); if (valid_data) { int ap_odr = sensor->config[SENSOR_CONFIG_AP].odr & ~ROUND_UP_FLAG; int rate = INT_TO_FP(sensor->drv->get_data_rate(sensor)); /* If the AP does not want sensor info, skip */ if (ap_odr == 0) return; /* Skip if EC is oversampling */ if (sensor->oversampling < 0) { sensor->oversampling += fp_div(INT_TO_FP(1000), rate); return; } sensor->oversampling += fp_div(INT_TO_FP(1000), rate) - fp_div(INT_TO_FP(1000), INT_TO_FP(ap_odr)); } queue_add_unit(&motion_sense_fifo, data); }