project additions/changes

This commit is contained in:
2022-02-18 10:21:19 -06:00
parent a7303fe5f9
commit debbd37501
26 changed files with 1906 additions and 690 deletions

37
labW9barnestr/Inc/delay.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* delay.h
*
* Created on: Dec 10, 2021
* Author: Trevor Barnes
*/
//include guards
#ifndef DELAY_H_
#define DELAY_H_
#include <inttypes.h>
#define STK_CTRL (volatile uint32_t*) 0xE000E010
#define STK_LOAD (volatile uint32_t*) 0xE000E014
#define STK_VAL (volatile uint32_t*) 0xE000E018
#define EN 1
#define TICKINT (1<<1)
#define CLKSOURCE (1<<2)
#define COUNTFLAG (1<<16)
/*
* delay_1ms
* Busy wait for n ms
*
* For n iterations
* load number of cycles for 1 ms
* set one to enable and clock source
*
* wait for countflag to be set
*/
void delay_1ms(uint32_t n);
#endif /* DELAY_H_ */

101
labW9barnestr/Inc/led.h Normal file
View File

@@ -0,0 +1,101 @@
/*
* led.h
*
* Created on: Dec 10, 2021
* Author: Trevor Barnes
*/
#ifndef LED_H_
#define LED_H_
#include <inttypes.h>
#define RCC_AHB1ENR (volatile uint32_t*) 0x40023830
#define GPIOBEN 1
#define GPIOB_MODER (volatile uint32_t*) 0x40020400
#define GPIOB_PUPDR (volatile uint32_t*) 0x4002040C
#define GPIOB_IDR (volatile uint32_t*) 0x40020410
#define GPIOB_ODR (volatile uint32_t*) 0x40020414
#define GPIOB_BSRR (volatile uint32_t*) 0x40020418
#define ALL_LEDS (0b11110111111<<5)
/*
* led_init()
* This function should:
* 1. Enable the GPIOB in RCC_AHB1ENR
* 2. Turn on to set LED0 - LED9 to output mode ("01")
*/
void led_init();
/*
* led_allOn()
* 1. Turn on all leds (hint use ODR or BSRR)
* Note you should not effect other pins on PortB
*/
void led_allOn();
/*
* led_allOff()
* 1. Turn off all leds (hint use ODR or BSRR)
* Note you should not effect other pins on PortB
*/
void led_allOff();
/*
* led_on()
* Args: 0-9 to turn on specific led
* print error message is arg is out of range
*/
void led_on(uint8_t ledIndex);
/*
* led_off()
* Args: 0-9 to turn off specific led
* print error message is arg is out of range
*/
void led_off(uint8_t ledIndex);
/*
* led_scan()
* Scan the light across and back at the current speed
*/
void led_scan();
/*
* led_flash()
* flash all of the lights 10 times at the current speed
*/
void led_flash();
/*
* led_setSpeed (uint8_t speed)
* arg: speed (0 slow - 9 fast)
* Args out of range should print error to console
*/
void led_setSpeed(uint8_t speed);
/*
* led_incSpeed()
* increases the speed by one
* if maxed out leaves the speed at the max value
*/
void led_incSpeed();
/*
* led_decSpeed()
* decreases the speed by one
* if at zero should stay at zero
*/
void led_decSpeed();
/*
* getCurrentSpeed
* returns the current speed
*/
uint8_t getCurrentSpeed();
#endif

View File

@@ -0,0 +1,41 @@
/**
* @file tasker.h
* @author Trevor Barnes
* @brief
* @version 0.1
* @date 2022-02-11
*
* @copyright Copyright (c) 2022
*
*/
#include <inttypes.h>
typedef enum{PAUSED, ACTIVE} task_state;
#define SCB_ICSR 0xE000D04
#define PENDSVSET 28
extern int num_tasks;
extern int current_task;
extern int next_task;
extern Task tasks[];
typedef struct {
uint32_t* stack_pointer;
uint32_t ticks_starting;
uint32_t ticks_remaining;
task_state state;
} Task;
void SysTick_Init();
void tasker_tick();
void init_tasker(uint32_t total_tasks, uint32_t main_ticks);
void init_task(uint32_t task_num, uint32_t stacksize,
void(*entry_point)(void), uint32_t ticks);
void PendSV_Handler(void __attribute__((naked)));

View File

@@ -0,0 +1,49 @@
/*
* uart_driver.h
*
* Created on: Nov 8, 2016
* Author: barnekow
*/
#ifndef UART_DRIVER_H_
#define UART_DRIVER_H_
#include <inttypes.h>
// RCC registers
#define RCC_APB1ENR (volatile uint32_t*) 0x40023840
#define RCC_AHB1ENR (volatile uint32_t*) 0x40023830
#define GPIOAEN 0 // GPIOA Enable is bit 0 in RCC_APB1LPENR
#define USART2EN 17 // USART2 enable is bit 17 in RCC_AHB1LPENR
// GPIOA registers
#define GPIOA_MODER (volatile uint32_t*) 0x40020000
#define GPIOA_AFRL (volatile uint32_t*) 0x40020020
#define USART_SR (volatile uint32_t*) 0x40004400
#define USART_DR (volatile uint32_t*) 0x40004404
#define USART_BRR (volatile uint32_t*) 0x40004408
#define USART_CR1 (volatile uint32_t*) 0x4000440c
#define USART_CR2 (volatile uint32_t*) 0x40004410
#define USART_CR3 (volatile uint32_t*) 0x40004414
// CR1 bits
#define UE 13 //UART enable
#define TE 3 // Transmitter enable
#define RE 2 // Receiver enable
// Status register bits
#define TXE 7 // Transmit register empty
#define RXNE 5 // Receive register is not empty..char received
// Function prototypes
extern void init_usart2(uint32_t baud, uint32_t sysclk);
extern char usart2_getch();
extern void usart2_putch(char c);
// syscalls overrides
int _read(int file, char *ptr, int len);
int _write(int file, char *ptr, int len);
#endif /* UART_DRIVER_H_ */