mirror of https://github.com/Desuuuu/klipper.git
generic: Create generic board infrastructure and move misc.h to it
Instead of creating a misc.h file in each board directory, create a generic board directory and declare misc.h there. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
ff789058df
commit
9971f999b3
6
Makefile
6
Makefile
|
@ -26,13 +26,13 @@ PYTHON=python
|
||||||
|
|
||||||
# Source files
|
# Source files
|
||||||
src-y=sched.c command.c stepper.c basecmd.c gpiocmds.c spicmds.c endstop.c
|
src-y=sched.c command.c stepper.c basecmd.c gpiocmds.c spicmds.c endstop.c
|
||||||
DIRS=src src/avr src/simulator lib/pjrc_usb_serial
|
DIRS=src src/avr src/simulator src/generic lib/pjrc_usb_serial
|
||||||
|
|
||||||
# Default compiler flags
|
# Default compiler flags
|
||||||
cc-option=$(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`" \
|
cc-option=$(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`" \
|
||||||
; then echo "$(2)"; else echo "$(3)"; fi ;)
|
; then echo "$(2)"; else echo "$(3)"; fi ;)
|
||||||
|
|
||||||
CFLAGS-y := -I$(OUT) -Isrc -Os -MD -g \
|
CFLAGS-y := -I$(OUT) -Isrc -I$(OUT)board-generic/ -Os -MD -g \
|
||||||
-Wall -Wold-style-definition $(call cc-option,$(CC),-Wtype-limits,) \
|
-Wall -Wold-style-definition $(call cc-option,$(CC),-Wtype-limits,) \
|
||||||
-ffunction-sections -fdata-sections
|
-ffunction-sections -fdata-sections
|
||||||
CFLAGS-y += -flto -fwhole-program
|
CFLAGS-y += -flto -fwhole-program
|
||||||
|
@ -72,6 +72,8 @@ $(OUT)board-link: $(KCONFIG_CONFIG)
|
||||||
@echo " Creating symbolic link $(OUT)board"
|
@echo " Creating symbolic link $(OUT)board"
|
||||||
$(Q)touch $@
|
$(Q)touch $@
|
||||||
$(Q)ln -Tsf $(PWD)/src/$(CONFIG_BOARD_DIRECTORY) $(OUT)board
|
$(Q)ln -Tsf $(PWD)/src/$(CONFIG_BOARD_DIRECTORY) $(OUT)board
|
||||||
|
$(Q)mkdir -p $(OUT)board-generic
|
||||||
|
$(Q)ln -Tsf $(PWD)/src/generic $(OUT)board-generic/board
|
||||||
|
|
||||||
$(OUT)declfunc.lds: src/declfunc.lds.S
|
$(OUT)declfunc.lds: src/declfunc.lds.S
|
||||||
@echo " Precompiling $@"
|
@echo " Precompiling $@"
|
||||||
|
|
|
@ -7,7 +7,7 @@ CFLAGS-y += -mmcu=$(CONFIG_MCU) -DF_CPU=$(CONFIG_CLOCK_FREQ)
|
||||||
LDFLAGS-y += -Wl,--relax
|
LDFLAGS-y += -Wl,--relax
|
||||||
|
|
||||||
# Add avr source files
|
# Add avr source files
|
||||||
src-y += avr/main.c avr/timer.c avr/gpio.c avr/alloc.c
|
src-y += avr/main.c avr/timer.c avr/gpio.c avr/misc.c
|
||||||
src-$(CONFIG_AVR_WATCHDOG) += avr/watchdog.c
|
src-$(CONFIG_AVR_WATCHDOG) += avr/watchdog.c
|
||||||
src-$(CONFIG_AVR_USBSERIAL) += avr/usbserial.c ../lib/pjrc_usb_serial/usb_serial.c
|
src-$(CONFIG_AVR_USBSERIAL) += avr/usbserial.c ../lib/pjrc_usb_serial/usb_serial.c
|
||||||
src-$(CONFIG_AVR_SERIAL) += avr/serial.c
|
src-$(CONFIG_AVR_SERIAL) += avr/serial.c
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// AVR allocation checking code.
|
// AVR miscellaneous platform code
|
||||||
//
|
//
|
||||||
// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
||||||
//
|
//
|
||||||
|
@ -6,10 +6,22 @@
|
||||||
|
|
||||||
#include <avr/io.h> // AVR_STACK_POINTER_REG
|
#include <avr/io.h> // AVR_STACK_POINTER_REG
|
||||||
#include <stdlib.h> // __malloc_heap_end
|
#include <stdlib.h> // __malloc_heap_end
|
||||||
|
#include <util/crc16.h> // _crc_ccitt_update
|
||||||
#include "autoconf.h" // CONFIG_AVR_STACK_SIZE
|
#include "autoconf.h" // CONFIG_AVR_STACK_SIZE
|
||||||
|
#include "board/misc.h" // alloc_maxsize
|
||||||
#include "compiler.h" // ALIGN
|
#include "compiler.h" // ALIGN
|
||||||
#include "misc.h" // alloc_maxsize
|
|
||||||
|
|
||||||
|
// Optimized crc16_ccitt for the avr processor
|
||||||
|
uint16_t
|
||||||
|
crc16_ccitt(char *buf, uint8_t len)
|
||||||
|
{
|
||||||
|
uint16_t crc = 0xFFFF;
|
||||||
|
while (len--)
|
||||||
|
crc = _crc_ccitt_update(crc, *buf++);
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the maximum allocation size that can succeed up to 'reqsize'
|
||||||
size_t
|
size_t
|
||||||
alloc_maxsize(size_t reqsize)
|
alloc_maxsize(size_t reqsize)
|
||||||
{
|
{
|
|
@ -1,25 +0,0 @@
|
||||||
#ifndef __AVR_MISC_H
|
|
||||||
#define __AVR_MISC_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <util/crc16.h>
|
|
||||||
|
|
||||||
// alloc.c
|
|
||||||
size_t alloc_maxsize(size_t reqsize);
|
|
||||||
|
|
||||||
// console.c
|
|
||||||
char *console_get_input(uint8_t *plen);
|
|
||||||
void console_pop_input(uint8_t len);
|
|
||||||
char *console_get_output(uint8_t len);
|
|
||||||
void console_push_output(uint8_t len);
|
|
||||||
|
|
||||||
// Optimized crc16_ccitt for the avr processor
|
|
||||||
#define HAVE_OPTIMIZED_CRC 1
|
|
||||||
static inline uint16_t _crc16_ccitt(char *buf, uint8_t len) {
|
|
||||||
uint16_t crc = 0xFFFF;
|
|
||||||
while (len--)
|
|
||||||
crc = _crc_ccitt_update(crc, *buf++);
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // misc.h
|
|
|
@ -7,9 +7,9 @@
|
||||||
#include <avr/interrupt.h> // USART0_RX_vect
|
#include <avr/interrupt.h> // USART0_RX_vect
|
||||||
#include <string.h> // memmove
|
#include <string.h> // memmove
|
||||||
#include "autoconf.h" // CONFIG_SERIAL_BAUD
|
#include "autoconf.h" // CONFIG_SERIAL_BAUD
|
||||||
|
#include "board/misc.h" // console_get_input
|
||||||
#include "sched.h" // DECL_INIT
|
#include "sched.h" // DECL_INIT
|
||||||
#include "irq.h" // irq_save
|
#include "irq.h" // irq_save
|
||||||
#include "misc.h" // console_get_input
|
|
||||||
|
|
||||||
#define SERIAL_BUFFER_SIZE 96
|
#define SERIAL_BUFFER_SIZE 96
|
||||||
static char receive_buf[SERIAL_BUFFER_SIZE];
|
static char receive_buf[SERIAL_BUFFER_SIZE];
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include <stdlib.h> // strtod
|
#include <stdlib.h> // strtod
|
||||||
#include <string.h> // strcasecmp
|
#include <string.h> // strcasecmp
|
||||||
#include "board/irq.h" // irq_disable
|
#include "board/irq.h" // irq_disable
|
||||||
#include "board/misc.h" // HAVE_OPTIMIZED_CRC
|
#include "board/misc.h" // crc16_ccitt
|
||||||
#include "board/pgm.h" // READP
|
#include "board/pgm.h" // READP
|
||||||
#include "command.h" // output_P
|
#include "command.h" // output_P
|
||||||
#include "sched.h" // DECL_TASK
|
#include "sched.h" // DECL_TASK
|
||||||
|
@ -35,23 +35,6 @@ static uint8_t next_sequence = MESSAGE_DEST;
|
||||||
* Binary message parsing
|
* Binary message parsing
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
// Implement the standard crc "ccitt" algorithm on the given buffer
|
|
||||||
static uint16_t
|
|
||||||
crc16_ccitt(char *buf, uint8_t len)
|
|
||||||
{
|
|
||||||
if (HAVE_OPTIMIZED_CRC)
|
|
||||||
return _crc16_ccitt(buf, len);
|
|
||||||
uint16_t crc = 0xffff;
|
|
||||||
while (len--) {
|
|
||||||
uint8_t data = *buf++;
|
|
||||||
data ^= crc & 0xff;
|
|
||||||
data ^= data << 4;
|
|
||||||
crc = ((((uint16_t)data << 8) | (crc >> 8)) ^ (uint8_t)(data >> 4)
|
|
||||||
^ ((uint16_t)data << 3));
|
|
||||||
}
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode an integer as a variable length quantity (vlq)
|
// Encode an integer as a variable length quantity (vlq)
|
||||||
static char *
|
static char *
|
||||||
encode_int(char *p, uint32_t v)
|
encode_int(char *p, uint32_t v)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Dummy implementation for alloc commands
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
||||||
|
//
|
||||||
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
// Return the maximum allocation size that can succeed up to 'reqsize'
|
||||||
|
size_t alloc_maxsize(size_t reqsize)
|
||||||
|
{
|
||||||
|
return reqsize;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Code for crc16_ccitt
|
||||||
|
//
|
||||||
|
// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
||||||
|
//
|
||||||
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
|
#include "misc.h" // crc16_ccitt
|
||||||
|
|
||||||
|
// Implement the standard crc "ccitt" algorithm on the given buffer
|
||||||
|
uint16_t
|
||||||
|
crc16_ccitt(char *buf, uint8_t len)
|
||||||
|
{
|
||||||
|
uint16_t crc = 0xffff;
|
||||||
|
while (len--) {
|
||||||
|
uint8_t data = *buf++;
|
||||||
|
data ^= crc & 0xff;
|
||||||
|
data ^= data << 4;
|
||||||
|
crc = ((((uint16_t)data << 8) | (crc >> 8)) ^ (uint8_t)(data >> 4)
|
||||||
|
^ ((uint16_t)data << 3));
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef __GENERIC_MISC_H
|
||||||
|
#define __GENERIC_MISC_H
|
||||||
|
|
||||||
|
#include <stddef.h> // size_t
|
||||||
|
#include <stdint.h> // uint8_t
|
||||||
|
|
||||||
|
char *console_get_input(uint8_t *plen);
|
||||||
|
void console_pop_input(uint8_t len);
|
||||||
|
char *console_get_output(uint8_t len);
|
||||||
|
void console_push_output(uint8_t len);
|
||||||
|
|
||||||
|
size_t alloc_maxsize(size_t reqsize);
|
||||||
|
|
||||||
|
uint16_t crc16_ccitt(char *buf, uint8_t len);
|
||||||
|
|
||||||
|
#endif // misc.h
|
|
@ -1,3 +1,4 @@
|
||||||
# Additional simulator build rules
|
# Additional simulator build rules
|
||||||
|
|
||||||
src-y += simulator/main.c simulator/gpio.c
|
src-y += simulator/main.c simulator/gpio.c
|
||||||
|
src-y += generic/crc16_ccitt.c generic/alloc.c
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
#ifndef __SIMU_MISC_H
|
|
||||||
#define __SIMU_MISC_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
// main.c
|
|
||||||
char *console_get_input(uint8_t *plen);
|
|
||||||
void console_pop_input(uint8_t len);
|
|
||||||
char *console_get_output(uint8_t len);
|
|
||||||
void console_push_output(uint8_t len);
|
|
||||||
|
|
||||||
static inline size_t alloc_maxsize(size_t reqsize) {
|
|
||||||
return reqsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define HAVE_OPTIMIZED_CRC 0
|
|
||||||
static inline uint16_t _crc16_ccitt(char *buf, uint8_t len) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // misc.h
|
|
Loading…
Reference in New Issue