1 | int main(void)
|
2 | {
|
3 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
4 |
|
5 | // System startup
|
6 |
|
7 | MainGpioInit(); // GPIO configuration
|
8 | //A. Martin debug
|
9 | GPIO_SetBits(LED_OK_PORT, LED_OK_PIN);
|
10 | GPIO_ResetBits(LED_ERR_PORT, LED_ERR_PIN);
|
11 |
|
12 | RCC_Configuration(); // System clocks configuration
|
13 | RCC_ClockSecuritySystemCmd(ENABLE); // Enable clock security system(CSS)
|
14 | EH_Init(); // Error Code Handling initialization
|
15 | //A. Martin debug
|
16 | //NVIC_Configuration(); // NVIC configuration
|
17 | //MainGpioInit(); // GPIO configuration
|
18 |
|
19 | if (SysTick_Config(SystemCoreClock / SYSTICK_FREQ)) // Setup SysTick Timer for 1 msec interrupts
|
20 | while (1)
|
21 | ;
|
22 |
|
23 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
24 |
|
25 | // Initialize internal peripherals
|
26 |
|
27 | I2c_Configuration(); // I2C configuration
|
28 | Timer_Configuration(); // Timer configuration
|
29 | //ExtInt_Configuration(); // External hardware interrupt configuration
|
30 | // was only used for overtemp sensor which is not used in DLX
|
31 | Adc_Configuration(); // ADC_ configuration
|
32 |
|
33 |
|
34 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
35 |
|
36 | // Initialize system control and get system informations
|
37 |
|
38 | ParameterInit(); // initialize internal parameters and structures
|
39 | GetStartupInformation(); // request static system information
|
40 |
|
41 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
42 |
|
43 | // Prepare command reception and command buffer
|
44 |
|
45 | nCanRxCounter = 0;
|
46 | pCBWritePtr = pCBReadPtr = szCmdQueue; // set circular buffer pointer to first element of buffer
|
47 | Can_Configuration(); // CAN configuration
|
48 |
|
49 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
50 |
|
51 | // Prepare program execution
|
52 |
|
53 | FncDispEnable(true); // enable periodically function dispatcher
|
54 | WatchdogConfig(); // configure independent watchdog
|
55 |
|
56 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
57 |
|
58 | // Start program execution
|
59 | while (1)
|
60 | {
|
61 | //A. Martin debug
|
62 | GPIO_SetBits(LED_OK_PORT, LED_OK_PIN);
|
63 |
|
64 | GPIO_SetBits(TEST2_PORT, TEST2_PIN); // switch On Testpin, to check if app runs
|
65 |
|
66 |
|
67 | // check permanently for errors
|
68 | if( EH_GetErrorCounter() != 0)
|
69 | {
|
70 | nStatusByte |= (1<<UC_ERR_FLAG); // set error flag in global status byte
|
71 | SetStatusLED(UC_ERR);
|
72 | }
|
73 | else
|
74 | {
|
75 | nStatusByte &= ~(1<<UC_ERR_FLAG); // clear error flag in global status byte
|
76 | SetStatusLED(UC_OK);
|
77 | }
|
78 |
|
79 | //A. Martin debug
|
80 | GPIO_SetBits(LED_OK_PORT, LED_OK_PIN);
|
81 | /************************OVERTEMPERATURE-Handling***********************************************************/
|
82 |
|
83 | // check if over-temperature error is always active
|
84 | if (((nStatusByte & (1<<OVERTEMP_FLAG)) == !0) && (GPIO_ReadInputDataBit(OVT_PORT, OVT_PIN) == 0x00)) // read OV flag and input pin status (PORTE Pin11)/low active
|
85 | {
|
86 | EXTI_ClearITPendingBit(EXTI_LINE_OVT); // Clear the supervisor board over-temperature EXTI line pending bit
|
87 | OVFailureCount++; // increase failure counter
|
88 | if (OVFailureCount >= 500) // does counter reach end point?
|
89 | {
|
90 | Overtemp_Shutdown (); // call over temperature shutdown
|
91 | //nStatusByte &= ~(1<<OVERTEMP_FLAG); // clear over temperature flag
|
92 | OVFailureCount = 0; // clear counter
|
93 | }
|
94 | }
|
95 | else if (GPIO_ReadInputDataBit(OVT_PORT, OVT_PIN) == 0x01)
|
96 | {
|
97 | // if ((nStatusByte & (1<<OVERTEMP_FLAG)) == !0) // overtemp_flag was set
|
98 | // {
|
99 | nStatusByte &= ~(1<<OVERTEMP_FLAG); // clear over temperature flag
|
100 | EXTI_ClearITPendingBit(EXTI_LINE_OVT); // Clear the supervisor board over-temperature EXTI line pending bit
|
101 | // }
|
102 | //EH_ClearErrorCode(ERR_OVT); // clear error code
|
103 | OVFailureCount = 0; // clear counter
|
104 | }
|
105 |
|
106 | // reset watchdog counter
|
107 | WatchdogReset();
|
108 |
|
109 | // call command interpreter
|
110 | CmdEval();
|
111 |
|
112 | // reset watchdog counter
|
113 | WatchdogReset();
|
114 | }
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 | void NVIC_Configuration(void)
|
120 | {
|
121 | NVIC_InitTypeDef NVIC_InitStructure;
|
122 |
|
123 | /* Configure the Priority Grouping with 1 bit */
|
124 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
|
125 |
|
126 | /* Configure and enable CAN interrupt */
|
127 | NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
|
128 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
129 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
130 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
131 | NVIC_Init(&NVIC_InitStructure);
|
132 |
|
133 | // Enable ADC1_2 IRQChannel
|
134 | NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
|
135 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
136 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
|
137 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
138 | NVIC_Init(&NVIC_InitStructure);
|
139 |
|
140 | /* Enable the EXTI15_10 Interrupt */
|
141 | /*
|
142 | NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
|
143 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
144 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
|
145 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
146 | NVIC_Init(&NVIC_InitStructure);
|
147 | */
|
148 | }
|