1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Added some files to the PipXtreme folder.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1955 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2010-10-13 07:49:05 +00:00 committed by pip
parent a3ac3feae9
commit acadc4bc28
12 changed files with 1349 additions and 148 deletions

163
flight/PipXtreme/crc.c Normal file
View File

@ -0,0 +1,163 @@
#include "crc.h"
// **************************************************************************
#define Poly16 0x8408 // HDLC polynomial: 1 + x**5 + x**12 + x**16
#define Poly32 0x04c11db7 // 32-bit polynomial .. this should produce the same as the STM32 hardware CRC
static const uint16_t CRC_Table16[] = { // HDLC polynomial
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
};
static const uint32_t CRC_Table32[] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,
0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,
0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,
0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,
0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,
0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,
0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,
0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,
0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
// **************************************************************************
// 16-bit CRC
inline uint16_t UpdateCRC16(uint16_t crc, uint8_t b)
{ // update the crc - table method
return ((crc >> 8) ^ CRC_Table16[(crc & 0xff) ^ b]);
}
/*
uint16_t UpdateCRC16(uint16_t crc, uint8_t b)
{ // update the fcs - bit band method
register uint8_t f = (uint8_t)(crc >> 8);
crc = (crc & 0x00ff) ^ b;
for (int i = 8; i > 0; i--)
crc = (crc & 1) ? (crc >> 1) ^ Poly16 : crc >> 1;
return (crc ^ f);
}
*/
uint16_t UpdateCRC16Data(uint16_t crc, void *data, uint32_t len)
{
register uint8_t *p = (uint8_t *)data;
for (register uint32_t i = len; i > 0; i--)
crc = (crc >> 8) ^ CRC_Table16[(crc & 0xff) ^ *p++];
// crc = UpdateCRC16(crc, *p++);
return crc;
}
/*
// Generate the CRC table
void MakeCRC_Table16(void)
{
for (uint16_t i = 0; i < 256; i++)
{
uint16_t crc = i;
for (int j = 8; j > 0; j--)
crc = (crc & 1) ? (crc >> 1) ^ Poly16 : crc >> 1;
CRC_Table16[i] = crc;
}
}
*/
// **************************************************************************
// 32-bit CRC
inline uint32_t UpdateCRC32(uint32_t crc, uint8_t b)
{
return ((crc << 8) ^ CRC_Table32[(crc >> 24) ^ b]);
}
/*
uint32_t UpdateCRC32(uint32_t crc, uint8_t b)
{ // update the crc - bit bang method
register uint32_t f = crc << 8;
crc = (crc >> 24) ^ b;
for (int i = 8; i > 0; i--)
crc = (crc & 1) ? (crc << 1) ^ Poly32 : crc << 1;
return (crc ^ f);
}
*/
uint32_t UpdateCRC32Data(uint32_t crc, void *data, uint32_t len)
{
register uint8_t *p = (uint8_t *)data;
for (register uint32_t i = len; i > 0; i--)
crc = (crc << 8) ^ CRC_Table32[(crc >> 24) ^ *p++];
// crc = UpdateCRC32(crc, *p++);
return crc;
}
/*
// Generate the CRC table
void MakeCRC_Table32(void)
{
for (uint32_t i = 0; i < 256; i++)
{
uint32_t crc = i;
for (int j = 8; j > 0; j--)
crc = (crc & 1) ? (crc << 1) ^ Poly32 : crc << 1;
CRC_Table32[i] = crc;
}
}
*/
// **************************************************************************
void CRC_init(void)
{
// MakeCRC_Table16();
// MakeCRC_Table32();
}
// **************************************************************************

182
flight/PipXtreme/gpio_in.c Normal file
View File

@ -0,0 +1,182 @@
/**
******************************************************************************
*
* @file gpio_in.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief GPIO input functions
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* *****************************************************************
// Example pin definitions .. this would go into your pios_board.h file
// GPIO_Mode_AIN Analog Input
// GPIO_Mode_IN_FLOATING Input Floating
// GPIO_Mode_IPD Input Pull-Down
// GPIO_Mode_IPU Input Pull-up
// API mode line
#define GPIO_IN_0_PORT GPIOB
#define GPIO_IN_0_PIN GPIO_Pin_13
#define GPIO_IN_0_MODE GPIO_Mode_IPU
// Serial port CTS line
#define GPIO_IN_1_PORT GPIOB
#define GPIO_IN_1_PIN GPIO_Pin_14
#define GPIO_IN_1_MODE GPIO_Mode_IPU
#define GPIO_IN_NUM 2
#define GPIO_IN_PORTS { GPIO_IN_0_PORT, GPIO_IN_1_PORT }
#define GPIO_IN_PINS { GPIO_IN_0_PIN, GPIO_IN_1_PIN }
#define GPIO_IN_MODES { GPIO_IN_0_MODE, GPIO_IN_1_MODE }
#define API_MODE_PIN 0
#define SERIAL_CTS_PIN 1
*********************************************************************
Example usage ..
{
// setup all the GPIO input pins
GPIO_IN_Init();
if (!GPIO_IN(API_MODE_PIN))
{ // pin is LOW
}
else
{ // pin is HIGH
}
}
***************************************************************************** */
#include <pios.h>
#include "gpio_in.h"
// *****************************************************************************
// setup the GPIO input pins
// PORT ..
// GPIOA
// GPIOB
// GPIOC
// GPIOD
// GPIOE
// GPIOF
// GPIOG
// PIN ..
// GPIO_Pin_0
// GPIO_Pin_1
// GPIO_Pin_2
// GPIO_Pin_3
// GPIO_Pin_4
// GPIO_Pin_5
// GPIO_Pin_6
// GPIO_Pin_7
// GPIO_Pin_8
// GPIO_Pin_9
// GPIO_Pin_10
// GPIO_Pin_11
// GPIO_Pin_12
// GPIO_Pin_13
// GPIO_Pin_14
// GPIO_Pin_15
// MODE ..
// GPIO_Mode_AIN Analog Input
// GPIO_Mode_IN_FLOATING Input Floating
// GPIO_Mode_IPD Input Pull-Down
// GPIO_Mode_IPU Input Pull-up
#if defined(GPIO_IN_NUM) && defined(GPIO_IN_PORTS) && defined(GPIO_IN_PINS) && defined(GPIO_IN_MODES)
// #if defined(PIOS_INCLUDE_GPIO_IN) && defined(PIOS_GPIO_IN_NUM) && defined(PIOS_GPIO_IN_PORTS) && defined(PIOS_GPIO_IN_PINS) && defined(PIOS_GPIO_IN_MODES)
// Local Variables
static GPIO_TypeDef *GPIO_IN_PORT[GPIO_IN_NUM] = GPIO_IN_PORTS;
static const uint32_t GPIO_IN_PIN[GPIO_IN_NUM] = GPIO_IN_PINS;
static const uint32_t GPIO_IN_MODE[GPIO_IN_NUM] = GPIO_IN_MODES;
/**
* Initialises all the GPIO INPUT's
*/
void GPIO_IN_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
for (int i = 0; i < GPIO_IN_NUM; i++)
{
switch ((uint32_t)GPIO_IN_PORT[i])
{
case (uint32_t)GPIOA: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); break;
case (uint32_t)GPIOB: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); break;
case (uint32_t)GPIOC: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); break;
case (uint32_t)GPIOD: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); break;
case (uint32_t)GPIOE: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); break;
case (uint32_t)GPIOF: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); break;
case (uint32_t)GPIOG: RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE); break;
}
GPIO_InitStructure.GPIO_Pin = GPIO_IN_PIN[i];
GPIO_InitStructure.GPIO_Mode = GPIO_IN_MODE[i];
GPIO_Init(GPIO_IN_PORT[i], &GPIO_InitStructure);
}
}
/**
* Read input pin level
* \param[num] Pin Pin Number
*/
bool GPIO_IN(uint8_t num)
{ // return ..
// FALSE if the input pin is LOW
// TRUE if the input pin is HIGH
if (num >= GPIO_IN_NUM) return FALSE;
return ((GPIO_IN_PORT[num]->IDR & GPIO_IN_PIN[num]) != 0);
}
#endif
// ***********************************************************************************
/**
* @}
* @}
*/

