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

Modules added for communications with PC|

parent 86e40598
No related branches found
No related tags found
No related merge requests found
......@@ -14,4 +14,6 @@
//#define DEBUG
#define REF_VOLTAGE_DIV_BY_ADC_10BITS_RESOLUTION 1.17
#define QUEUE_DIMENSION_UART 20
#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 a char array
* @param char* buffer_pointer: auxiliary buffer pointer which contains data to be transmitted
*
*/
void sendPacket(char* buffer_pointer);
#endif /* INCLUDE_COMMUNICATIONS_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_
/**
* @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
*
*/
void uartReceive(char* buffer_pointer);
#endif /* INCLUDE_UART_H_ */
#include "communications.h"
#include "uart.h"
void processIncomingPacket();
void initializeCommunications(void)
{
initializeUART();
setUartCallbackFunction(processIncomingPacket);
}
void sendPacket(char* buffer_pointer){}
void processIncomingPacket()
{
}
#include <msp.h>
#include "uart.h"
#include "fifo_queue.h"
#include "fifo_function_queue.h"
#include "common.h"
//Reception and Transmission Queues
static char rx_buffer[QUEUE_DIMENSION_UART];
static char tx_buffer[QUEUE_DIMENSION_UART];
static char tail_rx, head_rx;
static char tail_tx, head_tx;
//Callback function for queue
void (*message_received_callback)();
void initializeUART()
{
//Keep module in reset while being configured
UCA0CTL1 = UCSWRST;
//Parity disabled, LSB first, 8-bit length, 1 stop bit, asynchronous uart mode
UCA0CTL0 = 0;
//ACLK source, not dormant mode
UCA0CTL1 |= UCSSEL0;
//Baud Rate = 9600bps, sourced by ACLK @ 32kHZ
//N = frequency of brclk / desired baud rate
//UCBR = int(N)
//UCBRS = round((N-int(N))*8)
UCA0BR0 = 3;
UCA0BR1 = 0;
//Second modulation stage = UCBRSx, Oversampling disabled
//UCA0MCTL = UCBRS1 | UCBRS0;
//Configure shared i/o pins
//Tx as output pin
//P1DIR |= TXPIN;
//P1SEL |= TXPIN | RXPIN;
//P1SEL2 |= TXPIN | RXPIN;
//Init queues
initQueue(&head_rx, &tail_rx);
initQueue(&head_tx, &tail_tx);
//Turn on the module
UCA0CTL1 &= ~UCSWRST;
//Enable Interrupts
//UC0IE = UCA0RXIE;
}
void setUartCallbackFunction(void *callback_function)
{
message_received_callback = callback_function;
}
void uartReceive(char* buffer_pointer)
{
int i = 0;
char value;
if(!queueIsEmpty(head_rx, tail_rx))
{
value = getFromQueue(&tail_rx, rx_buffer);
while (value != '\r') //'\r' is expected as defined by the assignment
{
*(buffer_pointer + i) = value;
if(!queueIsEmpty(head_rx, tail_rx))
{
value = getFromQueue(&tail_rx, rx_buffer);
}
else
{
value = 0;
}
i++;
}
*(buffer_pointer + i) = value; //Copying '\r'
}
}
void uartTransmit(char* buffer_pointer)
{
int i = 0;
while (*(buffer_pointer + i) != '\r') //'\r' is expected as defined by the assignment
{
if(!queueIsFull(head_tx, tail_tx))
{
addToQueue(*(buffer_pointer + i), &head_tx, tx_buffer);
}
i++;
}
if(!queueIsFull(head_tx, tail_tx))
{
addToQueue(*(buffer_pointer + i), &head_tx, tx_buffer); //Adding '\r'
}
// UC0IE |= UCA0TXIE;
}
/*
#pragma vector=USCIAB0RX_VECTOR
__interrupt void rxUARTInterruptRoutine(void)
{
if(!queueIsFull(head_rx, tail_rx))
{
addToQueue(UCA0RXBUF, &head_rx, rx_buffer);
if(UCA0RXBUF == '\r')
{
addToFunctionQueue(message_received_callback);
__low_power_mode_off_on_exit();
}
}
}
#pragma vector=USCIAB0TX_VECTOR
__interrupt void txUARTInterruptRoutine(void)
{
if(!queueIsEmpty(head_tx, tail_tx))
{
UCA0TXBUF = getFromQueue(&tail_tx, tx_buffer);
}
else
{
UC0IE &= ~UCA0TXIE;
}
}
*/
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