Skip to content

Commit

Permalink
Further cleanups to allow compiling for ATmega324 as C99 with all war…
Browse files Browse the repository at this point in the history
…nings turned on
  • Loading branch information
dren-dk committed Oct 19, 2011
1 parent 8660045 commit 4cb2054
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Part of Grbl
#
# Copyright (c) 2009-2011 Simen Svale Skogsrud
# Copyright (c) 2011 Flemming Frandsen
#
# Grbl is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -27,8 +28,8 @@
# is connected.
# FUSES ........ Parameters for avrdude to flash the fuses appropriately.

DEVICE = atmega328p
CLOCK = 16000000
DEVICE = atmega324p
CLOCK = 20000000
PROGRAMMER = -c avrisp2 -P usb
OBJECTS = main.o motion_control.o gcode.o spindle_control.o wiring_serial.o serial_protocol.o stepper.o \
eeprom.o settings.o planner.o
Expand All @@ -40,7 +41,7 @@ FUSES = -U hfuse:w:0xd2:m -U lfuse:w:0xff:m
# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -B 10 -F
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections
COMPILE = avr-gcc -Wall -Os -pedantic-errors -Werror -std=c99 -Wl,-u,vfprintf -lprintf_min -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections

# symbolic targets:
all: grbl.hex
Expand Down
7 changes: 4 additions & 3 deletions gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Part of Grbl
Copyright (c) 2009-2011 Simen Svale Skogsrud
Copyright (c) 2011 Flemming Frandsen
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -98,7 +99,7 @@ void gc_init()
gc.absolute_mode = TRUE;
}

inline float to_millimeters(double value)
float to_millimeters(double value)
{
return (gc.inches_mode ? (value * MM_PER_INCH) : value);
}
Expand Down Expand Up @@ -185,7 +186,7 @@ uint8_t gc_execute_line(char *line)
case 1:
gc.motion_mode = MOTION_MODE_LINEAR;
break;
#ifdef __AVR_ATmega328P__
#ifndef CFG_TINY
case 2:
gc.motion_mode = MOTION_MODE_CW_ARC;
break;
Expand Down Expand Up @@ -355,7 +356,7 @@ uint8_t gc_execute_line(char *line)
(gc.inverse_feed_rate_mode) ? inverse_feed_rate : gc.
feed_rate, gc.inverse_feed_rate_mode);
break;
#ifdef __AVR_ATmega328P__
#ifndef CFG_TINY
case MOTION_MODE_CW_ARC:
case MOTION_MODE_CCW_ARC:
if (radius_mode) {
Expand Down
6 changes: 4 additions & 2 deletions motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
void mc_dwell(uint32_t milliseconds)
{
st_synchronize();
_delay_ms(milliseconds);
while (milliseconds--) {
_delay_ms(1);
}
}

// Execute an arc. theta == start angle, angular_travel == number of radians to go along the arc,
Expand All @@ -42,7 +44,7 @@ void mc_dwell(uint32_t milliseconds)
// axis in axis_l which will be the axis for linear travel if you are tracing a helical motion.
// position is a pointer to a vector representing the current position in millimeters.

#ifdef __AVR_ATmega328P__
#ifndef CFG_TINY
// The arc is approximated by generating a huge number of tiny, linear segments. The length of each
// segment is configured in settings.mm_per_arc_segment.
void mc_arc(double theta, double angular_travel, double radius,
Expand Down
2 changes: 1 addition & 1 deletion motion_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// NOTE: Although this function structurally belongs in this module, there is nothing to do but
// to forward the request to the planner. For efficiency the function is implemented with a macro.

#ifdef __AVR_ATmega328P__
#ifndef CFG_TINY
// Execute an arc. theta == start angle, angular_travel == number of radians to go along the arc,
// positive angular_travel means clockwise, negative means counterclockwise. Radius == the radius of the
// circle in millimeters. axis_1 and axis_2 selects the circle plane in tool space. Stick the remaining
Expand Down
10 changes: 5 additions & 5 deletions planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
#include "wiring_serial.h"

// The number of linear motions that can be in the plan at any give time
#ifdef __AVR_ATmega328P__
#define BLOCK_BUFFER_SIZE 20
#else
#ifdef CFG_TINY
#define BLOCK_BUFFER_SIZE 5
#else
#define BLOCK_BUFFER_SIZE 20
#endif

static block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions
Expand Down Expand Up @@ -365,14 +365,14 @@ int plan_is_acceleration_manager_enabled()
return (acceleration_manager_enabled);
}

inline void plan_discard_current_block()
void plan_discard_current_block()
{
if (block_buffer_head != block_buffer_tail) {
block_buffer_tail = (block_buffer_tail + 1) % BLOCK_BUFFER_SIZE;
}
}

inline block_t *plan_get_current_block()
block_t *plan_get_current_block()
{
if (block_buffer_head == block_buffer_tail) {
return (NULL);
Expand Down
4 changes: 2 additions & 2 deletions planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ void plan_buffer_line(double x, double y, double z, double feed_rate,

// Called when the current block is no longer needed. Discards the block and makes the memory
// availible for new blocks.
inline void plan_discard_current_block();
void plan_discard_current_block();

// Gets the current block. Returns NULL if buffer empty
inline block_t *plan_get_current_block();
block_t *plan_get_current_block();

// Enables or disables acceleration-management for upcoming blocks
void plan_set_acceleration_manager_enabled(int enabled);
Expand Down
4 changes: 2 additions & 2 deletions stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void st_wake_up()

// Initializes the trapezoid generator from the current block. Called whenever a new
// block begins.
inline void trapezoid_generator_reset()
void trapezoid_generator_reset()
{
trapezoid_adjusted_rate = current_block->initial_rate;
trapezoid_tick_cycle_counter = 0; // Always start a new trapezoid with a full acceleration tick
Expand All @@ -98,7 +98,7 @@ inline void trapezoid_generator_reset()
// This is called ACCELERATION_TICKS_PER_SECOND times per second by the step_event
// interrupt. It can be assumed that the trapezoid-generator-parameters and the
// current_block stays untouched by outside handlers for the duration of this function call.
inline void trapezoid_generator_tick()
void trapezoid_generator_tick()
{
if (current_block) {
if (step_events_completed < current_block->accelerate_until) {
Expand Down
9 changes: 5 additions & 4 deletions wiring_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
Copyright (c) 2011 Flemming Frandsen
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -32,10 +33,10 @@
// using a ring buffer (I think), in which rx_buffer_head is the index of the
// location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read.
#ifdef __AVR_ATmega328P__
#define RX_BUFFER_SIZE 256
#else
#ifdef CFG_TINY
#define RX_BUFFER_SIZE 64
#else
#define RX_BUFFER_SIZE 256
#endif

unsigned char rx_buffer[RX_BUFFER_SIZE];
Expand Down Expand Up @@ -96,7 +97,7 @@ void serialFlush()
rx_buffer_head = rx_buffer_tail;
}

SIGNAL(USART_RX_vect)
SIGNAL(USART0_RX_vect)
{
unsigned char c = UDR0;
int i = (rx_buffer_head + 1) % RX_BUFFER_SIZE;
Expand Down

0 comments on commit 4cb2054

Please sign in to comment.