Added lab3 and files needed for it in the common folder

This commit is contained in:
AntonJ 2025-02-20 16:18:26 +02:00
parent d22cefce1a
commit d81227ddf0
9 changed files with 239 additions and 5 deletions

View File

@ -71,4 +71,4 @@ void ClockInit48MHz(void) {
0x00000050 | // configure for SMCLK and HSMCLK sourced from HFXTCLK 0x00000050 | // configure for SMCLK and HSMCLK sourced from HFXTCLK
0x00000005; // configure for MCLK sourced from HFXTCLK 0x00000005; // configure for MCLK sourced from HFXTCLK
CS->KEY = 0; // lock CS module from unintended access CS->KEY = 0; // lock CS module from unintended access
} }

22
common/cpu.c Normal file
View File

@ -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);
}

8
common/cpu.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef CPU_H
#define CPU_H
#include <stdint.h>
uint32_t CPU_cpsie(void);
#endif /* CPU_H */

37
common/reflectance.c Normal file
View File

@ -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
}

52
common/reflectance.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef REFLECTANCE_H
#define REFLECTANCE_H
#include <stdint.h>
// ------------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 */

View File

@ -5,8 +5,6 @@ CC = arm-none-eabi-gcc
# is installed. # is installed.
ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/..
ROOT ?= $(abspath ..)
OBJECTS = main.o system.o startup.o OBJECTS = main.o system.o startup.o
NAME = lab NAME = lab

View File

@ -5,8 +5,6 @@ CC = arm-none-eabi-gcc
# is installed. # is installed.
ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/..
ROOT ?= $(abspath ../..)
OBJECTS = main.o bump.o delay.o clock.o system.o startup.o OBJECTS = main.o bump.o delay.o clock.o system.o startup.o
NAME = lab NAME = lab

75
lab3/Makefile Normal file
View File

@ -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

44
lab3/main.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdbool.h>
#include <stdint.h>
#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) {}
}