Skip to content

Commit

Permalink
Modified to simple LED version
Browse files Browse the repository at this point in the history
  • Loading branch information
jondurrant committed Sep 6, 2022
1 parent a289612 commit cdee90d
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 227 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ node_modules
# Ignore files related to API keys
.env

build
build
.project
1 change: 0 additions & 1 deletion 5-Semaphore/TaskNotification/src/BlinkAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class BlinkAgent: public Agent {
*/
virtual configSTACK_DEPTH_TYPE getMaxStackSize();

private:
//GPIO PAD for LED
uint8_t xLedPad = 0;

Expand Down
80 changes: 80 additions & 0 deletions 5-Semaphore/TaskNotification/src/BlinkWorker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* BlinkWorker.cpp
*
* Blink worker, to blink LED on a GPIO pad but do a random amount of work
* between blinks
*
* Created on: 17 Aug 2022
* Author: jondurrant
*/

#include "BlinkWorker.h"
#include "math.h"
#include <cstdio>

//Blink Delay
#define DELAY 500

/***
* Constructor
* @param gp = GPIO pad number
*/
BlinkWorker::BlinkWorker(uint8_t gp):BlinkAgent(gp) {
//NOP

}

/***
* Destructor
*/
BlinkWorker::~BlinkWorker() {
// NOP
}

/***
* Main Run Task for agent
*/
void BlinkWorker::run(){

printf("Blink Started\n");

gpio_init(xLedPad);

gpio_set_dir(xLedPad, GPIO_OUT);

while (true) { // Loop forever
gpio_put(xLedPad, 1);
vTaskDelay(DELAY);
gpio_put(xLedPad, 0);

int n = rand() % 5000;
for (int i=0; i < n; i++ ){
double d = asin(sin(sqrt((double)n)));
d = acos(cos(d));
}
vTaskDelay(DELAY);
if (pPeer != NULL){
xTaskNotifyGive(pPeer->getTask());
}
uint32_t r = ulTaskNotifyTake(pdTRUE, DELAY);
}

}

/***
* Get the static depth required in words
* @return - words
*/
configSTACK_DEPTH_TYPE BlinkWorker::getMaxStackSize(){
return 150;
}


/***
* Set Peer Worker
* @param peer - peer BlinkWorker that we will sync blink with
*/
void BlinkWorker::setPeer(BlinkWorker *peer){
pPeer = peer;
}

62 changes: 62 additions & 0 deletions 5-Semaphore/TaskNotification/src/BlinkWorker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* BlinkWorker.h
*
* Blink worker, to blink LED on a GPIO pad but do a random amount of work
* between blinks
*
* Created on: 17 Aug 2022
* Author: jondurrant
*/

#ifndef BLINKWORKER_H_
#define BLINKWORKER_H_

#include "pico/stdlib.h"
#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"

#include "BlinkAgent.h"


class BlinkWorker: public BlinkAgent {
public:
/***
* Constructor
* @param gp = GPIO pad number
*/
BlinkWorker(uint8_t gp);

/***
* Destructor
*/
virtual ~BlinkWorker();

/***
* Set Peer Worker
* @param peer - peer BlinkWorker that we will sync blink with
*/
virtual void setPeer(BlinkWorker *peer);


protected:

/***
* Run loop for the agent.
*/
virtual void run();


/***
* Get the static depth required in words
* @return - words
*/
virtual configSTACK_DEPTH_TYPE getMaxStackSize();


BlinkWorker *pPeer = NULL;

};


#endif /* BLINKWORKER_H_ */
2 changes: 1 addition & 1 deletion 5-Semaphore/TaskNotification/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(${NAME}
main.cpp
BlinkAgent.cpp
Agent.cpp
RainbowAgent.cpp
BlinkWorker.cpp
)

# Pull in our pico_stdlib which pulls in commonly used features
Expand Down
120 changes: 0 additions & 120 deletions 5-Semaphore/TaskNotification/src/RainbowAgent.cpp

This file was deleted.

91 changes: 0 additions & 91 deletions 5-Semaphore/TaskNotification/src/RainbowAgent.h

This file was deleted.

Loading

0 comments on commit cdee90d

Please sign in to comment.