1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
/**
******************************************************************************
* @file STM32L152_Ex01_3TKeys_EVAL\src\main.c
* @author MCD Application Team
* @version V1.1.0
* @date 24-February-2014
* @brief Basic example of how to use the STMTouch Driver.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/*
Здесь необходимо создать большой комментарий о характеристиках железа МК. Или
же лучше создать отдельный файл и сделать на него ссылку. Кстати, такой файл
создает программа STM32CubeMX.
И вообще, нужно создать глобальную папку проекта, где будет лежать все по
полочкам ( схема, программа, текстовые файлы, документация и тд )
*/
// Это программа для версии NixieClock_v2, которая является модифицированной версией предыдущей
// NixieLUT
/* Includes ------------------------------------------------------------------*/
#include "time.h"
// FreeRTOS includes
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "ltimers/ltimers.h"
#include "head_task/head_task.h"
#include "button/button_task.h"
#include "button/button_handler.h"
#include "nixie_driver/nixie_driver_task.h"
#include "light_sensor/light_sensor_task.h"
#ifdef LED_DRIVER
#include "led_driver/led_driver_task.h"
#endif
#include "indicate/indicate_modes_task.h"
#include "tsl_user.h"
#include "time/time.h"
#include "stm32f0xx_usart.h"
/* Private typedefs ----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
// Задаем размеры кучи для каждой задачи отдельно
// - как правильно определить необходимый минимум для кучи задачи?
#define STACK_SIZE_HEAD ((unsigned short) 230)
#define STACK_SIZE_NIXIE_DRIVER ((unsigned short) 80)
#define STACK_SIZE_BUTTON ((unsigned short) 200)
#define STACK_SIZE_LIGHT_SENSOR ((unsigned short) 70)
#ifdef LED_DRIVER
#define STACK_SIZE_LED_DRIVER ((unsigned short) 70)
#endif
#define STACK_SIZE_INDICATE_MODES ((unsigned short) 250)
/* Private functions prototype ---------------------------------------------- */
static void USART1Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitTypeDef usart_init = {0};
usart_init.USART_BaudRate = 115200;
usart_init.USART_WordLength = USART_WordLength_8b;
usart_init.USART_StopBits = USART_StopBits_1;
usart_init.USART_Parity = USART_Parity_No;
usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1, &usart_init);
USART_Cmd(USART1, ENABLE);
}
static void USART4Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART4, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_4);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_4);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitTypeDef usart_init = {0};
usart_init.USART_BaudRate = 9600;
usart_init.USART_WordLength = USART_WordLength_8b;
usart_init.USART_StopBits = USART_StopBits_1;
usart_init.USART_Parity = USART_Parity_No;
usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART4, &usart_init);
USART_Cmd(USART4, ENABLE);
}
static void WIFI_IO_GPIOInit(void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_0); // WIFI_EN
GPIO_ResetBits(GPIOA, GPIO_Pin_15); // WIFI_IO0
}
static void USART3Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_4);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_4);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_4);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_4);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_InitTypeDef usart_init = {0};
usart_init.USART_BaudRate = 115200;
usart_init.USART_WordLength = USART_WordLength_8b;
usart_init.USART_StopBits = USART_StopBits_1;
usart_init.USART_Parity = USART_Parity_No;
usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;
USART_Init(USART3, &usart_init);
USART_Cmd(USART3, ENABLE);
}
// ----------------------------------------------------------------------------
// Инициализация до создания задач
// ----------------------------------------------------------------------------
void InitAll ( void )
{
SystemInit();
WIFI_IO_GPIOInit();
USART1Init();
USART3Init();
USART4Init();
InitLTimers();
LightSensorInit();
NixieDriverInit();
HeadTaskInit();
IndicateModesInit();
#ifdef LED_DRIVER
LED_DriverInit();
#endif
TSL_user_Init();
TimeInit();
ButtonInit();
}
static void TestUart(void *arg)
{
(void) arg;
while (1) {
if (USART3->ISR & USART_ISR_RXNE) {
const uint16_t data = USART_ReceiveData(USART3);
USART_SendData(USART1, data);
}
if (USART1->ISR & USART_ISR_RXNE) {
const uint16_t data = USART_ReceiveData(USART1);
USART_SendData(USART3, data);
}
}
}
BaseType_t TaskSuccess;
// Главный цикл ------------------------------------------------------------- //
int main ()
{
InitAll ();
// Создаем задачи FreeRTOS ----------------------------------------------- //
// ВНИМАНИЕ !!!
// Необходимо проверять кучу при создании задачи! ( и очереди )
// Если в программе используется подключаемая библиотека, которая использует
// ОСРВ, то задача должна там и создаватья. То есть это нужно оформить в
// в виде специальной функции
TaskSuccess = xTaskCreate(Button_Task, "Button_Task", STACK_SIZE_BUTTON, NULL, tskIDLE_PRIORITY + 2, NULL);
configASSERT(TaskSuccess);
TaskSuccess = xTaskCreate(LightSensor_Task, "LightSensor_Task", STACK_SIZE_LIGHT_SENSOR, NULL, tskIDLE_PRIORITY + 2, NULL);
configASSERT(TaskSuccess);
TaskSuccess = xTaskCreate(Head_Task, "Head_Task", STACK_SIZE_HEAD, NULL, tskIDLE_PRIORITY + 2, NULL);
configASSERT(TaskSuccess);
TaskSuccess = xTaskCreate(IndicateModes_Task, "IndicateModes_Task", STACK_SIZE_INDICATE_MODES, NULL, tskIDLE_PRIORITY + 2, NULL);
configASSERT(TaskSuccess);
TaskSuccess = xTaskCreate(NixieDriver_Task, "NixieDriver_Task", STACK_SIZE_NIXIE_DRIVER, NULL, tskIDLE_PRIORITY + 2, NULL);
configASSERT(TaskSuccess);
#ifdef LED_DRIVER
TaskSuccess = xTaskCreate(LED_Driver_Task, "LED_Driver_Task", STACK_SIZE_LED_DRIVER, NULL, tskIDLE_PRIORITY + 2, NULL);
configASSERT(TaskSuccess);
#endif
TaskSuccess = xTaskCreate(TestUart, "TestUart", 200, NULL, tskIDLE_PRIORITY + 2, NULL);
configASSERT(TaskSuccess);
vTaskStartScheduler(); // И запускаем диспетчер задач ( он же планировщик )
} // end of main
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|