Finish lab 5 report
This commit is contained in:
parent
5b65a542a3
commit
8ce053b689
2 changed files with 279 additions and 0 deletions
279
lab5/labReport.md
Normal file
279
lab5/labReport.md
Normal file
|
@ -0,0 +1,279 @@
|
|||
# Experiment Set #5
|
||||
|
||||
## Exercises 13-16
|
||||
|
||||
### Blizzard Finnegan
|
||||
|
||||
13. Use flags you create to coordinate activities.
|
||||
|
||||
`flag.c`
|
||||
|
||||
```c
|
||||
#include "flag.h"
|
||||
CustomFlag FlagOne = Reset;
|
||||
CustomFlag FlagTwo = Reset;
|
||||
void Set_Flag(int flag_num){
|
||||
switch(flag_num){
|
||||
case 1: FlagOne = Set;
|
||||
break;
|
||||
case 2: FlagTwo = Set;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
void Reset_Flag(int flag_num){
|
||||
switch(flag_num){
|
||||
case 1: FlagOne = Reset;
|
||||
break;
|
||||
case 2: FlagTwo = Reset;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
CustomFlag Check_Flag(int flag_num){
|
||||
switch(flag_num){
|
||||
case 1: return FlagOne;
|
||||
case 2: return FlagTwo;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`flag.h`
|
||||
|
||||
```c
|
||||
/*
|
||||
* Flag.h
|
||||
*
|
||||
* Created on: Feb 25, 2024
|
||||
* Author: firestar
|
||||
*/
|
||||
#ifndef SRC_FLAG_H_
|
||||
#define SRC_FLAG_H_
|
||||
typedef enum {Set,Reset} CustomFlag;
|
||||
void Set_Flag(int);
|
||||
void Reset_Flag(int);
|
||||
CustomFlag Check_Flag(int);
|
||||
#endif /* SRC_FLAG_H_ */
|
||||
```
|
||||
|
||||
`main.c`
|
||||
|
||||
```c
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "flag.h"
|
||||
/* USER CODE END Includes */
|
||||
void startGreenFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
for(int i = 0; i < 200; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_12);
|
||||
osDelay(50);
|
||||
}
|
||||
Set_Flag(1);
|
||||
for(int i = 0; i < 20; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_12);
|
||||
osDelay(500);
|
||||
}
|
||||
Reset_Flag(1);
|
||||
for(int i = 0; i < 200; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_12);
|
||||
osDelay(50);
|
||||
}
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
void startRedFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN startRedFlash */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
for(int i = 0; i < 300; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_14);
|
||||
osDelay(50);
|
||||
}
|
||||
Set_Flag(2);
|
||||
for(int i = 0; i < 20; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_14);
|
||||
osDelay(500);
|
||||
}
|
||||
Reset_Flag(2);
|
||||
for(int i = 0; i < 100; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_14);
|
||||
osDelay(50);
|
||||
}
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
/* USER CODE END startRedFlash */
|
||||
}
|
||||
void startBlueFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN startBlueFlash */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15);
|
||||
if(Check_Flag(1) == Set && Check_Flag(2) == Set){
|
||||
osDelay(500);
|
||||
} else {
|
||||
osDelay(50);
|
||||
}
|
||||
}
|
||||
/* USER CODE END startBlueFlash */
|
||||
}
|
||||
```
|
||||
|
||||
14. Use signals to provide unilateral synchronisation.
|
||||
|
||||
```c
|
||||
/* USER CODE BEGIN 4 */
|
||||
void flashForFiveSeconds(uint16_t gpio_pin_number){
|
||||
for(int i = 0; i < 100; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,gpio_pin_number);
|
||||
osDelay(50);
|
||||
}
|
||||
}
|
||||
/* USER CODE END 4 */
|
||||
void startGreenFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
osSignalWait(ThreadFlag,osWaitForever);
|
||||
flashForFiveSeconds(GPIO_PIN_12);
|
||||
}
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
void startRedFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN startRedFlash */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
osSignalWait(ThreadFlag,osWaitForever);
|
||||
flashForFiveSeconds(GPIO_PIN_14);
|
||||
}
|
||||
/* USER CODE END startRedFlash */
|
||||
}
|
||||
void startBlueFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN startBlueFlash */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
for(int i = 0; i < 20; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15);
|
||||
osDelay(500);
|
||||
}
|
||||
osSignalSet(greenLEDFlashHandle,ThreadFlag);
|
||||
osDelay(6000);
|
||||
osSignalSet(redLEDFlashHandle,ThreadFlag);
|
||||
}
|
||||
/* USER CODE END startBlueFlash */
|
||||
}
|
||||
```
|
||||
|
||||
15. Use semaphores to provide unilateral synchronisation.
|
||||
|
||||
```c
|
||||
/* USER CODE BEGIN 4 */
|
||||
void flashForFiveSeconds(uint16_t gpio_pin_number){
|
||||
for(int i = 0; i < 100; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,gpio_pin_number);
|
||||
osDelay(50);
|
||||
}
|
||||
}
|
||||
/* USER CODE END 4 */
|
||||
void startGreenFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
osSemaphoreWait(BlueToGreenEFHandle,portMAX_DELAY);
|
||||
flashForFiveSeconds(GPIO_PIN_12);
|
||||
}
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
void startRedFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN startRedFlash */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
osSemaphoreWait(BlueToRedEFHandle,portMAX_DELAY);
|
||||
flashForFiveSeconds(GPIO_PIN_14);
|
||||
}
|
||||
/* USER CODE END startRedFlash */
|
||||
}
|
||||
void startBlueFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN startBlueFlash */
|
||||
/* Infinite loop */
|
||||
osSemaphoreWait(BlueToGreenEFHandle,0);
|
||||
osSemaphoreWait(BlueToRedEFHandle,0);
|
||||
for(;;)
|
||||
{
|
||||
for(int i = 0; i < 20; i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15);
|
||||
osDelay(500);
|
||||
}
|
||||
osSemaphoreRelease(BlueToGreenEFHandle);
|
||||
osDelay(6000);
|
||||
osSemaphoreRelease(BlueToRedEFHandle);
|
||||
}
|
||||
/* USER CODE END startBlueFlash */
|
||||
}
|
||||
```
|
||||
|
||||
16. Use semaphores to provide bilateral synchronisation.
|
||||
|
||||
```c
|
||||
/* USER CODE BEGIN 4 */
|
||||
void flashFast(uint16_t gpio_pin_number, int duration_s){
|
||||
for(int i = 0; i < (20*duration_s); i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,gpio_pin_number);
|
||||
osDelay(50);
|
||||
}
|
||||
}
|
||||
void flashSlow(uint16_t gpio_pin_number, int duration_s){
|
||||
for(int i = 0; i < (2*duration_s); i++){
|
||||
HAL_GPIO_TogglePin(GPIOD,gpio_pin_number);
|
||||
osDelay(500);
|
||||
}
|
||||
}
|
||||
/* USER CODE END 4 */
|
||||
void startGreenFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
/* Infinite loop */
|
||||
osSemaphoreWait(Sync2Handle,0);
|
||||
for(;;)
|
||||
{
|
||||
flashFast(GPIO_PIN_12,5);
|
||||
osSemaphoreWait(Sync1Handle,portMAX_DELAY);
|
||||
flashSlow(GPIO_PIN_12,10);
|
||||
osSemaphoreRelease(Sync2Handle);
|
||||
}
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
void startRedFlash(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN startRedFlash */
|
||||
/* Infinite loop */
|
||||
osSemaphoreWait(Sync1Handle,0);
|
||||
for(;;)
|
||||
{
|
||||
flashSlow(GPIO_PIN_14,10);
|
||||
osSemaphoreRelease(Sync1Handle);
|
||||
flashFast(GPIO_PIN_14,5);
|
||||
osSemaphoreWait(Sync2Handle,portMAX_DELAY);
|
||||
}
|
||||
/* USER CODE END startRedFlash */
|
||||
}
|
||||
```
|
BIN
lab5/labReport.pdf
Normal file
BIN
lab5/labReport.pdf
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue