Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ firmware/tinyg/default/path
firmware/tinyg/Release/Makefile
firmware/tinyg/Release/makedep.mk
firmware/tinyg/default/path
build
tinyg.hex
51 changes: 51 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/lib/avr/include/**",
"/usr/lib/gcc/avr/5.4.0/include/**"
],
"defines": [
"__AVR",
"__DOXYGEN__",
"__AVR_ATxmega192A3__",
"AS_5600_ENCODER"
],
"compilerPath": "/usr/bin/avr-gcc",
"cStandard": "c17",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
"-mmcu=atmega192a3",
"-DF_CPU=16000000UL",
"-Os"
]
},
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/Cellar/avr-gcc@12/12.2.0_2/avr/include/**"
],
"defines": [
"__AVR",
"__DOXYGEN__",
"__AVR_ATxmega192A3__",
"AS_5600_ENCODER"
],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/opt/homebrew/opt/avr-gcc@12/bin/avr-gcc",
"cStandard": "c17",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
"-mmcu=atmega192a3",
"-DF_CPU=16000000UL",
"-Os"
]
}
],
"version": 4
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files.associations": {
"tinyg.h": "c",
"xio.h": "c",
"encoder.h": "c"
},
"cmake.sourceDirectory": "/home/rvalls/dev/personal/TinyG-openpnp/firmware/tinyg"
}
31 changes: 31 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"targets": [
"all"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
],
"detail": "CMake template build task"
}
],
"inputs": [
{
"type": "pickString",
"id": "makeTarget", "description": "Select a build target",
"options": [
"make -j $(nprocs)"
],
"default": "make -j $(nprocs)"
}
]
}
1 change: 1 addition & 0 deletions firmware/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
*.srec
*.aws
*.atsuo
build
.DS_Store
TcfTransactionLog.csv
1 change: 1 addition & 0 deletions firmware/tinyg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
95 changes: 95 additions & 0 deletions firmware/tinyg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 3.10)

set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
project(tinyg VERSION 0.1.0)

unset(_CMAKE_APPLE_ARCHS_DEFAULT)
set(CMAKE_C_COMPILER avr-gcc)

add_executable(tinyg.elf
canonical_machine.c
config.c
config_app.c
controller.c
cycle_homing.c
cycle_jogging.c
cycle_probing.c
encoder.c
encoder_as5600.c
gcode_parser.c
gpio.c
hardware.c
help.c
json_parser.c
kinematics.c
main.c
network.c
persistence.c
planner.c
plan_arc.c
plan_exec.c
plan_line.c
plan_zoid.c
pwm.c
report.c
spindle.c
stepper.c
switch.c
test.c
text_parser.c
util.c
xio.c
xio/xio_file.c
xio/xio_pgm.c
xio/xio_rs485.c
xio/xio_spi.c
xio/xio_usart.c
xio/xio_usb.c
xmega/xmega_adc.c
xmega/xmega_eeprom.c
xmega/xmega_init.c
xmega/xmega_interrupts.c
xmega/xmega_rtc.c
xmega/xmega_twi.c
)

target_compile_definitions(tinyg.elf PRIVATE
F_CPU=32000000UL
M115_BUILD_SYSTEM_STRING=", X-BUILD_SYSTEM:CMake"
)
target_compile_options(tinyg.elf PRIVATE
-mmcu=atxmega192a3
-O2 -g2 -Wall
-funsigned-char
-funsigned-bitfields
-fno-align-functions
-fno-align-jumps
-fno-align-loops
-fno-align-labels
-fno-reorder-blocks
-fno-reorder-blocks-and-partition
-fno-prefetch-loop-arrays
-fno-tree-vect-loop-version
-ffunction-sections
-fdata-sections
-fpack-struct
-fshort-enums
)

if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 12.0)
if (CMAKE_C_COMPILER_VERSION VERSION_LESS_EQUAL 13.0)
message(STATUS "Addding workaround for avr-gcc 12 bug")
target_compile_options(tinyg.elf PRIVATE
--param=min-pagesize=0
)
endif()
endif()

target_link_options(tinyg.elf PRIVATE -mmcu=atxmega192a3)

add_custom_command(
TARGET tinyg.elf
POST_BUILD
COMMAND avr-objcopy
ARGS -O ihex $<TARGET_FILE:tinyg.elf> ${PROJECT_BINARY_DIR}/tinyg.hex
)
6 changes: 5 additions & 1 deletion firmware/tinyg/canonical_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,14 @@ stat_t cm_get_adc()
return (STAT_OK);
}

#ifndef M115_BUILD_SYSTEM_STRING
#define M115_BUILD_SYSTEM_STRING ""
#endif

stat_t cm_get_firmware()
{
// M115: Get Firmware Version and Capabilities, see https://www.reprap.org/wiki/G-code#M115:_Get_Firmware_Version_and_Capabilities.
static const char m115_response[] PROGMEM = "FIRMWARE_NAME:TinyG, FIRMWARE_URL:https%%3A//github.com/synthetos/TinyG, FIRMWARE_VERSION:%0.2f, FIRMWARE_BUILD:%0.2f, HARDWARE_PLATFORM:%0.2f, HARDWARE_VERSION:%0.2f\n";
static const char m115_response[] PROGMEM = "FIRMWARE_NAME:TinyG, FIRMWARE_URL:https%%3A//github.com/synthetos/TinyG, FIRMWARE_VERSION:%0.2f, FIRMWARE_BUILD:%0.2f, HARDWARE_PLATFORM:%0.2f, HARDWARE_VERSION:%0.2f, MACHINE_TYPE:OpenPnP" M115_BUILD_SYSTEM_STRING "\n";
fprintf_P(stderr, m115_response, cs.fw_version, cs.fw_build, cs.hw_platform, cs.hw_version);
return (STAT_OK);
}
Expand Down
111 changes: 56 additions & 55 deletions firmware/tinyg/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This file is part of the TinyG project
*
* Copyright (c) 2010 - 2015 Alden S. Hart, Jr.
* Copyright (c) 2013 - 2015 Robert Giseburt
* Copyright (c) 2013 - 2015 Robert Giseburt
*
* This file ("the software") is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 as published by the
Expand Down Expand Up @@ -36,7 +36,7 @@
#include "plan_arc.h"
#include "planner.h"
#include "stepper.h"

#include "encoder.h"
#include "hardware.h"
#include "switch.h"
Expand Down Expand Up @@ -146,7 +146,7 @@ void controller_run()
_controller_HSM();
}
}

#define DISPATCH(func) if (func == STAT_EAGAIN) return;
static void _controller_HSM()
{
Expand Down Expand Up @@ -200,54 +200,54 @@ static void _controller_HSM()

static stat_t _command_dispatch()
{
#ifdef __AVR
stat_t status;

// read input line or return if not a completed line
// xio_gets() is a non-blocking workalike of fgets()
while (true) {
if ((status = xio_gets(cs.primary_src, cs.in_buf, sizeof(cs.in_buf))) == STAT_OK) {
cs.bufp = cs.in_buf;
break;
}
// handle end-of-file from file devices
if (status == STAT_EOF) { // EOF can come from file devices only
if (cfg.comm_mode == TEXT_MODE) {
fprintf_P(stderr, PSTR("End of command file\n"));
} else {
rpt_exception(STAT_EOF); // not really an exception
}
tg_reset_source(); // reset to default source
}
return (status); // Note: STAT_EAGAIN, errors, etc. will drop through
}
#endif // __AVR
#ifdef __ARM
// detect USB connection and transition to disconnected state if it disconnected
if (SerialUSB.isConnected() == false) cs.state = CONTROLLER_NOT_CONNECTED;

// read input line and return if not a completed line
if (cs.state == CONTROLLER_READY) {
if (read_line(cs.in_buf, &cs.read_index, sizeof(cs.in_buf)) != STAT_OK) {
cs.bufp = cs.in_buf;
return (STAT_OK); // This is an exception: returns OK for anything NOT OK, so the idler always runs
}
} else if (cs.state == CONTROLLER_NOT_CONNECTED) {
if (SerialUSB.isConnected() == false) return (STAT_OK);
cm_request_queue_flush();
rpt_print_system_ready_message();
cs.state = CONTROLLER_STARTUP;

} else if (cs.state == CONTROLLER_STARTUP) { // run startup code
cs.state = CONTROLLER_READY;

} else {
return (STAT_OK);
}
cs.read_index = 0;
#ifdef __AVR
stat_t status;
// read input line or return if not a completed line
// xio_gets() is a non-blocking workalike of fgets()
while (true) {
if ((status = xio_gets(cs.primary_src, cs.in_buf, sizeof(cs.in_buf))) == STAT_OK) {
cs.bufp = cs.in_buf;
break;
}
// handle end-of-file from file devices
if (status == STAT_EOF) { // EOF can come from file devices only
if (cfg.comm_mode == TEXT_MODE) {
fprintf_P(stderr, PSTR("End of command file\n"));
} else {
rpt_exception(STAT_EOF); // not really an exception
}
tg_reset_source(); // reset to default source
}
return (status); // Note: STAT_EAGAIN, errors, etc. will drop through
}
#endif // __AVR
#ifdef __ARM
// detect USB connection and transition to disconnected state if it disconnected
if (SerialUSB.isConnected() == false) cs.state = CONTROLLER_NOT_CONNECTED;
// read input line and return if not a completed line
if (cs.state == CONTROLLER_READY) {
if (read_line(cs.in_buf, &cs.read_index, sizeof(cs.in_buf)) != STAT_OK) {
cs.bufp = cs.in_buf;
return (STAT_OK); // This is an exception: returns OK for anything NOT OK, so the idler always runs
}
} else if (cs.state == CONTROLLER_NOT_CONNECTED) {
if (SerialUSB.isConnected() == false) return (STAT_OK);
cm_request_queue_flush();
rpt_print_system_ready_message();
cs.state = CONTROLLER_STARTUP;
} else if (cs.state == CONTROLLER_STARTUP) { // run startup code
cs.state = CONTROLLER_READY;
} else {
return (STAT_OK);
}
cs.read_index = 0;
#endif // __ARM

// set up the buffers
// set up the buffers
cs.linelen = strlen(cs.in_buf)+1; // linelen only tracks primary input
strncpy(cs.saved_buf, cs.bufp, SAVED_BUFFER_LEN-1); // save input buffer for reporting

Expand Down Expand Up @@ -276,8 +276,9 @@ static stat_t _command_dispatch()
}
default: { // anything else must be Gcode
if (cfg.comm_mode == JSON_MODE) { // run it as JSON...
strncpy(cs.out_buf, cs.bufp, INPUT_BUFFER_LEN -8); // use out_buf as temp
sprintf((char *)cs.bufp,"{\"gc\":\"%s\"}\n", (char *)cs.out_buf); // '-8' is used for JSON chars
strncpy(cs.out_buf, cs.bufp, INPUT_BUFFER_LEN -10); // use out_buf as temp
cs.out_buf[INPUT_BUFFER_LEN-10] = '\0';
snprintf(cs.bufp,INPUT_BUFFER_LEN,"{\"gc\":\"%.244s\"}\n", cs.out_buf); // 10 chars used for JSON shell
json_parser(cs.bufp);
} else { //...or run it as text
text_response(gc_gcode_parser(cs.bufp), cs.saved_buf);
Expand All @@ -287,7 +288,7 @@ static stat_t _command_dispatch()
return (STAT_OK);
}


/**** Local Utilities ********************************************************/
/*
* _shutdown_idler() - blink rapidly and prevent further activity from occurring
Expand Down Expand Up @@ -406,7 +407,7 @@ static stat_t _sync_to_planner()
}
return (STAT_OK);
}

/*
static stat_t _sync_to_time()
{
Expand All @@ -426,7 +427,7 @@ static stat_t _sync_to_time()
static stat_t _limit_switch_handler(void)
{
if (cm_get_machine_state() == MACHINE_ALARM) { return (STAT_NOOP);}

if (get_limit_switch_thrown() == false) return (STAT_NOOP);
return(cm_hard_alarm(STAT_LIMIT_SWITCH_HIT));
return (STAT_OK);
Expand All @@ -435,7 +436,7 @@ static stat_t _limit_switch_handler(void)
/*
* _system_assertions() - check memory integrity and other assertions
*/
#define emergency___everybody_to_get_from_street(a) if((status_code=a) != STAT_OK) return (cm_hard_alarm(status_code));
#define emergency___everybody_to_get_from_street(a) if((status_code=a) != STAT_OK) return (cm_hard_alarm(status_code));

stat_t _system_assertions()
{
Expand Down
Loading