Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from yorkaerospace/nofs
Browse files Browse the repository at this point in the history
Nofs
  • Loading branch information
ProtonNumber authored Nov 5, 2022
2 parents 578f81b + f9cb72c commit 72234ca
Show file tree
Hide file tree
Showing 18 changed files with 324 additions and 56 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "kicad/YAR-Kicad-Libs"]
path = kicad/YAR-Kicad-Libs
url = https://github.com/yorkaerospace/YAR-Kicad-Libs.git
[submodule "firmware/lib/spiffs"]
path = firmware/lib/spiffs
url = https://github.com/ProtonNumber/spiffs-pico.git
1 change: 1 addition & 0 deletions drivers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
log.csv
10 changes: 10 additions & 0 deletions drivers/readData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Takes data from the bob and yheets it into a file.
# Usage: readData <tty> <destination>

echo "r" -> $1;
stdbuf -o0 cat $1 >> $2

sed -i '/?/d' $2
sed -i '/^$/d' $2
7 changes: 6 additions & 1 deletion firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ set(sources src/main.c
src/cmd.c
src/cmd.h
src/ansi.h
src/states.h
src/sensors.c
src/sensors.h
src/logger.c
src/logger.h
src/dataBuf.c
src/dataBuf.h)

add_executable(Bob
src/main.c
src/cmd.c
src/sensors.c
src/logger.c
src/dataBuf.c
)

add_subdirectory(lib)

target_link_libraries(Bob QMI8658C HP203B QMC5883L pico_stdlib pico_multicore hardware_i2c PICO_SPIFFS)
target_link_libraries(Bob QMI8658C HP203B QMC5883L pico_stdlib pico_multicore hardware_i2c)

pico_enable_stdio_usb(Bob 1)

pico_add_extra_outputs(Bob)

pico_set_binary_type(Bob copy_to_ram)
2 changes: 1 addition & 1 deletion firmware/genBin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cd $SCRIPT_DIR
git submodule init
git submodule update

CMAKE_ARGS="-DPICO_BOARD=bob -DPICO_BOARD_HEADER_DIRS=$SCRIPT_DIR/src $@"
CMAKE_ARGS="-DPICO_BOARD=bob -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DPICO_BOARD_HEADER_DIRS=$SCRIPT_DIR/src $@"

mkdir -p bin

Expand Down
1 change: 0 additions & 1 deletion firmware/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
add_subdirectory(hp203b)
add_subdirectory(qmc5883l)
add_subdirectory(qmi8658c)
add_subdirectory(spiffs)
1 change: 0 additions & 1 deletion firmware/lib/spiffs
Submodule spiffs deleted from 397170
6 changes: 6 additions & 0 deletions firmware/src/ansi.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define MOV_EC(n) "\x1b[0K\x1b[999C\x1b[" #n "D"
// Moves the cursor to row, column
#define MOV(r, c) "\x1b[" #r ":" #c "H"
// Moves the cursor to column c
#define CHA(c) "\x1b[" #c "G"
// Clears from the cursor to the end of the line. Inserts a newline.
#define CLRLN "\x1b[0k\n"
// Sets text to be rendered neither bold nor faint
Expand All @@ -17,4 +19,8 @@
#define GREEN "\x1b[32;1m"
#define BLUE "\x1b[34;1m"

// Save and restore cursor positions
#define SCP "\x1b[s"
#define RCP "\x1b[u"

#endif
4 changes: 2 additions & 2 deletions firmware/src/bob.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Header file containing bob-specific constants
* This overrides a lot of things that the SDK sets by default
/* Header file containing bob-specific constants
* This overrides a lot of things that the SDK sets by default
* You dont have to include this in any code you write; the SDK
* should include it by default. */
#ifndef BOB_H
Expand Down
47 changes: 44 additions & 3 deletions firmware/src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "dataBuf.h"
#include "ansi.h"
#include "logger.h"

// How fast should updatey bits be updated?
#define UPDATE_PERIOD 200
Expand Down Expand Up @@ -79,22 +80,56 @@ static void debugPrint(void) {
latest.mag[0], latest.mag[1], latest.mag[2], goStr[2],
latest.pres, temp, goStr[3]);

if (getchar_timeout_us(0) != PICO_ERROR_TIMEOUT) {
break;
}
sleep_ms(UPDATE_PERIOD);

}

clearTTY();
showCursor(true);
}

static void manualLogger(void) {
int n = 0;
printf("Press any key to stop logging. \n");
while(getchar_timeout_us(0) == PICO_ERROR_TIMEOUT) {
n = n + writeAll();
//printf( NORM "Structs written: %d\n", n);
}
printf("\nExiting Logging!\n");
}

