revised code

Dependencies:   mbed

Committer:
nmaududi
Date:
Sat Oct 05 21:17:17 2019 +0000
Revision:
2:64a34ae90bb1
Parent:
1:9fa7cc80f1a7
revised version for module 4;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nmaududi 0:4fb921928934 1 /**-----------------------------------------------------------------------------
nmaududi 0:4fb921928934 2 \file shared.h
nmaududi 0:4fb921928934 3 -- --
nmaududi 0:4fb921928934 4 -- ECEN 5803 Mastering Embedded System Architecture --
nmaududi 0:4fb921928934 5 -- Project 1 Module 4 --
nmaududi 0:4fb921928934 6 -- Microcontroller Firmware --
nmaududi 0:4fb921928934 7 -- shared.h --
nmaududi 0:4fb921928934 8 -- --
nmaududi 0:4fb921928934 9 -------------------------------------------------------------------------------
nmaududi 0:4fb921928934 10 --
nmaududi 0:4fb921928934 11 -- Designed for: University of Colorado at Boulder
nmaududi 0:4fb921928934 12 --
nmaududi 0:4fb921928934 13 --
nmaududi 0:4fb921928934 14 -- Designed by: Tim Scherr
nmaududi 0:4fb921928934 15 -- Revised by: Naved Maududi and Bryan Cisneros
nmaududi 0:4fb921928934 16 --
nmaududi 0:4fb921928934 17 -- Version: 2.1
nmaududi 0:4fb921928934 18 -- Date of current revision: 2017-09-25
nmaududi 0:4fb921928934 19 -- Target Microcontroller: Freescale MKL25ZVMT4
nmaududi 0:4fb921928934 20 -- Tools used: ARM mbed compiler
nmaududi 0:4fb921928934 21 -- ARM mbed SDK
nmaududi 0:4fb921928934 22 -- Freescale FRDM-KL25Z Freedom Board
nmaududi 0:4fb921928934 23 --
nmaududi 0:4fb921928934 24 --
nmaududi 0:4fb921928934 25 -- Functional Description: Header file for all globals
nmaududi 0:4fb921928934 26 --
nmaududi 0:4fb921928934 27 -- Copyright (c) 2015, 2016 Tim Scherr All rights reserved.
nmaududi 0:4fb921928934 28 --
nmaududi 0:4fb921928934 29 */
nmaududi 0:4fb921928934 30
nmaududi 0:4fb921928934 31 #include "mbed.h"
nmaududi 0:4fb921928934 32
nmaududi 0:4fb921928934 33 /*****************************************************************************
nmaududi 0:4fb921928934 34 * #defines available to all modules included here
nmaududi 0:4fb921928934 35 ******************************************************************************/
nmaududi 0:4fb921928934 36 #define OFF 0 /* used for readability */
nmaududi 0:4fb921928934 37 #define ON 1 /* used for readability */
nmaududi 0:4fb921928934 38 #define NO 0 /* used for readability */
nmaududi 0:4fb921928934 39 #define YES 1 /* used for readability */
nmaududi 0:4fb921928934 40 #define TEN 10
nmaududi 0:4fb921928934 41
nmaududi 0:4fb921928934 42 #define TIMER0 TMR0
nmaududi 0:4fb921928934 43 #define SEC 10000 /* 10000 timer0 interrupts per second (100 usec.) */
nmaududi 0:4fb921928934 44
nmaududi 0:4fb921928934 45 #define T100MS 0.1*SEC
nmaududi 0:4fb921928934 46 #define T2S 2*SEC
nmaududi 0:4fb921928934 47
nmaududi 0:4fb921928934 48 #define LED_FLASH_PERIOD .5 /* in seconds */
nmaududi 0:4fb921928934 49
nmaududi 0:4fb921928934 50 #define CLOCK_FREQUENCY_MHZ 8
nmaududi 0:4fb921928934 51 #define CODE_VERSION "2.0 2016/09/29" /* YYYY/MM/DD */
nmaududi 0:4fb921928934 52 #define COPYRIGHT "Copyright (c) University of Colorado"
nmaududi 0:4fb921928934 53
nmaududi 0:4fb921928934 54 enum boolean { FALSE, TRUE }; /// \enum boolean
nmaududi 0:4fb921928934 55 enum dmode {QUIET, NORMAL, DEBUG, VERSION};
nmaududi 0:4fb921928934 56
nmaududi 0:4fb921928934 57 typedef unsigned char UCHAR;
nmaududi 0:4fb921928934 58 typedef unsigned char bit;
nmaududi 0:4fb921928934 59 typedef unsigned int uint32_t;
nmaududi 0:4fb921928934 60 typedef unsigned short uint16_t;
nmaududi 0:4fb921928934 61 typedef signed short int16_t;
nmaududi 0:4fb921928934 62
nmaududi 0:4fb921928934 63 #ifdef __cplusplus
nmaududi 0:4fb921928934 64 extern "C" {
nmaududi 0:4fb921928934 65 #endif
nmaududi 0:4fb921928934 66
nmaududi 0:4fb921928934 67 /************************************************************************/
nmaududi 0:4fb921928934 68 /* Global Variable declarations */
nmaududi 0:4fb921928934 69 /************************************************************************/
nmaududi 0:4fb921928934 70
nmaududi 0:4fb921928934 71 extern unsigned char Error_status; // Variable for debugging use
nmaududi 0:4fb921928934 72 extern UCHAR display_timer; // \var 1 second software timer for display
nmaududi 0:4fb921928934 73 extern UCHAR display_flag; // flag between timer interrupt and monitor.c,
nmaududi 0:4fb921928934 74 extern UCHAR LED_timer_flag; // flag between timer interrupt and main.c,
nmaududi 0:4fb921928934 75 // like a binary semaphore
nmaududi 0:4fb921928934 76 extern UCHAR tx_in_progress;
nmaududi 0:4fb921928934 77 extern UCHAR *rx_in_ptr; /* pointer to the receive in data */
nmaududi 0:4fb921928934 78 extern UCHAR *rx_out_ptr; /* pointer to the receive out data*/
nmaududi 0:4fb921928934 79 extern UCHAR *tx_in_ptr; /* pointer to the transmit in data*/
nmaududi 0:4fb921928934 80 extern UCHAR *tx_out_ptr; /*pointer to the transmit out */
nmaududi 0:4fb921928934 81 extern uint16_t ADC_buffer; // value that ADC will read in, need to be external so that flow function can read in
nmaududi 0:4fb921928934 82 extern uint16_t temperature; // value that will be external to all variable. stores the value of temperature
nmaududi 2:64a34ae90bb1 83 extern int Vtemp; // value in mV of the temperature calculated
nmaududi 0:4fb921928934 84 extern uint16_t freq_value; // value that will store the frequency detected. Need it to be availaible to all functions
nmaududi 0:4fb921928934 85 extern uint16_t flow; // value that will store the flow that is determine
nmaududi 0:4fb921928934 86 extern uint16_t ADC_vortex_frequency_input; // value of the ADC_vortex_frequency_input
nmaududi 0:4fb921928934 87 extern uint16_t Vrefl; // value of the ADC_vortex_frequency_input
nmaududi 2:64a34ae90bb1 88 extern double zero_detect_counter;
nmaududi 2:64a34ae90bb1 89 extern UCHAR reset_counter_flag;
nmaududi 0:4fb921928934 90
nmaududi 0:4fb921928934 91 #define RX_BUF_SIZE 10 /* size of receive buffer in bytes */
nmaududi 0:4fb921928934 92 #define TX_BUF_SIZE 10 /* size of transmit buffer in bytes */
nmaududi 0:4fb921928934 93
nmaududi 0:4fb921928934 94 /******************************************************************************
nmaududi 0:4fb921928934 95 * Some variable definitions are done in the module main.c and are externed in
nmaududi 0:4fb921928934 96 * all other modules. The following section is visible to main.c only.
nmaududi 0:4fb921928934 97 ******************************************************************************/
nmaududi 0:4fb921928934 98 #ifdef MAIN
nmaududi 0:4fb921928934 99
nmaududi 0:4fb921928934 100 enum dmode display_mode = QUIET;
nmaududi 0:4fb921928934 101
nmaududi 0:4fb921928934 102 UCHAR serial_flag = 0;
nmaududi 0:4fb921928934 103
nmaududi 0:4fb921928934 104 UCHAR tx_in_progress;
nmaududi 0:4fb921928934 105 UCHAR *rx_in_ptr; /* pointer to the receive in data */
nmaududi 0:4fb921928934 106 UCHAR *rx_out_ptr; /* pointer to the receive out data*/
nmaududi 0:4fb921928934 107 UCHAR *tx_in_ptr; /* pointer to the transmit in data*/
nmaududi 0:4fb921928934 108 UCHAR *tx_out_ptr; /*pointer to the transmit out */
nmaududi 0:4fb921928934 109
nmaududi 0:4fb921928934 110 UCHAR rx_buf[RX_BUF_SIZE]; /* define the storage */
nmaududi 0:4fb921928934 111 UCHAR tx_buf[TX_BUF_SIZE]; /* define the storage */
nmaududi 0:4fb921928934 112
nmaududi 0:4fb921928934 113 #define MSG_BUF_SIZE 10
nmaududi 0:4fb921928934 114 UCHAR msg_buf[MSG_BUF_SIZE]; // define the storage for UART received messages
nmaududi 0:4fb921928934 115 UCHAR msg_buf_idx = 0; // index into the received message buffer
nmaududi 0:4fb921928934 116
nmaududi 0:4fb921928934 117 /******************************************************************************
nmaududi 0:4fb921928934 118 * Some variable definitions are done in the module main.c and are externed in
nmaududi 0:4fb921928934 119 * all other modules. The following section is visible to all modules EXCEPT
nmaududi 0:4fb921928934 120 * main.c.
nmaududi 0:4fb921928934 121 *******************************************************************************/
nmaududi 0:4fb921928934 122 #else
nmaududi 0:4fb921928934 123
nmaududi 0:4fb921928934 124 /**********************/
nmaududi 0:4fb921928934 125 /* Declarations */
nmaududi 0:4fb921928934 126 /**********************/
nmaududi 0:4fb921928934 127
nmaududi 0:4fb921928934 128 extern volatile UCHAR swtimer0;
nmaududi 0:4fb921928934 129 extern volatile UCHAR swtimer1;
nmaududi 0:4fb921928934 130 extern volatile UCHAR swtimer2;
nmaududi 0:4fb921928934 131 extern volatile UCHAR swtimer3;
nmaududi 0:4fb921928934 132 extern volatile UCHAR swtimer4;
nmaududi 0:4fb921928934 133 extern volatile UCHAR swtimer5;
nmaududi 0:4fb921928934 134 extern volatile UCHAR swtimer6;
nmaududi 0:4fb921928934 135 extern volatile UCHAR swtimer7;
nmaududi 0:4fb921928934 136
nmaududi 0:4fb921928934 137 extern UCHAR serial_flag;
nmaududi 0:4fb921928934 138
nmaududi 0:4fb921928934 139 extern enum dmode display_mode;
nmaududi 0:4fb921928934 140
nmaududi 0:4fb921928934 141
nmaududi 0:4fb921928934 142 extern UCHAR rx_buf[]; /* declare the storage */
nmaududi 0:4fb921928934 143 extern UCHAR tx_buf[]; /* declare the storage */
nmaududi 0:4fb921928934 144
nmaududi 0:4fb921928934 145 #define MSG_BUF_SIZE 10
nmaududi 0:4fb921928934 146 extern UCHAR msg_buf[MSG_BUF_SIZE]; // declare the storage for UART received messages
nmaududi 0:4fb921928934 147 extern UCHAR msg_buf_idx; // index into the received message buffer
nmaududi 0:4fb921928934 148
nmaududi 0:4fb921928934 149 #endif
nmaududi 0:4fb921928934 150
nmaududi 0:4fb921928934 151 /*******************************************************************************
bcis93 1:9fa7cc80f1a7 152 * All function prototypes are visible in all the modules.
nmaududi 0:4fb921928934 153 *******************************************************************************/
bcis93 1:9fa7cc80f1a7 154 void monitor(void); /* located in module monitor.c */
bcis93 1:9fa7cc80f1a7 155 void timer0(void); /* located in module timer0.c */
bcis93 1:9fa7cc80f1a7 156 void serial(void); /* located in module UART_poll.c */
nmaududi 0:4fb921928934 157
bcis93 1:9fa7cc80f1a7 158 void UART_put(UCHAR); /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 159 UCHAR UART_get(void); /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 160 UCHAR UART_input(void); /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 161 void UART_direct_msg_put(const char *);
nmaududi 0:4fb921928934 162 /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 163 void UART_msg_put(const char *);
nmaududi 0:4fb921928934 164 /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 165 void UART_direct_hex_put(UCHAR); /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 166 void UART_direct_hex_put_word(uint32_t c);
bcis93 1:9fa7cc80f1a7 167 void UART_direct_put(UCHAR); /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 168 void UART_hex_put(UCHAR); /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 169 void UART_low_nibble_put(UCHAR); /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 170 void UART_high_nibble_put(UCHAR); /* located in module UART_poll.c */
bcis93 1:9fa7cc80f1a7 171 void chk_UART_msg(void); /* located in module monitor.c */
bcis93 1:9fa7cc80f1a7 172 void UART_msg_process(void); /* located in module monitors.c */
bcis93 1:9fa7cc80f1a7 173 void status_report(void); /* located in module monitor.c */
bcis93 1:9fa7cc80f1a7 174 void set_display_mode(void); /* located in module monitor.c */
bcis93 1:9fa7cc80f1a7 175 void UART_direct_hex_put_word(uint32_t); /* located in module monitor.c */
bcis93 1:9fa7cc80f1a7 176 float calculateViscosity(int16_t); /* located in module Calculate_flow.c */
bcis93 1:9fa7cc80f1a7 177 float calculateDensity(int16_t); /* located in module Calculate_flow.c */
bcis93 1:9fa7cc80f1a7 178 float calculateReynoldsNumber(float, float, float); /* located in module Calculate_flow.c */
bcis93 1:9fa7cc80f1a7 179 float calculateStrouhalNumber(float); /* located in module Calculate_flow.c */
bcis93 1:9fa7cc80f1a7 180 float calculateVelocity(uint16_t, float); /* located in module Calculate_flow.c */
bcis93 1:9fa7cc80f1a7 181 float convertVelocityMetersToInches(float); /* located in module Calculate_flow.c */
bcis93 1:9fa7cc80f1a7 182 void calculateFlow(void); /* located in module Calculate_flow.c */
bcis93 1:9fa7cc80f1a7 183 void read_ADC(uint8_t);
bcis93 1:9fa7cc80f1a7 184 void frequency_detect(void);
bcis93 1:9fa7cc80f1a7 185 void adc_calibration(void);
bcis93 1:9fa7cc80f1a7 186 void PwmOutputs_flowmeter(void);
bcis93 1:9fa7cc80f1a7 187 void Pulse_Output_Frequency(void);
bcis93 1:9fa7cc80f1a7 188 void LCD_Display(void);
nmaududi 0:4fb921928934 189
nmaududi 0:4fb921928934 190 #ifdef __cplusplus
nmaududi 0:4fb921928934 191 }
nmaududi 0:4fb921928934 192
nmaududi 0:4fb921928934 193 #endif
nmaududi 0:4fb921928934 194
nmaududi 0:4fb921928934 195