-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.c
133 lines (112 loc) · 4.83 KB
/
application.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* File : application.c
* Author : Mohamed Ahmed Abdel Wahab
* LinkedIn : https://www.linkedin.com/in/mohamed-abdel-wahab-162413253/
* Github : https://github.com/moabdelwahab6611
* Created on May 21, 2023, 5:38 PM
*/
/**************************Includes-Section*****************************/
#include "application.h"
#include "MCAL_Layer/USART/hal_usart.h"
/***********************************************************************/
/***********************************************************************/
uint8 receive_usart_data;
led_t led1 = {.port_name = PORTD_INDEX, .pin = GPIO_PIN0, .led_status = GPIO_LOW};
led_t led2 = {.port_name = PORTC_INDEX, .pin = GPIO_PIN1, .led_status = GPIO_LOW};
volatile uint32 valid_usart_tx;
volatile uint32 valid_usart_rx;
void usart_module_init(void)
{
Std_ReturnType ret = E_NOT_OK;
usart_t usart_obj;
usart_obj.USART_FramingErrorHandler = NULL;
usart_obj.USART_OverrunErrorHandler = NULL;
usart_obj.USART_RxDefaultInterruptHandler = NULL;
usart_obj.USART_TxDefaultInterruptHandler = NULL;
usart_obj.baudrate = 9600;
usart_obj.baudrate_config = BAUDRATE_ASYNCHRONOUS_MODE_8BIT_LOW_SPEED;
usart_obj.usart_tx_cfg.usart_enable_tx = USART_ENABLE_ASYNCHRONOUS_MODE_TX;
usart_obj.usart_tx_cfg.usart_enable_tx_interrupt = USART_DISABLE_ASYNCHRONOUS_MODE_TX_INTERRUPT;
usart_obj.usart_tx_cfg.usart_enable_9bit_tx = USART_DISABLE_ASYNCHRONOUS_MODE_9BIT_TX;
usart_obj.usart_rx_cfg.usart_enable_rx = USART_ENABLE_ASYNCHRONOUS_MODE_RX;
usart_obj.usart_rx_cfg.usart_enable_rx_interrupt = USART_DISABLE_ASYNCHRONOUS_MODE_RX_INTERRUPT;
usart_obj.usart_rx_cfg.usart_enable_9bit_rx = USART_DISABLE_ASYNCHRONOUS_MODE_9BIT_RX;
ret = USART_Asynchronous_Initialize(&usart_obj);
}
void USART_FramingDefaultErrorHandler(void)
{
uint8 _data_;
USART_Asynchronous_ReadByte_NonBlocking(&_data_);
}
void USART_OverrunDefaultErrorHandler(void)
{
USART_Asynchronous_Restart_RX();
}
void USART_TxDefaultInterruptHandler(void)
{
valid_usart_tx++;
}
void USART_RxDefaultInterruptHandler(void)
{
Std_ReturnType ret = E_NOT_OK;
valid_usart_rx++;
ret = USART_Asynchronous_ReadByte_NonBlocking(&receive_usart_data);
switch(receive_usart_data)
{
case 'a' : led_turn_on(&led1);
ret = USART_Asynchronous_WriteString_Blocking("Led1 On\r", 8);
break;
case 'b' : led_turn_off(&led1);
ret = USART_Asynchronous_WriteString_Blocking("Led1 Off\r", 9);
break;
case 'c' : led_turn_on(&led2);
ret = USART_Asynchronous_WriteString_Blocking("Led2 On\r", 8);
break;
case 'd' : led_turn_off(&led2);
ret = USART_Asynchronous_WriteString_Blocking("Led2 Off\r", 9);
break;
default : led_turn_off(&led1);
led_turn_off(&led2);
}
}
void usart_module_int_init(void)
{
Std_ReturnType ret = E_NOT_OK;
usart_t usart_obj;
usart_obj.USART_FramingErrorHandler = USART_FramingDefaultErrorHandler;
usart_obj.USART_OverrunErrorHandler = USART_OverrunDefaultErrorHandler;
usart_obj.USART_RxDefaultInterruptHandler = USART_RxDefaultInterruptHandler;
usart_obj.USART_TxDefaultInterruptHandler = USART_TxDefaultInterruptHandler;
usart_obj.baudrate = 9600;
usart_obj.baudrate_config = BAUDRATE_ASYNCHRONOUS_MODE_8BIT_LOW_SPEED;
usart_obj.usart_tx_cfg.usart_enable_tx = USART_ENABLE_ASYNCHRONOUS_MODE_TX;
usart_obj.usart_tx_cfg.usart_enable_tx_interrupt = USART_ENABLE_ASYNCHRONOUS_MODE_TX_INTERRUPT;
usart_obj.usart_tx_cfg.usart_enable_9bit_tx = USART_DISABLE_ASYNCHRONOUS_MODE_9BIT_TX;
usart_obj.usart_rx_cfg.usart_enable_rx = USART_ENABLE_ASYNCHRONOUS_MODE_RX;
usart_obj.usart_rx_cfg.usart_enable_rx_interrupt = USART_ENABLE_ASYNCHRONOUS_MODE_RX_INTERRUPT;
usart_obj.usart_rx_cfg.usart_enable_9bit_rx = USART_DISABLE_ASYNCHRONOUS_MODE_9BIT_RX;
ret = USART_Asynchronous_Initialize(&usart_obj);
}
/***********************************************************************/
/***********************Main Function-Section***************************/
int main()
{
Std_ReturnType ret = E_NOT_OK;
application_intialize();
usart_module_int_init();
ret = led_initialize(&led1);
ret = led_initialize(&led2);
while(1)
{
// ret = USART_Asynchronous_WriteString_Blocking("Mohamed", 7);
}
return (EXIT_SUCCESS);
}
/***********************************************************************/
/*************************Functions-Section*****************************/
void application_intialize(void)
{
Std_ReturnType ret = E_NOT_OK;
ecu_layer_intialize();
}
/***********************************************************************/