This commit is contained in:
Mark Qvist 2014-04-03 22:21:37 +02:00
commit c898b090dd
1049 changed files with 288572 additions and 0 deletions

102
bertos/algo/crc.c Normal file
View file

@ -0,0 +1,102 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief CRC table and support routines
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#include "crc.h"
/*
* The boot on AVR cpu is placed at the end of flash memory, but the avr
* address memory by byte and the pointers are 16bits long, so we are able
* to address 64Kbyte memory max. For this reason we can't read the crctab
* from flash, because it is placed at the end of memory. This is true every
* time we have an AVR cpu with more that 64Kbyte of flash. To fix this problem
* we let the compiler copy the table in RAM at startup. Obviously this solution
* is not efficent, but for now this is the only way.
*/
#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT))
#define CRC_TABLE const uint16_t PROGMEM crc16tab[256]
#else
#define CRC_TABLE const uint16_t crc16tab[256]
#endif
/**
* crctab calculated by Mark G. Mendel, Network Systems Corporation
*/
CRC_TABLE = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
uint16_t crc16(uint16_t crc, const void *buffer, size_t len)
{
const unsigned char *buf = (const unsigned char *)buffer;
while(len--)
crc = UPDCRC16(*buf++, crc);
return crc;
}

115
bertos/algo/crc.h Normal file
View file

@ -0,0 +1,115 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief Cyclic Redundancy Check 16 (CRC). This algorithm is the one used by the XMODEM protocol.
*
* \note This algorithm is incompatible with the CCITT-CRC16.
*
* This code is based on the article Copyright 1986 Stephen Satchell.
*
* Programmers may incorporate any or all code into their programs,
* giving proper credit within the source. Publication of the
* source routines is permitted so long as proper credit is given
* to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
* Omen Technology.
*
* \author Bernie Innocenti <bernie@codewiz.org>
*
* $WIZ$ module_name = "crc16"
*/
#ifndef ALGO_CRC_H
#define ALGO_CRC_H
#include "cfg/cfg_arch.h"
#include <cfg/compiler.h>
#include <cpu/pgm.h>
EXTERN_C_BEGIN
/* CRC table */
extern const uint16_t crc16tab[256];
/**
* \brief Compute the updated CRC16 value for one octet (macro version)
*
* \note This version is only intended for old/broken compilers.
* Use the inline function in new code.
*
* \param c New octet (range 0-255)
* \param oldcrc Previous CRC16 value (referenced twice, beware of side effects)
*/
#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT))
#define UPDCRC16(c, oldcrc) (pgm_read_uint16_t(&crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8))
#else
#define UPDCRC16(c, oldcrc) ((crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8))
#endif
/** CRC-16 init value */
#define CRC16_INIT_VAL ((uint16_t)0)
#ifdef INLINE
/**
* \brief Compute the updated CRC16 value for one octet (inline version)
*/
INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc)
{
#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT))
return pgm_read_uint16_t(&crc16tab[(oldcrc >> 8) ^ c]) ^ (oldcrc << 8);
#else
return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8);
#endif
}
#endif // INLINE
/**
* This function implements the CRC 16 calculation on a buffer.
*
* \param crc Current CRC16 value.
* \param buf The buffer to perform CRC calculation on.
* \param len The length of the Buffer.
*
* \return The updated CRC16 value.
*/
extern uint16_t crc16(uint16_t crc, const void *buf, size_t len);
int crc_testSetup(void);
int crc_testRun(void);
int crc_testTearDown(void);
EXTERN_C_END
#endif /* ALGO_CRC_H */

83
bertos/algo/crc_ccitt.c Normal file
View file

@ -0,0 +1,83 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief CRC-CCITT table and support routines
*
* \author Francesco Sacchi <batt@develer.com>
*/
#include "crc_ccitt.h"
const uint16_t PROGMEM crc_ccitt_tab[256] = {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78,
};
uint16_t crc_ccitt(uint16_t crc, const void *buffer, size_t len)
{
const unsigned char *buf = (const unsigned char *)buffer;
while (len--)
crc = updcrc_ccitt(*buf++, crc);
return crc;
}

78
bertos/algo/crc_ccitt.h Normal file
View file

@ -0,0 +1,78 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief CCITT Cyclic Redundancy Check (CRC-CCITT).
*
* \note This algorithm is incompatible with the CRC16.
*
* \author Francesco Sacchi <batt@develer.com>
*
* $WIZ$ module_name = "crc-ccitt"
*/
#ifndef ALGO_CRC_CCITT_H
#define ALGO_CRC_CCITT_H
#include <cfg/compiler.h>
#include <cpu/pgm.h>
EXTERN_C_BEGIN
/* CRC table */
extern const uint16_t crc_ccitt_tab[256];
/**
* \brief Compute the updated CRC-CCITT value for one octet (inline version)
*/
INLINE uint16_t updcrc_ccitt(uint8_t c, uint16_t oldcrc)
{
return (oldcrc >> 8) ^ pgm_read16(&crc_ccitt_tab[(oldcrc ^ c) & 0xff]);
}
/** CRC-CCITT init value */
#define CRC_CCITT_INIT_VAL ((uint16_t)0xFFFF)
/**
* This function implements the CRC-CCITT calculation on a buffer.
*
* \param crc Current CRC-CCITT value.
* \param buf The buffer to perform CRC calculation on.
* \param len The length of the Buffer.
*
* \return The updated CRC-CCITT value.
*/
extern uint16_t crc_ccitt(uint16_t crc, const void *buf, size_t len);
EXTERN_C_END
#endif /* ALGO_CRC_CCITT_H */

75
bertos/algo/crc_test.c Normal file
View file

@ -0,0 +1,75 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief CRC-CCITT table and support routines
*
* \author Francesco Sacchi <batt@develer.com>
*/
#include "crc_ccitt.h"
#include "crc.h"
#include <cfg/debug.h>
#include <cfg/test.h>
int crc_testSetup(void)
{
kdbg_init();
return 0;
}
int crc_testTearDown(void)
{
return 0;
}
int crc_testRun(void)
{
char vector[9] = "123456789";
uint16_t crc = CRC_CCITT_INIT_VAL;
crc = crc_ccitt(crc, vector, sizeof(vector));
kprintf("crc_ccitt [%04X]\n", crc);
ASSERT(crc == 0x6F91);
crc = CRC16_INIT_VAL;
crc = crc16(crc, vector, sizeof(vector));
kprintf("crc16 [%04X]\n", crc);
ASSERT(crc == 0x31C3);
return 0;
}
TEST_MAIN(crc);

336
bertos/algo/md2.c Normal file
View file

@ -0,0 +1,336 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2007 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief MD2 Message-Digest algorithm.
*
* The MD2 algorithm work with a constant array of 256 permutationt
* defined in RFC1319. If you don't want to use a standard array of
* permutatione you can use a md2_perm() function that generate an
* array of 256 "casual" permutation. To swich from a standard array
* to md2_perm function you must chanche CONFIG_MD2_STD_PERM defined in
* appconfig.h.
* If you need to store array in program memory you must define
* a macro _PROGMEM (for more info see cpu/pgm.h).
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#include "md2.h"
#include <string.h> //memset(), memcpy();
#include <cfg/compiler.h>
#include <cfg/debug.h> //ASSERT()
#include <cfg/macros.h> //MIN(), countof(), ROTR();
#include <cpu/pgm.h>
#if CONFIG_MD2_STD_PERM
/*
* Official array of 256 byte pemutation contructed from digits of pi, defined
* in the RFC 1319.
*/
static const uint8_t PROGMEM md2_perm[256] =
{
41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
31, 26, 219, 153, 141, 51, 159, 17, 131, 20
};
#define MD2_PERM(x) pgm_read8(&md2_perm[x])
#else
/**
* Md2_perm() function generate an array of 256 "casual" permutation.
*/
/**
* Costant define for computing an array of 256 "casual" permutation.
* \{
*/
#define K1 5
#define K2 3
#define R 2
#define X 172
/*\}*/
static uint8_t md2_perm(uint8_t i)
{
i = i * K1;
i = ROTR(i, R);
i ^= X;
i = i * K2;
return i;
}
#define MD2_PERM(x) md2_perm(x)
#endif
/**
* Pad function. Put len_pad unsigned char in
* input block.
*/
static void md2_pad(void *_block, size_t len_pad)
{
uint8_t *block;
block = (uint8_t *)_block;
ASSERT(len_pad <= CONFIG_MD2_BLOCK_LEN);
/*
* Fill input block with len_pad char.
*/
memset(block, len_pad, len_pad);
}
static void md2_compute(void *_state, void *_checksum, void *_block)
{
int i = 0;
uint16_t t = 0;
uint8_t compute_array[COMPUTE_ARRAY_LEN];
uint8_t *state;
uint8_t *checksum;
uint8_t *block;
state = (uint8_t *)_state;
checksum = (uint8_t *)_checksum;
block = (uint8_t *)_block;
/*
* Copy state and checksum context in compute array.
*/
memcpy(compute_array, state, CONFIG_MD2_BLOCK_LEN);
memcpy(compute_array + CONFIG_MD2_BLOCK_LEN, block, CONFIG_MD2_BLOCK_LEN);
/*
* Fill compute array with state XOR block
*/
for(i = 0; i < CONFIG_MD2_BLOCK_LEN; i++)
compute_array[i + (CONFIG_MD2_BLOCK_LEN * 2)] = state[i] ^ block[i];
/*
* Encryt block.
*/
for(i = 0; i < NUM_COMPUTE_ROUNDS; i++)
{
for(int j = 0; j < COMPUTE_ARRAY_LEN; j++)
{
compute_array[j] ^= MD2_PERM(t);
t = compute_array[j];
}
t = (t + i) & 0xff; //modulo 256.
}
/*
* Update checksum.
*/
t = checksum[CONFIG_MD2_BLOCK_LEN - 1];
for(i = 0; i < CONFIG_MD2_BLOCK_LEN; i++)
{
checksum[i] ^= MD2_PERM(block[i] ^ t);
t = checksum[i];
}
/*
* Update state and clean compute array.
*/
memcpy(state, compute_array, CONFIG_MD2_BLOCK_LEN);
memset(compute_array, 0, sizeof(compute_array));
}
/**
* Algorithm initialization.
*
* \param context empty context.
*/
void md2_init(Md2Context *context)
{
memset(context, 0, sizeof(Md2Context));
}
/**
* Update block.
*/
void md2_update(Md2Context *context, const void *_block_in, size_t block_len)
{
const uint8_t *block_in;
size_t cpy_len;
block_in = (const uint8_t *)_block_in;
while(block_len > 0)
{
/*
* Choose a number of block that fill input context buffer.
*/
cpy_len = MIN(block_len, CONFIG_MD2_BLOCK_LEN - context->counter);
/*
* Copy in the buffer input block.
*/
memcpy(&context->buffer[context->counter], block_in, cpy_len);
/*
* Update a context counter, input block length and remaning
* context buffer block lenght.
*/
context->counter += cpy_len;
block_len -= cpy_len;
block_in += cpy_len;
/*
* If buffer is full, compute it.
*/
if (context->counter >= CONFIG_MD2_BLOCK_LEN)
{
md2_compute(context->state, context->checksum, context->buffer);
context->counter = 0;
}
}
}
/**
* Ends an MD2 message digest operation.
* This fuction take an context and return a pointer
* to context state.
*
* \param context in input.
* \return a pointer to context state (message digest).
*/
uint8_t *md2_end(Md2Context *context)
{
uint8_t buf[CONFIG_MD2_BLOCK_LEN];
/*
* Fill remaning empty context buffer.
*/
md2_pad(buf, CONFIG_MD2_BLOCK_LEN - context->counter);
/*
* Update context buffer and compute it.
*/
md2_update(context, buf, CONFIG_MD2_BLOCK_LEN - context->counter);
/*
* Add context checksum to message input.
*/
md2_update(context, context->checksum, CONFIG_MD2_BLOCK_LEN);
return context->state; //return a pointer to message digest.
}
/**
* MD2 test fuction.
* This function test MD2 algorithm with a standard string specified
* in RFC 1319.
*
* \note This test work with official array of 256 byte pemutation
* contructed from digits of pi, defined in the RFC 1319.
*
*/
bool md2_test(void)
{
Md2Context context;
const char *test[] =
{
"",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"
};
const char *result[] = {
"\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69\x27\x73",
"\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe\x06\xb0",
"\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b",
"\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3\xef\xd8",
};
for (size_t i = 0; i < countof(test); i++)
{
md2_init(&context);
md2_update(&context, test[i], strlen(test[i]));
if(memcmp(result[i], md2_end(&context), MD2_DIGEST_LEN))
return false;
}
return true;
}
#if 0
#include <stdio.h>
int main(int argc, char * argv[])
{
if(md2_test())
printf("MD2 algorithm work well!\n");
else
printf("MD2 algorithm doesn't work well.\n");
}
#endif

74
bertos/algo/md2.h Normal file
View file

@ -0,0 +1,74 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2007 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief MD2 Message-Digest algorithm.
*
* The algorithm takes as input a message of arbitrary length and produces
* as output a 128-bit message digest of the input.
* It is conjectured that it is computationally infeasible to produce
* two messages having the same message digest, or to produce any
* message having a given prespecified target message digest.
*
*
* \author Daniele Basile <asterix@develer.com>
*
* $WIZ$ module_name = "md2"
* $WIZ$ module_configuration = "bertos/cfg/cfg_md2.h"
*/
#ifndef ALGO_MD2_H
#define ALGO_MD2_H
#include "cfg/cfg_md2.h"
#include <cfg/compiler.h>
#define NUM_COMPUTE_ROUNDS 18 ///< Number of compute rounds.
#define COMPUTE_ARRAY_LEN CONFIG_MD2_BLOCK_LEN * 3 ///< Lenght of compute array.
#define MD2_DIGEST_LEN CONFIG_MD2_BLOCK_LEN
/**
* Context for MD2 computation.
*/
typedef struct Md2Context
{
uint8_t buffer[CONFIG_MD2_BLOCK_LEN]; ///< Input buffer.
uint8_t state[CONFIG_MD2_BLOCK_LEN]; ///< Current state buffer.
uint8_t checksum[CONFIG_MD2_BLOCK_LEN]; ///< Checksum.
size_t counter; ///< Counter of remaining bytes.
} Md2Context;
void md2_init(Md2Context *context);
void md2_update(Md2Context *context, const void *block_in, size_t block_len);
uint8_t *md2_end(Md2Context *context);
bool md2_test(void);
#endif /* ALGO_MD2_H */

41
bertos/algo/mean.h Normal file
View file

@ -0,0 +1,41 @@
#warning revise me!
/**
* DECLARE_SMEAN(temperature, uint8_t, uint16_t);
* for (i = 0; i < TEMP_MEANS; ++i)
* SMEAN_ADD(temperature, adc_get(), TEMP_MEANS);
* printf("mean temperature = %d\n", SMEAN_GET(temperature));
*/
/**
* Instantiate a mean instance
*/
#define DECLARE_SMEAN(name, Type, SumType) \
struct { \
SumType sum; \
Type result; \
int count; \
} name = { 0, 0, 0 }
/**
* Insert a new sample into the mean.
*
* \note \a mean and \a max_samples are evaluated multiple times
*/
#define SMEAN_ADD(mean, sample, max_samples) \
do { \
(mean).sum += (sample); \
if ((mean).count++ >= (max_samples)) \
{ \
(mean).result = (mean).sum / (max_samples); \
(mean).sum = 0; \
(mean).count = 0; \
} \
} while (0)
/**
* Return current mean value.
*/
#define SMEAN_GET(mean) ((mean).result)

115
bertos/algo/pid_control.c Normal file
View file

@ -0,0 +1,115 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* -->
*
*
* \brief Proportional, integral, derivative controller (PID controller) (implementation)
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#include "pid_control.h"
#include "cfg/cfg_pid.h"
// Define logging setting (for cfg/log.h module).
#define LOG_LEVEL PID_LOG_LEVEL
#define LOG_VERBOSITY PID_LOG_FORMAT
#include <cfg/log.h>
#include <cfg/debug.h>
/**
* Compute next value for reaching \a target point.
*/
piddata_t pid_control_update(PidContext *pid_ctx, piddata_t target, piddata_t curr_pos)
{
piddata_t P;
piddata_t I;
piddata_t D;
piddata_t err;
//Compute current error.
err = target - curr_pos;
/*
* Compute Proportional contribute
*/
P = err * pid_ctx->cfg->kp;
//Update integral state error
pid_ctx->i_state += err;
//Clamp integral state between i_min and i_max
pid_ctx->i_state = MINMAX(pid_ctx->cfg->i_min, pid_ctx->i_state, pid_ctx->cfg->i_max);
/*
* Compute Integral contribute
*
* note: for computing the integral contribute we use a sample period in seconds
* and so we divide sample_period in microsenconds for 1000.
*/
I = pid_ctx->i_state * pid_ctx->cfg->ki * ((piddata_t)pid_ctx->cfg->sample_period / 1000);
/*
* Compute derivative contribute
*/
D = (err - pid_ctx->prev_err) * pid_ctx->cfg->kd / ((piddata_t)pid_ctx->cfg->sample_period / 1000);
LOG_INFO("curr_pos[%lf],tgt[%lf],err[%f],P[%f],I[%f],D[%f]", curr_pos, target, err, P, I, D);
//Store the last error value
pid_ctx->prev_err = err;
piddata_t pid = MINMAX(pid_ctx->cfg->out_min, (P + I + D), pid_ctx->cfg->out_max);
LOG_INFO("pid[%lf]",pid);
//Clamp out between out_min and out_max
return pid;
}
/**
* Init PID control.
*/
void pid_control_init(PidContext *pid_ctx, const PidCfg *pid_cfg)
{
/*
* Init all values of pid control struct
*/
pid_ctx->cfg = pid_cfg;
pid_control_reset(pid_ctx);
}

115
bertos/algo/pid_control.h Normal file
View file

@ -0,0 +1,115 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* -->
*
*
* \brief Proportional, integral, derivative controller (PID controller).
*
*
* \author Daniele Basile <asterix@develer.com>
*
* $WIZ$ module_name = "pid_control"
* $WIZ$ module_depends = "timer"
*/
#ifndef ALGO_PID_CONTROL_H
#define ALGO_PID_CONTROL_H
#include <drv/timer.h>
/**
* Data type for pid coefficient.
*/
typedef float pidk_t;
typedef float piddata_t;
/**
* PID context structure.
*/
typedef struct PidCfg
{
pidk_t kp; ///< Proportional term of PID control method (Gain).
pidk_t ki; ///< Integral term of PID control method (Integral Gain).
pidk_t kd; ///< Derivative of PID control method (Derivative Gain).
piddata_t i_max; ///< Max value of integral term.
piddata_t i_min; ///< Min value of integral term.
piddata_t out_max; ///< Man value of output.
piddata_t out_min; ///< Min value of output.
mtime_t sample_period; ///< Sample period in milliseconds.
} PidCfg;
/**
* PID context structure.
*/
typedef struct PidContext
{
const PidCfg *cfg;
piddata_t prev_err; ///< Previous error.
piddata_t i_state; ///< Integrator state (sum of all the preceding errors).
} PidContext;
/**
* Set Kp, Ki, Kd constants of PID control.
*/
INLINE void pid_control_setPid(PidCfg *pid_cfg, pidk_t kp, pidk_t ki, pidk_t kd)
{
pid_cfg->kp = kp;
pid_cfg->ki = ki;
pid_cfg->kd = kd;
}
/**
* Set sample period for PID control.
*/
INLINE void pid_control_setPeriod(PidCfg *pid_cfg, mtime_t sample_period)
{
pid_cfg->sample_period = sample_period;
}
/**
* Clear a pid control structure
*/
INLINE void pid_control_reset(PidContext *pid_ctx)
{
pid_ctx->i_state = 0;
pid_ctx->prev_err = 0;
}
piddata_t pid_control_update(PidContext *pid_ctx, piddata_t target, piddata_t curr_pos);
void pid_control_init(PidContext *pid_ctx, const PidCfg *pid_cfg);
#endif /* ALGO_PID_CONTROL_H */

200
bertos/algo/ramp.c Normal file
View file

