Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 Use unity build #715

Draft
wants to merge 11 commits into
base: develop-pros-4
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ temp.errors
.clangd/
.cache/
.DS_Store
/amalgamate-src/*
23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ BINDIR=$(ROOT)/bin
SRCDIR=$(ROOT)/src
INCDIR=$(ROOT)/include
EXTRA_INCDIR=$(FWDIR)/libv5rts/sdk/vexv5/patched_include
AMALGAMATE_SRCDIR=$(ROOT)/amalgamate-src

# Directories to be excluded from all builds
EXCLUDE_SRCDIRS+=$(SRCDIR)/tests
Expand Down Expand Up @@ -46,26 +47,38 @@ TEMPLATE_FILES+= $(ROOT)/template-gitignore

PATCHED_SDK=$(FWDIR)/libv5rts/sdk/vexv5/libv5rts.patched.a

ifndef NO_AMALGAMATE
SRCDIR=$(AMALGAMATE_SRCDIR)
endif

EXTRA_LIB_DEPS=$(INCDIR)/api.h $(PATCHED_SDK)

################################################################################
################################################################################
########## Nothing below this line should be edited by typical users ###########
-include ./common.mk

.PHONY: $(INCDIR)/api.h patch_sdk_headers clean
$(INCDIR)/api.h: version.py
.PHONY: $(INCDIR)/pros/version.h patch_sdk_headers amalgamate clean
$(INCDIR)/pros/version.h: version.py
$(VV)python version.py

amalgamate: amalgamate.py
ifndef NO_AMALGAMATE
@echo "Amalgamating src files"
$(VV)python amalgamate.py
$(VV)cp src/main.cpp amalgamate-src/main.cpp
endif

patch_sdk_headers: patch_headers.py
@echo "Patching SDK headers"
$(VV)python patch_headers.py

# Override clean, necessary to remove patched sdk on clean
clean:
clean::
@echo "Cleaning patched SDK"
@rm -f $(PATCHED_SDK)
@rm -rf $(EXTRA_INCDIR)
@rm -rf $(AMALGAMATE_SRCDIR)

$(PATCHED_SDK): $(FWDIR)/libv5rts/sdk/vexv5/libv5rts.a
$(call test_output_2,Stripping unwanted symbols from libv5rts.a ,$(STRIP) $^ @libv5rts-strip-options.txt -o $@, $(DONE_STRING))
Expand All @@ -75,7 +88,7 @@ CREATE_TEMPLATE_ARGS+=--user "src/main.{cpp,c,cc}" --user "include/main.{hpp,h,h
CREATE_TEMPLATE_ARGS+=--target v5
CREATE_TEMPLATE_ARGS+=--output bin/monolith.bin --cold_output bin/cold.package.bin --hot_output bin/hot.package.bin --cold_addr 58720256 --hot_addr 125829120

template: patch_sdk_headers clean-template library
template: patch_sdk_headers amalgamate clean-template library
$(VV)mkdir -p $(TEMPLATE_DIR)
@echo "Moving template files to $(TEMPLATE_DIR)"
$Dif [ $(shell uname -s) == "Darwin" ]; then \
Expand All @@ -91,7 +104,7 @@ template: patch_sdk_headers clean-template library
$Dpros c create-template $(TEMPLATE_DIR) kernel $(shell cat $(ROOT)/version) $(CREATE_TEMPLATE_ARGS)

LIBV5RTS_EXTRACTION_DIR=$(BINDIR)/libv5rts
$(LIBAR): patch_sdk_headers $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)) $(EXTRA_LIB_DEPS)
$(LIBAR): patch_sdk_headers amalgamate $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)) $(EXTRA_LIB_DEPS)
$(VV)mkdir -p $(LIBV5RTS_EXTRACTION_DIR)
$(call test_output_2,Extracting libv5rts ,cd $(LIBV5RTS_EXTRACTION_DIR) && $(AR) x ../../$(PATCHED_SDK),$(DONE_STRING))
$(eval LIBV5RTS_OBJECTS := $(shell $(AR) t $(PATCHED_SDK)))
Expand Down
49 changes: 49 additions & 0 deletions amalgamate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from os import listdir, makedirs, walk
from os.path import isfile, join, exists, dirname, realpath, splitext

def print_and_exit(message):
print(message)
print("Failed to amalgamate files")
exit(1)

# get the current directory
try:
current_dir = dirname(realpath(__file__))
except:
print_and_exit("Could not get working directory!")

src_dir = current_dir + "/src"
amalgamate_src_dir = current_dir + "/amalgamate-src"

if not exists(amalgamate_src_dir):
try:
makedirs(amalgamate_src_dir)
except:
print_and_exit("Could not create directory for amalgamation!")

c_src_files = [join(dp, f) for dp, dn, filenames in walk(f"{current_dir}/src") for f in filenames if
splitext(f)[1].lower() == '.c']
cpp_src_files = [join(dp, f) for dp, dn, filenames in walk(f"{current_dir}/src") for f in filenames if
splitext(f)[1].lower() == '.cpp']

with open(amalgamate_src_dir + "/amalgamate.c", "w") as dest:
for c_file in c_src_files:
if "/test/" in c_file:
continue
with open(c_file) as f:
contents = f.read()
dest.write(f"#line 1 \"{c_file}\"\n")
dest.write(contents + "\n")

with open(amalgamate_src_dir + "/amalgamate.cpp", "w") as dest:
for cpp_file in cpp_src_files:
if "/test/" in cpp_file or "main.cpp" in cpp_file:
continue
with open(cpp_file) as f:
contents = f.read()
dest.write(f"#line 1 \"{cpp_file}\"\n")
dest.write(contents + "\n")

with open(amalgamate_src_dir + "/main.cpp", "w") as dest:
with open(src_dir + "/main.cpp", "r") as src:
dest.write(src.read())
4 changes: 2 additions & 2 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ quick: $(DEFAULT_BIN)

all: clean $(DEFAULT_BIN)

clean:
clean::
@echo Cleaning project
-$Drm -rf $(BINDIR)
-$Drm -rf $(DEPDIR)
Expand Down Expand Up @@ -262,7 +262,7 @@ $(foreach asmext,$(ASMEXTS),$(eval $(call asm_rule,$(asmext))))

define c_rule
$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1
$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 $(DEPDIR)/$(basename $1).d
$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 $(DEPDIR)/$(basename %).d
$(VV)mkdir -p $$(dir $$@)
$(MAKEDEPFOLDER)
$$(call test_output_2,Compiled $$< ,$(CC) -c $(INCLUDE) -iquote"$(INCDIR)/$$(dir $$*)" $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAGS) -o $$@ $$<,$(OK_STRING))
Expand Down
7 changes: 0 additions & 7 deletions include/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@
#include <unistd.h>
#endif /* __cplusplus */

