diff --git a/inc/comm_service.h b/inc/comm_service.h index 46ad4f3..fd1d844 100644 --- a/inc/comm_service.h +++ b/inc/comm_service.h @@ -8,12 +8,12 @@ #ifndef COMM_SERVICE_H_ #define COMM_SERVICE_H_ - #include "usart2_comm.h" +#include "i2c_lcd.h" #include void parser_gprmc(char *); - +void Display_Time_LCD(char *str_to_parse, char *str_to_extract, const uint8_t ofsset); #endif /* COMM_SERVICE_H_ */ diff --git a/inc/dma2_driver.h b/inc/dma2_driver.h new file mode 100644 index 0000000..aec753f --- /dev/null +++ b/inc/dma2_driver.h @@ -0,0 +1,23 @@ +/* + * dma1_driver.h + * + * Created on: Feb 2, 2018 + * Author: abel + */ + +#ifndef DMA2_DRIVER_H_ +#define DMA2_DRIVER_H_ + + +#include "stm32f4xx_dma.h" + +#define DMA2_USART6_STREAM DMA2_Stream2 +#define DMA_RX_BUFFER_SIZE 384 +uint8_t DMA_RX_Buffer[DMA_RX_BUFFER_SIZE]; + +void init_dma2(void); + +void enable_dma2_irq(void); + + +#endif /* DMA2_DRIVER_H_ */ diff --git a/inc/external_int_button.h b/inc/external_int_button.h index f46af1b..eb92a5b 100644 --- a/inc/external_int_button.h +++ b/inc/external_int_button.h @@ -11,8 +11,11 @@ #include "stm32f4xx.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_it.h" +#include "stm32f4xx_exti.h" +#include "stm32f4xx_gpio.h" #include "stm32f4xx_syscfg.h" #include "vector_prio.h" +#include "misc.h" diff --git a/inc/gpio_led.h b/inc/gpio_led.h index e7de324..7b58333 100644 --- a/inc/gpio_led.h +++ b/inc/gpio_led.h @@ -13,6 +13,7 @@ #include "stm32f4xx.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_it.h" +#include "stm32f4xx_gpio.h" diff --git a/inc/inp_capture.h b/inc/inp_capture.h index b6125ca..dc2f2b5 100644 --- a/inc/inp_capture.h +++ b/inc/inp_capture.h @@ -11,7 +11,10 @@ #include "stm32f4xx.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_it.h" +#include "stm32f4xx_tim.h" +#include "stm32f4xx_gpio.h" #include "vector_prio.h" +#include "misc.h" TIM_ICInitTypeDef Tim1_IC_Struct; void init_capture_module(void); diff --git a/inc/main.h b/inc/main.h index 14356a4..2f9b051 100644 --- a/inc/main.h +++ b/inc/main.h @@ -25,7 +25,6 @@ - void initialiseTimer(void); void SysTick_Init(void); void Delay_ms(unsigned long); @@ -35,6 +34,6 @@ void enable_Tim_Interrupts(void); -GPIO_InitTypeDef GPIO_InitDef; +//GPIO_InitTypeDef GPIO_InitDef; #endif /* MAIN_H_ */ diff --git a/inc/timer2_output.h b/inc/timer2_output.h index f1a29ba..5dc8d07 100644 --- a/inc/timer2_output.h +++ b/inc/timer2_output.h @@ -3,6 +3,8 @@ #include "stm32f4xx.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_it.h" +#include "stm32f4xx_tim.h" +#include "misc.h" #include "vector_prio.h" diff --git a/inc/usart2_comm.h b/inc/usart2_comm.h index db7bf66..e881111 100644 --- a/inc/usart2_comm.h +++ b/inc/usart2_comm.h @@ -13,10 +13,12 @@ #include "stm32f4xx_rcc.h" #include "stm32f4xx_it.h" #include "stm32f4xx_usart.h" +#include "misc.h" +#include "stm32f4xx_gpio.h" #include "vector_prio.h" #include -volatile uint16_t Recvd_word; +//volatile uint16_t Recvd_word; void init_usart2_comm_module(void); void init_usart2_gpio(void); void enable_usart2_rx_irq(void); diff --git a/inc/usart6_dma_comm.h b/inc/usart6_dma_comm.h new file mode 100644 index 0000000..268d20b --- /dev/null +++ b/inc/usart6_dma_comm.h @@ -0,0 +1,37 @@ +/* + * usart1_dma_comm.h + * + * Created on: Feb 2, 2018 + * Author: abel + */ + +#ifndef USART6_DMA_COMM_H_ +#define USART6_DMA_COMM_H_ + +#define USART6_GPIO GPIOC + + +#include "stm32f4xx.h" +#include "stm32f4xx_rcc.h" +#include "stm32f4xx_it.h" +#include "stm32f4xx_usart.h" +#include "misc.h" +#include "stm32f4xx_gpio.h" +#include "vector_prio.h" +#include + + +void init_usart6_comm_module(void); +void init_usart6_gpio(void); +void enable_usart6_rx_irq(void); +void USART6_TX_byte(uint8_t); +void USART6_TX_string(char *); + + + + + + + + +#endif /* USART6_DMA_COMM_H_ */ diff --git a/src/comm_service.c b/src/comm_service.c index c48140c..33e7a4b 100644 --- a/src/comm_service.c +++ b/src/comm_service.c @@ -23,3 +23,36 @@ void parser_gprmc(char *str_to_parse) USART_TX_byte('\n'); } + +void Display_Time_LCD(char *str_to_parse, char *str_to_extract, const uint8_t offset) +{ + int k=0; + volatile char *substr; + char Time_buffer[10]={0}; + char gps_buffer[1024]={0}; + + for(int i=0;i #include "main.h" #include +#include #include "inp_capture.h" #include "timer2_output.h" #include "comm_service.h" @@ -20,17 +22,17 @@ //#define LED_DEBUG #define BUF_SIZE 384 char gps_string[BUF_SIZE] = { 0 }; -char Time_buffer[10]={0}; -volatile char *substr; -volatile static uint16_t debounce_count=0; +uint8_t str_to_disp[DMA_RX_BUFFER_SIZE] = { 0 }; + +volatile static uint16_t debounce_count = 0; volatile unsigned long msTicks = 0; volatile uint8_t Rx_Interrupt_flag = FALSE; volatile char Transfer_cplt = FALSE; -volatile uint8_t Ext_Int_Occured= FALSE; - - +volatile uint8_t Ext_Int_Occured = FALSE; +volatile uint8_t DMA2_TxCplt_Occured = FALSE; +volatile uint8_t Recvd_word = 0; void Delay_ms(unsigned long del_count) { del_count *= 1000; @@ -54,10 +56,10 @@ void SysTick_Init(void) } static uint16_t buf_count = 0; + int main(void) { - int k = 0; SystemInit(); SysTick_Init(); RCC_HSICmd(ENABLE); @@ -68,10 +70,9 @@ int main(void) enable_Timer2_Interrupts(); /* InputCapture config */ - init_capture_module(); - init_IC_gpio(); - enable_capture_mod_irq(); - +// init_capture_module(); +// init_IC_gpio(); +// enable_capture_mod_irq(); /* USART config */ init_usart2_comm_module(); init_usart2_gpio(); @@ -90,17 +91,18 @@ int main(void) LCD_Goto(1, 1); LCD_Write_String("Time: "); - init_external_int_gpio(); init_external_interrupt(); enable_external_button_interrupt(); + /*Crazy USART DMA Part*/ + init_dma2(); + enable_dma2_irq(); - - - - - + /*USART6 init*/ + init_usart6_gpio(); + init_usart6_comm_module(); + enable_usart6_rx_irq(); #ifdef LED_DEBUG @@ -120,99 +122,56 @@ int main(void) while (1) { - GPIO_SetBits(GPIOD, GPIO_Pin_13); - - if(Ext_Int_Occured) + if (DMA2_TxCplt_Occured == TRUE) { -// LCD_Clear(); -// LCD_Goto(1,2); -// LCD_Write_String("Location: "); -// // Delay_ms(3000); -// Ext_Int_Occured=FALSE; + /* Copy the DMA Buffer into local buffer*/ + memcpy(gps_string, DMA_RX_Buffer, DMA_RX_BUFFER_SIZE); - } - - - if(Rx_Interrupt_flag==TRUE) - { - //__disable_irq(); - // USART_TX_byte(Recvd_word); - - gps_string[buf_count]=Recvd_word; - buf_count++; + //USART6_TX_string(gps_string); - if(buf_count>BUF_SIZE-1) - { - substr = strstr(gps_string,"$GPRMC"); - k=7; - while(k<13) - { - Time_buffer[k-7]=(substr[k]); - k++; - } - - //Time_buffer[1] += 1; - //Time_buffer[1] %=0x0a; - if(Time_buffer[1] == 0x39) - { - Time_buffer[1] = 0x30; - Time_buffer[0]+=1; - } - else - Time_buffer[1] += 1; - - - LCD_Goto(7,1); - //LCD_Write_String("Time: "); - LCD_Write_String(Time_buffer); - //LCD_Goto(7,1); - - buf_count=0; - - } - - Rx_Interrupt_flag=FALSE; - //__enable_irq(); + init_dma2(); + /*Display the parsed string over LCD*/ + Display_Time_LCD(gps_string, "$GPRMC", 7); + DMA2_TxCplt_Occured = FALSE; } - - - - - -#ifdef LED_DEBUG - if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) + if (Ext_Int_Occured == TRUE) { - GPIO_SetBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_14); - Delay_ms(1000); - GPIO_ResetBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_14); - Delay_ms(1000); - + LCD_Clear(); + LCD_Goto(1, 2); + LCD_Write_String("Location: "); + //Delay_ms(100); + LCD_Clear(); + LCD_Goto(1, 1); + LCD_Write_String("Time: "); + Ext_Int_Occured = FALSE; } - else + if (Rx_Interrupt_flag == TRUE) { - GPIO_ResetBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_14); - } - -#endif + buf_count++; + if (buf_count > BUF_SIZE - 1) + { + buf_count = 0; + } + Rx_Interrupt_flag = FALSE; + } } return 0; } -void TIM2_IRQHandler() +void TIM2_IRQHandler(void) { //GPIO_SetBits(GPIOD, GPIO_Pin_12); if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { GPIO_ToggleBits(GPIOD, GPIO_Pin_12); TIM_ClearITPendingBit(TIM2, TIM_IT_Update); - } } @@ -223,7 +182,6 @@ void TIM1_CC_IRQHandler(void) { //GPIO_ToggleBits(GPIOD, GPIO_Pin_14); TIM_ClearITPendingBit(TIM1, TIM_IT_CC1); - } } @@ -233,7 +191,7 @@ void SysTick_Handler(void) msTicks--; } -void USART2_IRQHandler() +void USART2_IRQHandler(void) { if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) @@ -247,17 +205,34 @@ void USART2_IRQHandler() } } -void EXTI0_IRQHandler() +void EXTI0_IRQHandler(void) { - - if( (EXTI_GetITStatus(EXTI_Line0)!= RESET ) ) + if ((EXTI_GetITStatus(EXTI_Line0) != RESET)) { Ext_Int_Occured = TRUE; - //GPIO_ToggleBits(GPIOD, GPIO_Pin_15); + //GPIO_ToggleBits(GPIOD, GPIO_Pin_14); EXTI_ClearITPendingBit(EXTI_Line0); } } +void DMA2_Stream2_IRQHandler(void) +{ + + if (DMA_GetITStatus(DMA2_USART6_STREAM, DMA_IT_TCIF2) != RESET) + { + DMA2_TxCplt_Occured = TRUE; + + GPIO_ToggleBits(GPIOD, GPIO_Pin_15); + + DMA_ClearITPendingBit(DMA2_USART6_STREAM, DMA_IT_TCIF2); + DMA_ClearITPendingBit(DMA2_USART6_STREAM, DMA_IT_HTIF2); + DMA_ClearITPendingBit(DMA2_USART6_STREAM, DMA_IT_FEIF2); + DMA_ClearITPendingBit(DMA2_USART6_STREAM, DMA_IT_DMEIF2); + DMA_ClearITPendingBit(DMA2_USART6_STREAM, DMA_IT_TEIF2); + + } +} +