Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
userOutputTask.c
Go to the documentation of this file.
1 /**
2  ******************************************************************************
3  * @file userOutputTask.c
4  * @author Michael Riedel
5  * @author Marc Kossmann
6  * @version v2.0.0
7  * @date 18.11.2014
8  * @brief Source code for User-Output-Task which communications with
9  * the user and shows him system information
10  ******************************************************************************
11  * @par History:
12  * @details v0.1.0 21.10.2014 Kossmann
13  * - first draft for milestone 1b
14  * @details v0.1.1 30.10.2014 Kossmann
15  * - added error handling for flags and mailboxes
16  * @details v0.1.2 06.11.2014 Riedel
17  * - added usage of new LCD-functions
18  * @details v1.0.0 11.11.2014 Riedel & Kossmann
19  * - moved 1 second wait to userInputTask
20  * @details v1.0.1 13.11.2014 Kossmann
21  * - removed OutputTaskMailbox and using global var instead
22  * @details v2.0.0 18.11.2014 Riedel & Kossmann
23  * - corrected position of version lcd output
24  * - added waiting for GLOB_VAR_UPDATE event @see events.h
25  * - verified functionality -> release MS2
26  * @details v2.0.1 18.11.2014 Riedel & Kossmann
27  * - added terminal output "New Step Chain Event"
28  ******************************************************************************
29  */
30 
31 #include "../INC/userOutputTask.h"
32 
33 extern OS_FLAG_GRP *userOutputTaskFlagsGrp;
34 
35 void UserOutputTask(void *pdata) {
36  uint8_t err;
37  uint8_t modeBits;
38  outputTaskData_t outputTaskDataLocal;
39  OS_FLAGS newFlag;
40  uint32_t termMsgCounter = 2;
41  bool oldMotorRunning = false;
42 
43  // Wait 2 seconds before starting
44  OSTimeDlyHMSM(0, 0, 2, 0);
45 
46  while (1) {
48  OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME, 0, &err);
49  if (OS_NO_ERR == err){
50  if(newFlag & GLOB_VAR_UPDATE) {
51  err = outputTaskDataRx(&outputTaskDataLocal);
52  }
53  if (OS_NO_ERR == err) {
54 
55  /***********************************************************************/
56  /* terminal output */
57  /***********************************************************************/
58  // once when motor is started
59  if ((outputTaskDataLocal.ctrlReg & CTRL_REG_RS_MSK)
60  && !oldMotorRunning) {
61  oldMotorRunning = true;
62  printTerminalInfo(&outputTaskDataLocal, &termMsgCounter);
63  }
64  // when motor stop irq was detected
65  if(newFlag & MOTOR_STOP_EVENT){
66  printf_term("New Step Chain Event\n");
67  }
68  // once when motor is stopped
69  if (!(outputTaskDataLocal.ctrlReg & CTRL_REG_RS_MSK)
70  && oldMotorRunning) {
71  oldMotorRunning = false;
72  printTerminalInfo(&outputTaskDataLocal, &termMsgCounter);
73  }
74  // output of stepsReg every second when motor running
75  if (outputTaskDataLocal.ctrlReg & CTRL_REG_RS_MSK) {
76  printf_term("Steps: %i\n", outputTaskDataLocal.stepsReg);
77  }
78  /***********************************************************************/
79 
80  /***********************************************************************/
81  /* lcd output */
82  /***********************************************************************/
83  clear_lcd();
84  modeBits = (outputTaskDataLocal.ctrlReg & CTRL_REG_MODE_MSK) >> 2;
85  setPos_lcd(1, 1);
86  printf_lcd("M:%i%i%i%i", (modeBits & 0x8) >> 3, (modeBits & 0x4) >> 2,
87  (modeBits & 0x2) >> 1, (modeBits & 0x1));
88  setPos_lcd(1, 11);
89  printf_lcd("v%s", VERSION);
90  if (outputTaskDataLocal.ctrlReg & CTRL_REG_RS_MSK) {
91  setPos_lcd(2, 1);
92  printf_lcd("Running");
93  } else {
94  setPos_lcd(2, 1);
95  printf_lcd("Stopped");
96  }
97  if (DEBUG == outputTaskDataLocal.systemState.operationalStatus) {
98  setPos_lcd(2, 12);
99  printf_lcd("Debug");
100  }
101  fflush_lcd();
102  /***********************************************************************/
103 
104  /***********************************************************************/
105  /* hex-display output */
106  /***********************************************************************/
107  // display direction on hex0
108  if (outputTaskDataLocal.ctrlReg & CTRL_REG_LR_MSK) {
110  } else {
112  }
113  // display mode on hex1
114  switch (outputTaskDataLocal.systemState.activeUseCase) {
115  case QUARTER_ROTATION:
117  break;
118  case HALF_ROTATION:
120  break;
121  case FULL_ROTATION:
123  break;
124  case DOUBLE_ROTATION:
126  break;
127  default:
129  break;
130  }
131  switch (outputTaskDataLocal.speedReg) {
132  case 1:
134  break;
135  case 2:
137  break;
138  case 3:
140  break;
141  case 4:
143  break;
144  case 5:
146  break;
147  case 6:
149  break;
150  case 7:
152  break;
153  case 8:
155  break;
156  case 9:
158  break;
159  default:
161  break;
162  }
163  /***********************************************************************/
164 
165  } else {
166  error("OUTPUT_TASK_GLOB_VAR_ERR: %i\n", err);
167  }
168  } else {
169  error("OUTPUT_TASK_FLAG_ERR: %i\n", err);
170  }
171  fflush_term();
172  }
173 }
174 
175 void printTerminalInfo(outputTaskData_t *outputTaskDataPtr,
176  uint32_t *termMsgCounterPtr) {
177  uint8_t modeBits;
178  printf_term("Message Nr. #%i\n", *termMsgCounterPtr);
179  if (outputTaskDataPtr->ctrlReg & CTRL_REG_RS_MSK) {
180  printf_term("Motor: Running ");
181  } else {
182  printf_term("Motor: Stopped ");
183  }
184  if ((outputTaskDataPtr->ctrlReg & CTRL_REG_LR_MSK)) {
185  printf_term("right\n");
186  } else {
187  printf_term("left\n");
188  }
189  modeBits = (outputTaskDataPtr->ctrlReg & CTRL_REG_MODE_MSK) >> 2;
190  printf_term("M:%i%i%i%i ", (modeBits & 0x8) >> 3, (modeBits & 0x4) >> 2,
191  (modeBits & 0x2) >> 1, (modeBits & 0x1));
192  switch (outputTaskDataPtr->systemState.activeUseCase) {
193  case STOP:
194  printf_term("Stop\n");
195  break;
196  case QUARTER_ROTATION:
197  printf_term("Chain of Steps - 1/4 rotation\n");
198  break;
199  case HALF_ROTATION:
200  printf_term("Chain of Steps - 1/2 rotation\n");
201  break;
202  case FULL_ROTATION:
203  printf_term("Chain of Steps - 1 rotation\n");
204  break;
205  case DOUBLE_ROTATION:
206  printf_term("Chain of Steps - 2 rotations\n");
207  break;
208  case CONTINOUS:
209  printf_term("Continous Run\n");
210  break;
211  default:
212  printf_term("Reserved\n");
213  break;
214  }
215  printf_term("Interrupt-Enable: %i\n",
216  (outputTaskDataPtr->ctrlReg & CTRL_REG_IE_MSK) >> 6);
217  printf_term("Interrupt-Request: %i\n",
218  (outputTaskDataPtr->ctrlReg & CTRL_REG_IR_MSK) >> 7);
219  printf_term("Speed-Step: %i\n", outputTaskDataPtr->speedReg);
220  printf_term("Steps: %i\n", outputTaskDataPtr->stepsReg);
221  (*termMsgCounterPtr)++;
222 }
#define CTRL_REG_LR_MSK
Left (0) or Right (1)-Bit.
void printf_term(const char *,...)
Writes formated string to terminal.
Motor not moving.
Definition: dataTypes.h:28
#define HEX_FIVE
number 5 on HEX-segments
#define HEX_FOUR
number 4 on HEX-segments
#define HEX_LINE
middle line on HEX-segments
#define CTRL_REG_IE_MSK
Interrupt-Enable Bit.
void fflush_lcd()
Writes buffed data to lcd.
static __inline__ void PIO_HEX1_Set(uint32_t segmentValues)
Function to set segments on hex1 display.
#define error(...)
Prints the Error-messages in the terminal.
#define CTRL_REG_MODE_MSK
Mode-combination according to ctrlRegSet()-function.
#define HEX_SEVEN
number 7 on HEX-segments
uint8_t ctrlReg
copy control register
Definition: dataTypes.h:52
void UserOutputTask(void *pdata)
UserOutputTask.
#define HEX_THREE
number 3 on HEX-segments
Motor turning one rotation.
Definition: dataTypes.h:31
static __inline__ void PIO_HEX2_Set(uint32_t segmentValues)
Function to set segments on hex2 display.
#define MOTOR_STOP_EVENT
the interrupt is sent via VHDL-Component, when the motor reached its end-position ...
Definition: events.h:52
state_t operationalStatus
operational status
Definition: dataTypes.h:38
void printTerminalInfo(outputTaskData_t *outputTaskDataPtr, uint32_t *termMsgCounterPtr)
Prints Motor information on the terminal.
debugging is active
Definition: dataTypes.h:23
void clear_lcd(void)
Clears display.
#define HEX_SIX
number 6 on HEX-segments
uint8_t speedReg
copy of speed register
Definition: dataTypes.h:53
#define CTRL_REG_IR_MSK
Interrupt-Request Bit.
systemState_t systemState
stores state of system
Definition: dataTypes.h:50
Motor turning 1/2 rotation.
Definition: dataTypes.h:30
#define HEX_EIGHT
number 8 on HEX-segments
uint8_t outputTaskDataRx(outputTaskData_t *data)
Received data from ipc channel.
Motor is continously running.
Definition: dataTypes.h:33
Motor turning 1/4 rotation.
Definition: dataTypes.h:29
#define HEX_NINE
number 9 on HEX-segments
#define HEX_ZERO
number 0 on HEX-segments
#define HEX_RIGHT
r for right on HEX-segments
OS_FLAG_GRP * userOutputTaskFlagsGrp
The flags group used in the user-output-task.
Definition: events.h:51
#define CTRL_REG_RS_MSK
Run (1) or Stop (0)-Bit.
#define GLOB_VAR_UPDATE
signals that data changed
Definition: events.h:53
void printf_lcd(const char *,...)
Writes formated string to lcd.
#define HEX_ONE
number 1 on HEX-segments
#define VERSION
global version definition
void setPos_lcd(int32_t row, int32_t col)
Sets the cursor position on display.
uint32_t stepsReg
copy of steps register
Definition: dataTypes.h:51
void fflush_term()
Writes buffed data to terminal.
#define HEX_TWO
number 2 on HEX-segments
#define HEX_LEFT
L for left on HEX-segments
Motor turning two rotation.
Definition: dataTypes.h:32
useCases_t activeUseCase
active use case
Definition: dataTypes.h:39
static __inline__ void PIO_HEX0_Set(uint32_t segmentValues)
Function to set segments on hex0 display.
Datatype of global variable for transmitting information from InputTask to OutputTask.
Definition: dataTypes.h:49