revised code
Embed:
(wiki syntax)
Show/hide line numbers
shared.h
Go to the documentation of this file.
00001 /**----------------------------------------------------------------------------- 00002 \file shared.h 00003 -- -- 00004 -- ECEN 5803 Mastering Embedded System Architecture -- 00005 -- Project 1 Module 4 -- 00006 -- Microcontroller Firmware -- 00007 -- shared.h -- 00008 -- -- 00009 ------------------------------------------------------------------------------- 00010 -- 00011 -- Designed for: University of Colorado at Boulder 00012 -- 00013 -- 00014 -- Designed by: Tim Scherr 00015 -- Revised by: Naved Maududi and Bryan Cisneros 00016 -- 00017 -- Version: 2.1 00018 -- Date of current revision: 2017-09-25 00019 -- Target Microcontroller: Freescale MKL25ZVMT4 00020 -- Tools used: ARM mbed compiler 00021 -- ARM mbed SDK 00022 -- Freescale FRDM-KL25Z Freedom Board 00023 -- 00024 -- 00025 -- Functional Description: Header file for all globals 00026 -- 00027 -- Copyright (c) 2015, 2016 Tim Scherr All rights reserved. 00028 -- 00029 */ 00030 00031 #include "mbed.h" 00032 00033 /***************************************************************************** 00034 * #defines available to all modules included here 00035 ******************************************************************************/ 00036 #define OFF 0 /* used for readability */ 00037 #define ON 1 /* used for readability */ 00038 #define NO 0 /* used for readability */ 00039 #define YES 1 /* used for readability */ 00040 #define TEN 10 00041 00042 #define TIMER0 TMR0 00043 #define SEC 10000 /* 10000 timer0 interrupts per second (100 usec.) */ 00044 00045 #define T100MS 0.1*SEC 00046 #define T2S 2*SEC 00047 00048 #define LED_FLASH_PERIOD .5 /* in seconds */ 00049 00050 #define CLOCK_FREQUENCY_MHZ 8 00051 #define CODE_VERSION "2.0 2016/09/29" /* YYYY/MM/DD */ 00052 #define COPYRIGHT "Copyright (c) University of Colorado" 00053 00054 enum boolean { FALSE, TRUE }; /// \enum boolean 00055 enum dmode {QUIET, NORMAL, DEBUG, VERSION}; 00056 00057 typedef unsigned char UCHAR; 00058 typedef unsigned char bit; 00059 typedef unsigned int uint32_t; 00060 typedef unsigned short uint16_t; 00061 typedef signed short int16_t; 00062 00063 #ifdef __cplusplus 00064 extern "C" { 00065 #endif 00066 00067 /************************************************************************/ 00068 /* Global Variable declarations */ 00069 /************************************************************************/ 00070 00071 extern unsigned char Error_status; // Variable for debugging use 00072 extern UCHAR display_timer; // \var 1 second software timer for display 00073 extern UCHAR display_flag; // flag between timer interrupt and monitor.c, 00074 extern UCHAR LED_timer_flag; // flag between timer interrupt and main.c, 00075 // like a binary semaphore 00076 extern UCHAR tx_in_progress; 00077 extern UCHAR *rx_in_ptr; /* pointer to the receive in data */ 00078 extern UCHAR *rx_out_ptr; /* pointer to the receive out data*/ 00079 extern UCHAR *tx_in_ptr; /* pointer to the transmit in data*/ 00080 extern UCHAR *tx_out_ptr; /*pointer to the transmit out */ 00081 extern uint16_t ADC_buffer; // value that ADC will read in, need to be external so that flow function can read in 00082 extern uint16_t temperature; // value that will be external to all variable. stores the value of temperature 00083 extern int Vtemp; // value in mV of the temperature calculated 00084 extern uint16_t freq_value; // value that will store the frequency detected. Need it to be availaible to all functions 00085 extern uint16_t flow; // value that will store the flow that is determine 00086 extern uint16_t ADC_vortex_frequency_input; // value of the ADC_vortex_frequency_input 00087 extern uint16_t Vrefl; // value of the ADC_vortex_frequency_input 00088 extern double zero_detect_counter; 00089 extern UCHAR reset_counter_flag; 00090 00091 #define RX_BUF_SIZE 10 /* size of receive buffer in bytes */ 00092 #define TX_BUF_SIZE 10 /* size of transmit buffer in bytes */ 00093 00094 /****************************************************************************** 00095 * Some variable definitions are done in the module main.c and are externed in 00096 * all other modules. The following section is visible to main.c only. 00097 ******************************************************************************/ 00098 #ifdef MAIN 00099 00100 enum dmode display_mode = QUIET; 00101 00102 UCHAR serial_flag = 0; 00103 00104 UCHAR tx_in_progress; 00105 UCHAR *rx_in_ptr; /* pointer to the receive in data */ 00106 UCHAR *rx_out_ptr; /* pointer to the receive out data*/ 00107 UCHAR *tx_in_ptr; /* pointer to the transmit in data*/ 00108 UCHAR *tx_out_ptr; /*pointer to the transmit out */ 00109 00110 UCHAR rx_buf[RX_BUF_SIZE]; /* define the storage */ 00111 UCHAR tx_buf[TX_BUF_SIZE]; /* define the storage */ 00112 00113 #define MSG_BUF_SIZE 10 00114 UCHAR msg_buf[MSG_BUF_SIZE]; // define the storage for UART received messages 00115 UCHAR msg_buf_idx = 0; // index into the received message buffer 00116 00117 /****************************************************************************** 00118 * Some variable definitions are done in the module main.c and are externed in 00119 * all other modules. The following section is visible to all modules EXCEPT 00120 * main.c. 00121 *******************************************************************************/ 00122 #else 00123 00124 /**********************/ 00125 /* Declarations */ 00126 /**********************/ 00127 00128 extern volatile UCHAR swtimer0; 00129 extern volatile UCHAR swtimer1; 00130 extern volatile UCHAR swtimer2; 00131 extern volatile UCHAR swtimer3; 00132 extern volatile UCHAR swtimer4; 00133 extern volatile UCHAR swtimer5; 00134 extern volatile UCHAR swtimer6; 00135 extern volatile UCHAR swtimer7; 00136 00137 extern UCHAR serial_flag; 00138 00139 extern enum dmode display_mode; 00140 00141 00142 extern UCHAR rx_buf[]; /* declare the storage */ 00143 extern UCHAR tx_buf[]; /* declare the storage */ 00144 00145 #define MSG_BUF_SIZE 10 00146 extern UCHAR msg_buf[MSG_BUF_SIZE]; // declare the storage for UART received messages 00147 extern UCHAR msg_buf_idx; // index into the received message buffer 00148 00149 #endif 00150 00151 /******************************************************************************* 00152 * All function prototypes are visible in all the modules. 00153 *******************************************************************************/ 00154 void monitor(void); /* located in module monitor.c */ 00155 void timer0(void); /* located in module timer0.c */ 00156 void serial(void); /* located in module UART_poll.c */ 00157 00158 void UART_put(UCHAR); /* located in module UART_poll.c */ 00159 UCHAR UART_get(void); /* located in module UART_poll.c */ 00160 UCHAR UART_input(void); /* located in module UART_poll.c */ 00161 void UART_direct_msg_put(const char *); 00162 /* located in module UART_poll.c */ 00163 void UART_msg_put(const char *); 00164 /* located in module UART_poll.c */ 00165 void UART_direct_hex_put(UCHAR); /* located in module UART_poll.c */ 00166 void UART_direct_hex_put_word(uint32_t c); 00167 void UART_direct_put(UCHAR); /* located in module UART_poll.c */ 00168 void UART_hex_put(UCHAR); /* located in module UART_poll.c */ 00169 void UART_low_nibble_put(UCHAR); /* located in module UART_poll.c */ 00170 void UART_high_nibble_put(UCHAR); /* located in module UART_poll.c */ 00171 void chk_UART_msg(void); /* located in module monitor.c */ 00172 void UART_msg_process(void); /* located in module monitors.c */ 00173 void status_report(void); /* located in module monitor.c */ 00174 void set_display_mode(void); /* located in module monitor.c */ 00175 void UART_direct_hex_put_word(uint32_t); /* located in module monitor.c */ 00176 float calculateViscosity(int16_t); /* located in module Calculate_flow.c */ 00177 float calculateDensity(int16_t); /* located in module Calculate_flow.c */ 00178 float calculateReynoldsNumber(float, float, float); /* located in module Calculate_flow.c */ 00179 float calculateStrouhalNumber(float); /* located in module Calculate_flow.c */ 00180 float calculateVelocity(uint16_t, float); /* located in module Calculate_flow.c */ 00181 float convertVelocityMetersToInches(float); /* located in module Calculate_flow.c */ 00182 void calculateFlow(void); /* located in module Calculate_flow.c */ 00183 void read_ADC(uint8_t); 00184 void frequency_detect(void); 00185 void adc_calibration(void); 00186 void PwmOutputs_flowmeter(void); 00187 void Pulse_Output_Frequency(void); 00188 void LCD_Display(void); 00189 00190 #ifdef __cplusplus 00191 } 00192 00193 #endif 00194 00195
Generated on Tue Jul 12 2022 20:46:01 by
1.7.2