[Horus] Refactoring for the new fatal errors

This commit is contained in:
Bertrand Songis
2016-08-31 01:04:11 +02:00
parent 855814655e
commit 82b9ecc155
25 changed files with 165 additions and 75 deletions
+41 -25
View File
@@ -23,13 +23,24 @@
void backlightInit()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = BL_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(BL_GPIO, &GPIO_InitStructure);
GPIO_PinAFConfig(BL_GPIO, BL_GPIO_PinSource, BL_GPIO_AF);
if (IS_HORUS_PROD()) {
GPIO_InitStructure.GPIO_Pin = PROD_BL_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(BL_GPIO, &GPIO_InitStructure);
GPIO_PinAFConfig(BL_GPIO, PROD_BL_GPIO_PinSource, PROD_BL_GPIO_AF);
}
else {
GPIO_InitStructure.GPIO_Pin = BETA_BL_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(BL_GPIO, &GPIO_InitStructure);
GPIO_PinAFConfig(BL_GPIO, BETA_BL_GPIO_PinSource, BETA_BL_GPIO_AF);
}
}
void backlightEnable(uint8_t dutyCycle)
@@ -51,31 +62,36 @@ void backlightEnable(uint8_t dutyCycle)
TIM_TimeBaseStructure.TIM_Period = 100;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(BL_TIMER, &TIM_TimeBaseStructure);
TIM_Cmd(BL_TIMER, DISABLE);
if (IS_HORUS_PROD()) {
TIM_TimeBaseInit(PROD_BL_TIMER, &TIM_TimeBaseStructure);
TIM_Cmd(PROD_BL_TIMER, DISABLE);
}
else {
TIM_TimeBaseInit(BETA_BL_TIMER, &TIM_TimeBaseStructure);
TIM_Cmd(BETA_BL_TIMER, DISABLE);
}
/* PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
#if PCBREV >= 13
TIM_OCInitStructure.TIM_Pulse = dutyCycle;
#else
TIM_OCInitStructure.TIM_Pulse = (100 - dutyCycle);
#endif
if (IS_HORUS_PROD())
TIM_OCInitStructure.TIM_Pulse = dutyCycle;
else
TIM_OCInitStructure.TIM_Pulse = (100 - dutyCycle);
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;
#if PCBREV >= 13
TIM_OC4Init(BL_TIMER, &TIM_OCInitStructure);
#else
TIM_OC1Init(BL_TIMER, &TIM_OCInitStructure);
#endif
TIM_Cmd(BL_TIMER, ENABLE);
TIM_CtrlPWMOutputs(BL_TIMER, ENABLE);
if (IS_HORUS_PROD()) {
TIM_OC4Init(PROD_BL_TIMER, &TIM_OCInitStructure);
TIM_Cmd(PROD_BL_TIMER, ENABLE);
TIM_CtrlPWMOutputs(PROD_BL_TIMER, ENABLE);
}
else {
TIM_OC1Init(BETA_BL_TIMER, &TIM_OCInitStructure);
TIM_Cmd(BETA_BL_TIMER, ENABLE);
TIM_CtrlPWMOutputs(BETA_BL_TIMER, ENABLE);
}
}
+10 -16
View File
@@ -39,20 +39,6 @@ void watchdogInit(unsigned int duration)
IWDG->KR = 0xCCCC; // start
}
void getCPUUniqueID(char * s)
{
#if defined(SIMU)
uint32_t cpu_uid[3] = {0x12345678, 0x55AA55AA, 0x87654321};
#else
uint32_t * cpu_uid = (uint32_t *)0x1FFF7A10;
#endif
char * tmp = strAppendUnsigned(s, cpu_uid[0], 8, 16);
*tmp = ' ';
tmp = strAppendUnsigned(tmp+1, cpu_uid[1], 8, 16);
*tmp = ' ';
strAppendUnsigned(tmp+1, cpu_uid[2], 8, 16);
}
// Start TIMER7 at 2000000Hz
void init2MhzTimer()
{
@@ -116,9 +102,11 @@ void boardInit()
{
#if !defined(SIMU)
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph |
PCBREV_RCC_AHB1Periph |
LED_RCC_AHB1Periph |
LCD_RCC_AHB1Periph |
BL_RCC_AHB1Periph |
SD_RCC_AHB1Periph |
AUDIO_RCC_AHB1Periph |
KEYS_RCC_AHB1Periph_GPIO |
ADC_RCC_AHB1Periph |
@@ -131,9 +119,9 @@ void boardInit()
EXTMODULE_RCC_AHB1Periph |
GPS_RCC_AHB1Periph,
ENABLE);
RCC_APB1PeriphClockCmd(INTERRUPT_5MS_RCC_APB1Periph |
TIMER_2MHz_RCC_APB1Periph |
BL_RCC_APB1Periph |
AUDIO_RCC_APB1Periph |
SERIAL_RCC_APB1Periph |
TELEMETRY_RCC_APB1Periph |
@@ -144,7 +132,6 @@ void boardInit()
GPS_RCC_APB1Periph,
ENABLE);
RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph |
BL_RCC_APB2Periph |
ADC_RCC_APB2Periph |
HAPTIC_RCC_APB2Periph |
INTMODULE_RCC_APB2Periph |
@@ -152,6 +139,13 @@ void boardInit()
ENABLE);
pwrInit();
// must be called after pwrInit() because the PCBREV GPIO is initialized there
if (IS_HORUS_PROD())
RCC_APB1PeriphClockCmd(PROD_BL_RCC_APB1Periph,ENABLE);
else
RCC_APB2PeriphClockCmd(BETA_BL_RCC_APB2Periph,ENABLE);
delaysInit();
// FrSky removed the volume chip in latest board, that's why it doesn't answer!
+10
View File
@@ -95,6 +95,16 @@ void delay_ms(uint32_t ms);
}
#endif
// PCBREV driver
#define IS_HORUS_PROD() GPIO_ReadInputDataBit(PCBREV_GPIO, PCBREV_GPIO_PIN)
#if defined(SIMU)
#define IS_FIRMWARE_COMPATIBLE_WITH_BOARD() true
#elif PCBREV >= 13
#define IS_FIRMWARE_COMPATIBLE_WITH_BOARD() IS_HORUS_PROD()
#else
#define IS_FIRMWARE_COMPATIBLE_WITH_BOARD() (!IS_HORUS_PROD())
#endif
// CPU Unique ID
#define LEN_CPU_UID (3*8+2)
void getCPUUniqueID(char * s);
+19 -15
View File
@@ -138,6 +138,11 @@
#define PWR_ON_GPIO_PIN GPIO_Pin_1 // PJ.01
#define PWR_SWITCH_GPIO_PIN GPIO_Pin_0 // PJ.00
// PCBREV
#define PCBREV_RCC_AHB1Periph RCC_AHB1Periph_GPIOI
#define PCBREV_GPIO GPIOI
#define PCBREV_GPIO_PIN GPIO_Pin_11 // PI.11
// Led
#define LED_RCC_AHB1Periph RCC_AHB1Periph_GPIOI
#define LED_GPIO GPIOI
@@ -201,21 +206,20 @@
// Backlight
#define BL_RCC_AHB1Periph RCC_AHB1Periph_GPIOA
#define BL_GPIO GPIOA
#if PCBREV >= 13
#define BL_TIMER TIM5
#define BL_GPIO_PIN GPIO_Pin_3 // PA.03
#define BL_GPIO_PinSource GPIO_PinSource3
#define BL_RCC_APB1Periph RCC_APB1Periph_TIM5
#define BL_RCC_APB2Periph 0
#define BL_GPIO_AF GPIO_AF_TIM5
#else
#define BL_TIMER TIM8
#define BL_GPIO_PIN GPIO_Pin_5 // PA.05
#define BL_GPIO_PinSource GPIO_PinSource5
#define BL_RCC_APB1Periph 0
#define BL_RCC_APB2Periph RCC_APB2Periph_TIM8
#define BL_GPIO_AF GPIO_AF_TIM8
#endif
// Production board
#define PROD_BL_TIMER TIM5
#define PROD_BL_GPIO_PIN GPIO_Pin_3 // PA.03
#define PROD_BL_GPIO_PinSource GPIO_PinSource3
#define PROD_BL_RCC_APB1Periph RCC_APB1Periph_TIM5
#define PROD_BL_RCC_APB2Periph 0
#define PROD_BL_GPIO_AF GPIO_AF_TIM5
// Beta board
#define BETA_BL_TIMER TIM8
#define BETA_BL_GPIO_PIN GPIO_Pin_5 // PA.05
#define BETA_BL_GPIO_PinSource GPIO_PinSource5
#define BETA_BL_RCC_APB1Periph 0
#define BETA_BL_RCC_APB2Periph RCC_APB2Periph_TIM8
#define BETA_BL_GPIO_AF GPIO_AF_TIM8
// SD
#define SD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA2)
+11 -1
View File
@@ -39,7 +39,6 @@ void pwrInit()
GPIO_Init(AUDIO_SHUTDOWN_GPIO, &GPIO_InitStructure);
// Init Module PWR
// TODO not here
GPIO_ResetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
@@ -50,6 +49,17 @@ void pwrInit()
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure);
// Init PCBREV PIN
GPIO_ResetBits(PCBREV_GPIO, PCBREV_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = PCBREV_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(PCBREV_GPIO, &GPIO_InitStructure);
// Init SD-DETECT PIN
GPIO_ResetBits(SD_PRESENT_GPIO, SD_PRESENT_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = SD_PRESENT_GPIO_PIN;
GPIO_Init(SD_PRESENT_GPIO, &GPIO_InitStructure);
pwrOn();
}
-7
View File
@@ -198,8 +198,6 @@ void SD_LowLevel_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(SD_RCC_AHB1Periph, ENABLE);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_SDIO);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SDIO);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SDIO);
@@ -224,11 +222,6 @@ void SD_LowLevel_Init(void)
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = SD_PRESENT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(SD_PRESENT_GPIO, &GPIO_InitStructure);
/* Enable the SDIO APB2 Clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE);
+2 -9
View File
@@ -45,9 +45,7 @@ uint8_t portb, portc, porth=0, dummyport;
uint16_t dummyport16;
int g_snapshot_idx = 0;
#if !defined(CPUARM)
pthread_t main_thread_pid;
#endif
uint8_t main_thread_running = 0;
char * main_thread_error = NULL;
@@ -337,11 +335,7 @@ void StartSimu(bool tests)
try {
#endif
#if defined(CPUARM)
simuMain();
#else
pthread_create(&main_thread_pid, NULL, &simuMain, NULL);
#endif
pthread_create(&main_thread_pid, NULL, &simuMain, NULL);
#if defined(SIMU_EXCEPTIONS)
}
@@ -357,9 +351,8 @@ void StopSimu()
#if defined(CPUARM)
pthread_join(mixerTaskId, NULL);
pthread_join(menusTaskId, NULL);
#else
pthread_join(main_thread_pid, NULL);
#endif
pthread_join(main_thread_pid, NULL);
}
#if defined(CPUARM)