diff --git a/config/arch/cortexM4_stm32f4/stm32f429zi_skyward_anakin/board_settings.h b/config/arch/cortexM4_stm32f4/stm32f429zi_skyward_anakin/board_settings.h index ff6472e8437a122e0ad9337b6310424d8b4ce833..78fd694f67b6c1932b6b60b172bea8986e114027 100644 --- a/config/arch/cortexM4_stm32f4/stm32f429zi_skyward_anakin/board_settings.h +++ b/config/arch/cortexM4_stm32f4/stm32f429zi_skyward_anakin/board_settings.h @@ -64,7 +64,7 @@ const unsigned int AUX_TIMER_MAX=0xffff; ///<\internal Aux timer is 16 bits /// Serial port const unsigned int defaultSerial=1; -const unsigned int defaultSerialSpeed=19200; +const unsigned int defaultSerialSpeed=115200; const bool defaultSerialFlowctrl=false; //#define SERIAL_1_DMA //Serial 1 has no DMA as it would conflict with SPI6 #define SERIAL_2_DMA //Serial 2 is used by the piksi GPS, enable DMA diff --git a/scripts/anakin_client_curses/.gitignore b/scripts/anakin_client_curses/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b051c6c57fa8b6cc588a3ebad860005ec6fcf7cc --- /dev/null +++ b/scripts/anakin_client_curses/.gitignore @@ -0,0 +1 @@ +client diff --git a/scripts/anakin_client_curses/Makefile b/scripts/anakin_client_curses/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f97ef085b53c809ca0363276bbae66fbf22e6ded --- /dev/null +++ b/scripts/anakin_client_curses/Makefile @@ -0,0 +1,2 @@ +all: + gcc -o client client.c -lcurses diff --git a/scripts/anakin_client_curses/client.c b/scripts/anakin_client_curses/client.c new file mode 100644 index 0000000000000000000000000000000000000000..5c45227bddf8b8aa5ced0341a9cb56e0ce624d63 --- /dev/null +++ b/scripts/anakin_client_curses/client.c @@ -0,0 +1,319 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> +#include <ncurses.h> +#include <signal.h> +#include <stdint.h> +#include <termios.h> +#include <unistd.h> + +volatile int stop = 0; +uint8_t buf[8192] = {0}; +uint16_t rptr = 0, wptr = 0; + +#pragma pack(1) +struct vec3_t { + float x; + float y; + float z; +}; +#pragma pack() + +enum DataType +{ + DATA_VEC3 = 0, + DATA_QUAT = 1, + DATA_FLOAT = 2, + DATA_INT = 3, + DATA_STRING= 4, + DATA_LIMITED_INT = 5, + DATA_UINT32 = 6 +}; + +const char* sensor_names[] = +{ + "ACCEL_MPU9250", + "ACCEL_INEMO", + "ACCEL_MAX21105", + + "GYRO_MPU9250", + "GYRO_INEMO", + "GYRO_FXAS21002", + "GYRO_MAX21105", + + "COMPASS_MPU9250", + "COMPASS_INEMO", + + "TEMP_MPU9250", + "TEMP_INEMO", + "TEMP_LPS331AP", + "TEMP_MAX21105", + "TEMP_MS580", + + "PRESS_LPS331AP", + "PRESS_MS580", + + "UNUSED_16", + "DMA_TX_FIFOSZ", + "DMA_RX_FIFOSZ", + "DMA_FIFO_ERR", + "CPU%", + "LOG_QUEUE_SZ" +}; + +uint8_t sensor_type[] = +{ + DATA_VEC3, + DATA_VEC3, + DATA_VEC3, + + DATA_VEC3, + DATA_VEC3, + DATA_VEC3, + DATA_VEC3, + + DATA_VEC3, + DATA_VEC3, + + DATA_FLOAT, + DATA_FLOAT, + DATA_FLOAT, + DATA_FLOAT, + DATA_FLOAT, + + DATA_FLOAT, + DATA_FLOAT, + + DATA_INT, + DATA_LIMITED_INT, + DATA_LIMITED_INT, + DATA_UINT32, + DATA_UINT32, + DATA_LIMITED_INT +}; + +#define NUM_SENSORS ((int)((sizeof(sensor_names) / sizeof(sensor_names[0])))) + + +void on_signal(int s) +{ + if(!stop) + { + signal(s, on_signal); + stop = 1; + } +} + +int logline = 0; +void log_string(const char* data, int len) +{ + if(len <= 0) + return; + + move(NUM_SENSORS + 2 + logline, 10); + attron(COLOR_PAIR(1)); + printw(data); + if(len < 30) + for(int i=len;i<30;i++) + printw(" "); + refresh(); + logline = (logline+1)%20; +} + +void draw_sensor(int id, int type, const void* data) +{ + char tmp[256] = {0}; + + if(id >= (int)NUM_SENSORS) + { + sprintf(tmp, "Got packet for invalid sensor %d\n", id); + log_string(tmp, strlen(tmp)); + return; + } + + if(type < 0 || type > 6 || type == 4) + { + sprintf(tmp, "Got packet for invalid type %d\n", type); + log_string(tmp, strlen(tmp)); + return; + } + + move(1+id, 10); + sprintf(tmp, "%20s : ", sensor_names[id]); + + uint8_t color = (type != 5) ? (type + 1) : 2; + attron(COLOR_PAIR(color)); + printw(tmp); + attroff(COLOR_PAIR(color)); + + int all_null = 1; + for(int i=0;i<NUM_SENSORS && all_null == 1;i++) + if(((const char *)data)[i] != 0) + all_null = 0; + if((data == NULL || all_null == 1) && type != 5) + { + attron(COLOR_PAIR(5)); + attron(A_BOLD); + printw("[NULL] "); + attroff(A_BOLD); + attroff(COLOR_PAIR(5)); + return; + } + + const uint8_t* i = (const uint8_t*) data; + const struct vec3_t* v = (const struct vec3_t*) data; + const float* f = (const float*) data; + const uint8_t* ui = (const uint8_t*) data; + const uint32_t* ui32 = (const uint32_t*) data; + + switch(type) + { + case DATA_FLOAT: + sprintf(tmp, "%7.4f ", *f); + printw(tmp); + break; + case DATA_INT: + sprintf(tmp, "%d ", *i); + printw(tmp); + break; + case DATA_UINT32: + sprintf(tmp, "%d ", *ui32); + printw(tmp); + break; + case DATA_VEC3: + sprintf(tmp, "(%7.4f, %7.4f, %7.4f)", v->x, v->y, v->z); + printw(tmp); + break; + case DATA_LIMITED_INT: + { + uint32_t vv = (*ui * 27) / 256; + for(uint32_t i=0;i<27;i++) + { + if(i < vv) + printw("#"); + else + printw("."); + } + break; + } + default: + printw("[NOT IMPLEMENTED]"); + break; + } +} + +int sfd; +int init_serial(const char *device) +{ + sfd = open(device, O_RDWR | O_NOCTTY | O_SYNC); + if(sfd < 0) + { + printf("Cannot open ttyUSB0\n"); + return 1; + } + + struct termios tty; + memset(&tty, 0, sizeof(tty)); + if(tcgetattr(sfd, &tty) != 0) + { + printf("Cannot get attributes\n"); + return 1; + } + cfmakeraw(&tty); + cfsetospeed(&tty, B115200); + cfsetispeed(&tty, B115200); + tcsetattr(sfd, TCSANOW, &tty); + + return 0; +} + +void parse(int len) +{ + if(len == 0) + return; + + uint8_t type = buf[0]; + if(type == DATA_STRING) + log_string((const char *)&buf[1], len-1); + else + { + uint8_t id = buf[1]; + draw_sensor(id, type, &buf[2]); + } +} + +int fromHex(char l) +{ + if(l >= '0' && l <= '9') + return l - '0'; + if(l >= 'a' && l <= 'f') + return 10 + l - 'a'; + if(l >= 'A' && l <= 'F') + return 10 + l - 'A'; + return 0; +} + +int read_and_draw() +{ + memset(buf, 0, sizeof(buf)); + int bpos = 0; + char b; + char tmp = 0; + do { + read(sfd, &b, 1); + if(b == '\n' || b == '\r') + break; + else { + if(tmp == 0) + tmp = b; + else { + buf[bpos++] = (fromHex(tmp) << 4) | fromHex(b); + tmp = 0; + } + } + } while(1); + parse(bpos); + return 0; +} + +int main(int argc, char *argv[]) +{ + if(argc < 2) + { + printf("Usage: %s <PORT>\n", argv[0]); + return -1; + } + if(init_serial(argv[1])) + return -1; + + signal(SIGINT, on_signal); + signal(SIGTERM, on_signal); + + initscr(); + start_color(); + init_pair(1, COLOR_BLUE, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_CYAN, COLOR_BLACK); + init_pair(4, COLOR_WHITE, COLOR_BLACK); + init_pair(5, COLOR_RED, COLOR_BLACK); + init_pair(7, COLOR_MAGENTA, COLOR_BLACK); + erase(); + refresh(); + + log_string("Ready...", 8); + while(!stop) + { + if(read_and_draw() == 1) + stop = 1; + refresh(); + } + + endwin(); + + signal(SIGINT, 0); + signal(SIGTERM, 0); + + return 0; +} diff --git a/scripts/start_openocd.sh b/scripts/start_openocd.sh new file mode 100755 index 0000000000000000000000000000000000000000..35c9cf5928227b5f5f2cb9625cc3da087309566d --- /dev/null +++ b/scripts/start_openocd.sh @@ -0,0 +1,2 @@ +#!/bin/bash +openocd -f libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_anakin/anakin.cfg diff --git a/src/entrypoints/anakin-test-dma.cpp b/src/entrypoints/anakin-test-dma.cpp index 47535649e198417bdb076ed5818c94410fd0b0d8..5a130d38f6c4301026cc8b49aef2aaa75e89c4fb 100644 --- a/src/entrypoints/anakin-test-dma.cpp +++ b/src/entrypoints/anakin-test-dma.cpp @@ -32,6 +32,7 @@ void fifoQueueSz(void *arg) { const SPIDriver& spi = SPIDriver::instance(); int tx_accum = 0, rx_accum = 0, sz_ctr = 0; + int qsize_accum = 0; sLog->logString("Thread started"); @@ -44,15 +45,18 @@ void fifoQueueSz(void *arg) { tx_accum += tx; rx_accum += rx; + qsize_accum += sLog->getLogQueueSize(); if(++sz_ctr == 100) { float tx1 = tx_accum / (float)(DFS_100 - DFS_EE + 1) * 255.0f; float rx1 = rx_accum / (float)(DFS_100 - DFS_EE + 1) * 255.0f; - tx_accum = rx_accum = sz_ctr = 0; + float qsz = qsize_accum / 100.0f * 255.0f; + tx_accum = rx_accum = sz_ctr = qsize_accum = 0; sLog->logLimitedInt(17, 0, 255, tx1); sLog->logLimitedInt(18, 0, 255, rx1); sLog->logUInt32(19, spi.getFIFOFaultCtr()); sLog->logUInt32(20, averageCpuUtilization()); + sLog->logLimitedInt(21, 0, 255, qsz); } } Thread::sleep(1); @@ -90,68 +94,5 @@ int main() Thread::sleep(100); } - // NOT EXECUTED - while(1) - { - printf("---------%05d----------\n", ctr++); - for(const auto& s : data) - { - printf("Sensor %03d:", s.sensor); - if(s.value == nullptr) - { - printf("NULLPTR\n"); - continue; - } - - switch(s.data) - { - case DATA_VEC3: - { - const Vec3* d = (const Vec3*) s.value; - printf("(%f,%f,%f)\n", d->getX(), d->getY(), d->getZ()); - break; - } - case DATA_FLOAT: - { - const float* d = (const float*) s.value; - printf("%f\n", *d); - break; - } - case DATA_INT: - { - const int* d = (const int*) s.value; - printf("[%08x]\n", *d); - break; - } - default: - { - printf("Unhandled %d\n", s.data); - break; - } - } - } - printf("-----------------------\n"); - Thread::sleep(10); - } - /* - std::vector<SPIRequest> requests; - requests.push_back( - SPIRequest(CS_MPU9250::getPin(),{0x80 | 0x75, 0, 0, 0, 0, 0, 0, 0, 0}) - ); - - printf("A\n"); - auto& driver=SPIDriver::instance(); - printf("B\n"); - bool ret = driver.transaction(requests); - printf("C: %d\n", ret); - auto result=requests[0].readResponseFromPeripheral(); - printf("D\n"); - memDump(result.data(),result.size()); - printf("E\n"); - */ - - while(1){ - // Yo - } return 0; } diff --git a/src/shared/diagnostic/Log.h b/src/shared/diagnostic/Log.h index 5ee8c80610f73b93ed5e8819fb78a6e84d144b7e..cdde20743bcf8639c8f7ae0718b72cb04c7232d4 100644 --- a/src/shared/diagnostic/Log.h +++ b/src/shared/diagnostic/Log.h @@ -109,6 +109,8 @@ public: queue(std::move(buf)); } + + uint32_t getLogQueueSize() const { return mQueue.size(); } protected: void run() override { diff --git a/src/shared/i2c/stm32f2_f4_i2c.cpp b/src/shared/i2c/stm32f2_f4_i2c.cpp index 2b11eb23447c445ef6358f6552354f5da1ebf96a..6a2fefa5aa1c6664ae26fc34a5e7cde5638db0d7 100644 --- a/src/shared/i2c/stm32f2_f4_i2c.cpp +++ b/src/shared/i2c/stm32f2_f4_i2c.cpp @@ -30,7 +30,7 @@ #include <kernel/scheduler/scheduler.h> #warning -#warning "Integrate this duplicate driver in Miosix, see FIXME.txt +#warning "Integrate this duplicate driver in Miosix, see FIXME.txt" #warning // #define I2C_WITH_DMA