EV Logger
A MSP430 based datalogger for an electric vehicle
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
logger.h
Go to the documentation of this file.
1 
11 #ifndef __LOGGER_H__
12 #define __LOGGER_H__
13 
14 #include <stdio.h>
15 #include <msp430.h>
16 #include <msp430f5529.h>
17 #include <legacymsp430.h>
18 #include "typedefs.h"
19 #include "ff.h"
20 
21 #define S1_PORT_OUT P1OUT
22 #define S1_PORT_REN P1REN
23 #define S1_PORT_IES P1IES
24 #define S1_PORT_IE P1IE
25 #define S1_PORT_IFG P1IFG
26 #define S1_PIN _BV(7)
27 
28 #define S2_PORT_OUT P2OUT
29 #define S2_PORT_REN P2REN
30 #define S2_PORT_IES P2IES
31 #define S2_PORT_IE P2IE
32 #define S2_PORT_IFG P2IFG
33 #define S2_PIN _BV(2)
34 
39 #define SD_RINGBUF_LEN 2048
40 
44 #define SD_RINGBUF_MASK (SD_RINGBUF_LEN - 1)
45 
65 typedef struct RingBuffer
66 {
67  char* buffer;
68  uint16_t head, tail, len, mask;
69  uint8_t overflow;
70 } RingBuffer;
71 
76 #define ADC_CHANNELS 7
77 
82 #define ACCEL_CHANNELS 3
83 
92 typedef struct SampleBuffer
93 {
94  volatile uint16_t adc[ADC_CHANNELS];
95  volatile uint16_t accel[ACCEL_CHANNELS];
96 } SampleBuffer;
97 
98 void logger_init(void);
100 FRESULT sd_write(RingBuffer *rb, char *writebuf, FIL *fil, uint16_t n);
101 uint8_t ringbuf_write(RingBuffer* buf, char* data, uint16_t n);
102 uint8_t ringbuf_read(RingBuffer *buf, char* read_buffer, uint16_t n);
103 void update_lcd(RingBuffer *buf);
104 void logger_enable(void);
105 void logger_disable(void);
106 
107 #endif /* __LOGGER_H__ */
108 
#define ACCEL_CHANNELS
The number of accelerometer channels (typically 3) to be sampled from.
Definition: logger.h:82
uint16_t head
A pointer to the head of the ring buffer (the next free byte available for writing).
Definition: logger.h:68
void logger_enable(void)
Enable TA1 to begin logging by setting mode control to "up" mode, counter counts to TAxCCR0...
Definition: logger.c:411
uint16_t mask
This value is a ring buffer intrinsic and is automatically generated.
Definition: logger.h:68
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.
Definition: logger.c:295
A structure to contain one 'set' of samples from the vehicle.
Definition: logger.h:92
void logger_disable(void)
Disable TA1 to halt logging by setting mode control to STOP.
Definition: logger.c:433
uint16_t len
The length of the ring buffer.
Definition: logger.h:68
A ring buffer which can be attached to given (preallocated) memory area.
Definition: logger.h:65
uint8_t overflow
A flag that will be set non-zero if a buffer overflow occurs (the head tries to "overtake" the tail...
Definition: logger.h:69
void logger_init(void)
Set up the hardware for logging functionality, including the configuration of required peripherals su...
Definition: logger.c:80
volatile uint16_t adc[ADC_CHANNELS]
Storage for the ADC channels.
Definition: logger.h:94
void start_logger(RingBuffer *sdbuf)
Set up the SD card and the FATFS filesystem handler before commencing the logging service...
Definition: logger.c:194
uint8_t ringbuf_read(RingBuffer *buf, char *read_buffer, uint16_t n)
Read n bytes from a ring buffer.
Definition: logger.c:371
uint16_t tail
A pointer to the tail of the ring buffer (the next unread byte)
Definition: logger.h:68
void update_lcd(RingBuffer *buf)
Update the LCD with the current status of the logger, including buffer usage, data file size and SD c...
Definition: logger.c:145
static RingBuffer sdbuf
A RingBuffer that we will use to buffer sets of samples that are to be moved to the SD card...
Definition: logger.c:55
Standard data type shorthand defined as with avr-libc.
FIL fil
A pointer to the data file.
Definition: logger.c:65
#define ADC_CHANNELS
The number of ADC channels that we will sample from.
Definition: logger.h:76
volatile uint16_t accel[ACCEL_CHANNELS]
Storage for the accelerometer channels.
Definition: logger.h:95
char * buffer
A pointer to the start of the character buffer to be used by this ring buffer.
Definition: logger.h:67
uint8_t ringbuf_write(RingBuffer *buf, char *data, uint16_t n)
Write n bytes to a RingBuffer.
Definition: logger.c:325