@ -0,0 +1,200 @@
/*!
* \file
* <!--
* Copyright 2004, 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Compute, save and load ramps for stepper motors (implementation)
*
*
* \author Simone Zinanni <s.zinanni@develer.com>
* \author Bernie Innocenti <bernie@codewiz.org>
* \author Giovanni Bajo <rasky@develer.com>
* \author Daniele Basile <asterix@develer.com>
*
*
* The formula used by the ramp is the following:
*
* <pre>
* a * b
* f(t) = -------------
* lerp(a,b,t)
* </pre>
*
* Where <code>a</code> and <code>b</code> are the maximum and minimum speed
* respectively (minimum and maximum wavelength respectively), and <code>lerp</code>
* is a linear interpolation with a factor:
*
* <pre>
* lerp(a,b,t) = a + t * (b - a) = (a * (1 - t)) + (b * t)
* </pre>
*
* <code>t</code> must be in the [0,1] interval. It is easy to see that the
* following holds true:
*
* <pre>
* f(0) = b, f(1) = a
* </pre>
*
* And that the function is monotonic. So, the function effectively interpolates
* between the maximum and minimum speed through its domain ([0,1] -> [b,a]).
*
* The curve drawn by this function is similar to 1 / (sqrt(n)), so it is slower
* than a linear acceleration (which would be 1/n).
*
* The floating point version uses a slightly modified function which accepts
* the parameter in the domain [0, MT] (where MT is maxTime, the length of the
* ramp, which is a setup parameter for the ramp). This is done to reduce the
* number of operations per step. The formula looks like this:
*
* <pre>
* a * b * MT
* g(t) = ----------------------------
* (a * MT) + t * (b - a)
* </pre>
*
* It can be shown that this <code>g(t) = f(t * MT)</code>. The denominator
* is a linear interpolation in the range [b*MT, a*MT], as t moves in the
* interval [0, MT]. So the interpolation interval of the function is again
* [b, a]. The implementation caches the value of the numerator and parts
* of the denominator, so that the formula becomes:
*
* <pre>
* alpha = a * b * MT
* beta = a * MT
* gamma = b - a
*
* alpha
* g(t) = ----------------------
* beta + t * gamma
* </pre>
*
* and <code>t</code> is exactly the parameter that ramp_evaluate() gets,
* that is the current time (in range [0, MT]). The operations performed
* for each step are just an addition, a multiplication and a division.
*
* The fixed point version of the formula instead transforms the original
* function as follows:
*
* <pre>
* a * b a
* f(t) = ------------------------- = --------------------
* a a
* b * ( - * (1 - t) + t ) - * (1 - t) + t
* b b
* </pre>
*
* <code>t</code> must be computed by dividing the current time (24 bit integer)
* by the maximum time (24 bit integer). This is done by precomputing the
* reciprocal of the maximum time as a 0.32 fixed point number, and multiplying
* it to the current time. Multiplication is performed 8-bits a time by
* FIX_MULT32(), so that we end up with a 0.16 fixed point number for
* <code>t</code> (and <code>1-t</code> is just its twos-complement negation).
* <code>a/b</code> is in the range [0,1] (because a is always less than b,
* being the minimum wavelength), so it is precomputed as a 0.16 fixed point.
* The final step is then computing the denominator and executing the division
* (32 cycles using the 1-step division instruction in the DSP).
*
* The assembly implementation is needed for efficiency, but a C version of it
* can be easily written, in case it is needed in the future.
*
*/
#include "ramp.h"
#include <cfg/debug.h>
#include <string.h> // memcpy()
void ramp_compute(struct Ramp *ramp, uint32_t clocksRamp, uint16_t clocksMinWL, uint16_t clocksMaxWL)
{
ASSERT(clocksMaxWL >= clocksMinWL);
// Save values in ramp struct
ramp->clocksRamp = clocksRamp;
ramp->clocksMinWL = clocksMinWL;
ramp->clocksMaxWL = clocksMaxWL;
#if RAMP_USE_FLOATING_POINT
ramp->precalc.gamma = ramp->clocksMaxWL - ramp->clocksMinWL;
ramp->precalc.beta = (float)ramp->clocksMinWL * (float)ramp->clocksRamp;
ramp->precalc.alpha = ramp->precalc.beta * (float)ramp->clocksMaxWL;
#else
ramp->precalc.max_div_min = ((uint32_t)clocksMinWL << 16) / (uint32_t)clocksMaxWL;
/* Calcola 1/total_time in fixed point .32. Assumiamo che la rampa possa al
* massimo avere 25 bit (cioé valore in tick fino a 2^25, che con il
* prescaler=3 sono circa 7 secondi). Inoltre, togliamo qualche bit di precisione
* da destra (secondo quanto specificato in RAMP_CLOCK_SHIFT_PRECISION).
*/
ASSERT(ramp->clocksRamp < (1UL << (24 + RAMP_CLOCK_SHIFT_PRECISION)));
ramp->precalc.inv_total_time = 0xFFFFFFFFUL / (ramp->clocksRamp >> RAMP_CLOCK_SHIFT_PRECISION);
ASSERT(ramp->precalc.inv_total_time < 0x1000000UL);
#endif
}
void ramp_setup(struct Ramp* ramp, uint32_t length, uint32_t minFreq, uint32_t maxFreq)
{
uint32_t minWL, maxWL;
minWL = TIME2CLOCKS(FREQ2MICROS(maxFreq));
maxWL = TIME2CLOCKS(FREQ2MICROS(minFreq));
ASSERT2(minWL < 65536UL, "Maximum frequency too high");
ASSERT2(maxWL < 65536UL, "Minimum frequency too high");
ASSERT(maxFreq > minFreq);
ramp_compute(
ramp,
TIME2CLOCKS(length),
TIME2CLOCKS(FREQ2MICROS(maxFreq)),
TIME2CLOCKS(FREQ2MICROS(minFreq))
);
}
void ramp_default(struct Ramp *ramp)
{
ramp_setup(ramp, RAMP_DEF_TIME, RAMP_DEF_MINFREQ, RAMP_DEF_MAXFREQ);
}
#if RAMP_USE_FLOATING_POINT
float ramp_evaluate(const struct Ramp* ramp, float curClock)
{
return ramp->precalc.alpha / (curClock * ramp->precalc.gamma + ramp->precalc.beta);
}
#else
INLINE uint32_t fix_mult32(uint32_t m1, uint32_t m2)
{
uint32_t accum = 0;
accum += m1 * ((m2 >> 0) & 0xFF);
accum >>= 8;
accum += m1 * ((m2 >> 8) & 0xFF);
accum >>= 8;
accum += m1 * ((m2 >> 16) & 0xFF);
return accum;
}
// a*b >> 16
INLINE uint16_t fix_mult16(uint16_t a, uint32_t b)
{
return (b*(uint32_t)a) >> 16;
}
uint16_t FAST_FUNC ramp_evaluate(const struct Ramp* ramp, uint32_t curClock)
{
uint16_t t = FIX_MULT32(curClock >> RAMP_CLOCK_SHIFT_PRECISION, ramp->precalc.inv_total_time);
uint16_t denom = fix_mult16((uint16_t)~t + 1, ramp->precalc.max_div_min) + t;
uint16_t cur_delta = ((uint32_t)ramp->clocksMinWL << 16) / denom;
return cur_delta;
}
#endif

166
bertos/algo/ramp.h Normal file
View file

@ -0,0 +1,166 @@
/**
* \file
* <!--
* Copyright 2004, 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Compute, save and load ramps for stepper motors.
*
* The acceleration ramp is used to properly accelerate a stepper motor. The main
* entry point is the function ramp_evaluate(), which must be called at every step
* of the motor: it gets as input the time elapsed since the stepper started
* accelerating, and returns the time to wait before sending the next step. A pseudo
* usage pattern is as follows:
*
* <pre>
* float time = 0;
* while (1)
* {
* float delta = ramp_evaluate(&my_ramp, time);
* sleep(delta);
* do_motor_step();
* time += delta;
* }
* </pre>
*
* A similar pattern can be used to decelerate (it is sufficient to move the total
* time backward, such as "time -= delta").
*
* The ramp can be configured with ramp_setup(), providing it with the minimum and
* maximum operating frequency of the motor, and the total acceleration time in
* milliseconds (that is, the time that will be needed to accelerate from the
* minimum frequency to the maximum frequency).
*
* Both a very precise floating point and a very fast fixed point implementation
* of the ramp evaluation are provided. The fixed point is hand-optimized assembly
* for DSP56000 (but a portable C version of it can be easily written, see the
* comments in the code).
*
*
* \author Simone Zinanni <s.zinanni@develer.com>
* \author Giovanni Bajo <rasky@develer.com>
* \author Daniele Basile <asterix@develer.com>
*
* $WIZ$ module_name = "ramp"
* $WIZ$ module_configuration = "bertos/cfg/cfg_ramp.h"
*/
#ifndef ALGO_RAMP_H
#define ALGO_RAMP_H
#include "hw/hw_stepper.h"
#include "cfg/cfg_ramp.h"
#include <cfg/compiler.h>
/**
* Convert microseconds to timer clock ticks
*/
#define TIME2CLOCKS(micros) ((uint32_t)(micros) * (STEPPER_CLOCK / 1000000))
/**
* Convert timer clock ticks back to microseconds
*/
#define CLOCKS2TIME(clocks) ((uint32_t)(clocks) / (STEPPER_CLOCK / 1000000))
/**
* Convert microseconds to Hz
*/
#define MICROS2FREQ(micros) (1000000UL / ((uint32_t)(micros)))
/**
* Convert frequency (in Hz) to time (in microseconds)
*/
#define FREQ2MICROS(hz) (1000000UL / ((uint32_t)(hz)))
/**
* Multiply \p a and \p b two integer at 32 bit and extract the high 16 bit word.
*/
#define FIX_MULT32(a,b) (((uint64_t)(a)*(uint32_t)(b)) >> 16)
/**
* Structure holding pre-calculated data for speeding up real-time evaluation
* of the ramp. This structure is totally different between the fixed and the
* floating point version of the code.
*
* Consult the file-level documentation of ramp.c for more information about
* the values of this structure.
*/
struct RampPrecalc
{
#if RAMP_USE_FLOATING_POINT
float beta;
float alpha;
float gamma;
#else
uint16_t max_div_min;
uint32_t inv_total_time;
#endif
};
/**
* Ramp structure
*/
struct Ramp
{
uint32_t clocksRamp;
uint16_t clocksMinWL;
uint16_t clocksMaxWL;
struct RampPrecalc precalc; ///< pre-calculated values for speed
};
/*
* Function prototypes
*/
void ramp_compute(
struct Ramp * ramp,
uint32_t clocksInRamp,
uint16_t clocksInMinWavelength,
uint16_t clocksInMaxWavelength);
/** Setup an acceleration ramp for a stepper motor
*
* \param ramp Ramp to fill
* \param length Length of the ramp (milliseconds)
* \param minFreq Minimum operating frequency of the motor (hertz)
* \param maxFreq Maximum operating frequency of the motor (hertz)
*
*/
void ramp_setup(struct Ramp* ramp, uint32_t length, uint32_t minFreq, uint32_t maxFreq);
/**
* Initialize a new ramp with default values
*/
void ramp_default(struct Ramp *ramp);
/**
* Evaluate the ramp at the given point. Given a \a ramp, and the current \a clock since
* the start of the acceleration, compute the next step, that is the interval at which
* send the signal to the motor.
*
* \note The fixed point version does not work when curClock is zero. Anyway,
* the first step is always clocksMaxWL, as stored within the ramp structure.
*/
#if RAMP_USE_FLOATING_POINT
float ramp_evaluate(const struct Ramp* ramp, float curClock);
#else
uint16_t ramp_evaluate(const struct Ramp* ramp, uint32_t curClock);
#endif
/** Self test */
int ramp_testSetup(void);
int ramp_testRun(void);
int ramp_testTearDown(void);
#endif /* ALGO_RAMP_H */

186
bertos/algo/ramp_test.c Normal file
View file

@ -0,0 +1,186 @@
/*!
* \file
* <!--
* Copyright 2004, 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Test for compute, save and load ramps for stepper motors (implementation)
*
*
* \author Simone Zinanni <s.zinanni@develer.com>
* \author Bernie Innocenti <bernie@codewiz.org>
* \author Giovanni Bajo <rasky@develer.com>
* \author Daniele Basile <asterix@develer.com>
*
*
* The formula used by the ramp is the following:
*
* <pre>
* a * b
* f(t) = -------------
* lerp(a,b,t)
* </pre>
*
* Where <code>a</code> and <code>b</code> are the maximum and minimum speed
* respectively (minimum and maximum wavelength respectively), and <code>lerp</code>
* is a linear interpolation with a factor:
*
* <pre>
* lerp(a,b,t) = a + t * (b - a) = (a * (1 - t)) + (b * t)
* </pre>
*
* <code>t</code> must be in the [0,1] interval. It is easy to see that the
* following holds true:
*
* <pre>
* f(0) = b, f(1) = a
* </pre>
*
* And that the function is monotonic. So, the function effectively interpolates
* between the maximum and minimum speed through its domain ([0,1] -> [b,a]).
*
* The curve drawn by this function is similar to 1 / (sqrt(n)), so it is slower
* than a linear acceleration (which would be 1/n).
*
* The floating point version uses a slightly modified function which accepts
* the parameter in the domain [0, MT] (where MT is maxTime, the length of the
* ramp, which is a setup parameter for the ramp). This is done to reduce the
* number of operations per step. The formula looks like this:
*
* <pre>
* a * b * MT
* g(t) = ----------------------------
* (a * MT) + t * (b - a)
* </pre>
*
* It can be shown that this <code>g(t) = f(t * MT)</code>. The denominator
* is a linear interpolation in the range [b*MT, a*MT], as t moves in the
* interval [0, MT]. So the interpolation interval of the function is again
* [b, a]. The implementation caches the value of the numerator and parts
* of the denominator, so that the formula becomes:
*
* <pre>
* alpha = a * b * MT
* beta = a * MT
* gamma = b - a
*
* alpha
* g(t) = ----------------------
* beta + t * gamma
* </pre>
*
* and <code>t</code> is exactly the parameter that ramp_evaluate() gets,
* that is the current time (in range [0, MT]). The operations performed
* for each step are just an addition, a multiplication and a division.
*
* The fixed point version of the formula instead transforms the original
* function as follows:
*
* <pre>
* a * b a
* f(t) = ------------------------- = --------------------
* a a
* b * ( - * (1 - t) + t ) - * (1 - t) + t
* b b
* </pre>
*
* <code>t</code> must be computed by dividing the current time (24 bit integer)
* by the maximum time (24 bit integer). This is done by precomputing the
* reciprocal of the maximum time as a 0.32 fixed point number, and multiplying
* it to the current time. Multiplication is performed 8-bits a time by
* FIX_MULT32(), so that we end up with a 0.16 fixed point number for
* <code>t</code> (and <code>1-t</code> is just its twos-complement negation).
* <code>a/b</code> is in the range [0,1] (because a is always less than b,
* being the minimum wavelength), so it is precomputed as a 0.16 fixed point.
* The final step is then computing the denominator and executing the division
* (32 cycles using the 1-step division instruction in the DSP).
*
* The assembly implementation is needed for efficiency, but a C version of it
* can be easily written, in case it is needed in the future.
*
*/
#include "ramp.h"
#include <cfg/debug.h>
#include <cfg/test.h>
static bool ramp_test_single(uint32_t minFreq, uint32_t maxFreq, uint32_t length)
{
struct Ramp r;
uint16_t cur, old;
uint32_t clock;
uint32_t oldclock;
ramp_setup(&r, length, minFreq, maxFreq);
cur = old = r.clocksMaxWL;
clock = 0;
oldclock = 0;
kprintf("testing ramp: (length=%lu, min=%lu, max=%lu)\n", (unsigned long)length, (unsigned long)minFreq, (unsigned long)maxFreq);
kprintf(" [length=%lu, max=%04x, min=%04x]\n", (unsigned long)r.clocksRamp, r.clocksMaxWL, r.clocksMinWL);
int i = 0;
int nonbyte = 0;
while (clock + cur < r.clocksRamp)
{
oldclock = clock;
old = cur;
clock += cur;
cur = ramp_evaluate(&r, clock);
if (old < cur)
{
uint16_t t1 = FIX_MULT32(oldclock >> RAMP_CLOCK_SHIFT_PRECISION, r.precalc.inv_total_time);
uint16_t t2 = FIX_MULT32(clock >> RAMP_CLOCK_SHIFT_PRECISION, r.precalc.inv_total_time);
uint16_t denom1 = FIX_MULT32((uint16_t)((~t1) + 1), r.precalc.max_div_min) + t1;
uint16_t denom2 = FIX_MULT32((uint16_t)((~t2) + 1), r.precalc.max_div_min) + t2;
kprintf(" Failed: %04x @ %lu --> %04x @ %lu\n", old, (unsigned long)oldclock, cur, (unsigned long)clock);
kprintf(" T: %04x -> %04x\n", t1, t2);
kprintf(" DENOM: %04x -> %04x\n", denom1, denom2);
cur = ramp_evaluate(&r, clock);
return false;
}
i++;
if ((old-cur) >= 256)
nonbyte++;
}
kprintf("Test finished: %04x @ %lu [min=%04x, totlen=%lu, numsteps:%d, nonbyte:%d]\n", cur, (unsigned long)clock, r.clocksMinWL, (unsigned long)r.clocksRamp, i, nonbyte);
return true;
}
int ramp_testSetup(void)
{
kdbg_init();
return 0;
}
int ramp_testTearDown(void)
{
return 0;
}
int ramp_testRun(void)
{
#define TEST_RAMP(min, max, len) do { \
if (!ramp_test_single(min, max, len)) \
return -1; \
} while(0)
TEST_RAMP(200, 5000, 3000000);
TEST_RAMP(1000, 2000, 1000000);
return 0;
}
TEST_MAIN(ramp);

52
bertos/algo/rand.c Normal file
View file

@ -0,0 +1,52 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2006 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief Very simple rand() algorithm.
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#include "rand.h"
/**
* This would really belong to libc
*/
int rand(void)
{
static unsigned long seed;
/* Randomize seed */
seed = (seed ^ 0x4BAD5A39UL) + 6513973UL;
return (int)(seed>>16);
}

44
bertos/algo/rand.h Normal file
View file

@ -0,0 +1,44 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2006 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief Very simple rand() algorithm.
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#ifndef RAND_H
#define RAND_H
int rand(void);
#endif

257
bertos/algo/randpool.c Normal file
View file

@ -0,0 +1,257 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2007 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief API function for to manage entropy pool.
*
* \author Daniele Basile <asterix@develer.com>
*/
#include "randpool.h"
#include "md2.h"
#include <cfg/compiler.h>
#include <cfg/debug.h> //ASSERT()
#include <cfg/macros.h> //MIN(), ROUND_UP();
#include <stdio.h> //sprintf();
#include <string.h> //memset(), memcpy();
#if CONFIG_RANDPOOL_TIMER
#include <drv/timer.h> //timer_clock();
#endif
/*
* Insert bytes in entropy pool, making a XOR of bytes present
* in entropy pool.
*/
static void randpool_push(EntropyPool *pool, void *_byte, size_t n_byte)
{
size_t i = pool->pos_add; // Current number of byte insert in entropy pool.
uint8_t *byte;
byte = (uint8_t *)_byte;
/*
* Insert a bytes in entropy pool.
*/
for(size_t j = 0; j < n_byte; j++)
{
pool->pool_entropy[i] = pool->pool_entropy[i] ^ byte[j];
i++;
i = i % CONFIG_SIZE_ENTROPY_POOL;
}
pool->pos_add = i; // Update a insert bytes.
}
/*
* This function stir entropy pool with MD2 function hash.
*
*/
static void randpool_stir(EntropyPool *pool)
{
size_t entropy = pool->entropy; //Save current calue of entropy.
Md2Context context;
uint8_t tmp_buf[((sizeof(size_t) * 2) + sizeof(int)) * 2 + 1]; //Temporary buffer.
md2_init(&context); //Init MD2 algorithm.
randpool_add(pool, NULL, 0);
for (int i = 0; i < (CONFIG_SIZE_ENTROPY_POOL / MD2_DIGEST_LEN); i++)
{
sprintf((char *)tmp_buf, "%0x%0x%0x", pool->counter, i, pool->pos_add);
/*
* Hash with MD2 algorithm the entropy pool.
*/
md2_update(&context, pool->pool_entropy, CONFIG_SIZE_ENTROPY_POOL);
md2_update(&context, tmp_buf, sizeof(tmp_buf) - 1);
/*Insert a message digest in entropy pool.*/
randpool_push(pool, md2_end(&context), MD2_DIGEST_LEN);
pool->counter = pool->counter + 1;
}
/*Insert in pool the difference between a two call of this function (see above).*/
randpool_add(pool, NULL, 0);
pool->entropy = entropy; //Restore old value of entropy. We haven't add entropy.
}
/**
* Add \param entropy bits from \param data buffer to the entropy \param pool
*/
void randpool_add(EntropyPool *pool, void *data, size_t entropy)
{
uint8_t sep[] = "\xaa\xaa\xaa\xaa"; // ??
size_t data_len = ROUND_UP(entropy, 8) / 8; //Number of entropy byte in input.
randpool_push(pool, data, data_len); //Insert data to entropy pool.
#if CONFIG_RANDPOOL_TIMER
ticks_t event = timer_clock();
ticks_t delta;
/*Difference of time between a two accese to entropy pool.*/
delta = event - pool->last_counter;
randpool_push(pool, &event, sizeof(ticks_t));
randpool_push(pool, sep, sizeof(sep) - 1); // ??
randpool_push(pool, &delta, sizeof(delta));
/*
* Count of number entropy bit add with delta.
*/
delta = delta & 0xff;
while(delta)
{
delta >>= 1;
entropy++;
}
pool->last_counter = event;
#endif
pool->entropy += entropy; //Update a entropy of the pool.
}
/**
* Randpool function initialization.
* The entropy pool can be initialize also with
* a previous entropy pool.
*/
void randpool_init(EntropyPool *pool, void *_data, size_t len)
{
uint8_t *data;
data = (uint8_t *)_data;
memset(pool, 0, sizeof(EntropyPool));
pool->pos_get = MD2_DIGEST_LEN;
#if CONFIG_RANDPOOL_TIMER
pool->last_counter = timer_clock();
#endif
if(data)
{
/*
* Initialize a entropy pool with a
* previous pool, and assume all pool as
* entropy.
*/
len = MIN(len,(size_t)CONFIG_SIZE_ENTROPY_POOL);
memcpy(pool->pool_entropy, data, len);
pool->entropy = len;
}
}
/**
* Get the actual value of entropy.
*/
size_t randpool_size(EntropyPool *pool)
{
return pool->entropy;
}
/**
* Get \param n_byte from entropy pool. If n_byte is larger than number
* byte of entropy in entropy pool, randpool_get continue
* to generate pseudocasual value from previous state of
* pool.
* \param n_byte number fo bytes to read.
* \param pool is the pool entropy context.
* \param _data is the pointer to write the random data to.
*/
void randpool_get(EntropyPool *pool, void *_data, size_t n_byte)
{
Md2Context context;
size_t i = pool->pos_get;
size_t n = n_byte;
size_t pos_write = 0; //Number of block has been written in data.
size_t len = MIN((size_t)MD2_DIGEST_LEN, n_byte);
uint8_t *data;
data = (uint8_t *)_data;
/* Test if i + CONFIG_MD2_BLOCK_LEN is inside of entropy pool.*/
ASSERT((MD2_DIGEST_LEN + i) <= CONFIG_SIZE_ENTROPY_POOL);
md2_init(&context);
while(n > 0)
{
/*Hash previous state of pool*/
md2_update(&context, &pool->pool_entropy[i], MD2_DIGEST_LEN);
memcpy(&data[pos_write], md2_end(&context), len);
pos_write += len; //Update number of block has been written in data.
n -= len; //Number of byte copied in data.
len = MIN(n,(size_t)MD2_DIGEST_LEN);
i = (i + MD2_DIGEST_LEN) % CONFIG_SIZE_ENTROPY_POOL;
/* If we haven't more entropy pool to hash, we stir it.*/
if(i < MD2_DIGEST_LEN)
{
randpool_stir(pool);
i = pool->pos_get;
}
}
pool->pos_get = i; //Current number of byte we get from pool.
pool->entropy -= n_byte; //Update a entropy.
}
/**
* Return a pointer to entropy pool.
*/
uint8_t *randpool_pool(EntropyPool *pool)
{
return pool->pool_entropy;
}

