EV Logger
A MSP430 based datalogger for an electric vehicle
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
logger.c File Reference

Handles the main logger functionality of the device, including the configuration of all required peripherals for the logging service. More...

#include <string.h>
#include "HAL_Dogs102x6.h"
#include "accel.h"
#include "logger.h"
#include "adc.h"
#include "ff.h"
#include "uart.h"
#include "system.h"
#include "typedefs.h"
#include "mmc.h"

Macros

#define rb_getused_m(b)   ((b->tail==b->head) ? 0:(b->head - b->tail + b->len) % b->len)
 Quick facility to get the used value of a ring buffer. More...
 
#define rb_getfree_m(b)   ((b->tail==b->head) ? b->len : (b->tail - b->head + b->len) % b->len)
 Quick facility to get the free value of a ring buffer. More...
 
#define rb_reset_m(b)   do {b->tail = b->head = 0} while (0)
 Reset a ring buffer to its original empty state. More...
 

Functions

void logger_init (void)
 Set up the hardware for logging functionality, including the configuration of required peripherals such as the ADC and Accelerometer. More...
 
void update_lcd (RingBuffer *buf)
 Update the LCD with the current status of the logger, including buffer usage, data file size and SD card utilisation. More...
 
void start_logger (RingBuffer *sdbuf)
 Set up the SD card and the FATFS filesystem handler before commencing the logging service. More...
 
FRESULT sd_write (RingBuffer *rb, char *writebuf, FIL *fil, uint16_t n)
 Write n bytes from a ring buffer to an SD card controlled by fatfs. More...
 
uint8_t ringbuf_write (RingBuffer *buf, char *data, uint16_t n)
 Write n bytes to a RingBuffer. More...
 
uint8_t ringbuf_read (RingBuffer *buf, char *read_buffer, uint16_t n)
 Read n bytes from a ring buffer. More...
 
void logger_enable (void)
 Enable TA1 to begin logging by setting mode control to "up" mode, counter counts to TAxCCR0. More...
 
void logger_disable (void)
 Disable TA1 to halt logging by setting mode control to STOP. More...
 
 interrupt (TIMER1_A0_VECTOR)
 Interrupt service routine for Timer A1 (TA1), where we should log one block of data. More...
 
 interrupt (PORT1_VECTOR)
 Interrupt vector for button S1 which is used for enabled and disabling logging. More...
 
 interrupt (PORT2_VECTOR)
 Interrupt vector for button S2.
 

Variables

static volatile uint32_t time
 
static volatile uint8_t logger_running
 
static volatile uint8_t file_open
 
static char s [UART_BUF_LEN]
 
static char ringbuf [SD_RINGBUF_LEN]
 
static char writebuf [512]
 
static RingBuffer sdbuf
 A RingBuffer that we will use to buffer sets of samples that are to be moved to the SD card.
 
static volatile SampleBuffer sb
 A SampleBuffer to store a single set of readings before they are transferred into the SD transaction buffer. More...
 
FATFS FatFs
 A FATFS filesystem object which we use to handle files and directories on the SD Card. More...
 
FIL fil
 A pointer to the data file.
 
DWORD fsz
 Stores the current size of the data file.
 

Detailed Description

Handles the main logger functionality of the device, including the configuration of all required peripherals for the logging service.

Logging data into the SD buffer is interrupt controlled so that precise timing may be maintained. Other functionality such as updating the LCD screen and opening, flushing and closing of files is up to an infinite loop such that it can be easily interrupted by higher priority tasks.

Author
Jon Sowman, University of Southampton j.sow.nosp@m.man@.nosp@m.soton.nosp@m..ac..nosp@m.uk