static void clearPrompt(void) {
printf(NORM
"Are you sure you wish to clear the flash? "
"["GREEN "Y" WHITE "/" RED "N" WHITE "]\n"
NORM);
switch(getchar_timeout_us(30000000)){
case PICO_ERROR_TIMEOUT:
printf("Timed out due to lack of response, please try again\n");
break;
case 'y':
printf("Clearing flash. (This may take a while) \n");
clearData();
printf("Done!\n");
break;
}
}


/* Polls stdin and interprets what it gets. */
void pollUsb(void) {
static const char helpText[] =
"Bob Rev 3 running build: %s %s\n"
"Press:\n"
"b to enter bootsel mode\n"
"c to clear this tty\n"
"c to clear the contents of the flash\n"
"d to show the debug prompt\n"
"h to display this help text\n";
"h to display this help text\n"
"l to start manual logging\n"
"r to read files\n";

switch(getchar_timeout_us(0)) {
case PICO_ERROR_TIMEOUT: // If there is no char, just break.
Expand All @@ -104,14 +139,20 @@ void pollUsb(void) {
reset_usb_boot(0,0);
break;
case 'c':
clearTTY();
clearPrompt();
break;
case 'd':
debugPrint();
break;
case 'h':
printf(helpText, __TIME__, __DATE__);
break;
case 'l':
manualLogger();
break;
case 'r':
dumpLogs();
break;
default:
printf("?\n");
break;
Expand Down
28 changes: 15 additions & 13 deletions firmware/src/dataBuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@

#include "dataBuf.h"


// Simple circular buffer.
static volatile data_t dataBuf[BUF_SIZE];
static volatile uint16_t tail = 0;
static volatile uint16_t head = 0;

auto_init_mutex(mtx);
auto_init_mutex(bufMtx);

/* Increments an index with looping */
static inline uint16_t incIndex(uint16_t i) {
Expand All @@ -36,7 +35,7 @@ static inline uint16_t incIndex(uint16_t i) {
* 1 if data has been overwritten */
int8_t dataPush(data_t d){
int8_t res;
if(mutex_enter_timeout_ms(&mtx, BUF_TIMEOUT)) {
if(mutex_enter_timeout_ms(&bufMtx, BUF_TIMEOUT)) {
head = incIndex(head);
dataBuf[head] = d;
// Increment tail if we've overwritten data
Expand All @@ -46,7 +45,7 @@ int8_t dataPush(data_t d){
} else {
res = 0;
}
mutex_exit(&mtx);
mutex_exit(&bufMtx);
return res;
} else {
return -1;
Expand All @@ -56,8 +55,8 @@ int8_t dataPush(data_t d){
/* Returns the amount of data in the buffer */
uint16_t dataSize(void) {
return head >= tail ?
head - tail :
BUF_SIZE - (tail - head);
head - tail - 1:
BUF_SIZE - (tail - head) - 1;
}

/* Pops a piece of data from the end of the buffer
Expand All @@ -66,28 +65,31 @@ uint16_t dataSize(void) {
* 0 if successful
* -1 if no data is in the buffer */
int8_t dataPop(data_t * ptr) {
mutex_enter_blocking(&mtx);
if(head == tail + 1) {
printf("Entering mutex\n");
mutex_enter_blocking(&bufMtx);
printf("%d, %d \n", head, tail);
if(head == incIndex(tail)) {
mutex_exit(&bufMtx);
return -1;
} else {
*ptr = dataBuf[tail];
tail = incIndex(tail);
mutex_exit(&mtx);
mutex_exit(&bufMtx);
return 0;
}
}

/* Gets the data at the head of the buffer
* Blocks indefinitely. */
void dataHead(data_t * ptr) {
mutex_enter_blocking(&mtx);
mutex_enter_blocking(&bufMtx);
*ptr = dataBuf[head];
mutex_exit(&mtx);
mutex_exit(&bufMtx);
}

/* Gets the data that was offset samples ago */
void dataRel(data_t * ptr, size_t offset) {
mutex_enter_blocking(&mtx);
mutex_enter_blocking(&bufMtx);
*ptr = dataBuf[(head - offset) % BUF_SIZE];
mutex_exit(&mtx);
mutex_exit(&bufMtx);
}
2 changes: 1 addition & 1 deletion firmware/src/dataBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "sensors.h"

// A 10 second buffer should be ~30 kB
#define BUF_SIZE 10 * 100
#define BUF_SIZE (10 * 100)
#define BUF_TIMEOUT 1

/* Pushes a piece of data into the buffer.
Expand Down
Loading

0 comments on commit 72234ca

Please sign in to comment.