View File

@ -0,0 +1,19 @@
#ifndef _crc_H
#define _crc_H
#include "stm32f10x.h"
// ********************************************************************
uint16_t UpdateCRC16(uint16_t crc, uint8_t b);
uint16_t UpdateCRC16Data(uint16_t crc, void *data, uint32_t len);
uint32_t UpdateCRC32(uint32_t crc, uint8_t b);
uint32_t UpdateCRC32Data(uint32_t crc, void *data, uint32_t len);
void CRC_init(void);
// ********************************************************************
#endif

View File

@ -1,9 +1,9 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file pipbee.h * @file gpio_in.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Main PipBee header. * @brief GPIO functions header.
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* *
*****************************************************************************/ *****************************************************************************/
@ -23,12 +23,19 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef __GPIO_IN_H__
#define __GPIO_IN_H__
#ifndef PIPBEE_H // *****************************************************************
#define PIPBEE_H
void GPIO_IN_Init(void);
bool GPIO_IN(uint8_t num);
/* PIOS Includes */ // *****************************************************************
#include <pios.h>
#endif /* PIPBEE_H */ #endif
/**
* @}
* @}
*/

View File

@ -23,21 +23,19 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef PIOS_BOARD_H #ifndef PIOS_BOARD_H
#define PIOS_BOARD_H #define PIOS_BOARD_H
// *****************************************************************
//------------------------
// Timers and Channels Used // Timers and Channels Used
//------------------------
/* /*
Timer | Channel 1 | Channel 2 | Channel 3 | Channel 4 Timer | Channel 1 | Channel 2 | Channel 3 | Channel 4
------+-----------+-----------+-----------+---------- ------+-----------+-----------+-----------+----------
TIM1 | | | | TIM1 | | | |
TIM2 | --------------- PIOS_DELAY ----------------- TIM2 | --------------- DELAY ----------------------
TIM3 | | | | TIM3 | --------------- Timer Interrupt ------------
TIM4 | | | | TIM4 | --------------- STOPWATCH ------------------
TIM5 | | | | TIM5 | | | |
TIM6 | | | | TIM6 | | | |
TIM7 | | | | TIM7 | | | |
@ -61,9 +59,29 @@ TIM8 | | | |
/* Channel 11 - */ /* Channel 11 - */
/* Channel 12 - */ /* Channel 12 - */
//------------------------ // *****************************************************************
// System Settings
#define PIOS_MASTER_CLOCK 72000000ul
#define PIOS_PERIPHERAL_CLOCK (PIOS_MASTER_CLOCK / 2)
#if defined(USE_BOOTLOADER)
#define PIOS_NVIC_VECTTAB_FLASH ((uint32_t)0x08006000)
#else
#define PIOS_NVIC_VECTTAB_FLASH ((uint32_t)0x08000000)
#endif
// *****************************************************************
// Interrupt Priorities
#define PIOS_IRQ_PRIO_LOW 12 // lower than RTOS
#define PIOS_IRQ_PRIO_MID 8 // higher than RTOS
#define PIOS_IRQ_PRIO_HIGH 5 // for SPI, ADC, I2C etc...
#define PIOS_IRQ_PRIO_HIGHEST 4 // for USART etc...
// *****************************************************************
// PIOS_LED // PIOS_LED
//------------------------
#define PIOS_LED_LED1_GPIO_PORT GPIOA // USB Activity LED #define PIOS_LED_LED1_GPIO_PORT GPIOA // USB Activity LED
#define PIOS_LED_LED1_GPIO_PIN GPIO_Pin_3 #define PIOS_LED_LED1_GPIO_PIN GPIO_Pin_3
#define PIOS_LED_LED1_GPIO_CLK RCC_APB2Periph_GPIOA #define PIOS_LED_LED1_GPIO_CLK RCC_APB2Periph_GPIOA
@ -88,129 +106,79 @@ TIM8 | | | |
#define USB_LED_ON PIOS_LED_On(LED1) #define USB_LED_ON PIOS_LED_On(LED1)
#define USB_LED_OFF PIOS_LED_Off(LED1) #define USB_LED_OFF PIOS_LED_Off(LED1)
#define USB_LED_TOGGLE PIOS_LED_Toggle(LED1) #define USB_LED_TOGGLE PIOS_LED_Toggle(LED1)
#define LINK_LED_ON PIOS_LED_On(LED2) #define LINK_LED_ON PIOS_LED_On(LED2)
#define LINK_LED_OFF PIOS_LED_Off(LED2) #define LINK_LED_OFF PIOS_LED_Off(LED2)
#define LINK_LED_TOGGLE PIOS_LED_Toggle(LED2) #define LINK_LED_TOGGLE PIOS_LED_Toggle(LED2)
#define RX_LED_ON PIOS_LED_On(LED3) #define RX_LED_ON PIOS_LED_On(LED3)
#define RX_LED_OFF PIOS_LED_Off(LED3) #define RX_LED_OFF PIOS_LED_Off(LED3)
#define RX_LED_TOGGLE PIOS_LED_Toggle(LED3) #define RX_LED_TOGGLE PIOS_LED_Toggle(LED3)
#define TX_LED_ON PIOS_LED_On(LED4) #define TX_LED_ON PIOS_LED_On(LED4)
#define TX_LED_OFF PIOS_LED_Off(LED4) #define TX_LED_OFF PIOS_LED_Off(LED4)
#define TX_LED_TOGGLE PIOS_LED_Toggle(LED4) #define TX_LED_TOGGLE PIOS_LED_Toggle(LED4)
//------------------------- // *****************************************************************
// Delay Timer // Delay Timer
//-------------------------
#define PIOS_DELAY_TIMER TIM2 #define PIOS_DELAY_TIMER TIM2
#define PIOS_DELAY_TIMER_RCC_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE) #define PIOS_DELAY_TIMER_RCC_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE)
//------------------------- // *****************************************************************
// System Settings // Timer interrupt
//-------------------------
#define PIOS_MASTER_CLOCK 72000000
#define PIOS_PERIPHERAL_CLOCK (PIOS_MASTER_CLOCK / 2)
#if defined(USE_BOOTLOADER)
#define PIOS_NVIC_VECTTAB_FLASH ((uint32_t)0x08006000)
#else
#define PIOS_NVIC_VECTTAB_FLASH ((uint32_t)0x08000000)
#endif
//------------------------- #define TIMER_INT_TIMER TIM3
// Interrupt Priorities #define TIMER_INT_FUNC TIM3_IRQHandler
//------------------------- #define TIMER_INT_PRIORITY 0
#define PIOS_IRQ_PRIO_LOW 12 // lower than RTOS
#define PIOS_IRQ_PRIO_MID 8 // higher than RTOS
#define PIOS_IRQ_PRIO_HIGH 5 // for SPI, ADC, I2C etc...
#define PIOS_IRQ_PRIO_HIGHEST 4 // for USART etc...
//------------------------- // *****************************************************************
// Stop watch timer
#define STOPWATCH_TIMER TIM4
// *****************************************************************
// SPI // SPI
// //
// See also pios_board.c // See also pios_board.c
//-------------------------
#define PIOS_SPI_PERIF 0
//------------------------- #define PIOS_SPI_PORT 0
// *****************************************************************
// PIOS_USART // PIOS_USART
//-------------------------
#define PIOS_USART_RX_BUFFER_SIZE 512 #define PIOS_USART_RX_BUFFER_SIZE 512
#define PIOS_USART_TX_BUFFER_SIZE 256 #define PIOS_USART_TX_BUFFER_SIZE 256
//#define PIOS_USART_BAUDRATE 57600
#define PIOS_USART_BAUDRATE 115200
#define PIOS_COM_SERIAL 0 #define PIOS_COM_SERIAL 0
#define PIOS_COM_DEBUG PIOS_COM_SERIAL #define PIOS_COM_DEBUG PIOS_COM_SERIAL // comment this out if you don't want debug text sent out on the serial port
//------------------------- #if defined(PIOS_INCLUDE_USB_HID)
#define PIOS_COM_TELEM_USB 1
#if 0
//-------------------------
// ADC
// PIOS_ADC_PinGet(0) = Accel Z
// PIOS_ADC_PinGet(1) =
// PIOS_ADC_PinGet(2) =
// PIOS_ADC_PinGet(3) =
// PIOS_ADC_PinGet(4) = Accel ?
// PIOS_ADC_PinGet(5) =
// PIOS_ADC_PinGet(6) =
// PIOS_ADC_PinGet(7) =
//-------------------------
//#define PIOS_ADC_OVERSAMPLING_RATE 1
#define PIOS_ADC_USE_TEMP_SENSOR 0
#define PIOS_ADC_TEMP_SENSOR_ADC ADC1
#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1
#define PIOS_ADC_PIN1_GPIO_PORT GPIOB // PB1 (PSU Voltage)
#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_1 // ADC12_IN9
#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_9
#define PIOS_ADC_PIN1_ADC ADC2
#define PIOS_ADC_PIN1_ADC_NUMBER 4
#define PIOS_ADC_NUM_PINS 1
#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT }
#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN }
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL }
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC }
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER }
#define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR)
#define PIOS_ADC_NUM_ADC_CHANNELS 2
#define PIOS_ADC_USE_ADC2 1
#define PIOS_ADC_CLOCK_FUNCTION RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE)
#define PIOS_ADC_ADCCLK RCC_PCLK2_Div8
/* RCC_PCLK2_Div2: ADC clock = PCLK2/2 */
/* RCC_PCLK2_Div4: ADC clock = PCLK2/4 */
/* RCC_PCLK2_Div6: ADC clock = PCLK2/6 */
/* RCC_PCLK2_Div8: ADC clock = PCLK2/8 */
#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_239Cycles5
/* Sample time: */
/* With an ADCCLK = 14 MHz and a sampling time of 293.5 cycles: */
/* Tconv = 239.5 + 12.5 = 252 cycles = 18<31>s */
/* (1 / (ADCCLK / CYCLES)) = Sample Time (<28>S) */
#define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_HIGH
#endif #endif
//------------------------- // *****************************************************************
// ADC // ADC
// PIOS_ADC_PinGet(0) = Accel Z
// PIOS_ADC_PinGet(1) =
// PIOS_ADC_PinGet(2) =
// PIOS_ADC_PinGet(3) =
// PIOS_ADC_PinGet(4) = Accel ?
// PIOS_ADC_PinGet(5) =
// PIOS_ADC_PinGet(6) =
// PIOS_ADC_PinGet(7) =
//-------------------------
//#define PIOS_ADC_OVERSAMPLING_RATE 1
#define PIOS_ADC_USE_TEMP_SENSOR 0
#define PIOS_ADC_TEMP_SENSOR_ADC ADC1
#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1
#define PIOS_ADC_PIN1_GPIO_PORT GPIOB // PB1 (PSU Voltage) // PIOS_ADC_PinGet(0) = Temperature Sensor (On-board)
#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_1 // ADC12_IN9 // PIOS_ADC_PinGet(1) = PSU Voltage
#define PIOS_ADC_OVERSAMPLING_RATE 2
#define PIOS_ADC_USE_TEMP_SENSOR 1
#define PIOS_ADC_TEMP_SENSOR_ADC ADC1
#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 16 // Temperature sensor channel
//#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 17 // VREF channel
#define PIOS_ADC_PIN1_GPIO_PORT GPIOB // Port B (PSU Voltage)
#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_1 // PB1 .. ADC12_IN9
#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_9 #define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_9
#define PIOS_ADC_PIN1_ADC ADC2 #define PIOS_ADC_PIN1_ADC ADC2
#define PIOS_ADC_PIN1_ADC_NUMBER 4 #define PIOS_ADC_PIN1_ADC_NUMBER 1
#define PIOS_ADC_NUM_PINS 1 #define PIOS_ADC_NUM_PINS 1
@ -219,15 +187,22 @@ TIM8 | | | |
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL } #define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL }
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC } #define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC }
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER } #define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER }
#define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR) #define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR)
#define PIOS_ADC_NUM_ADC_CHANNELS 2 #define PIOS_ADC_NUM_ADC_CHANNELS 2
#define PIOS_ADC_USE_ADC2 1 #define PIOS_ADC_USE_ADC2 1
#define PIOS_ADC_CLOCK_FUNCTION RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE) #define PIOS_ADC_CLOCK_FUNCTION RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE)
#define PIOS_ADC_ADCCLK RCC_PCLK2_Div8 //#define PIOS_ADC_ADCCLK RCC_PCLK2_Div2 // ADC clock = PCLK2/2
/* RCC_PCLK2_Div2: ADC clock = PCLK2/2 */ //#define PIOS_ADC_ADCCLK RCC_PCLK2_Div4 // ADC clock = PCLK2/4
/* RCC_PCLK2_Div4: ADC clock = PCLK2/4 */ //#define PIOS_ADC_ADCCLK RCC_PCLK2_Div6 // ADC clock = PCLK2/6
/* RCC_PCLK2_Div6: ADC clock = PCLK2/6 */ #define PIOS_ADC_ADCCLK RCC_PCLK2_Div8 // ADC clock = PCLK2/8
/* RCC_PCLK2_Div8: ADC clock = PCLK2/8 */ //#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_1Cycles5
//#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_7Cycles5
//#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_13Cycles5
//#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_28Cycles5
//#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_41Cycles5
//#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_55Cycles5
//#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_71Cycles5
#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_239Cycles5 #define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_239Cycles5
/* Sample time: */ /* Sample time: */
/* With an ADCCLK = 14 MHz and a sampling time of 293.5 cycles: */ /* With an ADCCLK = 14 MHz and a sampling time of 293.5 cycles: */
@ -235,21 +210,131 @@ TIM8 | | | |
/* (1 / (ADCCLK / CYCLES)) = Sample Time (<28>S) */ /* (1 / (ADCCLK / CYCLES)) = Sample Time (<28>S) */
#define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_HIGH #define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_HIGH
//------------------------- // *****************************************************************
// GPIO // GPIO output pins
//-------------------------
#define PIOS_GPIO_1_PORT GPIOB // GPIO_Mode_Out_OD Open Drain Output
#define PIOS_GPIO_1_PIN GPIO_Pin_15 // GPIO_Mode_Out_PP Push-Pull Output
#define PIOS_GPIO_1_GPIO_CLK RCC_APB2Periph_GPIOB // GPIO_Mode_AF_OD Open Drain Output Alternate-Function
#define PIOS_GPIO_PORTS { PIOS_GPIO_1_PORT } // GPIO_Mode_AF_PP Push-Pull Output Alternate-Function
#define PIOS_GPIO_PINS { PIOS_GPIO_1_PIN }
#define PIOS_GPIO_CLKS { PIOS_GPIO_1_GPIO_CLK }
#define PIOS_GPIO_NUM 1
#define SET_RTS PIOS_GPIO_On(0); // Serial port RTS line
#define CLEAR_RTS PIOS_GPIO_Off(0); #define PIOS_GPIO_OUT_0_PORT GPIOB
#define PIOS_GPIO_OUT_0_PIN GPIO_Pin_15
#define PIOS_GPIO_OUT_0_GPIO_CLK RCC_APB2Periph_GPIOB
//------------------------- // RF module chip-select line
#define PIOS_GPIO_OUT_1_PORT GPIOA
#define PIOS_GPIO_OUT_1_PIN GPIO_Pin_4
#define PIOS_GPIO_OUT_1_GPIO_CLK RCC_APB2Periph_GPIOA
// EEPROM chip-select line
#define PIOS_GPIO_OUT_2_PORT GPIOA
#define PIOS_GPIO_OUT_2_PIN GPIO_Pin_1
#define PIOS_GPIO_OUT_2_GPIO_CLK RCC_APB2Periph_GPIOA
/*
// SPI-1 SCK line
#define PIOS_GPIO_OUT_3_PORT GPIOA
#define PIOS_GPIO_OUT_3_PIN GPIO_Pin_5
#define PIOS_GPIO_OUT_3_GPIO_CLK RCC_APB2Periph_GPIOA
// SPI-1 MOSI line
#define PIOS_GPIO_OUT_4_PORT GPIOA
#define PIOS_GPIO_OUT_4_PIN GPIO_Pin_7
#define PIOS_GPIO_OUT_4_GPIO_CLK RCC_APB2Periph_GPIOA
*/
#define PIOS_GPIO_NUM 3
#define PIOS_GPIO_PORTS { PIOS_GPIO_OUT_0_PORT, PIOS_GPIO_OUT_1_PORT, PIOS_GPIO_OUT_2_PORT, }
#define PIOS_GPIO_PINS { PIOS_GPIO_OUT_0_PIN, PIOS_GPIO_OUT_1_PIN, PIOS_GPIO_OUT_2_PIN, }
#define PIOS_GPIO_CLKS { PIOS_GPIO_OUT_0_GPIO_CLK, PIOS_GPIO_OUT_1_GPIO_CLK, PIOS_GPIO_OUT_2_GPIO_CLK }
#define SERIAL_RTS_ENABLE PIOS_GPIO_Enable(0)
#define SERIAL_RTS_SET PIOS_GPIO_Off(0)
#define SERIAL_RTS_CLEAR PIOS_GPIO_On(0)
#define RF_CS_ENABLE PIOS_GPIO_Enable(1)
#define RF_CS_HIGH PIOS_GPIO_Off(1)
#define RF_CS_LOW PIOS_GPIO_On(1)
#define EE_CS_ENABLE PIOS_GPIO_Enable(2)
#define EE_CS_HIGH PIOS_GPIO_Off(2)
#define EE_CS_LOW PIOS_GPIO_On(2)
/*
#define SPI1_SCK_ENABLE PIOS_GPIO_Enable(3)
#define SPI1_SCK_HIGH PIOS_GPIO_Off(3)
#define SPI1_SCK_LOW PIOS_GPIO_On(3)
#define SPI1_MOSI_ENABLE PIOS_GPIO_Enable(4)
#define SPI1_MOSI_HIGH PIOS_GPIO_Off(4)
#define SPI1_MOSI_LOW PIOS_GPIO_On(4)
*/
// *****************************************************************
// GPIO input pins
// GPIO_Mode_AIN Analog Input
// GPIO_Mode_IN_FLOATING Input Floating
// GPIO_Mode_IPD Input Pull-Down
// GPIO_Mode_IPU Input Pull-up
// API mode line
#define GPIO_IN_0_PORT GPIOB
#define GPIO_IN_0_PIN GPIO_Pin_13
#define GPIO_IN_0_MODE GPIO_Mode_IPU
// Serial port CTS line
#define GPIO_IN_1_PORT GPIOB
#define GPIO_IN_1_PIN GPIO_Pin_14
#define GPIO_IN_1_MODE GPIO_Mode_IPU
// VBUS sense line
#define GPIO_IN_2_PORT GPIOA
#define GPIO_IN_2_PIN GPIO_Pin_8
#define GPIO_IN_2_MODE GPIO_Mode_IN_FLOATING
// 868MHz JP
#define GPIO_IN_3_PORT GPIOB
#define GPIO_IN_3_PIN GPIO_Pin_8
#define GPIO_IN_3_MODE GPIO_Mode_IPU
// 915MHz JP
#define GPIO_IN_4_PORT GPIOB
#define GPIO_IN_4_PIN GPIO_Pin_9
#define GPIO_IN_4_MODE GPIO_Mode_IPU
// RF INT line
#define GPIO_IN_5_PORT GPIOA
#define GPIO_IN_5_PIN GPIO_Pin_2
#define GPIO_IN_5_MODE GPIO_Mode_IN_FLOATING
// RF misc line
#define GPIO_IN_6_PORT GPIOB
#define GPIO_IN_6_PIN GPIO_Pin_0
#define GPIO_IN_6_MODE GPIO_Mode_IN_FLOATING
#define GPIO_IN_NUM 7
#define GPIO_IN_PORTS { GPIO_IN_0_PORT, GPIO_IN_1_PORT, GPIO_IN_2_PORT, GPIO_IN_3_PORT, GPIO_IN_4_PORT, GPIO_IN_5_PORT, GPIO_IN_6_PORT }
#define GPIO_IN_PINS { GPIO_IN_0_PIN, GPIO_IN_1_PIN, GPIO_IN_2_PIN, GPIO_IN_3_PIN, GPIO_IN_4_PIN, GPIO_IN_5_PIN, GPIO_IN_6_PIN }
#define GPIO_IN_MODES { GPIO_IN_0_MODE, GPIO_IN_1_MODE, GPIO_IN_2_MODE, GPIO_IN_3_MODE, GPIO_IN_4_MODE, GPIO_IN_5_MODE, GPIO_IN_6_MODE }
#define API_MODE_PIN 0
#define SERIAL_CTS_PIN 1
#define VBUS_SENSE_PIN 2
#define _868MHz_PIN 3
#define _915MHz_PIN 4
#define RF_INT_PIN 5
#define RF_MISC_PIN 6
// *****************************************************************
// USB
#if defined(PIOS_INCLUDE_USB_HID)
#define PIOS_USB_ENABLED 1
#define PIOS_USB_DETECT_GPIO_PORT GPIO_IN_2_PORT
#define PIOS_USB_DETECT_GPIO_PIN GPIO_IN_2_PIN
#define PIOS_USB_DETECT_EXTI_LINE EXTI_Line4
#define PIOS_IRQ_USB_PRIORITY PIOS_IRQ_PRIO_MID
#endif
// *****************************************************************
#endif /* PIOS_BOARD_H */ #endif /* PIOS_BOARD_H */