75
bertos/algo/randpool.h Normal file
View file

@ -0,0 +1,75 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2007 Develer S.r.l. (http://www.develer.com/);
*
* -->
*
* \brief Collection of functions to manage entropy pool.
*
*
* \author Daniele Basile <asterix@develer.com>
*
* $WIZ$ module_name = "randpool"
* $WIZ$ module_depends = "timer", "sprintf"
* $WIZ$ module_configuration = "bertos/cfg/cfg_randpool.h"
*/
#ifndef ALGO_RANDPOOL_H
#define ALGO_RANDPOOL_H
#include "cfg/cfg_randpool.h"
#include <cfg/compiler.h>
/**
* Sturct data of entropy pool.
*/
typedef struct EntropyPool
{
size_t entropy; ///< Actual value of entropy (byte).
size_t pos_add; ///< Number of byte added in entropy pool.
size_t pos_get; ///< Number of byte got in entropy pool.
size_t counter; ///< Counter.
#if CONFIG_RANDPOOL_TIMER
size_t last_counter; ///< Last timer value.
#endif
uint8_t pool_entropy[CONFIG_SIZE_ENTROPY_POOL]; ///< Entropy pool.
} EntropyPool;
void randpool_add(EntropyPool *pool, void *data, size_t entropy);
void randpool_init(EntropyPool *pool, void *_data, size_t len);
size_t randpool_size(EntropyPool *pool);
void randpool_get(EntropyPool *pool, void *data, size_t n_byte);
uint8_t *randpool_pool(EntropyPool *pool);
#endif /* ALGO_RANDPOOL_H */

View file

@ -0,0 +1,87 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief REVERSE macro test.
*
* \author Francesco Sacchi <batt@develer.com>
*/
#include <cfg/macros.h>
#include <cfg/debug.h>
#include <cfg/test.h>
/* Silent compiler warning */
int reverse_testSetup(void);
int reverse_testRun(void);
int reverse_testTearDown(void);
int reverse_testSetup(void)
{
kdbg_init();
return 0;
}
int reverse_testTearDown(void)
{
return 0;
}
/**
* Naive reverse implementation.
*/
static uint8_t reverse(uint8_t b)
{
uint8_t r = 0;
for (int i = 0; i < 8; i++)
{
r <<= 1;
r |= (b & BV(i)) ? 1 : 0;
}
return r;
}
int reverse_testRun(void)
{
for (int i = 0; i < 256; i++)
{
kprintf("i [%02X], REVERSE(i) [%02X], reverse(i) [%02X]\n", i, REVERSE_UINT8(i), reverse(i));
ASSERT(reverse(i) == REVERSE_UINT8(i));
}
return 0;
}
TEST_MAIN(reverse);

150
bertos/algo/rle.c Normal file
View file

@ -0,0 +1,150 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief General-purpose run-length {en,de}coding algorithm (implementation)
*
* Original source code from http://www.compuphase.com/compress.htm
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#include "rle.h"
/**
* Run-length encode \a len bytes from the \a input buffer
* to the \a output buffer.
*/
int rle(unsigned char *output, const unsigned char *input, int len)
{
int count, index, i;
unsigned char first;
unsigned char *out;
out = output;
count = 0;
while (count < len)
{
index = count;
first = input[index++];
/* Scan for bytes identical to the first one */
while ((index < len) && (index - count < 127) && (input[index] == first))
index++;
if (index - count == 1)
{
/* Failed to "replicate" the current byte. See how many to copy.
*/
while ((index < len) && (index - count < 127))
{
/* Avoid a replicate run of only 2-bytes after a literal run.
* There is no gain in this, and there is a risc of loss if the
* run after the two identical bytes is another literal run.
* So search for 3 identical bytes.
*/
if ((input[index] == input[index - 1]) &&
((index > 1) && (input[index] == input[index - 2])))
{
/* Reset the index so we can back up these three identical
* bytes in the next run.
*/
index -= 2;
break;
}
index++;
}
/* Output a run of uncompressed bytes: write length and values */
*out++ = (unsigned char)(count - index);
for (i = count; i < index; i++)
*out++ = input[i];
}
else
{
/* Output a compressed run: write length and value */
*out++ = (unsigned char)(index - count);
*out++ = first;
}
count = index;
}
/* Output EOF marker */
*out++ = 0;
return (out - output);
}
/**
* Run-length decode from the \a input buffer to the \a output
* buffer.
*
* \note The output buffer must be large enough to accomodate
* all decoded output.
*/
int unrle(unsigned char *output, const unsigned char *input)
{
signed char count;
unsigned char *out;
unsigned char value;
out = output;
for (;;)
{
count = (signed char)*input++;
if (count > 0)
{
/* replicate run */
value = *input++;
while (count--)
*out++ = value;
}
else if (count < 0)
{
/* literal run */
while (count++)
*out++ = *input++;
}
else
/* EOF */
break;
}
return (out - output);
}

46
bertos/algo/rle.h Normal file
View file

@ -0,0 +1,46 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief General-purpose run-length {en,de}coding algorithm.
*
* \author Bernie Innocenti <bernie@codewiz.org>
*
* $WIZ$ module_name = "rle"
*/
#ifndef RLE_H
#define RLE_H
int rle(unsigned char *output, const unsigned char *input, int length);
int unrle(unsigned char *output, const unsigned char *input);
#endif /* RLE_H */

View file

@ -0,0 +1,83 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2007 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Rotating Hash algorithm.
*
* This is a simple yet powerfull checksum algorithm.
* Instead of just xor-ing the data, rotating hash
* circular shift the checksum 4 place left before xoring.
* This is a bit more stronger than simply sum the data.
*
*
* \author Francesco Sacchi <batt@develer.com>
*
* $WIZ$ module_name = "rotating_hash"
*/
#ifndef ALGO_ROTATING_H
#define ALGO_ROTATING_H
#include <cfg/compiler.h>
typedef uint16_t rotating_t;
/**
* Init rotating checksum.
*/
INLINE void rotating_init(rotating_t *rot)
{
*rot = 0;
}
/**
* Update checksum pointed by \c rot with \c c data.
*/
INLINE void rotating_update1(uint8_t c, rotating_t *rot)
{
*rot = (*rot << 4) ^ (*rot >> 12) ^ c;
}
/**
* Update checksum pointed by \c rot with data supplied in \c buf.
*/
INLINE void rotating_update(const void *_buf, size_t len, rotating_t *rot)
{
const uint8_t *buf = (const uint8_t *)_buf;
while (len--)
rotating_update1(*buf++, rot);
}
#endif // ALGO_ROTATING_H

131
bertos/algo/tea.c Normal file
View file

@ -0,0 +1,131 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2006 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief TEA Tiny Encription Algorith functions (implementation).
*
* \author Francesco Sacchi <batt@develer.com>
*
* The Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham
* of the Cambridge Computer Laboratory
*
* Placed in the Public Domain by David Wheeler and Roger Needham.
*
* **** ANSI C VERSION ****
*
* Notes:
*
* TEA is a Feistel cipher with XOR and and addition as the non-linear
* mixing functions.
*
* Takes 64 bits of data in v[0] and v[1]. Returns 64 bits of data in w[0]
* and w[1]. Takes 128 bits of key in k[0] - k[3].
*
* TEA can be operated in any of the modes of DES. Cipher Block Chaining is,
* for example, simple to implement.
*
* n is the number of iterations. 32 is ample, 16 is sufficient, as few
* as eight may be OK. The algorithm achieves good dispersion after six
* iterations. The iteration count can be made variable if required.
*
* Note this is optimised for 32-bit CPUs with fast shift capabilities. It
* can very easily be ported to assembly language on most CPUs.
*
* delta is chosen to be the real part of (the golden ratio Sqrt(5/4) -
* 1/2 ~ 0.618034 multiplied by 2^32).
*/
#include "tea.h"
#include <cpu/byteorder.h>
static uint32_t tea_func(uint32_t *in, uint32_t *sum, uint32_t *k)
{
return ((*in << 4) + cpu_to_le32(k[0])) ^ (*in + *sum) ^ ((*in >> 5) + cpu_to_le32(k[1]));
}
/**
* \brief TEA encryption function.
* This function encrypts <EM>v</EM> with <EM>k</EM> and returns the
* encrypted data in <EM>v</EM>.
* \param _v Array of two long values containing the data block.
* \param _k Array of four long values containing the key.
*/
void tea_enc(void *_v, void *_k)
{
uint32_t y, z;
uint32_t sum = 0;
uint8_t n = ROUNDS;
uint32_t *v = (uint32_t *)_v;
uint32_t *k = (uint32_t *)_k;
y=cpu_to_le32(v[0]);
z=cpu_to_le32(v[1]);
while(n-- > 0)
{
sum += DELTA;
y += tea_func(&z, &sum, &(k[0]));
z += tea_func(&y, &sum, &(k[2]));
}
v[0] = le32_to_cpu(y);
v[1] = le32_to_cpu(z);
}
/**
* \brief TEA decryption function.
* This function decrypts <EM>v</EM> with <EM>k</EM> and returns the
* decrypted data in <EM>v</EM>.
* \param _v Array of two long values containing the data block.
* \param _k Array of four long values containing the key.
*/
void tea_dec(void *_v, void *_k)
{
uint32_t y, z;
uint32_t sum = DELTA * ROUNDS;
uint8_t n = ROUNDS;
uint32_t *v = (uint32_t *)_v;
uint32_t *k = (uint32_t *)_k;
y = cpu_to_le32(v[0]);
z = cpu_to_le32(v[1]);
while(n-- > 0)
{
z -= tea_func(&y, &sum, &(k[2]));
y -= tea_func(&z, &sum, &(k[0]));
sum -= DELTA;
}
v[0] = le32_to_cpu(y);
v[1] = le32_to_cpu(z);
}

58
bertos/algo/tea.h Normal file
View file

@ -0,0 +1,58 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2006 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief TEA Tiny Encription Algorith functions.
*
* Documentation for TEA is available at
* http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm
*
* \author Francesco Sacchi <batt@develer.com>
*
* $WIZ$ module_name = "tea"
*/
#ifndef ALGO_TEA_H
#define ALGO_TEA_H
#include <cfg/compiler.h>
#define TEA_KEY_LEN 16 //!< TEA key size.
#define TEA_BLOCK_LEN 8 //!< TEA block length.
#define DELTA 0x9E3779B9 //!< Magic value. (Golden number * 2^31)
#define ROUNDS 32 //!< Number of rounds.
void tea_enc(void *_v, void *_k);
void tea_dec(void *_v, void *_k);
#endif /* ALGO_TEA_H */

View file

@ -0,0 +1,136 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Context switch benchmark
*
* \author Andrea Righi <arighi@develer.com>
* \author Daniele Basiele <asterix@develer.com>
*/
#include "context_switch.h"
#include "hw/hw_led.h"
#include "cfg/cfg_context_switch.h"
#include <cfg/debug.h>
#include <cpu/irq.h>
#include <cpu/power.h>
#include <drv/timer.h>
#if CONFIG_USE_HP_TIMER
#include <drv/ser.h>
static Serial out;
#endif
#include <kern/proc.h>
#define PROC_STACK_SIZE KERN_MINSTACKSIZE
static PROC_DEFINE_STACK(hp_stack, PROC_STACK_SIZE);
static PROC_DEFINE_STACK(lp_stack, PROC_STACK_SIZE);
static Process *hp_proc, *lp_proc, *main_proc;
#if CONFIG_USE_HP_TIMER
static hptime_t start, end;
#endif
static void NORETURN hp_process(void)
{
while (1)
{
sig_wait(SIG_USER0);
#if CONFIG_USE_LED
LED_ON();
#endif
#if CONFIG_USE_HP_TIMER
end = timer_hw_hpread();
#endif
sig_send(main_proc, SIG_USER0);
}
}
static void NORETURN lp_process(void)
{
while (1)
{
sig_wait(SIG_USER0);
#if CONFIG_USE_LED
LED_ON();
LED_OFF();
#endif
#if CONFIG_USE_HP_TIMER
start = timer_hw_hpread();
#endif
sig_send(hp_proc, SIG_USER0);
}
}
void NORETURN context_switch(void)
{
IRQ_ENABLE;
timer_init();
proc_init();
#if CONFIG_USE_HP_TIMER
ser_init(&out, CONFIG_CTX_DEBUG_PORT);
ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE);
#endif
#if CONFIG_USE_LED
LED_INIT();
#endif
proc_forbid();
hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack);
lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack);
main_proc = proc_current();
proc_setPri(hp_proc, 2);
proc_setPri(lp_proc, 1);
proc_permit();
while (1)
{
timer_delay(100);
sig_send(lp_proc, SIG_USER0);
sig_wait(SIG_USER0);
#if CONFIG_USE_HP_TIMER
kfile_printf(&out.fd,
"Switch: %lu.%lu usec\n\r",
hptime_to_us((end - start)),
hptime_to_us((end - start) * 1000) % 1000);
#endif
}
}

View file

@ -0,0 +1,49 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Context switch benchmark
*
* \author Andrea Righi <arighi@develer.com>
* \author Daniele Basiele <asterix@develer.com>
*
* $WIZ$ module_name = "context_switch"
* $WIZ$ module_depends = "kfile", "kern", "signal", "timer"
* $WIZ$ module_configuration = "bertos/cfg/cfg_context_switch.h"
* $WIZ$ module_hw = "bertos/hw/hw_led.h"
*/
#ifndef BENCHMARK_CONTEXT_SWITCH_H
#define BENCHMARK_CONTEXT_SWITCH_H
void context_switch(void);
#endif /* BENCHMARK_CONTEXT_SWITCH_H */

View file

@ -0,0 +1,96 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \author Luca Ottaviano <lottaviano@develer.com>
* \author Andrea Righi <arighi@develer.com>
* \author Daniele Basile <asterix@develer.com>
*
* \brief Kernel footprint benchmark.
*/
#include "kernel_footprint.h"
#include <cpu/irq.h>
#include <kern/proc.h>
#include <kern/signal.h>
#include <kern/msg.h>
#include <kern/sem.h>
MsgPort in_port;
static void init(void)
{
IRQ_ENABLE;
proc_init();
}
static PROC_DEFINE_STACK(proc1_stack, KERN_MINSTACKSIZE);
static NORETURN void proc1_main(void)
{
int i;
for(;;)
{
i++;
}
}
void kernel_footprint(void)
{
init();
// generate code for process
struct Process *p =
proc_new(proc1_main, 0, sizeof(proc1_stack), proc1_stack);
proc_setPri(p, 5);
proc_yield();
// generate code for msg
Msg msg;
msg_initPort(&in_port, event_createSignal(p, SIG_USER1));
msg_put(&in_port, &msg);
msg_peek(&in_port);
Msg *msg_re = msg_get(&in_port);
msg_reply(msg_re);
// generate code for signals
sig_send(p, SIG_USER0);
// generate code for msg
Semaphore sem;
sem_init(&sem);
sem_obtain(&sem);
sem_release(&sem);
sig_wait(SIG_USER0);
}

View file

@ -0,0 +1,46 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \author Daniele Basile <asterix@develer.com>
*
* \brief Kernel footprint benchmark.
*
* $WIZ$ module_name = "kernel_footprint"
* $WIZ$ module_depends = "kfile", "kern", "signal", "msg", "semaphores", "event"
*/
#ifndef BENCHMARK_KERNEL_FOOTPRINT_H
#define BENCHMARK_KERNEL_FOOTPRINT_H
void kernel_footprint(void);
#endif /* BENCHMARK_KERNEL_FOOTPRINT_H */

149
bertos/cfg/cfg_adc.h Normal file
View file

@ -0,0 +1,149 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for the ADC module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_ADC_H
#define CFG_ADC_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define ADC_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define ADC_LOG_FORMAT LOG_FMT_VERBOSE
/**
* Clock Frequency for ADC conversion.
* This frequency will be rounded down to an integer
* submultiple of CPU_FREQ.
*
* $WIZ$ type = "int"
* $WIZ$ supports = "at91"
* $WIZ$ max = 5000000
*/
#define CONFIG_ADC_CLOCK 4800000UL
/**
* Minimum time for starting up a conversion [us].
*
* $WIZ$ type = "int"
* $WIZ$ min = 20
* $WIZ$ supports = "at91"
*/
#define CONFIG_ADC_STARTUP_TIME 20
/**
* Minimum time for sample and hold [ns].
*
* $WIZ$ type = "int"
* $WIZ$ min = 600
* $WIZ$ supports = "at91"
*/
#define CONFIG_ADC_SHTIME 834
/**
* ADC Voltage Reference.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "avr_adc_refs"
* $WIZ$ supports = "avr"
*/
#define CONFIG_ADC_AVR_REF ADC_AVR_AVCC
/**
* ADC clock divisor from main crystal.
*
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ max = 128
* $WIZ$ supports = "avr"
*/
#define CONFIG_ADC_AVR_DIVISOR 2
/**
* Enable ADC strobe for debugging ADC ISR.
*
* $WIZ$ type = "boolean"
*/
#define CONFIG_ADC_STROBE 0
/**
* Start up timer[s] = startup value / ADCClock [Hz]
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "sam3_adc_sut"
* $WIZ$ supports = "sam3"
*/
#define CONFIG_ADC_SUT ADC_SUT512
/**
* Analog Settling Time[s] = settling value / ADCClock[Hz]
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "sam3_adc_stt"
* $WIZ$ supports = "sam3"
*/
#define CONFIG_ADC_STTLING ADC_AST17
/**
* Tracking Time[s] = (TRACKTIM + 1) / ADCClock[Hz]
*
* $WIZ$ type = "int"
* $WIZ$ min = 0
* $WIZ$ supports = "sam3"
*/
#define CONFIG_ADC_TRACKTIM 0
/**
* Transfer Period[s] = (TRANSFER * 2 + 3) ADCClock[Hz]
*
* $WIZ$ type = "int"
* $WIZ$ min = 0
* $WIZ$ supports = "sam3"
*/
#define CONFIG_ADC_TRANSFER 1
#endif /* CFG_ADC_H */

113
bertos/cfg/cfg_afsk.h Normal file
View file

