diff --git a/common/clock.c b/common/clock.c index fd7ba1d..69d3b7d 100644 --- a/common/clock.c +++ b/common/clock.c @@ -71,4 +71,4 @@ void ClockInit48MHz(void) { 0x00000050 | // configure for SMCLK and HSMCLK sourced from HFXTCLK 0x00000005; // configure for MCLK sourced from HFXTCLK CS->KEY = 0; // lock CS module from unintended access -} \ No newline at end of file +} diff --git a/common/cpu.c b/common/cpu.c new file mode 100644 index 0000000..f8ae136 --- /dev/null +++ b/common/cpu.c @@ -0,0 +1,22 @@ +#include "cpu.h" + +uint32_t __attribute__((naked)) CPU_cpsie(void) +{ + uint32_t ret; + + // + // Read PRIMASK and enable interrupts. + // + __asm(" mrs r0, PRIMASK\n" + " cpsie i\n" + " bx lr\n" + : "=r" (ret)); + + // + // The return is handled in the inline assembly, but the compiler will + // still complain if there is not an explicit return here (despite the fact + // that this does not result in any code being produced because of the + // naked attribute). + // + return(ret); +} \ No newline at end of file diff --git a/common/cpu.h b/common/cpu.h new file mode 100644 index 0000000..c45349d --- /dev/null +++ b/common/cpu.h @@ -0,0 +1,8 @@ +#ifndef CPU_H +#define CPU_H + +#include + +uint32_t CPU_cpsie(void); + +#endif /* CPU_H */ \ No newline at end of file diff --git a/common/reflectance.c b/common/reflectance.c new file mode 100644 index 0000000..a2a4cda --- /dev/null +++ b/common/reflectance.c @@ -0,0 +1,37 @@ +#include "reflectance.h" + +#include "delay.h" + +#include "inc/msp432p401r.h" + +void ReflectanceInit(void) { + // write this as part of Lab 3 +} + +uint8_t ReflectanceRead(uint32_t time) { + // write this as part of Lab 3 + return 0; +} + +int32_t ReflectancePosition(uint8_t sensor_data) { + // write this as part of Lab 3 + return 0; +} + +void ReflectanceStart(void) { + // write this as part of Lab 3 + // turn on 4 even IR LEDs + // turn on 4 odd IR LEDs + // make P7.7-P7.0 out + // prime for measurement + // wait 10 us + // make P7.7-P7.0 in +} + +uint8_t ReflectanceEnd(void) { + // write this as part of Lab 3 + // convert P7.0 input to digital + // turn off 4 even IR LEDs + // turn off 4 odd IR LEDs + return 0; // replace this line +} diff --git a/common/reflectance.h b/common/reflectance.h new file mode 100644 index 0000000..fdf5933 --- /dev/null +++ b/common/reflectance.h @@ -0,0 +1,52 @@ +#ifndef REFLECTANCE_H +#define REFLECTANCE_H + +#include + +// ------------Reflectance_Init------------ +// Initialize the GPIO pins associated with the QTR-8RC +// reflectance sensor. Infrared illumination LEDs are +// initially off. +// Input: none +// Output: none +void ReflectanceInit(void); + +// ------------Reflectance_Read------------ +// Read the eight sensors +// Turn on the 8 IR LEDs +// Pulse the 8 sensors high for 10 us +// Make the sensor pins input +// wait t us +// Read sensors +// Turn off the 8 IR LEDs +// Input: time to wait in usec +// Output: sensor readings +// Assumes: Reflectance_Init() has been called +uint8_t ReflectanceRead(uint32_t time); + +// Perform sensor integration +// Input: data is 8-bit result from line sensor +// Output: position in 0.1mm relative to center of line +int32_t ReflectancePosition(uint8_t line_sensor_data); + +// ------------Reflectance_Start------------ +// Begin the process of reading the eight sensors +// Turn on the 8 IR LEDs +// Pulse the 8 sensors high for 10 us +// Make the sensor pins input +// Input: none +// Output: none +// Assumes: Reflectance_Init() has been called +void ReflectanceStart(void); + +// ------------Reflectance_End------------ +// Finish reading the eight sensors +// Read sensors +// Turn off the 8 IR LEDs +// Input: none +// Output: sensor readings +// Assumes: Reflectance_Init() has been called +// Assumes: Reflectance_Start() was called 1 ms ago +uint8_t ReflectanceEnd(void); + +#endif /* REFLECTANCE_H */ \ No newline at end of file diff --git a/lab1/Makefile b/lab1/Makefile index 72bc400..81e0b30 100644 --- a/lab1/Makefile +++ b/lab1/Makefile @@ -6,8 +6,6 @@ CC = arm-none-eabi-gcc ARMGCC_ROOT := /usr/arm-none-eabi # ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. -ROOT ?= $(abspath ..) - OBJECTS = main.o system.o startup.o NAME = lab diff --git a/lab2/Makefile b/lab2/Makefile index 409c0c8..bdbe9ae 100644 --- a/lab2/Makefile +++ b/lab2/Makefile @@ -5,8 +5,6 @@ CC = arm-none-eabi-gcc # is installed. ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. -ROOT ?= $(abspath ../..) - OBJECTS = main.o bump.o delay.o clock.o system.o startup.o NAME = lab diff --git a/lab3/Makefile b/lab3/Makefile new file mode 100644 index 0000000..baf7de6 --- /dev/null +++ b/lab3/Makefile @@ -0,0 +1,75 @@ +CC = arm-none-eabi-gcc + +# The location of the C compiler +# ARMGCC_ROOT is used by some makefiles that need to know where the compiler +# is installed. +ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. + +OBJECTS = main.o bump.o delay.o clock.o reflectance.o cpu.o system.o startup.o + +NAME = lab + +CFLAGS = -I.. -I../inc -I../common \ + -D__MSP432P401R__ \ + -DDeviceFamily_MSP432P401x \ + -mcpu=cortex-m4 \ + -march=armv7e-m \ + -mthumb \ + -std=c99 \ + -mfloat-abi=hard \ + -mfpu=fpv4-sp-d16 \ + -ffunction-sections \ + -fdata-sections \ + -g \ + -gstrict-dwarf \ + -Wall \ + -I$(ARMGCC_ROOT)/arm-none-eabi/include/newlib-nano \ + -I$(ARMGCC_ROOT)/arm-none-eabi/include + +LFLAGS = -Wl,-T,../config.lds \ + -Wl,-Map,$(NAME).map \ + -march=armv7e-m \ + -mthumb \ + -mfloat-abi=hard \ + -mfpu=fpv4-sp-d16 \ + -static \ + -Wl,--gc-sections \ + -lgcc \ + -lc \ + -lm \ + -lnosys \ + --specs=nano.specs + +all: $(NAME).out + +main.o: main.c + @$(CC) $(CFLAGS) $< -c -o $@ + +bump.o: ../common/bump.c + @$(CC) $(CFLAGS) $< -c -o $@ + +delay.o: ../common/delay.c + @$(CC) $(CFLAGS) $< -c -o $@ + +clock.o: ../common/clock.c + @$(CC) $(CFLAGS) $< -c -o $@ + +reflectance.o: ../common/reflectance.c + @$(CC) $(CFLAGS) $< -c -o $@ + +cpu.o: ../common/cpu.c + @$(CC) $(CFLAGS) $< -c -o $@ + +system.o: ../system.c + @$(CC) $(CFLAGS) $< -c -o $@ + +startup.o: ../startup.c + @$(CC) $(CFLAGS) $< -c -o $@ + +$(NAME).out: $(OBJECTS) + @$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out + +clean: # Redirecting both the stderr and stdout to /dev/null + @rm -f $(OBJECTS) > /dev/null 2>&1 + @rm -f $(NAME).out > /dev/null 2>&1 + @rm -f $(NAME).map > /dev/null 2>&1 diff --git a/lab3/main.c b/lab3/main.c new file mode 100644 index 0000000..14a1d18 --- /dev/null +++ b/lab3/main.c @@ -0,0 +1,44 @@ +#include +#include + +#include "bump.h" +#include "delay.h" +#include "clock.h" +#include "reflectance.h" +#include "cpu.h" + +#include "inc/msp432p401r.h" + +void DebugDump(uint8_t bump, uint8_t line) { + // write this as part of Lab 10 +} + +// **************SysTick_Init********************* +// Initialize SysTick periodic interrupts +// Input: interrupt period +// Units of period are in bus clock period +// Maximum is 2^24-1 +// Minimum is determined by execution time of the ISR +// Input: priority 0 (high) to 7 (low) +// Output: none +void SysTickInit(uint32_t period, uint32_t priority) { + SysTick->CTRL = 0; // 1) disable SysTick during setup + SysTick->LOAD = period - 1; // 2) reload value sets period + SysTick->VAL = 0; // 3) any write to current clears it + SCB->SHP[11] = priority << 5; // set priority into top 3 bits of 8-bit register + SysTick->CTRL = 0x00000007; // 4) enable SysTick with core clock and interrupts +} + +void SysTick_Handler(void) { // every 1ms + // write this as part of Lab 10 +} + +int main(void) { + // write this as part of Lab 3 + ClockInit48MHz(); + BumpInit(); + ReflectanceInit(); + SysTickInit(?, 1); // 1ms SysTickInit + CPU_cpsie(); // Enable interrupts + while (true) {} +}