Skip to content

Commit

Permalink
2.11.1 (#7)
Browse files Browse the repository at this point in the history
2.11.1 release. Changes include:

* Fix broken fault reporting
* Add newlines to errorMessages
* Add issue template and contributing message
* Add PROS CLI template generation to automated build
* Implement watchdog timer
* Document watchdog timer and how best to work with it
* Naming fixes and more accurate task timing
* Update Jenkinsfile build
* A new README for a new world
  • Loading branch information
edjubuh authored and jabibi100 committed Mar 31, 2017
1 parent a74bcdb commit 690bd8f
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 1,061 deletions.
22 changes: 22 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributing to PROS

:tada: :+1: :steam_locomotive: Thanks for taking the time to contribute :steam_locomotive: :+1: :tada:

**Did you find a bug?**
- **Verify the bug lies in PROS.** We receive quite a few reports that are due to bugs in user code, not the kernel.
- Ensure the bug wasn't already reported by searching GitHub [issues](https://github.com/purduesigbots/pros/issues)
- If you're unable to find an issue, [open](https://github.com/purduesigbots/pros/issues/new) a new one.

**Did you patch a bug or add a new feature?**
1. [Fork](https://github.com/purduesigbots/pros/fork) and clone the repository
2. Create a new branch: `git checkout -b my-branch-name`
3. Make your changes
4. Push to your fork and submit a pull request.
5. Wait for your pull request to be reviewed. In order to ensure that the PROS kernel is stable, we take extra time to test pull requests. As a result, your pull request may take some time to be merged into master.

Here are a few tips that can help expedite your pull request being accepted:
- Follow existing code's style.
- Document why you made the changes you did
- Keep your change as focused as possible. If you have multiple independent changes, make a pull request for each.
- If you did some testing, describe your procedure and results.
- If you're fixing an issue, reference it by number
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#### Expected Behavior:

#### Actual Behavior:

#### Steps to reproduce:

#### System information:
Kernel Version:

#### Additional Information
40 changes: 40 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
stage('Build') {
def build_ver = '2.11.0'
node('win') {
def venv = new edu.purdue.pros.venv()
stage('Clean') {
if(isUnix()) {
sh 'git init'
sh 'git clean -x -d -f'
} else {
bat 'git init'
bat 'git clean -x -d -f'
}
}
stage('PROS CLI') {
tool 'python3'
if(isUnix()) {
sh 'sudo apt-get install -y python3-pip'
}
venv.create_virtualenv()
venv.run 'pip3 install --no-cache-dir git+git://github.com/purduesigbots/pros-cli.git@master', sudo = true
}
stage('Clone') {
checkout scm
if(isUnix()) {
sh 'git describe --tags > version'
} else {
bat 'git describe --tags > version'
}
build_ver = readFile 'version'
echo "Build PROS at version ${build_ver}"
}
toolchain_dir = tool 'arm-gcc'
withEnv(["PROS_TOOLCHAIN=${toolchain_dir}"]) {
venv.run 'pros conduct first-run --use-defaults --no-download --no-force'
venv.run 'pros make template'
}
zip archive: true, dir: 'template', glob: '', zipFile: "kernel-template.zip"
}
}

19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ CPPSRC:=$(wildcard *.$(CPPEXT))
CPPOBJ:=$(patsubst %.o,$(BINDIR)/%.o,$(CPPSRC:.$(CPPEXT)=.o))
OUT:=$(BINDIR)/$(OUTNAME)

.PHONY: all clean documentation library upload _force_look
.PHONY: all clean documentation library template upload _force_look release develop

# default version just uses the latest tag
VERSION := `git describe --abbrev=0`
release:
$(eval CCFLAGS += -D FW_VERSION="$(VERSION)")

develop:
$(eval VERSION := `git describe --abbrev=1`)
$(eval CCFLAGS += -D FW_VERSION="$(VERSION)")

# By default, compile program
all: $(BINDIR) $(OUT)
Expand All @@ -50,6 +59,14 @@ library: clean $(BINDIR) $(SUBDIRS) $(ASMOBJ) $(COBJ) $(CPPOBJ)
$(MCUPREFIX)ar rvs $(BINDIR)/$(LIBNAME)_sym.a $(BINDIR)/*.o
$(MCUPREFIX)objcopy -S -g --strip-unneeded --keep-symbols public.txt $(BINDIR)/$(LIBNAME)_sym.a $(BINDIR)/$(LIBNAME).a

TEMPLATEFILES:=src/auto.c src/init.c src/opcontrol.c include/API.h include/main.h firmware
template: library
-rm -rf $(addprefix $(ROOT)/template/,$(TEMPLATEFILES))
mkdir -p $(ROOT)/template/src $(ROOT)/template/inlcude $(ROOT)/template/firmware
$(foreach f,$(TEMPLATEFILES),cp -r $(ROOT)/$(f) $(ROOT)/template/$(f); )
cp $(BINDIR)/$(LIBNAME).a $(ROOT)/template/firmware/$(LIBNAME).a
pros conduct create-template kernel $(VERSION) pros-mainline --location $(ROOT)/template -u "firmware/$(LIBNAME).a" -u "include/API.h" -u "common.mk" -i "template.pros"

# Builds the documentation
documentation:
doxygen Doxyfile
Expand Down
1,079 changes: 25 additions & 1,054 deletions README.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions include/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,14 @@ void wait(const unsigned long time);
* @param time the duration of the delay in milliseconds (1 000 milliseconds per second)
*/
void waitUntil(unsigned long *previousWakeTime, const unsigned long time);
/**
* Enables IWDG watchdog timer which will reset the cortex if it locks up due to static shock
* or a misbehaving task preventing the timer to be reset. Not recovering from static shock
* will cause the robot to continue moving its motors indefinitely until turned off manually.
*
* This function should only be called once in initializeIO()
*/
void watchdogInit();

// End C++ extern to C
#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {

#define FW_VERSION_MAJOR "2"
#define FW_VERSION_MINOR "11"
#define FW_VERSION_PATCH "0"
#define FW_VERSION_PATCH "1"

#define FW_VERSION FW_VERSION_MAJOR "." FW_VERSION_MINOR "." FW_VERSION_PATCH

Expand Down
29 changes: 29 additions & 0 deletions include/watchdog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* watchdog.h - IWDG API for reseting the cortex when something goes wrong
*
* Copyright (c) 2011-2016, Purdue University ACM SIGBots.
* All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* PROS contains FreeRTOS (http://www.freertos.org) whose source code may be
* obtained from http://sourceforge.net/projects/freertos/files/ or on request.
*/

#ifndef WATCHDOG_H_
#define WATCHDOG_H_

/*
* Public API Function to enable watchdog.
* Must be called in initializeIO
*/
void watchdogInit();

/*
* Initilaizes the watchdog and feed task if watchdog is enabled
*/
void watchdogStart();

#endif
3 changes: 2 additions & 1 deletion public.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ delayMicroseconds
micros
millis
wait
waitUntil
waitUntil
iwdgEnable
11 changes: 7 additions & 4 deletions src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <periph.h>
#include <supervisor.h>
#include <taskpriv.h>
#include <watchdog.h>

// Low-resolution clock
extern volatile uint32_t _clockLowRes;
Expand All @@ -29,15 +30,15 @@ extern volatile uint32_t _clockLowRes;
// Error messages for _exit
// Since SDIV by 0 is configured not to fault, no divide by 0 can occur here
static const char * const errorMessages[] = {
"Segmentation fault", "Segmentation fault", "Illegal instruction",
"Stack overflow", "System task failure"
"Segmentation fault\n", "Segmentation fault\n", "Illegal instruction\n",
"Stack overflow\n", "System task failure\n"
};
static const char * const crashMessage =
"\r\nThe VEX Cortex has stopped working!\r\nError cause: ";

// _exit - Exits the program with an error message
void __attribute__((noreturn)) _exit(int status) {
char c; const char *buffer = (const char *)crashMessage;
char c; char const * buffer = crashMessage;
__disable_irq();
// No point in safeRobot(), since no interrupts can run and therefore no
// EXTI or SPI interrupts can be used to send state/start user code
Expand All @@ -49,7 +50,7 @@ void __attribute__((noreturn)) _exit(int status) {
}
// Dump message
if ((unsigned int)status < 5U) {
buffer = (const char *)&errorMessages[status];
buffer = errorMessages[status];
while ((c = *buffer++) != 0) {
while (!(USART1->SR & USART_SR_TXE));
USART1->DR = c;
Expand Down Expand Up @@ -120,6 +121,8 @@ void startKernel() {
//__libc_init_array();
// User I/O initialization, really should be empty in most cases
initializeIO();
// Watchdog initialization, resets cortex when it locks up
watchdogStart();
#ifndef NO_FILESYSTEM
// File system scan with the TRIM enabled/disabled
fsScan((csr & RCC_CSR_PORRSTF) ? true : false);
Expand Down
53 changes: 53 additions & 0 deletions src/watchdog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* watchdog.c - IWDG API for reseting the cortex when something goes wrong
*
* Copyright (c) 2011-2016, Purdue University ACM SIGBots.
* All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* PROS contains FreeRTOS (http://www.freertos.org) whose source code may be
* obtained from http://sourceforge.net/projects/freertos/files/ or on request.
*/

#include <stdint.h>
#include <watchdog.h>
#include <task.h>

static bool iwdgEnabled = false;

// iwdgInit - Enables the watchdog
void watchdogInit() {
iwdgEnabled = true;
}

// iwdgFeed - Resets the watchdog's timer
static inline void _iwdgFeed() {
IWDG->KR = 0xAAAA;
}

static void _iwdgTask(void* ud) {
(void)(ud);
clock_t now = timeLowRes();
for (;;) {
_iwdgFeed();
taskDelayUntil(&now, 125);
}
}

// iwdgStart - Initializes the watchdog with a timeout
void watchdogStart() {
// implementation based on STM32 IWDG guidance. (https://goo.gl/sQaIF3)
if (!iwdgEnabled) return;

IWDG->KR = 0x5555; // enable access to iwdg reg (prevents accidental writes into iwdg cofig by runaway code)
IWDG->PR = 2; // prescaler divides low speed internal (LSI) oscillator
IWDG->RLR = 2500; // (timeout * 40) / exp(2, (2 + prescalerCode)) as per specification
IWDG->KR = 0xAAAA; // refresh the watchdog (i.e. load these settings)
IWDG->KR = 0xCCCC; // start the watchdog
_iwdgFeed(); // feed it once and start the task

taskCreate(_iwdgTask, TASK_MINIMAL_STACK_SIZE, NULL, TASK_PRIORITY_DEFAULT);
}
53 changes: 53 additions & 0 deletions template/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Universal C Makefile for MCU targets

# Path to project root (NO trailing slash!)
ROOT=..
# Binary output directory
BINDIR=$(ROOT)/bin
# Subdirectories to include in the build
SUBDIRS=

# Nothing below here needs to be modified by typical users

# Include common aspects of this project
-include $(ROOT)/common.mk

ASMSRC:=$(wildcard *.$(ASMEXT))
ASMOBJ:=$(patsubst %.o,$(BINDIR)/%.o,$(ASMSRC:.$(ASMEXT)=.o))
HEADERS:=$(wildcard *.$(HEXT))
CSRC=$(wildcard *.$(CEXT))
COBJ:=$(patsubst %.o,$(BINDIR)/%.o,$(CSRC:.$(CEXT)=.o))
CPPSRC:=$(wildcard *.$(CPPEXT))
CPPOBJ:=$(patsubst %.o,$(BINDIR)/%.o,$(CPPSRC:.$(CPPEXT)=.o))
OUT:=$(BINDIR)/$(OUTNAME)

.PHONY: all do_subdirs _force_look

# By default, compile program
all: do_subdirs .

# Phony force-look target
_force_look:
@true

# Compiles the program if anything is changed
.: $(SUBDIRS) $(ASMOBJ) $(COBJ) $(CPPOBJ)
@touch .

# Builds the subdirectories
do_subdirs: _force_look
@for dir in $(SUBDIRS); do $(MAKE) --no-print-directory -C $$dir || exit 1; done

# Assembly source file management
$(ASMOBJ): $(BINDIR)/%.o: %.$(ASMEXT)
@echo AS $<
@$(AS) $(AFLAGS) -o $@ $<

# Object management
$(COBJ): $(BINDIR)/%.o: %.$(CEXT) $(HEADERS)
@echo CC $(INCLUDE) $<
@$(CC) $(INCLUDE) $(CFLAGS) -o $@ $<

$(CPPOBJ): $(BINDIR)/%.o: %.$(CPPEXT) $(HEADERS)
@echo CPC $(INCLUDE) $<
@$(CPPCC) $(INCLUDE) $(CPPFLAGS) -o $@ $<
47 changes: 47 additions & 0 deletions template/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Universal C Makefile for MCU targets
# Top-level template file to configure build

MAKE_COMMAND=make

# Makefile for IFI VeX Cortex Microcontroller (STM32F103VD series)
DEVICE=VexCortex
# Libraries to include in the link (use -L and -l) e.g. -lm, -lmyLib
LIBRARIES=$(wildcard $(ROOT)/firmware/*.a) -lgcc -lm
# Prefix for ARM tools (must be on the path)
MCUPREFIX=arm-none-eabi-
# Flags for the assembler
MCUAFLAGS=-mthumb -mcpu=cortex-m3 -mlittle-endian
# Flags for the compiler
MCUCFLAGS=-mthumb -mcpu=cortex-m3 -mlittle-endian -mfloat-abi=soft
# Flags for the linker
MCULFLAGS=-nostartfiles -Wl,-static -Bfirmware -Wl,-u,VectorTable -Wl,-T -Xlinker firmware/cortex.ld
# Prepares the elf file by converting it to a binary that java can write
MCUPREPARE=$(OBJCOPY) $(OUT) -O binary $(BINDIR)/$(OUTBIN)
# Advanced sizing flags
SIZEFLAGS=
# Uploads program using java
UPLOAD=@java -jar firmware/uniflash.jar vex $(BINDIR)/$(OUTBIN)

# Advanced options
ASMEXT=s
CEXT=c
CPPEXT=cpp
HEXT=h
INCLUDE=-I$(ROOT)/include -I$(ROOT)/src
OUTBIN=output.bin
OUTNAME=output.elf

# Flags for programs
AFLAGS:=$(MCUAFLAGS)
ARFLAGS:=$(MCUCFLAGS)
CCFLAGS:=-c -Wall $(MCUCFLAGS) -Os -ffunction-sections -fsigned-char -fomit-frame-pointer -fsingle-precision-constant
CFLAGS:=$(CCFLAGS) -std=gnu99 -Werror=implicit-function-declaration
CPPFLAGS:=$(CCFLAGS) -fno-exceptions -fno-rtti -felide-constructors
LDFLAGS:=-Wall $(MCUCFLAGS) $(MCULFLAGS) -Wl,--gc-sections

# Tools used in program
AR:=$(MCUPREFIX)ar
AS:=$(MCUPREFIX)as
CC:=$(MCUPREFIX)gcc
CPPCC:=$(MCUPREFIX)g++
OBJCOPY:=$(MCUPREFIX)objcopy

0 comments on commit 690bd8f

Please sign in to comment.