@ -0,0 +1,113 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for AFSK1200 modem.
*
* \author Francesco Sacchi <asterix@develer.com>
*/
#ifndef CFG_AFSK_H
#define CFG_AFSK_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define AFSK_LOG_LEVEL LOG_LVL_WARN
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define AFSK_LOG_FORMAT LOG_FMT_TERSE
/**
* AFSK discriminator filter type.
*
* $WIZ$ type = "enum"; value_list = "afsk_filter_list"
*/
#define CONFIG_AFSK_FILTER AFSK_CHEBYSHEV
/**
* AFSK receiver buffer length.
*
* $WIZ$ type = "int"
* $WIZ$ min = 2
*/
#define CONFIG_AFSK_RX_BUFLEN 32
/**
* AFSK transimtter buffer length.
*
* $WIZ$ type = "int"
* $WIZ$ min = 2
*/
#define CONFIG_AFSK_TX_BUFLEN 32
/**
* AFSK DAC sample rate for modem outout.
* $WIZ$ type = "int"
* $WIZ$ min = 2400
*/
#define CONFIG_AFSK_DAC_SAMPLERATE 9600
/**
* AFSK RX timeout in ms, set to -1 to disable.
* $WIZ$ type = "int"
* $WIZ$ min = -1
*/
#define CONFIG_AFSK_RXTIMEOUT 0
/**
* AFSK Preamble length in [ms], before starting transmissions.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_AFSK_PREAMBLE_LEN 300UL
/**
* AFSK Trailer length in [ms], before stopping transmissions.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_AFSK_TRAILER_LEN 50UL
#endif /* CFG_AFSK_H */

52
bertos/cfg/cfg_arch.h Normal file
View file

@ -0,0 +1,52 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 2001,2002,2003 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief Set system configuration.
*
*
* \author Bernie Innocenti <bernie@codewiz.org>
*
*/
#ifndef CFG_ARCH_CONFIG_H
#define CFG_ARCH_CONFIG_H
#define ARCH_DEFAULT (1<<0) ///< Default architecture
#define ARCH_EMUL (1<<2) ///< EMUL architecture
#define ARCH_QT (1<<3) ///< QT architecture
#define ARCH_UNITTEST (1<<4) ///< UNITTEST architecture
#define ARCH_NIGHTTEST (1<<5) ///< NIGHTTEST architecture
#endif /* CFG_ARCH_CONFIG_H */

46
bertos/cfg/cfg_attr.h Normal file
View file

@ -0,0 +1,46 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for Debug module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_ATTR_H
#define CFG_ATTR_H
/// Put a function or critical code in fast memory.
#define CONFIG_FAST_MEM 0
#endif /* CFG_ATTR_H */

75
bertos/cfg/cfg_ax25.h Normal file
View file

@ -0,0 +1,75 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for the AX25 protocol module.
*
* \author Francesco Sacchi <batt@develer.com>
*/
#ifndef CFG_AX25_H
#define CFG_AX25_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define AX25_LOG_LEVEL LOG_LVL_WARN
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define AX25_LOG_FORMAT LOG_FMT_TERSE
/**
* AX25 frame buffer lenght.
*
* $WIZ$ type = "int"
* $WIZ$ min = 18
*/
#define CONFIG_AX25_FRAME_BUF_LEN 330
/**
* Enable repeaters listing in AX25 frames.
* If enabled use 56 addtional bytes of RAM
* for each message received.
*
* $WIZ$ type = "boolean"
*/
#define CONFIG_AX25_RPT_LST 1
#endif /* CFG_AX25_H */

67
bertos/cfg/cfg_battfs.h Normal file
View file

@ -0,0 +1,67 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for BattFS module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_BATTFS_H
#define CFG_BATTFS_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define BATTFS_LOG_LEVEL LOG_LVL_INFO
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define BATTFS_LOG_FORMAT LOG_FMT_VERBOSE
/**
* Set to 1 to enable free page shuffling.
* This increase memories life but makes debugging
* more difficult due to its unrepeteable state.
* $WIZ$ type = "boolean"
*/
#define CONFIG_BATTFS_SHUFFLE_FREE_PAGES 0
#endif /* BATTFS */

46
bertos/cfg/cfg_boot.h Normal file
View file

@ -0,0 +1,46 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
* -->
*
* \author Daniele Basile <asterix@develer.com>
*
* \brief Configuration file for bootloader module.
*/
#ifndef CFG_BOOT_H
#define CFG_BOOT_H
/// Bootloader log level
#define CONFIG_BOOT_LOG_LEVEL LOG_LVL_INFO
/// Bootoloader log format
#define CONFIG_BOOT_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_FLASH_AT91_H */

View file

@ -0,0 +1,47 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for buzzerled module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_BUZZERLED_H
#define CFG_BUZZERLED_H
/// TODO
#define CONFIG_NUM_BLDS 1
#endif /* CFG_BUZZERLED_H */

View file

@ -0,0 +1,71 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for the context switch benchmark.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_CONTEXT_SWITCH_H
#define CFG_CONTEXT_SWITCH_H
/**
* Use hp timer for the bechmark.
*
* $WIZ$ type = "boolean"
* $WIZ$ module= "boolean"
* $WIZ$ conditional_deps = "ser"
*/
#define CONFIG_USE_HP_TIMER 1
/**
* Use board led for benchmark.
*
* $WIZ$ type = "boolean"
*/
#define CONFIG_USE_LED 1
/**
* Debug console port.
* $WIZ$ type = "int"; min = 0
*/
#define CONFIG_CTX_DEBUG_PORT 0
/**
* Baudrate for the debug console.
* $WIZ$ type = "int"; min = 300
*/
#define CONFIG_CTX_DEBUG_BAUDRATE 115200UL
#endif /* CFG_CONTEXT_SWITCH_H */

88
bertos/cfg/cfg_dac.h Normal file
View file

@ -0,0 +1,88 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2011 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for DAC module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_DAC_H
#define CFG_DAC_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define DAC_LOG_LEVEL LOG_LVL_WARN
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define DAC_LOG_FORMAT LOG_FMT_TERSE
/**
* DAC Refresh Period = 1024*REFRESH/DACC Clock
*
* $WIZ$ type = "int"
* $WIZ$ supports = "sam3x"
* $WIZ$ min = 0
* $WIZ$ max = 65536
*/
#define CONFIG_DAC_REFRESH 16
/**
* DAC Startup Time Selection.
* see datasheet table.
*
* $WIZ$ type = "int"
* $WIZ$ supports = "sam3x"
* $WIZ$ min = 0
* $WIZ$ max = 63
*/
#define CONFIG_DAC_STARTUP 0
/**
* DAC Trigger Selection.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "sam3x_dac_tc"
* $WIZ$ supports = "sam3x"
*/
#define CONFIG_DAC_TIMER DACC_TRGSEL_TIO_CH0
#endif /* CFG_DAC_H */

View file

@ -0,0 +1,55 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for data flash memory module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_DATAFLASH_H
#define CFG_DATAFLASH_H
/**
* Module logging level.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define DATAFLASH_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define DATAFLASH_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_DATAFLASH_H */

111
bertos/cfg/cfg_dc_motor.h Normal file
View file

@ -0,0 +1,111 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for DC motor module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_DC_MOTOR_H
#define CFG_DC_MOTOR_H
/**
* Number of the DC motors to manage.
*
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_NUM_DC_MOTOR 4
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define DC_MOTOR_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define DC_MOTOR_LOG_FORMAT LOG_FMT_VERBOSE
/**
* Min value of DC motor speed.
* \note Generally this value is the min value of the ADC conversion,
* if you use it.
*
* $WIZ$ type = "int"
*/
#define CONFIG_DC_MOTOR_MIN_SPEED 0
/**
* Max value of DC motor speed.
* \note Generally this value is the max value of the ADC conversion,
* if you use it.
*
* $WIZ$ type = "int"
* $WIZ$ max = 65535
*/
#define CONFIG_DC_MOTOR_MAX_SPEED 65535
/**
* Sampling period in millisecond.
* $WIZ$ type = "int"
*/
#define CONFIG_DC_MOTOR_SAMPLE_PERIOD 40
/**
* Amount of millisecond before to read sample.
* $WIZ$ type = "int"
*/
#define CONFIG_DC_MOTOR_SAMPLE_DELAY 2
/**
* This control set which mode the driver use to lock share
* resources when we use the preempitive kernel.
* If we set to 1 we use the semaphore module otherwise the
* driver disable the switch context every time we need to access
* to shared sources.
*
* $WIZ$ type = "int"
*/
#define CONFIG_DC_MOTOR_USE_SEM 1
#endif /* CFG_DC_MOTOR_H */

70
bertos/cfg/cfg_debug.h Normal file
View file

@ -0,0 +1,70 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for Debug module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_DEBUG_H
#define CFG_DEBUG_H
/**
* Debug console port.
* $WIZ$ type = "int"; min = 0
*/
#define CONFIG_KDEBUG_PORT 0
/**
* Baudrate for the debug console.
* $WIZ$ type = "int"; min = 300
*/
#define CONFIG_KDEBUG_BAUDRATE 115200UL
/**
* Clock source for the UART module. You need to write the code to reprogram the respective clock at the required frequency in your project before calling kdbg_init().
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "kdbg_clk_src"
* $WIZ$ supports = "msp430"
*/
#define CONFIG_KDEBUG_CLOCK_SOURCE KDBG_UART_SMCLK
/**
* Clock frequency. (Only if different from MCLK's frequency, otherwise leave it zero)
* $WIZ$ type = "int"; min = 0
* $WIZ$ supports = "msp430"
*/
#define CONFIG_KDEBUG_CLOCK_FREQ 0UL
#endif /* CFG_DEBUG_H */

64
bertos/cfg/cfg_eeprom.h Normal file
View file

@ -0,0 +1,64 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for the Eeprom module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_EEPROM_H
#define CFG_EEPROM_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define EEPROM_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define EEPROM_LOG_FORMAT LOG_FMT_TERSE
/**
* Check this to disable Eeprom deprecated API support.
*
* $WIZ$ type = "boolean"
*/
#define CONFIG_EEPROM_DISABLE_OLD_API 0
#endif /* CFG_EEPROM_H */

View file

@ -0,0 +1,73 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* -->
*
* \author Daniele Basile <asterix@develer.com>
*
* \brief Configuration file for embedded flash module.
*/
#ifndef CFG_EMB_FLASH_H
#define CFG_EMB_FLASH_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define CONFIG_FLASH_EMB_LOG_LEVEL LOG_LVL_INFO
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define CONFIG_FLASH_EMB_LOG_FORMAT LOG_FMT_TERSE
/**
* Write emb flash timeout.
* For how many milliseconds the cpu wait
* to complete write operation.
*
* $WIZ$ type = "int"
*/
#define CONFIG_FLASH_WR_TIMEOUT 100
/**
* Check this to disable embedded flash deprecated API support.
*
* $WIZ$ type = "boolean"
*/
#define CONFIG_FLASH_DISABLE_OLD_API 0
#endif /* CFG_FLASH_AT91_H */

57
bertos/cfg/cfg_eth.h Normal file
View file

@ -0,0 +1,57 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \author Andrea Righi <arighi@develer.com>
*
* \brief Configuration file for the generic ethernet driver module
*/
#ifndef CFG_ETH_H
#define CFG_ETH_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define ETH_LOG_LEVEL LOG_LVL_WARN
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define ETH_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_ETH_H */

156
bertos/cfg/cfg_fat.h Normal file
View file

@ -0,0 +1,156 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for Fat module.
*
*
* \author Luca Ottaviano <lottaviano@develer.com>
* \author Francesco Sacchi <batt@develer.com>
*/
#ifndef CFG_FAT_H
#define CFG_FAT_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define FAT_LOG_LEVEL LOG_LVL_ERR
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define FAT_LOG_FORMAT LOG_FMT_VERBOSE
/**
* Use word alignment to access FAT structure.
* $WIZ$ type = "boolean"
*/
#define CONFIG_FAT_WORD_ACCESS 0
#define _WORD_ACCESS CONFIG_FAT_WORD_ACCESS
/**
* Enable read functions only.
* $WIZ$ type = "boolean"
*/
#define CONFIG_FAT_FS_READONLY 0
#define _FS_READONLY CONFIG_FAT_FS_READONLY
/**
* Minimization level to remove some functions.
* $WIZ$ type = "int"; min = 0; max = 3
*/
#define CONFIG_FAT_FS_MINIMIZE 0
#define _FS_MINIMIZE CONFIG_FAT_FS_MINIMIZE
/**
* If enabled, this reduces memory consumption 512 bytes each file object by using a shared buffer.
* $WIZ$ type = "boolean"
*/
#define CONFIG_FAT_FS_TINY 1
#define _FS_TINY CONFIG_FAT_FS_TINY
/**
* To enable string functions, set _USE_STRFUNC to 1 or 2.
* $WIZ$ type = "int"
* $WIZ$ supports = "False"
*/
#define CONFIG_FAT_USE_STRFUNC 0
#define _USE_STRFUNC CONFIG_FAT_USE_STRFUNC
/**
* Enable f_mkfs function. Requires CONFIG_FAT_FS_READONLY = 0.
* $WIZ$ type = "boolean"
*/
#define CONFIG_FAT_USE_MKFS 0
#define _USE_MKFS (CONFIG_FAT_USE_MKFS && !CONFIG_FAT_FS_READONLY)
/**
* Enable f_forward function. Requires CONFIG_FAT_FS_TINY.
* $WIZ$ type = "boolean"
*/
#define CONFIG_FAT_USE_FORWARD 0
#define _USE_FORWARD (CONFIG_FAT_USE_FORWARD && CONFIG_FAT_FS_TINY)
/**
* Number of volumes (logical drives) to be used.
* $WIZ$ type = "int"; min = 1; max = 255
*/
#define CONFIG_FAT_DRIVES 1
#define _DRIVES CONFIG_FAT_DRIVES
/**
* Maximum sector size to be handled. (512/1024/2048/4096).
* 512 for memory card and hard disk, 1024 for floppy disk, 2048 for MO disk
* $WIZ$ type = "int"; min = 512; max = 4096
*/
#define CONFIG_FAT_MAX_SS 512
#define _MAX_SS CONFIG_FAT_MAX_SS
/**
* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical
* drive number and can mount only first primaly partition. When it is set to 1,
* each volume is tied to the partitions listed in Drives[].
* $WIZ$ type = "boolean"
* $WIZ$ supports = "False"
*/
#define CONFIG_FAT_MULTI_PARTITION 0
#define _MULTI_PARTITION CONFIG_FAT_MULTI_PARTITION
/**
* Specifies the OEM code page to be used on the target system.
* $WIZ$ type = "int"
*/
#define CONFIG_FAT_CODE_PAGE 850
#define _CODE_PAGE CONFIG_FAT_CODE_PAGE
/**
* Support for long filenames. Enable only if you have a valid Microsoft license.
* $WIZ$ type = "boolean"
*/
#define CONFIG_FAT_USE_LFN 0
#define _USE_LFN CONFIG_FAT_USE_LFN
/**
* Maximum Long File Name length to handle.
* $WIZ$ type = "int"; min = 8; max = 255
*/
#define CONFIG_FAT_MAX_LFN 255
#define _MAX_LFN CONFIG_FAT_MAX_LFN
#endif /* CFG_FAT_H */

51
bertos/cfg/cfg_flash25.h Normal file
View file

@ -0,0 +1,51 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for flash25 module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_FLASH25_H
#define CFG_FLASH25_H
/**
* Eeprom memory type.
*
*$WIZ$ type = "enum"
*$WIZ$ value_list = "flash25_list"
*/
#define CONFIG_FLASH25 FLASH25_AT25F2048
#endif /* CFG_FALSH25_H */

65
bertos/cfg/cfg_formatwr.h Normal file
View file

@ -0,0 +1,65 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for formatted write module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_FORMATWR_H
#define CFG_FORMATWR_H
/**
* printf()-style formatter configuration.
* $WIZ$ type = "enum"; value_list = "printf_list"
*
* \sa PRINTF_DISABLED
* \sa PRINTF_NOMODIFIERS
* \sa PRINTF_REDUCED
* \sa PRINTF_NOFLOAT
* \sa PRINTF_FULL
*/
#define CONFIG_PRINTF PRINTF_FULL
/**
* Size of buffer to format "%" sequences in printf.
*
* Warning: no check on buffer size is done when formatting, be careful especially
* with big numbers and %f formatting.
*
* $WIZ$ type = "int"
* $WIZ$ min = 4
*/
#define CONFIG_FRMWRI_BUFSIZE 134
#endif /* CFG_FORMATWR_H */

67
bertos/cfg/cfg_gfx.h Normal file
View file

@ -0,0 +1,67 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for GFX module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_GFX_H
#define CFG_GFX_H
/**
* Enable line clipping algorithm.
* $WIZ$ type = "boolean"
*/
#define CONFIG_GFX_CLIPPING 1
/**
* Enable text rendering in bitmaps.
* $WIZ$ type = "boolean"
*/
#define CONFIG_GFX_TEXT 1
/**
* Enable virtual coordinate system.
* $WIZ$ type = "boolean"
*/
#define CONFIG_GFX_VCOORDS 1
/**
* Select bitmap pixel format.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "bitmap_format"
*/
#define CONFIG_BITMAP_FMT BITMAP_FMT_PLANAR_V_LSB
#endif /* CFG_GFX_H */

View file

@ -0,0 +1,51 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for hashtable module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_HASHTABLE_H
#define CFG_HASHTABLE_H
/**
* Enable/disable support to declare special hash tables which maintain a copy of the key internally instead of relying on the hook to extract it from the data.
*
* $WIZ$ type = "boolean"
*/
#define CONFIG_HT_OPTIONAL_INTERNAL_KEY 1
#endif /* CFG_HASHTABLE_H */

50
bertos/cfg/cfg_heap.h Normal file
View file

@ -0,0 +1,50 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for heap module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_HEAP_H
#define CFG_HEAP_H
/**
* Enable malloc/free like API.
* $WIZ$ type = "boolean"
*/
#define CONFIG_HEAP_MALLOC 1
#endif /* CFG_HEAP_H */

83
bertos/cfg/cfg_i2c.h Normal file
View file

@ -0,0 +1,83 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for I2C module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_I2C_H
#define CFG_I2C_H
/**
*Comunication frequency.
*
* $WIZ$ type = "int"
*/
#define CONFIG_I2C_FREQ 100000UL
/**
* I2C start timeout.
* For how many milliseconds the i2c_start
* should try to get an ACK before
* returning error.
*
* $WIZ$ type = "int"
*/
#define CONFIG_I2C_START_TIMEOUT 100
/**
* Check this to disable I2c deprecated API support.
*
* $WIZ$ type = "boolean"
*/
#define CONFIG_I2C_DISABLE_OLD_API 0
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define I2C_LOG_LEVEL LOG_LVL_INFO
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define I2C_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_I2C_H */

74
bertos/cfg/cfg_i2s.h Normal file
View file

@ -0,0 +1,74 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for I2S module.
*
*
* \author Luca Ottaviano <lottaviano@develer.com>
*/
#ifndef CFG_I2S_H
#define CFG_I2S_H
/**
* Length of each play buffer.
*
* $WIZ$ type = "int"
*/
#define CONFIG_PLAY_BUF_LEN 8192
/**
* Sampling frequency of the audio file.
*
* $WIZ$ type = "int"
* $WIZ$ min = 32000
* $WIZ$ max = 192000
*/
#define CONFIG_SAMPLE_FREQ 44100UL
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define I2S_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define I2S_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_I2S_H */

View file

@ -0,0 +1,48 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for ini reader module.
*
*
* \author Luca Ottaviano <lottaviano@develer.com>
*/
#ifndef CFG_INI_READER_H
#define CFG_INI_READER_H
/**
* Maximum ini file line length (chars).
* $WIZ$ type = "int"; min = 1
*/
#define CONFIG_INI_MAX_LINE_LEN 64
#endif /* CFG_INI_READER_H */

58
bertos/cfg/cfg_kbd.h Normal file
View file

@ -0,0 +1,58 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for keyboard module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_KBD_H
#define CFG_KBD_H
/// Keyboard polling method. $WIZ$ supports = "False"
#define CONFIG_KBD_POLL KBD_POLL_SOFTINT
/// Enable keyboard event delivery to observers. $WIZ$ type = "boolean"
#define CONFIG_KBD_OBSERVER 0
/// Enable key beeps. $WIZ$ type = "boolean"
#define CONFIG_KBD_BEEP 0
/// Enable long pression handler for keys. $WIZ$ type = "boolean"
#define CONFIG_KBD_LONGPRESS 0
/// Enable calling poor man's scheduler to be called inside kbd_peek. $WIZ$ type = "boolean"
#define CONFIG_KBD_SCHED 0
#endif /* CFG_KBD_H */

54
bertos/cfg/cfg_kern.h Normal file
View file

