Mercurial > public > ostc4
changeset 148:ee744c7160ce FlipDisplay
Use SPI TX callback to synchronize to main CPU
author | Ideenmodellierer |
---|---|
date | Sat, 02 Mar 2019 17:01:06 +0100 |
parents | 14e4c83a7559 |
children | e1d66bc78f9a |
files | Small_CPU/Inc/scheduler.h Small_CPU/Src/baseCPU2.c Small_CPU/Src/scheduler.c Small_CPU/Src/spi.c |
diffstat | 4 files changed, 16 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/Small_CPU/Inc/scheduler.h Sat Mar 02 16:57:59 2019 +0100 +++ b/Small_CPU/Inc/scheduler.h Sat Mar 02 17:01:06 2019 +0100 @@ -88,6 +88,7 @@ /* Variables ---------------------------------------------------------*/ extern SGlobal global; +extern uint8_t dohardspisync; /* Function prototypes -----------------------------------------------*/
--- a/Small_CPU/Src/baseCPU2.c Sat Mar 02 16:57:59 2019 +0100 +++ b/Small_CPU/Src/baseCPU2.c Sat Mar 02 17:01:06 2019 +0100 @@ -164,7 +164,7 @@ // See CPU2-RTE.ld const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") ))= { .versionFirst = 1, - .versionSecond = 6, + .versionSecond = 7, .versionThird = 0, .versionBeta = 0, @@ -384,6 +384,7 @@ MX_SPI1_Init(); MX_EXTI_wireless_Init(); SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ + dohardspisync = 1; EXTI_Test_Button_Init(); /* @@ -479,11 +480,11 @@ compass_init(0, 7); accelerator_init(); wireless_init(); -// SPI_synchronize_with_Master(); TODO: REMOVE + SPI_synchronize_with_Master(); MX_DMA_Init(); MX_SPI1_Init(); MX_EXTI_wireless_Init(); -// SPI_Start_single_TxRx_with_Master(); + SPI_Start_single_TxRx_with_Master(); // EXTILine0_Button_DeInit(); not now, later after testing break;
--- a/Small_CPU/Src/scheduler.c Sat Mar 02 16:57:59 2019 +0100 +++ b/Small_CPU/Src/scheduler.c Sat Mar 02 17:01:06 2019 +0100 @@ -58,6 +58,7 @@ SDevice DeviceDataFlash; uint8_t deviceDataFlashValid = 0; uint8_t deviceDataSubSeconds = 0; +uint8_t dohardspisync = 1; /* Private variables ---------------------------------------------------------*/ /* can be lost while in sleep */ @@ -181,6 +182,8 @@ global.deviceData.temperatureMaximum.value_int32 = INT32_MIN; global.deviceData.temperatureMinimum.value_int32 = INT32_MAX; global.deviceData.voltageMinimum.value_int32 = INT32_MAX; + + dohardspisync = 1; } @@ -430,7 +433,7 @@ void schedule_check_resync(void) { //TODO: REMOVE - if((global.check_sync_not_running >= 2)) + if((global.check_sync_not_running >= 3)) { // global.dataSendToSlaveIsNotValidCount = 0; global.check_sync_not_running = 0; @@ -904,7 +907,6 @@ } } } -static uint8_t dohardspisync = 1; void HardSyncToSPI() {
--- a/Small_CPU/Src/spi.c Sat Mar 02 16:57:59 2019 +0100 +++ b/Small_CPU/Src/spi.c Sat Mar 02 17:01:06 2019 +0100 @@ -137,7 +137,7 @@ hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.NSS = SPI_NSS_HARD_INPUT; //SPI_NSS_SOFT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi1.Init.TIMode = SPI_TIMODE_DISABLED; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; //_DISABLED; _ENABLED; @@ -154,6 +154,7 @@ GPIO_InitTypeDef GPIO_InitStruct; if (hspi->Instance == SPI1) { + SPIDataRX = 0; // Peripheral clock enable __SPI1_CLK_ENABLE(); __GPIOA_CLK_ENABLE(); @@ -280,9 +281,9 @@ } void SPI_synchronize_with_Master(void) { +#ifdef USE_OLD_SYNC_METHOD GPIO_InitTypeDef GPIO_InitStruct; // -#if 0 __GPIOA_CLK_ENABLE(); /**SPI1 GPIO Configuration PA5 ------> SPI1_SCK @@ -290,14 +291,14 @@ GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; + GPIO_InitStruct.Speed = GPIO_SPEED_FAST; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // HAL_Delay(10); while (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) == 0); HAL_Delay(10); while (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_5) == 1); - HAL_Delay(20); + HAL_Delay(50); #endif } @@ -321,6 +322,7 @@ /* restart SPI */ if (hspi == &hspi1) { + HardSyncToSPI(); SPIDataRX = 1; global.check_sync_not_running = 0; @@ -330,7 +332,6 @@ global.dataSendToSlavePending = 0; global.dataSendToSlaveIsValid = 1; global.dataSendToSlaveIsNotValidCount = 0; - return; } } } @@ -351,13 +352,11 @@ HAL_SPI_Abort_IT(&hspi1); global.dataSendToMaster.header.checkCode[SPI_HEADER_INDEX_SLAVE] = global.dataSendToSlave.header.checkCode[SPI_HEADER_INDEX_MASTER]; global.dataSendToSlave.header.checkCode[SPI_HEADER_INDEX_SLAVE] = 0; - return; } else { global.dataSendToMaster.header.checkCode[SPI_HEADER_INDEX_SLAVE] = global.dataSendToSlave.header.checkCode[SPI_HEADER_INDEX_MASTER]; } - HardSyncToSPI(); } else { // GPIO_new_DEBUG_LOW(); //For debug. global.dataSendToSlaveIsValid = 0; @@ -387,7 +386,7 @@ static uint8_t SPI_check_header_and_footer_ok(void) { if (global.dataSendToSlave.header.checkCode[0] != 0xBB) return 0; -#if USE_OLD_HEADER_FORMAT +#ifdef USE_OLD_HEADER_FORMAT if (global.dataSendToSlave.header.checkCode[1] != 0x01) return 0; if (global.dataSendToSlave.header.checkCode[2] != 0x01)