From 1ec114d14a48afbd82b89adceb173204417e7df7 Mon Sep 17 00:00:00 2001
From: Edward Longman <el7g15@soton.ac.uk>
Date: Fri, 5 Jul 2019 11:20:19 +0100
Subject: [PATCH] Add libary usage to minimal example

---
 source/lib/uart_drv/CMakeLists.txt | 12 ++++
 source/test/min.c                  | 93 ++++++++++++++++++++++++++----
 2 files changed, 93 insertions(+), 12 deletions(-)
 create mode 100644 source/lib/uart_drv/CMakeLists.txt

diff --git a/source/lib/uart_drv/CMakeLists.txt b/source/lib/uart_drv/CMakeLists.txt
new file mode 100644
index 0000000..3a13fb2
--- /dev/null
+++ b/source/lib/uart_drv/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.8)
+
+include(${CMAKE_SOURCE_DIR}/../common.cmake)
+
+
+add_library(
+  uart_drv
+  STATIC
+  circ_buf.c
+  uart_drv.c
+  ee_printf.c
+  )
diff --git a/source/test/min.c b/source/test/min.c
index 23d216c..56ac5fb 100644
--- a/source/test/min.c
+++ b/source/test/min.c
@@ -10,7 +10,7 @@
  * LOCAL FUNCTIONS
  */
 extern void msp_setup(void);
-extern unsigned long volatile time_counter;
+unsigned long volatile time_counter;
 
 /******************************************************************************
  * GLOBALS
@@ -53,11 +53,11 @@ void main (void)
 	WDTCTL = WDTPW + WDTHOLD;
 
 	/* Setup MSP specific functions, IO's, timers and WDT */
-  //Comes from lib/hal_mcu/hal_mcu.c
+    //Comes from lib/hal_mcu/hal_mcu.c
 	msp_setup();
 
 	/* Initialize the UART port */
-	//hal_uart_init();
+	hal_uart_init();
 
 	/* enable uart echo function */
 	//uart_drv_toggle_echo();
@@ -94,8 +94,9 @@ void main (void)
 	{
 
 		/* Put MCU in low power mode, wait for UART and blink LED */
+		//Skip Low power mode to debug
 		HAL_LED2_OFF();
-		_BIS_SR(LPM0_bits + GIE);
+		//_BIS_SR(LPM0_bits + GIE);
 		HAL_LED2_ON();
 		idle_counter++;
 
@@ -105,19 +106,87 @@ void main (void)
 		 */
 		switch(state)
 		{
-		/* print the main menu to the UART buffer */
+		/* print the tick state to the UART buffer */
 		case WAIT:
-      if(idle_counter>250){
-        state = IDLE_RESET;
-      }
+            if(time_counter>5){
+                state = IDLE_RESET;
+                uartSendString("Tic:\n\r");
+                time_counter = 0;
+            }
 			state = OPERATE;
-      break;
-    case OPERATE:
-      state = OPERATE;
-      break;
+			HAL_LED1_OFF();
+            break;
+        case OPERATE:
+            if(time_counter>5){
+                state = WAIT;
+                uartSendString("Tic:\n\r");
+                time_counter = 0;
+            }
+			HAL_LED1_ON();
+            break;
 		default:
 			state = WAIT;
 			break;
 		}
 	}
 }
+
+
+/******************************************************************************
+ * @fn         uartSendString
+ *
+ * @brief      Implements a simple uart string sender by automatically finding
+ *             the end of line delimeter and using it to call the uart sub
+ *             functions
+ *
+ * input parameters
+ *
+ * @param            unsigned char *str
+ *
+ * output parameters
+ *
+ * @return      void
+ *
+ */
+void uartSendString(char *str)
+{
+	unsigned char ii;
+
+	for(ii=0;ii<UART_BUFF_SIZE;ii++)
+	{
+		if(str[ii] == 13)
+		{
+			uart_put_str(str, ii+1);
+			ii = UART_BUFF_SIZE;
+		}
+	}
+	return;
+}
+
+/******************************************************************************
+ * @fn         wdt_isr
+ *
+ * @brief      Interrupt service routine for watch dog timer.
+ *
+ * input parameters
+ *
+ * @param       void
+ *
+ * output parameters
+ *
+ * @return      void
+ *
+ */
+HAL_ISR_FUNC_DECLARATION(wdt_isr,WDT)
+{
+	/* global "0.5 second" counter used for printing time stamped packet sniffer data */
+	time_counter++;
+
+	/* check to see if wake on wdt is enabled */
+	if(wakeup_on_wdt == 1)
+	{
+
+		/* exit from low power mode on ISR exit */
+		//_BIC_SR_IRQ(LPM3_bits);
+	}
+}
-- 
GitLab