Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
heartbeatTask.c
Go to the documentation of this file.
1 /**
2  *****************************************************************************
3  * @file heartbeatTask.c
4  * @author Michael Riedel
5  * @author Marc Kossmann
6  * @version v1.0.0
7  * @date 11.11.2014
8  * @brief Source code of heartbeatTask which shows that scheduling is
9  * working. Also used for debuging.
10  *****************************************************************************
11  * @par History:
12  * @details v0.1.0 30.10.2014 Riedel
13  * - first draft for milestone 1b
14  * @details v0.1.1 31.10.2014 Riedel
15  * - added hardware-access to heartbeat
16  * @details v0.1.2 31.10.2014 Riedel & Kossmann
17  * - finilized heartbeat functionality
18  * @details v0.1.3 02.11.2014 Riedel
19  * - finalized Debug functionality
20  * @details v1.0.0 11.11.2014 Riedel & Kossmann
21  * - switched stepsReg-inc/dec in debug-mode
22  *****************************************************************************
23  */
24 
25 #include "../INC/heartbeatTask.h"
26 
27 extern OS_FLAG_GRP *heartbeatTaskFlagsGrp;
28 
29 void HeartbeatTask(void *pdata) {
30  uint8_t err;
31  OS_FLAGS heartbeatFlag;
32  bool debug = false;
34  heartbeatState_t *heartbeatStatePtr = &heartbeatState;
35 
36  while (1) {
37  heartbeatFlag = OSFlagPend(heartbeatTaskFlagsGrp, (DEBUG_ON_EVENT | DEBUG_OFF_EVENT),
38  OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME, 10, &err);
39  if (OS_NO_ERR != err && OS_TIMEOUT != err) {
40  error("There was an error while waiting for the event!");
41  } else {
42  if (heartbeatFlag & DEBUG_ON_EVENT){
43  debug = true;
44  }else if(heartbeatFlag & DEBUG_OFF_EVENT){
45  debug = false;
46  }
47  if(debug){
48  debugAndHeartbeat(heartbeatStatePtr);
49  }else{
50  nextHeartbeatStep(heartbeatStatePtr);
51  }
52  }
53  }
54 }
55 
56 void nextHeartbeatStep(heartbeatState_t *heartbeatStatePtr) {
57  switch (*heartbeatStatePtr) {
58  case FIRST:
61  *heartbeatStatePtr = SECOND;
62  break;
63  case SECOND:
66  *heartbeatStatePtr = THIRD;
67  break;
68  case THIRD:
71  *heartbeatStatePtr = FOURTH;
72  break;
73  case FOURTH:
76  *heartbeatStatePtr = FIRST;
77  break;
78  default:
79  break;
80  }
81  OSTimeDlyHMSM(0, 0, 1, 0);
82 }
83 
84 void debugAndHeartbeat(heartbeatState_t *heartbeatStatePtr) {
85  uint32_t ctrlReg = 0;
86  uint8_t stepCounter = 0;
87 
88  while (stepCounter < 4) {
89  ctrlReg = ctrlRegGet();
90  // Is Run-Bit == 1? (RUN)
91  if (ctrlReg & CTRL_REG_RS_MSK) {
92  // Is Dir-Bit == 1? (RIGHT)
93  if (ctrlReg & CTRL_REG_LR_MSK) {
94  stepsRegSet(stepsRegGet() + 10);
95  }else{
96  stepsRegSet(stepsRegGet() - 10);
97  }
98  }
99 
100  // Debug things done -> next step of heartbeat-cycle...
101  ++stepCounter;
102  nextHeartbeatStep(heartbeatStatePtr);
103  }
104  // Set IR
106 }
#define CTRL_REG_LR_MSK
Left (0) or Right (1)-Bit.
enum heartbeatState heartbeatState_t
The state-machine for the heartbeat.
static __inline__ void stepsRegSet(uint32_t newStepCount)
Sets the given steps for the Stepper-Motor-Control VHDL-component.
heartbeatState
The state-machine for the heartbeat.
Definition: dataTypes.h:66
#define error(...)
Prints the Error-messages in the terminal.
#define LED_ON
turn the led on
Definition: heartbeatTask.h:47
static __inline__ void ctrlRegBitSet(uint8_t bitsToSet)
Sets the CtrlReg bitwise.
#define DEBUG_OFF_EVENT
deactivates the debug-mode via sw_9
Definition: events.h:44
#define UPPER_O
represents the letter o in the upper HEX-segments
Definition: heartbeatTask.h:45
#define CTRL_REG_IR_MSK
Interrupt-Request Bit.
static __inline__ void PIO_HEX3_Set(uint32_t segmentValues)
Function to set segments on hex3 display.
static __inline__ void PIO_LED9_Set(uint32_t ledValue)
Function to set led9 for heartbeat.
#define debug(...)
Prints Debug-messages in the terminal.
#define LOWER_O
represents the letter o in the lower HEX-segments
Definition: heartbeatTask.h:44
#define DEBUG_ON_EVENT
activates the debug-mode via sw_9
Definition: events.h:43
#define CTRL_REG_RS_MSK
Run (1) or Stop (0)-Bit.
static __inline__ uint32_t stepsRegGet(void)
Returns the actual content of the steps-register.
void HeartbeatTask(void *pdata)
The task for the hearbeat and the debug-mode.
Definition: heartbeatTask.c:29
#define LINE
represents a centered bar in the HEX-segments
Definition: heartbeatTask.h:46
OS_FLAG_GRP * heartbeatTaskFlagsGrp
The flags group used in the heartbeat-task and user-input-task.
Definition: events.h:42
void nextHeartbeatStep(heartbeatState_t *heartbeatStatePtr)
State machine for the heartbeat.
Definition: heartbeatTask.c:56
#define LED_OFF
turn the led off
Definition: heartbeatTask.h:48
static __inline__ uint8_t ctrlRegGet(void)
Returns the actual content of the control-register.
void debugAndHeartbeat(heartbeatState_t *heartbeatStatePtr)
This function implements the debug-logic.
Definition: heartbeatTask.c:84