1
0

Fix print and timer

This commit is contained in:
tmk 2014-06-16 15:38:39 +09:00
parent d7004b97d8
commit 81504a8ef0
8 changed files with 58 additions and 16 deletions

42
common/avr/timer_avr.h Normal file
View File

@ -0,0 +1,42 @@
/*
Copyright 2011 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TIMER_AVR_H
#define TIMER_AVR_H 1
#include <stdint.h>
#ifndef TIMER_PRESCALER
# if F_CPU > 16000000
# define TIMER_PRESCALER 256
# elif F_CPU > 2000000
# define TIMER_PRESCALER 64
# elif F_CPU > 250000
# define TIMER_PRESCALER 8
# else
# define TIMER_PRESCALER 1
# endif
#endif
#define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER)
#define TIMER_RAW TCNT0
#define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000)
#if (TIMER_RAW_TOP > 255)
# error "Timer0 can't count 1ms at this clock freq. Use larger prescaler."
#endif
#endif

View File

@ -25,13 +25,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NO_DEBUG #ifndef NO_DEBUG
#define dprint(s) do { if (debug_enable) print(s); } while (0) #define dprint(s) do { if (debug_enable) print(s); } while (0)
#define dprintln() do { if (debug_enable) print_crlf(); } while (0) #define dprintln(s) do { if (debug_enable) println(s); } while (0)
#define dprintf(fmt, ...) do { if (debug_enable) xprintf(fmt, ##__VA_ARGS__); } while (0) #define dprintf(fmt, ...) do { if (debug_enable) xprintf(fmt, ##__VA_ARGS__); } while (0)
#define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s)) #define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s))
/* DO NOT USE these anymore */ /* DO NOT USE these anymore */
#define debug(s) do { if (debug_enable) print(s); } while (0) #define debug(s) do { if (debug_enable) print(s); } while (0)
#define debugln(s) do { if (debug_enable) print_crlf(); } while (0) #define debugln(s) do { if (debug_enable) println(s); } while (0)
#define debug_S(s) do { if (debug_enable) print_S(s); } while (0) #define debug_S(s) do { if (debug_enable) print_S(s); } while (0)
#define debug_P(s) do { if (debug_enable) print_P(s); } while (0) #define debug_P(s) do { if (debug_enable) print_P(s); } while (0)
#define debug_msg(s) do { \ #define debug_msg(s) do { \

View File

@ -38,14 +38,15 @@ typedef union {
} debug_config_t; } debug_config_t;
debug_config_t debug_config; debug_config_t debug_config;
#ifdef __cplusplus
}
#endif
/* for backward compatibility */ /* for backward compatibility */
#define debug_enable (debug_config.enable) #define debug_enable (debug_config.enable)
#define debug_matrix (debug_config.matrix) #define debug_matrix (debug_config.matrix)
#define debug_keyboard (debug_config.keyboard) #define debug_keyboard (debug_config.keyboard)
#define debug_mouse (debug_config.mouse) #define debug_mouse (debug_config.mouse)
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -11,6 +11,7 @@ void SysTick_Handler(void) {
void timer_init(void) void timer_init(void)
{ {
timer_count = 0;
SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
} }

View File

@ -18,8 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NODEBUG_H #ifndef NODEBUG_H
#define NODEBUG_H 1 #define NODEBUG_H 1
#include "debug_config.h"
#define dprint(s) #define dprint(s)
#define dprintln(s) #define dprintln(s)
#define dprintf(fmt, ...) #define dprintf(fmt, ...)

View File

@ -35,7 +35,7 @@
#ifndef NO_PRINT #ifndef NO_PRINT
#ifdef __AVR__ #if defined(__AVR__)
#include "xprintf.h" #include "xprintf.h"
@ -44,21 +44,21 @@
#ifndef __cplusplus #ifndef __cplusplus
#define print(s) xputs(PSTR(s)) #define print(s) xputs(PSTR(s))
#endif #endif
#define println(s) xputs(PSTR(s "\n")) #define println(s) xputs(PSTR(s "\r\n"))
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
#endif #endif
/* function pointer of sendchar to be used by print utility */ /* function pointer of sendchar to be used by print utility */
void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
#elif __arm__ #elif defined(__arm__)
#include "mbed/xprintf.h"
#include "mbed.h"
Serial ser(UART_TX, UART_RX);
#define xprintf ser.printf
#define print(s) xprintf(s) #define print(s) xprintf(s)
#define println(s) xprintf(s "\n") #define println(s) xprintf(s "\r\n")
/* TODO: to select output destinations: UART/USBSerial */ /* TODO: to select output destinations: UART/USBSerial */
#define print_set_sendchar(func) #define print_set_sendchar(func)