void CAN_start_transmission_internal(volatile can_stream_data_t* data) { int i=0; while ((buffer_bytes_available((buffer_t*)&data->byte_buffer)>0) && i<8) { data->can_msg.data.u8[i]=buffer_get((buffer_t*)&data->byte_buffer); i++; } if (i==0) { // nothing left to transmit data->transmission_active=false; return; } /* if (data->can_channel==0) { can_bus_init(data->can_channel, ((uint32_t)&mob_ram_ch0[0]), CANIF_CHANNEL_MODE_NORMAL, can_callback0); } else { can_bus_init(data->can_channel, ((uint32_t)&mob_ram_ch1[0]), CANIF_CHANNEL_MODE_NORMAL, can_callback1); } */ data->can_mob.handle=CAN_TX_MOB; data->can_mob.dlc=i; data->can_msg.id=data->id; data->can_msg.id_mask = data->id_mask; data->can_mob.req_type=CAN_DATA_FRAME; data->transmission_active=true; can_bus_tx(data->can_channel, data->can_mob.handle, data->can_mob.dlc, data->can_mob.req_type, data->can_mob.can_msg); }
bool acoustic_update(audio_t* audio_data) { uint8_t buffer[6]; //reset new_data flag audio_data->new_data = 0; if (first_run == 0) { first_run = 1; buffer_clear(&(audio_data->audio_buffer)); } else if (buffer_bytes_available(&(audio_data->audio_buffer)) >= 6) { buffer[0] = buffer_get(&(audio_data->audio_buffer)); if (buffer[0] == 254) { buffer[1] = buffer_get(&(audio_data->audio_buffer)); buffer[2] = buffer_get(&(audio_data->audio_buffer)); buffer[3] = buffer_get(&(audio_data->audio_buffer)); buffer[4] = buffer_get(&(audio_data->audio_buffer)); buffer[5] = buffer_get(&(audio_data->audio_buffer)); //checksum check if ((-(buffer[1] + buffer[2] + buffer[3] + buffer[4]) & 0xFF) == buffer[5]) { audio_data->azimuth = (float)((buffer[1] << 8) | buffer[2]); audio_data->elevation = (float)((buffer[3] << 8) | buffer[4]); audio_data->new_data = 1; buffer_clear(&(audio_data->audio_buffer)); } } } acoustic_process(audio_data); return true; }
int CAN_bytes_available(can_stream_data_t *data) { return buffer_bytes_available(&data->byte_buffer); }
static ssize_t annotate_write(struct file *file, char const __user *buf, size_t count_orig, loff_t *offset) { int pid, cpu, header_size, available, contiguous, length1, length2, size, count = count_orig & 0x7fffffff; bool interrupt_context; if (*offset) return -EINVAL; interrupt_context = in_interrupt(); /* Annotations are not supported in interrupt context, but may work * if you comment out the the next four lines of code. By doing so, * annotations in interrupt context can result in deadlocks and lost * data. */ if (interrupt_context) { pr_warning("gator: Annotations are not supported in interrupt context. Edit gator_annotate.c in the gator driver to enable annotations in interrupt context.\n"); return -EINVAL; } retry: /* synchronize between cores and with collect_annotations */ spin_lock(&annotate_lock); if (!collect_annotations) { /* Not collecting annotations, tell the caller everything was written */ size = count_orig; goto annotate_write_out; } /* Annotation only uses a single per-cpu buffer as the data must be in order to the engine */ cpu = 0; if (current == NULL) pid = 0; else pid = current->pid; /* determine total size of the payload */ header_size = MAXSIZE_PACK32 * 3 + MAXSIZE_PACK64; available = buffer_bytes_available(cpu, ANNOTATE_BUF) - header_size; size = count < available ? count : available; if (size <= 0) { /* Buffer is full, wait until space is available */ spin_unlock(&annotate_lock); /* Drop the annotation as blocking is not allowed in interrupt context */ if (interrupt_context) return -EINVAL; wait_event_interruptible(gator_annotate_wait, buffer_bytes_available(cpu, ANNOTATE_BUF) > header_size || !collect_annotations); /* Check to see if a signal is pending */ if (signal_pending(current)) return -EINTR; goto retry; } /* synchronize shared variables annotateBuf and annotatePos */ if (per_cpu(gator_buffer, cpu)[ANNOTATE_BUF]) { u64 time = gator_get_time(); gator_buffer_write_packed_int(cpu, ANNOTATE_BUF, get_physical_cpu()); gator_buffer_write_packed_int(cpu, ANNOTATE_BUF, pid); gator_buffer_write_packed_int64(cpu, ANNOTATE_BUF, time); gator_buffer_write_packed_int(cpu, ANNOTATE_BUF, size); /* determine the sizes to capture, length1 + length2 will equal size */ contiguous = contiguous_space_available(cpu, ANNOTATE_BUF); if (size < contiguous) { length1 = size; length2 = 0; } else { length1 = contiguous; length2 = size - contiguous; } if (annotate_copy(file, buf, length1) != 0) { size = -EINVAL; goto annotate_write_out; } if (length2 > 0 && annotate_copy(file, &buf[length1], length2) != 0) { size = -EINVAL; goto annotate_write_out; } /* Check and commit; commit is set to occur once buffer is 3/4 full */ buffer_check(cpu, ANNOTATE_BUF, time); } annotate_write_out: spin_unlock(&annotate_lock); /* return the number of bytes written */ return size; }