Skip to content

Commit

Permalink
seems to all work
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhitman committed Jun 9, 2024
1 parent f26fe96 commit bb6d9c6
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 41 deletions.
8 changes: 7 additions & 1 deletion alles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import socket, struct, datetime, os, time, sys
import socket, struct, datetime, os, time, sys, datetime
sys.path.append('amy')
import amy
from amy import *
Expand Down Expand Up @@ -117,6 +117,12 @@ def decode_battery_mask(mask):
if (mask & 0x80): level = 1
return(state, level)

def millis():
now = datetime.datetime.now()
midnight = datetime.datetime.combine(now.date(), datetime.time.min)
delta = now - midnight
milliseconds = (delta.total_seconds() * 1000) + (delta.microseconds / 1000)
return int(milliseconds)

def sync(count=10, delay_ms=100):
global sock
Expand Down
2 changes: 1 addition & 1 deletion amy
Submodule amy updated from ad6cb9 to 33fb9b
5 changes: 4 additions & 1 deletion main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ list(APPEND IDF_COMPONENTS
mdns
)

target_compile_definitions(${COMPONENT_TARGET} PUBLIC "-DALLES")
target_compile_options(${COMPONENT_TARGET} PUBLIC
-DALLES
-Wno-uninitialized
)

set_source_files_properties(alles_esp32.c alles.c ../amy/src/amy.c
PROPERTIES COMPILE_FLAGS
Expand Down
3 changes: 2 additions & 1 deletion main/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ CC = gcc
CFLAGS = -g -Wall -Wno-strict-aliasing -I$(AMY) -I.

OBJECTS = $(patsubst %.c, %.o, multicast_desktop.c alles_desktop.c alles.c sounds.c $(AMY)/algorithms.c $(AMY)/delay.c \
$(AMY)/amy.c $(AMY)/envelope.c $(AMY)/filters.c $(AMY)/oscillators.c $(AMY)/pcm.c $(AMY)/partials.c $(AMY)/libminiaudio-audio.c)
$(AMY)/amy.c $(AMY)/envelope.c $(AMY)/filters.c $(AMY)/oscillators.c $(AMY)/pcm.c $(AMY)/partials.c $(AMY)/libminiaudio-audio.c \
$(AMY)/log2_exp2.c $(AMY)/custom.c $(AMY)/patches.c)
HEADERS = alles.h $(wildcard amy/*.h)

UNAME_S := $(shell uname -s)
Expand Down
6 changes: 4 additions & 2 deletions main/alles.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ amy_err_t sync_init() {



void update_map(uint8_t client, uint8_t ipv4, int64_t time) {
void update_map(int16_t client, uint8_t ipv4, int64_t time) {
// I'm called when I get a sync response or a regular ping packet
// I update a map of booted devices.

Expand Down Expand Up @@ -111,7 +111,8 @@ void alles_parse_message(char *message, uint16_t length) {
if(b == '_' && c==0) sync_response = 1;
if( ((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z')) || b == 0) { // new mode or end
if(mode=='g') client = atoi(message + start);
if(mode=='i') sync_index = atoi(message + start);
if(sync_response) if(mode=='i') sync_index = atoi(message + start);
if(sync_response) if(mode=='r') ipv4=atoi(message + start);
if(mode=='U') sync = atol(message + start);
mode = b;
start = c + 1;
Expand All @@ -120,6 +121,7 @@ void alles_parse_message(char *message, uint16_t length) {
}
if(sync_response) {
// If this is a sync response, let's update our local map of who is booted
//printf("got sync response client %d ipv4 %d sync %lld\n", client, ipv4, sync);
update_map(client, ipv4, sync);
length = 0; // don't need to do the rest
}
Expand Down
4 changes: 2 additions & 2 deletions main/alles.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "driver/gpio.h"


#define MAX_TASKS 9
#define MAX_TASKS 8

// Pins & buttons
#define BUTTON_WAKEUP 34
Expand Down Expand Up @@ -94,7 +94,7 @@ extern int16_t client_id;
void ping(int64_t sysclock);
amy_err_t sync_init();

extern void update_map(uint8_t client, uint8_t ipv4, int64_t time);
extern void update_map(int16_t client, uint8_t ipv4, int64_t time);
extern void handle_sync(int64_t time, int8_t index);
extern void mcast_send(char * message, uint16_t len);
#ifndef ESP_PLATFORM
Expand Down
2 changes: 1 addition & 1 deletion main/alles_desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ char *local_ip, *raw_file;

int main(int argc, char ** argv) {
sync_init();
amy_start();
amy_start(1,0,1);
amy_reset_oscs();
amy_global.latency_ms = ALLES_LATENCY_MS;

Expand Down
42 changes: 18 additions & 24 deletions main/alles_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,43 +191,35 @@ amy_err_t esp_amy_init() {
void esp_show_debug(uint8_t type) {
TaskStatus_t *pxTaskStatusArray;
volatile UBaseType_t uxArraySize, x, i;
const char* const tasks[] = { "render_task0", "render_task1", "mcast_task", "parse_task", "main", "fill_audio_buff", "wifi", "idle0", "idle1", 0 };
const char* const tasks[] = { ALLES_PARSE_TASK_NAME, ALLES_RECEIVE_TASK_NAME, ALLES_RENDER_TASK_NAME, ALLES_FILL_BUFFER_TASK_NAME, "main", "wifi", "IDLE0", "IDLE1", 0 };
const uint8_t cores[] = {ALLES_PARSE_TASK_COREID, ALLES_RECEIVE_TASK_COREID, ALLES_RENDER_TASK_COREID, ALLES_FILL_BUFFER_TASK_COREID, 0, 0, 0, 1, 0};

uxArraySize = uxTaskGetNumberOfTasks();
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );
unsigned long counter_since_last[MAX_TASKS];
unsigned long ulTotalRunTime = 0;
TaskStatus_t xTaskDetails;
//unsigned long ulTotalRunTime = 0;
unsigned long ulTotalRunTime_per_core[2];
ulTotalRunTime_per_core[0] = 0;
ulTotalRunTime_per_core[1] = 0;

//TaskStatus_t xTaskDetails;

// We have to check for the names we want to track
for(i=0;i<MAX_TASKS;i++) { // for each name
counter_since_last[i] = 0;
for(x=0; x<uxArraySize; x++) { // for each task
if(strcmp(pxTaskStatusArray[x].pcTaskName, tasks[i])==0) {
counter_since_last[i] = pxTaskStatusArray[x].ulRunTimeCounter - last_task_counters[i];
last_task_counters[i] = pxTaskStatusArray[x].ulRunTimeCounter;
ulTotalRunTime = ulTotalRunTime + counter_since_last[i];
//ulTotalRunTime = ulTotalRunTime + counter_since_last[i];
ulTotalRunTime_per_core[cores[i]] += counter_since_last[i];
}
}

// Have to get these specially as the task manager calls them both "IDLE" and swaps their orderings around
if(strcmp("idle0", tasks[i])==0) {
vTaskGetInfo(idle_0_handle, &xTaskDetails, pdFALSE, eRunning);
counter_since_last[i] = xTaskDetails.ulRunTimeCounter - last_task_counters[i];
last_task_counters[i] = xTaskDetails.ulRunTimeCounter;
ulTotalRunTime = ulTotalRunTime + counter_since_last[i];
}
if(strcmp("idle1", tasks[i])==0) {
vTaskGetInfo(idle_1_handle, &xTaskDetails, pdFALSE, eRunning);
counter_since_last[i] = xTaskDetails.ulRunTimeCounter - last_task_counters[i];
last_task_counters[i] = xTaskDetails.ulRunTimeCounter;
ulTotalRunTime = ulTotalRunTime + counter_since_last[i];
}


}
printf("------ CPU usage since last call to debug()\n");
for(i=0;i<MAX_TASKS;i++) {
printf("%-15s\t%-15ld\t\t%2.2f%%\n", tasks[i], counter_since_last[i], (float)counter_since_last[i]/ulTotalRunTime * 100.0);
printf("%d %-15s\t%-15ld\t\t%2.2f%%\n", cores[i], tasks[i], counter_since_last[i], (float)counter_since_last[i]/ulTotalRunTime_per_core[cores[i]] * 100.0);
}
printf("------\nEvent queue size %d / %d. Received %" PRIu32 " events and %" PRIu32 " messages\n", amy_global.event_qsize, AMY_EVENT_FIFO_LEN, event_counter, message_counter);
event_counter = 0;
Expand Down Expand Up @@ -472,16 +464,18 @@ void app_main() {
// Setup the socket
create_multicast_ipv4_socket();

// Create the task that waits for UDP messages, parses them and puts them on the sequencer queue (core 1)
xTaskCreatePinnedToCore(&esp_parse_task, ALLES_PARSE_TASK_NAME, ALLES_PARSE_TASK_STACK_SIZE, NULL, ALLES_PARSE_TASK_PRIORITY, &parseTask, ALLES_PARSE_TASK_COREID);
// Create the task that listens fro new incoming UDP messages (core 2)
xTaskCreatePinnedToCore(&mcast_listen_task, ALLES_RECEIVE_TASK_NAME, ALLES_RECEIVE_TASK_STACK_SIZE, NULL, ALLES_RECEIVE_TASK_PRIORITY, &mcastTask, ALLES_RECEIVE_TASK_COREID);
delay_ms(100);

// Create the task that waits for UDP messages, parses them and puts them on the sequencer queue (core 1)
xTaskCreatePinnedToCore(&esp_parse_task, ALLES_PARSE_TASK_NAME, ALLES_PARSE_TASK_STACK_SIZE, NULL, ALLES_PARSE_TASK_PRIORITY, &parseTask, ALLES_PARSE_TASK_COREID);

// Schedule a "turning on" sound
bleep();

// Print free RAm
heap_caps_print_heap_info(MALLOC_CAP_INTERNAL);
//heap_caps_print_heap_info(MALLOC_CAP_INTERNAL);

// Spin this core until the power off button is pressed, parsing events and making sounds
while(status & RUNNING) {
Expand Down
21 changes: 13 additions & 8 deletions sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ CONFIG_PARTITION_TABLE_MD5=y
#
# Compiler options
#
CONFIG_COMPILER_OPTIMIZATION_DEBUG=y
# CONFIG_COMPILER_OPTIMIZATION_DEBUG is not set
# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set
# CONFIG_COMPILER_OPTIMIZATION_PERF is not set
CONFIG_COMPILER_OPTIMIZATION_PERF=y
# CONFIG_COMPILER_OPTIMIZATION_NONE is not set
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT is not set
Expand Down Expand Up @@ -1055,14 +1055,17 @@ CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048
CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10
CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0
CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1
# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
# CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID is not set
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U32=y
# CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U64 is not set
# end of Kernel

#
# Port
#
CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS=y
# CONFIG_FREERTOS_TASK_PRE_DELETION_HOOK is not set
Expand All @@ -1075,6 +1078,8 @@ CONFIG_FREERTOS_TICK_SUPPORT_CORETIMER=y
CONFIG_FREERTOS_CORETIMER_0=y
# CONFIG_FREERTOS_CORETIMER_1 is not set
CONFIG_FREERTOS_SYSTICK_USES_CCOUNT=y
CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER=y
# CONFIG_FREERTOS_RUN_TIME_STATS_USING_CPU_CLK is not set
# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set
# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
# end of Port
Expand Down Expand Up @@ -1749,9 +1754,9 @@ CONFIG_LOG_BOOTLOADER_LEVEL=3
CONFIG_FLASHMODE_DIO=y
# CONFIG_FLASHMODE_DOUT is not set
CONFIG_MONITOR_BAUD=115200
CONFIG_OPTIMIZATION_LEVEL_DEBUG=y
CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y
CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set
# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set
# CONFIG_COMPILER_OPTIMIZATION_DEFAULT is not set
# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set
# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set
CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y
Expand Down

0 comments on commit bb6d9c6

Please sign in to comment.