Skip to content
Snippets Groups Projects
Commit 0d587e2c authored by Leonardo Martinez Hornak's avatar Leonardo Martinez Hornak
Browse files

Merge with firmware_leo - working

parents 8c1b486a 89f91ad6
Branches firmware firmware_isa
No related tags found
No related merge requests found
Showing
with 859 additions and 16 deletions
......@@ -15,3 +15,6 @@
#Whitelist c files inside subdirectories
!**/*.c
!**/*.h
#Whitelist python files inside subdirectories
!**/*.py
\ No newline at end of file
/**
* @file adc.h
* @brief ADC Module header
*
* Proyecto Smart Watch - ADC
* ADC module
*
* This module is used to configure the
* ADC14, start adc conversion and get last temperature using the internal sensor
*
* adc.h
* Module that allows the configuration of the ADC14 and getting the temperature reading
*
* @authors Leonardo Martínez <leonardo.martinez.hornak@fing.edu.uy>, Isabel Morales <imorales@fing.edu.uy>
* @version 1.0
* @date May 15, 2021
*/
#ifndef INCLUDE_ADC_H_
#define INCLUDE_ADC_H_
/**
* @brief Initializes REFA and ADC14, configuring it to use the temperature sensor
*/
void initializeADC();
/**
* @brief Sets callback function to be added from this module to the function queue
* @param void* callback_function: function to be called when a temperature reading is ready
*
*/
void setTempCallbackFunction(void *callback_function);
/**
* @brief Start ADC conversion
*/
void runADCConversion(void);
/**
* @brief Obtains the last temperature reading in celsius
* @return int temperature in celsius degrees
*
*/
int getTemperatureReading(void);
#endif /* INCLUDE_ADC_H_ */
/**
* @file alarmas.h
* @brief Alarms Module header
*
* Proyecto Smart Watch - Alarms
* Alarms module
*
* This module is used to configure and set alarms
*
* alarms.h
* Module used to configure and set alarms
*
* @authors Leonardo Martínez <leonardo.martinez.hornak@fing.edu.uy>, Isabel Morales <imorales@fing.edu.uy>
* @version 1.0
* @date May 29, 2021
*/
#ifndef INCLUDE_ALARMS_H_
#define INCLUDE_ALARMS_H_
/**
* @brief Initializes the module
*
*/
void initializeAlarmsManagement(void);
/**
* @brief Sets Heart Alarm
* @param int minimum_value: in beats per minute (bpm)
* @param int maximum_value: in beats per minute (bpm)
*
*/
void setHeartRateAlarm(int minimum_value, int maximum_value);
/**
* @brief Sets SpO2 Alarm
* @param int minimum_value: in percentage (%)
* @param int maximum_value: in percentage (%)
*
*/
void setSpO2Alarm(int minimum_value, int maximum_value);
/**
* @brief Sets Temperature Alarm
* @param int minimum_value: in celsius degrees (%)
* @param int maximum_value: in celsius degrees (%)
*
*/
void setTemperatureAlarm(int minimum_value, int maximum_value);
/**
* @brief Sets Respiration Rate Alarm
* @param int minimum_value: in breaths per minute (bpm)
* @param int maximum_value: in breaths per minute (bpm)
*
*/
void setRespirationRateAlarm(int minimum_value, int maximum_value);
#endif /* INCLUDE_ALARMS_H_ */
/**
* @file body_temperature.h
* @brief Body Temperature Module header
*
* Proyecto Smart Watch - Body Temperature
* Body Temperature module
*
* This module is used to get the body temperature of the user
*
* body_temperature.h
* Module that provides the body temperature of the user
*
* @authors Leonardo Martínez <leonardo.martinez.hornak@fing.edu.uy>, Isabel Morales <imorales@fing.edu.uy>
* @version 1.0
* @date May 15, 2021
*/
#ifndef INCLUDE_BODY_TEMPERATURE_H_
#define INCLUDE_BODY_TEMPERATURE_H_
/**
* @brief Initializes the module (eg. set function callback to be called when a new temperature reading is available
*
*/
void initializeBodyTemperature(void);
/**
* @brief Obtains the last temperature reading in milicelsius
* @return int temperature in celsius degrees divided by 1000
*
*/
int getLastTemperatureReading(void);
#endif /* INCLUDE_BODY_TEMPERATURE_H_ */
......@@ -13,9 +13,33 @@
//#define DEBUG
#define FUNCTION_QUEUE_DIMENSION 2000
#define SLOW_ISR_FUNCTION_CALL_TICK 250 //Miliseconds time for slow function to be called
#define FAST_ISR_FUNCTION_CALL_TICK 10 //Miliseconds time for fast function to be called
//ADC
#define REF_VOLTAGE_DIV_BY_ADC_10BITS_RESOLUTION 1.17
//Communications
#define COMM_BUFFER_UART_DIMENSION_TX 20
#define COMM_BUFFER_UART_DIMENSION_RX 20
#define COMM_BUFFER_BT_DIMENSION_TX 200
#define COMM_BUFFER_BT_DIMENSION_RX 200
#define START_CHARACTER_PROCESSED 0xFF
#define START_CHARACTER_RAW 0xFE
#define START_CHARACTER_OK 0xFD
#define START_CHARACTER_ERROR 0xFC
#define END_CHARACTER 0xEF
#define MESSAGE_ID_HR_ALARM 0xAA
#define MESSAGE_ID_SPO2_ALARM 0xAB
#define MESSAGE_ID_RR_ALARM 0xAC
#define MESSAGE_ID_TEMP_ALARM 0xAD
//Bluetooth
#define BLUETOOTH_CONFIGURED //Used to enter configuration mode of the HC-06. Uncomment it when configured. Needs to be done only once as data is retained by the module
//Timing
#define SLOW_ISR_FUNCTION_CALL_TICK 250 //Miliseconds time for slow function to be called
#define FAST_ISR_FUNCTION_CALL_TICK 10 //Miliseconds time for fast function to be called
#endif /* INCLUDE_COMMON_H_ */
/**
* @file communications.h
* @brief Communications Module header
*
* Proyecto Smart Watch - UART
* Communications module
*
* This module is used to configure the
* device peripheral used for communications with the PC and send/receive data, transmit data
*
* communications.h
* Module that allows the configuration of the interface of communications between the smartwatch and the external world
*
* @authors Leonardo Martínez <leonardo.martinez.hornak@fing.edu.uy>, Isabel Morales <imorales@fing.edu.uy>
* @version 1.0
* @date May 15, 2021
*/
#ifndef INCLUDE_COMMUNICATIONS_H_
#define INCLUDE_COMMUNICATIONS_H_
/**
* @brief Initializes communication module
*/
void initializeCommunications(void);
/**
* @brief Sends processed values using Bluetooth interface
*
*/
void sendProcessedValues(void);
/**
* @brief Sends confirmation message using Bluetooth interface
*
*/
void sendConfirmationMessage(void);
/**
* @brief Sends error message using Bluetooth interface
*
*/
void sendErrorMessage(void);
/**
* @brief Sends raw values using Bluetooth interface
*
*/
void sendRawValues(void);
#endif /* INCLUDE_COMMUNICATIONS_H_ */
......@@ -19,10 +19,7 @@
#ifndef INCLUDE_I2C_H_
#define INCLUDE_I2C_H_
//#define QUEUE_DIMENSION_I2C_R 400*2
#define QUEUE_DIMENSION_I2C_R 4000
#define QUEUE_DIMENSION_I2C_R 400*2
#define QUEUE_DIMENSION_I2C_W 10*2
#define I2C_STATE_NO_ERROR 0
......
......@@ -24,10 +24,19 @@
void initializeTimingLogic(void);
/**
* @brief Obtains the current time in milliseconds
* @return unsigned int time: Time in milliseconds
*/
unsigned int getCurrentMilisecondsTime(void);
* @brief Initializes messages transmission over Bluetooth:
*/
void startBluetoothTransmission(void);
/**
* @brief Stops messages transmission over Bluetooth:
*/
void stopBluetoothTransmission(void);
/**
* @brief Set transmission mode of Bluetooth:
*/
void setBluetoothTransmission(void);
/**
* @brief Obtains an auxiliary time in milliseconds
......@@ -40,6 +49,10 @@ unsigned int getAuxiliaryMilisecondsTime(void);
*/
void clearAuxiliaryMilisecondsTime(void);
/**
* @brief Function used to delay program execution by miliseconds_to_wait. It uses Timer Interrupts.
* @param int miliseconds_to_wait: Time in miliseconds to wait
*/
void waitMilliseconds(int miliseconds_to_wait);
#endif /* INCLUDE_TIMING_LOGIC_H_ */
/**
* @file uart.h
* @brief UART Module header
*
* Proyecto Smart Watch - UART
* UART module
*
* This module is used to configure the
* UART peripheral of the MSP432P401R, transmit data and receive data using the peripheral
*
* uart.h
* Modules that allows the configuration of the UART peripheral of the MSP432P401R
*
* @authors Leonardo Martínez <leonardo.martinez.hornak@fing.edu.uy>, Isabel Morales <imorales@fing.edu.uy>
* @version 1.0
* @date May 15, 2021
*/
#ifndef INCLUDE_UART_H_
#define INCLUDE_UART_H_
#define QUEUE_DIMENSION_UART_RX 200
#define QUEUE_DIMENSION_UART_TX 200
#define UART_TRAILING_CHARACTER 0x0D
#define UART_END_CHARACTER 0xEF
/**
* @brief Initializes UART module
*/
void initializeUART(void);
/**
* @brief Sets callback function to be added from this module to the function queue
* @param void* callback_function: function to be called when a new message is available
*
*/
void setUartCallbackFunction(void *callback_function);
/**
* @brief Sends a char array using UART module
* @param char* buffer_pointer: auxiliary buffer pointer which contains data to be transmitted
*
*/
void uartTransmit(char* buffer_pointer);
/**
* @brief Copies message received by the UART module into an external char array indicated by buffer_pointer
* @param char* buffer_pointer: auxiliary buffer pointer which points to the address to use for copying the message
* @param int* bytes_received: pointer used to return the number of bytes received by reference
*/
void uartReceive(char* buffer_pointer, int* bytes_received);
#endif /* INCLUDE_UART_H_ */
/**
* @file uartBluetooth.h
* @brief UART Bluetooth Module header
*
* Proyecto Smart Watch - UART Bluetooth
* UART Bluetooth module
*
* This module is used to configure the
* UART peripheral of the MSP432P401R used for the HC-06 module. It will be used to send and receive data
* using EUSCI_A2.
*
* uartBluetooth.h
* Modules that allows the configuration of the UART peripheral of the MSP432P401R for the HC-06
*
* @authors Leonardo Martínez <leonardo.martinez.hornak@fing.edu.uy>, Isabel Morales <imorales@fing.edu.uy>
* @version 1.0
* @date May 23, 2021
*/
#ifndef INCLUDE_UARTBLUETOOTH_H_
#define INCLUDE_UARTBLUETOOTH_H_
#include "common.h"
#define QUEUE_DIMENSION_BT_RX 200
#define QUEUE_DIMENSION_BT_TX 200
#define BT_TRAILING_CHARACTER_1 0x0D
#define BT_TRAILING_CHARACTER_2 0x0A
/**
* @brief Initializes UART module
*/
void initializeUARTBluetooth(void);
/**
* @brief Sets callback function to be added from this module to the function queue
* @param void* callback_function: function to be called when a new message is available
*
*/
void setUartBluetoothCallbackFunction(void *callback_function);
/**
* @brief Sends a char array using UART Bluetooth module
* @param char* buffer_pointer: auxiliary buffer pointer which contains data to be transmitted
* @param int length: when bluetooth module is configured, it indicates the length of data to send
*
*/
#ifdef BLUETOOTH_CONFIGURED
void uartBluetoothTransmit(char* buffer_pointer, int length);
#else
void uartBluetoothTransmit(char* buffer_pointer);
#endif
/**
* @brief Copies message received by the UART module into an external char array indicated by buffer_pointer
* @param char* buffer_pointer: auxiliary buffer pointer which points to the address to use for copying the message
* @param int* bytes_received: pointer used to return the number of bytes received by reference
*
*/
void uartBluetoothReceive(char* buffer_pointer, int* bytes_received);
#endif /* INCLUDE_UARTBLUETOOTH_H_ */
......@@ -53,4 +53,10 @@ void turnOnDebugLED(void);
*/
void turnOffDebugLED(void);
//TODO Remove
/**
* @brief Turns off debug LED for alarms test
*/
void test_alarms(void);
#endif /* INCLUDE_USER_INTERFACE_H_ */
......@@ -2,6 +2,8 @@
#include "fifo_function_queue.h"
#include "user_interface.h"
#include "gpio.h"
#include "body_temperature.h"
#include "communications.h"
#include "timing_logic.h"
#include "i2c.h"
#include "sen_15219.h"
......@@ -18,14 +20,17 @@ void main(void)
initFunctionQueue();
initializeGPIOModule();
initializeUserInterface();
initializeBodyTemperature();
initializeCommunications();
initializeTimingLogic();
__enable_irq();
initializeSen15219();
//TODO See shared data issue
while(1)
while(1)
{
if(!functionQueueIsEmpty())
{
......@@ -37,5 +42,4 @@ void main(void)
__low_power_mode_0();
}
}
}
#include <msp.h>
#include "common.h"
#include "adc.h"
#include "fifo_function_queue.h"
static unsigned int adcval;
//Callback function for queue
void (*temperature_ready_callback)();
void initializeADC(){
//REF_A, waits until reference generator is not busy
while(REFCTL0 & REF_A_CTL0_GENBUSY);
//Set REF_A to be used, temp sensor enabled and REFOUT disabled
REFCTL0 = REF_A_CTL0_ON;
//Sets ADC14ENC to 0 to make modifications to the registers, resets all register just in case
ADC14->CTL0 = 0;
//ADC Clock Divided by 3, SMCLK, Single Channel - Single Conversion, SH signal sourced from sampling timer
ADC14->CTL0 |= ADC14_CTL0_DIV_2 + ADC14_CTL0_SSEL_4 + ADC14_CTL0_SHP;
//TODO Make sure time makes sense when timer is configured - Sample rate must not exceed 200ksps
//Sets default value to CTL1 register and
//sets resolution to 10 bits, low power mode (sample rate must not exceed 200ksps), temperature sensor selected for ADC input channel MAX - 1, ADC14CSTARTADDx = 0
//ADC14->CTL1 = ADC14_CTL1_RES_1 + ADC14_CTL1_PWRMD_2 + ADC14_CTL1_TCMAP;
ADC14->CTL1 = ADC14_CTL1_RES_1 + ADC14_CTL1_TCMAP;
//Sets Channel 22 as input channel, single ended mode, V(R+) = Vref buffered / V(R-) = Vss
ADC14->MCTL[0]= ADC14_MCTLN_INCH_22 + ADC14_MCTLN_VRSEL_1;
//TODO Review this function
//Wait for ADC to stabilize
__delay_cycles(1000);
}
void setTempCallbackFunction(void *callback_function)
{
temperature_ready_callback = callback_function;
}
void runADCConversion(){
//ADC14 is turned on, enable conversion, start conversion,
ADC14->CTL0 |= ADC14_CTL0_ON + ADC14_CTL0_ENC + ADC14_CTL0_SC;
//Enable ISRs (ADC Register 0 - Channel 22)
ADC14 -> IER0 |= ADC14_IER0_IE0;
NVIC_SetPriority(ADC14_IRQn,3);
NVIC_EnableIRQ(ADC14_IRQn);
}
int getTemperatureReading(){
int temp;
float aux;
//Converts ADC Reading to mVolts (1.2 Volts set for reference voltage)
aux = (float)(adcval) * REF_VOLTAGE_DIV_BY_ADC_10BITS_RESOLUTION;
//Converts mVolts to celsius using temperature sensor transfer function (no calibration)
//Using 10 bits resolution
temp = (int)((aux - 686) * 0.512);
return temp;
}
void ADC14_IRQHandler(void)
{
//Reading to ADC14MEM clears the IFG
adcval = ADC14->MEM[0];
ADC14->CTL0 &= ~ADC14_CTL0_ENC;
ADC14->CTL0 &= ~ADC14_CTL0_ON;
//Disable ISRs
ADC14 -> IER0 &= ~ADC14_IER0_IE0;
NVIC_DisableIRQ(ADC14_IRQn);
addToFunctionQueue(temperature_ready_callback);
__low_power_mode_off_on_exit();
}
#include "alarms.h"
#include "user_interface.h"
void initializeAlarmsManagement(void)
{
//TODO Add logic to queue
}
void setHeartRateAlarm(int minimum_value, int maximum_value)
{
test_alarms();
}
void setSpO2Alarm(int minimum_value, int maximum_value)
{
test_alarms();
}
void setTemperatureAlarm(int minimum_value, int maximum_value)
{
test_alarms();
}
void setRespirationRateAlarm(int minimum_value, int maximum_value)
{
test_alarms();
}
#include "body_temperature.h"
#include "adc.h"
void updateTemperatureReading(void);
volatile static int body_temperature;
void initializeBodyTemperature(void)
{
initializeADC();
setTempCallbackFunction(updateTemperatureReading);
}
int getLastTemperatureReading(void)
{
return body_temperature;
}
void updateTemperatureReading(void)
{
body_temperature = getTemperatureReading();
}
#include "msp.h"
#include "communications.h"
#include "common.h"
#include "user_interface.h"
#include "body_temperature.h"
#include "uart.h"
#include "uartBluetooth.h"
#include "fifo_function_queue.h"
#include "alarms.h"
static char rx_buffer_uart[COMM_BUFFER_UART_DIMENSION_RX];
static char tx_buffer_uart[COMM_BUFFER_UART_DIMENSION_TX];
static char rx_buffer_bluetooth[COMM_BUFFER_BT_DIMENSION_RX];
static char tx_buffer_bluetooth[COMM_BUFFER_BT_DIMENSION_TX];
void processUARTIncomingPacket(void);
void processBluetoothIncomingPacket(void);
void cleanBuffer(char *buffer, int size);
#ifndef BLUETOOTH_CONFIGURED
void bluetoothModuleConfiguration(void);
#endif
void initializeCommunications(void)
{
initializeUART();
initializeUARTBluetooth();
setUartCallbackFunction(processUARTIncomingPacket);
setUartBluetoothCallbackFunction(processBluetoothIncomingPacket);
P4OUT |= BIT0;
#ifndef BLUETOOTH_CONFIGURED
addToFunctionQueue(bluetoothModuleConfiguration);
#endif
}
void sendProcessedValues(void)
{
//TODO Adjust to what will be obtained from SEN-15219
int raw_value, i;
tx_buffer_bluetooth[0] = START_CHARACTER_PROCESSED;
tx_buffer_bluetooth[1] = 7;
tx_buffer_bluetooth[2] = (char)getLastTemperatureReading();
//Heart Rate
raw_value = 180;
tx_buffer_bluetooth[3] = (char)(raw_value & 0xFF);
//SpO2
raw_value = 90;
tx_buffer_bluetooth[4] = (char)(raw_value & 0xFF);
//Confidence Level
raw_value = 50;
tx_buffer_bluetooth[5] = (char)(raw_value & 0xFF);
//Respiration
raw_value = 12;
tx_buffer_bluetooth[6] = (char)(raw_value & 0xFF);
tx_buffer_bluetooth[7] = tx_buffer_bluetooth[0];
for(i=0; i< 6; i++)
{
tx_buffer_bluetooth[7] ^= tx_buffer_bluetooth[1 + i];
}
tx_buffer_bluetooth[8] = END_CHARACTER;
uartBluetoothTransmit(&tx_buffer_bluetooth[0], 9);
}
void sendRawValues(void)
{
//TODO Adjust to what will be obtained from SEN-15219
int raw_value, i;
tx_buffer_bluetooth[0] = START_CHARACTER_RAW;
tx_buffer_bluetooth[1] = 20;
//There might be an error with the representation of the value
//PPG_RED - IR
raw_value = -100;
tx_buffer_bluetooth[2] = (char)((raw_value & 0xFF0000) >> 16);
tx_buffer_bluetooth[3] = (char)((raw_value & 0xFF00) >> 8);
tx_buffer_bluetooth[4] = (char)(raw_value & 0xFF);
//PPG_RED - RED
raw_value = 1000;
tx_buffer_bluetooth[5] = (char)((raw_value & 0xFF0000) >> 16);
tx_buffer_bluetooth[6] = (char)((raw_value & 0xFF00) >> 8);
tx_buffer_bluetooth[7] = (char)(raw_value & 0xFF);
//PPG_RED - IR
raw_value = 700;
tx_buffer_bluetooth[8] = (char)((raw_value & 0xFF0000) >> 16);
tx_buffer_bluetooth[9] = (char)((raw_value & 0xFF00) >> 8);
tx_buffer_bluetooth[10] = (char)(raw_value & 0xFF);
//PPG_RED - RED
raw_value = -400;
tx_buffer_bluetooth[11] = (char)((raw_value & 0xFF0000) >> 16);
tx_buffer_bluetooth[12] = (char)((raw_value & 0xFF00) >> 8);
tx_buffer_bluetooth[13] = (char)(raw_value & 0xFF);
//PPG_RED - IR
raw_value = -1;
tx_buffer_bluetooth[14] = (char)((raw_value & 0xFF0000) >> 16);
tx_buffer_bluetooth[15] = (char)((raw_value & 0xFF00) >> 8);
tx_buffer_bluetooth[16] = (char)(raw_value & 0xFF);
//PPG_RED - RED
raw_value = 14;
tx_buffer_bluetooth[17] = (char)((raw_value & 0xFF0000) >> 16);
tx_buffer_bluetooth[18] = (char)((raw_value & 0xFF00) >> 8);
tx_buffer_bluetooth[19] = (char)(raw_value & 0xFF);
tx_buffer_bluetooth[20] = tx_buffer_bluetooth[0];
for(i=0; i< 19; i++)
{
tx_buffer_bluetooth[20] ^= tx_buffer_bluetooth[1 + i];
}
tx_buffer_bluetooth[21] = END_CHARACTER;
uartBluetoothTransmit(&tx_buffer_bluetooth[0], 22);
}
void sendConfirmationMessage(void)
{
tx_buffer_bluetooth[0] = START_CHARACTER_OK;
tx_buffer_bluetooth[1] = 2;
tx_buffer_bluetooth[2] = tx_buffer_bluetooth[0] ^ tx_buffer_bluetooth[1];
tx_buffer_bluetooth[3] = END_CHARACTER;
uartBluetoothTransmit(&tx_buffer_bluetooth[0], 4);
}
void sendErrorMessage(void)
{
tx_buffer_bluetooth[0] = START_CHARACTER_ERROR;
tx_buffer_bluetooth[1] = 2;
tx_buffer_bluetooth[2] = tx_buffer_bluetooth[0] ^ tx_buffer_bluetooth[1];
tx_buffer_bluetooth[3] = END_CHARACTER;
uartBluetoothTransmit(&tx_buffer_bluetooth[0], 4);
}
void processUARTIncomingPacket(void)
{
#ifndef BLUETOOTH_CONFIGURED
int bytes_received;
uartReceive(&rx_buffer_uart[0], &bytes_received);
rx_buffer_uart[bytes_received] = END_CHARACTER;
uartBluetoothTransmit(&rx_buffer_uart[0]);
cleanTXBuffer(&rx_buffer_uart[0]);
#endif
}
void processBluetoothIncomingPacket(void)
{
int bytes_received, i;
int message_id, packet_length, parameter_one, parameter_two, xor_checksum;
int packet_length_iterator, message_verified, xor_checksum_result;
uartBluetoothReceive(&rx_buffer_bluetooth[0], &bytes_received);
i = 0;
message_id = 0;
packet_length = 0;
message_verified = 0;
while (i < bytes_received)
{
if(message_id == 0)
{
if((rx_buffer_bluetooth[i] == MESSAGE_ID_HR_ALARM) || (rx_buffer_bluetooth[i] == MESSAGE_ID_SPO2_ALARM) || (rx_buffer_bluetooth[i] == MESSAGE_ID_RR_ALARM) || (rx_buffer_bluetooth[i] == MESSAGE_ID_TEMP_ALARM))
{
message_id = rx_buffer_bluetooth[i];
xor_checksum_result = message_id;
}
}
else
{
if (packet_length == 0)
{
packet_length = rx_buffer_bluetooth[i];
xor_checksum_result ^= packet_length;
packet_length_iterator = 0;
}
else
{
//Process packet and tell that the message was completed
if(packet_length_iterator < packet_length - 1)
{
if(packet_length_iterator == 0)
{
parameter_one = rx_buffer_bluetooth[i];
xor_checksum_result ^= parameter_one;
}
else if(packet_length_iterator == 1)
{
parameter_two = rx_buffer_bluetooth[i];
xor_checksum_result ^= parameter_two;
}
else if(packet_length_iterator == 2)
{
xor_checksum = rx_buffer_bluetooth[i];
}
packet_length_iterator++;
}
else
{
//We should have received the complete message here
if((rx_buffer_bluetooth[i] == END_CHARACTER) && (xor_checksum == xor_checksum_result))
{
message_verified = 1;
}
else
{
//In case there is an error in the frame
message_id = 0;
packet_length = 0;
}
}
}
}
if (message_verified == 1)
{
if (message_id == MESSAGE_ID_HR_ALARM)
{
setHeartRateAlarm(parameter_one, parameter_two);
}
else if (message_id == MESSAGE_ID_SPO2_ALARM)
{
setSpO2Alarm(parameter_one, parameter_two);
}
else if (message_id == MESSAGE_ID_RR_ALARM)
{
setRespirationRateAlarm(parameter_one, parameter_two);
}
else if (message_id == MESSAGE_ID_TEMP_ALARM)
{
setTemperatureAlarm(parameter_one, parameter_two);
}
//In case it receives more than one message
message_verified = 0;
message_id = 0;
packet_length = 0;
}
i++;
}
#ifndef BLUETOOTH_CONFIGURED
rx_buffer_bluetooth[bytes_received] = END_CHARACTER;
#endif
uartTransmit(&rx_buffer_bluetooth[0]); //Just for debugging purposes
cleanBuffer(&rx_buffer_bluetooth[0], COMM_BUFFER_BT_DIMENSION_RX);
}
void cleanBuffer(char *buffer, int size)
{
int i;
for (i = 0; i < size; i++)
{
buffer[i] = 0;
}
}
#ifndef BLUETOOTH_CONFIGURED
void bluetoothModuleConfiguration(void)
{
tx_buffer_uart[0] = 'C';
tx_buffer_uart[1] = 'o';
tx_buffer_uart[2] = 'n';
tx_buffer_uart[3] = 'f';
tx_buffer_uart[4] = 'i';
tx_buffer_uart[5] = 'g';
tx_buffer_uart[6] = 'u';
tx_buffer_uart[7] = 'r';
tx_buffer_uart[8] = 'e';
tx_buffer_uart[9] = ' ';
tx_buffer_uart[10] = 'B';
tx_buffer_uart[11] = 'T';
tx_buffer_uart[12] = END_CHARACTER;
uartTransmit(&tx_buffer_uart[0]);
}
#endif
#include "fifo_function_queue.h"
#include "common.h"
#include "assert_lab4.h"
static void* function_queue_buffer[FUNCTION_QUEUE_DIMENSION];
......
......@@ -13,12 +13,22 @@ void initializeGPIOModule(void)
P1OUT = 0;
P1DIR = 0xE9;
P1SEL1 = 0;
P1SEL0 = 0xE6;
P1SEL0 = 0xEC;
P2OUT = 0;
P2DIR = 0xFF;
P2SEL1 = 0;
P2SEL0 = 0xF0;
P2SEL0 = 0;
P3OUT = 0;
P3DIR = 0xFF;
P3SEL1 = 0;
P3SEL0 = 0;
P4OUT = 0;
P4DIR = 0xFF;
P4SEL1 = 0;
P4SEL0 = 0;
//Configure Interrupt for P1.4
P1IFG = 0;
......
......@@ -68,4 +68,3 @@ void TA0_0_IRQHandler(void)
TIMER_A0->CCTL[0] &= ~TIMER_A_CCTLN_CCIFG;
}
}
#include "timing_logic.h"
#include "user_interface.h"
#include "communications.h"
#include "body_temperature.h"
#include "clock.h"
#include "timer.h"
#include "sen_15219.h"
//TODO Remove and call from body_temp
#include "adc.h"
void slowPeriodicFunction(void);
void fastPeriodicFunction(void);
volatile int prueba_slow;
volatile int prueba_fast;
static int bluetoothTransmissionEnable = 0;
static int bluetoothTransmissionMode = 0;
void initializeTimingLogic(void)
{
configureClockSystem();
......@@ -38,9 +46,48 @@ void clearAuxiliaryMilisecondsTime(void)
resetAuxiliaryTime();
}
void startBluetoothTransmission(void)
{
bluetoothTransmissionEnable = 1;
}
void stopBluetoothTransmission(void)
{
bluetoothTransmissionEnable = 0;
}
void setBluetoothTransmission(void)
{
bluetoothTransmissionMode++;
if(bluetoothTransmissionMode == 5)
{
bluetoothTransmissionMode = 0;
}
}
void slowPeriodicFunction(void)
{
readSamples();
runADCConversion();
/*
if(bluetoothTransmissionMode == 1)
{
sendProcessedValues();
}
else if(bluetoothTransmissionMode == 2)
{
sendRawValues();
}
else if(bluetoothTransmissionMode == 3)
{
sendConfirmationMessage();
}
else if(bluetoothTransmissionMode == 4)
{
sendErrorMessage();
}
*/
if(prueba_slow == 0)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment