From 7cba1cf7d2ee89559239a22c50297a1545de0587 Mon Sep 17 00:00:00 2001
From: siddhu8990
Date: Wed, 13 Jan 2016 11:15:17 +0530
Subject: Test commit

---
 src/c/hardware/avr/includes/AVRPeripheralPWM.h     |  2 +-
 src/c/hardware/avr/includes/AVRPeripheralTimer.h   | 27 +++++++
 .../hardware/avr/interfaces/int_AVRPeripheralADC.h |  4 +-
 .../avr/interfaces/int_AVRPeripheralGPIO.h         | 11 +--
 .../hardware/avr/interfaces/int_AVRPeripheralPWM.h |  4 +-
 .../avr/interfaces/int_AVRPeripheralTimer.h        | 25 +++++++
 src/c/hardware/avr/timer/u8AVRGetTimerValues.c     | 37 ++++++++++
 src/c/hardware/avr/timer/u8AVRTimerSetups.c        | 42 +++++++++++
 src/c/hardware/avr/uart/u8AVRUARTSetups.c          | 84 ++++++++++++++++++++++
 9 files changed, 223 insertions(+), 13 deletions(-)
 create mode 100644 src/c/hardware/avr/includes/AVRPeripheralTimer.h
 create mode 100644 src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h
 create mode 100644 src/c/hardware/avr/timer/u8AVRGetTimerValues.c
 create mode 100644 src/c/hardware/avr/timer/u8AVRTimerSetups.c
 create mode 100644 src/c/hardware/avr/uart/u8AVRUARTSetups.c

(limited to 'src/c/hardware/avr')

diff --git a/src/c/hardware/avr/includes/AVRPeripheralPWM.h b/src/c/hardware/avr/includes/AVRPeripheralPWM.h
index 80b29f3a..7371dd74 100644
--- a/src/c/hardware/avr/includes/AVRPeripheralPWM.h
+++ b/src/c/hardware/avr/includes/AVRPeripheralPWM.h
@@ -17,7 +17,7 @@ extern "C" {
 //Function prototypes
 uint8 u8AVRPWMSetups(uint8 timer, uint8 prescalar, uint8 waveform_mode, uint8 output_mode);
 
-uint8 u8AVRPWMSetDuty(uint8 timer, uint8 duty);
+uint8 u8AVRPWMSetDutys(uint8 timer, uint8 duty);
 
 
 #ifdef  __cplusplus
diff --git a/src/c/hardware/avr/includes/AVRPeripheralTimer.h b/src/c/hardware/avr/includes/AVRPeripheralTimer.h
new file mode 100644
index 00000000..78b04aae
--- /dev/null
+++ b/src/c/hardware/avr/includes/AVRPeripheralTimer.h
@@ -0,0 +1,27 @@
+//This file defines functions prototypes related to Timer.
+//
+// Authors
+//     Siddhesh Wani
+//
+
+#ifndef __AVRPERIPHERALTIMER_H__
+#define __AVRPERIPHERALTIMER_H__
+
+#include <avr/io.h>
+#include "types.h"
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+//Function prototypes
+uint8 u8AVRTimerSetups(uint8 timer, uint8 prescalar);
+
+uint8 u8AVRGetTimerValue(uint8 timer);
+
+
+#ifdef  __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* !__AVRPERIPHERALTIMER_H__ */
diff --git a/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h
index 0aafb8c0..425b03fc 100644
--- a/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h
+++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralADC.h
@@ -14,10 +14,10 @@
 extern "C" {
 #endif
 
-#define d0d0AVRADCSetupu80(in1,in2) u8AVRADCSetups((uint8) in1,\
+#define AVRADCSetup(in1,in2) u8AVRADCSetups((uint8) in1,\
                                                   (uint8) in2);
 
-#define d0AVRReadADCu160(in1) u8AVRReadADCs((uint8) in1);
+#define AVRReadADC(in1) u8AVRReadADCs((uint8) in1);
 
 #ifdef  __cplusplus
 } /* extern "C" */
diff --git a/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h
index 439532db..c034718c 100644
--- a/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h
+++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralGPIO.h
@@ -14,19 +14,14 @@
 extern "C" {
 #endif
 
-#define d0d0d0AVRDigitalSetupu80(in1,in2,in3) u8AVRDigitalSetups((uint8) in1,\
+#define AVRDigitalSetup(in1,in2,in3) u8AVRDigitalSetups((uint8) in1,\
                                                   (uint8) in2, (uint8) in3);
 
-#define d0d0AVRDigitalInu80(in1,in2) u8AVRDigitalIns((uint8) in1,\
-                                                  (uint8) in2);
+#define AVRDigitalIn(in1,in2) u8AVRDigitalIns((uint8) in1, (uint8) in2);
 
-#define d0d0d0AVRDigitalOutu80(in1,in2,in3) u8AVRDigitalOuts((uint8) in1,\
+#define AVRDigitalOut(in1,in2,in3) u8AVRDigitalOuts((uint8) in1,\
                                                   (uint8) in2, (uint8) in3);
 
-#define d0d0u80AVRDigitalOutu80(in1,in2,in3) u8AVRDigitalOuts((uint8) in1,\
-                                                  (uint8) in2, (uint8) in3);
-
-
 #ifdef  __cplusplus
 } /* extern "C" */
 #endif
diff --git a/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h
index 73686190..2d5e5cbd 100644
--- a/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h
+++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralPWM.h
@@ -14,10 +14,10 @@
 extern "C" {
 #endif
 
-#define d0d0d0d0AVRPWMSetupu80(in1,in2) u8AVRPWMSetups((uint8) in1,\
+#define AVRPWMSetup(in1,in2,in3,in4) u8AVRPWMSetups((uint8) in1,\
                                          (uint8) in2, (uint8) in3, (uint8) in4);
 
-#define d0d0AVRPWMSetDuty(in1,in2) u8AVRPWMSetDutys((uint8) in1, (uint8) in2);
+#define AVRPWMSetDuty(in1,in2) u8AVRPWMSetDutys((uint8) in1, (uint8) in2);
 
 #ifdef  __cplusplus
 } /* extern "C" */
