Skip to content

Commit 7ab99bb

Browse files
committed
Added tests for the USART module
1 parent 909a5d4 commit 7ab99bb

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

MCAL/USART/USART_test.c

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*******************************************************
2+
*
3+
* @file USART_test.c
4+
* @brief Tests for the USART driver
5+
* @author Abdulrahman Aboghanima
6+
* @date Sun Feb 20 22:55:31 2022
7+
* @copyright Copyright (c) 2022
8+
* @version 0.2
9+
*
10+
*******************************************************/
11+
12+
#include "../../LIB/STD_TYPES.h"
13+
#include "../DIO/DIO_interface.h"
14+
#include "../GIE/GIE_interface.h"
15+
#include "USART_interface.h"
16+
#include <util/delay.h>
17+
#include <stdio.h>
18+
19+
20+
/* The following two functions are used as a call back for the ISRs of the USART*/
21+
void blink1(void)
22+
{
23+
DIO_SetPinValue(DIO_PORTD, DIO_PIN6, 1);
24+
_delay_ms(1000);
25+
DIO_SetPinValue(DIO_PORTD, DIO_PIN6, 0);
26+
_delay_ms(1000);
27+
DIO_SetPinValue(DIO_PORTD, DIO_PIN6, 1);
28+
_delay_ms(1000);
29+
DIO_SetPinValue(DIO_PORTD, DIO_PIN6, 0);
30+
}
31+
void blink2(void)
32+
{
33+
DIO_SetPinValue(DIO_PORTD, DIO_PIN5, 1);
34+
_delay_ms(1000);
35+
DIO_SetPinValue(DIO_PORTD, DIO_PIN5, 0);
36+
}
37+
int main(void)
38+
{
39+
40+
DIO_SetPortDirection(DIO_PORTD, DIO_PORT_OUTPUT);
41+
GIE_enable();
42+
USART_init();
43+
USART_redirect_stream_to_stdout();
44+
uint8_t data;
45+
46+
while(1){
47+
printf("\n.............Testing the USART.............\n");
48+
printf("Testing printf()\n");
49+
printf("Done \n");
50+
51+
printf("Testing: USART_sendStream()\n");
52+
USART_sendStream("------------------------------\n");
53+
USART_sendStream(">Testing not interrupt driven data transmission..\n");
54+
USART_sendStream(">>>1- Sending `k`: ");
55+
USART_send('k');
56+
USART_sendStream("\n>>>2- Receiving a letter: ");
57+
data=USART_receive();
58+
USART_sendStream("\n You entered: ");
59+
USART_send(data);
60+
61+
USART_sendStream("\n>Testing interrupt driven data transmission..");
62+
USART_sendStream("\n>>>1- Sending `k` with led blinking after transmission complete: ");_delay_ms(1000);
63+
USART_sendWithInterruptDriven('k', blink1);
64+
USART_sendStream("\n>>>2- Receiving a letter: ");
65+
data=USART_receiveWithInterruptDriven(blink2);
66+
USART_sendStream("\n You entered: ");
67+
USART_send(data);
68+
69+
}
70+
71+
return 0;
72+
}

0 commit comments

Comments
 (0)