mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 17:55:19 +03:00
[X9D] Previous revisions re-enabled. The CoOs was not started, which is a little bit a problem!
This commit is contained in:
parent
d360c0e820
commit
d558e33647
31 changed files with 347 additions and 285 deletions
15
src/Makefile
15
src/Makefile
|
@ -506,16 +506,17 @@ ifeq ($(PCB), X9D)
|
|||
# X9D radio
|
||||
OPT = 2
|
||||
CPPDEFS += -DPCBX9D -DCPUARM -DEEPROM_VARIANT=0 -DAUDIO -DPXX
|
||||
EXTRAINCDIRS += CoOS/kernel CoOS/portable
|
||||
EXTRAINCDIRS += x9d CoOS/kernel CoOS/portable
|
||||
EXTRAINCDIRS += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include
|
||||
EXTRAINCDIRS += x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc
|
||||
EXTRAINCDIRS += x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/hid/inc
|
||||
BOARDSRC = x9d/board_x9d.cpp
|
||||
EXTRABOARDSRC += x9d/lcd_driver.cpp x9d/aspi.cpp x9d/i2c.c x9d/pwr_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/adc_driver.cpp x9d/trainer_driver.cpp x9d/audio_driver.cpp x9d/delays.cpp x9d/uart_driver.cpp x9d/sport_driver.cpp
|
||||
EXTRABOARDSRC += x9d/lcd_driver.cpp x9d/aspi.cpp x9d/i2c.c
|
||||
SRC += CoOS/kernel/core.c CoOS/kernel/hook.c CoOS/kernel/task.c CoOS/kernel/event.c CoOS/kernel/time.c CoOS/kernel/timer.c CoOS/kernel/flag.c CoOS/kernel/mutex.c CoOS/kernel/serviceReq.c CoOS/portable/GCC/port.c CoOS/portable/arch.c
|
||||
EEPROMSRC = eeprom_avr.cpp # TODO later eeprom_conversions.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp # TODO later eeprom_conversions.cpp
|
||||
PULSESSRC = pulses_arm.cpp
|
||||
CPPSRC += audio_arm.cpp
|
||||
CPPSRC += x9d/pwr_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/adc_driver.cpp x9d/trainer_driver.cpp x9d/audio_driver.cpp x9d/delays.cpp x9d/uart_driver.cpp x9d/sport_driver.cpp
|
||||
CPPSRC += bmp.cpp monitors_views.cpp
|
||||
SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c
|
||||
SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/misc.c
|
||||
|
@ -570,7 +571,7 @@ ifeq ($(PCB), SKY9X)
|
|||
SRC += sky9x/usb/device/massstorage/MSDDriver.c sky9x/usb/device/massstorage/MSDDStateMachine.c sky9x/usb/device/massstorage/MSDLun.c sky9x/usb/device/massstorage/MSDDriverDescriptors.c sky9x/usb/device/massstorage/SBCMethods.c
|
||||
SRC += sky9x/usb/common/core/USBEndpointDescriptor.c sky9x/usb/common/core/USBGenericRequest.c sky9x/usb/common/core/USBFeatureRequest.c sky9x/usb/common/core/USBInterfaceRequest.c sky9x/usb/common/core/USBGetDescriptorRequest.c sky9x/usb/common/core/USBSetAddressRequest.c sky9x/usb/common/core/USBSetConfigurationRequest.c sky9x/usb/common/core/USBConfigurationDescriptor.c sky9x/usb/common/core/USBGenericDescriptor.c
|
||||
SRC += sky9x/MEDSdcard.c
|
||||
EEPROMSRC = eeprom_arm.cpp eeprom_conversions.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_raw.cpp eeprom_conversions.cpp
|
||||
PULSESSRC = pulses_arm.cpp
|
||||
CPPSRC += audio_arm.cpp haptic.cpp
|
||||
CPPSRC += sky9x/pwr_driver.cpp sky9x/adc_driver.cpp sky9x/coproc_driver.cpp sky9x/rotenc_driver.cpp sky9x/eeprom_driver.cpp sky9x/pulses_driver.cpp sky9x/keys_driver.cpp sky9x/audio_driver.cpp sky9x/buzzer_driver.cpp sky9x/haptic_driver.cpp sky9x/sdcard_driver.cpp sky9x/massstorage.cpp
|
||||
|
@ -605,7 +606,7 @@ ifeq ($(PCB), GRUVIN9X)
|
|||
EXTRAINCDIRS += gruvin9x stock FatFs FatFs/option
|
||||
BOARDSRC += gruvin9x/board_gruvin9x.cpp
|
||||
EXTRABOARDSRC += stock/lcd_driver.cpp
|
||||
EEPROMSRC = eeprom_avr.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
|
||||
PULSESSRC = pulses_avr.cpp
|
||||
CPPSRC += audio_avr.cpp haptic.cpp
|
||||
|
||||
|
@ -633,7 +634,7 @@ ifeq ($(PCB), $(filter $(PCB), STD128 9X128 9XR128))
|
|||
EXTRAINCDIRS += stock
|
||||
BOARDSRC = stock/board_stock.cpp
|
||||
EXTRABOARDSRC += stock/lcd_driver.cpp
|
||||
EEPROMSRC = eeprom_avr.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
|
||||
PULSESSRC = pulses_avr.cpp
|
||||
|
||||
ifeq ($(PCB), 9XR128)
|
||||
|
@ -679,7 +680,7 @@ ifeq ($(PCB), $(filter $(PCB), STD 9X 9XR))
|
|||
CPPDEFS += -DPCBSTD -DCPUM64 -DEEPROM_VARIANT=$(shell echo ${EEPROM_VARIANT} | bc)
|
||||
BOARDSRC = stock/board_stock.cpp
|
||||
EXTRABOARDSRC += stock/lcd_driver.cpp
|
||||
EEPROMSRC = eeprom_avr.cpp
|
||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
|
||||
PULSESSRC = pulses_avr.cpp
|
||||
|
||||
ifeq ($(PCB), 9XR)
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
|
||||
#if !defined(SIMU)
|
||||
|
||||
Fifo512 debugRxFifo;
|
||||
Fifo512 debugTxFifo;
|
||||
Fifo<512> debugRxFifo;
|
||||
Fifo<512> debugTxFifo;
|
||||
|
||||
// Outputs a string to the UART
|
||||
void debugPuts(const char *format, ...)
|
||||
|
@ -61,17 +61,17 @@ void debugPuts(const char *format, ...)
|
|||
|
||||
void dump(unsigned char *data, unsigned int size)
|
||||
{
|
||||
debugPuts("DUMP %d bytes ...\n\r", size);
|
||||
unsigned int i = 0, j=0;
|
||||
while (i*32+j < size) {
|
||||
debugPuts("%.2X ", data[i*32+j]);
|
||||
j++;
|
||||
if (j==32) {
|
||||
i++; j=0;
|
||||
debugPuts("\n\r");
|
||||
}
|
||||
}
|
||||
debugPuts("\n\r");
|
||||
debugPuts("DUMP %d bytes ...\n\r", size);
|
||||
unsigned int i = 0, j=0;
|
||||
while (i*32+j < size) {
|
||||
debugPuts("%.2X ", data[i*32+j]);
|
||||
j++;
|
||||
if (j==32) {
|
||||
i++; j=0;
|
||||
debugPuts("\n\r");
|
||||
}
|
||||
}
|
||||
debugPuts("\n\r");
|
||||
}
|
||||
|
||||
void debugTask(void* pdata)
|
||||
|
@ -87,9 +87,9 @@ void debugTask(void* pdata)
|
|||
|
||||
void debugTx(void)
|
||||
{
|
||||
uint8_t txchar;
|
||||
|
||||
if(debugTxFifo.pop(txchar))
|
||||
debugPutc(txchar);
|
||||
uint8_t txchar;
|
||||
|
||||
if (debugTxFifo.pop(txchar))
|
||||
debugPutc(txchar);
|
||||
}
|
||||
#endif
|
||||
|
|
68
src/eeprom_common.cpp
Normal file
68
src/eeprom_common.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* open9x is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "open9x.h"
|
||||
#include "inttypes.h"
|
||||
#include "string.h"
|
||||
|
||||
uint8_t s_eeDirtyMsk;
|
||||
tmr10ms_t s_eeDirtyTime10ms;
|
||||
|
||||
void eeDirty(uint8_t msk)
|
||||
{
|
||||
s_eeDirtyMsk |= msk;
|
||||
s_eeDirtyTime10ms = get_tmr10ms() ;
|
||||
}
|
||||
|
||||
#if defined(CPUARM)
|
||||
|
||||
char modelNames[MAX_MODELS][sizeof(g_model.name)];
|
||||
|
||||
#if defined(PXX)
|
||||
uint8_t modelIds[MAX_MODELS];
|
||||
#endif
|
||||
|
||||
void eeLoadModelNames()
|
||||
{
|
||||
for (uint32_t i=0; i<MAX_MODELS; i++) {
|
||||
eeLoadModelName(i, modelNames[i]);
|
||||
#if defined(PXX)
|
||||
modelIds[i] = eeLoadModelId(i);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
72
src/eeprom_common.h
Normal file
72
src/eeprom_common.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* open9x is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(SIMU)
|
||||
#define WRITE_DELAY_10MS 200
|
||||
#elif defined(PCBX9D)
|
||||
#define WRITE_DELAY_10MS 500
|
||||
#elif defined(PCBSKY9X) && !defined(REV0)
|
||||
#define WRITE_DELAY_10MS 500
|
||||
#elif defined(PCBGRUVIN9X) && !defined(REV0)
|
||||
#define WRITE_DELAY_10MS 500
|
||||
#else
|
||||
#define WRITE_DELAY_10MS 200
|
||||
#endif
|
||||
|
||||
extern uint8_t s_eeDirtyMsk;
|
||||
extern tmr10ms_t s_eeDirtyTime10ms;
|
||||
|
||||
void eeDirty(uint8_t msk);
|
||||
void eeCheck(bool immediately=false);
|
||||
void eeReadAll();
|
||||
bool eeModelExists(uint8_t id);
|
||||
void eeLoadModelName(uint8_t id, char *name);
|
||||
void eeLoadModel(uint8_t id);
|
||||
|
||||
#if defined(CPUARM)
|
||||
|
||||
extern char modelNames[MAX_MODELS][sizeof(g_model.name)];
|
||||
void eeLoadModelNames();
|
||||
|
||||
#if defined(PXX)
|
||||
extern uint8_t modelIds[MAX_MODELS];
|
||||
#endif
|
||||
|
||||
#else // defined(CPUARM)
|
||||
|
||||
#define eeLoadModelNames()
|
||||
|
||||
#endif
|
|
@ -40,8 +40,6 @@
|
|||
#include "string.h"
|
||||
|
||||
volatile uint32_t Spi_complete; // TODO in the driver ?
|
||||
uint8_t s_eeDirtyMsk;
|
||||
tmr10ms_t s_eeDirtyTime10ms;
|
||||
|
||||
// Logic for storing to EEPROM/loading from EEPROM
|
||||
// If main needs to wait for the eeprom, call mainsequence without actioning menus
|
||||
|
@ -78,15 +76,8 @@ uint32_t Eeprom32_data_size ;
|
|||
|
||||
#define EE_NOWAIT 1
|
||||
|
||||
void eeDirty(uint8_t msk)
|
||||
{
|
||||
s_eeDirtyMsk |= msk;
|
||||
s_eeDirtyTime10ms = get_tmr10ms() ;
|
||||
}
|
||||
|
||||
uint32_t get_current_block_number( uint32_t block_no, uint16_t *p_size, uint32_t *p_seq ) ;
|
||||
void write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate=0 ) ;
|
||||
void eeLoadModelNames( void ) ;
|
||||
|
||||
// New file system
|
||||
|
||||
|
@ -360,8 +351,6 @@ bool eeLoadGeneral()
|
|||
|
||||
void eeLoadModel(uint8_t id)
|
||||
{
|
||||
uint16_t size;
|
||||
|
||||
if (id<MAX_MODELS) {
|
||||
|
||||
#if defined(SDCARD)
|
||||
|
@ -374,7 +363,7 @@ void eeLoadModel(uint8_t id)
|
|||
|
||||
pauseMixerCalculations();
|
||||
|
||||
size = File_system[id+1].size ;
|
||||
uint16_t size = File_system[id+1].size ;
|
||||
|
||||
memset(&g_model, 0, sizeof(g_model));
|
||||
|
||||
|
@ -387,7 +376,7 @@ void eeLoadModel(uint8_t id)
|
|||
if (size > sizeof(g_model)) {
|
||||
size = sizeof(g_model) ;
|
||||
}
|
||||
|
||||
|
||||
if(size < 256) { // if not loaded a fair amount
|
||||
modelDefault(id) ;
|
||||
eeCheck(true);
|
||||
|
@ -445,12 +434,19 @@ void eeLoadModelName(uint8_t id, char *name)
|
|||
}
|
||||
}
|
||||
|
||||
void eeLoadModelNames()
|
||||
#if defined(PXX)
|
||||
uint8_t eeLoadModelId(uint8_t id)
|
||||
{
|
||||
for (uint32_t i=0; i<MAX_MODELS; i++) {
|
||||
eeLoadModelName(i, modelNames[i]);
|
||||
uint8_t modelId = 0;
|
||||
if (id < MAX_MODELS) {
|
||||
id += 1;
|
||||
if (File_system[id].size > sizeof(g_model.name) + 1) {
|
||||
read32_eeprom_data( ( File_system[id].block_no << 12) + 8 + sizeof(g_model.name), &modelId, 1);
|
||||
}
|
||||
}
|
||||
return modelId;
|
||||
}
|
||||
#endif
|
||||
|
||||
void fill_file_index()
|
||||
{
|
|
@ -40,17 +40,6 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(SIMU)
|
||||
#define WRITE_DELAY_10MS 200
|
||||
#elif defined(PCBSKY9X) && defined(REV0)
|
||||
#define WRITE_DELAY_10MS 200
|
||||
#else
|
||||
#define WRITE_DELAY_10MS 500
|
||||
#endif
|
||||
|
||||
extern uint8_t s_eeDirtyMsk;
|
||||
extern tmr10ms_t s_eeDirtyTime10ms;
|
||||
|
||||
// States in Eeprom32_process_state
|
||||
#define E32_IDLE 1
|
||||
#define E32_ERASESENDING 2
|
||||
|
@ -77,6 +66,10 @@ extern bool eeModelExists(uint8_t id) ;
|
|||
extern bool eeCopyModel(uint8_t dst, uint8_t src);
|
||||
extern void eeSwapModels(uint8_t id1, uint8_t id2);
|
||||
|
||||
#if defined(PXX)
|
||||
uint8_t eeLoadModelId(uint8_t id);
|
||||
#endif
|
||||
|
||||
#define DISPLAY_PROGRESS_BAR(x)
|
||||
|
||||
struct t_file_entry
|
|
@ -40,18 +40,10 @@
|
|||
#include "string.h"
|
||||
|
||||
uint8_t s_write_err = 0; // error reasons
|
||||
uint8_t s_eeDirtyMsk;
|
||||
tmr10ms_t s_eeDirtyTime10ms;
|
||||
|
||||
RlcFile theFile; //used for any file operation
|
||||
EeFs eeFs;
|
||||
|
||||
void eeDirty(uint8_t msk)
|
||||
{
|
||||
s_eeDirtyMsk |= msk;
|
||||
s_eeDirtyTime10ms = get_tmr10ms();
|
||||
}
|
||||
|
||||
#if !defined(CPUARM)
|
||||
uint8_t s_sync_write = false;
|
||||
uint16_t eeprom_pointer;
|
||||
|
@ -837,7 +829,6 @@ bool eeLoadGeneral()
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
void eeLoadModelName(uint8_t id, char *name)
|
||||
{
|
||||
memclear(name, sizeof(g_model.name));
|
||||
|
@ -847,16 +838,14 @@ void eeLoadModelName(uint8_t id, char *name)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(CPUARM)
|
||||
// TODO same function in eeprom_arm.cpp
|
||||
void eeLoadModelNames()
|
||||
#if defined(PXX)
|
||||
// must be called just after eeLoadModelName!
|
||||
uint8_t eeLoadModelIdAfterName()
|
||||
{
|
||||
for (uint32_t i=0; i<MAX_MODELS; i++) {
|
||||
eeLoadModelName(i, modelNames[i]);
|
||||
}
|
||||
uint8_t modelId = 0;
|
||||
theFile.readRlc(&modelId, sizeof(modelId));
|
||||
return modelId;
|
||||
}
|
||||
#else
|
||||
#define eeLoadModelNames()
|
||||
#endif
|
||||
|
||||
bool eeModelExists(uint8_t id)
|
||||
|
@ -864,7 +853,7 @@ bool eeModelExists(uint8_t id)
|
|||
return EFile::exists(FILE_MODEL(id));
|
||||
}
|
||||
|
||||
// TODO Now the 2 functions in eeprom_avr.cpp and eeprom_arm.cpp are really close, should be merged.
|
||||
// TODO Now the 2 functions in eeprom_rlc.cpp and eeprom_raw.cpp are really close, should be merged.
|
||||
void eeLoadModel(uint8_t id)
|
||||
{
|
||||
if (id<MAX_MODELS) {
|
|
@ -39,19 +39,6 @@
|
|||
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined(SIMU)
|
||||
#define WRITE_DELAY_10MS 200
|
||||
#elif defined(PCBX9D)
|
||||
#define WRITE_DELAY_10MS 1000
|
||||
#elif defined(PCBGRUVIN9X) && !defined(REV0)
|
||||
#define WRITE_DELAY_10MS 500
|
||||
#else
|
||||
#define WRITE_DELAY_10MS 200
|
||||
#endif
|
||||
|
||||
extern uint8_t s_eeDirtyMsk;
|
||||
extern tmr10ms_t s_eeDirtyTime10ms;
|
||||
|
||||
#if defined(CPUARM)
|
||||
#define blkid_t uint16_t
|
||||
#define EESIZE (32*1024)
|
||||
|
@ -153,6 +140,11 @@ class EFile
|
|||
#define eeFileSize(f) eeFs.files[f].size
|
||||
#define eeModelSize(id) eeFileSize(FILE_MODEL(id))
|
||||
|
||||
#if defined(PXX)
|
||||
uint8_t eeLoadModelIdAfterName();
|
||||
#define eeLoadModelId(id) eeLoadModelIdAfterName()
|
||||
#endif
|
||||
|
||||
#define ERR_NONE 0
|
||||
#define ERR_FULL 1
|
||||
extern uint8_t s_write_err; // error reasons
|
11
src/fifo.h
11
src/fifo.h
|
@ -37,17 +37,18 @@
|
|||
#ifndef fifo_h
|
||||
#define fifo_h
|
||||
|
||||
class Fifo512
|
||||
template <int N>
|
||||
class Fifo
|
||||
{
|
||||
public:
|
||||
Fifo512():
|
||||
Fifo():
|
||||
widx(0),
|
||||
ridx(0)
|
||||
{
|
||||
}
|
||||
|
||||
void push(uint8_t byte) {
|
||||
uint32_t next = (widx+1) & 0x1ff;
|
||||
uint32_t next = (widx+1) & (N-1);
|
||||
if (next != ridx) {
|
||||
fifo[widx] = byte;
|
||||
widx = next;
|
||||
|
@ -60,13 +61,13 @@ class Fifo512
|
|||
}
|
||||
else {
|
||||
byte = fifo[ridx];
|
||||
ridx = (ridx+1) & 0x1ff;
|
||||
ridx = (ridx+1) & (N-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t fifo[512];
|
||||
uint8_t fifo[N];
|
||||
volatile uint32_t widx;
|
||||
volatile uint32_t ridx;
|
||||
};
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
#define TIMER_16KHZ_VECT TIMER2_OVF_vect
|
||||
#define COUNTER_16KHZ TCNT2
|
||||
#define TIMER_10MS_VECT TIMER2_COMPA_vect
|
||||
#define TIMER_10MS_COMPVAL OCR2A
|
||||
#define PAUSE_10MS_INTERRUPT() TIMSK2 &= ~(1<<OCIE2A)
|
||||
#define RESUME_10MS_INTERRUPT() TIMSK2 |= (1<<OCIE2A)
|
||||
#define PAUSE_PULSES_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
|
||||
|
|
|
@ -37,10 +37,6 @@
|
|||
#include "open9x.h"
|
||||
|
||||
uint8_t s_evt;
|
||||
void putEvent(uint8_t evt)
|
||||
{
|
||||
s_evt = evt;
|
||||
}
|
||||
|
||||
#if defined(CPUARM)
|
||||
uint8_t getEvent(bool trim)
|
||||
|
|
|
@ -1073,15 +1073,25 @@ void menuModelSetup(uint8_t event)
|
|||
|
||||
lcd_putsLeft(y, STR_RXNUM);
|
||||
lcd_outdezNAtt(MODEL_SETUP_2ND_COLUMN-3*FW, y, g_model.modelId, (m_posHorz==0 ? attr : 0) | LEADING0|LEFT, 2);
|
||||
if (attr && (m_posHorz==0 && (editMode>0 || p1valdiff)))
|
||||
if (attr && (m_posHorz==0 && (editMode>0 || p1valdiff))) {
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.modelId, 99);
|
||||
#if defined(CPUARM)
|
||||
if (checkIncDec_Ret)
|
||||
modelIds[g_eeGeneral.currModel] = g_model.modelId;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PXX)
|
||||
if (protocol == PROTO_PXX) {
|
||||
#if defined(CPUARM)
|
||||
if (attr && m_posHorz==0 && editMode==0 && event==EVT_KEY_BREAK(KEY_ENTER))
|
||||
checkModelIdUnique(g_eeGeneral.currModel);
|
||||
#endif
|
||||
|
||||
lcd_putsAtt(MODEL_SETUP_2ND_COLUMN, y, STR_SYNCMENU, (m_posHorz==1 ? attr : 0));
|
||||
if (attr && m_posHorz==1) {
|
||||
s_editMode = 0;
|
||||
if (event==EVT_KEY_LONG(KEY_MENU)) {
|
||||
if (event==EVT_KEY_LONG(KEY_ENTER)) {
|
||||
// send reset code
|
||||
pxxFlag = PXX_SEND_RXNUM;
|
||||
}
|
||||
|
@ -1091,7 +1101,7 @@ void menuModelSetup(uint8_t event)
|
|||
|
||||
#if defined(DSM2)
|
||||
if (IS_DSM2_PROTOCOL(protocol)) {
|
||||
lcd_putsiAtt(MODEL_SETUP_2ND_COLUMN, y, PSTR("\013Range[MENU]Norm [MENU]"), s_rangecheck_mode, (m_posHorz==1 ? attr : 0));
|
||||
lcd_putsiAtt(MODEL_SETUP_2ND_COLUMN, y, PSTR("\013Range"TR_ENTER"Norm "TR_ENTER), s_rangecheck_mode, (m_posHorz==1 ? attr : 0));
|
||||
s_rangecheck_mode = (attr && m_posHorz==1 && editMode>0); // [MENU] key toggles range check mode
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1104,6 +1104,7 @@ enum Protocols {
|
|||
|
||||
PACK(typedef struct t_ModelData {
|
||||
char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName
|
||||
uint8_t modelId;
|
||||
TimerData timers[MAX_TIMERS];
|
||||
uint8_t protocol:3;
|
||||
uint8_t thrTrim:1; // Enable Throttle Trim
|
||||
|
@ -1130,7 +1131,6 @@ PACK(typedef struct t_ModelData {
|
|||
|
||||
int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5ms increments
|
||||
uint8_t thrTraceSrc;
|
||||
uint8_t modelId;
|
||||
|
||||
swstate_t switchWarningStates;
|
||||
|
||||
|
|
199
src/open9x.cpp
199
src/open9x.cpp
|
@ -68,8 +68,6 @@ OS_FlagID audioFlag;
|
|||
OS_MutexID audioMutex;
|
||||
OS_MutexID mixerMutex;
|
||||
|
||||
char modelNames[MAX_MODELS][sizeof(g_model.name)];
|
||||
|
||||
#endif // defined(CPUARM)
|
||||
|
||||
#if defined(SPLASH)
|
||||
|
@ -272,7 +270,6 @@ void per10ms()
|
|||
rePreviousValue = reNewValue;
|
||||
putEvent(scrollRE < 0 ? EVT_ROTARY_LEFT : EVT_ROTARY_RIGHT);
|
||||
}
|
||||
extern uint8_t s_evt;
|
||||
uint8_t evt = s_evt;
|
||||
if (EVT_KEY_MASK(evt) == BTN_REa + NAVIGATION_RE_IDX()) {
|
||||
if (IS_KEY_BREAK(evt)) {
|
||||
|
@ -285,7 +282,7 @@ void per10ms()
|
|||
}
|
||||
#endif
|
||||
|
||||
#if (defined(FRSKY) || defined(MAVLINK) || defined(JETI)) && !defined(CPUARM) && !(defined(PCBSTD) && (defined(AUDIO) || defined(VOICE)))
|
||||
#if (defined(FRSKY) || defined(MAVLINK) || defined(JETI)) && !defined(CPUARM)
|
||||
if (!IS_DSM2_SERIAL_PROTOCOL(s_current_protocol))
|
||||
telemetryPoll10ms();
|
||||
#endif
|
||||
|
@ -385,7 +382,7 @@ uint16_t evalChkSum()
|
|||
return sum;
|
||||
}
|
||||
|
||||
#ifndef TEMPLATES
|
||||
#if !defined(TEMPLATES)
|
||||
inline void applyDefaultTemplate()
|
||||
{
|
||||
for (int i=0; i<NUM_STICKS; i++) {
|
||||
|
@ -399,10 +396,27 @@ inline void applyDefaultTemplate()
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(PXX) && defined(CPUARM)
|
||||
void checkModelIdUnique(uint8_t id)
|
||||
{
|
||||
for (uint8_t i=0; i<MAX_MODELS; i++) {
|
||||
if (i != id && g_model.modelId!=0 && g_model.modelId == modelIds[i]) {
|
||||
s_warning = PSTR("Model ID already used");
|
||||
s_warning_type = WARNING_TYPE_ASTERISK;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void modelDefault(uint8_t id)
|
||||
{
|
||||
memset(&g_model, 0, sizeof(g_model));
|
||||
applyDefaultTemplate();
|
||||
|
||||
#if defined(PXX) && defined(CPUARM)
|
||||
modelIds[id] = g_model.modelId = id+1;
|
||||
checkModelIdUnique(id);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t intpol(int16_t x, uint8_t idx) // -100, -75, -50, -25, 0, 25 ,50, 75, 100
|
||||
|
@ -528,7 +542,8 @@ uint16_t expou(uint16_t x, uint16_t k)
|
|||
bool extended;
|
||||
if (k>80) {
|
||||
extended=true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
k+=(k>>2); // use bigger values before extend, because the effect is anyway very very low
|
||||
extended=false;
|
||||
} // endif k > 50
|
||||
|
@ -769,42 +784,40 @@ int16_t applyLimits(uint8_t channel, int32_t value)
|
|||
if (ofs > lim_p) ofs = lim_p;
|
||||
if (ofs < lim_n) ofs = lim_n;
|
||||
|
||||
// because the recaling optimization would reduce the calculation reserve we activate this for all builds
|
||||
// it increases the caculation reserve from factor 20,25x to 32x, which it slightly better as original
|
||||
// without it we would only have 16x which is slightly worse as original, we should not do this
|
||||
// #ifdef PREVENT_ARITHMETIC_OVERFLOW
|
||||
// because the rescaling optimization would reduce the calculation reserve we activate this for all builds
|
||||
// it increases the calculation reserve from factor 20,25x to 32x, which it slightly better as original
|
||||
// without it we would only have 16x which is slightly worse as original, we should not do this
|
||||
|
||||
// thanks to gbirkus, he motivated this change, which greatly reduces overruns
|
||||
// unfortunately the constants and 32bit compares generates about 50 bytes codes; didn't find a way to get it down.
|
||||
|
||||
value = limit(int32_t(-RESXl*256),value,int32_t(RESXl*256)); // saves 2 bytes compared to other solutions up to now
|
||||
// #endif
|
||||
value = limit(int32_t(-RESXl*256), value, int32_t(RESXl*256)); // saves 2 bytes compared to other solutions up to now
|
||||
|
||||
#if defined(PPM_LIMITS_SYMETRICAL)
|
||||
if (value) {
|
||||
int16_t tmp;
|
||||
int16_t tmp;
|
||||
if (lim->symetrical)
|
||||
tmp = (value > 0) ? (lim_p) : (-lim_n);
|
||||
else
|
||||
tmp = (value > 0) ? (lim_p - ofs) : (-lim_n + ofs);
|
||||
value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024
|
||||
value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024
|
||||
#else
|
||||
if (value) {
|
||||
int16_t tmp = (value > 0) ? (lim_p - ofs) : (-lim_n + ofs);
|
||||
value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024
|
||||
value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024
|
||||
#endif
|
||||
|
||||
#ifdef CORRECT_NEGATIVE_SHIFTS
|
||||
int8_t sign=(value<0?1:0);
|
||||
value-=sign;
|
||||
tmp=value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes;
|
||||
tmp>>=2; // now one simple shift right for two bytes does the rest
|
||||
tmp+=sign;
|
||||
int8_t sign = (value<0?1:0);
|
||||
value -= sign;
|
||||
tmp = value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes;
|
||||
tmp >>= 2; // now one simple shift right for two bytes does the rest
|
||||
tmp += sign;
|
||||
#else
|
||||
tmp=value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes;
|
||||
tmp>>=2; // now one simple shift right for two bytes does the rest
|
||||
tmp = value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes;
|
||||
tmp >>= 2; // now one simple shift right for two bytes does the rest
|
||||
#endif
|
||||
|
||||
ofs+=tmp; // ofs can to added directly because already recalculated,
|
||||
ofs += tmp; // ofs can to added directly because already recalculated,
|
||||
}
|
||||
|
||||
if (ofs > lim_p) ofs = lim_p;
|
||||
|
@ -862,8 +875,7 @@ int16_t getValue(uint8_t i)
|
|||
#endif
|
||||
else if (i<MIXSRC_LAST_CSW) return __getSwitch(SWSRC_THR+i+1-MIXSRC_THR) ? 1024 : -1024;
|
||||
#endif
|
||||
else if (i<MIXSRC_PPM1+NUM_CAL_PPM) return (g_ppmIns[i+1-MIXSRC_PPM1] - g_eeGeneral.trainer.calib[i+1-MIXSRC_PPM1])*2;
|
||||
else if (i<MIXSRC_LAST_PPM) return g_ppmIns[i+1-MIXSRC_PPM1]*2;
|
||||
else if (i<MIXSRC_LAST_PPM) { int16_t x = g_ppmIns[i+1-MIXSRC_PPM1]; if (i<MIXSRC_PPM1+NUM_CAL_PPM) { x-= g_eeGeneral.trainer.calib[i+1-MIXSRC_PPM1]; } return x*2; }
|
||||
else if (i<MIXSRC_LAST_CH) return ex_chans[i+1-MIXSRC_CH1];
|
||||
#if defined(GVARS)
|
||||
else if (i<MIXSRC_LAST_GVAR) return GVAR_VALUE(i+1-MIXSRC_GVAR1, getGVarFlightPhase(s_perout_flight_phase, i+1-MIXSRC_GVAR1));
|
||||
|
@ -1394,8 +1406,9 @@ void checkBacklight()
|
|||
rotencPoll();
|
||||
#endif
|
||||
|
||||
if (tmr10ms != g_blinkTmr10ms) {
|
||||
tmr10ms = g_blinkTmr10ms;
|
||||
uint8_t x = g_blinkTmr10ms;
|
||||
if (tmr10ms != x) {
|
||||
tmr10ms = x;
|
||||
uint16_t tsum = stickMoveValue();
|
||||
if (tsum != inacSum) {
|
||||
inacSum = tsum;
|
||||
|
@ -1675,7 +1688,7 @@ uint8_t checkTrim(uint8_t event)
|
|||
if (k>=0 && k<8 && !IS_KEY_BREAK(event)) {
|
||||
#endif
|
||||
// LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP
|
||||
uint8_t idx = CONVERT_MODE(1+k/2) - 1;
|
||||
uint8_t idx = CONVERT_MODE(1+(uint8_t)k/2) - 1;
|
||||
uint8_t phase;
|
||||
int16_t before;
|
||||
bool thro;
|
||||
|
@ -1814,18 +1827,19 @@ uint16_t anaIn(uint8_t chan)
|
|||
#if defined(PCBX9D)
|
||||
// crossAna[]={LH,LV,RH,RV,S1,S2,LS,RS,BAT
|
||||
// s_anaFilt[]={LH,LV,RH,RV,S1,S2,LS,RS,_BAT
|
||||
static const uint8_t crossAna[]={0,1,2,3,4,5,6,7,8};
|
||||
return s_anaFilt[chan];
|
||||
#elif defined(PCBSKY9X) && !defined(REVA)
|
||||
static const uint8_t crossAna[]={1,5,7,0,4,6,2,3};
|
||||
if (chan == TX_CURRENT) {
|
||||
return Current_analogue ;
|
||||
}
|
||||
#else
|
||||
static const pm_char crossAna[] PROGMEM ={3,1,2,0,4,5,6,7};
|
||||
#endif
|
||||
|
||||
volatile uint16_t *p = &s_anaFilt[pgm_read_byte(crossAna+chan)];
|
||||
return *p;
|
||||
#else
|
||||
static const pm_char crossAna[] PROGMEM = {3,1,2,0,4,5,6,7};
|
||||
volatile uint16_t *p = &s_anaFilt[pgm_read_byte(crossAna+chan)];
|
||||
return *p;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(CPUARM)
|
||||
|
@ -1893,7 +1907,7 @@ void getADC_bandgap()
|
|||
ADCSRB |= (1<<MUX5);
|
||||
#else
|
||||
// TODO is the next line needed (because it has been called before perMain)?
|
||||
ADMUX=0x1E|ADC_VREF_TYPE; // Switch MUX to internal 1.22V reference
|
||||
ADMUX = 0x1E|ADC_VREF_TYPE; // Switch MUX to internal 1.22V reference
|
||||
|
||||
/*
|
||||
MCUCR|=0x28; // enable Sleep (bit5) enable ADC Noise Reduction (bit2)
|
||||
|
@ -1905,10 +1919,9 @@ void getADC_bandgap()
|
|||
MCUCR&=0x08; // disable sleep
|
||||
*/
|
||||
|
||||
ADCSRA|=0x40;
|
||||
while ((ADCSRA & 0x10)==0);
|
||||
ADCSRA|=0x10; // take sample
|
||||
BandGap=ADC;
|
||||
ADCSRA |= 0x40;
|
||||
while (ADCSRA & 0x40);
|
||||
BandGap = ADC;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
@ -1996,7 +2009,11 @@ uint16_t inacSum = 0;
|
|||
BeepANACenter bpanaCenter = 0;
|
||||
|
||||
uint16_t sDelay[MAX_MIXERS] = {0};
|
||||
#if defined(CPUARM)
|
||||
int32_t act [MAX_MIXERS] = {0};
|
||||
#else
|
||||
__int24 act [MAX_MIXERS] = {0};
|
||||
#endif
|
||||
uint8_t swOn [MAX_MIXERS] = {0};
|
||||
uint8_t mixWarning;
|
||||
|
||||
|
@ -2804,7 +2821,8 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||
if (mode == e_perout_mode_normal && (md->speedUp || md->speedDown)) { // there are delay values
|
||||
#define DEL_MULT_SHIFT 8
|
||||
// we recale to a mult 256 higher value for calculation
|
||||
int16_t diff = v - ((int32_t) act[i]>>DEL_MULT_SHIFT);
|
||||
int32_t tact = act[i];
|
||||
int16_t diff = v - (tact>>DEL_MULT_SHIFT);
|
||||
if (diff) {
|
||||
// open.20.fsguruh: speed is defined in % movement per second; In menu we specify the full movement (-100% to 100%) = 200% in total
|
||||
// the unit of the stored value is the value from md->speedUp or md->speedDown divide SLOW_STEP seconds; e.g. value 4 means 4/SLOW_STEP = 2 seconds for CPU64
|
||||
|
@ -2819,21 +2837,21 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||
if (diff>0) {
|
||||
if (md->speedUp>0) {
|
||||
// if a speed upwards is defined recalculate the new value according configured speed; the higher the speed the smaller the add value is
|
||||
int32_t newValue = act[i]+rate/((int16_t)(100/SLOW_STEP)*md->speedUp);
|
||||
int32_t newValue = tact+rate/((int16_t)(100/SLOW_STEP)*md->speedUp);
|
||||
if (newValue<currentValue) currentValue=newValue; // Endposition; prevent toggling around the destination
|
||||
}
|
||||
}
|
||||
else { // if is <0 because ==0 is not possible
|
||||
if (md->speedDown>0) {
|
||||
// see explanation in speedUp
|
||||
int32_t newValue = act[i]-rate/((int16_t)(100/SLOW_STEP)*md->speedDown);
|
||||
int32_t newValue = tact-rate/((int16_t)(100/SLOW_STEP)*md->speedDown);
|
||||
if (newValue>currentValue) currentValue=newValue; // Endposition; prevent toggling around the destination
|
||||
}
|
||||
} //endif diff>0
|
||||
act[i] = currentValue;
|
||||
act[i] = tact = currentValue;
|
||||
// open.20.fsguruh: this implementation would save about 50 bytes code
|
||||
} // endif tick10ms ; in case no time passed assign the old value, not the current value from source
|
||||
v = (act[i] >> DEL_MULT_SHIFT);
|
||||
v = (tact >> DEL_MULT_SHIFT);
|
||||
} //endif diff
|
||||
} //endif speed
|
||||
|
||||
|
@ -3523,24 +3541,13 @@ uint16_t getTmr16KHz()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// new implementation
|
||||
|
||||
// This ISR is only called if timer matches OCR0. We updated OCR0 on each call to make ISR happen.
|
||||
// If we do not do this, we have 16,385msec time before overflow causes an IRQ
|
||||
// So it's so easy instead of preventing IRQ we
|
||||
//just do not cause it! It's enough not to write to OCR0. This gives plenty of time to finish ISR.
|
||||
// So instead of masking we write OCR0 at the end. Max would be ISR is caused here immediately, which would not do anything,
|
||||
// because all critical pfathes are finished. It also would give us the chance to measure if we passed the next tick and count it.
|
||||
// It's already implemented but commented out, because of code cost.
|
||||
|
||||
ISR(TIMER_10MS_VECT, ISR_NOBLOCK)
|
||||
// 10ms timer
|
||||
{
|
||||
static uint8_t accuracyWarble; // because 16M / 1024 / 100 = 156.25. we need to correct the fault; no start value needed
|
||||
|
||||
#if defined(PCBSTD) && (defined(AUDIO) || defined(VOICE))
|
||||
// Clocks every 128 uS
|
||||
ISR(TIMER2_OVF_vect, ISR_NOBLOCK)
|
||||
{
|
||||
cli();
|
||||
TIMSK &= ~ (1<<TOIE2) ; // stop reentrance
|
||||
sei();
|
||||
|
||||
#if defined(AUDIO)
|
||||
AUDIO_DRIVER();
|
||||
|
@ -3550,70 +3557,30 @@ ISR(TIMER_10MS_VECT, ISR_NOBLOCK)
|
|||
VOICE_DRIVER();
|
||||
#endif
|
||||
|
||||
static uint8_t cnt10ms; // no initialization needed here; execute 10ms code once every 78 ISRs; takes 16.38msec to overrun for first round --> no problem
|
||||
|
||||
#if defined(FRSKY) || defined(MAVLINK) || defined(JETI)
|
||||
if (cnt10ms == 30) {
|
||||
if (!IS_DSM2_SERIAL_PROTOCOL(s_current_protocol))
|
||||
telemetryPoll10ms();
|
||||
}
|
||||
cli();
|
||||
TIMSK |= (1<<TOIE2) ;
|
||||
sei();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (--cnt10ms == 0) { // BEGIN { ... every 10ms ... }
|
||||
// Begin 10ms event
|
||||
// cnt10ms = 78;
|
||||
cnt10ms = (!(++accuracyWarble &0x07)) ? 79 : 78; // instead of assigning we add to take missed ISRs into account
|
||||
// each per10ms() we are 0,016msec too fast
|
||||
// one tick more means 0,112 msec too slow = 7*0,016msec --> in sum we are correct!!!
|
||||
// therefore every 8. round we need to slow down one tick
|
||||
|
||||
#endif
|
||||
// Clocks every 10ms
|
||||
ISR(TIMER_10MS_VECT, ISR_NOBLOCK)
|
||||
{
|
||||
// without correction we are 0,16% too fast; that mean in one hour we are 5,76Sek too fast; we do not like that
|
||||
static uint8_t accuracyWarble; // because 16M / 1024 / 100 = 156.25. we need to correct the fault; no start value needed
|
||||
|
||||
AUDIO_HEARTBEAT();
|
||||
AUDIO_HEARTBEAT();
|
||||
|
||||
#if defined(HAPTIC)
|
||||
HAPTIC_HEARTBEAT();
|
||||
HAPTIC_HEARTBEAT();
|
||||
#endif
|
||||
|
||||
per10ms();
|
||||
per10ms();
|
||||
|
||||
#if defined(PCBSTD) && (defined(AUDIO) || defined(VOICE))
|
||||
} // end 10ms event
|
||||
#endif
|
||||
|
||||
// without correction we are 0,16% too fast; that mean in one hour we are 5,76Sek too fast; we do not like that
|
||||
#if defined(PCBGRUVIN9X)
|
||||
// static uint8_t accuracyWarble; // because 16M / 1024 / 100 = 156.25. we need to correct the fault; not start value needed
|
||||
uint8_t bump = (!(++accuracyWarble & 0x03)) ? 157 : 156;
|
||||
OCR2A += bump;
|
||||
#elif defined(AUDIO) || defined(VOICE)
|
||||
// simple solution; if ISR tooks longer this round is just ignored; The problem in this case is, it takes 16msec for the next ISR --> big gap in AUDIO, VOICE and a big fault in time calculaiton if it happens
|
||||
// cnt10ms--;
|
||||
OCR0 += 2; // interrupt every 128us
|
||||
/*
|
||||
// needs to change cnt10ms to int instead uint to allow cnt10ms to be negative
|
||||
// also remove cnt10ms-- in if statement above, because substraction is done here
|
||||
// code oost: 34 bytes
|
||||
// this solutions all missed ISRs are counted and next ISR is in about 128usec (exception is wrap around)
|
||||
cli();
|
||||
do {
|
||||
cnt10ms--;
|
||||
OCR0 += 2; // interrupt every 128us
|
||||
} while ((OCR0<TCNT0) && (OCR0>=2)); // loop in case ISR tooks too long; If it laps around, ignore additional calcuation and stop anyway
|
||||
// sei(); will be done anyway if ISR is left
|
||||
*/
|
||||
#else
|
||||
// static uint8_t accuracyWarble; // because 16M / 1024 / 100 = 156.25. we need to correct the fault; not start value needed
|
||||
// each tick we are 0,016msec too fast
|
||||
// one tick more means 0,048 msec too slow = 3*0,016msec --> in sum we are correct!!!
|
||||
// therefore every 4 round we need to slow down one tick
|
||||
uint8_t bump = (!(++accuracyWarble & 0x03)) ? 157 : 156;
|
||||
OCR0 += bump;
|
||||
#endif
|
||||
|
||||
TIMER_10MS_COMPVAL += bump;
|
||||
}
|
||||
|
||||
|
||||
// Timer3 used for PPM_IN pulse width capture. Counter running at 16MHz / 8 = 2MHz
|
||||
// equating to one count every half millisecond. (2 counts = 1ms). Control channel
|
||||
// count delta values thus can range from about 1600 to 4400 counts (800us to 2200us),
|
||||
|
@ -4032,10 +3999,14 @@ void menusTask(void * pdata)
|
|||
|
||||
while (pwrCheck() != e_power_off) {
|
||||
perMain();
|
||||
#if defined(PCBSKY9X)
|
||||
for (uint8_t i=0; i<5; i++) {
|
||||
usbMassStorage();
|
||||
CoTickDelay(1); // 5*2ms for now
|
||||
}
|
||||
#else
|
||||
CoTickDelay(5); // 5*2ms for now
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(SDCARD)
|
||||
|
|
25
src/open9x.h
25
src/open9x.h
|
@ -362,10 +362,6 @@ enum EnumKeys {
|
|||
#define PPM_CH_CENTER(ch) (PPM_CENTER)
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
extern char modelNames[MAX_MODELS][sizeof(g_model.name)];
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
// This doesn't need protection on this processor
|
||||
#define tmr10ms_t uint32_t
|
||||
|
@ -384,11 +380,11 @@ extern inline uint16_t get_tmr10ms()
|
|||
}
|
||||
#endif
|
||||
|
||||
// TODO try to merge the 2 include files
|
||||
#include "eeprom_common.h"
|
||||
#if defined(PCBSKY9X)
|
||||
#include "eeprom_arm.h"
|
||||
#include "eeprom_raw.h"
|
||||
#else
|
||||
#include "eeprom_avr.h"
|
||||
#include "eeprom_rlc.h"
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
|
@ -653,18 +649,17 @@ extern uint8_t pxxFlag;
|
|||
|
||||
extern char idx2char(int8_t idx);
|
||||
|
||||
extern uint8_t s_evt;
|
||||
#define putEvent(evt) s_evt = evt
|
||||
void clearKeyEvents();
|
||||
void pauseEvents(uint8_t enuk);
|
||||
void killEvents(uint8_t enuk);
|
||||
|
||||
#if defined(CPUARM)
|
||||
uint8_t getEvent(bool trim);
|
||||
#else
|
||||
uint8_t getEvent();
|
||||
#endif
|
||||
|
||||
void putEvent(uint8_t evt);
|
||||
|
||||
uint8_t keyDown();
|
||||
|
||||
enum PowerState {
|
||||
|
@ -952,15 +947,13 @@ void saveTimers();
|
|||
#define saveTimers()
|
||||
#endif
|
||||
|
||||
void eeDirty(uint8_t msk);
|
||||
void eeCheck(bool immediately=false);
|
||||
void eeReadAll();
|
||||
bool eeModelExists(uint8_t id);
|
||||
void eeLoadModelName(uint8_t id, char *name);
|
||||
void eeLoadModel(uint8_t id);
|
||||
void generalDefault();
|
||||
void modelDefault(uint8_t id);
|
||||
|
||||
#if defined(PXX) && defined(CPUARM)
|
||||
void checkModelIdUnique(uint8_t id);
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
inline int16_t calc100to256_16Bits(register int16_t x) // @@@2 open.20.fsguruh: return x*2.56
|
||||
{
|
||||
|
|
|
@ -97,6 +97,7 @@ typedef const uint16_t pm_uint16_t;
|
|||
typedef const uint8_t pm_uint8_t;
|
||||
typedef const int16_t pm_int16_t;
|
||||
typedef const int8_t pm_int8_t;
|
||||
typedef int32_t __int24;
|
||||
|
||||
#if defined(PCBX9D) || defined(PCBACT)
|
||||
extern GPIO_TypeDef gpioa;
|
||||
|
|
|
@ -49,8 +49,8 @@ void btInit()
|
|||
}
|
||||
|
||||
OS_FlagID btFlag;
|
||||
Fifo32 btTxFifo;
|
||||
Fifo32 btRxFifo;
|
||||
Fifo<32> btTxFifo;
|
||||
Fifo<32> btRxFifo;
|
||||
|
||||
struct t_serial_tx btTx ;
|
||||
uint8_t btTxBuffer[32] ;
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
#if !defined(SIMU)
|
||||
|
||||
extern Fifo512 debugRxFifo;
|
||||
extern Fifo<512> debugRxFifo;
|
||||
|
||||
/*
|
||||
* Outputs a character on the UART line.
|
||||
|
|
|
@ -102,29 +102,22 @@ inline void boardInit()
|
|||
DDRB = 0x81; PORTB = 0x7e; //pullups keys+nc
|
||||
DDRC = 0x3e; PORTC = 0xc1; //pullups nc
|
||||
DDRD = 0x00; PORTD = 0xff; //pullups keys
|
||||
DDRE = (1<<OUT_E_BUZZER); PORTE = 0xff-(1<<OUT_E_BUZZER); //pullups + buzzer 0
|
||||
DDRE = (1<<OUT_E_BUZZER); PORTE = 0xff-(1<<OUT_E_BUZZER); //pullups + buzzer 0
|
||||
DDRF = 0x00; PORTF = 0x00; //anain
|
||||
DDRG = 0x14; PORTG = 0xfb; //pullups + SIM_CTL=1 = phonejack = ppm_in, Haptic output and off (0)
|
||||
|
||||
ADMUX=ADC_VREF_TYPE;
|
||||
ADCSRA=0x85; // ADC enabled, pre-scaler division=32 (no interrupt, no auto-triggering)
|
||||
|
||||
/**** Set up timer/counter 0 ****/
|
||||
#if defined (AUDIO)
|
||||
// TCNT0 10ms = 16MHz/1024/2(/78) periodic timer (for speaker tone generation)
|
||||
// Capture ISR 7812.5/second -- runs per-10ms code segment once every 78
|
||||
// cycles (9.984ms). Timer overflows at about 61Hz or once every 16ms.
|
||||
TCCR0 = (0b111 << CS00);// Norm mode, clk/1024
|
||||
OCR0 = 2;
|
||||
#else
|
||||
// TCNT0 10ms = 16MHz/1024/156 periodic timer (9.984ms)
|
||||
// (with 1:4 duty at 157 to average 10.0ms)
|
||||
// Timer overflows at about 61Hz or once every 16ms.
|
||||
TCCR0 = (0b111 << CS00);// Norm mode, clk/1024
|
||||
TCCR0 = (0b111 << CS00); // Norm mode, clk/1024
|
||||
OCR0 = 156;
|
||||
#endif
|
||||
|
||||
#if defined(PWM_BACKLIGHT)
|
||||
#if defined(AUDIO) || defined(VOICE)
|
||||
TCCR2 = (0b010 << CS00); // Norm mode, clk/8
|
||||
#elif defined(PWM_BACKLIGHT)
|
||||
/** Smartieparts LED Backlight is connected to PORTB/pin7, which can be used as pwm output of timer2 **/
|
||||
#if defined(SP22)
|
||||
TCCR2 = (0b011 << CS20)|(1<<WGM20)|(1<<COM21)|(1<<COM20); // inv. pwm mode, clk/64
|
||||
|
@ -133,8 +126,7 @@ inline void boardInit()
|
|||
#endif
|
||||
#endif
|
||||
|
||||
TIMSK |= (1<<OCIE0) | (1<<TOIE0); // Enable Output-Compare and Overflow interrrupts
|
||||
/********************************/
|
||||
TIMSK |= (1<<OCIE0) | (1<<TOIE0) | (1<<TOIE2); // Enable Output-Compare and Overflow interrrupts
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
#define COUNTER_16KHZ TCNT0
|
||||
|
||||
#define TIMER_10MS_VECT TIMER0_COMP_vect
|
||||
#define TIMER_10MS_COMPVAL OCR0
|
||||
#define PAUSE_10MS_INTERRUPT() TIMSK &= ~(1<<OCIE0)
|
||||
#define RESUME_10MS_INTERRUPT() TIMSK |= (1<<OCIE0)
|
||||
|
||||
|
|
|
@ -327,16 +327,15 @@
|
|||
#define INDENT_WIDTH (FW/2)
|
||||
|
||||
#if defined(PCBX9D)
|
||||
#define TR_POPUPS "[ENTER]\010[EXIT]"
|
||||
#define TR_ENTER "[ENTER]"
|
||||
#else
|
||||
#define TR_POPUPS "[MENU]\010[EXIT]"
|
||||
#endif
|
||||
#define OFS_EXIT 7
|
||||
#if defined(PCBX9D)
|
||||
#define TR_MENUWHENDONE CENTER"\006[ENTER] WHEN DONE"
|
||||
#else
|
||||
#define TR_MENUWHENDONE CENTER"\006[MENU] WHEN DONE"
|
||||
#define TR_ENTER "[MENU]"
|
||||
#endif
|
||||
|
||||
#define TR_POPUPS TR_ENTER"\010[EXIT]"
|
||||
#define OFS_EXIT sizeof(TR_ENTER)
|
||||
|
||||
#define TR_MENUWHENDONE CENTER"\006"TR_ENTER" WHEN DONE"
|
||||
#define TR_FREE "free"
|
||||
#define TR_DELETEMODEL "DELETE MODEL"
|
||||
#define TR_COPYINGMODEL "Copying model..."
|
||||
|
@ -434,13 +433,7 @@
|
|||
#define TR_CAL "Cal"
|
||||
#define TR_VTRIM "Trim- +"
|
||||
#define TR_BG "BG:"
|
||||
|
||||
#if defined(PCBX9D)
|
||||
#define TR_MENUTOSTART CENTER"\006[ENTER] TO START"
|
||||
#else
|
||||
#define TR_MENUTOSTART CENTER"\006[MENU] TO START"
|
||||
#endif
|
||||
|
||||
#define TR_MENUTOSTART CENTER"\006"TR_ENTER" TO START"
|
||||
#define TR_SETMIDPOINT CENTER"\003SET STICKS MIDPOINT"
|
||||
#define TR_MOVESTICKSPOTS CENTER"\006MOVE STICKS/POTS"
|
||||
#define TR_RXBATT "Rx Batt:"
|
||||
|
@ -475,7 +468,7 @@
|
|||
#define TR_PRESSANYKEYTOSKIP CENTER"Press any key to skip"
|
||||
#define TR_THROTTLENOTIDLE CENTER"Throttle not idle"
|
||||
#define TR_ALARMSDISABLED CENTER"Alarms Disabled"
|
||||
#define TR_PRESSANYKEY TR("\010Press any Key",CENTER"Press any Key")
|
||||
#define TR_PRESSANYKEY TR("\010Press any Key", CENTER"Press any Key")
|
||||
#define TR_BADEEPROMDATA CENTER"Bad EEprom Data"
|
||||
#define TR_EEPROMFORMATTING CENTER"Formatting EEPROM"
|
||||
#define TR_EEPROMOVERFLOW CENTER"EEPROM overflow"
|
||||
|
@ -511,7 +504,7 @@
|
|||
#define TR_MENUSTAT "STATS"
|
||||
#define TR_MENUDEBUG "DEBUG"
|
||||
#define TR_RXNUM TR("RxNum","Receiver No.")
|
||||
#define TR_SYNCMENU "Sync [MENU]"
|
||||
#define TR_SYNCMENU "Sync "TR_ENTER
|
||||
#define TR_LIMIT INDENT"Limit"
|
||||
#define TR_MINRSSI "Min Rssi"
|
||||
#define TR_LATITUDE "Latitude"
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#ifndef _USB_MSC_CORE_H_
|
||||
#define _USB_MSC_CORE_H_
|
||||
|
||||
#include "usbd_ioreq.h"
|
||||
#include "../../../Core/inc/usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup USBD_MSC_BOT
|
||||
* @{
|
||||
|
|
|
@ -266,9 +266,9 @@ static int8_t SCSI_ReadCapacity10(uint8_t lun, uint8_t *params)
|
|||
else
|
||||
{
|
||||
|
||||
MSC_BOT_Data[0] = (uint8_t)(SCSI_blk_nbr - 1 >> 24);
|
||||
MSC_BOT_Data[1] = (uint8_t)(SCSI_blk_nbr - 1 >> 16);
|
||||
MSC_BOT_Data[2] = (uint8_t)(SCSI_blk_nbr - 1 >> 8);
|
||||
MSC_BOT_Data[0] = (uint8_t)((SCSI_blk_nbr - 1) >> 24);
|
||||
MSC_BOT_Data[1] = (uint8_t)((SCSI_blk_nbr - 1) >> 16);
|
||||
MSC_BOT_Data[2] = (uint8_t)((SCSI_blk_nbr - 1) >> 8);
|
||||
MSC_BOT_Data[3] = (uint8_t)(SCSI_blk_nbr - 1);
|
||||
|
||||
MSC_BOT_Data[4] = (uint8_t)(SCSI_blk_size >> 24);
|
||||
|
@ -309,9 +309,9 @@ static int8_t SCSI_ReadFormatCapacity(uint8_t lun, uint8_t *params)
|
|||
else
|
||||
{
|
||||
MSC_BOT_Data[3] = 0x08;
|
||||
MSC_BOT_Data[4] = (uint8_t)(blk_nbr - 1 >> 24);
|
||||
MSC_BOT_Data[5] = (uint8_t)(blk_nbr - 1 >> 16);
|
||||
MSC_BOT_Data[6] = (uint8_t)(blk_nbr - 1 >> 8);
|
||||
MSC_BOT_Data[4] = (uint8_t)((blk_nbr - 1) >> 24);
|
||||
MSC_BOT_Data[5] = (uint8_t)((blk_nbr - 1) >> 16);
|
||||
MSC_BOT_Data[6] = (uint8_t)((blk_nbr - 1) >> 8);
|
||||
MSC_BOT_Data[7] = (uint8_t)(blk_nbr - 1);
|
||||
|
||||
MSC_BOT_Data[8] = 0x02;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#define __USBD_CORE_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_dcd.h"
|
||||
#include "../../../STM32_USB_OTG_Driver/inc/usb_dcd.h"
|
||||
#include "usbd_def.h"
|
||||
#include "../../../../../usbd_conf.h"
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#define __USB_CORE_H__
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../../../../../usb_conf.h"
|
||||
#include "../../../../usb_conf.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usb_defines.h"
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#define __USB_DEF_H__
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../../../../../usb_conf.h"
|
||||
#include "../../../../usb_conf.h"
|
||||
|
||||
/** @addtogroup USB_OTG_DRIVER
|
||||
* @{
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#define __USB_OTG_REGS_H__
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../../../../../usb_conf.h"
|
||||
#include "../../../../usb_conf.h"
|
||||
|
||||
|
||||
/** @addtogroup USB_OTG_DRIVER
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include "../open9x.h"
|
||||
extern "C" {
|
||||
#include "x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h"
|
||||
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h"
|
||||
}
|
||||
|
||||
// TODO needed?
|
||||
|
@ -128,14 +128,7 @@ void start_ppm_capture()
|
|||
{
|
||||
}
|
||||
|
||||
void usbBootloader()
|
||||
{
|
||||
}
|
||||
|
||||
void usbMassStorage()
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" {
|
||||
USB_OTG_CORE_HANDLE USB_OTG_dev;
|
||||
|
||||
|
@ -149,6 +142,7 @@ void usbInit()
|
|||
{
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
|
||||
}
|
||||
#endif
|
||||
|
||||
void watchdogInit()
|
||||
{
|
||||
|
|
|
@ -63,8 +63,6 @@ extern "C" {
|
|||
#define TIMER_MULT_APB1 2
|
||||
#define TIMER_MULT_APB2 1
|
||||
|
||||
void usbMassStorage();
|
||||
|
||||
#define JACK_PPM_OUT()
|
||||
#define JACK_PPM_IN()
|
||||
|
||||
|
@ -81,7 +79,7 @@ uint8_t getTemperature();
|
|||
extern uint16_t sessionTimer;
|
||||
|
||||
uint8_t usbPlugged(void);
|
||||
#define BOOTLOADER_REQUEST() (0/*usbPlugged()*/)
|
||||
#define BOOTLOADER_REQUEST() (0)
|
||||
|
||||
#define SLAVE_MODE() (0/*pwrCheck() == e_power_trainer*/)
|
||||
|
||||
|
|
|
@ -50,10 +50,10 @@ uint32_t pwrCheck()
|
|||
return e_power_on;
|
||||
#if !defined(REV3)
|
||||
else if (GPIO_ReadInputDataBit(GPIOTRNDET, PIN_TRNDET) == Bit_SET)
|
||||
return e_power_trainer;
|
||||
return e_power_trainer;
|
||||
#endif
|
||||
else if (usbPlugged())
|
||||
return e_power_usb;
|
||||
return e_power_usb;
|
||||
else
|
||||
return e_power_off;
|
||||
#endif
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#define __USB_DESC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_def.h"
|
||||
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc/usbd_def.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue