Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
main.c
Go to the documentation of this file.
1 /**
2  *****************************************************************************
3  * @file main.c
4  * @author Michael Riedel
5  * @author Marc Kossmann
6  * @version v2.0.0
7  * @date 18.11.2014
8  * @brief Main-Routine for Stepper-Motor-Control
9  *****************************************************************************
10  * @par History:
11  * @details v0.1.0 22.10.2014 Riedel & Kossmann
12  * - first draft for milestone 1b
13  * @details v0.1.1 29.10.2014 Kossmann
14  * - edited ISRs inits to work with new pio access concept
15  * @details v0.1.2 30.10.2014 Kossmann
16  * - adopted error handling to new makro call
17  * - moved all flagsgroups to main and added creating them
18  * @details v1.0.0 31.10.2014 Riedel & Kossmann
19  * - moved hardwareTest() and initial printouts into userInputTask
20  * because the need OS running
21  * @details v1.0.1 14.11.2014 Kossmann
22  * - finished motor isr registration
23  * - moved init IPC global var to main
24  * @details v2.0.0 18.11.2014 Riedel & Kossmann
25  * - adapted function call init_outputTaskDataTxRx
26  * @see auxilaryFunctions.h
27  * - verified functionality -> release MS2
28  *****************************************************************************
29  */
30 
31 #include "../INC/main.h"
32 
33 extern OS_FLAG_GRP *userInputTaskFlagsGrp;
34 extern OS_FLAG_GRP *heartbeatTaskFlagsGrp;
35 extern OS_FLAG_GRP *userOutputTaskFlagsGrp;
36 
37 /** @brief Variable for ISR-Context
38  * @details Not used in this program
39  */
40 uint32_t ISRcontext;
41 
42 int main(void) {
43  uint8_t err;
44  init_term();
45 
46  // -------------------- Flags creation--------------------------------
47  userInputTaskFlagsGrp = OSFlagCreate(0x0000, &err);
48  if (OS_NO_ERR != err) {
49  error("INPUT_FLAG_CREATE_ERR: %i\n", err);
50  }
51  heartbeatTaskFlagsGrp = OSFlagCreate(0x0000, &err);
52  if (OS_NO_ERR != err) {
53  error("HEARTBEAT_FLAG_CREATE_ERR: %i\n", err);
54  }
55  userOutputTaskFlagsGrp = OSFlagCreate(0x0000, &err);
56  if (OS_NO_ERR != err) {
57  error("OUTPUT_FLAG_CREATE_ERR: %i\n", err);
58  }
59  // -------------------- Tasks ----------------------------------------
60  err = OSTaskCreateExt(UserInputTask, NULL,
61  (void *) &UserInputTask_Stk[TASK_STACKSIZE - 1],
64  if (OS_NO_ERR != err) {
65  error("Err creating UserInputTask: %i\n", err);
66  }
67 
68  err = OSTaskCreateExt(UserOutputTask, NULL,
69  (void *) &UserOutputTask_Stk[TASK_STACKSIZE - 1],
72  if (OS_NO_ERR != err) {
73  error("Err creating UserInputTask: %i\n", err);
74  }
75 
76  err = OSTaskCreateExt(HeartbeatTask, NULL,
77  (void *) &HeartbeatTask_Stk[TASK_STACKSIZE - 1],
80  if (OS_NO_ERR != err) {
81  error("Err creating HeartbeatTask: %i\n", err);
82  }
83 
84  //init keys ISR
85  alt_ic_isr_register(PIO_KEY_IRQ_INTERRUPT_CONTROLLER_ID, PIO_KEY_IRQ,
86  keysIRQhandler, (void *) &ISRcontext, NULL);
87  alt_ic_irq_enable(PIO_KEY_IRQ_INTERRUPT_CONTROLLER_ID, PIO_KEY_IRQ);
88  //Enable Interrupt in PIO component
91  //Clear captured edges
93 
94  //init switches ISR
95  alt_ic_isr_register(PIO_SW_IRQ_INTERRUPT_CONTROLLER_ID, PIO_SW_IRQ,
96  switchesIRQhandler, (void *) &ISRcontext, NULL);
97  alt_ic_irq_enable(PIO_SW_IRQ_INTERRUPT_CONTROLLER_ID, PIO_SW_IRQ);
98  //Enable Interrupt in PIO component
103 
104  //init motor ISR
105  alt_ic_isr_register(REGISTERS_IRQ_INTERRUPT_CONTROLLER_ID, REGISTERS_IRQ,
106  motorIRQhandler, (void *) &ISRcontext, NULL);
107  alt_ic_irq_enable(REGISTERS_IRQ_INTERRUPT_CONTROLLER_ID, REGISTERS_IRQ);
108 
109  //initialize global var and mutex
110  err = init_outputTaskDataTxRx();
111  if (OS_NO_ERR != err) {
112  error("IPC_GLOB_VAR_ERR: %i\n", err);
113  } else {
114  OSStart();
115  }
116  return 0;
117 }
static __inline__ void PIO_KEY_SetIRMsk(uint32_t enablebits)
Function to enable interrupts for pio key.
#define PIO_KEY_MINUS_IR2_MSK
Increase steps mask for PIO-Key.
#define PIO_KEY_PLUS_IR3_MSK
Decreses steps mask for PIO-Key.
OS_STK UserInputTask_Stk[TASK_STACKSIZE]
Stack for Task 1.
Definition: main.h:50
#define PIO_KEY_RS_IR0_MSK
Run/Stop mask for PIO-Key.
#define USER_INPUT_TASK_PRIORITY
lower numbers mean higher priority
Definition: main.h:59
#define error(...)
Prints the Error-messages in the terminal.
#define PIO_SW_DEBUG_MSK
Debug mask for PIO-Switches.
OS_FLAG_GRP * userOutputTaskFlagsGrp
The flags group used in the user-output-task.
Definition: events.h:51
#define PIO_SW_MODE_MSK
Mode mask for PIO-Switches.
void keysIRQhandler(void *context)
IRQ-Handler for key-input.
void UserInputTask(void *pdata)
UserInputTask.
Definition: userInputTask.c:55
uint32_t ISRcontext
Variable for ISR-Context.
Definition: main.c:40
OS_FLAG_GRP * userInputTaskFlagsGrp
The flags group used in the user-input-task.
Definition: events.h:32
static __inline__ void PIO_KEY_ClearEdgeCptBits(uint32_t clearbits)
Function to clear bits of keys edgecapture register.
#define HEARTBEAT_TASK_PRIORITY
Definition: main.h:61
OS_STK UserOutputTask_Stk[TASK_STACKSIZE]
Stack for Task 2.
Definition: main.h:52
void UserOutputTask(void *pdata)
UserOutputTask.
void init_term(void)
Initializes terminal output.
static __inline__ void PIO_SW_SetIRMsk(uint32_t enablebits)
Function to enable interrupts for pio sw.
void motorIRQhandler(void *context)
IRQ-Handler for motor stopped.
OS_FLAG_GRP * heartbeatTaskFlagsGrp
The flags group used in the heartbeat-task and user-input-task.
Definition: events.h:42
uint8_t init_outputTaskDataTxRx(void)
Initializes the interprocess communication between OutputTask and InputTask.
#define PIO_SW_LR_MSK
Left/Right mask for PIO-Switches.
void HeartbeatTask(void *pdata)
The task for the hearbeat and the debug-mode.
Definition: heartbeatTask.c:29
OS_STK HeartbeatTask_Stk[TASK_STACKSIZE]
Stack for Task 3.
Definition: main.h:54
void switchesIRQhandler(void *context)
IRQ-Handler for switches.
int main(void)
Main-Routine.
Definition: main.c:42
#define TASK_STACKSIZE
Definition of Task Stacks.
Definition: main.h:47
#define USER_OUTPUT_TASK_PRIORITY
Definition: main.h:60