@ -0,0 +1,54 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999, 2000, 2001, 2008 Bernie Innocenti <bernie@codewiz.org>
* -->
*
* \brief Kernel configuration parameters (deprecated)
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#ifndef CFG_KERN_H
#define CFG_KERN_H
#warning This file is deprecated, you should use the correct combination of cfg_proc.h, cfg_sem.h, cfg_signal.h and cfg_monitor.h
#include "cfg_proc.h"
#include "cfg_sem.h"
#include "cfg_signal.h"
#include "cfg_monitor.h"
/**
* Left for backwards compatibility.
* Do not use this anymore, will be deprecated soon.
*/
#define CONFIG_KERN_SCHED CONFIG_KERN
#endif /* CFG_KERN_H */

61
bertos/cfg/cfg_keytag.h Normal file
View file

@ -0,0 +1,61 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for keytag module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_KEYTAG_H
#define CFG_KEYTAG_H
/**
* Module logging level.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define CONFIG_KEYTAG_LOG_LEVEL LOG_LVL_ERR
/**
* Module logging format.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define CONFIG_KEYTAG_LOG_FORMAT LOG_FMT_TERSE
/**
* Max buffer lenght
* $WIZ$ type = "int"
*/
#define CONFIG_TAG_MAX_LEN 14U
#endif /* CFG_KEYTAG_H */

61
bertos/cfg/cfg_kfile.h Normal file
View file

@ -0,0 +1,61 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for KFile interface module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_KFILE_H
#define CFG_KFILE_H
/**
* Module logging level.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define KFILE_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define KFILE_LOG_FORMAT LOG_FMT_TERSE
/**
* Enable the gets function with echo.
* $WIZ$ type = "boolean"
*/
#define CONFIG_KFILE_GETS 0
#endif /* CFG_KFILE_H */

View file