diff --git a/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h b/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h
new file mode 100644
index 00000000..b4b66bae
--- /dev/null
+++ b/src/c/hardware/avr/interfaces/int_AVRPeripheralTimer.h
@@ -0,0 +1,25 @@
+//This file defines constants corresponding to gpios.
+//
+// Authors
+//     Siddhesh Wani
+//
+
+#ifndef __INT_AVRPERIPHERALTIMER_H__
+#define __INT_AVRPERIPHERALTIMER_H__
+
+#include <avr/io.h>
+#include "AVRPeripheralTimer.h"
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#define AVRTimerSetup(in1,in2) u8AVRTimerSetups((uint8) in1, (uint8) in2);
+
+#define AVRGetTimerValue(in1) u8AVRGetTimerValues((uint8) in1);
+
+#ifdef  __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* !__AVRPERIPHERALADC_H__ */
diff --git a/src/c/hardware/avr/timer/u8AVRGetTimerValues.c b/src/c/hardware/avr/timer/u8AVRGetTimerValues.c
new file mode 100644
index 00000000..c542c182
--- /dev/null
+++ b/src/c/hardware/avr/timer/u8AVRGetTimerValues.c
@@ -0,0 +1,37 @@
+// Function to get timer count
+//
+// Calling Sequence
+//     u8AVRGetTimerValues(timer)
+//
+// Parameters
+//     timer: timer whose current count is to be returned (0,1,2)
+//     ***Refer datasheet for more description about timer
+//              
+// Description
+//     This function returns the count of timer specified 
+//
+//
+// Authors
+//     Siddhesh Wani
+//
+
+
+#include "AVRPeripheralTimer.h"
+
+
+uint8 u8AVRGetTimerValues(uint8 timer)
+{
+    switch(timer)
+	{
+		case 0:
+				return TCNT0;
+				
+		case 1:
+				break;
+		case 2:
+				return TCNT2;
+	}	    
+
+	return 0;
+}
+
diff --git a/src/c/hardware/avr/timer/u8AVRTimerSetups.c b/src/c/hardware/avr/timer/u8AVRTimerSetups.c
new file mode 100644
index 00000000..1d93429b
--- /dev/null
+++ b/src/c/hardware/avr/timer/u8AVRTimerSetups.c
@@ -0,0 +1,42 @@
+// Function to setup timer on AVR
+//
+// Calling Sequence
+//     u8AVRTimerSetups(timer, prescalar)
+//
+// Parameters
+//     timer: timer to be set up (0,1,2)
+//     prescalar: prescalar to be used for timer (0-7)
+//     ***Refer datasheet for more description about timer
+//              
+// Description
+//     This function sets prescalr for timers. 'timer' decides which of the 
+//     three (0,1,2) timers available to be used. The 'prescalar' is needed for 
+//     deciding timer clock. Select appropriate prescalar depending on MCU clock
+//     and requirement.
+//
+//
+// Authors
+//     Siddhesh Wani
+//
+
+
+#include "AVRPeripheralTimer.h"
+
+
+uint8 u8AVRTimerSetups(uint8 timer,uint8 prescalar)
+{
+    switch(timer)
+	{
+		case 0:
+				TCCR0|= (prescalar & 0x07);  //Select clock source
+				break;
+		case 1:
+				break;
+		case 2:
+				TCCR2|= (prescalar & 0x07);  //Select clock source
+				break;
+	}	    
+
+	return 0;
+}
+
diff --git a/src/c/hardware/avr/uart/u8AVRUARTSetups.c b/src/c/hardware/avr/uart/u8AVRUARTSetups.c
new file mode 100644
index 00000000..f311500a
--- /dev/null
+++ b/src/c/hardware/avr/uart/u8AVRUARTSetups.c
@@ -0,0 +1,84 @@
+// Function to initialise uart interface of AVR
+//
+// Calling Sequence
+//     u8AVRUARTSetups(uint8 mode, uint8 baudrate, uint8 stopbits, uint8 parity)
+//
+// Parameters
+//     mode : Mode of usart interface (0-Normal mode, 1-Double speed mode, 
+//							2-Synchronous master mode)
+//     baudrate : Baudrate for communication. Refer AVRPeripheralUART.h 
+//							for available options) 
+//     stopbits : No. of stopbits (0-1) for stopbits 1 and 2 resp.
+//	   parity: set parity bit. (0-disabled, 1-Even parity, 2-Odd parity)	
+//
+//
+// Description
+//	   This function initialises uart interface for AVR. Available modes are 
+//	   Normal mode (0), Double speed mode (1), Synchronous master mode(2). 'baudrate' 
+//	   decides baudrate for communication. For baudrate settings, variable 
+//	   'XTAL_FREQUENCY' is required. 'stopbits' sets no of stopbits for data 
+//	   packet. 0 for 1 stopbit and 1 for 2 stopbits. 'parity' decides parity bit
+//	   for communication. 0 for disabling parity bit, 1 for even parity and 2 
+//	   for odd parity.  	     
+//
+// Authors
+//     Siddhesh Wani
+//
+
+#include "AVRPeripheralUART.h"
+
+uint8 u8AVRUARTSetups(uint8 mode, uint8 baudrate, uint8 stopbits, uint8 parity)
+{
+	switch (mode) //According to mode set bits UMSEL and U2X
+	{
+		case 0: //Normal mode
+				UCSRC &= ~(1<<6); //Clear bit 6 UMSEL  
+				break;
+
+		case 1: //Double speed mode
+				UCSRC &= ~(1<<6); //Clear bit 6 UMSEL
+				break;
+
+		case 2: //Synchronous master mode
+				UCSRC |= (1<<6);  //Set bit 6 UMSEL  
+				break;
+	}
+    
+	if(stopbits == 0)
+	{   // 1 stopbit
+		UCSRC &= ~(1<<3);
+	}
+	else 
+	{   // 2 stopbits
+		UCSRC |= (1<<3);
+	}
+
+	//Set parity bit settings
+	switch(parity)
+	{
+		case 0: // Parity disabled
+				UCSRC &= ~(3<<4);	//UPM1:0=0
+				break;
+		case 1:// Even parity
+				UCSRC |= (1<<5);    //UPM1:0 = 2
+				UCSRC &= ~(1<<4);
+				break;
+		case 2:// Odd parity
+				UCSRC |= (1<<5);    //UPM1:1 = 3
+				UCSRC |= (1<<4);
+				break;
+	}
+
+	//Set baud rate
+	# define BAUD baudrate
+	#include "util/setbaud.h"
+	UBRRH = UBRRH_VALUE;
+	UBRRL = UBRRL_VALUE;
+	#if USE_2X
+	UCSRA |= (1 << U2X);
+	#else
+	UCSRA &= ~(1 << U2X);
+	#endif
+    return 0;
+}
+
-- 
cgit