Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
shared.h@1:9fa7cc80f1a7, 2019-10-04 (annotated)
- Committer:
- bcis93
- Date:
- Fri Oct 04 22:03:30 2019 +0000
- Revision:
- 1:9fa7cc80f1a7
- Parent:
- 0:4fb921928934
- Child:
- 2:64a34ae90bb1
compiled;
Who changed what in which revision?
| User | Revision | Line number | New 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 | #define SAMPLES_SECOND 1/SEC /* # of seoconds between sample used in frequency detection (100 usec.) */ |
| nmaududi | 0:4fb921928934 | 45 | |
| nmaududi | 0:4fb921928934 | 46 | #define T100MS 0.1*SEC |
| nmaududi | 0:4fb921928934 | 47 | #define T2S 2*SEC |
| nmaududi | 0:4fb921928934 | 48 | |
| nmaududi | 0:4fb921928934 | 49 | #define LED_FLASH_PERIOD .5 /* in seconds */ |
| nmaududi | 0:4fb921928934 | 50 | |
| nmaududi | 0:4fb921928934 | 51 | #define CLOCK_FREQUENCY_MHZ 8 |
| nmaududi | 0:4fb921928934 | 52 | #define CODE_VERSION "2.0 2016/09/29" /* YYYY/MM/DD */ |
| nmaududi | 0:4fb921928934 | 53 | #define COPYRIGHT "Copyright (c) University of Colorado" |
| nmaududi | 0:4fb921928934 | 54 | |
| nmaududi | 0:4fb921928934 | 55 | enum boolean { FALSE, TRUE }; /// \enum boolean |
| nmaududi | 0:4fb921928934 | 56 | enum dmode {QUIET, NORMAL, DEBUG, VERSION}; |
| nmaududi | 0:4fb921928934 | 57 | |
| nmaududi | 0:4fb921928934 | 58 | typedef unsigned char UCHAR; |
| nmaududi | 0:4fb921928934 | 59 | typedef unsigned char bit; |
| nmaududi | 0:4fb921928934 | 60 | typedef unsigned int uint32_t; |
| nmaududi | 0:4fb921928934 | 61 | typedef unsigned short uint16_t; |
| nmaududi | 0:4fb921928934 | 62 | typedef signed short int16_t; |
| nmaududi | 0:4fb921928934 | 63 | |
| nmaududi | 0:4fb921928934 | 64 | #ifdef __cplusplus |
| nmaududi | 0:4fb921928934 | 65 | extern "C" { |
| nmaududi | 0:4fb921928934 | 66 | #endif |
| nmaududi | 0:4fb921928934 | 67 | |
| nmaududi | 0:4fb921928934 | 68 | /************************************************************************/ |
| nmaududi | 0:4fb921928934 | 69 | /* Global Variable declarations */ |
| nmaududi | 0:4fb921928934 | 70 | /************************************************************************/ |
| nmaududi | 0:4fb921928934 | 71 | |
| nmaududi | 0:4fb921928934 | 72 | extern unsigned char Error_status; // Variable for debugging use |
| nmaududi | 0:4fb921928934 | 73 | extern UCHAR display_timer; // \var 1 second software timer for display |
| nmaududi | 0:4fb921928934 | 74 | extern UCHAR display_flag; // flag between timer interrupt and monitor.c, |
| nmaududi | 0:4fb921928934 | 75 | extern UCHAR LED_timer_flag; // flag between timer interrupt and main.c, |
| nmaududi | 0:4fb921928934 | 76 | // like a binary semaphore |
| nmaududi | 0:4fb921928934 | 77 | extern UCHAR tx_in_progress; |
| nmaududi | 0:4fb921928934 | 78 | extern UCHAR *rx_in_ptr; /* pointer to the receive in data */ |
| nmaududi | 0:4fb921928934 | 79 | extern UCHAR *rx_out_ptr; /* pointer to the receive out data*/ |
| nmaududi | 0:4fb921928934 | 80 | extern UCHAR *tx_in_ptr; /* pointer to the transmit in data*/ |
| nmaududi | 0:4fb921928934 | 81 | extern UCHAR *tx_out_ptr; /*pointer to the transmit out */ |
| nmaududi | 0:4fb921928934 | 82 | 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 | 83 | extern uint16_t temperature; // value that will be external to all variable. stores the value of temperature |
| nmaududi | 0:4fb921928934 | 84 | extern uint16_t Vtemp; // value in mV of the temperature calculated |
| nmaududi | 0:4fb921928934 | 85 | extern uint16_t freq_value; // value that will store the frequency detected. Need it to be availaible to all functions |
| nmaududi | 0:4fb921928934 | 86 | extern uint16_t flow; // value that will store the flow that is determine |
| nmaududi | 0:4fb921928934 | 87 | extern uint16_t ADC_vortex_frequency_input; // value of the ADC_vortex_frequency_input |
| nmaududi | 0:4fb921928934 | 88 | extern uint16_t Vrefl; // value of the ADC_vortex_frequency_input |
| nmaududi | 0:4fb921928934 | 89 | |
| nmaududi | 0:4fb921928934 | 90 | #define RX_BUF_SIZE 10 /* size of receive buffer in bytes */ |
| nmaududi | 0:4fb921928934 | 91 | #define TX_BUF_SIZE 10 /* size of transmit buffer in bytes */ |
| nmaududi | 0:4fb921928934 | 92 | |
| nmaududi | 0:4fb921928934 | 93 | /****************************************************************************** |
| nmaududi | 0:4fb921928934 | 94 | * Some variable definitions are done in the module main.c and are externed in |
| nmaududi | 0:4fb921928934 | 95 | * all other modules. The following section is visible to main.c only. |
| nmaududi | 0:4fb921928934 | 96 | ******************************************************************************/ |
| nmaududi | 0:4fb921928934 | 97 | #ifdef MAIN |
| nmaududi | 0:4fb921928934 | 98 | |
| nmaududi | 0:4fb921928934 | 99 | enum dmode display_mode = QUIET; |
| nmaududi | 0:4fb921928934 | 100 | |
| nmaududi | 0:4fb921928934 | 101 | UCHAR serial_flag = 0; |
| nmaududi | 0:4fb921928934 | 102 | |
| nmaududi | 0:4fb921928934 | 103 | UCHAR tx_in_progress; |
| nmaududi | 0:4fb921928934 | 104 | UCHAR *rx_in_ptr; /* pointer to the receive in data */ |
| nmaududi | 0:4fb921928934 | 105 | UCHAR *rx_out_ptr; /* pointer to the receive out data*/ |
| nmaududi | 0:4fb921928934 | 106 | UCHAR *tx_in_ptr; /* pointer to the transmit in data*/ |
| nmaududi | 0:4fb921928934 | 107 | UCHAR *tx_out_ptr; /*pointer to the transmit out */ |
| nmaududi | 0:4fb921928934 | 108 | |
| nmaududi | 0:4fb921928934 | 109 | UCHAR rx_buf[RX_BUF_SIZE]; /* define the storage */ |
| nmaududi | 0:4fb921928934 | 110 | UCHAR tx_buf[TX_BUF_SIZE]; /* define the storage */ |
| nmaududi | 0:4fb921928934 | 111 | |
| nmaududi | 0:4fb921928934 | 112 | #define MSG_BUF_SIZE 10 |
| nmaududi | 0:4fb921928934 | 113 | UCHAR msg_buf[MSG_BUF_SIZE]; // define the storage for UART received messages |
| nmaududi | 0:4fb921928934 | 114 | UCHAR msg_buf_idx = 0; // index into the received message buffer |
| nmaududi | 0:4fb921928934 | 115 | |
| nmaududi | 0:4fb921928934 | 116 | /****************************************************************************** |
| nmaududi | 0:4fb921928934 | 117 | * Some variable definitions are done in the module main.c and are externed in |
| nmaududi | 0:4fb921928934 | 118 | * all other modules. The following section is visible to all modules EXCEPT |
| nmaududi | 0:4fb921928934 | 119 | * main.c. |
| nmaududi | 0:4fb921928934 | 120 | *******************************************************************************/ |
| nmaududi | 0:4fb921928934 | 121 | #else |
| nmaududi | 0:4fb921928934 | 122 | |
| nmaududi | 0:4fb921928934 | 123 | /**********************/ |
| nmaududi | 0:4fb921928934 | 124 | /* Declarations */ |
| nmaududi | 0:4fb921928934 | 125 | /**********************/ |
| nmaududi | 0:4fb921928934 | 126 | |
| nmaududi | 0:4fb921928934 | 127 | extern volatile UCHAR swtimer0; |
| nmaududi | 0:4fb921928934 | 128 | extern volatile UCHAR swtimer1; |
| nmaududi | 0:4fb921928934 | 129 | extern volatile UCHAR swtimer2; |
| nmaududi | 0:4fb921928934 | 130 | extern volatile UCHAR swtimer3; |
| nmaududi | 0:4fb921928934 | 131 | extern volatile UCHAR swtimer4; |
| nmaududi | 0:4fb921928934 | 132 | extern volatile UCHAR swtimer5; |
| nmaududi | 0:4fb921928934 | 133 | extern volatile UCHAR swtimer6; |
| nmaududi | 0:4fb921928934 | 134 | extern volatile UCHAR swtimer7; |
| nmaududi | 0:4fb921928934 | 135 | |
| nmaududi | 0:4fb921928934 | 136 | extern UCHAR serial_flag; |
| nmaududi | 0:4fb921928934 | 137 | |
| nmaududi | 0:4fb921928934 | 138 | extern enum dmode display_mode; |
| nmaududi | 0:4fb921928934 | 139 | |
| nmaududi | 0:4fb921928934 | 140 | |
| nmaududi | 0:4fb921928934 | 141 | extern UCHAR rx_buf[]; /* declare the storage */ |
| nmaududi | 0:4fb921928934 | 142 | extern UCHAR tx_buf[]; /* declare the storage */ |
| nmaududi | 0:4fb921928934 | 143 | |
| nmaududi | 0:4fb921928934 | 144 | #define MSG_BUF_SIZE 10 |
| nmaududi | 0:4fb921928934 | 145 | extern UCHAR msg_buf[MSG_BUF_SIZE]; // declare the storage for UART received messages |
| nmaududi | 0:4fb921928934 | 146 | extern UCHAR msg_buf_idx; // index into the received message buffer |
| nmaududi | 0:4fb921928934 | 147 | |
| nmaududi | 0:4fb921928934 | 148 | #endif |
| nmaududi | 0:4fb921928934 | 149 | |
| nmaududi | 0:4fb921928934 | 150 | /******************************************************************************* |
| bcis93 | 1:9fa7cc80f1a7 | 151 | * All function prototypes are visible in all the modules. |
| nmaududi | 0:4fb921928934 | 152 | *******************************************************************************/ |
| bcis93 | 1:9fa7cc80f1a7 | 153 | void monitor(void); /* located in module monitor.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 154 | void timer0(void); /* located in module timer0.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 155 | void serial(void); /* located in module UART_poll.c */ |
| nmaududi | 0:4fb921928934 | 156 | |
| bcis93 | 1:9fa7cc80f1a7 | 157 | void UART_put(UCHAR); /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 158 | UCHAR UART_get(void); /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 159 | UCHAR UART_input(void); /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 160 | void UART_direct_msg_put(const char *); |
| nmaududi | 0:4fb921928934 | 161 | /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 162 | void UART_msg_put(const char *); |
| nmaududi | 0:4fb921928934 | 163 | /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 164 | void UART_direct_hex_put(UCHAR); /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 165 | void UART_direct_hex_put_word(uint32_t c); |
| bcis93 | 1:9fa7cc80f1a7 | 166 | void UART_direct_put(UCHAR); /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 167 | void UART_hex_put(UCHAR); /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 168 | void UART_low_nibble_put(UCHAR); /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 169 | void UART_high_nibble_put(UCHAR); /* located in module UART_poll.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 170 | void chk_UART_msg(void); /* located in module monitor.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 171 | void UART_msg_process(void); /* located in module monitors.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 172 | void status_report(void); /* located in module monitor.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 173 | void set_display_mode(void); /* located in module monitor.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 174 | void UART_direct_hex_put_word(uint32_t); /* located in module monitor.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 175 | float calculateViscosity(int16_t); /* located in module Calculate_flow.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 176 | float calculateDensity(int16_t); /* located in module Calculate_flow.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 177 | float calculateReynoldsNumber(float, float, float); /* located in module Calculate_flow.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 178 | float calculateStrouhalNumber(float); /* located in module Calculate_flow.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 179 | float calculateVelocity(uint16_t, float); /* located in module Calculate_flow.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 180 | float convertVelocityMetersToInches(float); /* located in module Calculate_flow.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 181 | void calculateFlow(void); /* located in module Calculate_flow.c */ |
| bcis93 | 1:9fa7cc80f1a7 | 182 | void read_ADC(uint8_t); |
| bcis93 | 1:9fa7cc80f1a7 | 183 | void frequency_detect(void); |
| bcis93 | 1:9fa7cc80f1a7 | 184 | void adc_calibration(void); |
| bcis93 | 1:9fa7cc80f1a7 | 185 | void PwmOutputs_flowmeter(void); |
| bcis93 | 1:9fa7cc80f1a7 | 186 | void Pulse_Output_Frequency(void); |
| bcis93 | 1:9fa7cc80f1a7 | 187 | void LCD_Display(void); |
| nmaududi | 0:4fb921928934 | 188 | |
| nmaududi | 0:4fb921928934 | 189 | #ifdef __cplusplus |
| nmaududi | 0:4fb921928934 | 190 | } |
| nmaududi | 0:4fb921928934 | 191 | |
| nmaududi | 0:4fb921928934 | 192 | #endif |
| nmaududi | 0:4fb921928934 | 193 | |
| nmaududi | 0:4fb921928934 | 194 |