Compare commits

..

No commits in common. "master" and "PM15" have entirely different histories.
master ... PM15

4 changed files with 30 additions and 68 deletions

View File

@ -96,13 +96,6 @@ static bool reload_config = false;
static uint16_t write_offset = 0;
static uint16_t read_offset = 0;
typedef enum {
NormalOperation,
SaveRequested,
Saving
} State;
static State saveState = NormalOperation;
bool validate_filter_configuration(filter_configuration_tlv *filters)
{
if (filters->header.type != FILTER_CONFIGURATION) {
@ -364,47 +357,37 @@ void load_config() {
}
#ifndef TEST_TARGET
bool __no_inline_not_in_flash_func(save_config)() {
bool __no_inline_not_in_flash_func(save_configuration)() {
const uint8_t active_configuration = inactive_working_configuration ? 0 : 1;
tlv_header* config = (tlv_header*) working_configuration[active_configuration];
switch (saveState) {
case SaveRequested:
if (validate_configuration(config)) {
/* Turn the DAC off so we don't make a huge noise when disrupting
real time audio operation. */
power_down_dac();
if (validate_configuration(config)) {
const size_t config_length = config->length - ((size_t)config->value - (size_t)config);
// Write data to flash
uint8_t flash_buffer[CFG_BUFFER_SIZE];
flash_header_tlv* flash_header = (flash_header_tlv*) flash_buffer;
flash_header->header.type = FLASH_HEADER;
flash_header->header.length = sizeof(flash_header_tlv) + config_length;
flash_header->magic = FLASH_MAGIC;
flash_header->version = CONFIG_VERSION;
memcpy((void*)(flash_header->tlvs), config->value, config_length);
const size_t config_length = config->length - ((size_t)config->value - (size_t)config);
// Write data to flash
uint8_t flash_buffer[CFG_BUFFER_SIZE];
flash_header_tlv* flash_header = (flash_header_tlv*) flash_buffer;
flash_header->header.type = FLASH_HEADER;
flash_header->header.length = sizeof(flash_header_tlv) + config_length;
flash_header->magic = FLASH_MAGIC;
flash_header->version = CONFIG_VERSION;
memcpy((void*)(flash_header->tlvs), config->value, config_length);
uint32_t ints = save_and_disable_interrupts();
flash_range_erase(USER_CONFIGURATION_OFFSET, FLASH_SECTOR_SIZE);
flash_range_program(USER_CONFIGURATION_OFFSET, flash_buffer, CFG_BUFFER_SIZE);
restore_interrupts(ints);
saveState = Saving;
/* Turn the DAC off so we don't make a huge noise when disrupting
real time audio operation. */
power_down_dac();
// Return true, so the caller skips processing audio
return true;
}
// Validation failed, give up.
saveState = NormalOperation;
break;
case Saving:
/* Turn the DAC off so we don't make a huge noise when disrupting
real time audio operation. */
power_up_dac();
saveState = NormalOperation;
return false;
default:
break;
uint32_t ints = save_and_disable_interrupts();
flash_range_erase(USER_CONFIGURATION_OFFSET, FLASH_SECTOR_SIZE);
flash_range_program(USER_CONFIGURATION_OFFSET, flash_buffer, CFG_BUFFER_SIZE);
restore_interrupts(ints);
power_up_dac();
return true;
}
return false;
@ -432,14 +415,7 @@ bool process_cmd(tlv_header* cmd) {
}
break;
case SAVE_CONFIGURATION: {
if (cmd->length == 4) {
saveState = SaveRequested;
if (audio_state.interface == 0) {
// The OS will configure the alternate "zero" interface when the device is not in use
// in this sate we can write to flash now. Otherwise, defer the save until we get the next
// usb packet.
save_config();
}
if (cmd->length == 4 && save_configuration()) {
result->type = OK;
result->length = 4;
return true;

View File

@ -52,7 +52,6 @@ void config_in_packet(struct usb_endpoint *ep);
void config_out_packet(struct usb_endpoint *ep);
void configuration_ep_on_cancel(struct usb_endpoint *ep);
extern void load_config();
extern bool save_config();
extern void apply_config_changes();
#endif // CONFIGURATION_MANAGER_H

View File

@ -52,7 +52,6 @@ static uint8_t *userbuf;
audio_state_config audio_state = {
.freq = 48000,
.de_emphasis_frequency = 0x1, // 48khz
.interface = 0
};
preprocessing_config preprocessing = {
@ -126,18 +125,6 @@ static void __no_inline_not_in_flash_func(_as_audio_packet)(struct usb_endpoint
int32_t *out = (int32_t *) userbuf;
int samples = usb_buffer->data_len / 2;
// Make sure core 1 is ready for us.
multicore_fifo_pop_blocking();
if (save_config()) {
// Skip processing while we are writing to flash
multicore_fifo_push_blocking(CORE0_ABORTED);
// keep on truckin'
usb_grow_transfer(ep->current_transfer, 1);
usb_packet_done(ep);
return;
}
if (preprocessing.reverse_stereo) {
for (int i = 0; i < samples; i+=2) {
out[i] = in[i+1];
@ -149,6 +136,8 @@ static void __no_inline_not_in_flash_func(_as_audio_packet)(struct usb_endpoint
out[i] = in[i];
}
// Make sure core 1 is ready for us.
multicore_fifo_pop_blocking();
multicore_fifo_push_blocking(CORE0_READY);
multicore_fifo_push_blocking(samples);
@ -197,7 +186,8 @@ void __no_inline_not_in_flash_func(core1_entry)() {
// Block until the userbuf is filled with data
uint32_t ready = multicore_fifo_pop_blocking();
if (ready == CORE0_ABORTED) continue;
while (ready != CORE0_READY)
ready = multicore_fifo_pop_blocking();
const uint32_t samples = multicore_fifo_pop_blocking();
@ -770,7 +760,6 @@ static const struct usb_transfer_type _audio_cmd_transfer_type = {
static bool as_set_alternate(struct usb_interface *interface, uint alt) {
assert(interface == &as_op_interface);
audio_state.interface = alt;
switch (alt) {
case 0: power_down_dac(); return true;
case 1: power_up_dac(); return true;

View File

@ -76,7 +76,6 @@ typedef struct _audio_state_config {
int16_t _target_pcm3060_registers;
};
int16_t pcm3060_registers;
int8_t interface;
} audio_state_config;
extern audio_state_config audio_state;
@ -150,7 +149,6 @@ static char *descriptor_strings[] = {
#define SAMPLING_FREQ (CODEC_FREQ / 192)
#define CORE0_READY 19813219
#define CORE0_ABORTED 91231891
#define CORE1_READY 72965426
/*****************************************************************************