changes in IRQ priorities and names of functions defined for dallas ds12b20

pull/2/head
Mateusz Lubecki 2019-01-27 13:14:36 +01:00
rodzic 02274ad9a2
commit 5ce7f8fcc8
10 zmienionych plików z 92 dodań i 47 usunięć

Wyświetl plik

@ -0,0 +1,14 @@
/*
* it_handlers.h
*
* Created on: 27.01.2019
* Author: mateusz
*/
#ifndef IT_HANDLERS_H_
#define IT_HANDLERS_H_
void it_handlers_set_priorities(void);
#endif /* IT_HANDLERS_H_ */

Wyświetl plik

@ -19,7 +19,7 @@ void TimerConfig(void) {
///////////////////////////////////////////
/// konfiguracja TIM2 -- dallas delay ///
///////////////////////////////////////////
NVIC_SetPriority(TIM2_IRQn, 1);
//NVIC_SetPriority(TIM2_IRQn, 1);
TIM2->PSC = 0;
TIM2->ARR = 119;
TIM2->CR1 |= TIM_CR1_DIR;
@ -31,7 +31,7 @@ void TimerConfig(void) {
// //////////////////////////////
// //// konfiguracja TIM4 -- dac ///
// //////////////////////////////
NVIC_SetPriority(TIM4_IRQn, 2);
//NVIC_SetPriority(TIM4_IRQn, 2);
TIM4->PSC = 0;
TIM4->ARR = 2499;
TIM4->CR1 |= TIM_CR1_DIR;
@ -42,7 +42,7 @@ void TimerConfig(void) {
///////////////////////////////////////////
/// konfiguracja TIM7 --adc ///
///////////////////////////////////////////
NVIC_SetPriority(TIM7_IRQn, 3);
//NVIC_SetPriority(TIM7_IRQn, 3);
TIM7->PSC = 0;
TIM7->ARR = 624; /// 2499
TIM7->CR1 |= TIM_CR1_DIR;

Wyświetl plik

@ -23,6 +23,22 @@
#include "station_config.h"
/*
* INTERRUPT PRIORITIES
*
* TIM2_IRQHandler - 1 -> Dallas delay (enable only during dallas comm)
* I2C1_EV_IRQHandler - 2 -> I2C comm interrupt (active & enable only during communication with i2c sensor)
* TIM4_IRQHandler - 3 -> APRS softmodem DAC (enable only during tx)
* TIM7_IRQHandler - 4 -> APRS softmodem ADC
* SysTick_Handler - 5
* TIM1_UP_TIM16_IRQHandler - 6 -> TX20 baudrate timer
* EXTI9_5_IRQHandler - 7 -> TX20 anemometer GPIO
* EXTI4_IRQHandler - 8 -> DHT22 sensor GPIO interrupt
* USART1_IRQHandler - 9 -> uart to comm with KISS host
* I2C1_ER_IRQHandler - 10 -> I2C error interrupt
*
*/
// TIM1 w TX20
@ -31,6 +47,21 @@ char adc_sample_count = 0, adc_sample_c2 = 0; // Zmienna odliczająca próbki
unsigned short int AdcBuffer[4]; // Bufor przechowujący kolejne wartości rejestru DR
short int AdcValue;
// this function will set all iterrupt priorities except systick
void it_handlers_set_priorities(void) {
NVIC_SetPriority(TIM2_IRQn, 1);
NVIC_SetPriority(I2C1_EV_IRQn, 2);
NVIC_SetPriority(TIM4_IRQn, 3);
NVIC_SetPriority(TIM7_IRQn, 4);
// systick
NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 6);
NVIC_SetPriority(EXTI9_5_IRQn, 7);
NVIC_SetPriority(EXTI4_IRQn, 8);
NVIC_SetPriority(USART1_IRQn, 9);
NVIC_SetPriority(I2C1_ER_IRQn, 10);
}
// Systick interrupt used for time measurements, checking timeouts and SysTick_Handler
void SysTick_Handler(void) {
@ -76,14 +107,6 @@ void TIM2_IRQHandler( void ) {
}
/*
void TIM3_IRQHandler(void) {
// wysylanie wlasnej pozycji i danych WX
TIM3->SR &= ~(1<<0);
}
*/
void TIM4_IRQHandler( void ) {
// obsluga przerwania cyfra-analog
TIM4->SR &= ~(1<<0);

Wyświetl plik

@ -110,6 +110,9 @@ main(int argc, char* argv[])
// Configuring the SysTick timer to generate interrupt 100x per second (one interrupt = 10ms)
SysTick_Config(SystemCoreClock / SYSTICK_TICKS_PER_SECONDS);
// setting an Systick interrupt priority
NVIC_SetPriority(SysTick_IRQn, 5);
#if defined _RANDOM_DELAY
// configuring a default delay value
delay_set(_DELAY_BASE, 1);
@ -131,16 +134,19 @@ main(int argc, char* argv[])
#ifdef _METEO
dht22_init();
DallasInit(GPIOC, GPIO_Pin_6, GPIO_PinSource6);
dallas_init(GPIOC, GPIO_Pin_6, GPIO_PinSource6);
TX20Init();
#endif
#ifdef _DALLAS_AS_TELEM
DallasInit(GPIOC, GPIO_Pin_6, GPIO_PinSource6);
dallas_init(GPIOC, GPIO_Pin_6, GPIO_PinSource6);
#endif
// initializing UART drvier
srl_init();
// configuring interrupt priorities
it_handlers_set_priorities();
#ifdef _METEO
ms5611_reset(&rte_wx_ms5611_qf);
ms5611_read_calibration(SensorCalData, &rte_wx_ms5611_qf);

Wyświetl plik

@ -18,7 +18,7 @@ void wx_get_all_measurements(void) {
#if defined _METEO || defined _DALLAS_AS_TELEM
// quering dallas DS12B20 thermometer for current temperature
rte_wx_temperature_dallas = DallasQuery(&rte_wx_dallas_qf);
rte_wx_temperature_dallas = dallas_query(&rte_wx_dallas_qf);
// checking if communication was successfull
if (rte_wx_temperature_dallas != -128.0f)

Wyświetl plik

@ -37,14 +37,14 @@ typedef enum DallasQF {
DALLAS_QF_NOT_AVALIABLE
}DallasQF;
void DallasInit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t GPIO_PinSource);
void DallasConfigTimer(void);
void DallasDeConfigTimer(void);
char DallasReset(void);
float DallasQuery(DallasQF *qf);
void DallasSendByte(char data);
char DallasReceiveByte(void);
uint8_t CalculateCRC8(uint8_t *addr, uint8_t len);
void dallas_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t GPIO_PinSource);
void dallas_config_timer(void);
void dallas_deconfig_timer(void);
char dallas_reset(void);
float dallas_query(DallasQF *qf);
void dallas_send_byte(char data);
char dallas_receive_byte(void);
uint8_t dallas_calculate_crc8(uint8_t *addr, uint8_t len);

Wyświetl plik

@ -66,7 +66,7 @@ void dht22_comm(dht22Values *in) {
GPIO_Init(DHT22_PIN_PORT,&PORT_out);
GPIO_SetBits(DHT22_PIN_PORT, DHT22_PIN_PIN);
DallasConfigTimer();
dallas_config_timer();
/*
* Setting pin logic-low to initialize transfer.
@ -85,7 +85,7 @@ void dht22_comm(dht22Values *in) {
uint8_t sensorResp = GPIO_ReadInputDataBit(DHT22_PIN_PORT, DHT22_PIN_PIN);
if (sensorResp == Bit_SET) {
dht22State = DHT22_STATE_TIMEOUT;
DallasDeConfigTimer();
dallas_deconfig_timer();
if (in != 0x00)
in->qf = DHT22_QF_UNAVALIABLE;
return; // if pin is still high it usually means that there is a problem with comm with the sensor
@ -152,7 +152,7 @@ void dht22_timeout_keeper(void) {
if (delay_5us == 0) {
dht22_init();
EXTI_Init(&exti_disable);
DallasDeConfigTimer();
dallas_deconfig_timer();
dht22State = DHT22_STATE_TIMEOUT;
}
}
@ -171,7 +171,7 @@ void dht22_irq_handler(void) {
GPIO_Init(DHT22_PIN_PORT,&PORT_out);
GPIO_SetBits(DHT22_PIN_PORT, DHT22_PIN_PIN);
dht22State = DHT22_STATE_DATA_RDY;
DallasDeConfigTimer();
dallas_deconfig_timer();
}
}

Wyświetl plik

@ -18,7 +18,7 @@ volatile char timm = 0;
DallasStruct dallas;
void DallasInit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t GPIO_PinSource) {
void dallas_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t GPIO_PinSource) {
// GPIO_output.GPIO_Mode = GPIO_Mode_Out_OD;
// GPIO_output.GPIO_Pin = GPIO_Pin;
// GPIO_output.GPIO_Speed = GPIO_Speed_50MHz;
@ -41,7 +41,7 @@ void DallasInit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t GPIO_PinSource)
}
void DallasConfigTimer(void) {
void dallas_config_timer(void) {
// Disabling any time-consuming iterrupts
NVIC_DisableIRQ( TIM3_IRQn ); // data transmission initializer
NVIC_DisableIRQ( TIM4_IRQn ); // data transmission initializer
@ -59,7 +59,7 @@ void DallasConfigTimer(void) {
//timm = 1;
}
void DallasDeConfigTimer(void) {
void dallas_deconfig_timer(void) {
TIM2->CR1 &= (0xFFFFFFFF ^ TIM_CR1_CEN); // disabling timer
NVIC_EnableIRQ( TIM3_IRQn ); // adc
@ -78,7 +78,7 @@ void DallasDeConfigTimer(void) {
//timm = 0;
}
char DallasReset(void) {
char dallas_reset(void) {
// PULLING LINE LOW
dallas.GPIOx->CRL &= dallas.clear_term;
dallas.GPIOx->CRL |= dallas.output_term;
@ -105,7 +105,7 @@ char DallasReset(void) {
return 0;
}
void __attribute__((optimize("O0"))) DallasSendByte(char data) {
void __attribute__((optimize("O0"))) dallas_send_byte(char data) {
char i;
for (i = 0; i < 8; i++) {
// PULLING LINE LOW
@ -123,7 +123,7 @@ void __attribute__((optimize("O0"))) DallasSendByte(char data) {
}
}
char __attribute__((optimize("O0"))) DallasReceiveByte(void) {
char __attribute__((optimize("O0"))) dallas_receive_byte(void) {
char data = 0, i;
for (i = 0; i < 8; i++) {
@ -155,7 +155,7 @@ char __attribute__((optimize("O0"))) DallasReceiveByte(void) {
return data;
}
float __attribute__((optimize("O0"))) DallasQuery(DallasQF *qf) {
float __attribute__((optimize("O0"))) dallas_query(DallasQF *qf) {
unsigned char data[9];
int crc;
char temp1, temp2, sign, i;
@ -163,24 +163,24 @@ float __attribute__((optimize("O0"))) DallasQuery(DallasQF *qf) {
float temperature = 0.0f;
// ENABLE ONEWIRE DELAY TIMER
DallasConfigTimer();
dallas_config_timer();
memset(data, 0x00, 9);
DallasReset();
DallasSendByte(0xCC); // ROM skip
DallasSendByte(0x44); // Temperature conversion
dallas_reset();
dallas_send_byte(0xCC); // ROM skip
dallas_send_byte(0x44); // Temperature conversion
delay_5us = 190000; // 800msec delay for conversion
while (delay_5us != 0);
DallasReset();
DallasSendByte(0xCC);
DallasSendByte(0xBE); // read scratchpad
dallas_reset();
dallas_send_byte(0xCC);
dallas_send_byte(0xBE); // read scratchpad
for (i = 0; i <= 8; i++)
data[i] = DallasReceiveByte();
data[i] = dallas_receive_byte();
// DISABLE ONEWIRE DELAY TIMER
DallasDeConfigTimer();
dallas_deconfig_timer();
crc = CalculateCRC8(data, 8);
crc = dallas_calculate_crc8(data, 8);
if ((data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x00 && data[3] == 0x00 && data[4] == 0x00 && data[5] == 0x00 && data[6] == 0x00) ||
(data[0] == 0xFF && data[1] == 0xFF && data[2] == 0xFF && data[3] == 0xFF && data[4] == 0xFF && data[5] == 0xFF && data[6] == 0xFF))
@ -214,7 +214,7 @@ float __attribute__((optimize("O0"))) DallasQuery(DallasQF *qf) {
}
uint8_t CalculateCRC8(uint8_t *addr, uint8_t len) {
uint8_t dallas_calculate_crc8(uint8_t *addr, uint8_t len) {
uint8_t crc = 0, inbyte, i, mix;
while (len--) {

Wyświetl plik

@ -86,7 +86,7 @@ void srl_init(void) {
USART_Init(PORT, &USART_InitStructure);
NVIC_EnableIRQ( USART1_IRQn );
NVIC_SetPriority(USART1_IRQn, 9); /// bylo 10
//NVIC_SetPriority(USART1_IRQn, 9); /// bylo 10
PORT->CR1 |= USART_CR1_UE;
// PORT->BRR |= srlBRRegValue; // ustawianie wartoœci preskalera do baudrate

Wyświetl plik

@ -113,8 +113,8 @@ void TX20Batch(void) {
else
OE++;
DCD = 0, BQ = 0, RD = 1, FC = 0, QL = 0, BS = 0;
TIMER->CR1 &= (0xFFFFFFFF ^ TIM_CR1_CEN);
TIMER->CNT = 0;
TIMER->CR1 &= (0xFFFFFFFF ^ TIM_CR1_CEN); // disabling baudrate timer after receiving whole frame
TIMER->CNT = 0; // resetting timer counter back to zero
}
else
FC++;
@ -225,6 +225,8 @@ void EXTI4_IRQHandler(void) {
void EXTI9_5_IRQHandler(void) {
EXTI->PR |= EXTI_PR_PR0 << TX;
// TIMER is disabled after each complete frame, so it needs to be started once again
// when start bit (an endge at the begining of next frame from anemometer) is received
if ((TIMER->CR1 & TIM_CR1_CEN) == 0 )
TIMER->CR1 |= TIM_CR1_CEN;
// QL = 0;