#define PROS_VERSION_MAJOR 4
#define PROS_VERSION_MINOR 1

#define PROS_VERSION_PATCH 0
#define PROS_VERSION_STRING "4.1.0"


#include "pros/adi.h"
#include "pros/colors.h"
#include "pros/device.h"
Expand Down
14 changes: 7 additions & 7 deletions include/pros/apix.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef void* sem_t;
* task_abort_delay(task);
* \endcode
*/
bool task_abort_delay(task_t task);
int32_t task_abort_delay(task_t task);

/**
* Notify a task when a target task is being deleted.
Expand Down Expand Up @@ -152,7 +152,7 @@ mutex_t mutex_recursive_create(void);
*
* \endcode
*/
bool mutex_recursive_take(mutex_t mutex, uint32_t timeout);
uint8_t mutex_recursive_take(mutex_t mutex, uint32_t timeout);

/**
* Gives a recursive mutex.
Expand All @@ -179,7 +179,7 @@ bool mutex_recursive_take(mutex_t mutex, uint32_t timeout);
*
* \endcode
*/
bool mutex_recursive_give(mutex_t mutex);
uint8_t mutex_recursive_give(mutex_t mutex);

/**
* Returns a handle to the current owner of a mutex.
Expand Down Expand Up @@ -360,7 +360,7 @@ sem_t sem_binary_create(void);
* }
* \endcode
*/
bool sem_wait(sem_t sem, uint32_t timeout);
uint8_t sem_wait(sem_t sem, uint32_t timeout);

/**
* Increments a semaphore's value.
Expand Down Expand Up @@ -390,7 +390,7 @@ bool sem_wait(sem_t sem, uint32_t timeout);
*
* \endcode
*/
bool sem_post(sem_t sem);
uint8_t sem_post(sem_t sem);

/**
* Returns the current value of the semaphore.
Expand Down Expand Up @@ -524,7 +524,7 @@ bool queue_append(queue_t queue, const void* item, uint32_t timeout);
* }
* \endcode
*/
bool queue_peek(queue_t queue, void* const buffer, uint32_t timeout);
int32_t queue_peek(queue_t queue, void* const buffer, uint32_t timeout);

/**
* Receive an item from the queue.
Expand Down Expand Up @@ -555,7 +555,7 @@ bool queue_peek(queue_t queue, void* const buffer, uint32_t timeout);
* }
* \endcode
*/
bool queue_recv(queue_t queue, void* const buffer, uint32_t timeout);
int32_t queue_recv(queue_t queue, void* const buffer, uint32_t timeout);

/**
* Return the number of messages stored in a queue.
Expand Down
33 changes: 33 additions & 0 deletions include/pros/optical.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,39 @@ int32_t optical_enable_gesture(uint8_t port);
*/
int32_t optical_disable_gesture(uint8_t port);

/**
* Get integration time (update rate) of the optical sensor in milliseconds, with
* minimum time being
*
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of V5 ports (1-21).
* ENODEV - The port cannot be configured as an Optical Sensor
*
* \param port
* The V5 Optical Sensor port number from 1-21
* \return Integration time in milliseconds if the operation is successful
* or PROS_ERR if the operation failed, setting errno.
*/
double optical_get_integration_time(uint8_t port);

