4th Semseter files
This commit is contained in:
6
4th-Semester-Spring-2023/Embedded/.vscode/settings.json
vendored
Executable file
6
4th-Semester-Spring-2023/Embedded/.vscode/settings.json
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"stdbool.h": "c",
|
||||
"embedded_utils.h": "c"
|
||||
}
|
||||
}
|
||||
BIN
4th-Semester-Spring-2023/Embedded/Final_Exam_IES_Spring 2023.docx
Executable file
BIN
4th-Semester-Spring-2023/Embedded/Final_Exam_IES_Spring 2023.docx
Executable file
Binary file not shown.
BIN
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/.Jan19_CirArea.c.swp
Executable file
BIN
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/.Jan19_CirArea.c.swp
Executable file
Binary file not shown.
BIN
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/CirArea.out
Executable file
BIN
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/CirArea.out
Executable file
Binary file not shown.
16
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/Jan19_CirArea.c
Executable file
16
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/Jan19_CirArea.c
Executable file
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#define PI 3.141593
|
||||
|
||||
float circleArea(float radius);
|
||||
|
||||
int main()
|
||||
{
|
||||
float radius = 5;
|
||||
printf("Area of circle with radius %4.3f is %4.3f\n", radius, circleArea(radius));
|
||||
return 0;
|
||||
}
|
||||
|
||||
float circleArea(float radius)
|
||||
{
|
||||
return PI * radius * radius;
|
||||
}
|
||||
12
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/Jan19_SubF.c
Executable file
12
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/Jan19_SubF.c
Executable file
@@ -0,0 +1,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
float average(int a, int b, int c)
|
||||
{
|
||||
return (a + b + c) / 3.0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("%4.3f\n", average(4, 5, 6));
|
||||
return 0;
|
||||
}
|
||||
BIN
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/Jan19_SubF.out
Executable file
BIN
4th-Semester-Spring-2023/Embedded/Lectures/Lecture01/Jan19_SubF.out
Executable file
Binary file not shown.
28
4th-Semester-Spring-2023/Embedded/Lectures/Lecture05/Makefile
Executable file
28
4th-Semester-Spring-2023/Embedded/Lectures/Lecture05/Makefile
Executable file
@@ -0,0 +1,28 @@
|
||||
ifndef $(MSPGCCDIR)
|
||||
MSPGCCDIR=$(HOME)/ti/msp430-gcc
|
||||
endif
|
||||
#paths
|
||||
INCLUDES_DIRECTORY = $(MSPGCCDIR)/include
|
||||
|
||||
DEVICE = msp430fr2355
|
||||
|
||||
# compiler options
|
||||
CC=$(MSPGCCDIR)/bin/msp430-elf-gcc
|
||||
|
||||
CFLAGS = -I . -I $(INCLUDES_DIRECTORY) -mmcu=$(DEVICE) -g -mhwmult=f5series
|
||||
LFLAGS = -L . -L $(INCLUDES_DIRECTORY)
|
||||
|
||||
# mspdebug driver -- used for installation
|
||||
DRIVER:= tilib
|
||||
|
||||
# Compiling
|
||||
all: main.elf
|
||||
|
||||
%.elf : %.c
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $< -o $@
|
||||
|
||||
install: main.elf
|
||||
mspdebug $(DRIVER) "prog $<" --allow-fw-update
|
||||
|
||||
clean:
|
||||
rm -f *.o *.elf
|
||||
62
4th-Semester-Spring-2023/Embedded/Lectures/Lecture05/notes.md
Executable file
62
4th-Semester-Spring-2023/Embedded/Lectures/Lecture05/notes.md
Executable file
@@ -0,0 +1,62 @@
|
||||
# Intro to Embedded Systems Lecture Notes: January 31st, 2023
|
||||
|
||||
## POLLING
|
||||
|
||||
**Initialize the port**
|
||||
|
||||
Output:
|
||||
```c
|
||||
P6DIR |= BIT6;
|
||||
P6OUT &= ~BIT6;
|
||||
```
|
||||
Input:
|
||||
```c
|
||||
P4DIR &= ~BIT1;
|
||||
```
|
||||
Clear LOCKLPM5 (Lock low-power mode) from PMCTL0 (Power management control):
|
||||
```c
|
||||
PMCTL0 &= ~LOCKLPM5;
|
||||
```
|
||||
|
||||
Program the board
|
||||
|
||||
**Floating condition: not 1 or 0**
|
||||
Fix using pull-up/pull-down resistor
|
||||
|
||||
## PULL-UP / PULL-DOWN RESISTORS
|
||||
|
||||
**Pull-up resesistor**
|
||||
- Active Low
|
||||
- Mostly preferrable for MCUs
|
||||
- Safety -> reduces noise
|
||||
|
||||
**Pull-down resistor**
|
||||
- Active high
|
||||
|
||||
## I/O Configuration
|
||||
|
||||
|
||||
| P<sub>x</sub>DIR | P<sub>x</sub>REN | P<sub>x</sub>OUT | Comment |
|
||||
|-------|-------|-------|----------------|
|
||||
| 0 | 0 | X | Input |
|
||||
| 0 | 1 | 0 | Input with PDR |
|
||||
| 0 | 1 | 1 | Input with PUR |
|
||||
| 1 | X | X | Output |
|
||||
|
||||
## LOW POWER MODE
|
||||
|
||||
| SCG<sub>1 | SCG<sub>0 | OSC OFF | CPU OFF | Mode |
|
||||
|------|------|---------|---------|----------|
|
||||
| 0 | 0 | 0 | 0 | Active |
|
||||
| 0 | 0 | 0 | 1 | LPM0 |
|
||||
| 0 | 1 | 0 | 1 | LPM1 |
|
||||
| 1 | 0 | 0 | 1 | LPM2 |
|
||||
| 1 | 1 | 0 | 1 | LPM3 |
|
||||
| 1 | 1 | 1 | 1 | LPM4 |
|
||||
|
||||
## WHEN INTERRUPT HAPPENS
|
||||
- Processor stops what it's doing
|
||||
- Stores information to later resume
|
||||
- Executes interrupt service routine (ISR)
|
||||
- Restores saved information
|
||||
- Resumes execution
|
||||
62
4th-Semester-Spring-2023/Embedded/Lectures/Lecture06/notes.md
Executable file
62
4th-Semester-Spring-2023/Embedded/Lectures/Lecture06/notes.md
Executable file
@@ -0,0 +1,62 @@
|
||||
# Intro to Embedded Systems Lecture Notes: February 2nd, 2023
|
||||
|
||||
## Registers
|
||||
|
||||
|Reg Name|Function|
|
||||
|-------|-------|
|
||||
|P<sub>x</sub>SEL| Function select register
|
||||
|P<sub>x</sub>DIR | Whether input or output
|
||||
|P<sub>x</sub>OUT| Output value
|
||||
|P<sub>x</sub>IN| Input value
|
||||
|P<sub>x</sub>REN |Pull-up / Pull-down resistor
|
||||
|P<sub>x</sub>IE | Interrupt enable
|
||||
|P<sub>x</sub>IFG | Interrupt flag register
|
||||
|P<sub>x</sub>IES | Interrupt edge select register
|
||||
|
||||
|
||||
## P<sub>x</sub>SEL
|
||||
|
||||
|P<sub>x</sub>SEL1|P<sub>x</sub>SEL0| I/O Function
|
||||
|----|-----|----
|
||||
|0|0|General purpose I/O
|
||||
|0|1|ADC
|
||||
|1|0|Timer
|
||||
|1|1|Digital Communication (SPI / UART / I<sup>2</sup>C)
|
||||
|
||||
## Using P<sub>x</sub>SEL to Modify Behavior of P<sub>1.7</sub>
|
||||
|
||||
### GPIO Function
|
||||
```
|
||||
P1SEL1 &= ~BIT7;
|
||||
P1SEL0 &= ~BIT7;
|
||||
```
|
||||
|
||||
### ADC Function
|
||||
```
|
||||
P1SEL1 &= ~BIT7;
|
||||
P1SEL0 |= BIT7;
|
||||
```
|
||||
|
||||
### Timer Function
|
||||
```
|
||||
P1SEL1 |= BIT7;
|
||||
P1SEL0 &= ~BIT7;
|
||||
```
|
||||
|
||||
### SPI (Requires 4 Pins)
|
||||
```
|
||||
P1SEL1 |= 0xF0;
|
||||
P1SEL0 |= 0xF0;
|
||||
```
|
||||
|
||||
## Using P<sub>x</sub>IE, P<sub>x</sub>IFG, and P<sub>x</sub>IES
|
||||
|
||||
|Level Triggering | Edge Triggering |
|
||||
|--|--|
|
||||
|Signal asserted when high| Signal asseted on positive* edge
|
||||
|Signal not asserted when low|
|
||||
|
||||
\* positive edge only used when using positive edge triggering. Negative edge triggering also exists
|
||||
|
||||
|
||||
|
||||
BIN
4th-Semester-Spring-2023/Embedded/Lectures/Lecture07/L#4-Interrupts_Polling.pptx
Executable file
BIN
4th-Semester-Spring-2023/Embedded/Lectures/Lecture07/L#4-Interrupts_Polling.pptx
Executable file
Binary file not shown.
54
4th-Semester-Spring-2023/Embedded/Lectures/Lecture07/notes.md
Executable file
54
4th-Semester-Spring-2023/Embedded/Lectures/Lecture07/notes.md
Executable file
@@ -0,0 +1,54 @@
|
||||
# Intro to Embedded Systems Lecture Notes: February 7th, 2023
|
||||
|
||||
## Using Interrupts
|
||||
```c
|
||||
#define INTERRUPT_PINS 0x03
|
||||
|
||||
int main(void)
|
||||
{
|
||||
P4IE |= INTERRUPT_PINS; // Local interrupt enable
|
||||
P4IFG |= INTERRUPT_PINS;
|
||||
P4IES |= INTERRUPT_PINS;
|
||||
|
||||
_enable_interrupts(); // Global interrupt enable
|
||||
__bis_SR_register(GIE);
|
||||
|
||||
while (true)
|
||||
{
|
||||
...
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Port 4 interrupt service routine
|
||||
void __attribute__ ((interrupt(PORT4_VECTOR))) Port_4 (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Interrupt Servicing Summary
|
||||
1. Interrupt Pending
|
||||
2. Complete Current Instruction
|
||||
3. Clear SR
|
||||
4. Retrieve starting address of ISR & put address in PC
|
||||
5. Execute ISR
|
||||
6. Pop SR and PC from stack
|
||||
7. Continue to main program
|
||||
|
||||
## Multiple Interrupts
|
||||
### Three Types:
|
||||
1. Reset Interrupt
|
||||
2. Maskable Interrupt
|
||||
- ADC, port, timer, e_USCI
|
||||
- User-asserted event
|
||||
3. Non-Maskable Interrupt
|
||||
- Fault, error detection
|
||||
- Oscillator fault
|
||||
- Flash key violation
|
||||
|
||||
## Priority of Interrupts
|
||||
1. Timers
|
||||
2. e_USCI
|
||||
3. ADC
|
||||
4. Port
|
||||
17
4th-Semester-Spring-2023/Embedded/MSP-Testing/.vscode/c_cpp_properties.json
vendored
Executable file
17
4th-Semester-Spring-2023/Embedded/MSP-Testing/.vscode/c_cpp_properties.json
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"${$HOME}/ti/"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/bin/gcc",
|
||||
"cStandard": "gnu17",
|
||||
"cppStandard": "gnu++17",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
28
4th-Semester-Spring-2023/Embedded/MSP-Testing/Makefile
Executable file
28
4th-Semester-Spring-2023/Embedded/MSP-Testing/Makefile
Executable file
@@ -0,0 +1,28 @@
|
||||
ifndef $(MSPGCCDIR)
|
||||
MSPGCCDIR=$(HOME)/ti/msp430-gcc
|
||||
endif
|
||||
#paths
|
||||
INCLUDES_DIRECTORY = $(MSPGCCDIR)/include
|
||||
|
||||
DEVICE = msp430fr2355
|
||||
|
||||
# compiler options
|
||||
CC=$(MSPGCCDIR)/bin/msp430-elf-gcc
|
||||
|
||||
CFLAGS = -I . -I $(INCLUDES_DIRECTORY) -mmcu=$(DEVICE) -g -mhwmult=f5series
|
||||
LFLAGS = -L . -L $(INCLUDES_DIRECTORY)
|
||||
|
||||
# mspdebug driver -- used for installation
|
||||
DRIVER:= tilib
|
||||
|
||||
# Compiling
|
||||
all: main.elf
|
||||
|
||||
%.elf : %.c
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $< -o $@
|
||||
|
||||
install: main.elf
|
||||
mspdebug $(DRIVER) "prog $<" --allow-fw-update
|
||||
|
||||
clean:
|
||||
rm -f *.o *.elf
|
||||
31
4th-Semester-Spring-2023/Embedded/MSP-Testing/main.c
Executable file
31
4th-Semester-Spring-2023/Embedded/MSP-Testing/main.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include <msp430fr2355.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
// half a second at 1Mhz
|
||||
#define BLINK_CYCLES 2000000L
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// stop watchdog timer
|
||||
WDTCTL = WDTPW | WDTHOLD;
|
||||
|
||||
// allow changes to port registers
|
||||
PM5CTL0 &= ~LOCKLPM5;
|
||||
|
||||
P1DIR |= BIT0; // set pin 1.0 as output
|
||||
P1OUT &= ~BIT0; // clear pin 1.0 (make it low)
|
||||
|
||||
P4DIR |= BIT0; // set pin 4.6 as output
|
||||
P4OUT |= BIT6; // set pin 4.6 (make it high)
|
||||
|
||||
while (true)
|
||||
{
|
||||
__delay_cycles(BLINK_CYCLES);
|
||||
P1OUT ^= BIT0; // toggle pin 1.0
|
||||
P4OUT ^= BIT6; // toggle pin 4.6
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
BIN
4th-Semester-Spring-2023/Embedded/MSP-Testing/main.elf
Executable file
BIN
4th-Semester-Spring-2023/Embedded/MSP-Testing/main.elf
Executable file
Binary file not shown.
28
4th-Semester-Spring-2023/Embedded/Makefile
Executable file
28
4th-Semester-Spring-2023/Embedded/Makefile
Executable file
@@ -0,0 +1,28 @@
|
||||
ifndef $(MSPGCCDIR)
|
||||
MSPGCCDIR=$(HOME)/ti/msp430-gcc
|
||||
endif
|
||||
#paths
|
||||
INCLUDES_DIRECTORY = $(MSPGCCDIR)/include
|
||||
|
||||
DEVICE = msp430fr2355
|
||||
|
||||
# compiler options
|
||||
CC=$(MSPGCCDIR)/bin/msp430-elf-gcc
|
||||
|
||||
CFLAGS = -I . -I $(INCLUDES_DIRECTORY) -mmcu=$(DEVICE) -g -mhwmult=f5series
|
||||
LFLAGS = -L . -L $(INCLUDES_DIRECTORY)
|
||||
|
||||
# mspdebug driver -- used for installation
|
||||
DRIVER:= tilib
|
||||
|
||||
# Compiling
|
||||
all: main.elf
|
||||
|
||||
%.elf : %.c
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $< -o $@
|
||||
|
||||
install: main.elf
|
||||
mspdebug $(DRIVER) "prog $<" --allow-fw-update
|
||||
|
||||
clean:
|
||||
rm -f *.o *.elf
|
||||
28
4th-Semester-Spring-2023/Embedded/SamplingLab/Makefile
Executable file
28
4th-Semester-Spring-2023/Embedded/SamplingLab/Makefile
Executable file
@@ -0,0 +1,28 @@
|
||||
ifndef $(MSPGCCDIR)
|
||||
MSPGCCDIR=$(HOME)/ti/msp430-gcc
|
||||
endif
|
||||
#paths
|
||||
INCLUDES_DIRECTORY = $(MSPGCCDIR)/include
|
||||
|
||||
DEVICE = msp430fr2355
|
||||
|
||||
# compiler options
|
||||
CC=$(MSPGCCDIR)/bin/msp430-elf-gcc
|
||||
|
||||
CFLAGS = -I . -I $(INCLUDES_DIRECTORY) -mmcu=$(DEVICE) -g -mhwmult=f5series
|
||||
LFLAGS = -L . -L $(INCLUDES_DIRECTORY)
|
||||
|
||||
# mspdebug driver -- used for installation
|
||||
DRIVER:= tilib
|
||||
|
||||
# Compiling
|
||||
all: main.elf
|
||||
|
||||
%.elf : %.c
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $< -o $@
|
||||
|
||||
install: main.elf
|
||||
mspdebug $(DRIVER) "prog $<" --allow-fw-update
|
||||
|
||||
clean:
|
||||
rm -f *.o *.elf
|
||||
232
4th-Semester-Spring-2023/Embedded/SamplingLab/embedded_utils.h
Executable file
232
4th-Semester-Spring-2023/Embedded/SamplingLab/embedded_utils.h
Executable file
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
* Adog64's wonderful library of Embedded System Utility Functions for the MSP430FR2355
|
||||
**/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <msp430.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// #define OUTPUT 0x01
|
||||
// #define INPUT 0x00
|
||||
|
||||
#define LOCATION_OF_P1DIR 0x0204
|
||||
#define LOCATION_OF_P1OUT 0x0202
|
||||
#define LOCATION_OF_P1IE 0x021A
|
||||
#define LOCATION_OF_P1IES 0x0218
|
||||
#define LOCATION_OF_P1IN 0x0200
|
||||
|
||||
#define LOCATION_OF_TB0CTL 0x0380
|
||||
|
||||
#define TIMER_SOURCE_SMCLK 0
|
||||
#define TIMER_SOURCE_ACLK 1
|
||||
#define TIMER_SOURCE_VLOCLK 2
|
||||
|
||||
#define TIMER_MODE_1STOP 0
|
||||
#define TIMER_MODE_UP 1
|
||||
#define TIMER_MODE_CONTINUOUS 2
|
||||
#define TIMER_MODE_UP_DOWN 3
|
||||
|
||||
// ======= PORT MEMORY LOCATION TABLE =======
|
||||
// | PORT | DIR | OUT | IE | IES |
|
||||
// |--------|-------|-------|-------|-------|
|
||||
// | P1 | 0204h | 0202h | 021Ah | 0218h |
|
||||
// | P2 | 0205h | 0203h | 021Bh | 0219h |
|
||||
// | P3 | 0224h | 0222h | 023Ah | 0238h |
|
||||
// | P4 | 0225h | 0223h | 023Bh | 0239h |
|
||||
// | P5 | 0244h | 0242h | 025Ah | 0258h |
|
||||
// | P6 | 0245h | 0243h | 025Bh | 0259h |
|
||||
|
||||
/// @brief kill the watchdog timer
|
||||
void killWatchdogTimer();
|
||||
|
||||
/// @brief disable low power lock on GPIO
|
||||
void unlockGPIO();
|
||||
|
||||
// ===== GPIO Config =====
|
||||
|
||||
/// @brief Set a pin as output P[port].[pin]
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void setAsOutput(char port, char pin);
|
||||
|
||||
/// @brief Set a pin as input P[port].[pin]
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void setAsInput(char port, char pin);
|
||||
|
||||
/// @brief Set the value of pin P[port].[pin] to logic 1
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void setPinValue(char port, char pin);
|
||||
|
||||
/// @brief Clear the value of pin P[port].[pin] to logic 0
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void clearPinValue(char port, char pin);
|
||||
|
||||
/// @brief Toggle the value of pin P[port].[pin]
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void togglePinValue(char port, char pin);
|
||||
|
||||
/// @brief Read the value from a GPIO pin
|
||||
/// @param port the port containing pin
|
||||
/// @param pin bit index within port
|
||||
void getPinValue(char port, char pin);
|
||||
|
||||
|
||||
// ===== Interrupt Config =====
|
||||
|
||||
/// @brief Enable interrupts locally on pin P[port].[pin]
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within register
|
||||
void enablePinInterrupt(char port, char pin);
|
||||
|
||||
/// @brief Set the interrupt trigger edge to the rising edge
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within register
|
||||
void setInterruptEdgeRising(char port, char pin);
|
||||
|
||||
/// @brief Set the interrupt trigger edge to the falling edge
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within register
|
||||
void setInterruptEdgeFalling(char port, char pin);
|
||||
|
||||
// ===== Timer Config =====
|
||||
|
||||
|
||||
/// @brief Set the value of ID
|
||||
/// @param timer Timer that ID
|
||||
/// @param n value of ID = 2^n
|
||||
void setB3TimerID(char timer, char n);
|
||||
|
||||
/// @brief Set the value of IDEX for the timer
|
||||
/// @param timer timer being modified
|
||||
/// @param n value of ID = 2^n
|
||||
// void setB3TimerIDEX(char timer, char n);
|
||||
|
||||
/// @brief Clear the timer register
|
||||
/// @param timer timer being modified
|
||||
void resetB3Timer(char timer);
|
||||
|
||||
/// @brief Set timer mode
|
||||
/// @param timer timer being modified
|
||||
void setB3TimerMode(char timer, char mode);
|
||||
|
||||
/// @brief Generate a PWM signal on the 1 MHz SMCLK
|
||||
/// @param timer timer to generate signal on
|
||||
/// @param duty_cycle_us the time the signal is high in microseconds
|
||||
void generateTimerPWM(char timer, char duty_cycle_us);
|
||||
|
||||
/// @brief Undefined function; called for generating a PWM signal when TB0_PWM is a defined macro
|
||||
void tb0SignalLow();
|
||||
|
||||
/// @brief Undefined function; called for generating a PWM signal when TB0_PWM is a defined macro
|
||||
void tb0SignalHigh();
|
||||
|
||||
/// @brief Undefined function; called for generating a PWM signal when TB1_PWM is a defined macro
|
||||
void tb1SignalLow();
|
||||
|
||||
/// @brief Undefined function; called for generating a PWM signal when TB1_PWM is a defined macro
|
||||
void tb1SignalHigh();
|
||||
|
||||
//================= DEFINITIONS ==================
|
||||
|
||||
void setAsOutput(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin; // select the bit to change by left shifting the logic 1 in BIT0 to its final spot
|
||||
port -= 1; // change from 1-indexed ports to 0-indexed ports
|
||||
char* dir = LOCATION_OF_P1DIR + ((port >> 1) << 5) + (port & 1); // find the memory location of the selected port (3 groups of 2 consecutive memory locations; groups spaced by 20h)
|
||||
*dir |= bit; // set the bit in the memory location to logic 1
|
||||
}
|
||||
|
||||
void setAsInput(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin; // select the bit to change by left shifting the logic 1 in BIT0 to its final spot
|
||||
port -= 1; // change from 1-indexed ports to 0-indexed ports
|
||||
char* dir = LOCATION_OF_P1DIR + ((port >> 1) << 5) + (port & 1); // find the memory location of the selected port (3 groups of 2 consecutive memory locations; groups spaced by 20h)
|
||||
*dir &= ~bit; // set the bit in the memory location to logic 0
|
||||
}
|
||||
|
||||
|
||||
void setPinValue(char port , char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* out = LOCATION_OF_P1OUT + ((port >> 1) << 5) + (port & 1);
|
||||
*out |= bit;
|
||||
}
|
||||
|
||||
void clearPinValue(char port , char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* out = LOCATION_OF_P1OUT + ((port >> 1) << 5) + (port & 1);
|
||||
*out &= ~bit;
|
||||
}
|
||||
|
||||
void getPinValue(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* out = LOCATION_OF_P1IN + ((port >> 1) << 5) + (port & 1);
|
||||
*out |= bit;
|
||||
}
|
||||
|
||||
void togglePinValue(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* out = LOCATION_OF_P1OUT + ((port >> 1) << 5) + (port & 1);
|
||||
*out ^= bit;
|
||||
}
|
||||
|
||||
void enablePinInterrupt(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* ie = LOCATION_OF_P1IE + ((port >> 1) << 5) + (port & 1);
|
||||
*ie |= bit;
|
||||
}
|
||||
|
||||
void setInterruptEdgeRising(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* ies = LOCATION_OF_P1IES + ((port >> 1) << 5) + (port & 1);
|
||||
*ies &= ~bit;
|
||||
}
|
||||
|
||||
void setInterruptEdgeFalling(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* ies = LOCATION_OF_P1IES + ((port >> 1) << 5) + (port & 1);
|
||||
*ies |= bit;
|
||||
}
|
||||
|
||||
void killWatchdogTimer()
|
||||
{
|
||||
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
|
||||
}
|
||||
|
||||
void unlockGPIO()
|
||||
{
|
||||
PM5CTL0 &= ~LOCKLPM5;
|
||||
}
|
||||
|
||||
void setB3TimerID(char timer, char n)
|
||||
{
|
||||
// | n | bit |
|
||||
// |----|---------------|
|
||||
// | 0 | 0b00xx_xxxx |
|
||||
// | 1 | 0b01xx_xxxx |
|
||||
// | 2 | 0b10xx_xxxx |
|
||||
// | 3 | 0b11xx_xxxx |
|
||||
|
||||
int bit = n << 6;
|
||||
int* timer_ctl = LOCATION_OF_TB0CTL + (timer << 6);
|
||||
*timer_ctl |= ((BIT6|BIT7) & bit);
|
||||
}
|
||||
361
4th-Semester-Spring-2023/Embedded/SamplingLab/main.c
Executable file
361
4th-Semester-Spring-2023/Embedded/SamplingLab/main.c
Executable file
@@ -0,0 +1,361 @@
|
||||
//******************************************************************************
|
||||
|
||||
// MSP430FR235x Demo - SAC-L3, DAC Buffer Mode
|
||||
|
||||
//
|
||||
|
||||
// Description: Configure SAC-L3 for DAC Buffer Mode. Use the 12 bit DAC to
|
||||
|
||||
// output positive ramp. The OA is set in buffer mode to improve DAC output
|
||||
|
||||
// drive strength. Internal 2.5V reference is selected as DAC reference.
|
||||
|
||||
// Observe the output of OA0O pin with oscilloscope.
|
||||
|
||||
// ACLK = n/a, MCLK = SMCLK = default DCODIV ~1MHz.
|
||||
|
||||
//
|
||||
|
||||
// MSP430FR235x
|
||||
|
||||
// -------------------
|
||||
|
||||
// /|\| |
|
||||
|
||||
// | | |
|
||||
|
||||
// --|RST DAC12->OA0O|--> oscilloscope
|
||||
|
||||
// | |
|
||||
|
||||
// | |
|
||||
|
||||
// | |
|
||||
|
||||
// | |
|
||||
|
||||
// | |
|
||||
|
||||
//
|
||||
|
||||
// Darren Lu
|
||||
|
||||
// Texas Instruments Inc.
|
||||
|
||||
// Oct. 2016
|
||||
|
||||
// Built with IAR Embedded Workbench v6.50 & Code Composer Studio v6.2
|
||||
|
||||
//******************************************************************************
|
||||
|
||||
#include <msp430.h>
|
||||
|
||||
|
||||
|
||||
|
||||
void gpioInit();
|
||||
|
||||
void adcInit();
|
||||
|
||||
void sacInit();
|
||||
|
||||
void timerInit();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned int DAC_data=0;
|
||||
|
||||
unsigned int ADC_Result = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
|
||||
{
|
||||
|
||||
WDTCTL = WDTPW + WDTHOLD; // Stop watch dog timer
|
||||
|
||||
|
||||
|
||||
|
||||
gpioInit();
|
||||
|
||||
|
||||
|
||||
|
||||
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
|
||||
|
||||
// to activate previously configured port settings
|
||||
|
||||
|
||||
|
||||
|
||||
sacInit();
|
||||
|
||||
timerInit();
|
||||
|
||||
|
||||
|
||||
|
||||
adcInit();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
while(1){
|
||||
|
||||
ADCCTL0 |= ADCENC | ADCSC; // Sampling and conversion start
|
||||
|
||||
__bis_SR_register(LPM0_bits | GIE); // LPM0, ADC_ISR will force exit
|
||||
|
||||
__no_operation(); // For debug only
|
||||
|
||||
DAC_data = ADC_Result;
|
||||
|
||||
__delay_cycles(10);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void gpioInit()
|
||||
|
||||
{
|
||||
|
||||
P1OUT &= ~BIT0; // Clear P1.0 output latch for a defined power-on state
|
||||
|
||||
P1DIR |= BIT0; // Set P1.0 to output direction
|
||||
|
||||
P1SEL0 |= BIT1; // Select P1.1 as OA0O function
|
||||
|
||||
P1SEL1 |= BIT1; // OA is used as buffer for DAC
|
||||
|
||||
|
||||
|
||||
|
||||
// Configure ADC A5 pin
|
||||
|
||||
P1SEL0 |= BIT5;
|
||||
|
||||
P1SEL1 |= BIT5;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void sacInit()
|
||||
|
||||
{
|
||||
|
||||
// Configure reference module
|
||||
|
||||
PMMCTL0_H = PMMPW_H; // Unlock the PMM registers
|
||||
|
||||
PMMCTL2 = INTREFEN | REFVSEL_2; // Enable internal 2.5V reference
|
||||
|
||||
while(!(PMMCTL2 & REFGENRDY)); // Poll till internal reference settles
|
||||
|
||||
|
||||
|
||||
|
||||
SAC0DAC = DACSREF_1 + DACLSEL_2 + DACIE; // Select int Vref as DAC reference
|
||||
|
||||
SAC0DAT = DAC_data; // Initial DAC data
|
||||
|
||||
SAC0DAC |= DACEN; // Enable DAC
|
||||
|
||||
|
||||
|
||||
|
||||
SAC0OA = NMUXEN + PMUXEN + PSEL_1 + NSEL_1;//Select positive and negative pin input
|
||||
|
||||
SAC0OA |= OAPM_0; // Select low speed and low power mode
|
||||
|
||||
SAC0PGA = MSEL_1; // Set OA as buffer mode
|
||||
|
||||
SAC0OA |= SACEN + OAEN; // Enable SAC and OA
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void timerInit()
|
||||
|
||||
{
|
||||
|
||||
// Use TB2.1 as DAC hardware trigger
|
||||
|
||||
TB2CCR0 = 100-1; // PWM Period/2
|
||||
|
||||
TB2CCTL1 = OUTMOD_6; // TBCCR1 toggle/set
|
||||
|
||||
TB2CCR1 = 50; // TBCCR1 PWM duty cycle
|
||||
|
||||
TB2CTL = TBSSEL__SMCLK | MC_1 | TBCLR; // SMCLK, up mode, clear TBR
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void adcInit()
|
||||
|
||||
{
|
||||
|
||||
// Configure ADC12
|
||||
|
||||
ADCCTL0 |= ADCSHT_2 | ADCON; // ADCON, S&H=16 ADC clks
|
||||
|
||||
ADCCTL1 |= ADCSHP; // ADCCLK = MODOSC; sampling timer
|
||||
|
||||
ADCCTL2 &= ~ADCRES; // clear ADCRES in ADCCTL
|
||||
|
||||
ADCCTL2 |= ADCRES_2; // 12-bit conversion results
|
||||
|
||||
ADCMCTL0 |= ADCINCH_5; // A5 ADC input select; Vref=AVCC
|
||||
|
||||
ADCIE |= ADCIE0; // Enable ADC conv complete interrupt
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
|
||||
|
||||
#pragma vector = SAC0_SAC2_VECTOR
|
||||
|
||||
__interrupt void SAC0_ISR(void)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
void __attribute__ ((interrupt(SAC0_SAC2_VECTOR))) SAC0_ISR (void)
|
||||
|
||||
#else
|
||||
|
||||
#error Compiler not supported!
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
|
||||
switch(__even_in_range(SAC0IV,SACIV_4))
|
||||
|
||||
{
|
||||
|
||||
case SACIV_0: break;
|
||||
|
||||
case SACIV_2: break;
|
||||
|
||||
case SACIV_4:
|
||||
|
||||
//DAC_data++;
|
||||
|
||||
DAC_data &= 0xFFF;
|
||||
|
||||
SAC0DAT = DAC_data; // DAC12 output positive ramp
|
||||
|
||||
break;
|
||||
|
||||
default: break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ADC interrupt service routine
|
||||
|
||||
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
|
||||
|
||||
#pragma vector=ADC_VECTOR
|
||||
|
||||
__interrupt void ADC_ISR(void)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
|
||||
|
||||
#else
|
||||
|
||||
#error Compiler not supported!
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
|
||||
switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
|
||||
|
||||
{
|
||||
|
||||
case ADCIV_NONE:
|
||||
|
||||
break;
|
||||
|
||||
case ADCIV_ADCOVIFG:
|
||||
|
||||
break;
|
||||
|
||||
case ADCIV_ADCTOVIFG:
|
||||
|
||||
break;
|
||||
|
||||
case ADCIV_ADCHIIFG:
|
||||
|
||||
break;
|
||||
|
||||
case ADCIV_ADCLOIFG:
|
||||
|
||||
break;
|
||||
|
||||
case ADCIV_ADCINIFG:
|
||||
|
||||
break;
|
||||
|
||||
case ADCIV_ADCIFG:
|
||||
|
||||
ADC_Result = ADCMEM0;
|
||||
|
||||
P1OUT ^= BIT0;
|
||||
|
||||
__bic_SR_register_on_exit(LPM0_bits); // Clear CPUOFF bit from LPM0
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
BIN
4th-Semester-Spring-2023/Embedded/SamplingLab/main.elf
Executable file
BIN
4th-Semester-Spring-2023/Embedded/SamplingLab/main.elf
Executable file
Binary file not shown.
28
4th-Semester-Spring-2023/Embedded/UART-Transmission/Makefile
Executable file
28
4th-Semester-Spring-2023/Embedded/UART-Transmission/Makefile
Executable file
@@ -0,0 +1,28 @@
|
||||
ifndef $(MSPGCCDIR)
|
||||
MSPGCCDIR=$(HOME)/ti/msp430-gcc
|
||||
endif
|
||||
#paths
|
||||
INCLUDES_DIRECTORY = $(MSPGCCDIR)/include
|
||||
|
||||
DEVICE = msp430fr2355
|
||||
|
||||
# compiler options
|
||||
CC=$(MSPGCCDIR)/bin/msp430-elf-gcc
|
||||
|
||||
CFLAGS = -I . -I $(INCLUDES_DIRECTORY) -mmcu=$(DEVICE) -g -mhwmult=f5series
|
||||
LFLAGS = -L . -L $(INCLUDES_DIRECTORY)
|
||||
|
||||
# mspdebug driver -- used for installation
|
||||
DRIVER:= tilib
|
||||
|
||||
# Compiling
|
||||
all: main.elf
|
||||
|
||||
%.elf : %.c
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $< -o $@
|
||||
|
||||
install: main.elf
|
||||
mspdebug $(DRIVER) "prog $<" --allow-fw-update
|
||||
|
||||
clean:
|
||||
rm -f *.o *.elf
|
||||
62
4th-Semester-Spring-2023/Embedded/UART-Transmission/main.c
Executable file
62
4th-Semester-Spring-2023/Embedded/UART-Transmission/main.c
Executable file
@@ -0,0 +1,62 @@
|
||||
#include <msp430.h> //115200, No jumper change
|
||||
|
||||
char result[] = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!'};
|
||||
|
||||
void uart_init(void);
|
||||
void port_init();
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
|
||||
PM5CTL0 &= ~LOCKLPM5;
|
||||
|
||||
port_init();
|
||||
int m=0;
|
||||
uart_init();
|
||||
__delay_cycles(5); // Wait for ADC Ref to settle
|
||||
int acount = 0;
|
||||
while(1){
|
||||
if(m == 0)
|
||||
{
|
||||
__delay_cycles(200);
|
||||
// then conver the Fahrenheit integer to an ASCII char array
|
||||
// while(result[acount]!='\0')
|
||||
//{
|
||||
while((UCA1IFG & UCTXIFG)==0); //Wait Unitl the UART transmitter is ready //UCTXIFG
|
||||
UCA1TXBUF = result[acount] ; //Transmit the received data.
|
||||
acount = (acount < 13) ? acount + 1 : 0;
|
||||
}//while
|
||||
}//main
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void uart_init(void){
|
||||
// Configure UART
|
||||
UCA1CTLW0 |= UCSWRST;
|
||||
|
||||
/*UCA1CTLW0 |= UCSSEL__ACLK;//UCSSEL__SMCLK;
|
||||
UCA1BRW = 3;//8; // 9600
|
||||
UCA1MCTLW = 0X92;//0xD600;*/
|
||||
UCA1CTLW0 |= UCSSEL__SMCLK;
|
||||
UCA1BRW = 8; // 115200
|
||||
UCA1MCTLW = 0xD600;
|
||||
UCA1CTLW0 &= ~UCSWRST; // Initialize eUSCI
|
||||
UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt ??
|
||||
}
|
||||
|
||||
|
||||
|
||||
void port_init(){
|
||||
P1DIR |= BIT0;
|
||||
P1OUT |= BIT0;
|
||||
P4SEL0 |= BIT2 | BIT3; // set 2-UART pin as second function
|
||||
P4SEL1 &= ~BIT2; // set 2-UART pin as second function
|
||||
P4SEL1 &= ~ BIT3; // set 2-UART pin as second function
|
||||
|
||||
}
|
||||
|
||||
|
||||
BIN
4th-Semester-Spring-2023/Embedded/UART-Transmission/main.elf
Executable file
BIN
4th-Semester-Spring-2023/Embedded/UART-Transmission/main.elf
Executable file
Binary file not shown.
232
4th-Semester-Spring-2023/Embedded/embedded_utils.h
Executable file
232
4th-Semester-Spring-2023/Embedded/embedded_utils.h
Executable file
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
* Adog64's wonderful library of Embedded System Utility Functions for the MSP430FR2355
|
||||
**/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <msp430.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// #define OUTPUT 0x01
|
||||
// #define INPUT 0x00
|
||||
|
||||
#define LOCATION_OF_P1DIR 0x0204
|
||||
#define LOCATION_OF_P1OUT 0x0202
|
||||
#define LOCATION_OF_P1IE 0x021A
|
||||
#define LOCATION_OF_P1IES 0x0218
|
||||
#define LOCATION_OF_P1IN 0x0200
|
||||
|
||||
#define LOCATION_OF_TB0CTL 0x0380
|
||||
|
||||
#define TIMER_SOURCE_SMCLK 0
|
||||
#define TIMER_SOURCE_ACLK 1
|
||||
#define TIMER_SOURCE_VLOCLK 2
|
||||
|
||||
#define TIMER_MODE_1STOP 0
|
||||
#define TIMER_MODE_UP 1
|
||||
#define TIMER_MODE_CONTINUOUS 2
|
||||
#define TIMER_MODE_UP_DOWN 3
|
||||
|
||||
// ======= PORT MEMORY LOCATION TABLE =======
|
||||
// | PORT | DIR | OUT | IE | IES |
|
||||
// |--------|-------|-------|-------|-------|
|
||||
// | P1 | 0204h | 0202h | 021Ah | 0218h |
|
||||
// | P2 | 0205h | 0203h | 021Bh | 0219h |
|
||||
// | P3 | 0224h | 0222h | 023Ah | 0238h |
|
||||
// | P4 | 0225h | 0223h | 023Bh | 0239h |
|
||||
// | P5 | 0244h | 0242h | 025Ah | 0258h |
|
||||
// | P6 | 0245h | 0243h | 025Bh | 0259h |
|
||||
|
||||
/// @brief kill the watchdog timer
|
||||
void killWatchdogTimer();
|
||||
|
||||
/// @brief disable low power lock on GPIO
|
||||
void unlockGPIO();
|
||||
|
||||
// ===== GPIO Config =====
|
||||
|
||||
/// @brief Set a pin as output P[port].[pin]
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void setAsOutput(char port, char pin);
|
||||
|
||||
/// @brief Set a pin as input P[port].[pin]
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void setAsInput(char port, char pin);
|
||||
|
||||
/// @brief Set the value of pin P[port].[pin] to logic 1
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void setPinValue(char port, char pin);
|
||||
|
||||
/// @brief Clear the value of pin P[port].[pin] to logic 0
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void clearPinValue(char port, char pin);
|
||||
|
||||
/// @brief Toggle the value of pin P[port].[pin]
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within port
|
||||
void togglePinValue(char port, char pin);
|
||||
|
||||
/// @brief Read the value from a GPIO pin
|
||||
/// @param port the port containing pin
|
||||
/// @param pin bit index within port
|
||||
void getPinValue(char port, char pin);
|
||||
|
||||
|
||||
// ===== Interrupt Config =====
|
||||
|
||||
/// @brief Enable interrupts locally on pin P[port].[pin]
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within register
|
||||
void enablePinInterrupt(char port, char pin);
|
||||
|
||||
/// @brief Set the interrupt trigger edge to the rising edge
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within register
|
||||
void setInterruptEdgeRising(char port, char pin);
|
||||
|
||||
/// @brief Set the interrupt trigger edge to the falling edge
|
||||
/// @param port port containing pin
|
||||
/// @param pin bit index within register
|
||||
void setInterruptEdgeFalling(char port, char pin);
|
||||
|
||||
// ===== Timer Config =====
|
||||
|
||||
|
||||
/// @brief Set the value of ID
|
||||
/// @param timer Timer that ID
|
||||
/// @param n value of ID = 2^n
|
||||
void setB3TimerID(char timer, char n);
|
||||
|
||||
/// @brief Set the value of IDEX for the timer
|
||||
/// @param timer timer being modified
|
||||
/// @param n value of ID = 2^n
|
||||
// void setB3TimerIDEX(char timer, char n);
|
||||
|
||||
/// @brief Clear the timer register
|
||||
/// @param timer timer being modified
|
||||
void resetB3Timer(char timer);
|
||||
|
||||
/// @brief Set timer mode
|
||||
/// @param timer timer being modified
|
||||
void setB3TimerMode(char timer, char mode);
|
||||
|
||||
/// @brief Generate a PWM signal on the 1 MHz SMCLK
|
||||
/// @param timer timer to generate signal on
|
||||
/// @param duty_cycle_us the time the signal is high in microseconds
|
||||
void generateTimerPWM(char timer, char duty_cycle_us);
|
||||
|
||||
/// @brief Undefined function; called for generating a PWM signal when TB0_PWM is a defined macro
|
||||
void tb0SignalLow();
|
||||
|
||||
/// @brief Undefined function; called for generating a PWM signal when TB0_PWM is a defined macro
|
||||
void tb0SignalHigh();
|
||||
|
||||
/// @brief Undefined function; called for generating a PWM signal when TB1_PWM is a defined macro
|
||||
void tb1SignalLow();
|
||||
|
||||
/// @brief Undefined function; called for generating a PWM signal when TB1_PWM is a defined macro
|
||||
void tb1SignalHigh();
|
||||
|
||||
//================= DEFINITIONS ==================
|
||||
|
||||
void setAsOutput(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin; // select the bit to change by left shifting the logic 1 in BIT0 to its final spot
|
||||
port -= 1; // change from 1-indexed ports to 0-indexed ports
|
||||
char* dir = LOCATION_OF_P1DIR + ((port >> 1) << 5) + (port & 1); // find the memory location of the selected port (3 groups of 2 consecutive memory locations; groups spaced by 20h)
|
||||
*dir |= bit; // set the bit in the memory location to logic 1
|
||||
}
|
||||
|
||||
void setAsInput(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin; // select the bit to change by left shifting the logic 1 in BIT0 to its final spot
|
||||
port -= 1; // change from 1-indexed ports to 0-indexed ports
|
||||
char* dir = LOCATION_OF_P1DIR + ((port >> 1) << 5) + (port & 1); // find the memory location of the selected port (3 groups of 2 consecutive memory locations; groups spaced by 20h)
|
||||
*dir &= ~bit; // set the bit in the memory location to logic 0
|
||||
}
|
||||
|
||||
|
||||
void setPinValue(char port , char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* out = LOCATION_OF_P1OUT + ((port >> 1) << 5) + (port & 1);
|
||||
*out |= bit;
|
||||
}
|
||||
|
||||
void clearPinValue(char port , char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* out = LOCATION_OF_P1OUT + ((port >> 1) << 5) + (port & 1);
|
||||
*out &= ~bit;
|
||||
}
|
||||
|
||||
void getPinValue(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* out = LOCATION_OF_P1IN + ((port >> 1) << 5) + (port & 1);
|
||||
*out |= bit;
|
||||
}
|
||||
|
||||
void togglePinValue(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* out = LOCATION_OF_P1OUT + ((port >> 1) << 5) + (port & 1);
|
||||
*out ^= bit;
|
||||
}
|
||||
|
||||
void enablePinInterrupt(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* ie = LOCATION_OF_P1IE + ((port >> 1) << 5) + (port & 1);
|
||||
*ie |= bit;
|
||||
}
|
||||
|
||||
void setInterruptEdgeRising(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* ies = LOCATION_OF_P1IES + ((port >> 1) << 5) + (port & 1);
|
||||
*ies &= ~bit;
|
||||
}
|
||||
|
||||
void setInterruptEdgeFalling(char port, char pin)
|
||||
{
|
||||
char bit = BIT0 << pin;
|
||||
port -= 1;
|
||||
char* ies = LOCATION_OF_P1IES + ((port >> 1) << 5) + (port & 1);
|
||||
*ies |= bit;
|
||||
}
|
||||
|
||||
void killWatchdogTimer()
|
||||
{
|
||||
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
|
||||
}
|
||||
|
||||
void unlockGPIO()
|
||||
{
|
||||
PM5CTL0 &= ~LOCKLPM5;
|
||||
}
|
||||
|
||||
void setB3TimerID(char timer, char n)
|
||||
{
|
||||
// | n | bit |
|
||||
// |----|---------------|
|
||||
// | 0 | 0b00xx_xxxx |
|
||||
// | 1 | 0b01xx_xxxx |
|
||||
// | 2 | 0b10xx_xxxx |
|
||||
// | 3 | 0b11xx_xxxx |
|
||||
|
||||
int bit = n << 6;
|
||||
int* timer_ctl = LOCATION_OF_TB0CTL + (timer << 6);
|
||||
*timer_ctl |= ((BIT6|BIT7) & bit);
|
||||
}
|
||||
Reference in New Issue
Block a user