Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
auxilaryFunctions.c
Go to the documentation of this file.
1 /**
2  ***************************************************************************
3  * @file auxilaryFunctions.c
4  * @author Michael Riedel
5  * @author Marc Kossmann
6  * @version v2.0.0
7  * @date 18.11.2014
8  * @brief Collection of auxilary functions, mainly output functions
9  *****************************************************************************
10  * @par History:
11  * @details v0.1.0 28.10.2014 Riedel & Kossmann
12  * - added functions for using printf like lcd and term output
13  * @details v0.1.1 31.10.2014 Riedel & Kossmann
14  * - added timeout for clearing display but not sure if needed
15  * - clear display function added
16  * @details v0.1.2 06.11.2014 Riedel
17  * - implemented some functions for better display-usage
18  * @details v1.0.0 06.11.2014 Riedel
19  * - implemented some functions for better display-usage
20  * @details v1.1.0 14.11.2014 Kossmann
21  * - implemented init rx,tx functions for access to global ipc var
22  * for transmitting data between UserInput- and UserOuputTask
23  * @details v2.0.0 18.11.2014 Riedel & Kossmann
24  * - fixed all global var function parameters
25  * - verified functionality -> release MS2
26  *****************************************************************************
27  */
28 
29 #include "../INC/auxilaryFunctions.h"
30 
31 FILE *term; //!< stream to write on terminal device
32 FILE *lcd; //!< stream to write lcd device
33 
34 outputTaskData_t outputTaskData; //!< Variable for transmitting information from InputTask to OutputTask
35 OS_EVENT *outputTaskDataMutex; //!< Mutex for secured variable acces
36 
38  uint8_t err;
41  .activeUseCase = STOP
42  };
43 
44  outputTaskDataMutex = OSMutexCreate(MUTEX_PRIORITY, &err);
45  if(OS_NO_ERR == err){
46  outputTaskData.ctrlReg = 0;
47  outputTaskData.stepsReg = 0;
48  outputTaskData.speedReg = 0;
49  outputTaskData.systemState = systemState;
50  }
51  return err;
52 }
53 
55  uint8_t err;
56 
57  if(NULL == outputTaskDataMutex){
58  err = OS_ERR_INVALID_OPT;
59  }else
60  OSMutexPend(outputTaskDataMutex, 0, &err);
61  if(OS_NO_ERR == err){
62  outputTaskData.ctrlReg = data.ctrlReg;
63  outputTaskData.speedReg = data.speedReg;
64  outputTaskData.stepsReg = data.stepsReg;
65  outputTaskData.systemState = data.systemState;
66  err = OSMutexPost(outputTaskDataMutex);
67  }
68  return err;
69 }
70 
72  uint8_t err;
73 
74  if(NULL == outputTaskDataMutex || NULL == data){
75  err = OS_ERR_INVALID_OPT;
76  }else
77  OSMutexPend(outputTaskDataMutex, 0, &err);
78  if(OS_NO_ERR == err){
79  data->ctrlReg = outputTaskData.ctrlReg;
80  data->stepsReg = outputTaskData.stepsReg;
81  data->speedReg = outputTaskData.speedReg;
82  data->systemState = outputTaskData.systemState;
83  err = OSMutexPost(outputTaskDataMutex);
84  }
85  return err;
86 }
87 
88 void init_term(void) {
89  term = fopen(JTAG_UART_NAME, "w");
90 }
91 
92 void init_lcd(void) {
93  DOGM162lcd_init(LCD_BASE);
94  lcd = fopen(LCD_NAME, "w");
95 }
96 
97 void clear_lcd(void) {
98  fprintf(lcd, "\x1B[2J");
99  fflush(lcd);
100 }
101 
102 void setPos_lcd(int32_t row, int32_t col) {
103  fprintf(lcd, "\x1B[%d;%dH", (int) row, (int) col);
104  fflush(lcd);
105 }
106 
107 void setCursorMode_lcd(int32_t cursorMode) {
108  DOGM162lcd_setCursorMode(LCD_BASE, cursorMode);
109 }
110 
111 void printf_term(const char *format, ...) {
112  va_list args;
113  va_start(args, format);
114  vfprintf(term, format, args);
115  va_end(args);
116 }
117 void printf_lcd(const char *format, ...) {
118  va_list args;
119  va_start(args, format);
120  vfprintf(lcd, format, args);
121  va_end(args);
122 }
123 
124 void fflush_term() {
125  fflush(term);
126 }
127 void fflush_lcd() {
128  fflush(lcd);
129 }
Struct to store state of system and use case information.
Definition: dataTypes.h:37
Motor not moving.
Definition: dataTypes.h:28
void fflush_term()
Writes buffed data to terminal.
uint8_t init_outputTaskDataTxRx(void)
Initializes the interprocess communication between OutputTask and InputTask.
uint8_t ctrlReg
copy control register
Definition: dataTypes.h:52
void DOGM162lcd_setCursorMode(uint32_t lcdBase, int32_t cursorMode)
function changes cursor mode
Definition: lcdDOGM162.c:64
FILE * term
stream to write on terminal device
void DOGM162lcd_init(uint32_t lcdBase)
Initialization function of LCD DOGM162B-A.
Definition: lcdDOGM162.c:39
state_t operationalStatus
operational status
Definition: dataTypes.h:38
void init_term(void)
Initializes terminal output.
FILE * lcd
stream to write lcd device
OS_EVENT * outputTaskDataMutex
Mutex for secured variable acces.
everything is full functional
Definition: dataTypes.h:22
uint8_t speedReg
copy of speed register
Definition: dataTypes.h:53
void printf_lcd(const char *format,...)
Writes formated string to lcd.
void fflush_lcd()
Writes buffed data to lcd.
systemState_t systemState
stores state of system
Definition: dataTypes.h:50
void printf_term(const char *format,...)
Writes formated string to terminal.
void clear_lcd(void)
Clears display.
void setPos_lcd(int32_t row, int32_t col)
Sets the cursor position on display.
uint8_t outputTaskDataTx(outputTaskData_t data)
Sends data to ipc channel.
uint8_t outputTaskDataRx(outputTaskData_t *data)
Received data from ipc channel.
#define MUTEX_PRIORITY
void setCursorMode_lcd(int32_t cursorMode)
Sets the cursor-mode.
uint32_t stepsReg
copy of steps register
Definition: dataTypes.h:51
outputTaskData_t outputTaskData
Variable for transmitting information from InputTask to OutputTask.
void init_lcd(void)
Initializes lcd output.
Datatype of global variable for transmitting information from InputTask to OutputTask.
Definition: dataTypes.h:49