=Norig) twidx-=Norig;
+ C_MUL(t,scratch[q] , twiddles[twidx] );
+ C_ADDTO( Fout[ k ] ,t);
+ }
+ k += m;
+ }
+ }
+ KISS_FFT_TMP_FREE(scratch);
+}
+
+static
+void kf_work(
+ kiss_fft_cpx * Fout,
+ const kiss_fft_cpx * f,
+ const size_t fstride,
+ int in_stride,
+ int * factors,
+ const kiss_fft_cfg st
+ )
+{
+ kiss_fft_cpx * Fout_beg=Fout;
+ const int p=*factors++; /* the radix */
+ const int m=*factors++; /* stage's fft length/p */
+ const kiss_fft_cpx * Fout_end = Fout + p*m;
+
+#ifdef _OPENMP
+ // use openmp extensions at the
+ // top-level (not recursive)
+ if (fstride==1 && p<=5)
+ {
+ int k;
+
+ // execute the p different work units in different threads
+# pragma omp parallel for
+ for (k=0;k floor_sqrt)
+ p = n; /* no more factors, skip to end */
+ }
+ n /= p;
+ *facbuf++ = p;
+ *facbuf++ = n;
+ } while (n > 1);
+}
+
+/*
+ *
+ * User-callable function to allocate all necessary storage space for the fft.
+ *
+ * The return value is a contiguous block of memory, allocated with malloc. As such,
+ * It can be freed with free(), rather than a kiss_fft-specific function.
+ * */
+kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem )
+{
+ kiss_fft_cfg st=NULL;
+ size_t memneeded = sizeof(struct kiss_fft_state)
+ + sizeof(kiss_fft_cpx)*(nfft-1); /* twiddle factors*/
+
+ if ( lenmem==NULL ) {
+ st = ( kiss_fft_cfg)KISS_FFT_MALLOC( memneeded );
+ }else{
+ if (mem != NULL && *lenmem >= memneeded)
+ st = (kiss_fft_cfg)mem;
+ *lenmem = memneeded;
+ }
+ if (st) {
+ int i;
+ st->nfft=nfft;
+ st->inverse = inverse_fft;
+
+ for (i=0;iinverse)
+ phase *= -1;
+ kf_cexp(st->twiddles+i, phase );
+ }
+
+ kf_factor(nfft,st->factors);
+ }
+ return st;
+}
+
+
+void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
+{
+ if (fin == fout) {
+ //NOTE: this is not really an in-place FFT algorithm.
+ //It just performs an out-of-place FFT into a temp buffer
+ kiss_fft_cpx * tmpbuf = (kiss_fft_cpx*)KISS_FFT_TMP_ALLOC( sizeof(kiss_fft_cpx)*st->nfft);
+ kf_work(tmpbuf,fin,1,in_stride, st->factors,st);
+ memcpy(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft);
+ KISS_FFT_TMP_FREE(tmpbuf);
+ }else{
+ kf_work( fout, fin, 1,in_stride, st->factors,st );
+ }
+}
+
+void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
+{
+ kiss_fft_stride(cfg,fin,fout,1);
+}
+
+
+void kiss_fft_cleanup(void)
+{
+ // nothing needed any more
+}
+
+int kiss_fft_next_fast_size(int n)
+{
+ while(1) {
+ int m=n;
+ while ( (m%2) == 0 ) m/=2;
+ while ( (m%3) == 0 ) m/=3;
+ while ( (m%5) == 0 ) m/=5;
+ if (m<=1)
+ break; /* n is completely factorable by twos, threes, and fives */
+ n++;
+ }
+ return n;
+}
diff --git a/kiss_fft.h b/kiss_fft.h
new file mode 100644
index 0000000..64c50f4
--- /dev/null
+++ b/kiss_fft.h
@@ -0,0 +1,124 @@
+#ifndef KISS_FFT_H
+#define KISS_FFT_H
+
+#include
+#include
+#include
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ ATTENTION!
+ If you would like a :
+ -- a utility that will handle the caching of fft objects
+ -- real-only (no imaginary time component ) FFT
+ -- a multi-dimensional FFT
+ -- a command-line utility to perform ffts
+ -- a command-line utility to perform fast-convolution filtering
+
+ Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c
+ in the tools/ directory.
+*/
+
+#ifdef USE_SIMD
+# include
+# define kiss_fft_scalar __m128
+#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16)
+#define KISS_FFT_FREE _mm_free
+#else
+#define KISS_FFT_MALLOC malloc
+#define KISS_FFT_FREE free
+#endif
+
+
+#ifdef FIXED_POINT
+#include
+# if (FIXED_POINT == 32)
+# define kiss_fft_scalar int32_t
+# else
+# define kiss_fft_scalar int16_t
+# endif
+#else
+# ifndef kiss_fft_scalar
+/* default is float */
+# define kiss_fft_scalar float
+# endif
+#endif
+
+typedef struct {
+ kiss_fft_scalar r;
+ kiss_fft_scalar i;
+}kiss_fft_cpx;
+
+typedef struct kiss_fft_state* kiss_fft_cfg;
+
+/*
+ * kiss_fft_alloc
+ *
+ * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
+ *
+ * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
+ *
+ * The return value from fft_alloc is a cfg buffer used internally
+ * by the fft routine or NULL.
+ *
+ * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
+ * The returned value should be free()d when done to avoid memory leaks.
+ *
+ * The state can be placed in a user supplied buffer 'mem':
+ * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
+ * then the function places the cfg in mem and the size used in *lenmem
+ * and returns mem.
+ *
+ * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
+ * then the function returns NULL and places the minimum cfg
+ * buffer size in *lenmem.
+ * */
+
+kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
+
+/*
+ * kiss_fft(cfg,in_out_buf)
+ *
+ * Perform an FFT on a complex input buffer.
+ * for a forward FFT,
+ * fin should be f[0] , f[1] , ... ,f[nfft-1]
+ * fout will be F[0] , F[1] , ... ,F[nfft-1]
+ * Note that each element is complex and can be accessed like
+ f[k].r and f[k].i
+ * */
+void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
+
+/*
+ A more generic version of the above function. It reads its input from every Nth sample.
+ * */
+void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
+
+/* If kiss_fft_alloc allocated a buffer, it is one contiguous
+ buffer and can be simply free()d when no longer needed*/
+#define kiss_fft_free free
+
+/*
+ Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
+ your compiler output to call this before you exit.
+*/
+void kiss_fft_cleanup(void);
+
+
+/*
+ * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
+ */
+int kiss_fft_next_fast_size(int n);
+
+/* for real ffts, we need an even size */
+#define kiss_fftr_next_fast_size_real(n) \
+ (kiss_fft_next_fast_size( ((n)+1)>>1)<<1)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/main.c b/main.c
index a59aac4..0c75318 100644
--- a/main.c
+++ b/main.c
@@ -1,3 +1,4 @@
+
/*
* ECE 3849 Lab2 starter project
*
@@ -30,21 +31,45 @@
#include "driverlib/pin_map.h"
#include "sampling.h"
#include "buttons.h"
-#define PWM_FREQUENCY 20000 // PWM frequency = 20 kHz
+#include "frequency.h"
+#include "kiss_fft.h"
+#include "_kiss_fft_guts.h"
-uint32_t gSystemClock = 120000000; // [Hz] system clock frequency
+
+
+#define PI 3.14159265358979f
tContext sContext;
uint32_t cputime_unloaded;
+#define FFT_EN false
+
#define LOCAL_BUF_LEN 128
uint16_t adc_buffer_sample[LOCAL_BUF_LEN]; // copy of g adc buffer
uint8_t adc_buffer_processed[LOCAL_BUF_LEN]; // copy of g adc buffer
-uint8_t voltage_scale = 4; // 2v
-uint8_t time_scale = 5; // 20us
-uint8_t trigger_mode = 1; // rising
+#define FFT_BUF_LEN 1024
+uint16_t adc_buffer_fft_sample[FFT_BUF_LEN]; // copy of g adc buffer
+uint8_t adc_buffer_fft_processed[FFT_BUF_LEN]; // copy of g adc buffer
+
+kiss_fft_cfg cfg;
+static kiss_fft_cpx in[FFT_BUF_LEN], out[FFT_BUF_LEN];
+
+typedef struct
+{
+ bool fft;
+ uint8_t voltage_scale;
+ uint8_t time_scale;
+ uint8_t trigger_mode;
+} Options;
+
+Options options = {
+ .fft = false, // oscilloscope mode
+ .voltage_scale = 4, // 2v
+ .time_scale = 5, // 20us
+ .trigger_mode = 1, // rising
+};
// assuming square lcd
#define HEIGHT LCD_VERTICAL_MAX
@@ -53,7 +78,7 @@ uint8_t trigger_mode = 1; // rising
#define VIN_RANGE 3.3 // volts
#define ADC_BITS 12
-#define ADC_OFFSET 30
+#define ADC_OFFSET 100
#define VOLTAGE_SCALES 5
const char * const gVoltageScaleStr[VOLTAGE_SCALES] = {
@@ -64,43 +89,9 @@ const float gVoltageScale[VOLTAGE_SCALES] = {
0.1, 0.2, 0.5, 1., 2.
};
-#define TIME_SCALES 6
-const char * const gTimeScaleStr[TIME_SCALES] = {
-"100 ms", "50 ms", "20 ms", " 10 ms", "50 us", "20 us"
-};
-
-const uint64_t gTImeScale[TIME_SCALES] = {
- 100 * 1000 / PIXELS_PER_DIV,
- 50 * 1000 / PIXELS_PER_DIV,
- 20 * 1000 / PIXELS_PER_DIV,
- 10 * 1000 / PIXELS_PER_DIV,
- 50 / PIXELS_PER_DIV,
- 20 / PIXELS_PER_DIV,
-};
-
int Trigger(bool rising);
-// start a pwm test signal
-void start_signal() {
- // configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
- GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2);
- GPIOPinConfigure(GPIO_PF2_M0PWM2);
- GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,
- GPIO_PIN_TYPE_STD);
- // configure the PWM0 peripheral, gen 1, outputs 2 and 3
- SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
- // use system clock without division
- PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
- PWMGenConfigure(PWM0_BASE, PWM_GEN_1,
- PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
- PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1,
- roundf((float)gSystemClock / PWM_FREQUENCY));
- PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,
- roundf((float)gSystemClock / PWM_FREQUENCY * 0.4f));
- PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);
- PWMGenEnable(PWM0_BASE, PWM_GEN_1);
-}
+
uint32_t cpu_load_count(void)
{
@@ -134,6 +125,7 @@ int main(void)
start_sampler();
ButtonInit();
start_cputimer();
+ start_frequency_scan();
Crystalfontz128x128_Init(); // Initialize the LCD display driver
Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); // set screen orientation
@@ -141,21 +133,17 @@ int main(void)
GrContextInit(&sContext, &g_sCrystalfontz128x128); // Initialize the grlib graphics context
GrContextFontSet(&sContext, &g_sFontFixed6x8); // select font
+ #define KISS_FFT_CFG_SIZE (sizeof(struct kiss_fft_state)+sizeof(kiss_fft_cpx)*(FFT_BUF_LEN-1))
+ static char kiss_fft_cfg_buffer[KISS_FFT_CFG_SIZE];
+ size_t buffer_size = KISS_FFT_CFG_SIZE;
+ cfg = kiss_fft_alloc(FFT_BUF_LEN, 0, kiss_fft_cfg_buffer, &buffer_size);
+
/* Start BIOS */
BIOS_start();
return (0);
}
-void task0_func(UArg arg1, UArg arg2)
-{
- IntMasterEnable();
-
- while (true) {
- // do nothing
- }
-}
-
void capture_waveform(UArg arg1, UArg arg2)
{
IntMasterEnable();
@@ -163,37 +151,77 @@ void capture_waveform(UArg arg1, UArg arg2)
Semaphore_pend(capture_sem, BIOS_WAIT_FOREVER);
int32_t adc_current_index;
- int32_t j;
- int trigger;
- if (trigger_mode == 2) {
- trigger = gADCBufferIndex - (WIDTH / 2); // show latest if trigger disabled
+ int32_t i;
+
+ if (options.fft) {
+ adc_current_index = getADCBufferIndex();
+ int32_t j = 0;
+ for(i=adc_current_index-FFT_BUF_LEN; i(b))?(a):(b))
+ #define CONSTRAIN(x) MAX(MIN(HEIGHT - 1, x), 0)
- int j;
- for(j=0; j(b))?(a):(b))
- #define CONSTRAIN(x) MAX(MIN(HEIGHT - 1, x), 0)
- #define TRANSPOSE(x) CONSTRAIN((HEIGHT/2) - (int)roundf(fScale * ((int)x - ADC_OFFSET)))
- adc_buffer_processed[j] = TRANSPOSE(adc_buffer_sample[j]);
+ if(options.fft) { // fft
+ for(i=0; i(b))?(a):(b))
- uint32_t upper,lower, current, last;
-
- if (j==0) {
- upper = adc_buffer_processed[j];
- lower = upper;
- last = upper;
- } else {
- current = adc_buffer_processed[j];
-
- upper = MAX(current, last);
- lower = MIN(current, last);
-
- last = current;
- }
-
- GrLineDrawV(&sContext, j, lower, upper);
+ for(j=1; j x_stop; x--) {
if (rising) {
@@ -327,6 +362,6 @@ int Trigger(bool rising) // search for edge trigger
}
}
if (x == x_stop) // for loop ran to the end
- x = gADCBufferIndex - (WIDTH / 2); // reset x back to how it was initialized
+ x = getADCBufferIndex() - (WIDTH / 2); // reset x back to how it was initialized
return x;
}
diff --git a/rtos.cfg b/rtos.cfg
index 6f06a7a..9754dd8 100644
--- a/rtos.cfg
+++ b/rtos.cfg
@@ -36,6 +36,7 @@
var Clock = xdc.useModule('ti.sysbios.knl.Clock');
var Mailbox = xdc.useModule('ti.sysbios.knl.Mailbox');
var TimestampProvider = xdc.useModule('ti.sysbios.family.arm.lm4.TimestampProvider');
+var GateHwi = xdc.useModule('ti.sysbios.gates.GateHwi');
/*
* Default value is family dependent. For example, Linux systems often only
* support a minimum period of 10000 us and multiples of 10000 us.
@@ -534,15 +535,11 @@ var driversConfig = xdc.useModule('ti.drivers.Config');
* Use TI-RTOS drivers library for debugging with asserts and logs enabled.
*/
driversConfig.libType = driversConfig.LibType_NonInstrumented;
-Clock.timerId = 0;
+Clock.timerId = 2;
TimestampProvider.useClockTimer = true;
-var task0Params = new Task.Params();
-task0Params.instance.name = "task0";
-task0Params.priority = 1;
-Program.global.task0 = Task.create("&task0_func", task0Params);
var m3Hwi0Params = new m3Hwi.Params();
m3Hwi0Params.instance.name = "m3Hwi0";
-m3Hwi0Params.priority = 0;
+m3Hwi0Params.priority = 64;
Program.global.m3Hwi0 = m3Hwi.create(62, "&ADC_ISR", m3Hwi0Params);
var task1Params = new Task.Params();
task1Params.instance.name = "waveform";
@@ -593,3 +590,14 @@ var task5Params = new Task.Params();
task5Params.instance.name = "user_input";
task5Params.priority = 6;
Program.global.user_input = Task.create("&handle_user_input", task5Params);
+var semaphore4Params = new Semaphore.Params();
+semaphore4Params.instance.name = "options_sem";
+semaphore4Params.mode = Semaphore.Mode_BINARY;
+Program.global.options_sem = Semaphore.create(1, semaphore4Params);
+var gateHwi0Params = new GateHwi.Params();
+gateHwi0Params.instance.name = "gateHwiDMA";
+Program.global.gateHwi0 = GateHwi.create(gateHwi0Params);
+var m3Hwi1Params = new m3Hwi.Params();
+m3Hwi1Params.instance.name = "m3Hwi1";
+m3Hwi1Params.priority = 4;
+Program.global.m3Hwi1 = m3Hwi.create(35, "&capture_handler", m3Hwi1Params);
diff --git a/sampling.c b/sampling.c
index 3407ada..1f32b1e 100644
--- a/sampling.c
+++ b/sampling.c
@@ -7,37 +7,111 @@
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
+#include "driverlib/udma.h"
#include "sysctl_pll.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include
#include "buttons.h"
#include "sampling.h"
+#include
+#include
+#include
+#include
+
+
+#define DMA
+
+#ifdef DMA
+#pragma DATA_ALIGN(gDMAControlTable, 1024)
+tDMAControlTable gDMAControlTable[64]; // uDMA control table
+#endif
extern uint32_t gSystemClock; // [Hz] system clock frequency
-// latest sample index
-void ADC_ISR(void)
+// is DMA occurring in the primary channel?
+volatile bool gDMAPrimary = true;
+void ADC_ISR(void) // DMA
{
- // clear ADC1 sequence0 interrupt flag in the ADCISC register
- //HWREGBITW(ADC1_ISC_R, 1) = 1;
- ADC1_ISC_R |= 1;
-
- // check for ADC FIFO overflow
- if(ADC1_OSTAT_R & ADC_OSTAT_OV0) {
- gADCErrors++; // count errors
- ADC1_OSTAT_R = ADC_OSTAT_OV0; // clear overflow condition
+ ADCIntClearEx(ADC1_BASE, ADC_INT_DMA_SS0); // clear the ADC1 sequence 0 DMA interrupt flag
+ // Check the primary DMA channel for end of transfer, and
+ // restart if needed.
+ if (uDMAChannelModeGet(UDMA_SEC_CHANNEL_ADC10 | UDMA_PRI_SELECT) ==
+ UDMA_MODE_STOP) {
+ // restart the primary channel (same as setup)
+ uDMAChannelTransferSet(UDMA_SEC_CHANNEL_ADC10 | UDMA_PRI_SELECT,
+ UDMA_MODE_PINGPONG, (void*)&ADC1_SSFIFO0_R,
+ (void*)&gADCBuffer[0], ADC_BUFFER_SIZE/2);
+ // DMA is currently occurring in the alternate buffer
+ gDMAPrimary = false;
+ }
+ // Check the alternate DMA channel for end of transfer, and
+ // restart if needed.
+ // Also set the gDMAPrimary global.
+ if (uDMAChannelModeGet(UDMA_SEC_CHANNEL_ADC10 | UDMA_ALT_SELECT) ==
+ UDMA_MODE_STOP) {
+ // restart the primary channel (same as setup)
+ uDMAChannelTransferSet(UDMA_SEC_CHANNEL_ADC10 | UDMA_ALT_SELECT,
+ UDMA_MODE_PINGPONG, (void*)&ADC1_SSFIFO0_R,
+ (void*)&gADCBuffer[ADC_BUFFER_SIZE/2],
+ ADC_BUFFER_SIZE/2);
+ // DMA is currently occurring in the primary buffer
+ gDMAPrimary = true;
+ }
+ // The DMA channel may be disabled if the CPU is paused by the debugger
+ if (!uDMAChannelIsEnabled(UDMA_SEC_CHANNEL_ADC10)) {
+ // re-enable the DMA channel
+ uDMAChannelEnable(UDMA_SEC_CHANNEL_ADC10);
}
- gADCBufferIndex = ADC_BUFFER_WRAP(gADCBufferIndex + 1);
- // read sample from the ADC1 sequence 0 FIFO
- gADCBuffer[gADCBufferIndex] = (ADC1_SSFIFO0_R & ADC_SSFIFO0_DATA_M);
}
+int32_t getADCBufferIndex(void)
+{
+ int32_t index;
+ uint32_t key = GateHwi_enter(gateHwi0);
+ if (gDMAPrimary) { // DMA is currently in the primary channel
+ index = ADC_BUFFER_SIZE/2 - 1 -
+ uDMAChannelSizeGet(UDMA_SEC_CHANNEL_ADC10 |
+ UDMA_PRI_SELECT);
+ } else { // DMA is currently in the alternate channel
+ index = ADC_BUFFER_SIZE - 1 -
+ uDMAChannelSizeGet(UDMA_SEC_CHANNEL_ADC10 |
+ UDMA_ALT_SELECT);
+ }
+ GateHwi_leave(gateHwi0, key);
+
+ return index;
+}
void start_sampler() {
gADCBufferIndex = ADC_BUFFER_SIZE - 1;
gADCErrors = 0;
+ // init DMA
+ SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
+ uDMAEnable();
+ uDMAControlBaseSet(gDMAControlTable);
+ // assign DMA channel 24 to ADC1 sequence 0
+ uDMAChannelAssign(UDMA_CH24_ADC1_0);
+ uDMAChannelAttributeDisable(UDMA_SEC_CHANNEL_ADC10, UDMA_ATTR_ALL);
+ // primary DMA channel = first half of the ADC buffer
+ uDMAChannelControlSet(UDMA_SEC_CHANNEL_ADC10 | UDMA_PRI_SELECT,
+ UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 |
+ UDMA_ARB_4);
+ uDMAChannelTransferSet(UDMA_SEC_CHANNEL_ADC10 | UDMA_PRI_SELECT,
+ UDMA_MODE_PINGPONG, (void*)&ADC1_SSFIFO0_R,
+ (void*)&gADCBuffer[0], ADC_BUFFER_SIZE/2);
+ // alternate DMA channel = second half of the ADC buffer
+ uDMAChannelControlSet(UDMA_SEC_CHANNEL_ADC10 | UDMA_ALT_SELECT,
+ UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 |
+ UDMA_ARB_4);
+ uDMAChannelTransferSet(UDMA_SEC_CHANNEL_ADC10 | UDMA_ALT_SELECT,
+ UDMA_MODE_PINGPONG, (void*)&ADC1_SSFIFO0_R,
+ (void*)&gADCBuffer[ADC_BUFFER_SIZE/2],
+ ADC_BUFFER_SIZE/2);
+ uDMAChannelEnable(UDMA_SEC_CHANNEL_ADC10);
+
+
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE,
GPIO_PIN_0); // GPIO setup for analog input AIN3
@@ -45,8 +119,6 @@ void start_sampler() {
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
- // timer for low-speed
- SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
// ADC clock
uint32_t pll_frequency = SysCtlFrequencyGet(CRYSTAL_FREQUENCY);
uint32_t pll_divisor =
@@ -64,28 +136,10 @@ void start_sampler() {
ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CH3 | ADC_CTL_END | ADC_CTL_IE);
// enable the sequence. it is now sampling
ADCSequenceEnable(ADC1_BASE, 0);
+
// enable sequence 0 interrupt in the ADC1 peripheral
- ADCIntEnable(ADC1_BASE, 0); // INT_ADC1SS0
-}
-
-void set_frequency(uint64_t microseconds) {
- if (microseconds == 1) {
- ADCSequenceDisable(ADC1_BASE, 0);
- // don't use a timer for high speed
- ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_ALWAYS, 0);
- ADCSequenceEnable(ADC1_BASE, 0);
- return;
- }
-
- // initialize timer 2 in periodic mode
- TimerDisable(TIMER2_BASE, TIMER_BOTH);
- TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC);
- #define MICROSECONDS_PER_SECOND 1000000
- TimerLoadSet(TIMER2_BASE, TIMER_A, (uint32_t) ((uint64_t) gSystemClock * microseconds / MICROSECONDS_PER_SECOND) - 1);
- TimerControlTrigger(TIMER2_BASE, TIMER_A, true);
- TimerEnable(TIMER2_BASE, TIMER_A);
-
- ADCSequenceDisable(ADC1_BASE, 0);
- ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_TIMER, 0);
- ADCSequenceEnable(ADC1_BASE, 0);
+ //ADCIntEnable(ADC1_BASE, 0); // INT_ADC1SS0
+
+ ADCSequenceDMAEnable(ADC1_BASE, 0); // enable DMA for ADC1 sequence 0
+ ADCIntEnableEx(ADC1_BASE, ADC_INT_DMA_SS0); // enable ADC1 sequence 0 DMA interrupt
}
diff --git a/sampling.h b/sampling.h
index 9cb9b8d..cb96dfd 100644
--- a/sampling.h
+++ b/sampling.h
@@ -17,4 +17,6 @@ void start_sampler(void);
void set_frequency(uint64_t microseconds);
+int32_t getADCBufferIndex(void);
+
#endif /* SAMPLING_H_ */
diff --git a/src/makefile.libs b/src/makefile.libs
index 86abb2c..e247312 100644
--- a/src/makefile.libs
+++ b/src/makefile.libs
@@ -1,6 +1,6 @@
#
# This file was generated based on the configuration script:
-# C:\Users\askillorin\Downloads\ECE3849-tirtos\ece3849_lab3_starter\rtos.cfg
+# C:\Users\askillorin\Documents\ece3849_lab3_starter\rtos.cfg
#
# This makefile may be included in other makefiles that need to build
# the libraries containing the compiled source files generated as
@@ -14,7 +14,7 @@
#
# The absolute path to the generated source directory (at the time the
# sources were generated) is:
-# C:\Users\askillorin\Downloads\ECE3849-tirtos\ece3849_lab3_starter\src
+# C:\Users\askillorin\Documents\ece3849_lab3_starter\src
#
GEN_SRC_DIR ?= ../src
diff --git a/src/sysbios/BIOS.obj b/src/sysbios/BIOS.obj
index b2684f9..98875ee 100644
Binary files a/src/sysbios/BIOS.obj and b/src/sysbios/BIOS.obj differ
diff --git a/src/sysbios/m3_Hwi_asm.obj b/src/sysbios/m3_Hwi_asm.obj
index 7b8a59f..4683f66 100644
Binary files a/src/sysbios/m3_Hwi_asm.obj and b/src/sysbios/m3_Hwi_asm.obj differ
diff --git a/src/sysbios/m3_Hwi_asm_switch.obj b/src/sysbios/m3_Hwi_asm_switch.obj
index b77a1c8..4e614d4 100644
Binary files a/src/sysbios/m3_Hwi_asm_switch.obj and b/src/sysbios/m3_Hwi_asm_switch.obj differ
diff --git a/src/sysbios/m3_IntrinsicsSupport_asm.obj b/src/sysbios/m3_IntrinsicsSupport_asm.obj
index 02a9be2..f9370ce 100644
Binary files a/src/sysbios/m3_IntrinsicsSupport_asm.obj and b/src/sysbios/m3_IntrinsicsSupport_asm.obj differ
diff --git a/src/sysbios/m3_TaskSupport_asm.obj b/src/sysbios/m3_TaskSupport_asm.obj
index ccfa956..39801e7 100644
Binary files a/src/sysbios/m3_TaskSupport_asm.obj and b/src/sysbios/m3_TaskSupport_asm.obj differ
diff --git a/src/sysbios/makefile b/src/sysbios/makefile
index e77e596..81636b4 100644
--- a/src/sysbios/makefile
+++ b/src/sysbios/makefile
@@ -16,7 +16,7 @@ BIOS_INC = -I"C:/ti/ccs1271/tirtos_tivac_2_16_01_14/products/bios_6_45_02_31/pa
TARGET_INC = -I"C:/ti/ccs1271/tirtos_tivac_2_16_01_14/products/bios_6_45_02_31/packages/"
-INCS = $(BIOS_INC) $(TARGET_INC) --include_path="C:/Users/askillorin/Downloads/ECE3849-tirtos/ece3849_lab3_starter" --include_path="C:/Users/askillorin/Downloads/ECE3849-tirtos/ece3849_lab3_starter" --include_path="C:/ti/ccs1271/tirtos_tivac_2_16_01_14/products/TivaWare_C_Series-2.1.1.71b" --include_path="C:/ti/ccs1271/tirtos_tivac_2_16_01_14/products/bios_6_45_01_29/packages/ti/sysbios/posix" --include_path="C:/ti/ccs1271/ccs/tools/compiler/ti-cgt-arm_20.2.7.LTS/include"
+INCS = $(BIOS_INC) $(TARGET_INC) --include_path="C:/Users/askillorin/Documents/ece3849_lab3_starter" --include_path="C:/Users/askillorin/Documents/ece3849_lab3_starter" --include_path="C:/ti/ccs1271/tirtos_tivac_2_16_01_14/products/TivaWare_C_Series-2.1.1.71b" --include_path="C:/ti/ccs1271/tirtos_tivac_2_16_01_14/products/bios_6_45_01_29/packages/ti/sysbios/posix" --include_path="C:/ti/ccs1271/ccs/tools/compiler/ti-cgt-arm_20.2.7.LTS/include"
CC = C:/ti/ccs1271/ccs/tools/compiler/ti-cgt-arm_20.2.7.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccs1271/ccs/tools/compiler/ti-cgt-arm_20.2.7.LTS/include
ASM = C:/ti/ccs1271/ccs/tools/compiler/ti-cgt-arm_20.2.7.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccs1271/ccs/tools/compiler/ti-cgt-arm_20.2.7.LTS/include
diff --git a/src/sysbios/sysbios.aem4f b/src/sysbios/sysbios.aem4f
index 57b4203..fe551a3 100644
Binary files a/src/sysbios/sysbios.aem4f and b/src/sysbios/sysbios.aem4f differ