@ -0,0 +1,63 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003, 2004, 2005, 2006, 2010 Develer S.r.l. (http://www.develer.com/)
* Copyright 2001 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief Displaytech 32122A LCD driver configuration file.
*
* \author Bernie Innocenti <bernie@codewiz.org>
* \author Stefano Fedrigo <aleph@develer.com>
*
*/
#ifndef CFG_LCD_32122A_H
#define CFG_LCD_32122A_H
/**
* Enable soft interrupt to refresh the LCD.
* $WIZ$ type = "boolean"
*/
#define CONFIG_LCD_SOFTINT_REFRESH 0
/**
* Enable wait macro when display is busy.
* $WIZ$ type = "boolean"
*/
#define CONFIG_LCD_WAIT 0
/**
* Display refresh time 32122a.
* $WIZ$ type = "int"
* $WIZ$ min = 0
*/
#define CONFIG_LCD_REFRESH 100
#endif /* CFG_LCD_32122A_H */

69
bertos/cfg/cfg_lcd_hd44.h Normal file
View file

@ -0,0 +1,69 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for lcd display module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_LCD_H
#define CFG_LCD_H
/**
* Use 4 bit addressing mode.
* $WIZ$ type = "boolean"
*/
#define CONFIG_LCD_4BIT 0
/**
* Use a table to speed up LCD memory addressing.
* This will use about 100 bytes of RAM.
* $WIZ$ type = "boolean"
*/
#define CONFIG_LCD_ADDRESS_FAST 1
/**
* Number of columns in LCD display.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "lcd_hd44_cols"
*/
#define CONFIG_LCD_COLS LCD_HD44_COLS_16
/**
* Number of rows in LCD display.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "lcd_hd44_rows"
*/
#define CONFIG_LCD_ROWS LCD_HD44_ROWS_2
#endif /* CFG_LCD_H */

80
bertos/cfg/cfg_led_7seg.h Normal file
View file

@ -0,0 +1,80 @@
/**
* \file cfg_led_7seg.h
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
* -->
*
* \brief Configuration file for led 7 segment display.
*
* \author Fabio Bizzi <fbizzi@bizzi.org>
*
* \addtogroup SevenSegDisplay 7 Segments LED Displays Driver
* \{
*
*/
#ifndef CFG_LED_7SEG_H
#define CFG_LED_7SEG_H
/**
* Use a Common Cathode display.
* $WIZ$ type = "boolean"
*/
#define CONFIG_LED_7SEG_CCAT 0
/**
* Number of digit present in the LED display.
* $WIZ$ type = "int"
* $WIZ$ min = 1
* $WIZ$ max = 8
*/
#define CONFIG_LED_7SEG_DIGIT 4
/**
* Max lenght of the string to be displayed.
* $WIZ$ type = "int"
* $WIZ$ min = 16
* $WIZ$ max = 255
*/
#define CONFIG_LED_7SEG_STRLEN 255
/**
* Default scrolling speed (ms * CONFIG_LED_7SEG_RTIME).
* $WIZ$ type = "int"
*/
#define CONFIG_LED_7SEG_SSPEED 10
/**
* Default refresh time (ms).
* $WIZ$ type = "int"
*/
#define CONFIG_LED_7SEG_RTIME 5
#endif /* CFG_LED_7SEG_H */
/** \} */ //defgroup drivers

57
bertos/cfg/cfg_lm75.h Normal file
View file

@ -0,0 +1,57 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for the LM75 sensor temperature.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_LM75_H
#define CFG_LM75_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define LM75_LOG_LEVEL LOG_LVL_WARN
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define LM75_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_AX25_H */

1863
bertos/cfg/cfg_lwip.h Normal file

File diff suppressed because it is too large Load diff

53
bertos/cfg/cfg_md2.h Normal file
View file

@ -0,0 +1,53 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for MD2 module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_MD2_H
#define CFG_MD2_H
/**
* Size of block for MD2 algorithm.
* $WIZ$ type = "int"
* $WIZ$ min = 2
*/
#define CONFIG_MD2_BLOCK_LEN 16
/// Use standard permutation in MD2 algorithm. $WIZ$ type = "boolean"
#define CONFIG_MD2_STD_PERM 0
#endif /* CFG_MD2_H */

67
bertos/cfg/cfg_menu.h Normal file
View file

@ -0,0 +1,67 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for Menu module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_MENU_H
#define CFG_MENU_H
/**
* Enable button bar behind menus
* $WIZ$ type = "boolean"
*/
#define CONFIG_MENU_MENUBAR 0
/**
* Level Edit Timeout
* $WIZ$ type = "boolean"
*/
#define CONFIG_LEVELEDIT_TIMEOUT 0
/**
* Menu timeout
* $WIZ$ type = "boolean"
*/
#define CONFIG_MENU_TIMEOUT 0
/**
* Enable smooth scrolling in menus
* $WIZ$ type = "boolean"
*/
#define CONFIG_MENU_SMOOTH 1
#endif /* CFG_MENU_H */

47
bertos/cfg/cfg_monitor.h Normal file
View file

@ -0,0 +1,47 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999, 2000, 2001, 2008 Bernie Innocenti <bernie@codewiz.org>
* -->
*
* \brief Kernel monitor configuration parameters
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#ifndef CFG_MONITOR_H
#define CFG_MONITOR_H
/**
* Process monitor.
* $WIZ$ type = "autoenabled"
*/
#define CONFIG_KERN_MONITOR 0
#endif /* CFG_MONITOR_H */

111
bertos/cfg/cfg_nand.h Normal file
View file

@ -0,0 +1,111 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2011 Develer S.r.l. (http://www.develer.com/)
* -->
*
* \author Stefano Fedrigo <aleph@develer.com>
*
* \brief Configuration file for NAND driver module.
*/
#ifndef CFG_NAND_H
#define CFG_NAND_H
/**
* Page data size
*
* Size of the data section of a programmable page in bytes.
*
* $WIZ$ type = "int"
*/
#define CONFIG_NAND_DATA_SIZE 2048
/**
* Page spare area size
*
* Size of the spare section of a programmable page in bytes.
*
* $WIZ$ type = "int"
*/
#define CONFIG_NAND_SPARE_SIZE 64
/**
* Pages per block
*
* Number of pages in a erase block.
*
* $WIZ$ type = "int"
*/
#define CONFIG_NAND_PAGES_PER_BLOCK 64
/**
* Number of blocks
*
* Total number of erase blocks in one NAND chip.
*
* $WIZ$ type = "int"
*/
#define CONFIG_NAND_NUM_BLOCK 2048
/**
* Number of reserved blocks
*
* Blocks reserved for remapping defective NAND blocks.
*
* $WIZ$ type = "int"
*/
#define CONFIG_NAND_NUM_REMAP_BLOCKS 128
/**
* NAND operations timeout
*
* How many milliseconds the cpu waits for
* completion of NAND operations.
*
* $WIZ$ type = "int"
*/
#define CONFIG_NAND_TMOUT 100
/**
* Module logging level
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define CONFIG_NAND_LOG_LEVEL LOG_LVL_WARN
/**
* Module logging format
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define CONFIG_NAND_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_NAND_H */

85
bertos/cfg/cfg_nmea.h Normal file
View file

@ -0,0 +1,85 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for NMEA module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_NMEA_H
#define CFG_NMEA_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define NMEA_LOG_LEVEL LOG_LVL_ERR
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define NMEA_LOG_FORMAT LOG_FMT_TERSE
/**
* Maximum number of sentence parsers supported.
*
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_NMEAP_MAX_SENTENCES 8
/**
* Max length of a complete sentence. The standard says 82 bytes, but its probably
* better to go at least 128 since some units don't adhere to the 82 bytes
* especially for proprietary sentences.
*
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_NMEAP_MAX_SENTENCE_LENGTH 255
/**
* Max tokens in one sentence. 24 is enough for any standard sentence.
*
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_NMEAP_MAX_TOKENS 24
#endif /* CFG_NMEA_H */

54
bertos/cfg/cfg_ntc.h Normal file
View file

@ -0,0 +1,54 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for NTC module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_NTC_H
#define CFG_NTC_H
/**
* Module logging level.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define CONFIG_NTC_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define CONFIG_NTC_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_NTC_H */

66
bertos/cfg/cfg_parser.h Normal file
View file

@ -0,0 +1,66 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for parser module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_PARSER_H
#define CFG_PARSER_H
/**
* Max number of arguments and results for each command
* $WIZ$ type = "int"
* $WIZ$ min = 0
*/
#define CONFIG_PARSER_MAX_ARGS 4
/**
* Max number of commands
* $WIZ$ type = "int"
* $WIZ$ min = 8
*/
#define CONFIG_MAX_COMMANDS_NUMBER 16
/**
* Enable compatibility behaviour.
*
* Skip the first word from incoming commands. Don't enable in new projects.
* $WIZ$ type = "boolean"
*/
#define CONFIG_ENABLE_COMPAT_BEHAVIOUR 1
#endif /* CFG_PARSER_H */

55
bertos/cfg/cfg_phase.h Normal file
View file

@ -0,0 +1,55 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for phase module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_PHASE_H
#define CFG_PHASE_H
/**
* Max value of the duty cycle on triac.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_TRIAC_MAX_DUTY 100
/**
* Max value of the triac power.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_TRIAC_MAX_POWER 100
#endif /* CFG_PHASE_H */

56
bertos/cfg/cfg_pid.h Normal file
View file

@ -0,0 +1,56 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
* -->
*
* \brief Configuration file for PWM module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_PID_H
#define CFG_PID_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define PID_LOG_LEVEL LOG_LVL_WARN
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define PID_LOG_FORMAT LOG_FMT_VERBOSE
#endif /* CFG_PID_H */

View file

@ -0,0 +1,71 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for pocketbus module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_POCKETBUS_H
#define CFG_POCKETBUS_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define POCKETBUS_LOG_LEVEL LOG_LVL_ERR
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define POCKETBUS_LOG_FORMAT LOG_FMT_TERSE
/**
*Buffer len for pockebus protocol.
* $WIZ$ type = "int"
* $WIZ$ min = 2
*/
#define CONFIG_POCKETBUS_BUFLEN 128
/**
* Command replay timeout in milliseconds.
* $WIZ$ type = "int"
*/
#define CONFIG_POCKETBUS_CMD_REPLY_TIMEOUT 50
#endif /* CFG_POCKETBUS_H */

113
bertos/cfg/cfg_proc.h Normal file
View file

@ -0,0 +1,113 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999, 2000, 2001, 2008 Bernie Innocenti <bernie@codewiz.org>
* -->
*
* \brief Kernel configuration parameters
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#ifndef CFG_PROC_H
#define CFG_PROC_H
/**
* Enable the multithreading kernel.
*
* $WIZ$ type = "autoenabled"
*/
#define CONFIG_KERN 0
/**
* Kernel interrupt supervisor. WARNING: Experimental, still incomplete!
* $WIZ$ type = "boolean"
* $WIZ$ supports = "False"
*/
#define CONFIG_KERN_IRQ 0
/**
* Preemptive process scheduling.
*
* $WIZ$ type = "boolean"
* $WIZ$ conditional_deps = "timer"
*/
#define CONFIG_KERN_PREEMPT 0
/**
* Time sharing quantum (a prime number prevents interference effects) [ms].
*
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_KERN_QUANTUM 11
/**
* Priority-based scheduling policy.
* $WIZ$ type = "boolean"
*/
#define CONFIG_KERN_PRI 0
/**
* Priority-inheritance protocol.
* $WIZ$ type = "boolean"
*/
#define CONFIG_KERN_PRI_INHERIT 0
/**
* Dynamic memory allocation for processes.
* $WIZ$ type = "boolean"
* $WIZ$ conditional_deps = "heap"
*/
#define CONFIG_KERN_HEAP 0
/**
* Size of the dynamic memory pool used by processes.
* $WIZ$ type = "int"
* $WIZ$ min = 0
*/
#define CONFIG_KERN_HEAP_SIZE 2048L
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define KERN_LOG_LEVEL LOG_LVL_ERR
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define KERN_LOG_FORMAT LOG_FMT_VERBOSE
#endif /* CFG_PROC_H */

64
bertos/cfg/cfg_pwm.h Normal file
View file

@ -0,0 +1,64 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* -->
*
* \brief Configuration file for PWM module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_PWM_H
#define CFG_PWM_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define PWM_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define PWM_LOG_FORMAT LOG_FMT_VERBOSE
/**
* Enable the OLD pwm API.
* Not recommended for new projects.
*
* $WIZ$ type = "boolean"
*/
#define CFG_PWM_ENABLE_OLD_API 1
#endif /* CFG_PWM_H */

115
bertos/cfg/cfg_ramp.h Normal file
View file

@ -0,0 +1,115 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file Ramp algorithm module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_RAMP_H
#define CFG_RAMP_H
/**
* Define whether the ramp will use floating point calculation within ramp_evaluate().
* Otherwise, a less precise fixed point version will be used, which is faster on
* platforms which do no support floating point operations.
*
* \note Floating point operations will be always done within ramp_compute() to
* precalculate values, so there has to be at least a floating point emulation support.
*
* $WIZ$ type = "boolean"
*/
#define RAMP_USE_FLOATING_POINT 0
#if !RAMP_USE_FLOATING_POINT
/**
* Number of least-significant bits which are stripped away during ramp evaluation.
* This setting allows to specify larger ramps at the price of less precision.
*
* The maximum ramp size allowed is 2^(24 + RAMP_CLOCK_SHIFT_PRECISION), in clocks.
* For instance, using RAMP_CLOCK_SHIFT_PRECISION 1, and a 8x prescaler, the maximum
* length of a ramp is about 6.7 secs. Raising RAMP_CLOCK_SHIFT_PRECISION to 2
* brings the maximum length to 13.4 secs, at the price of less precision.
*
* ramp_compute() will check that the length is below the maximum allowed through
* a runtime assertion.
*
* \note This macro is used only for the fixed-point version of the ramp.
* $WIZ$ type = "int"
* $WIZ$ min = 0
* $WIZ$ max = 32
*/
#define RAMP_CLOCK_SHIFT_PRECISION 2
#endif
/**
* Negative pulse width for ramp.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define RAMP_PULSE_WIDTH 50
/**
* Default ramp time (microsecs).
* $WIZ$ type = "int"
* $WIZ$ min = 1000
*/
#define RAMP_DEF_TIME 6000000UL
/**
* Default ramp maxfreq (Hz).
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define RAMP_DEF_MAXFREQ 5000
/**
* Default ramp minfreq (Hz).
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define RAMP_DEF_MINFREQ 200
/**
* Default ramp powerrun (deciampere).
* $WIZ$ type = "int"
* $WIZ$ min = 0
*/
#define RAMP_DEF_POWERRUN 10
/**
* Default ramp poweridle (Hz).
* $WIZ$ type = "int"
* $WIZ$ min = 0
*/
#define RAMP_DEF_POWERIDLE 1
#endif /* CFG_RAMP_H */

65
bertos/cfg/cfg_random.h Normal file
View file

@ -0,0 +1,65 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2011 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \author Andrea Righi <arighi@develer.com>
*
* \brief Configuration file for the "random" module
*/
#ifndef CFG_RANDOM_H
#define CFG_RANDOM_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define RANDOM_LOG_LEVEL LOG_LVL_INFO
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define RANDOM_LOG_FORMAT LOG_FMT_TERSE
/**
* Random security level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "random_level"
*/
#define RANDOM_SECURITY_LEVEL RANDOM_SECURITY_MINIMUM
#endif /* CFG_RANDOM_H */

55
bertos/cfg/cfg_randpool.h Normal file
View file

@ -0,0 +1,55 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for randpool module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_RANDPOOL_H
#define CFG_RANDPOOL_H
/**
* Define a size, in byte, of entropy pool.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_SIZE_ENTROPY_POOL 64
/// Enable timer in randpool algo. $WIZ$ type = "boolean"
#define CONFIG_RANDPOOL_TIMER 1
#endif /* CFG_RANDPOOL_H */

75
bertos/cfg/cfg_sd.h Normal file
View file

@ -0,0 +1,75 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file Secure Digital module.
*
*
* \author Francesco Sacchi <batt@develer.com>
*/
#ifndef CFG_SD_H
#define CFG_SD_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define SD_LOG_LEVEL LOG_LVL_ERR
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define SD_LOG_FORMAT LOG_FMT_VERBOSE
/**
* Enable autoassignment of SD driver to disk drive number 0 of FatFs module.
* $WIZ$ type = "boolean"
* $WIZ$ conditional_deps = "fat"
*/
#define CONFIG_SD_AUTOASSIGN_FAT 1
/**
* Enable backward compatibility for sd_init().
* If enabled, sd_init() will allocate internally an Sd context,
* otherwise sd_init() will need the context to be passed explicitly.
*
* $WIZ$ type = "boolean"
*/
#define CONFIG_SD_OLD_INIT 1
#endif /* CFG_SD_H */

47
bertos/cfg/cfg_sem.h Normal file
View file

@ -0,0 +1,47 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999, 2000, 2001, 2008 Bernie Innocenti <bernie@codewiz.org>
* -->
*
* \brief Kernel semaphores configuration parameters.
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#ifndef CFG_SEM_H
#define CFG_SEM_H
/**
* Re-entrant mutual exclusion primitives.
* $WIZ$ type = "autoenabled"
*/
#define CONFIG_KERN_SEMAPHORES 0
#endif /* CFG_SEM_H */

222
bertos/cfg/cfg_ser.h Normal file
View file

@ -0,0 +1,222 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for serial module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_SER_H
#define CFG_SER_H
/**
* Example of setting for serial port and
* spi port.
* Edit these define for your project.
*/
/**
* Size of the outbound FIFO buffer for port 0 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
*/
#define CONFIG_UART0_TXBUFSIZE 32
/**
* Size of the inbound FIFO buffer for port 0 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
*/
#define CONFIG_UART0_RXBUFSIZE 32
/**
* Size of the outbound FIFO buffer for port 1 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "lm3s or lpc2 or (at91 and not atmega8 and not atmega168 and not atmega32)"
*/
#define CONFIG_UART1_TXBUFSIZE 32
/**
* Size of the inbound FIFO buffer for port 1 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "lm3s or lpc2 or (at91 and not atmega8 and not atmega168 and not atmega32)"
*/
#define CONFIG_UART1_RXBUFSIZE 32
/**
* Size of the outbound FIFO buffer for port 2 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "lm3s or lpc2"
*/
#define CONFIG_UART2_TXBUFSIZE 32
/**
* Size of the inbound FIFO buffer for port 2 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "lm3s or lpc2"
*/
#define CONFIG_UART2_RXBUFSIZE 32
/**
* Size of the outbound FIFO buffer for port 3 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "lpc2"
*/
#define CONFIG_UART3_TXBUFSIZE 32
/**
* Size of the inbound FIFO buffer for port 3 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "lpc2"
*/
#define CONFIG_UART3_RXBUFSIZE 32
/**
* Size of the outbound FIFO buffer for SPI port [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "avr"
*/
#define CONFIG_SPI_TXBUFSIZE 32
/**
* Size of the inbound FIFO buffer for SPI port [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "avr"
*/
#define CONFIG_SPI_RXBUFSIZE 32
/**
* Size of the outbound FIFO buffer for SPI port 0 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "at91"
*/
#define CONFIG_SPI0_TXBUFSIZE 32
/**
* Size of the inbound FIFO buffer for SPI port 0 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "at91"
*/
#define CONFIG_SPI0_RXBUFSIZE 32
/**
* Size of the outbound FIFO buffer for SPI port 1 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "at91"
*/
#define CONFIG_SPI1_TXBUFSIZE 32
/**
* Size of the inbound FIFO buffer for SPI port 1 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
* $WIZ$ supports = "at91"
*/
#define CONFIG_SPI1_RXBUFSIZE 32
/**
* SPI data order.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "ser_order_bit"
* $WIZ$ supports = "avr"
*/
#define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST
/**
* SPI clock division factor.
* $WIZ$ type = "int"
* $WIZ$ supports = "avr"
*/
#define CONFIG_SPI_CLOCK_DIV 16
/**
* SPI clock polarity: normal low or normal high.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "ser_spi_pol"
* $WIZ$ supports = "avr"
*/
#define CONFIG_SPI_CLOCK_POL SPI_NORMAL_LOW
/**
* SPI clock phase you can choose sample on first edge or
* sample on second clock edge.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "ser_spi_phase"
* $WIZ$ supports = "avr"
*/
#define CONFIG_SPI_CLOCK_PHASE SPI_SAMPLE_ON_FIRST_EDGE
/**
* Default transmit timeout (ms). Set to -1 to disable timeout support.
* $WIZ$ type = "int"
* $WIZ$ min = -1
*/
#define CONFIG_SER_TXTIMEOUT -1
/**
* Default receive timeout (ms). Set to -1 to disable timeout support.
* $WIZ$ type = "int"
* $WIZ$ min = -1
*/
#define CONFIG_SER_RXTIMEOUT -1
/**
* Use RTS/CTS handshake.
* $WIZ$ type = "boolean"
* $WIZ$ supports = "False"
*/
#define CONFIG_SER_HWHANDSHAKE 0
/**
* Default baudrate for all serial ports (set to 0 to disable).
* $WIZ$ type = "int"
* $WIZ$ min = 0
*/
#define CONFIG_SER_DEFBAUDRATE 0UL
/// Enable strobe pin for debugging serial interrupt. $WIZ$ type = "boolean"
#define CONFIG_SER_STROBE 0
#endif /* CFG_SER_H */

47
bertos/cfg/cfg_signal.h Normal file
View file

@ -0,0 +1,47 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
* Copyright 1999, 2000, 2001, 2008 Bernie Innocenti <bernie@codewiz.org>
* -->
*
* \brief Kernel signals configuration parameters
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#ifndef CFG_SIGNAL_H
#define CFG_SIGNAL_H
/**
* Inter-process signals.
* $WIZ$ type = "autoenabled"
*/
#define CONFIG_KERN_SIGNALS 0
#endif /* CFG_SIGNAL_H */

View file

@ -0,0 +1,51 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for SPI bitbang module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_SPI_BITBANG_H
#define CFG_SPI_BITBANG_H
/**
* Set data order for emulated SPI.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "ordet_bit_list"
*/
#define CONFIG_SPI_DATAORDER SPI_LSB_FIRST
#endif /* CFG_SPI_BITBANG_H */

60
bertos/cfg/cfg_spi_dma.h Normal file
View file

@ -0,0 +1,60 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for spi dma module.
*
*
* \author Francesco Sacchi <batt@develer.com>
*/
#ifndef CFG_SPI_DMA_H
#define CFG_SPI_DMA_H
/**
* Max size received for each DMA transfer [bytes].
* Longer buffers will be split in two or more transfers of this size.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_SPI_DMA_MAX_RX 512
/**
* Default transmit timeout (ms). Set to -1 to disable timeout support.
* $WIZ$ type = "int"
* $WIZ$ min = -1
*/
#define CONFIG_SPI_DMA_TX_TIMEOUT -1
#endif /* CFG_SER_H */

69
bertos/cfg/cfg_stepper.h Normal file
View file

@ -0,0 +1,69 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for stepper motor module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_STEPPER_H
#define CFG_STEPPER_H
/**
* Module logging level.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define STEPPER_LOG_LEVEL LOG_LVL_INFO
/**
* Module logging format.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define STEPPER_LOG_FORMAT LOG_FMT_TERSE
/**
* Max number of the stepper motor.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_NUM_STEPPER_MOTORS 6
/**
* Max number of the timer usable on target to drive stepper motor.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_TC_STEPPER_MAX_NUM 6
#endif /* CFG_STEPPER_H */

50
bertos/cfg/cfg_tas5706a.h Normal file
View file

@ -0,0 +1,50 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2009 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for the TAS5706A module.
*
* \author Luca Ottaviano <lottaviano@develer.com>
*/
#ifndef CFG_TAS5706A_H
#define CFG_TAS5706A_H
/**
* Maximum output volume for TAS chip [dB].
*
* $WIZ$ type = "int"
* $WIZ$ min = -100
* $WIZ$ max = 24
*/
#define CONFIG_TAS_MAX_VOL -39
#endif /* CFG_TAS5706A_H */

20
bertos/cfg/cfg_tftp.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef CFG_TFTP_H
#define CFG_TFTP_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define TFTP_LOG_LEVEL LOG_LVL_WARN
/**
* Module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define TFTP_LOG_FORMAT LOG_FMT_VERBOSE
#endif /* CFG_TFTP_H */

71
bertos/cfg/cfg_thermo.h Normal file
View file

@ -0,0 +1,71 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Configuration file for thermo module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_THERMO_H
#define CFG_THERMO_H
/**
* Module logging level.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define CONFIG_THERMO_LOG_LEVEL LOG_LVL_ERR
/**
* Module logging format.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define CONFIG_THERMO_LOG_FORMAT LOG_FMT_TERSE
/**
* Interval at which thermo control is performed [ms].
*
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_THERMO_INTERVAL_MS 100
/**
* Number of different samples we interpolate over to get the hifi temperature.
*
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_THERMO_HIFI_NUM_SAMPLES 10
#endif /* CFG_THERMO_H */

67
bertos/cfg/cfg_timer.h Normal file
View file

@ -0,0 +1,67 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for timer module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_TIMER_H
#define CFG_TIMER_H
/**
* Hardware timer selection for drv/timer.c.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "timer_select"
*/
#define CONFIG_TIMER TIMER_DEFAULT
/**
* Debug timer interrupt using a strobe pin.
* $WIZ$ type = "boolean"
*/
#define CONFIG_TIMER_STROBE 0
/**
* Enable asynchronous timers.
* $WIZ$ type = "boolean"
*/
#define CONFIG_TIMER_EVENTS 1
/**
* Support hi-res timer_usleep().
* $WIZ$ type = "boolean"
*/
#define CONFIG_TIMER_UDELAY 1
#endif /* CFG_TIMER_H */

85
bertos/cfg/cfg_usb.h Normal file
View file

@ -0,0 +1,85 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \author Andrea Righi <arighi@develer.com>
*
* \brief Configuration file for the USB driver module
*/
#ifndef CFG_USB_H
#define CFG_USB_H
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define USB_LOG_LEVEL LOG_LVL_INFO
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define USB_LOG_FORMAT LOG_FMT_TERSE
/**
* Size of the USB buffer used for endpoint transfers [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 2
*/
#define CONFIG_USB_BUFSIZE 64
/**
* Maximum number of USB device interfaces (default = 1).
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_USB_INTERFACE_MAX 1
/**
* Maximum number of allocated endpoints (0 = auto).
* $WIZ$ type = "int"
* $WIZ$ min = 0
*/
#define CONFIG_USB_EP_MAX 0
/**
* Maximum packet size of the control endpoint 0 [bytes].
* $WIZ$ type = "int"
* $WIZ$ min = 8
*/
#define CONFIG_EP0_MAX_SIZE 8
#endif /* CFG_USB_H */

78
bertos/cfg/cfg_usbkbd.h Normal file
View file

@ -0,0 +1,78 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \author Andrea Righi <arighi@develer.com>
*
* \brief Configuration file for the usbkbd driver module
*/
#ifndef CFG_USBKBD_H
#define CFG_USBKBD_H
/**
* Enable the usbkbd module.
*
* $WIZ$ type = "autoenabled"
*/
#define CONFIG_USBKBD 0
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define USB_KEYBOARD_LOG_LEVEL LOG_LVL_INFO
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define USB_KEYBOARD_LOG_FORMAT LOG_FMT_TERSE
/**
* USB vendor ID (please change this in your project, using a valid ID number!).
*
* $WIZ$ type = "hex"
*/
#define USB_KEYBOARD_VENDOR_ID 0x046d
/**
* USB product ID (please change this in your project, using a valid ID number!).
*
* $WIZ$ type = "hex"
*/
#define USB_KEYBOARD_PRODUCT_ID 0xffff
#endif /* CFG_USB_KEYBOARD_H */

78
bertos/cfg/cfg_usbmouse.h Normal file
View file

@ -0,0 +1,78 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \author Andrea Righi <arighi@develer.com>
*
* \brief Configuration file for the usbmouse driver module
*/
#ifndef CFG_USBMOUSE_H
#define CFG_USBMOUSE_H
/**
* Enable the usbmouse module.
*
* $WIZ$ type = "autoenabled"
*/
#define CONFIG_USBMOUSE 0
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define USB_MOUSE_LOG_LEVEL LOG_LVL_INFO
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define USB_MOUSE_LOG_FORMAT LOG_FMT_TERSE
/**
* USB vendor ID (please change this in your project, using a valid ID number!).
*
* $WIZ$ type = "hex"
*/
#define USB_MOUSE_VENDOR_ID 0xffff
/**
* USB product ID (please change this in your project, using a valid ID number!).
*
* $WIZ$ type = "hex"
*/
#define USB_MOUSE_PRODUCT_ID 0x0000
#endif /* CFG_USBMOUSE_H */

78
bertos/cfg/cfg_usbser.h Normal file
View file

@ -0,0 +1,78 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \author Andrea Righi <arighi@develer.com>
*
* \brief Configuration file for the USB serial driver module
*/
#ifndef CFG_USBSER_H
#define CFG_USBSER_H
/**
* Enable the usb-serial module.
*
* $WIZ$ type = "autoenabled"
*/
#define CONFIG_USBSER 0
/**
* Module logging level.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define USB_SERIAL_LOG_LEVEL LOG_LVL_INFO
/**
* module logging format.
*
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define USB_SERIAL_LOG_FORMAT LOG_FMT_TERSE
/**
* USB vendor ID (please change this in your project, using a valid ID number!).
*
* $WIZ$ type = "hex"
*/
#define USB_SERIAL_VENDOR_ID 0x05f9
/**
* USB product ID (please change this in your project, using a valid ID number!).
*
* $WIZ$ type = "hex"
*/
#define USB_SERIAL_PRODUCT_ID 0xffff
#endif /* CFG_USBSER_H */

47
bertos/cfg/cfg_wdt.h Normal file
View file

@ -0,0 +1,47 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for watchdog module.
*
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_WDT_H
#define CFG_WDT_H
/// Enable watchdog timer. $WIZ$ type = "autoenabled"
#define CONFIG_WATCHDOG 0
#endif /* CFG_WDT_H */

79
bertos/cfg/cfg_xmodem.h Normal file
View file

@ -0,0 +1,79 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
* All Rights Reserved.
* -->
*
* \brief Configuration file for xmodem module.
*
* \author Daniele Basile <asterix@develer.com>
*/
#ifndef CFG_XMODEM_H
#define CFG_XMODEM_H
/**
* Module logging level.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_level"
*/
#define CONFIG_XMODEM_LOG_LEVEL LOG_LVL_ERR
/**
* Module logging format.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
#define CONFIG_XMODEM_LOG_FORMAT LOG_FMT_TERSE
/// Enable Rx. $WIZ$ type = "boolean"
#define CONFIG_XMODEM_RECV 1
/// Enable TX. $WIZ$ type = "boolean"
#define CONFIG_XMODEM_SEND 1
/// Allow a Rx/Tx of 1Kbyte block. $WIZ$ type = "boolean"
#define CONFIG_XMODEM_1KCRC 1
/**
* Max retries before giving up.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_XMODEM_MAXRETRIES 15
/**
* Max retries before switching to BCC.
* $WIZ$ type = "int"
* $WIZ$ min = 1
*/
#define CONFIG_XMODEM_MAXCRCRETRIES 7
#endif /* CFG_XMODEM_H */

640
bertos/cfg/compiler.h Normal file
View file

@ -0,0 +1,640 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
* Copyright 2001, 2002, 2003 Bernie Innocenti <bernie@codewiz.org>
*
* -->
*
* \brief Additional support macros for compiler independance
*
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#ifndef BERTOS_COMPILER_H
#define BERTOS_COMPILER_H
#include <cpu/detect.h>
#if defined __GNUC__ && defined __GNUC_MINOR__
#define GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
#define GNUC_PREREQ(maj, min) 0
#endif
/* Some CW versions do not allow enabling C99 from the settings panel. */
#if defined(__MWERKS__)
#pragma c99 on
#endif
#if defined(__STDC_VERSION__)
#if (__STDC_VERSION__ == 199409L) // IAR
#define COMPILER_C99 1 // not true, because partial C99, avoid miscompilation
#elif (__STDC_VERSION__ >= 199901L) // GCC
#define COMPILER_C99 1
#else
#define COMPILER_C99 0
#endif
#endif
/** Concatenate two different preprocessor tokens (allowing macros to expand) */
#define PP_CAT(x,y) PP_CAT__(x,y)
#define PP_CAT__(x,y) x ## y
#define PP_CAT3(x,y,z) PP_CAT(PP_CAT(x,y),z)
#define PP_CAT4(x,y,z,w) PP_CAT(PP_CAT3(x,y,z),w)
#define PP_CAT5(x,y,z,w,j) PP_CAT(PP_CAT4(x,y,z,w),j)
/** String-ize a token (allowing macros to expand) */
#define PP_STRINGIZE(x) PP_STRINGIZE__(x)
#define PP_STRINGIZE__(x) #x
/**
*/
#if COMPILER_C99
#define COUNT_PARMS2(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _, ...) _
#define COUNT_PARMS(...) \
COUNT_PARMS2(11 , ## __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
/**
* usage:
* \code
* #define foo_init(...) PP_CAT(foo_init_, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
* \endcode
*/
#else
#define COUNT_PARMS2(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _, ...) _
#define COUNT_PARMS(args...) \
COUNT_PARMS2(11 , ## args, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
/**
* usage:
* \code
* #define foo_init(args...) PP_CAT(foo_init_, COUNT_PARMS(args)) (args)
* \endcode
*/
#endif
#if defined(__IAR_SYSTEMS_ICC) || defined(__IAR_SYSTEMS_ICC__)
#pragma language=extended
/* IAR iccarm specific functions */
#include <intrinsics.h>
#pragma diag_suppress=Pe940
#pragma inline = forced
#define MEMORY_BARRIER asm("")
#if CPU_ARM || CPU_CM3
#define COMPILER_VARIADIC_MACROS 1
#define INTERRUPT(x) __irq __arm void x (void)
#define INLINE static inline
#define NAKED
/* Include some standard C89/C99 stuff */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#elif CPU_I196
// IAR has size_t as built-in type, but does not define this symbol.
#define _SIZE_T_DEFINED
#define INTERRUPT(x) interrupt [x]
#define REGISTER shortad
#define INLINE /* unsupported */
/*
* Imported from <longjmp.h>. Unfortunately, we can't just include
* this header because it typedefs jmp_buf to be an array of chars.
* This would allow the compiler to place the buffer on an odd address.
* The CPU _should_ be able to perform word accesses to
* unaligned data, but there are *BUGS* in the 80196KC with
* some combinations of opcodes and addressing modes. One of
* these, "ST SP,[?GR]+" is used in the longjmp() implementation
* provided by the IAR compiler ANSI C library. When ?GR contains
* an odd address, surprisingly the CPU will copy the high order
* byte of the source operand (SP) in the low order byte of the
* destination operand (the memory location pointed to by ?GR).
*
* We also need to replace the library setjmp()/longjmp() with
* our own versions because the IAR implementation "forgets" to
* save the contents of local registers (?LR).
*/
struct _JMP_BUF
{
void *sp; /* Stack pointer */
void *return_addr; /* Return address */
int lr[6]; /* 6 local registers */
};
typedef struct _JMP_BUF jmp_buf[1];
int setjmp(jmp_buf env);
void longjmp(jmp_buf env, int val);
/* Fake bool support */
#define true (1==1)
#define false (1!=1)
typedef unsigned char bool;
#else
#error Unsupported CPU
#endif
#elif defined(_MSC_VER) /* Win32 emulation support */
/* MSVC doesn't provide <stdbool.h>. */
#ifndef __cplusplus
#define true (1==1)
#define false (1!=1)
typedef int bool;
#endif /* !__cplusplus */
/* These C99 functions are oddly named in MSVCRT32.lib */
#define snprintf _snprintf
#define vsnprintf _vsnprintf
/* MSVC doesn't support C99's __func__, but has a similar extension. */
#define __func__ __FUNCTION__
/* MSVC doesn't support C99's inline keyword */
#ifndef __cplusplus
#define INLINE __inline
#endif
#elif defined(__GNUC__)
/* Compiler features */
#define COMPILER_VARIADIC_MACROS 1 /* Even in C++ */
#define COMPILER_TYPEOF 1
#define COMPILER_STATEMENT_EXPRESSIONS 1
/* GCC attributes */
#define FORMAT(type,fmt,first) __attribute__((__format__(type, fmt, first)))
#define NORETURN __attribute__((__noreturn__))
#define UNUSED_ARG(type,arg) __attribute__((__unused__)) type arg
#define UNUSED_VAR(type,name) __attribute__((__unused__)) type name
#define USED_VAR(type,name) __attribute__((__used__)) type name
#define INLINE static inline __attribute__((__always_inline__))
#define NOINLINE __attribute__((noinline))
#define LIKELY(x) __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#define PURE_FUNC __attribute__((pure))
#define CONST_FUNC __attribute__((const))
#define UNUSED_FUNC __attribute__((unused))
#define USED_FUNC __attribute__((__used__))
#define RESTRICT __restrict__
#define MUST_CHECK __attribute__((warn_unused_result))
#define PACKED __attribute__((packed))
#define ALIGNED(x) __attribute__ ((__aligned__(x)))
#if CPU_ARM | CPU_CM3
#define NAKED __attribute__((naked))
#else
#define NAKED
#endif
/**
* Force compiler to reload context variable.
*/
#define MEMORY_BARRIER asm volatile ("" : : : "memory")
#if GNUC_PREREQ(3,1)
#define DEPRECATED __attribute__((__deprecated__))
#endif
#if GNUC_PREREQ(4,5)
#define UNREACHABLE() __builtin_unreachable()
#endif
#ifndef __cplusplus
#define ASSERT_TYPE_EQUAL(var1, var2) \
STATIC_ASSERT(__builtin_types_compatible_p(typeof(var1), typeof(var2)))
#define ASSERT_TYPE_IS(var, type) \
STATIC_ASSERT(__builtin_types_compatible_p(typeof(var), type))
#endif
/* Include some standard C89/C99 stuff */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#if !CPU_AVR
#include <sys/types.h> /* for ssize_t */
#endif
#ifndef __cplusplus
/*
* Disallow some C++ keywords as identifiers in C programs,
* for improved portability.
*/
#pragma GCC poison new delete class template typename
#pragma GCC poison private protected public operator
#pragma GCC poison friend mutable using namespace
#pragma GCC poison cin cout cerr clog
#endif
#elif defined(__MWERKS__)
/* Compiler features */
#define COMPILER_VARIADIC_MACROS 1
#define COMPILER_TYPEOF 1
#define COMPILER_STATEMENT_EXPRESSIONS 1
#define typeof __typeof__
#define UNUSED_ARG(type,arg) type
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
// CodeWarrior has size_t as built-in type, but does not define this symbol.
#define _SIZE_T_DEFINED
#else
#error unknown compiler
#endif
/* Defaults for compiler extensions. */
/**
* \def COMPILER_VARIADIC_MACROS
* Support for macros with variable arguments.
*/
#ifndef COMPILER_VARIADIC_MACROS
#define COMPILER_VARIADIC_MACROS (COMPILER_C99 != 0)
#endif
/**
* \def COMPILER_TYPEOF
* Support for dynamic type identification.
*/
#ifndef COMPILER_TYPEOF
#define COMPILER_TYPEOF 0
#endif
/**
* \def COMPILER_STATEMENT_EXPRESSIONS
* Support for statement expressions.
*/
#ifndef COMPILER_STATEMENT_EXPRESSIONS
#define COMPILER_STATEMENT_EXPRESSIONS 0
#endif
/* A few defaults for missing compiler features. */
#ifndef INLINE
#define INLINE static inline
#endif
#ifndef NOINLINE
#define NOINLINE /* nothing */
#endif
#ifndef NORETURN
#define NORETURN /* nothing */
#endif
#ifndef FORMAT
#define FORMAT(type,fmt,first) /* nothing */
#endif
#ifndef DEPRECATED
#define DEPRECATED /* nothing */
#endif
#ifndef UNUSED_ARG
#define UNUSED_ARG(type,arg) type arg
#endif
#ifndef UNUSED_VAR
#define UNUSED_VAR(type,name) type name
#endif
#ifndef USED_VAR
#define USED_VAR(type,name) type name
#endif
#ifndef REGISTER
#define REGISTER /* nothing */
#endif
#ifndef LIKELY
#define LIKELY(x) x
#endif
#ifndef UNLIKELY
#define UNLIKELY(x) x
#endif
#ifndef PURE_FUNC
#define PURE_FUNC /* nothing */
#endif
#ifndef CONST_FUNC
#define CONST_FUNC /* nothing */
#endif
#ifndef UNUSED_FUNC
#define UNUSED_FUNC /* nothing */
#endif
#ifndef USED_FUNC
#define USED_FUNC /* nothing */
#endif
#ifndef RESTRICT
#define RESTRICT /* nothing */
#endif
#ifndef MUST_CHECK
#define MUST_CHECK /* nothing */
#endif
#ifndef PACKED
#define PACKED /* nothing */
#endif
#ifndef ALIGNED
#define ALIGNED /* nothing */
#endif
#ifndef MEMORY_BARRIER
#define MEMORY_BARRIER /* nothing */
#warning No memory barrier defined for select compiler. If you use the kernel check it.
#endif
#ifndef UNREACHABLE
#define UNREACHABLE() for (;;)
#endif
/* Misc definitions */
#ifndef NULL
#define NULL (void *)0
#endif
#ifndef EOF
#define EOF (-1)
#endif
/* Support for hybrid C/C++ applications. */
#ifdef __cplusplus
#define EXTERN_C extern "C"
#define EXTERN_C_BEGIN extern "C" {
#define EXTERN_C_END }
#define EXTERN_CONST extern const
#define CONST_CAST(TYPE,EXPR) (const_cast<TYPE>(EXPR))
#else
#define EXTERN_C extern
#define EXTERN_C_BEGIN /* nothing */
#define EXTERN_C_END /* nothing */
#define EXTERN_CONST const
#define CONST_CAST(TYPE,EXPR) ((TYPE)(EXPR)) /* FIXME: How can we suppress the warning in C? */
#endif
#if defined(_MSC_VER) \
|| ((defined(__IAR_SYSTEMS_ICC) || defined(__IAR_SYSTEMS_ICC__)) && CPU_I196)
/**
* \name ISO C99 fixed-size types
*
* These should be in <stdint.h>, but a few compilers lack them.
* \{
*/
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int int16_t;
typedef unsigned short int uint16_t;
typedef long int int32_t; /* _WIN64 safe */
typedef unsigned long int uint32_t; /* _WIN64 safe */
#ifdef _MSC_VER
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
typedef long long int64_t;
typedef unsigned long long uint64_t;
#endif
/* \} */
#else
/* This is the standard location. */
#include <stdint.h>
#endif
#if CPU_AVR_ATMEGA8
/*
* The ATmega8 has a very small Flash, so we can't afford
* to link in support routines for 32bit integer arithmetic.
*/
typedef int16_t ticks_t; /**< Type for time expressed in ticks. */
typedef int16_t mtime_t; /**< Type for time expressed in milliseconds. */
typedef int16_t utime_t; /**< Type for time expressed in microseconds. */
#define SIZEOF_MTIME_T (16 / CPU_BITS_PER_CHAR)
#define SIZEOF_UTIME_T (16 / CPU_BITS_PER_CHAR)
#define MTIME_INFINITE 0x7FFFL
#else
typedef int32_t ticks_t; /**< Type for time expressed in ticks. */
typedef int32_t utime_t; /**< Type for time expressed in microseconds. */
#define SIZEOF_UTIME_T (32 / CPU_BITS_PER_CHAR)
#ifndef DEVLIB_MTIME_DEFINED
#define DEVLIB_MTIME_DEFINED 1 /* Resolve conflict with <os/hptime.h> */
typedef int32_t mtime_t; /**< Type for time expressed in milliseconds. */
#define SIZEOF_MTIME_T (32 / CPU_BITS_PER_CHAR)
#define MTIME_INFINITE 0x7FFFFFFFL
#endif
#endif
/** User defined callback type */
typedef void (*Hook)(void *);
/** Bulk storage large enough for both pointers or integers. */
typedef void * iptr_t;
/** Bulk storage large enough for both pointers to constants or integers. */
typedef const void * const_iptr_t;
typedef unsigned char sigbit_t; /**< Type for signal bits. */
typedef unsigned char sigmask_t; /**< Type for signal masks. */
/**
* Signal structure
*/
typedef struct Signal
{
sigmask_t wait; /**< Signals the process is waiting for */
sigmask_t recv; /**< Received signals */
} Signal;
/**
* \name Standard type definitions.
*
* These should be in <sys/types.h> or <stddef.h>, but many compilers
* and C libraries lack them.
*
* We check for some common definitions to avoid redefinitions:
*
* glibc, avr-libc: _SIZE_T_DEFINED, __ssize_t_defined
* Darwin libc: _BSD_SIZE_T_DEFINED_, _SIZE_T
* IAR ARM: _SIZE_T
*
* \{
*/
#if !(defined(size_t) || defined(_SIZE_T_DEFINED) || defined(_BSD_SIZE_T_DEFINED_) \
|| defined(_SIZE_T))
#if CPU_X86
/* 32bit or 64bit (32bit for _WIN64). */
typedef unsigned long size_t;
#else
#error Unknown CPU
#endif
#endif
#if !(defined(ssize_t) || defined(_SSIZE_T) || defined(__ssize_t_defined))
#if CPU_X86
/* 32bit or 64bit (32bit for _WIN64). */
typedef long ssize_t;
#elif CPU_ARM || CPU_CM3
typedef int ssize_t;
#elif CPU_AVR || CPU_MSP430
/* 16bit (missing in avr-/msp430-libc's sys/types.h). */
typedef int ssize_t;
#else
#error Unknown CPU
#endif
#endif
/*\}*/
/**
* \name Types for hardware registers.
*
* Only use these types for registers whose contents can
* be changed asynchronously by external hardware.
*
* \{
*/
#if CPU_DSP56K
/* Registers can be accessed only through 16-bit pointers */
typedef volatile uint16_t reg16_t;
#else
typedef volatile uint8_t reg8_t;
typedef volatile uint16_t reg16_t;
typedef volatile uint32_t reg32_t;
#endif
/*\}*/
/* Quasi-ANSI macros */
#ifndef offsetof
/**
* Return the byte offset of the member \a m in struct \a s.
*
* \note This macro should be defined in "stddef.h" and is sometimes
* compiler-specific (g++ has a builtin for it).
*/
#define offsetof(s,m) (size_t)&(((s *)0)->m)
#endif
#ifndef countof
/**
* Count the number of elements in the static array \a a.
*
* \note This macro is non-standard, but implements a very common idiom
*/
#if defined(__GNUC__) && !defined(__cplusplus)
/*
* Perform a compile time type checking: countof() can only
* work with static arrays, so throw a compile time error if a
* pointer is passed as argument.
*
* NOTE: the construct __builtin_types_compatible_p() is only
* available for C.
*/
#define countof(a) (sizeof(a) / sizeof(*(a)) + \
STATIC_ASSERT_EXPR( \
!__builtin_types_compatible_p( \
typeof(a), typeof(&a[0]))))
#else
#define countof(a) (sizeof(a) / sizeof(*(a)))
#endif
#endif
#ifndef alignof
/**
* Return the alignment in memory of a generic data type.
*
* \note We need to worry about alignment when allocating memory that
* will be used later by unknown objects (e.g., malloc()) or, more
* generally, whenever creating generic container types.
*/
#define alignof(type) offsetof(struct { char c; type member; }, member)
#endif
/**
* Cast a member of a structure out to the containing structure.
*
* \param ptr the pointer to the member.
* \param type the type of the container struct this is embedded in.
* \param member the name of the member within the struct.
*/
#if COMPILER_TYPEOF && COMPILER_STATEMENT_EXPRESSIONS
#define containerof(ptr, type, member) ({ \
typeof( ((type *)0)->member ) *_mptr = (ptr); /* type check */ \
(type *)(void *)((char *)_mptr - offsetof(type, member)); \
})
#else
#define containerof(ptr, type, member) \
( (type *)(void *)((char *)(ptr) - offsetof(type, member)) )
#endif
/** Issue a compilation error if the \a condition is false */
#define STATIC_ASSERT(condition) \
UNUSED_VAR(extern char, STATIC_ASSERTION_FAILED__[(condition) ? 1 : -1])
/**
* Issue a compilation error if \a __cond is false (this can be used inside an
* expression).
*/
#define STATIC_ASSERT_EXPR(__cond) \
(sizeof(struct { int STATIC_ASSERTION_FAILED__:!!(__cond); }) * 0)
#ifndef ASSERT_TYPE_EQUAL
/** Ensure two variables have the same type. */
#define ASSERT_TYPE_EQUAL(var1, var2) \
do { (void)(&(var1) == &(var2)); } while(0)
#endif
#ifndef ASSERT_TYPE_IS
/** Ensure variable is of specified type. */
#define ASSERT_TYPE_IS(var, type) \
do { (void)(&(var) == (type *)0); } while(0)
#endif
/**
* Prevent the compiler from optimizing access to the variable \a x, enforcing
* a refetch from memory. This also forbid from reordering successing instances
* of ACCESS_SAFE().
*/
#ifdef __ICCARM__
#define ACCESS_SAFE(x) x
#else
#define ACCESS_SAFE(x) (*(volatile typeof(x) *)&(x))
#endif
#endif /* BERTOS_COMPILER_H */