/**
* Set integration time (update rate) of the optical sensor in milliseconds.
*
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of V5 ports (1-21).
* ENODEV - The port cannot be configured as an Optical Sensor
*
* \param port
* The V5 Optical Sensor port number from 1-21
* \param time
* The desired integration time in milliseconds
* \return 1 if the operation is successful or PROS_ERR if the operation failed,
* setting errno.
*/
int32_t optical_set_integration_time(uint8_t port, double time);

///@}

///@}
Expand Down
30 changes: 30 additions & 0 deletions include/pros/optical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,36 @@ class Optical : public Device {
*/
virtual std::int32_t disable_gesture();

/**
* Set integration time (update rate) of the optical sensor in milliseconds, with
* minimum time being 3 ms and maximum time being 712 ms. Default is 100 ms, with the
* optical sensor communciating with the V5 brain every 20 ms.
*
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of V5 ports (1-21).
* ENODEV - The port cannot be configured as an Optical Sensor
*
* \return 1 if the operation is successful or PROS_ERR_F if the operation failed,
* setting errno.
*/
double get_integration_time();

/**
* Get integration time (update rate) of the optical sensor in milliseconds.
*
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of V5 ports (1-21).
* ENODEV - The port cannot be configured as an Optical Sensor
*
* \param time
* The desired integration time in milliseconds
* \return Integration time in milliseconds if the operation is successful
* or PROS_ERR if the operation failed, setting errno.
*/
std::int32_t set_integration_time(double time);

/**
* This is the overload for the << operator for printing to streams
*
Expand Down
9 changes: 6 additions & 3 deletions include/pros/rtos.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ typedef void (*task_fn_t)(void*);
/**
* The state of a task.
*/
#ifndef PROS_TASK_ENUMS_DEFINED
#define PROS_TASK_ENUMS_DEFINED
typedef enum {
E_TASK_STATE_RUNNING = 0, /**< The task is actively executing. */
E_TASK_STATE_READY, /**< The task exists and is available to run, but is not currently running. */
Expand All @@ -135,6 +137,7 @@ typedef enum {
E_NOTIFY_ACTION_OWRITE, /**< The task’s notification value will be unconditionally set to the new value.*/
E_NOTIFY_ACTION_NO_OWRITE /**< The task’s notification value will be set to the new value if the task does not already have a pending notification.*/
} notify_action_e_t;
#endif // PROS_TASK_ENUMS_DEFINED

/// @} Name: Enumerations

Expand Down Expand Up @@ -660,7 +663,7 @@ task_t task_get_current();
* }
* \endcode
*/
uint32_t task_notify(task_t task);
int32_t task_notify(task_t task);

/**
*
Expand Down Expand Up @@ -743,7 +746,7 @@ void task_join(task_t task);
* }
* \endcode
*/
uint32_t task_notify_ext(task_t task, uint32_t value, notify_action_e_t action, uint32_t* prev_value);
int32_t task_notify_ext(task_t task, uint32_t value, notify_action_e_t action, uint32_t* prev_value);

/**
* Waits for a notification to be nonzero.
Expand Down Expand Up @@ -820,7 +823,7 @@ uint32_t task_notify_take(bool clear_on_exit, uint32_t timeout);
* }
* \endcode
*/
bool task_notify_clear(task_t task);
int32_t task_notify_clear(task_t task);

/**
* Creates a mutex.
Expand Down
23 changes: 23 additions & 0 deletions include/pros/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* \file version.h
*
* PROS Version Information
*
* Contains PROS kernel version information
*
*
* \copyright Copyright (c) 2017-2023, 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/.
*/

#pragma once

#define PROS_VERSION_MAJOR 4
#define PROS_VERSION_MINOR 1

#define PROS_VERSION_PATCH 0
#define PROS_VERSION_STRING "4.1.0"
4 changes: 4 additions & 0 deletions include/rtos/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ typedef void * task_t;
*/
typedef int32_t (*TaskHookFunction_t)( void * );


#ifndef PROS_TASK_ENUMS_DEFINED
#define PROS_TASK_ENUMS_DEFINED
/* Task states returned by task_get_state. */
typedef enum
{
Expand All @@ -87,6 +90,7 @@ typedef enum
E_NOTIFY_ACTION_OWRITE, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
E_NOTIFY_ACTION_NO_OWRITE /* Set the task's notification value if the previous value has been read by the task. */
} notify_action_e_t;
#endif // PROS_TASK_ENUMS_DEFINED

/*
* Used internally only.
Expand Down
9 changes: 9 additions & 0 deletions include/system/hot.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ struct hot_table {
} functions;
};

// exidx is the table that tells the unwinder how to unwind a stack frame
// for a PC. Under hot/cold, there's two tables and the unwinder was kind
// enough to let us implement a function to give it a table for a PC so
// support for hot/cold is as easy as it gets
struct __EIT_entry {
_uw fnoffset;
_uw content;
};

extern struct hot_table* const HOT_TABLE;
Loading
Loading