labw9
This commit is contained in:
@@ -67,8 +67,8 @@ Note songFG[77] = {
|
|||||||
{E4, E}, {r, E}, {G4, E}, {r, S}, {G4, S}, {E4, E}, {C4, E}, {r, Q},
|
{E4, E}, {r, E}, {G4, E}, {r, S}, {G4, S}, {E4, E}, {C4, E}, {r, Q},
|
||||||
{A3, E}, {r, E}, {C4, E}, {r, S}, {A3, S}, {E4, E}, {D4, E}, {r, Q},
|
{A3, E}, {r, E}, {C4, E}, {r, S}, {A3, S}, {E4, E}, {D4, E}, {r, Q},
|
||||||
{G5, S}, {Gb5, S}, {G5, E+(Q*3)},
|
{G5, S}, {Gb5, S}, {G5, E+(Q*3)},
|
||||||
{r , E}, {F5, E}, {E5, E}, {F5, E}, {E5, E}, {C5, E}, {A4, E}, {G4, E+(Q*5)},
|
{r , E}, {F5, E}, {E5, E}, {F5, E}, {E5, E}, {C5, E}, {A4, E},
|
||||||
{r, E},
|
{G4, E+(Q*5)}, {r, E},
|
||||||
{C5, E}, {B4, E}, {D5, E}, {A5, E}, {G5, E+W+E}, {r, E},
|
{C5, E}, {B4, E}, {D5, E}, {A5, E}, {G5, E+W+E}, {r, E},
|
||||||
{A5, E}, {B5, E}, {A5, E}, {G5, E}, {F5, E}, {E5, E}, {D5, E}, {E5, Q},
|
{A5, E}, {B5, E}, {A5, E}, {G5, E}, {F5, E}, {E5, E}, {D5, E}, {E5, Q},
|
||||||
{C5, E}, {G4, E+(Q*3)}, {r, E},
|
{C5, E}, {G4, E+(Q*3)}, {r, E},
|
||||||
@@ -167,7 +167,8 @@ void TIM4_IRQHandler(void) {
|
|||||||
// Delay for duration of note
|
// Delay for duration of note
|
||||||
|
|
||||||
//delay_1ms(noteToPlay.noteDuration);
|
//delay_1ms(noteToPlay.noteDuration);
|
||||||
|
// Instead of delay, have timer count to loaded value
|
||||||
|
// Then trigger interrupt when count value has been reached
|
||||||
|
|
||||||
// Load timer with value of note duration
|
// Load timer with value of note duration
|
||||||
//currentNote = currentSong[currentNoteIndex];
|
//currentNote = currentSong[currentNoteIndex];
|
||||||
|
|||||||
@@ -11,6 +11,94 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
// RCC
|
||||||
|
typedef struct {
|
||||||
|
uint32_t CR;
|
||||||
|
uint32_t PLL_CFGR;
|
||||||
|
uint32_t CFGR;
|
||||||
|
uint32_t CIR;
|
||||||
|
uint32_t AHB1RSTR;
|
||||||
|
uint32_t AHB2RSTR;
|
||||||
|
uint32_t AHB3RSTR;
|
||||||
|
uint32_t _RESERVED_1_;
|
||||||
|
uint32_t APB1RSTR;
|
||||||
|
uint32_t APB2RSTR;
|
||||||
|
uint32_t _RESERVED_2_;
|
||||||
|
uint32_t _RESERVED_3_;
|
||||||
|
uint32_t AHB1ENR;
|
||||||
|
uint32_t AHB2ENR;
|
||||||
|
uint32_t AHB3ENR;
|
||||||
|
uint32_t _RESERVED_4_;
|
||||||
|
uint32_t APB1ENR;
|
||||||
|
uint32_t APB2ENR;
|
||||||
|
uint32_t _RESERVED_5_;
|
||||||
|
uint32_t _RESERVED_6_;
|
||||||
|
} RCC;
|
||||||
|
|
||||||
|
// GPIO
|
||||||
|
typedef struct {
|
||||||
|
uint32_t MODER;
|
||||||
|
uint32_t OTYPER;
|
||||||
|
uint32_t OSPEEDER;
|
||||||
|
uint32_t PUPDR;
|
||||||
|
uint32_t IDR;
|
||||||
|
uint32_t ODR;
|
||||||
|
uint32_t BSRR;
|
||||||
|
uint32_t LCKR;
|
||||||
|
uint32_t AFRL;
|
||||||
|
uint32_t AFRH;
|
||||||
|
} GPIO;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t CR1; // Control Register 1
|
||||||
|
uint32_t CR2; // Control Register 2
|
||||||
|
uint32_t SMCR; // Slave Mode Control Register
|
||||||
|
uint32_t DIER; // DMA/Interrupt Enable Register
|
||||||
|
uint32_t SR; // Status Register
|
||||||
|
uint32_t EGR; // Event Generation Register
|
||||||
|
uint32_t CCMR1; // Capture/Compare Mode Register 1
|
||||||
|
uint32_t CCMR2; // Capture/Compare Mode Register 2
|
||||||
|
uint32_t CCER; // Capture/Compare Enable Register
|
||||||
|
uint32_t CNT; // Counter
|
||||||
|
uint32_t PSC; // Prescaler
|
||||||
|
uint32_t ARR; // Auto-Reload Register
|
||||||
|
uint32_t _RESERVED_1_;
|
||||||
|
uint32_t CCR1; // Capture/Compare Register 1
|
||||||
|
uint32_t CCR2; // Capture/Compare Register 2
|
||||||
|
uint32_t CCR3; // Capture/Compare Register 3
|
||||||
|
uint32_t CCR4; // Capture/Compare Register 4
|
||||||
|
uint32_t _RESERVED_2_;
|
||||||
|
uint32_t DCR; // DMA Control Register
|
||||||
|
uint32_t DMAR; // DMA Address for Full Transfer
|
||||||
|
uint32_t TIM2_OR; // TIM2 Option Register
|
||||||
|
uint32_t TIM5_OR; // TIM5 Option Register
|
||||||
|
} TIM;
|
||||||
|
|
||||||
|
// Will have to include timer for task switching interrupt
|
||||||
|
|
||||||
|
// SYSCFG
|
||||||
|
typedef struct {
|
||||||
|
uint32_t MEMRMP;
|
||||||
|
uint32_t PMC;
|
||||||
|
uint32_t EXTICR1;
|
||||||
|
uint32_t EXTICR2;
|
||||||
|
uint32_t EXTICR3;
|
||||||
|
uint32_t EXTICR4;
|
||||||
|
uint32_t CMPCR;
|
||||||
|
uint32_t CFGR;
|
||||||
|
} SYSCFG;
|
||||||
|
|
||||||
|
// Interrupt
|
||||||
|
#define NVIC_ISER1 (volatile uint32_t*) 0xE000E104
|
||||||
|
typedef struct {
|
||||||
|
uint32_t IMR;
|
||||||
|
uint32_t EMR;
|
||||||
|
uint32_t RTSR;
|
||||||
|
uint32_t FTSR;
|
||||||
|
uint32_t SWIER;
|
||||||
|
uint32_t PR;
|
||||||
|
} EXTI;
|
||||||
|
|
||||||
typedef enum{PAUSED, ACTIVE} task_state;
|
typedef enum{PAUSED, ACTIVE} task_state;
|
||||||
|
|
||||||
#define SCB_ICSR 0xE000D04
|
#define SCB_ICSR 0xE000D04
|
||||||
@@ -29,8 +117,6 @@ typedef struct {
|
|||||||
task_state state;
|
task_state state;
|
||||||
} Task;
|
} Task;
|
||||||
|
|
||||||
void SysTick_Init();
|
|
||||||
|
|
||||||
void tasker_tick();
|
void tasker_tick();
|
||||||
|
|
||||||
void init_tasker(uint32_t total_tasks, uint32_t main_ticks);
|
void init_tasker(uint32_t total_tasks, uint32_t main_ticks);
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* @file main.c
|
* @file main.c
|
||||||
* @author Trevor Barnes
|
* @author Trevor Barnes
|
||||||
* @brief
|
* @brief Main driver for the task switching lab. Provides the code that
|
||||||
|
* initlizes the tasker/tasks. Also initializes any components being used
|
||||||
|
* in the tasks.
|
||||||
|
* Experience: Although this lab is not finished, I could see how to go
|
||||||
|
* about implementing the task switching. Each requested task would have
|
||||||
|
* been intilialized and the program would continuously switch between
|
||||||
|
* each task for an alotted or infinite amount of time.
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @date 2022-02-11
|
* @date 2022-02-11
|
||||||
*
|
*
|
||||||
@@ -14,10 +20,124 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "uart_driver.h"
|
#include "uart_driver.h"
|
||||||
#include "delay.h"
|
#include "memory.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
#include "delay.h"
|
||||||
|
#include "piezoSpeaker.h"
|
||||||
#include "tasker.h"
|
#include "tasker.h"
|
||||||
|
|
||||||
int main(void) {
|
#define F_CPU 16000000UL
|
||||||
|
|
||||||
|
void printHelp() {
|
||||||
|
printf("*Commands*\n\r");
|
||||||
|
printf("'rmw {hex address}' - Reads mem at a given address\n\r");
|
||||||
|
printf("'wmw {hex address} {value}' - Writes the given value as a word to "
|
||||||
|
"the given address\n\r");
|
||||||
|
printf("'dm {hex address} {length}' - Dumps the memory at a given address. "
|
||||||
|
"Defaults to 16 B if no length is given\n\r");
|
||||||
|
printf("'ps {song choice}' - Plays a song with the given selection\n\r");
|
||||||
|
printf("'songs' - Prints info about each song selection\n\r");
|
||||||
|
}
|
||||||
|
void songInfo() {
|
||||||
|
printf("Type 1 or 2 to play a song!\n\r");
|
||||||
|
printf("Song 1: Imperial March from Star Wars\n\r");
|
||||||
|
printf("Song 2: Metropolis Theme from Ratchet & Clank\n\r");
|
||||||
|
printf("Song 3: Flower Garden from Yoshi's Island\n\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
init_usart2(57600, F_CPU);
|
||||||
|
piezo_init();
|
||||||
|
led_init();
|
||||||
|
// Entry point for each task
|
||||||
|
// TODO: Arbitrary values for now
|
||||||
|
uint32_t * t1 = 0;
|
||||||
|
uint32_t * t2 = 0;
|
||||||
|
// Setup tasks
|
||||||
|
init_tasker(2, 20);
|
||||||
|
// Init Knight Rider Lights
|
||||||
|
// TODO: Find out what values are reasonable to init with, arbitrary for now
|
||||||
|
init_task(1, 50, t1, 10);
|
||||||
|
// Init Music
|
||||||
|
init_task(2, 50, t2, 10);
|
||||||
|
// Constantly switch between tasks in forever loop
|
||||||
|
|
||||||
|
// Following will need to be moved and/or greatly altered
|
||||||
|
char line[50];
|
||||||
|
char command[10];
|
||||||
|
int address;
|
||||||
|
int data;
|
||||||
|
int length;
|
||||||
|
int songSelection;
|
||||||
|
char background;
|
||||||
|
for(;;) {
|
||||||
|
// Get command from user
|
||||||
|
fgets(line, 100, stdin);
|
||||||
|
// Parse only the command for strcmp
|
||||||
|
sscanf(line, "%s", command);
|
||||||
|
if (!strcmp(command, "help")) {
|
||||||
|
// Print Help
|
||||||
|
printHelp();
|
||||||
|
} else if (!strcmp(command, "songs")) {
|
||||||
|
// Print Song Info
|
||||||
|
songInfo();
|
||||||
|
} else if (!strcmp(command, "rmw")) {
|
||||||
|
// Read Memory
|
||||||
|
sscanf(line, "%s %X", command, &address);
|
||||||
|
readMem(address);
|
||||||
|
} else if (!strcmp(command, "wmw")) {
|
||||||
|
// Write Memory
|
||||||
|
sscanf(line, "%s %X %u", command, &address, &data);
|
||||||
|
writeMem(address, data);
|
||||||
|
} else if (!strcmp(command, "dm")) {
|
||||||
|
// Dump Memory
|
||||||
|
sscanf(line, "%s %X %u", command, &address, &length);
|
||||||
|
dumpMem(address, length);
|
||||||
|
} else if (!strcmp(command, "ps")) {
|
||||||
|
// Song Selection Command Format:
|
||||||
|
// "ps {songSelection} {background}"
|
||||||
|
sscanf(line, "%s %u %c", command, &songSelection, &background);
|
||||||
|
if (background == 'b') {
|
||||||
|
switch(songSelection) {
|
||||||
|
case 1:
|
||||||
|
printf("Playing Imperial March in the background\n\r");
|
||||||
|
play_song_br(songIM);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
printf("Playing Metropolis Theme in the background\n\r");
|
||||||
|
play_song_br(songMT);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
printf("Playing Flower Garden in the background\n\r");
|
||||||
|
play_song_br(songFG);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
printf("Invalid song selection\n\r");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Without valid flag, program plays songs in foreground
|
||||||
|
switch(songSelection) {
|
||||||
|
case 1:
|
||||||
|
printf("Playing Imperial March\n\r");
|
||||||
|
play_song(songIM);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
printf("Playing Metropolis Theme\n\r");
|
||||||
|
play_song(songMT);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
printf("Playing Flower Garden\n\r");
|
||||||
|
play_song(songFG);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
printf("Invalid song selection\n\r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("Invalid input, type 'help' for instructions\n\r");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,9 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "tasker.h"
|
#include "tasker.h"
|
||||||
|
|
||||||
void SysTick_Init() {
|
|
||||||
|
|
||||||
}
|
void init_task(uint32_t task_num, uint32_t stacksize, void(*entry_point)(void),
|
||||||
|
uint32_t ticks) {
|
||||||
void init_task(uint32_t task_num, uint32_t stacksize, void(*entry_point)(void), uint32_t ticks) {
|
|
||||||
tasks[task_num].stack_pointer = (uint32_t*)malloc(stacksize*sizeof(uint32_t));
|
tasks[task_num].stack_pointer = (uint32_t*)malloc(stacksize*sizeof(uint32_t));
|
||||||
tasks[task_num].stack_pointer += stacksize;
|
tasks[task_num].stack_pointer += stacksize;
|
||||||
*(--tasks[task_num].stack_pointer) = 0x01000000; // PSR
|
*(--tasks[task_num].stack_pointer) = 0x01000000; // PSR
|
||||||
@@ -61,10 +59,6 @@ void tasker_tick() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SysTick_Handler(void) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void PendSV_Handler(void) {
|
void PendSV_Handler(void) {
|
||||||
register uint32_t* stack_pointer asm("r13");
|
register uint32_t* stack_pointer asm("r13");
|
||||||
asm volatile("push {r4-r11,lr}");
|
asm volatile("push {r4-r11,lr}");
|
||||||
|
|||||||
Reference in New Issue
Block a user