346
bertos/cfg/debug.h Normal file
View file

@ -0,0 +1,346 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \defgroup debug Debugging facilities and macros
* \ingroup core
* \{
*
* \brief Simple debug facilities for hosted and embedded C/C++ applications.
*
* Debug output goes to stderr in hosted applications.
* Freestanding (AKA embedded) applications use \c drv/kdebug.c to output
* diagnostic messages to a serial terminal or a JTAG debugger.
*
* \author Bernie Innocenti <bernie@codewiz.org>
*
* $WIZ$ module_name = "debug"
* $WIZ$ module_configuration = "bertos/cfg/cfg_debug.h"
* $WIZ$ DEBUG = 1
* $WIZ$ module_depends = "formatwr"
* $WIZ$ module_supports = "not atmega103"
*/
#ifndef BERTOS_DEBUG_H
#define BERTOS_DEBUG_H
#include <cfg/os.h>
#include <cfg/compiler.h>
#include "cfg/cfg_debug.h" /* CONFIG_KDEBUG_* */
/*
* Defaults for rarely used config stuff.
*/
#ifndef CONFIG_KDEBUG_TRACE
#define CONFIG_KDEBUG_TRACE 1
#endif
#ifndef CONFIG_KDEBUG_VERBOSE_ASSERT
#define CONFIG_KDEBUG_VERBOSE_ASSERT 1
#endif
#ifndef CONFIG_KDEBUG_WALLS
#define CONFIG_KDEBUG_WALLS 1
#endif
#if defined(__doxygen__)
/**
* Preprocessor symbol defined only for debug builds.
*
* The build infrastructure must arrange for _DEBUG to
* be predefined for all the source files being compiled.
*
* This is compatible with the MSVC convention for the
* default Debug and Release project targets.
*/
#define _DEBUG 1
#endif
#ifdef _DEBUG
// STLport specific: enable extra checks
#define __STL_DEBUG 1
// MSVC specific: Enable memory allocation debug
#if defined(_MSC_VER)
#include <crtdbg.h>
#endif
/*
* On UNIX systems the extabilished practice is to define
* NDEBUG for release builds and nothing for debug builds.
*/
#ifdef NDEBUG
#undef NDEBUG
#endif
/**
* This macro duplicates the old MSVC trick of redefining
* THIS_FILE locally to avoid the overhead of many duplicate
* strings in ASSERT().
*/
#ifndef THIS_FILE
#define THIS_FILE __FILE__
#endif
/**
* This macro can be used to conditionally exclude one or more
* statements conditioned on \c _DEBUG, avoiding the clutter
* of ifdef/endif pairs.
*
* \code
* struct FooBar
* {
* int foo;
* bool bar;
* DB(int ref_count;) // Track number of users
*
* void release()
* {
* DB(--ref_count;)
* }
* };
* \endcode
*/
#define DB(x) x
#include <cpu/attr.h> /* CPU_HARVARD */
/* These are implemented in drv/kdebug.c */
void kdbg_init(void);
void kputchar(char c);
int kputnum(int num);
void kdump(const void *buf, size_t len);
void __init_wall(long *wall, int size);
#if CPU_HARVARD
#include <cpu/pgm.h>
void kputs_P(const char *PROGMEM str);
void kprintf_P(const char *PROGMEM fmt, ...) FORMAT(__printf__, 1, 2);
int __bassert_P(const char *PROGMEM cond, const char *PROGMEM file, int line);
void __trace_P(const char *func);
void __tracemsg_P(const char *func, const char *PROGMEM fmt, ...);
int __invalid_ptr_P(void *p, const char *PROGMEM name, const char *PROGMEM file, int line);
int __check_wall_P(long *wall, int size, const char * PGM_ATTR name, const char * PGM_ATTR file, int line);
#define kputs(str) kputs_P(PSTR(str))
#define kprintf(fmt, ...) kprintf_P(PSTR(fmt) ,## __VA_ARGS__)
#define __bassert(cond, file, line) __bassert_P(PSTR(cond), PSTR(file), (line))
#define __trace(func) __trace_P(func)
#define __tracemsg(func, fmt, ...) __tracemsg_P(func, PSTR(fmt), ## __VA_ARGS__)
#define __invalid_ptr(p, name, file, line) __invalid_ptr_P((p), PSTR(name), PSTR(file), (line))
#define __check_wall(wall, size, name, file, line) __check_wall_P(wall, size, PSTR(name), PSTR(file), (line))
#else /* !CPU_HARVARD */
void kputs(const char *str);
void kprintf(const char *fmt, ...) FORMAT(__printf__, 1, 2);
int __bassert(const char *cond, const char *file, int line);
void __trace(const char *func);
void __tracemsg(const char *func, const char *fmt, ...) FORMAT(__printf__, 2, 3);
int __invalid_ptr(void *p, const char *name, const char *file, int line);
int __check_wall(long *wall, int size, const char *name, const char *file, int line);
#endif /* !CPU_HARVARD */
#if CONFIG_KDEBUG_VERBOSE_ASSERT
/**
* Assert a pre-condition on code.
*/
#define ASSERT(x) ((void)(LIKELY(x) ? 0 : __bassert(#x, THIS_FILE, __LINE__)))
/**
* Assert a pre-condition and give explanation message when assert fails
*/
#define ASSERT2(x, help) ((void)(LIKELY(x) ? 0 : __bassert(help " (" #x ")", THIS_FILE, __LINE__)))
#else
#define ASSERT(x) ((void)(LIKELY(x) ? 0 : __bassert("", THIS_FILE, __LINE__)))
#define ASSERT2(x, help) ((void)ASSERT(x))
#endif
#define IS_VALID_PTR(p) (LIKELY((void *)(p) >= (void *)CPU_RAM_START))
/**
* Check that the given pointer is either NULL or pointing to valid memory.
*
* The assumption here is that valid pointers never point to low
* memory regions. This helps catching pointers taken from
* struct/class memebers when the struct pointer was NULL.
*
* \see ASSERT_VALID_PTR_OR_NULL()
*/
#define ASSERT_VALID_PTR(p) (IS_VALID_PTR(p) \
? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__))
/**
* Check that the given pointer is not pointing to invalid memory.
*
* \note The check for invalid memory is architecture specific and
* conservative. The current implementation only checks against
* a lower bound.
*
* \see ASSERT_VALID_PTR()
*/
#define ASSERT_VALID_PTR_OR_NULL(p) ((void)(LIKELY((p == NULL) \
|| ((void *)(p) >= (void *)CPU_RAM_START)) \
? 0 : __invalid_ptr((p), #p, THIS_FILE, __LINE__)))
#if CONFIG_KDEBUG_TRACE
#define TRACE __trace(__func__)
#define TRACEMSG(msg,...) __tracemsg(__func__, msg, ## __VA_ARGS__)
#else
#define TRACE do {} while(0)
#define TRACEMSG(...) do {} while(0)
#endif
/**
* Check that the given pointer actually points to an object
* of the specified type.
*/
#define ASSERT_VALID_OBJ(_t, _o) do { \
ASSERT_VALID_PTR((_o)); \
ASSERT(dynamic_cast<_t>((_o)) != NULL); \
}
/**
* \name Debug object creation and destruction.
*
* These macros help track some kinds of leaks in C++ programs.
* Usage is as follows:
*
* \code
* class Foo
* {
* DECLARE_INSTANCE_TRACKING(Foo)
*
* Foo()
* {
* NEW_INSTANCE(Foo);
* // ...
* }
*
* ~Foo()
* {
* DELETE_INSTANCE(Foo);
* // ...
* }
* };
*
* // Put this in the implementation file of the class
* IMPLEMENT_INSTANCE_TRACKING(Foo)
*
* // Client code
* int main(void)
* {
* Foo *foo = new Foo;
* cout << GET_INSTANCE_COUNT(Foo) << endl; // prints "1"
* delete foo;
* ASSERT_ZERO_INSTANCES(Foo); // OK
* }
* \endcode
* \{
*/
#define NEW_INSTANCE(CLASS) do { ++CLASS::__instances } while (0)
#define DELETE_INSTANCE(CLASS) do { --CLASS::__instances } while (0)
#define ASSERT_ZERO_INSTANCES(CLASS) ASSERT(CLASS::__instances == 0)
#define GET_INSTANCE_COUNT(CLASS) (CLASS::__instances)
#define DECLARE_INSTANCE_TRACKING(CLASS) static int __instances
#define IMPLEMENT_INSTANCE_TRACKING(CLASS) int CLASS::__instances = 0
/*\}*/
#else /* !_DEBUG */
/*
* On UNIX systems the extabilished practice is to define
* NDEBUG for release builds and nothing for debug builds.
*/
#ifndef NDEBUG
#define NDEBUG 1
#endif
#define DB(x) /* nothing */
#ifndef ASSERT
#define ASSERT(x) ((void)0)
#endif /* ASSERT */
#define ASSERT2(x, help) ((void)0)
#define IS_VALID_PTR(p) (1)
#define ASSERT_VALID_PTR(p) ((void)0)
#define ASSERT_VALID_PTR_OR_NULL(p) ((void)0)
#define ASSERT_VALID_OBJ(_t, _o) ((void)0)
#define TRACE do {} while (0)
#if COMPILER_VARIADIC_MACROS
#define TRACEMSG(x, ...) do {} while (0)
#else
INLINE void TRACEMSG(UNUSED_ARG(const char *, msg), ...)
{
/* NOP */
}
#endif
#define NEW_INSTANCE(CLASS) do {} while (0)
#define DELETE_INSTANCE(CLASS) do {} while (0)
#define ASSERT_ZERO_INSTANCES(CLASS) do {} while (0)
#define GET_INSTANCE_COUNT(CLASS) ERROR_ONLY_FOR_DEBUG
#define DECLARE_INSTANCE_TRACKING(CLASS)
#define IMPLEMENT_INSTANCE_TRACKING(CLASS)
INLINE void kdbg_init(void) { /* nop */ }
INLINE void kputchar(UNUSED_ARG(char, c)) { /* nop */ }
INLINE int kputnum(UNUSED_ARG(int, num)) { return 0; }
INLINE void kputs(UNUSED_ARG(const char *, str)) { /* nop */ }
INLINE void kdump(UNUSED_ARG(const void *, buf), UNUSED_ARG(size_t, len)) { /* nop */ }
#if defined(__cplusplus) && COMPILER_VARIADIC_MACROS
/* G++ can't inline functions with variable arguments... */
#define kprintf(fmt,...) do { (void)(fmt); } while(0)
#else
/* ...but GCC can. */
INLINE void kprintf(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
#endif
#endif /* _DEBUG */
#if CONFIG_KDEBUG_WALLS
/**
* \name Walls to detect data corruption
* \{
*/
#define WALL_SIZE 8
#define WALL_VALUE (long)0xABADCAFEL
#define DECLARE_WALL(name,size) long name[(size) / sizeof(long)];
#define FWD_DECLARE_WALL(name,size) extern long name[(size) / sizeof(long)];
#define INIT_WALL(name) __init_wall((name), countof(name))
#define CHECK_WALL(name) __check_wall((name), countof(name), #name, THIS_FILE, __LINE__)
/*\}*/
#else
#define DECLARE_WALL(name, size) /* nothing */
#define FWD_DECLARE_WALL(name, size) /* nothing */
#define INIT_WALL(name) do {} while (0)
#define CHECK_WALL(name) do {} while (0)
#endif
/** \} */ // defgroup debug
#endif /* BERTOS_DEBUG_H */

49
bertos/cfg/depend.h Normal file
View file

@ -0,0 +1,49 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief Depend module.
*
* \author Bernie Innocenti <bernie@codewiz.org>
*
*/
#ifndef CFG_DEPEND_H
#define CFG_DEPEND_H
#include <cfg/compiler.h> // STATIC_ASSERT()
/**
* Compile-time enforcement of dependencies between configuration options
*/
#define CONFIG_DEPEND(FEATURE, DEPS) STATIC_ASSERT(!(FEATURE) || !!(DEPS))
#endif // CFG_DEPEND_H

63
bertos/cfg/kfile_debug.c Normal file
View file

@ -0,0 +1,63 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief KFile interface over debug.
*
* \author Francesco Sacchi <batt@develer.com>
*/
#include "kfile_debug.h"
#include <io/kfile.h>
#include <string.h>
static size_t kfiledebug_write(struct KFile *_fd, const void *buf, size_t size)
{
KFILEDEBUG_CAST(_fd);
kprintf("%.*s", (int)size, (const char *)buf);
return size;
}
void kfiledebug_init(KFileDebug *kd)
{
ASSERT(kd);
memset(kd, 0, sizeof(*kd));
kfile_init(&kd->fd);
kd->fd.write = kfiledebug_write;
DB(kd->fd._type = KFT_KFILEDEBUG);
}

76
bertos/cfg/kfile_debug.h Normal file
View file

@ -0,0 +1,76 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2010 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief KFile interface over a debug console.
*
*
* \author Francesco Sacchi <batt@develer.com>
*
* $WIZ$ module_name = "kfiledebug"
* $WIZ$ module_depends = "kfile"
*/
#ifndef CFG_KFILE_DEBUG
#define CFG_KFILE_DEBUG
#include <io/kfile.h>
/**
* Context for KFile over debug console.
*/
typedef struct KFileDebug
{
KFile fd; ///< KFile base class
} KFileDebug;
/**
* ID for KFileDebug.
*/
#define KFT_KFILEDEBUG MAKE_ID('K', 'D', 'B', 'G')
/**
* Convert + ASSERT from generic KFile to KFileDebug.
*/
INLINE KFileDebug * KFILEDEBUG_CAST(KFile *fd)
{
ASSERT(fd->_type == KFT_KFILEDEBUG);
return (KFileDebug *)fd;
}
/**
* Initialize KFileMem struct.
*
* \param km Interface to initialize.
*/
void kfiledebug_init(KFileDebug *km);
#endif /* CFG_KFILE_DEBUG */

200
bertos/cfg/log.h Normal file
View file

@ -0,0 +1,200 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \defgroup logging Logging facilities
* \ingroup core
* \{
* \brief Logging system module.
*
* This module implement a simple interface to use the multi level logging system.
* The log message have the priority order, like this:
*
* - error message (highest)
* - warning message
* - info message (lowest)
*
* With this priority system we log only the messages that have priority higher
* or equal to the log level that has been configurated; messages below the
* selected log level are not included at compile time, so no time and space
* is wasted on unused functions.
*
* Furthermore you can define different log levels for each module. To do this
* you just need to define LOG_LEVEL in the configuration file for the
* selected module.
*
* This module provides two types of macros:
*
* - LOG_* macros: these macros allow formatted output, using the same format
* as kprintf
* - LOG_*B macros: these macros allow to optionally compile a block of code
* depending on the logging level chosen
*
* To use the logging system you should include this module in your driver
* and use one of the LOG_ERR, LOG_WARN and LOG_INFO macros to output error
* messages.
* Then you should define a LOG_LEVEL and LOG_VERBOSE costant in your
* \c cfg/cfg_\<your_cfg_module_name\>.h using the follow policy:
*
* - in your file \c cfg/cfg_\<cfg_module_name\>.h, define the logging
* level and verbosity mode for your specific module:
*
* \code
* /// Module logging level.
* #define <cfg_module_name>_LOG_LEVEL LOG_LVL_INFO
*
* /// Module logging format.
* #define <cfg_module_name>_LOG_FORMAT LOG_FMT_VERBOSE
* \endcode
*
* - then, in the module where you use the logging macros you should define
* the macros LOG_LEVEL and LOG_FORMAT and you should include cfg/log.h
* module, as demonstrated in the following example:
*
* \code
* // Define log settings for cfg/log.h.
* #define LOG_LEVEL <cfg_module_name>_LOG_LEVEL
* #define LOG_FORMAT <cfg_module_name>_LOG_FORMAT
* #include <cfg/log.h>
* \endcode
*
* if you include a log.h module without defining the LOG_LEVEL and LOG_VERBOSE
* macros, the module uses the default settings.
*
* WARNING: when using the log.h module make sure to include this module after
* a \c cfg_<cfg_module_name>.h, because the LOG_LEVEL and LOG_VERBOSE macros
* must be defined before including the log module. Otherwise the log module
* will use the default settings.
*
* \author Daniele Basile <asterix@develer.com>
*
* $WIZ$
*/
#ifndef CFG_LOG_H
#define CFG_LOG_H
#include <cfg/debug.h>
// Use a default setting if nobody defined a log level
#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_LVL_ERR
#endif
// Use a default setting if nobody defined a log format
#ifndef LOG_FORMAT
#define LOG_FORMAT LOG_FMT_TERSE
#endif
/**
* \name Logging level definition
*
* When you choose a log level messages you choose
* also which print function are linked.
* When using a log level, you link all log functions that have a priority
* higher or equal than the level you chose.
* The priority level go from error (highest) to info (lowest).
*
* $WIZ$ log_level = "LOG_LVL_NONE", "LOG_LVL_ERR", "LOG_LVL_WARN", "LOG_LVL_INFO"
* \{
*/
#define LOG_LVL_NONE 0
#define LOG_LVL_ERR 1
#define LOG_LVL_WARN 2
#define LOG_LVL_INFO 3
/** \} */
/**
* \name Logging format
*
* There are two logging format: terse and verbose. The latter prepends
* function names and line number information to each log entry.
*
* $WIZ$ log_format = "LOG_FMT_VERBOSE", "LOG_FMT_TERSE"
* \{
*/
#define LOG_FMT_VERBOSE 1
#define LOG_FMT_TERSE 0
/** \} */
#if LOG_FORMAT == LOG_FMT_VERBOSE
#define LOG_PRINT(str_level, str,...) kprintf("%s():%d:%s: " str, __func__, __LINE__, str_level, ## __VA_ARGS__)
#elif LOG_FORMAT == LOG_FMT_TERSE
#define LOG_PRINT(str_level, str,...) kprintf("%s: " str, str_level, ## __VA_ARGS__)
#else
#error No LOG_FORMAT defined
#endif
#if LOG_LEVEL >= LOG_LVL_ERR
/**
* Output an error message
*/
#define LOG_ERR(str,...) LOG_PRINT("ERR", str, ## __VA_ARGS__)
/**
* Define a code block that will be compiled only when LOG_LEVEL >= LOG_LVL_ERR
*/
#define LOG_ERRB(x) x
#else
INLINE void LOG_ERR(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
#define LOG_ERRB(x) /* Nothing */
#endif
#if LOG_LEVEL >= LOG_LVL_WARN
/**
* Output a warning message
*/
#define LOG_WARN(str,...) LOG_PRINT("WARN", str, ## __VA_ARGS__)
/**
* Define a code block that will be compiled only when LOG_LEVEL >= LOG_LVL_WARN
*/
#define LOG_WARNB(x) x
#else
INLINE void LOG_WARN(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
#define LOG_WARNB(x) /* Nothing */
#endif
#if LOG_LEVEL >= LOG_LVL_INFO
/**
* Output an informative message
*/
#define LOG_INFO(str,...) LOG_PRINT("INFO", str, ## __VA_ARGS__)
/**
* Define a code block that will be compiled only when LOG_LEVEL >= LOG_LVL_INFO
*/
#define LOG_INFOB(x) x
#else
INLINE void LOG_INFO(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
#define LOG_INFOB(x) /* Nothing */
#endif
/** \} */
#endif /* CFG_LOG_H */

412
bertos/cfg/macros.h Normal file
View file

@ -0,0 +1,412 @@
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \defgroup macros General purpose macros
* \ingroup core
* \{
*
* \brief Common and handy function macros
*
* \author Bernie Innocenti <bernie@codewiz.org>
* \author Giovanni Bajo <rasky@develer.com>
*/
#ifndef CFG_MACROS_H
#define CFG_MACROS_H
#include <cfg/compiler.h>
/* avr-gcc does not seem to support libstdc++ */
#if defined(__cplusplus) && !CPU_AVR
/* Type-generic macros implemented with template functions. */
#include <algorithm>
template<class T> inline T ABS(T n) { return n >= 0 ? n : -n; }
#define MIN(a,b) std::min(a, b)
#define MAX(a,b) std::max(a, b)
#define SWAP(a,b) std::swap(a, b)
#elif (COMPILER_STATEMENT_EXPRESSIONS && COMPILER_TYPEOF)
/* Type-generic macros implemented with statement expressions. */
#define ABS(n) ({ \
typeof(n) _n = (n); \
(_n < 0) ? -_n : _n; \
})
#define MIN(a,b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
ASSERT_TYPE_EQUAL(_a, _b); \
/** \
* The (typeof(_a)) cast in necessary: \
* result type of conditional expressions is \
* *NOT* the type of the value returned but \
* the type that would be produced if _a and _b \
* were mixed in an expression. \
* Even in _a and _b are of the same type, \
* if mixed in an expression the type will be \
* (at least) promoted to int! \
*/ \
((typeof(_a))((_a < _b) ? _a : _b)); \
})
#define MAX(a,b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
ASSERT_TYPE_EQUAL(_a, _b); \
/** \
* The (typeof(_a)) cast in necessary: \
* result type of conditional expressions is \
* *NOT* the type of the value returned but \
* the type that would be produced if _a and _b \
* were mixed in an expression. \
* Even in _a and _b are of the same type, \
* if mixed in an expression the type will be \
* (at least) promoted to int! \
*/ \
((typeof(_a))((_a > _b) ? _a : _b)); \
})
#else /* !(COMPILER_STATEMENT_EXPRESSIONS && COMPILER_TYPEOF) */
/* Buggy macros for inferior compilers. */
#define ABS(a) (((a) < 0) ? -(a) : (a))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif /* !(COMPILER_STATEMENT_EXPRESSIONS && COMPILER_TYPEOF) */
/** Align \p value to the next \p align boundary */
#define ALIGN_UP(value, align) (((value) & ((align) - 1)) ? \
(((value) + ((align) - 1)) & ~((align) - 1)) : \
(value))
/** Bound \a x between \a min and \a max. */
#define MINMAX(min,x,max) (MIN(MAX(min, x), max))
#ifdef __cplusplus
/* Use standard implementation from <algorithm> */
#define SWAP(a,b) std::swap(a, b)
#elif COMPILER_TYPEOF
/**
* Type-generic macro to swap \a a with \a b.
*
* \note Arguments are evaluated multiple times.
*/
#define SWAP(a, b) \
do { \
typeof(a) tmp; \
ASSERT_TYPE_EQUAL(a, b); \
tmp = (a); \
(a) = (b); \
(b) = tmp; \
} while (0)
#else /* !COMPILER_TYPEOF */
/* Sub-optimal implementation that only works with integral types. */
#define SWAP(a, b) \
do { \
(a) ^= (b); \
(b) ^= (a); \
(a) ^= (b); \
} while (0)
#endif /* COMPILER_TYPEOF */
/**
* Shuffle the content of \a array that counts \a len elements.
*/
#define SHUFFLE(array, len) \
do { \
int i, j; \
for (i = (len) - 1; i > 0; i--) \
{ \
j = ((i + 1) * (rand() / (RAND_MAX + 1.0))); \
SWAP((array)[i], (array)[j]); \
} \
} while (0)
/**
* Macro to swap \a a with \a b, with explicit type \a T for dumb C89 compilers.
*
* \note Arguments are evaluated multiple times.
*/
#define SWAP_T(a, b, T) \
do { \
T tmp; \
ASSERT_TYPE_IS(a, T); \
ASSERT_TYPE_IS(b, T); \
tmp = (a); \
(a) = (b); \
(b) = tmp; \
} while (0)
/**
* Reverse the bits contained in b (LSB becomes the MSB and so on).
* \note \a b is evaluated twice
*/
#define REVERSE_UINT8(b) \
((uint8_t)((((b) * 0x0802UL & 0x22110UL) | ((b) * 0x8020UL & 0x88440UL)) * 0x10101UL >> 16))
#ifndef BV
/** Convert a bit value to a binary flag. */
#define BV(x) (1<<(x))
#endif
/** Same as BV() but with 32 bit result */
#define BV32(x) ((uint32_t)1<<(x))
/** Same as BV() but with 16 bit result */
#define BV16(x) ((uint16_t)1<<(x))
/** Same as BV() but with 8 bit result */
#define BV8(x) ((uint8_t)1<<(x))
/**
* Perform an integer division rounding the result to the nearest int value.
* \note \a divisor should preferibly be a costant, otherwise this macro generates
* 2 division. Also divisor is evaluated twice.
*/
#define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor))
/**
* Perform an integer division rounding the result to the upper int value.
* \note \a divisor is evaluated twice.
*/
#define DIV_ROUNDUP(dividend, divisor) (((dividend) + (divisor) - 1) / (divisor))
/**
* Perform a multiply between the integer \a a and the float constant \a f.
*
* This macro can be used in order to avoid floating point arithmetics
* in expressions like this:
* \code
* int a, b;
* a = b * 0.5579652750;
* \endcode
*
* This macro rounds the floating point constant to a fraction,
* usign (2 ^ prec) as the denominator.
* For instance, with prec = 8, the constant 0.5579652750 will be rounded to:
* (143 / 256) = 0.55859375
* So, the former code will be transformed to:
* \code
* a = b * 143 / 256;
* \endcode
*
* Since the denominator is a power of 2, we rely on the compiler to optimize
* this to a right shift.
* So, when you have to multiply an integer by a float constant, this macro
* will not use the floating point arithmentics.
* The operation will be converted to a mul + shift, with a huge performance boost.
*
* \note \a f MUST be a constant in order gain performance benefits.
*
* \param a integer you want to multiply
* \param f floating point constant which you want to multply with \a a
* \param prec conversion precision, ranges from 1 to the number of bits in a long.
* The higher, the better the approximation of the float constant will be.
*/
#define INT_MULT(a, f, prec) (((a) * (long)((f) * (1 << (prec)) + 0.5)) >> (prec))
/** Round up \a x to an even multiple of the 2's power \a pad. */
#define ROUND_UP2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1))
/**
* \name Integer round macros.
*
* Round \a x to a multiple of \a base.
* \note If \a x is signed these macros generate a lot of code.
* \{
*/
#define ROUND_DOWN(x, base) ( (x) - ((x) % (base)) )
#define ROUND_UP(x, base) ( ((x) + (base) - 1) - (((x) + (base) - 1) % (base)) )
#define ROUND_NEAREST(x, base) ( ((x) + (base) / 2) - (((x) + (base) / 2) % (base)) )
/* \} */
/** Check if \a x is an integer power of 2. */
#define IS_POW2(x) (!(bool)((x) & ((x)-1)))
/** Calculate a compile-time log2 for a uint8_t */
#define UINT8_LOG2(x) \
((x) < 2 ? 0 : \
((x) < 4 ? 1 : \
((x) < 8 ? 2 : \
((x) < 16 ? 3 : \
((x) < 32 ? 4 : \
((x) < 64 ? 5 : \
((x) < 128 ? 6 : 7)))))))
/** Calculate a compile-time log2 for a uint16_t */
#define UINT16_LOG2(x) \
((x < 256) ? UINT8_LOG2(x) : UINT8_LOG2((x) >> 8) + 8)
/** Calculate a compile-time log2 for a uint32_t */
#define UINT32_LOG2(x) \
((x < 65536UL) ? UINT16_LOG2(x) : UINT16_LOG2((x) >> 16) + 16)
#if COMPILER_VARIADIC_MACROS
/** Count the number of arguments (up to 16). */
#define PP_COUNT(...) \
PP_COUNT__(__VA_ARGS__,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
#define PP_COUNT__(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,count,...) \
count
#endif
#if COMPILER_VARIADIC_MACROS
/**
* \def BIT_CHANGE(reg, (mask, value), ...)
*
* This macro allows for efficient and compact bit toggling in a hardware
* register. It is meant to replace hand-coded cruft which toggles bits
* in sequence.
*
* It is possible to specify an unlimited pair of (mask, value) parameters.
* For instance:
*
* \code
* void set_timer(bool start)
* {
* BIT_CHANGE(REG_CTRL_TIMER,
* (TIMER_MODE, MODE_COUNT),
* (OVL_IRQ, 1),
* (CMP_IRQ, 1),
* (START, start)
* );
* }
* \endcode
*
* The macro expansion will be roughly the following:
*
* \code
* REG_CTRL_TIMER = (REG_CTRL_TIMER & ~(TIMER_MODE|OVL_IRQ|CMP_IRQ|START)
* | (MODE_COUNT|OVL_IRQ|CMP_IRQ|(start ? START : 0));
* \endcode
*
* It is up to the compiler to produce the optimal code. We checked that GCC produces
* the best code in most cases. We preferred this expansion over the use of a block
* with a local variable because CodeWarrior 6.1 was not able to remove completely the
* allocation of the local from the stack.
*
* \note This macro is available only in C99 because it makes use of variadic macros.
* It would be possible to make up an implementation with a slightly different syntax
* for use with C90 compilers, through Boost Preprocessor.
*/
/**
* \def BIT_CHANGE_BV(reg, (bit, value), ...)
*
* Similar to BIT_CHANGE(), but get bits instead of masks (and applies BV() to convert
* them to masks).
*/
#define BIT_EXTRACT_FLAG_0(bit, value) bit
#define BIT_EXTRACT_FLAG_1(bit, value) BV(bit)
#define BIT_EXTRACT_VALUE__(bit, value) value
#define BIT_MASK_SINGLE__(use_bv, index, max, arg) \
((index < max) ? (PP_CAT(BIT_EXTRACT_FLAG_, use_bv) arg) : 0) \
/* */
#define BIT_MASK_IF_SINGLE__(use_bv, index, max, arg) \
(((index < max) && (BIT_EXTRACT_VALUE__ arg)) ? (PP_CAT(BIT_EXTRACT_FLAG_, use_bv) arg) : 0) \
/* */
#define BIT_ITER__2(macro, use_bv, max, a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15, ...) \
(macro(use_bv, 0, max, a0) | \
macro(use_bv, 1, max, a1) | \
macro(use_bv, 2, max, a2) | \
macro(use_bv, 3, max, a3) | \
macro(use_bv, 4, max, a4) | \
macro(use_bv, 5, max, a5) | \
macro(use_bv, 6, max, a6) | \
macro(use_bv, 7, max, a7) | \
macro(use_bv, 8, max, a8) | \
macro(use_bv, 9, max, a9) | \
macro(use_bv, 10, max, a10) | \
macro(use_bv, 11, max, a11) | \
macro(use_bv, 12, max, a12) | \
macro(use_bv, 13, max, a13) | \
macro(use_bv, 14, max, a14) | \
macro(use_bv, 15, max, a15)) \
/* */
#define BIT_ITER__(macro, use_bv, ...) \
BIT_ITER__2(macro, use_bv, PP_COUNT(__VA_ARGS__), __VA_ARGS__, (0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1),(0,1)) \
/* */
#define BIT_MASKS__(use_bv, ...) \
BIT_ITER__(BIT_MASK_SINGLE__, use_bv, __VA_ARGS__)
/* */
#define BIT_MASKS_CONDITIONAL__(use_bv, ...) \
BIT_ITER__(BIT_MASK_IF_SINGLE__, use_bv, __VA_ARGS__)
/* */
#define BIT_CHANGE__(reg, use_bv, ...) \
((reg) = ((reg) & ~BIT_MASKS__(use_bv, __VA_ARGS__)) | BIT_MASKS_CONDITIONAL__(use_bv, __VA_ARGS__)) \
/* */
#define BIT_CHANGE(reg, ...) BIT_CHANGE__(reg, 0, __VA_ARGS__)
#define BIT_CHANGE_BV(reg, ...) BIT_CHANGE__(reg, 1, __VA_ARGS__)
#endif /* COMPILER_VARIADIC_MACROS */
/**
* Macro for rotating bit left or right.
* \{
*/
#define ROTR(var, rot) (((var) >> (rot)) | ((var) << ((sizeof(var) * 8) - (rot))))
#define ROTL(var, rot) (((var) << (rot)) | ((var) >> ((sizeof(var) * 8) - (rot))))
/*\}*/
/**
* Make an id from 4 letters, useful for
* file formats and kfile ids.
*/
#define MAKE_ID(a,b,c,d) \
( ((uint32_t)(a) << 24) \
| ((uint32_t)(b) << 16) \
| ((uint32_t)(c) << 8) \
| ((uint32_t)(d) << 0) )
/**
* Type for id generated by MAKE_ID().
*/
typedef uint32_t id_t;
/**
* Check if a pointer is aligned to a certain power-of-2 size
*/
INLINE bool is_aligned(const void *addr, size_t size)
{
return ((size_t)addr & (size - 1)) == 0;
}
/** \} */ //defgroup macros
#endif /* MACROS_H */

Some files were not shown because too many files have changed in this diff Show more