CooCox on ARM

New option THR_TRACE to save flash and RAM on Stock board
DMA used for SD-Card
CMD16 command added for block length = 512 bytes
This commit is contained in:
bsongis
2012-06-19 22:49:48 +00:00
parent 0d1496dbcd
commit 777f48121b
18 changed files with 304 additions and 171 deletions
+9 -9
View File
@@ -42,12 +42,12 @@ Idle task stack size(word).
/*!<
System frequency (Hz).
*/
#define CFG_CPU_FREQ (72000000)
#define CFG_CPU_FREQ (36000000)
/*!<
systick frequency (Hz).
*/
#define CFG_SYSTICK_FREQ (100)
#define CFG_SYSTICK_FREQ (500)
/*!<
max systerm api call num in ISR.
@@ -96,7 +96,7 @@ But in Dynamic Task Scheduling model(1),task resources will be recovered.
If in Static Task Scheduling model(0),mutex module can not be used, as this model don't
support to change task priority while CoOS running.
*/
#define CFG_TASK_SCHEDULE_EN (1)
#define CFG_TASK_SCHEDULE_EN (0)
/*---------------------- Task Management Config -----------------------------*/
@@ -110,19 +110,19 @@ Enable(1) or disable(0) CoSetPriority() API.
/*!<
Enable(1) or disable(0) CoAwakeTask() and CoSuspendTask() API.
*/
#define CFG_TASK_SUSPEND_EN (1)
#define CFG_TASK_SUSPEND_EN (0)
/*---------------------- Debug Management Config ----------------------------*/
/*!<
Enable(1) or disable(0) parameter checkout .
*/
#define CFG_PAR_CHECKOUT_EN (1)
#define CFG_PAR_CHECKOUT_EN (0)
/*!<
Enable(1) or disable(0) stack overflow checkout .
*/
#define CFG_STK_CHECKOUT_EN (1)
#define CFG_STK_CHECKOUT_EN (0)
@@ -130,7 +130,7 @@ Enable(1) or disable(0) stack overflow checkout .
/*!<
Enable(1) or disable(0) memory management.
*/
#define CFG_MM_EN (1)
#define CFG_MM_EN (0)
/*!<
Max number of memory.(must be less than 32).
@@ -161,7 +161,7 @@ Kernel heap size(word).
Enable(1) or disable(0) TimeDelay() API.
*/
#if CFG_TASK_WAITTING_EN >0
#define CFG_TIME_DELAY_EN (1)
#define CFG_TIME_DELAY_EN (0)
#endif
@@ -198,7 +198,7 @@ Event sort type.(1)FIFO (2)PRI (3)FIFO+PRI
Max number of event.(must be less than 255)
Event = semaphore + mailbox + queue;
*/
#define CFG_MAX_EVENT (20)
#define CFG_MAX_EVENT (10)
/*!<
Enable(1) or disable(0) semaphore management.
+1
View File
@@ -31,6 +31,7 @@
*
*/
#include "ff.h"
#include "fattime.h"
#include "integer.h"
+14 -4
View File
@@ -65,6 +65,9 @@ SPLASH = YES
# GRAPHICS (sliders / checkboxes)
GRAPHICS = YES
# THR trace (in STATS screen)
THR_TRACE = YES
# PPM center adjustable
# Values = YES, NO
PPM_CENTER_ADJUSTABLE = NO
@@ -172,6 +175,7 @@ ifeq ($(PCB), ARM)
endif
CC = $(TRGT)gcc
AS = $(TRGT)as
OBJCOPY = $(TRGT)objcopy
OBJDUMP = $(TRGT)objdump
SIZE = $(TRGT)size
@@ -191,6 +195,7 @@ FORMAT = ihex
TARGET = open9x
# List C++ source files here. (C dependencies are automatically generated.)
SRC =
CPPSRC = open9x.cpp $(PULSESSRC) stamp.cpp menus.cpp model_menus.cpp general_menus.cpp main_views.cpp statistics_views.cpp $(EEPROMSRC) lcd.cpp drivers.cpp translations.cpp
ifeq ($(EXT), JETI)
@@ -252,6 +257,10 @@ ifeq ($(GRAPHICS), YES)
CPPDEFS += -DGRAPHICS
endif
ifeq ($(THR_TRACE), YES)
CPPDEFS += -DTHRTRACE
endif
ifeq ($(FLIGHT_PHASES), YES)
CPPDEFS += -DFLIGHT_PHASES
endif
@@ -321,9 +330,10 @@ ifeq ($(PCB), ARM)
# V4 ARM, so ...
OPT = 2
CPPDEFS += -DPCBARM -DAUDIO -DHAPTIC -DPXX -DDSM2 -DDSM2_PPM
EXTRAINCDIRS += ersky9x
EXTRAINCDIRS += ersky9x CoOS/kernel CoOS/portable
BOARDSRC = board_ersky9x.cpp
SRC = ersky9x/core_cm3.c ersky9x/board_lowlevel.c ersky9x/crt.c ersky9x/vectors_sam3s.c
SRC += ersky9x/core_cm3.c ersky9x/board_lowlevel.c ersky9x/crt.c ersky9x/vectors_sam3s.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/serviceReq.c CoOS/portable/GCC/port.c CoOS/portable/arch.c
SRC += FatFs/ff.c FatFs/fattime.c ersky9x/diskio.c
EEPROMSRC = eeprom_arm.cpp
PULSESSRC = pulses_arm.cpp
@@ -620,8 +630,8 @@ FOXLIB=-L/usr/local/lib \
-lFOX-1.6 \
-Wl,-rpath,$(FOXPATH)/src/.libs
simu: stamp_header $(BOARDSRC) $(CPPSRC) Makefile simu.cpp simpgmspace.cpp *.h *.lbm eeprom.bin
g++ simu.cpp $(CPPFLAGS) $(BOARDSRC) $(CPPSRC) simpgmspace.cpp $(ARCH) -MD -DSIMU -o simu $(FOXINC) $(FOXLIB) -pthread
simu: stamp_header $(BOARDSRC) $(CPPSRC) $(SRC) Makefile simu.cpp simpgmspace.cpp *.h *.lbm eeprom.bin
g++ simu.cpp $(CPPFLAGS) $(BOARDSRC) $(CPPSRC) $(SRC) simpgmspace.cpp $(ARCH) -MD -DSIMU -o simu $(FOXINC) $(FOXLIB) -pthread
eeprom.bin:
dd if=/dev/zero of=$@ bs=1 count=2048
+2 -1
View File
@@ -750,7 +750,8 @@ uint32_t read_keys()
register uint32_t x;
register uint32_t y;
x = PIOC->PIO_PDSR << 1; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
x = lcdLock ? lcdInputs : PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
x <<= 1;
#ifdef REVB
y = x & 0x00000020; // RIGHT
+1 -6
View File
@@ -34,12 +34,7 @@
#ifndef board_ersky9x_h
#define board_ersky9x_h
#ifdef REVA
#include "ersky9x/AT91SAM3S2.h"
#else
#include "ersky9x/AT91SAM3S4.h"
#endif
#include "ersky9x/board.h"
#include "ersky9x/sound_driver.h"
#include "ersky9x/haptic_driver.h"
+8 -8
View File
@@ -39,7 +39,14 @@ void putEvent(uint8_t evt)
s_evt = evt;
}
#if defined(PCBV4)
#if defined(PCBSTD)
uint8_t getEvent()
{
uint8_t evt = s_evt;
s_evt = 0;
return evt;
}
#else
uint8_t getEvent(bool trim)
{
uint8_t evt = s_evt;
@@ -54,13 +61,6 @@ uint8_t getEvent(bool trim)
return 0;
}
}
#else
uint8_t getEvent()
{
uint8_t evt = s_evt;
s_evt = 0;
return evt;
}
#endif
#if defined(PCBARM)
+1 -1
View File
@@ -962,7 +962,7 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc)
strcpy(&buf[len], STR_MODELS_EXT);
result = f_open(&archiveFile, buf, FA_OPEN_ALWAYS | FA_WRITE);
result = f_open(&archiveFile, buf, FA_CREATE_ALWAYS | FA_WRITE);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
+52 -37
View File
@@ -39,7 +39,8 @@
/*-----------------------------------------------------------------------*/
#include "board.h"
#include "FatFs/diskio.h"
#include "../FatFs/diskio.h"
#include "../CoOS/kernel/CoOS.h"
// States for initialising card
#define SD_ST_EMPTY 0
@@ -586,67 +587,81 @@ uint32_t sd_card_ready( void )
return 0 ;
}
uint32_t sd_read_block( uint32_t block_no, uint32_t *dat )
uint32_t sd_cmd16()
{
Hsmci *phsmci = HSMCI;
if (CardIsConnected()) {
phsmci->HSMCI_BLKR = ( ( 512 ) << 16 ) | 1 ;
phsmci->HSMCI_ARGR = 512;
phsmci->HSMCI_CMDR = SDMMC_SET_BLOCKLEN;
while(1) {
if (phsmci->HSMCI_SR & HSMCI_SR_CMDRDY) {
break;
}
}
return phsmci->HSMCI_RSPR[0];
}
else {
return 0;
}
}
uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
{
if (Card_state == SD_ST_DATA) {
Hsmci *phsmci = HSMCI;
if (CardIsConnected()) {
uint8_t i;
for (i = 0; i < 3; i++) {
uint32_t *data = dat;
uint32_t j = 0;
// Block size = 512, nblocks = 1
phsmci->HSMCI_BLKR = ((512) << 16) | 1;
phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_PDCMODE|HSMCI_MR_FBYTE))) | HSMCI_MR_WRPROOF | HSMCI_MR_RDPROOF | (512 << 16);
phsmci->HSMCI_ARGR = block_no << 9;
phsmci->HSMCI_CMDR = SD_READ_SINGLE_BLOCK;
sd_cmd16();
// Block size = 512, nblocks = 1
phsmci->HSMCI_BLKR = ((512) << 16) | 1;
phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_FBYTE))) | (HSMCI_MR_PDCMODE|HSMCI_MR_WRPROOF|HSMCI_MR_RDPROOF) | (512 << 16);
phsmci->HSMCI_RPR = (uint32_t)data;
phsmci->HSMCI_RCR = 512 / 4;
phsmci->HSMCI_RNCR = 0;
phsmci->HSMCI_PTCR = HSMCI_PTCR_RXTEN;
phsmci->HSMCI_ARGR = block_no << 9;
phsmci->HSMCI_CMDR = SD_READ_SINGLE_BLOCK;
while (1) {
if (phsmci->HSMCI_SR & HSMCI_SR_RXRDY) {
*data++ = phsmci->HSMCI_RDR;
j += 1;
}
if (j >= 128) {
return 1;
}
if ((phsmci->HSMCI_SR & (HSMCI_SR_CMDRDY | HSMCI_SR_XFRDONE)) == (HSMCI_SR_CMDRDY | HSMCI_SR_XFRDONE)) {
break;
}
uint8_t retry = 100;
while (retry-- > 0) {
CoTickDelay(1); // 2ms
if (phsmci->HSMCI_SR & HSMCI_SR_ENDRX) {
return 1;
}
}
}
}
return 0;
}
uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
{
if (Card_state == SD_ST_DATA) {
uint32_t j = 0;
Hsmci *phsmci = HSMCI;
if (CardIsConnected()) {
sd_cmd16();
// Block size = 512, nblocks = 1
phsmci->HSMCI_BLKR = ((512) << 16) | 1;
phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_PDCMODE|HSMCI_MR_FBYTE))) | HSMCI_MR_WRPROOF | HSMCI_MR_RDPROOF | (512 << 16);
phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_FBYTE))) | (HSMCI_MR_PDCMODE|HSMCI_MR_WRPROOF|HSMCI_MR_RDPROOF) | (512 << 16);
phsmci->HSMCI_TPR = (uint32_t)data;
phsmci->HSMCI_TCR = 512 / 4;
phsmci->HSMCI_TNCR = 0;
phsmci->HSMCI_ARGR = block_no << 9;
phsmci->HSMCI_CMDR = SD_WRITE_SINGLE_BLOCK;
phsmci->HSMCI_PTCR = HSMCI_PTCR_TXTEN;
while (1) {
if (j >= 128) {
while (~phsmci->HSMCI_SR & HSMCI_SR_NOTBUSY)
;
uint8_t retry = 100;
while (retry-- > 0) {
CoTickDelay(1); // 2ms
if (phsmci->HSMCI_SR & HSMCI_SR_NOTBUSY) {
return 1;
}
if (phsmci->HSMCI_SR & HSMCI_SR_TXRDY) {
phsmci->HSMCI_TDR = *data++;
j += 1;
}
}
}
}
+1 -5
View File
@@ -51,9 +51,8 @@ void BusFault_Handler (void) __attribute__((weak));
void UsageFault_Handler (void) __attribute__((weak));
void SVC_Handler (void) __attribute__((weak));
void DebugMon_Handler (void) __attribute__((weak));
void PendSV_Handler (void) __attribute__((weak));
void PendSV_Handler(void) __attribute__((weak));
void SysTick_Handler (void) __attribute__((weak));
void SUPC_IRQHandler (void) __attribute__((weak));
void RSTC_IRQHandler (void) __attribute__((weak));
void RTC_IRQHandler (void) __attribute__((weak));
@@ -158,9 +157,6 @@ void BusFault_Handler (void) { while(1); }
void UsageFault_Handler (void) { while(1); }
void SVC_Handler (void) { while(1); }
void DebugMon_Handler (void) { while(1); }
void PendSV_Handler (void) { while(1); }
void SysTick_Handler (void) { while(1); }
void SUPC_IRQHandler (void) { while(1); }
void RSTC_IRQHandler (void) { while(1); }
void RTC_IRQHandler (void) { while(1); }
+15 -15
View File
@@ -1050,24 +1050,24 @@ void displayGpsCoord(uint8_t y, char direction, int16_t bp, int16_t ap)
if (!direction) direction = '-';
lcd_outdezAtt(10*FW, y, bp / 100, LEFT); // ddd before '.'
lcd_putc(lcd_lastPos, y, '@');
lcd_putc(lcdLastPos, y, '@');
uint8_t mn = bp % 100;
if (g_eeGeneral.gpsFormat == 0) {
lcd_putc(lcd_lastPos+FWNUM, y, direction);
lcd_outdezNAtt(lcd_lastPos+FW+FW+1, y, mn, LEFT|LEADING0, 2); // mm before '.'
lcd_vline(lcd_lastPos, y, 2);
lcd_putc(lcdLastPos+FWNUM, y, direction);
lcd_outdezNAtt(lcdLastPos+FW+FW+1, y, mn, LEFT|LEADING0, 2); // mm before '.'
lcd_vline(lcdLastPos, y, 2);
uint16_t ss = ap * 6;
lcd_outdezAtt(lcd_lastPos+3, y, ss / 1000, LEFT); // ''
lcd_plot(lcd_lastPos, y+FH-2, 0); // small decimal point
lcd_outdezAtt(lcd_lastPos+2, y, ss % 1000, LEFT); // ''
lcd_vline(lcd_lastPos, y, 2);
lcd_vline(lcd_lastPos+2, y, 2);
lcd_outdezAtt(lcdLastPos+3, y, ss / 1000, LEFT); // ''
lcd_plot(lcdLastPos, y+FH-2, 0); // small decimal point
lcd_outdezAtt(lcdLastPos+2, y, ss % 1000, LEFT); // ''
lcd_vline(lcdLastPos, y, 2);
lcd_vline(lcdLastPos+2, y, 2);
}
else {
lcd_outdezNAtt(lcd_lastPos+FW, y, mn, LEFT|LEADING0, 2); // mm before '.'
lcd_plot(lcd_lastPos, y+FH-2, 0); // small decimal point
lcd_outdezNAtt(lcd_lastPos+2, y, ap, LEFT|UNSIGN|LEADING0, 4); // after '.'
lcd_putc(lcd_lastPos+1, y, direction);
lcd_outdezNAtt(lcdLastPos+FW, y, mn, LEFT|LEADING0, 2); // mm before '.'
lcd_plot(lcdLastPos, y+FH-2, 0); // small decimal point
lcd_outdezNAtt(lcdLastPos+2, y, ap, LEFT|UNSIGN|LEADING0, 4); // after '.'
lcd_putc(lcdLastPos+1, y, direction);
}
}
else {
@@ -1270,9 +1270,9 @@ void menuProcFrsky(uint8_t event)
// Rssi
lcd_putsLeft(line, STR_MINRSSI);
lcd_puts(10*FW, line, STR_TX);
lcd_outdezNAtt(lcd_lastPos, line, frskyRSSI[1].min, LEFT|LEADING0, 2);
lcd_outdezNAtt(lcdLastPos, line, frskyRSSI[1].min, LEFT|LEADING0, 2);
lcd_puts(16*FW, line, STR_RX);
lcd_outdezNAtt(lcd_lastPos, line, frskyRSSI[0].min, LEFT|LEADING0, 2);
lcd_outdezNAtt(lcdLastPos, line, frskyRSSI[0].min, LEFT|LEADING0, 2);
}
#endif
}
+2 -2
View File
@@ -289,7 +289,7 @@ void menuProcSetup(uint8_t event)
case ITEM_SETUP_INACTIVITY_ALARM:
lcd_putsLeft( y,STR_INACTIVITYALARM);
lcd_outdezAtt(GENERAL_PARAM_OFS, y, g_eeGeneral.inactivityTimer, attr|LEFT);
lcd_putc(lcd_lastPos, y, 'm');
lcd_putc(lcdLastPos, y, 'm');
if(attr) g_eeGeneral.inactivityTimer = checkIncDec(event, g_eeGeneral.inactivityTimer, 0, 250, EE_GENERAL); //0..250minutes
break;
@@ -335,7 +335,7 @@ void menuProcSetup(uint8_t event)
lcd_putsLeft( y, STR_LIGHTOFFAFTER);
if(g_eeGeneral.lightAutoOff) {
lcd_outdezAtt(GENERAL_PARAM_OFS, y, g_eeGeneral.lightAutoOff*5, attr|LEFT);
lcd_putc(lcd_lastPos, y, 's');
lcd_putc(lcdLastPos, y, 's');
}
else {
lcd_putsiAtt(GENERAL_PARAM_OFS, y, STR_OFFON, 0, attr);
+30 -14
View File
@@ -65,7 +65,12 @@ void lcd_img(uint8_t x, uint8_t y, const pm_uchar * img, uint8_t idx, uint8_t mo
}
}
uint8_t lcd_lastPos;
uint8_t lcdLastPos;
#if defined(PCBARM)
uint8_t lcdLock;
uint8_t lcdInputs;
#endif
void lcd_putcAtt(uint8_t x, uint8_t y, const unsigned char c, uint8_t mode)
{
@@ -174,7 +179,7 @@ void lcd_putsnAtt(uint8_t x,uint8_t y,const pm_char * s,uint8_t len,uint8_t mode
s++;
len--;
}
lcd_lastPos = x;
lcdLastPos = x;
}
void lcd_putsn(uint8_t x,uint8_t y,const pm_char * s,uint8_t len)
@@ -272,7 +277,7 @@ void lcd_outdezNAtt(uint8_t x, uint8_t y, int16_t val, uint8_t flags, uint8_t le
x += (dblsize ? 7 : FWNUM);
}
lcd_lastPos = x;
lcdLastPos = x;
x -= fw + 1;
for (uint8_t i=1; i<=len; i++) {
@@ -317,7 +322,7 @@ void lcd_outdezNAtt(uint8_t x, uint8_t y, int16_t val, uint8_t flags, uint8_t le
#if defined(ROTARY_ENCODERS)
if (flags & SURROUNDED) {
xn = lcd_lastPos - x + 2;
xn = lcdLastPos - x + 2;
if (!neg) { x+=FW; xn-=FW; }
lcd_rect(x-1, y-1, xn, 9, BLINK_ON_PHASE ? DOTTED : ~DOTTED);
}
@@ -435,15 +440,15 @@ void putsTime(uint8_t x,uint8_t y,int16_t tme,uint8_t att,uint8_t att2)
}
lcd_outdezNAtt(x, y, tme/60, att|LEADING0|LEFT, 2);
lcd_putcAtt(lcd_lastPos-((att & DBLSIZE) ? 1 : 0), y, ':', att&att2);
lcd_outdezNAtt(lcd_lastPos+FW, y, tme%60, att2|LEADING0|LEFT, 2);
lcd_putcAtt(lcdLastPos-((att & DBLSIZE) ? 1 : 0), y, ':', att&att2);
lcd_outdezNAtt(lcdLastPos+FW, y, tme%60, att2|LEADING0|LEFT, 2);
}
// TODO to be optimized with putsTelemetryValue
void putsVolts(uint8_t x, uint8_t y, uint16_t volts, uint8_t att)
{
lcd_outdezAtt(x, y, (int16_t)volts, (~NO_UNIT) & (att | ((att&PREC2)==PREC2 ? 0 : PREC1)));
if (~att & NO_UNIT) lcd_putcAtt(lcd_lastPos, y, 'v', att&(~INVERS));
if (~att & NO_UNIT) lcd_putcAtt(lcdLastPos, y, 'v', att&(~INVERS));
}
void putsVBat(uint8_t x, uint8_t y, uint8_t att)
@@ -454,8 +459,8 @@ void putsVBat(uint8_t x, uint8_t y, uint8_t att)
void putsStrIdx(uint8_t x, uint8_t y, const pm_char *str, uint8_t idx, uint8_t att)
{
lcd_putsAtt(x, y, str, att & ~BSS); // TODO use something else than BSS for LEADING0
lcd_outdezNAtt(lcd_lastPos, y, idx, att|LEFT, 2);
if (att&TWO_DOTS) lcd_putc(lcd_lastPos, y, ':');
lcd_outdezNAtt(lcdLastPos, y, idx, att|LEFT, 2);
if (att&TWO_DOTS) lcd_putc(lcdLastPos, y, ':');
}
void putsChnRaw(uint8_t x, uint8_t y, uint8_t idx, uint8_t att)
@@ -754,6 +759,10 @@ void lcdSetRefVolt(uint8_t val)
register Pio *pioptr ;
pioptr = PIOC ;
// read the inputs, and lock the LCD lines
lcdInputs = PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
lcdLock = 1 ;
pioptr->PIO_OER = 0x0C00B0FFL ; // Set bits 27,26,15,13,12,7-0 output
lcdSendCtl(0x81);
@@ -766,13 +775,14 @@ void lcdSetRefVolt(uint8_t val)
#ifdef REVB
pioptr->PIO_ODR = 0x0000003AL ; // Set bits 1, 3, 4, 5 input
pioptr->PIO_PUER = 0x0000003AL ; // Set bits 1, 3, 4, 5 with pullups
pioptr->PIO_ODSR = 0 ; // Drive D0 low
#else
pioptr->PIO_ODR = 0x0000003CL ; // Set bits 2, 3, 4, 5 input
pioptr->PIO_PUER = 0x0000003CL ; // Set bits 2, 3, 4, 5 with pullups
pioptr->PIO_ODSR = 0 ; // Drive D0 low
#endif
#endif
pioptr->PIO_ODSR = lcdInputs; // Drive D0 low
lcdLock = 0 ;
}
#ifndef SIMU
@@ -784,11 +794,11 @@ void refreshDisplay()
register uint32_t x;
register uint32_t z;
register uint32_t ebit;
#ifdef REVB
#else
#ifndef REVB
register uint8_t *lookup;
lookup = (uint8_t *) Lcd_lookup;
#endif
ebit = LCD_E;
#ifdef REVB
@@ -797,6 +807,10 @@ void refreshDisplay()
pioptr->PIO_OER = 0x00000080;// Set bit 7 output
#endif
// read the inputs, and lock the LCD lines
lcdInputs = PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
lcdLock = 1 ;
pioptr = PIOC;
#ifdef REVB
pioptr->PIO_OER = 0x0C0030FFL; // Set bits 27,26,15,13,12,7-0 output
@@ -855,7 +869,9 @@ void refreshDisplay()
pioptr->PIO_PUER = 0x0000003CL ; // Set bits 2, 3, 4, 5 with pullups
pioptr->PIO_ODR = 0x0000003CL ; // Set bits 2, 3, 4, 5 input
#endif
pioptr->PIO_ODSR = 0xFE ; // Drive D0 low
pioptr->PIO_ODSR = lcdInputs; // Drive D0 low
lcdLock = 0;
}
#endif
+6 -1
View File
@@ -79,7 +79,12 @@
#define TWO_DOTS LEFT
extern uint8_t displayBuf[DISPLAY_W*DISPLAY_H/8];
extern uint8_t lcd_lastPos;
extern uint8_t lcdLastPos;
#if defined(PCBARM)
extern uint8_t lcdLock ;
extern uint8_t lcdInputs ;
#endif
extern void lcd_putc(uint8_t x,uint8_t y,const unsigned char c);
extern void lcd_putcAtt(uint8_t x,uint8_t y,const unsigned char c,uint8_t mode);
+1 -1
View File
@@ -298,7 +298,7 @@ bool check(uint8_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTa
}
#endif
DISPLAY_PROGRESS_BAR(menuTab ? lcd_lastPos-2*FW-((curr+1)/10*FWNUM)-2 : 20*FW+1);
DISPLAY_PROGRESS_BAR(menuTab ? lcdLastPos-2*FW-((curr+1)/10*FWNUM)-2 : 20*FW+1);
if (s_editMode<=0) {
if (scrollUD) {
+4 -4
View File
@@ -1516,7 +1516,7 @@ void menuProcMixOne(uint8_t event)
{
TITLEP(s_currCh ? STR_INSERTMIX : STR_EDITMIX);
MixData *md2 = mixaddress(s_currIdx) ;
putsChn(lcd_lastPos+1*FW,0,md2->destCh+1,0);
putsChn(lcdLastPos+1*FW,0,md2->destCh+1,0);
SIMPLE_SUBMENU_NOTITLE(MIX_FIELD_COUNT);
int8_t sub = m_posVert;
@@ -1647,8 +1647,8 @@ void menuProcExpoMix(uint8_t expo, uint8_t _event_)
}
TITLEP(expo ? STR_MENUDREXPO : STR_MIXER);
lcd_outdezAtt(lcd_lastPos+2*FW+FW/2, 0, getExpoMixCount(expo));
lcd_puts(lcd_lastPos, 0, expo ? STR_MAX(MAX_EXPOS) : STR_MAX(MAX_MIXERS));
lcd_outdezAtt(lcdLastPos+2*FW+FW/2, 0, getExpoMixCount(expo));
lcd_puts(lcdLastPos, 0, expo ? STR_MAX(MAX_EXPOS) : STR_MAX(MAX_MIXERS));
SIMPLE_MENU_NOTITLE(menuTabModel, expo ? e_ExposAll : e_MixAll, s_maxLines);
#if defined(ROTARY_ENCODERS)
@@ -2392,7 +2392,7 @@ void menuProcTelemetry(uint8_t event)
case ITEM_TELEMETRY_A2_RANGE:
lcd_puts(4, y, STR_RANGE);
putsTelemetryChannel(TELEM_COL2, y, ch+MAX_TIMERS, 255-channel.offset, ((attr && m_posHorz==0) ? blink : 0)|NO_UNIT|LEFT);
lcd_putsiAtt(lcd_lastPos, y, STR_VTELEMUNIT, channel.type, (attr && m_posHorz==1 ? blink : 0));
lcd_putsiAtt(lcdLastPos, y, STR_VTELEMUNIT, channel.type, (attr && m_posHorz==1 ? blink : 0));
if (attr && (s_editMode>0 || p1valdiff)) {
if (m_posHorz == 0) {
uint16_t ratio = checkIncDec(event, channel.ratio, 0, 256, EE_MODEL);
+150 -60
View File
@@ -31,6 +31,27 @@
*
*/
#if defined(PCBARM)
extern "C" {
#include <CoOS.h>
}
#define MIXER_STACK_SIZE 300
#define MENUS_STACK_SIZE 300
#define BT_STACK_SIZE 100
OS_TID mixerTaskId;
OS_STK mixerStack[MIXER_STACK_SIZE];
OS_TID menusTaskId;
OS_STK menusStack[MENUS_STACK_SIZE];
/*OS_TID btTask;
OS_STK btStack[BT_STACK_SIZE];
OS_TCID btTimer;
OS_FlagID btFlag;*/
#endif
#include "open9x.h"
#if defined(SPLASH)
@@ -763,7 +784,7 @@ void putsTelemetryValue(uint8_t x, uint8_t y, int16_t val, uint8_t unit, uint8_t
#endif
lcd_outdezAtt(x, (att & DBLSIZE ? y - FH : y), val, att & (~NO_UNIT)); // TODO we could add this test inside lcd_outdezAtt!
if (~att & NO_UNIT && unit != UNIT_RAW)
lcd_putsiAtt(lcd_lastPos/*+1*/, y, STR_VTELEMUNIT, unit, 0);
lcd_putsiAtt(lcdLastPos/*+1*/, y, STR_VTELEMUNIT, unit, 0);
}
#endif
@@ -1004,19 +1025,19 @@ void message(const pm_char *title, const pm_char *t, const char *last)
clearKeyEvents();
}
#if defined(PCBV4)
#if defined(PCBSTD)
uint8_t checkTrim(uint8_t event)
{
int8_t k = (event & EVT_KEY_MASK) - TRM_BASE;
int8_t s = g_model.trimInc;
if (k>=0 && k<8) {
#else
void checkTrims()
{
uint8_t event = getEvent(true);
if (event) {
int8_t k = (event & EVT_KEY_MASK) - TRM_BASE;
int8_t s = g_model.trimInc;
#else
uint8_t checkTrim(uint8_t event)
{
int8_t k = (event & EVT_KEY_MASK) - TRM_BASE;
int8_t s = g_model.trimInc;
if (k>=0 && k<8) {
#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;
@@ -1072,11 +1093,11 @@ uint8_t checkTrim(uint8_t event)
AUDIO_TRIM();
#endif
}
#if !defined(PCBV4)
#if defined(PCBSTD)
return 0;
#endif
}
#if !defined(PCBV4)
#if defined(PCBSTD)
return event;
#endif
}
@@ -1319,9 +1340,11 @@ static uint16_t s_sum[2] = {0, 0};
static uint8_t sw_toggled[2] = {false, false};
static uint16_t s_time_cum_16[2] = {0, 0};
#if defined(THRTRACE)
uint8_t s_traceBuf[MAXTRACE];
uint8_t s_traceWr;
int8_t s_traceCnt;
#endif
#if defined(HELI) || defined(FRSKY_HUB)
uint16_t isqrt32(uint32_t n)
@@ -2051,11 +2074,13 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms)
val /= (RESX/16); // calibrate it
static uint16_t s_time_tot;
static uint16_t s_time_trace;
static uint8_t s_cnt_1s;
static uint16_t s_sum_1s;
#if defined(THRTRACE)
static uint16_t s_time_trace;
static uint16_t s_cnt_10s;
static uint16_t s_sum_10s;
#endif
s_cnt_1s++;
s_sum_1s += val;
@@ -2068,10 +2093,9 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms)
s_timeCum16ThrP += val / 2;
if (val) s_timeCumThr += 1;
#if defined(THRTRACE)
s_cnt_10s += s_cnt_1s;
s_sum_10s += s_sum_1s;
s_cnt_1s = 0;
s_sum_1s = 0;
if ((uint16_t)(tmr10ms - s_time_trace) >= 1000) {// 10sec
s_time_trace += 1000;
@@ -2083,6 +2107,10 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms)
if (s_traceWr >= MAXTRACE) s_traceWr = 0;
if (s_traceCnt >= 0) s_traceCnt++; // TODO to be checked
}
#endif
s_cnt_1s = 0;
s_sum_1s = 0;
}
// Timers start
@@ -2218,7 +2246,7 @@ void perMain()
uint8_t tick10ms = (tmr10ms - lastTMR);
lastTMR = tmr10ms;
#if !defined(PCBV4) || defined(SIMU)
#if defined(PCBSTD) || defined(SIMU)
doMixerCalculations(tmr10ms, tick10ms);
#endif
@@ -2289,11 +2317,11 @@ void perMain()
lcd_clear();
#if defined(PCBV4)
uint8_t evt = getEvent(false);
#else
#if defined(PCBSTD)
uint8_t evt = getEvent();
evt = checkTrim(evt);
#else
uint8_t evt = getEvent(false);
#endif
// TODO port lightOnStickMove from er9x + flash saving, call checkBacklight()
@@ -2337,10 +2365,17 @@ void perMain()
}
#endif
#if defined(PCBARM)
static uint8_t counter = 0;
if (counter-- == 0) {
counter = 10;
#else
switch( tmr10ms & 0x1f ) { //alle 10ms*32
case 2:
{
{
#endif
#if defined(PCBARM)
int32_t instant_vbat = anaIn(7);
instant_vbat = ( instant_vbat + instant_vbat*(g_eeGeneral.vBatCalib)/128 ) * 4191 ;
@@ -2366,8 +2401,10 @@ void perMain()
AUDIO_ERROR(); // TODO AUDIO_TX_BATTERY_LOW()
}
}
#if !defined(PCBARM)
}
break;
#endif
}
}
@@ -2486,7 +2523,7 @@ ISR(TIMER0_COMP_vect, ISR_NOBLOCK) //10ms timer
#endif
#if !defined(PCBV4)
heartbeat |= HEART_TIMER10ms;
heartbeat |= HEART_TIMER10ms; // TODO check heartbeat everywhere!
#endif
@@ -2748,6 +2785,78 @@ uint16_t stack_free()
#endif
#if defined(PCBARM)
void mixerTask(void * pdata)
{
while(1) {
uint16_t t0 = getTmr2MHz();
static uint16_t lastTMR;
uint16_t tmr10ms = get_tmr10ms();
uint8_t tick10ms = (tmr10ms - lastTMR);
lastTMR = tmr10ms;
if (s_current_protocol < PROTO_NONE) {
checkTrims();
doMixerCalculations(tmr10ms, tick10ms);
}
heartbeat |= HEART_TIMER10ms;
if (heartbeat == HEART_TIMER_PULSES+HEART_TIMER10ms) {
wdt_reset();
heartbeat = 0;
}
t0 = getTmr2MHz() - t0;
if (t0 > g_timeMainMax) g_timeMainMax = t0 ;
CoTickDelay(1); // 2ms for now
}
}
void menusTask(void * pdata)
{
register uint32_t shutdown_state = 0;
while ((shutdown_state=check_soft_power()) <= e_power_trainer) {
perMain();
CoTickDelay(5); // 10ms for now
}
SysTick->CTRL = 0; // turn off systick
#if defined(HAPTIC)
hapticOff();
#endif
lcd_clear() ;
displayPopup(STR_SHUTDOWN);
g_eeGeneral.unexpectedShutdown=0;
eeDirty(EE_GENERAL);
eeCheck(true);
#if defined(SDCARD) && !defined(PCBARM)
closeLogs();
#endif
lcd_clear() ;
refreshDisplay() ;
soft_power_off(); // Only turn power off if necessary
if (shutdown_state == e_power_usb) {
lcd_putcAtt( 48, 24, 'U', DBLSIZE ) ;
lcd_putcAtt( 60, 24, 'S', DBLSIZE ) ;
lcd_putcAtt( 72, 24, 'B', DBLSIZE ) ;
refreshDisplay() ;
usb_mode();
}
lcdSetRefVolt(0); // TODO before soft_power_off?
}
#endif
int main(void)
{
// The WDT remains active after a WDT reset -- at maximum clock speed. So it's
@@ -2872,7 +2981,6 @@ int main(void)
if(cModel!=g_eeGeneral.currModel) eeDirty(EE_GENERAL); // if model was quick-selected, make sure it sticks
#if defined(PCBARM)
start_ppm_capture();
// TODO inside startPulses?
@@ -2885,80 +2993,62 @@ int main(void)
}
#if defined(PCBARM)
register uint32_t shutdown_state = 0;
#elif defined(PCBV4)
CoInitOS();
// btFlag = CoCreateFlag(TRUE, FALSE); // Auto-reset, start FALSE
// btTimer = CoCreateTmr(TMR_TYPE_PERIODIC, 1000/(1000/CFG_SYSTICK_FREQ), 1000/(1000/CFG_SYSTICK_FREQ), btTimerHandle);
// btTaskId = CoCreateTask(btTask, NULL, 19, &btStack[BT_STACK_SIZE-1], BT_STACK_SIZE);
menusTaskId = CoCreateTask(menusTask, NULL, 10, &menusStack[MENUS_STACK_SIZE-1], MENUS_STACK_SIZE);
mixerTaskId = CoCreateTask(mixerTask, NULL, 5, &mixerStack[MIXER_STACK_SIZE-1], MIXER_STACK_SIZE);
CoStartOS();
#else
#if defined(PCBV4)
uint8_t shutdown_state = 0;
#endif
while(1) {
#if defined(PCBARM) || defined(PCBV4)
#if defined(PCBV4)
if ((shutdown_state=check_soft_power()) > e_power_trainer)
break;
#endif
#if defined(PCBARM)
uint16_t t0 = getTmr2MHz();
#elif defined(PCBSTD)
#if defined(PCBSTD)
uint16_t t0 = getTmr16KHz();
#endif
perMain();
#if !defined(PCBV4)
#if defined(PCBSTD)
if(heartbeat == 0x3)
{
wdt_reset();
heartbeat = 0;
}
#if defined(PCBARM)
t0 = getTmr2MHz() - t0;
#else
t0 = getTmr16KHz() - t0;
if (t0 > g_timeMainMax) g_timeMainMax = t0;
#endif
if (t0 > g_timeMainMax) g_timeMainMax = t0 ;
#endif
}
#endif // PCBARM
#if defined(PCBARM) || defined(PCBV4)
#if defined(PCBV4)
// Time to switch off
lcd_clear() ;
displayPopup(STR_SHUTDOWN);
g_eeGeneral.unexpectedShutdown=0;
eeDirty(EE_GENERAL);
eeCheck(true);
#if defined(SDCARD) && !defined(PCBARM)
#if defined(SDCARD)
closeLogs();
#endif
lcd_clear() ;
refreshDisplay() ;
soft_power_off(); // Only turn power off if necessary
#endif
#if defined(PCBARM)
if (shutdown_state == e_power_usb) {
lcd_putcAtt( 48, 24, 'U', DBLSIZE ) ;
lcd_putcAtt( 60, 24, 'S', DBLSIZE ) ;
lcd_putcAtt( 72, 24, 'B', DBLSIZE ) ;
refreshDisplay() ;
#if defined(HAPTIC)
hapticOff();
#endif
/* end force haptic to be disabled in this mode */
usb_mode();
}
#endif
#if defined(PCBARM) || defined(PCBV4)
lcdSetRefVolt(0); // TODO before soft_power_off?
#endif
#if defined(PCBV4)
//never return from main() - there is no code to return back, if any daelays occurs in physical power it does dead loop.
wdt_disable();
for(;;){}
while(1); // never return from main() - there is no code to return back, if any delays occurs in physical power it does dead loop.
#endif
}
#endif
#endif // !SIMU
+5 -3
View File
@@ -484,10 +484,10 @@ extern char idx2char(int8_t idx);
void clearKeyEvents();
void pauseEvents(uint8_t enuk);
void killEvents(uint8_t enuk);
#if defined(PCBV4)
uint8_t getEvent(bool trim);
#else
#if defined(PCBSTD)
uint8_t getEvent();
#else
uint8_t getEvent(bool trim);
#endif
void putEvent(uint8_t evt);
@@ -574,10 +574,12 @@ extern uint16_t g_timeMainMax;
extern uint8_t g_timeMainLast;
#endif
#if defined(THRTRACE)
#define MAXTRACE 120
extern uint8_t s_traceBuf[MAXTRACE];
extern uint8_t s_traceWr;
extern int8_t s_traceCnt;
#endif
extern int8_t *s_trimPtr[NUM_STICKS];
+2
View File
@@ -58,6 +58,7 @@ void menuProcStatistic(uint8_t event)
lcd_puts( 17*FW, FH*0, STR_TOT);
putsTime( 12*FW, FH*0, s_timeCumTot, 0, 0);
#if defined(THRTRACE)
uint8_t traceRd = (s_traceCnt < 0 ? s_traceWr : 0);
const uint8_t x=5;
const uint8_t y=60;
@@ -75,6 +76,7 @@ void menuProcStatistic(uint8_t event)
if(traceRd>=MAXTRACE) traceRd=0;
if(traceRd==s_traceWr) break;
}
#endif
}
#define MENU_DEBUG_COL_OFS (14*FW)