View File

@ -38,6 +38,7 @@
#define PIOS_INCLUDE_USART #define PIOS_INCLUDE_USART
#define PIOS_INCLUDE_COM #define PIOS_INCLUDE_COM
#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_GPIO
#define PIOS_INCLUDE_EXTI
//#define PIOS_INCLUDE_USB_HID
#endif /* PIOS_CONFIG_H */ #endif /* PIOS_CONFIG_H */

View File

@ -0,0 +1,86 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Functions
* @brief PIOS USB interface code
* @{
*
* @file pios_usb.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB functions header.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PIOS_USB_H
#define PIOS_USB_H
/* Local defines */
/* Following settings allow to customise the USB device descriptor */
#ifndef PIOS_USB_VENDOR_ID
#define PIOS_USB_VENDOR_ID 0x20A0
#endif
#ifndef PIOS_USB_VENDOR_STR
#define PIOS_USB_VENDOR_STR "openpilot.org"
#endif
#ifndef PIOS_USB_PRODUCT_STR
#define PIOS_USB_PRODUCT_STR "OpenPilot"
#endif
#ifndef PIOS_USB_PRODUCT_ID
#define PIOS_USB_PRODUCT_ID 0x4117
#endif
#ifndef PIOS_USB_VERSION_ID
#define PIOS_USB_VERSION_ID 0x0200 /* v2.00 */
#endif
/* Internal defines which are used by PIOS USB HID (don't touch) */
#define PIOS_USB_EP_NUM 2
/* Buffer table base address */
#define PIOS_USB_BTABLE_ADDRESS 0x000
/* EP0 rx/tx buffer base address */
#define PIOS_USB_ENDP0_RXADDR 0x040
#define PIOS_USB_ENDP0_TXADDR 0x080
/* EP1 Rx/Tx buffer base address for HID driver */
#define PIOS_USB_ENDP1_TXADDR 0x0C0
#define PIOS_USB_ENDP1_RXADDR 0x100
/* Global Variables */
extern void (*pEpInt_IN[7])(void);
extern void (*pEpInt_OUT[7])(void);
/* Public Functions */
extern int32_t PIOS_USB_Init(uint32_t mode);
extern int32_t PIOS_USB_IsInitialized(void);
extern int32_t PIOS_USB_CableConnected(void);
#endif /* PIOS_USB_H */
/**
* @}
* @}
*/

View File

@ -0,0 +1,56 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_desc.h
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Descriptor Header for Custom HID Demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_DESC_H
#define __USB_DESC_H
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported define -----------------------------------------------------------*/
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
#define USB_STRING_DESCRIPTOR_TYPE 0x03
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
#define HID_DESCRIPTOR_TYPE 0x21
#define PIOS_HID_SIZ_HID_DESC 0x09
#define PIOS_HID_OFF_HID_DESC 0x12
#define PIOS_HID_SIZ_DEVICE_DESC 18
#define PIOS_HID_SIZ_CONFIG_DESC 41
#define PIOS_HID_SIZ_REPORT_DESC 36
#define PIOS_HID_SIZ_STRING_LANGID 4
#define PIOS_HID_SIZ_STRING_VENDOR 28
#define PIOS_HID_SIZ_STRING_PRODUCT 20
#define PIOS_HID_SIZ_STRING_SERIAL 52 /* 96 bits, 12 bytes, 24 characters, 48 in unicode */
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
/* Exported functions ------------------------------------------------------- */
extern const uint8_t PIOS_HID_DeviceDescriptor[PIOS_HID_SIZ_DEVICE_DESC];
extern const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC];
extern const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC];
extern const uint8_t PIOS_HID_StringLangID[PIOS_HID_SIZ_STRING_LANGID];
extern const uint8_t PIOS_HID_StringVendor[PIOS_HID_SIZ_STRING_VENDOR];
extern const uint8_t PIOS_HID_StringProduct[PIOS_HID_SIZ_STRING_PRODUCT];
extern uint8_t PIOS_HID_StringSerial[PIOS_HID_SIZ_STRING_SERIAL];
#endif /* __USB_DESC_H */
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,40 @@
/**
******************************************************************************
*
* @file stopwatch.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Stop watch function
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __STOPWATCH_H__
#define __STOPWATCH_H__
#include "stm32f10x.h"
// *****************************************************************************
void STOPWATCH_init(uint32_t resolution);
void STOPWATCH_reset(void);
uint32_t STOPWATCH_get_count(void);
uint32_t STOPWATCH_get_us(void);
// *****************************************************************************
#endif

View File

@ -0,0 +1,186 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_conf.h
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Custom HID demo configuration file
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_CONF_H
#define __USB_CONF_H
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/* External variables --------------------------------------------------------*/
/*-------------------------------------------------------------*/
/* EP_NUM */
/* defines how many endpoints are used by the device */
/*-------------------------------------------------------------*/
#define EP_NUM (2)
#ifndef STM32F10X_CL
/*-------------------------------------------------------------*/
/* -------------- Buffer Description Table -----------------*/
/*-------------------------------------------------------------*/
/* buffer table base address */
/* buffer table base address */
#define BTABLE_ADDRESS (0x00)
/* EP0 */
/* rx/tx buffer base address */
#define ENDP0_RXADDR (0x18)
#define ENDP0_TXADDR (0x58)
/* EP1 */
/* tx buffer base address */
#define ENDP1_TXADDR (0x100)
#define ENDP1_RXADDR (0x124)
/*-------------------------------------------------------------*/
/* ------------------- ISTR events -------------------------*/
/*-------------------------------------------------------------*/
/* IMR_MSK */
/* mask defining which events has to be handled */
/* by the device application software */
#define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \
| CNTR_ESOFM | CNTR_RESETM )
#endif /* STM32F10X_CL */
#ifdef STM32F10X_CL
/*******************************************************************************
* FIFO Size Configuration
*
* (i) Dedicated data FIFO SPRAM of 1.25 Kbytes = 1280 bytes = 320 32-bits words
* available for the endpoints IN and OUT.
* Device mode features:
* -1 bidirectional CTRL EP 0
* -3 IN EPs to support any kind of Bulk, Interrupt or Isochronous transfer
* -3 OUT EPs to support any kind of Bulk, Interrupt or Isochronous transfer
*
* ii) Receive data FIFO size = RAM for setup packets +
* OUT endpoint control information +
* data OUT packets + miscellaneous
* Space = ONE 32-bits words
* --> RAM for setup packets = 4 * n + 6 space
* (n is the nbr of CTRL EPs the device core supports)
* --> OUT EP CTRL info = 1 space
* (one space for status information written to the FIFO along with each
* received packet)
* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces
* (MINIMUM to receive packets)
* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces
* (if high-bandwidth EP is enabled or multiple isochronous EPs)
* --> miscellaneous = 1 space per OUT EP
* (one space for transfer complete status information also pushed to the
* FIFO with each endpoint's last packet)
*
* (iii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
* that particular IN EP. More space allocated in the IN EP Tx FIFO results
* in a better performance on the USB and can hide latencies on the AHB.
*
* (iv) TXn min size = 16 words. (n : Transmit FIFO index)
* (v) When a TxFIFO is not used, the Configuration should be as follows:
* case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
* --> Txm can use the space allocated for Txn.
* case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
* --> Txn should be configured with the minimum space of 16 words
* (vi) The FIFO is used optimally when used TxFIFOs are allocated in the top
* of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
*******************************************************************************/
#define RX_FIFO_SIZE 128
#define TX0_FIFO_SIZE 64
#define TX1_FIFO_SIZE 64
#define TX2_FIFO_SIZE 16
#define TX3_FIFO_SIZE 16
/* OTGD-FS-DEVICE IP interrupts Enable definitions */
/* Uncomment the define to enable the selected interrupt */
//#define INTR_MODEMISMATCH
#define INTR_SOFINTR
#define INTR_RXSTSQLVL /* Mandatory */
//#define INTR_NPTXFEMPTY
//#define INTR_GINNAKEFF
//#define INTR_GOUTNAKEFF
//#define INTR_ERLYSUSPEND
#define INTR_USBSUSPEND /* Mandatory */
#define INTR_USBRESET /* Mandatory */
#define INTR_ENUMDONE /* Mandatory */
//#define INTR_ISOOUTDROP
//#define INTR_EOPFRAME
//#define INTR_EPMISMATCH
#define INTR_INEPINTR /* Mandatory */
#define INTR_OUTEPINTR /* Mandatory */
//#define INTR_INCOMPLISOIN
//#define INTR_INCOMPLISOOUT
#define INTR_WKUPINTR /* Mandatory */
/* OTGD-FS-DEVICE IP interrupts subroutines */
/* Comment the define to enable the selected interrupt subroutine and replace it
by user code */
#define INTR_MODEMISMATCH_Callback NOP_Process
#define INTR_SOFINTR_Callback NOP_Process
#define INTR_RXSTSQLVL_Callback NOP_Process
#define INTR_NPTXFEMPTY_Callback NOP_Process
#define INTR_NPTXFEMPTY_Callback NOP_Process
#define INTR_GINNAKEFF_Callback NOP_Process
#define INTR_GOUTNAKEFF_Callback NOP_Process
#define INTR_ERLYSUSPEND_Callback NOP_Process
#define INTR_USBSUSPEND_Callback NOP_Process
#define INTR_USBRESET_Callback NOP_Process
#define INTR_ENUMDONE_Callback NOP_Process
#define INTR_ISOOUTDROP_Callback NOP_Process
#define INTR_EOPFRAME_Callback NOP_Process
#define INTR_EPMISMATCH_Callback NOP_Process
#define INTR_INEPINTR_Callback NOP_Process
#define INTR_OUTEPINTR_Callback NOP_Process
#define INTR_INCOMPLISOIN_Callback NOP_Process
#define INTR_INCOMPLISOOUT_Callback NOP_Process
#define INTR_WKUPINTR_Callback NOP_Process
/* Isochronous data update */
#define INTR_RXSTSQLVL_ISODU_Callback NOP_Process
/* Isochronous transfer parameters */
/* Size of a single Isochronous buffer (size of a single transfer) */
#define ISOC_BUFFER_SZE 1
/* Number of sub-buffers (number of single buffers/transfers), should be even */
#define NUM_SUB_BUFFERS 2
#endif /* STM32F10X_CL */
/* CTR service routines */
/* associated to defined endpoints */
#define EP1_IN_Callback NOP_Process
#define EP2_IN_Callback NOP_Process
#define EP3_IN_Callback NOP_Process
#define EP4_IN_Callback NOP_Process
#define EP5_IN_Callback NOP_Process
#define EP6_IN_Callback NOP_Process
#define EP7_IN_Callback NOP_Process
//#define EP1_OUT_Callback NOP_Process
#define EP2_OUT_Callback NOP_Process
#define EP3_OUT_Callback NOP_Process
#define EP4_OUT_Callback NOP_Process
#define EP5_OUT_Callback NOP_Process
#define EP6_OUT_Callback NOP_Process
#define EP7_OUT_Callback NOP_Process
#endif /*__USB_CONF_H*/
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,220 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_desc.c
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Descriptors for Custom HID Demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#include "usb_lib.h"
#include "pios_usb.h"
#include "pios_usb_hid.h"
#include "pios_usb_hid_desc.h"
// *************************************************
// USB Standard Device Descriptor
const uint8_t PIOS_HID_DeviceDescriptor[PIOS_HID_SIZ_DEVICE_DESC] =
{
0x12, // bLength
USB_DEVICE_DESCRIPTOR_TYPE, // bDescriptorType
0x00, // bcdUSB
0x02,
0x00, // bDeviceClass
0x00, // bDeviceSubClass
0x00, // bDeviceProtocol
0x40, // bMaxPacketSize40
(uint8_t)((PIOS_USB_VENDOR_ID) & 0xff), // idVendor
(uint8_t)((PIOS_USB_VENDOR_ID) >> 8),
(uint8_t)((PIOS_USB_PRODUCT_ID) & 0xff), // idProduct
(uint8_t)((PIOS_USB_PRODUCT_ID) >> 8),
(uint8_t)((PIOS_USB_VERSION_ID) & 0xff), // bcdDevice
(uint8_t)((PIOS_USB_VERSION_ID) >> 8),
0x01, // Index of string descriptor describing manufacturer
0x02, // Index of string descriptor describing product
0x03, // Index of string descriptor describing the device serial number
0x01 // bNumConfigurations
};
// *************************************************
// USB Configuration Descriptor
// All Descriptors (Configuration, Interface, Endpoint, Class, Vendor
const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
{
0x09, // bLength: Configuation Descriptor size
USB_CONFIGURATION_DESCRIPTOR_TYPE, // bDescriptorType: Configuration
PIOS_HID_SIZ_CONFIG_DESC,
// wTotalLength: Bytes returned
0x00,
0x01, // bNumInterfaces: 1 interface
0x01, // bConfigurationValue: Configuration value
0x00, // iConfiguration: Index of string descriptor describing the configuration
0xC0, // bmAttributes: Bus powered
0x7D, // MaxPower 250 mA - needed to power the RF transmitter
// ************** Descriptor of Custom HID interface ****************
// 09
0x09, // bLength: Interface Descriptor size
USB_INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType: Interface descriptor type
0x00, // bInterfaceNumber: Number of Interface
0x00, // bAlternateSetting: Alternate setting
0x02, // bNumEndpoints
0x03, // bInterfaceClass: HID
0x00, // bInterfaceSubClass : 1=BOOT, 0=no boot
0x00, // nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse
0, // iInterface: Index of string descriptor
// ******************** Descriptor of Custom HID HID ********************
// 18
0x09, // bLength: HID Descriptor size
HID_DESCRIPTOR_TYPE, // bDescriptorType: HID
0x10, // bcdHID: HID Class Spec release number
0x01,
0x00, // bCountryCode: Hardware target country
0x01, // bNumDescriptors: Number of HID class descriptors to follow
0x22, // bDescriptorType
PIOS_HID_SIZ_REPORT_DESC, // wItemLength: Total length of Report descriptor
0x00,
// ******************** Descriptor of Custom HID endpoints ******************
// 27
0x07, // bLength: Endpoint Descriptor size
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType:
0x81, // bEndpointAddress: Endpoint Address (IN)
0x03, // bmAttributes: Interrupt endpoint
0x40, // wMaxPacketSize: 2 Bytes max
0x00,
1, // bInterval: Polling Interval in ms
// 34
0x07, // bLength: Endpoint Descriptor size
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType:
// Endpoint descriptor type
0x01, // bEndpointAddress:
// Endpoint Address (OUT)
0x03, // bmAttributes: Interrupt endpoint
0x40, // wMaxPacketSize: 2 Bytes max
0x00,
1, // bInterval: Polling Interval in ms
// 41
};
// *************************************************
const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC] =
{
0x06, 0x9c, 0xff, // USAGE_PAGE (Vendor Page: 0xFF00)
0x09, 0x01, // USAGE (Demo Kit)
0xa1, 0x01, // COLLECTION (Application)
// 6
// Data 1
0x85, 0x01, // REPORT_ID (1)
0x09, 0x02, // USAGE (LED 1)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xff, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, PIOS_USB_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
0x81, 0x83, // INPUT (Const,Var,Array)
// 20
// Data 1
0x85, 0x02, // REPORT_ID (2)
0x09, 0x03, // USAGE (LED 1)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xff, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, PIOS_USB_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
0x91, 0x82, // OUTPUT (Data,Var,Abs,Vol)
// 34
0xc0 // END_COLLECTION
};
// *************************************************
// USB String Descriptors (optional)
const uint8_t PIOS_HID_StringLangID[PIOS_HID_SIZ_STRING_LANGID] =
{
PIOS_HID_SIZ_STRING_LANGID,
USB_STRING_DESCRIPTOR_TYPE,
0x09, 0x08 // LangID = 0x0809: UK. English
// 0x09, 0x04 // LangID = 0x0409: U.S. English
};
const uint8_t PIOS_HID_StringVendor[PIOS_HID_SIZ_STRING_VENDOR] =
{
PIOS_HID_SIZ_STRING_VENDOR, // Size of Vendor string
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
// Manufacturer: "STMicroelectronics"
'o', 0,
'p', 0,
'e', 0,
'n', 0,
'p', 0,
'i', 0,
'l', 0,
'o', 0,
't', 0,
'.', 0,
'o', 0,
'r', 0,
'g', 0
};
const uint8_t PIOS_HID_StringProduct[PIOS_HID_SIZ_STRING_PRODUCT] =
{
PIOS_HID_SIZ_STRING_PRODUCT, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
'O', 0,
'p', 0,
'e', 0,
'n', 0,
'P', 0,
'i', 0,
'l', 0,
'o', 0,
't', 0
};
uint8_t PIOS_HID_StringSerial[PIOS_HID_SIZ_STRING_SERIAL] =
{
PIOS_HID_SIZ_STRING_SERIAL, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0
};
// *************************************************

View File

@ -0,0 +1,156 @@
/**
******************************************************************************
*
* @file stopwatch.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Stop watch function
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "stopwatch.h"
#include "main.h"
// *****************************************************************************
uint32_t resolution_us = 0;
// *****************************************************************************
// initialise the stopwatch
void STOPWATCH_init(uint32_t resolution)
{
resolution_us = resolution;
if (resolution_us == 0)
return;
// enable timer clock
switch ((uint32_t)STOPWATCH_TIMER)
{
case (uint32_t)TIM1: RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); break;
case (uint32_t)TIM2: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); break;
case (uint32_t)TIM3: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); break;
case (uint32_t)TIM4: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); break;
#ifdef STM32F10X_HD
case (uint32_t)TIM5: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); break;
case (uint32_t)TIM6: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); break;
case (uint32_t)TIM7: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE); break;
case (uint32_t)TIM8: RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); break;
#endif
}
// time base configuration
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 0xffff; // max period
TIM_TimeBaseStructure.TIM_Prescaler = ((PIOS_MASTER_CLOCK / 1000000) * resolution_us) - 1; // <resolution> uS accuracy @ 72 MHz
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(STOPWATCH_TIMER, &TIM_TimeBaseStructure);
// enable interrupt request
TIM_ITConfig(STOPWATCH_TIMER, TIM_IT_Update, ENABLE);
// start counter
TIM_Cmd(STOPWATCH_TIMER, ENABLE);
}
// *****************************************************************************
// timer interrupt
/*
#ifdef STM32F10X_MD
#if (STOPWATCH_TIMER == TIM1)
void TIM1_IRQHandler(void)
#if (STOPWATCH_TIMER == TIM2)
void TIM2_IRQHandler(void)
#elif (STOPWATCH_TIMER == TIM3)
void TIM3_IRQHandler(void)
#elif (STOPWATCH_TIMER == TIM4)
void TIM4_IRQHandler(void)
#endif
#endif
#ifdef STM32F10X_HD
#if (STOPWATCH_TIMER == TIM1)
void TIM1_IRQHandler(void)
#if (STOPWATCH_TIMER == TIM2)
void TIM2_IRQHandler(void)
#elif (STOPWATCH_TIMER == TIM3)
void TIM3_IRQHandler(void)
#elif (STOPWATCH_TIMER == TIM4)
void TIM4_IRQHandler(void)
#elif (STOPWATCH_TIMER == TIM5)
void TIM5_IRQHandler(void)
#elif (STOPWATCH_TIMER == TIM6)
void TIM6_IRQHandler(void)
#elif (STOPWATCH_TIMER == TIM7)
void TIM7_IRQHandler(void)
#elif (STOPWATCH_TIMER == TIM8)
void TIM8_IRQHandler(void)
#endif
#endif
{
}
*/
// *****************************************************************************
// resets the stopwatch
void STOPWATCH_reset(void)
{
if (resolution_us > 0)
{ // reset the counter
STOPWATCH_TIMER->CNT = 1; // set to 1 instead of 0 to avoid new IRQ request
TIM_ClearITPendingBit(STOPWATCH_TIMER, TIM_IT_Update);
}
}
// *****************************************************************************
// returns the timer count since the last STOPWATCH_reset() call
// return 0xffffffff if counter overrun or not initialised
uint32_t STOPWATCH_get_count(void)
{
uint32_t value = STOPWATCH_TIMER->CNT; // get counter value ASAP
if (resolution_us == 0)
return 0xffffffff; // not initialized
if (TIM_GetITStatus(STOPWATCH_TIMER, TIM_IT_Update) != RESET)
return 0xffffffff; // timer overfloaw
return value; // return the timer count
}
// *****************************************************************************
// returns number of us since the last STOPWATCH_reset() call
// return 0xffffffff if counter overrun or not initialised
uint32_t STOPWATCH_get_us(void)
{
uint32_t value = STOPWATCH_TIMER->CNT; // get counter value ASAP
if (resolution_us == 0)
return 0xffffffff; // not initialized
if (TIM_GetITStatus(STOPWATCH_TIMER, TIM_IT_Update) != RESET)
return 0xffffffff; // timer overfloaw
return (value * resolution_us); // return number of micro seconds
}
// *****************************************************************************