Compare commits

..

46 Commits

Author SHA1 Message Date
c233edddd8 Добавлено примечание о версии драйвера ch340 2025-09-08 12:41:52 +03:00
00e8d1b1af Обновить docs/Elbear_description.md 2025-09-08 12:40:39 +03:00
0fbfd77518 v0.5.3
- начальный загрузчик для плат elbear, elsomik обновлен до версии 0.2.0
- исключено появление краткосрочных просадок при работе ШИМ с максимальным коэффициентом заполнения
- добавлена возможность пропускать код стандартного обработчика прерываний при использовании пользовательского обработчика
- добавлена возможность конфигурирования вывода на вход с притяжкой к земле (INPUT_PULLDOWN)
- исправление известных ошибок
2025-08-06 08:42:39 +03:00
8a675b2f61 Обновить docs/elsomik_description.md 2025-07-21 10:14:36 +03:00
fef9b6e2bf Удалить docs/pinout_ElsomikOEM.png 2025-07-18 10:45:28 +03:00
0a5482b7c9 Обновить docs/elsomik_description.md 2025-07-18 10:45:06 +03:00
5be685ce7b Загрузить файлы в «docs» 2025-07-18 10:44:47 +03:00
1d850f20d0 Обновить README.md 2025-07-18 09:25:49 +03:00
20c1b9bd4e Обновить docs/Instructions.md 2025-07-18 09:21:28 +03:00
6b50a0201c Обновить docs/debug_description.md 2025-07-18 09:19:20 +03:00
262826c3b6 Обновить docs/Instructions.md 2025-07-18 09:16:28 +03:00
1042468094 Обновить docs/debug_description.md 2025-07-18 06:26:16 +03:00
34c86da403 Обновить docs/Instructions.md 2025-07-18 06:23:33 +03:00
1a73000ae9 v0.5.2
- исправлены ошибки при работе с пользователями, в имени которых есть пробелы
- исправлены ошибки при работе с программатором на win11
- исправлены известные ошибки
2025-07-15 09:36:38 +03:00
f81c108d44 Добавил BMP280, VL53L0X, MCP2515 и DS18B20
Добавил BMP280, VL53L0X, MCP2515 и DS18B20 (:
2025-06-22 15:17:59 +03:00
df1d14a57c Добавлена функция инициализации параметров SPI по умолчанию 2025-06-04 12:33:52 +03:00
e39767832a Добавлена функция инициализации параметров SPI по умолчанию 2025-06-04 16:33:03 +07:00
149804cc07 Обновить README.md 2025-06-02 12:06:21 +03:00
643eb94344 Протестированные библиотеки вынесены в отдельный файл 2025-06-02 12:04:49 +03:00
eb9b1aa0c9 v0.5.1
- в модулях Wire, SPI, Serial приведена в соответствие нумерация используемых экземпляров и периферии микроконтроллера.
- в функции analogWrite() перед запуском ШИМ проверяется, не запущен ли уже указанный канал.
- добавлена возможность переопределения функции main() в скетчах.
- при старте программы задается граница кэшируемой области SPIFI в соответствии с размером текущего исполняемого кода.
- исправление выявленных ошибок.
Co-authored-by: KLASSENTS <klassen@elron.tech>
Co-committed-by: KLASSENTS <klassen@elron.tech>
2025-05-30 12:24:08 +03:00
f1e091bf77 Добавил AHT10, MCP472 и PIR
Добавил AHT10, MCP472 и PIR (AM312, SR501, SR602 и SR505)
2025-05-05 19:57:48 +03:00
d93e4e4ba4 Отделил таблицу 2025-05-05 12:12:42 +07:00
112614e93b обновление картинок в описании
Co-authored-by: KLASSENTS <klassen@elron.tech>
Co-committed-by: KLASSENTS <klassen@elron.tech>
2025-05-05 07:47:28 +03:00
f000b346e8 Уточнение про Arduino IDE 2.3.4 2025-04-28 09:32:24 +03:00
1c8e06634c v0.5.0
- добавлена поддержка платы ELBEAR ACE-NANO;
- добавлена поддержка плат ELSOMIK OEM и SE;
- добавлена возможность работы в режиме отладки для всех плат, входящих в состав пакета. Доступно для версии ArduinoIDE 2 и выше;
- добавлена поддержка библиотеки FreeRTOS;
- добавлена поддержка библиотеки IRremote;
- добавлена поддержка библиотеки OneWire;
- добавлена поддержка аппаратного I2C0 для плат START-MIK32 и ELSOMIK. Для работы с ним доступен экземпляр класса Wire1;
- добавлена поддержка аппаратного SPI0 для всех плат, входящих в пакет. Для работы с ним доступен экземпляр класса SPI1;
- увеличено быстродействие функций digitalWrite, digitalRead;
- исправлены известные ошибки.
Co-authored-by: KlassenTS <klassen@elron.tech>
Co-committed-by: KlassenTS <klassen@elron.tech>
2025-04-28 07:06:08 +03:00
de1f0d7fda Добавил HW-MS03
Датчик движения HW-MS03
2025-04-18 13:06:13 +03:00
54dc987661 LoRa модуль E32-170T30D
Добавил протестированный LoRa модуль E32-170T30D
2025-04-09 21:52:56 +03:00
56d5d07cfe Добавил гироскоп MPU6050
Модуль гироскопа и акселерометра MPU6050
2025-04-04 20:24:52 +03:00
5f300f9ac8 Добавил CC1101
Добавил радиомодуль CC1101 433 МГц и ссылки на видео для дисплея E-link 2.13 от Heltec
2025-04-01 15:26:05 +03:00
6db7afe564 Обновить docs/tested_shields.md 2025-03-31 09:49:16 +03:00
f322f19938 Добавлен список протестированных модулей 2025-03-31 09:19:33 +03:00
3cf1fdf3d0 Обновить README.md 2025-03-31 07:43:52 +03:00
a32d749c60 добавлена поддержка еще одного прерывания и еще двух выводов для ШИМ для
платы Elbear. добавлены флаги компиляции, необходимые для работы в
ArduinoIDE v1.8.19
2025-02-04 14:31:10 +07:00
f06650400b добавлена поддержка платы Start-MIK32 2025-02-04 14:24:52 +07:00
8c82685f37 fix for flashing on linux 2025-02-04 14:24:50 +07:00
fd9e0a1ce2 Обновить README.md 2025-02-04 14:24:50 +07:00
7261b03ea1 Обновление до версии 0.3.0
- обновлен elbear_fw_bootloader - добавлена проверка контрольной суммы каждой строки hex файла.
- в модуль работы с АЦП добавлена функция analogReadResolution(). Функция analogRead() теперь возвращает усредненное по 10 измерениям значение.
- общая функция обработки прерываний перенесена в память RAM. Обработчики прерываний модулей External Interrupts и Advanced I/O (функция tone()) так же перенесены в память RAM для увеличения скорости выполнения кода.
- в пакет добавлены библиотеки EEPROM, Servo, SoftSerial, NeoPixel, MFRC522 адаптированные для работы с платой Elbear Ace-Uno.
- добавлено описание особенностей работы с пакетом
2025-02-04 14:24:50 +07:00
2044614aba Обновлен README.md 2025-02-04 14:24:49 +07:00
66cbf1a67f Обновлен bootloader
- Притяжка к питанию на Rx
- Новая команда для full erase
- При получении "мусорных" байтов не реагируем и отключаемся по таймауту
2025-02-04 14:24:49 +07:00
a08072dc3b Удалить bootloaders/ace-uno/elbear_fw_bootloader_qpi_xip_cshigh_0.hex 2025-02-04 14:24:49 +07:00
295d68c3f4 Удалить bootloaders/ace-uno/bootloader.hex 2025-02-04 14:24:49 +07:00
221a587857 Merged with dev_beta 2025-02-04 14:24:49 +07:00
186e182c1d Добавлен файл Add_board.PNG 2025-02-04 14:24:49 +07:00
2b855b10e6 Удален файл Add_board.PNG 2025-02-04 14:24:49 +07:00
444e9e7af1 Обновила ссылку, надеюсь на финальную версию 2025-02-04 14:24:49 +07:00
0cc714ccf9 Merged with dev0.1.0 2025-02-04 14:24:49 +07:00
292 changed files with 100359 additions and 1293 deletions

View File

@ -1,40 +0,0 @@
## Установка пакета в ArduinoIDE
1. Установите [Arduino IDE](https://www.arduino.cc/en/software).
2. Откройте меню `Файл -> Параметры`.
3. Вставьте данную ссылку в поле "Дополнительные ссылки для Менеджера плат":
`https://elron.tech/files/package_elbear_beta_index.json`
![Add_board](docs/Add_board.PNG)
4. Откройте меню `Инструменты -> Плата -> Менеджер плат...`.
5. В поиске найдите плату `Elbear Ace-Uno`, выберите нужную версию и нажмите кнопку `Установить`.
![Install_board](docs/Install_board.PNG)
6. Процесс установки может занять некоторое время. Результаты установки отобразятся в поле `Вывод`, а так же во всплывающих уведомлениях.
![Installation_process](docs/Installation_process.PNG)
Для загрузки скетчей по USB в ArduinoIDE необходимо, чтобы на плате Elbear Ace-Uno был специальный начальный загрузчик ([elbear_fw_bootloader](https://gitflic.ru/project/elron-tech/elbear_fw_bootloader)). Если он уже есть на плате, можно сразу переходить к работе. Если загрузчика еще нет или необходимо обновить его на плате, ниже описан процесс загрузки. Актуальная версия начального загрузчика входит в состав пакета поддержки, отдельно скачивать его не нужно.
Платы ревизии 1.1.0 готовы к использованию в ArduinoIDE из коробки, так как поставляются с предварительно записанным начальным загрузчиком.
## Запись начального загрузчика через ArduinoIDE
1. Подключите плату Elbear Ace-Uno к ПК через программатор ELJTAG.
2. В ArduinoIDE выберите программатор: `Инструменты -> Программатор -> mik32 uploader`.
3. Для записи начального загрузчика выберите `Инструменты -> Записать Загрузчик`.
![Bootloader](docs/Bootloader.png)
4. При возникновении проблем с загрузкой ознакомьтесь с разделом `Настройка программатора` в [инструкции](https://elron.tech/wp-content/uploads/2024/05/instrukcija-po-pervomu-zapusku.pdf) по первому запуску платы ELBEAR ACE-UNO.
Теперь можно загружать скетчи в плату по USB.
## Начало работы
1. Подключите плату к ПК по USB.
2. Откройте ArduinoIDE и загрузите необходимый скетч. Для начала работы можно воспользоваться готовыми примерами, например - `Файл -> Примеры -> 01.Basics -> Blink`.
![Blink_example](docs/Blink_example.png)
3. Выберите активную плату - `Инструменты -> Плата`.
![Set_board](docs/Set_board.png)
4. Выберите используемый COM порт - `Инструменты -> Порт`.
![Set_port](docs/Set_port.png)
Выбранные плата и порт в ArduinoIDE должны отображаться следующим образом:
![Selected_board_port](docs/Selected_board_port.png)
5. Проверьте скетч, нажав соответствующую кнопку.
![Build_project](docs/Build_project.png)
6. Загрузите полученную прошивку на плату.
![Flash_project](docs/Flash_project.png)
7. При необходимости можно открыть терминал и получать сообщения от платы по интерфейсу Serial. Для этого добавьте в скетч работу с интерфейсом и после загрузки прошивки выберите `Инструменты -> Монитор порта`.
![Monitor](docs/Monitor.png)

115
README.md
View File

@ -1,95 +1,112 @@
# elbear_arduino_bsp
Пакет поддержки платы Elbear Ace-Uno на базе микроконтроллера MIK32 Амур в среде программирования Arduino IDE.
Пакет поддержки плат на базе микроконтроллера MIK32 Амур в среде программирования Arduino IDE.
## Установка пакета в ArduinoIDE
## Установка пакета в ArduinoIDE и подготовка к работе
Для установки пакета в параметрах ArduinoIDE необходимо добавить ссылку `https://elron.tech/files/package_elbear_beta_index.json` в поле "Дополнительные ссылки для Менеджера плат".
Подробные шаги по установке и начальной настройке описаны в [инструкции](./Instructions.md).
Подробные шаги по установке, начальной настройке и записи начального загрузчика для всех поддерживаемых плат описаны в [инструкции](./docs/Instructions.md).
## Функциональное назначение выводов
![Pinout](docs/pinout.PNG)
## Платы, входящие в состав пакета
Пакет включает в себя поддержку следующих плат:
- [ELBEAR ACE-UNO](./docs/Elbear_description.md) 8 Mb / 16 Mb / 32 Mb
- [ELBEAR ACE-NANO](./docs/nano_description.md)
- [ELSOMIK](./docs/elsomik_description.md)
- [START-MIK32](./docs/Start_mik32_description.md)
## Особенности использования платы Elbear Ace-Uno в ArduinoIDE
## Особенности использования пакета в ArduinoIDE
### Цифровые выводы
На плате Elbear Ace-Uno доступны встроенные светодиод и кнопка. Для их использования необходимо воспользоваться макросами `LED_BUILTIN` и `BTN_BUILTIN`, передавая их в качестве аргументов функции вместо номера цифрового вывода. Макросу `LED_BUILTIN` соответствует номер вывода D22, а макросу `BTN_BUILTIN` - D23.
В отличие от стандартного функционала Arduino, на плате Elbear Ace-Uno невозможно управлять притяжками цифрового вывода, настроенного на вход, с помощью функции `void digitalWrite(uint32_t PinNumber, uint32_t Val)`. Для включения притяжки к питанию необходимо воспользоваться функцией `void pinMode(PinNumber, INPUT_PULLUP)`.
В отличие от стандартного функционала Arduino на платах, входящих в состав пакета, невозможно управлять притяжками цифрового вывода, настроенного на вход, с помощью функции `void digitalWrite(uint32_t PinNumber, uint32_t Val)`. Для включения притяжки к питанию необходимо воспользоваться функцией `pinMode(PinNumber, INPUT_PULLUP)`.
Доступна возможность конфигурирования цифрового вывода на вход с притяжкой к земле, для этого необходимо использовать макрос `INPUT_PULLDOWN` - `pinMode(PinNumber, INPUT_PULLDOWN)`.
Для инвертирования состояния цифровых выводов доступна функция `void digitalToggle(uint32_t PinNumber)`.
### Аналоговые выводы
#### АЦП
Встроенный в MIK32 АЦП обладает разрешением 12 бит, однако по умолчанию в Arduino IDE применяется разрешение 10 бит. С помощью функции `void analogReadResolution(uint8_t resolution)` можно изменять разрешение в диапазоне от 1 до 32 бит.
Функция `uint32_t analogRead(uint32_t PinNumber)` возвращает результаты измерения после усреднения по 10 значениям.
Номера выводов, поддерживающих АЦП, отличаются для каждой платы и перечислены в их описаниях.
#### ШИМ
На плате Elbear Ace-Uno доступны следующие выводы для формирования ШИМ-сигнала: D3, D5, D6, D9, D10, D11. Генерация сигнала осуществляется с помощью 32-битного таймера. Выводы D3, D5, D6, D9 подключены к таймеру 1, выводы D10, D11 подключены к таймеру 2. Выводы, подключенные к одному и тому же таймеру, выдают ШИМ-сигнал одинаковой частоты.
Цифровой вывод D10 не может быть использован для генерации ШИМ, если одновременно активен интерфейс SPI. Это ограничение связано с особенностями работы микроконтроллера. Ограничение не распространяется на использование D10 в качестве цифрового вывода при активном SPI.
По умолчанию частота сформированного ШИМ-сигнала составляет 1 кГц. Функция `void analogWriteFrequency(uint32_t freq)` позволяет изменить частоту сигнала в диапазоне от 1 Гц до 1 МГц.
По умолчанию разрешение, используемое в функции `void analogWrite(uint32_t PinNumber, uint32_t writeVal)`, составляет 8 бит. Функция `void analogWriteResolution(uint8_t resolution)` позволяет измененить разрешение в диапазоне от 1 до 32 бит.
Остановить генерацию ШИМ-сигнала можно, вызвав функцию `void analogWriteStop(uint32_t PinNumber)` или функции `void digitalWrite(uint32_t PinNumber, uint32_t Val)`/`int digitalRead(uint32_t PinNumber)`.
Остановить генерацию ШИМ-сигнала можно, вызвав функцию `void analogWriteStop(uint32_t PinNumber)` или функции `void digitalWrite(uint32_t PinNumber, uint32_t Val)`/`int digitalRead(uint32_t PinNumber)`.
Номера выводов, поддерживающих ШИМ, отличаются для каждой платы и перечислены в их описаниях.
### Прерывания
На плате Elbear Ace-Uno доступно 7 прерываний, настраиваемых функцией `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`:
|Цифровой вывод|Номер прерывания|
|---------|---------|
|D2|0|
|D3|1|
|D4|2|
|D5|3|
|D8|4|
|D9|5|
|`BTN_BUILTIN`|6|
Платы, входящих в состав пакета, позволяют использовать прерывания, настраиваемые функцией `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`. Номера выводов, поддерживающих прерывания, отличаются для каждой платы и перечислены в их описаниях.
Для получения номера прерывания по номеру вывода существует функция `int8_t digitalPinToInterrupt(uint32_t digPinNumber)`.
В микроконтроллере MIK32 предусмотрен всего один вектор прерывания. Когда срабатывает прерывание от любого источника, общая функция-обработчик последовательно проверяет все возможные источники и, при необходимости, вызывает соответствующие обработчики конкретных модулей. Поэтому важно, чтобы функции, вызываемые при прерываниях, были небольшими и обеспечивали максимально быстрое завершение обработки. Это позволит избежать задержек и снизит риск пропуска последующих прерываний.
Общая функция-обработчик прерываний располагается в RAM памяти. Это позволяет устранить задержки, связанные с кэшированием при работе из FLASH памяти. Обработчики прерываний, назначаемые на цифровые выводы с помощью функции `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`, и обработчик прерывания для функции `tone()` так же располагаются в памяти RAM.
Глобальное разрешение прерываний активируется после завершения функции `setup()`. Если необходимо использовать прерывания внутри самой функции `setup()`, их можно включить вручную, вызвав функцию `interrupts()` перед вызовом функций, работающих с прерываниями. Прерывания используются для приема данных модулями `Serial`, `Wire`, для работы библиотеки `Servo`, функцией `tone()`.
В пакете поддержки доступна возможность дополнения или замены стандартного обработчика прерываний пользовательской функцией-обработчиком. Для этого в своем скетче необходимо определить функцию `extern "C" bool ISR()`, она вызывается первой в стандартном обработчике. Внутри функции можно проверять флаги прерываний и реагировать на нужные. Важно очищать флаги обрабатываемых прерываний, чтобы обработчик работал корректно.
Если функция возвращает `false`, после ее выполнения так же будет выполнен код стандартного обработчика прерываний. Если функция возвращает `true`, выполнение кода стандартного обработчика будет пропущено.
Пользовательскую функцию необходимо располагать в RAM памяти, так как стандартный обработчик прерываний расположен именно там.
Ниже приведен пример пользовательского обработчика прерывания по переполнению от 16-битного таймера 1:
```
extern "C" __attribute__((section(".ram_text"))) bool ISR(void)
{
// обработка прерывания от 16-битного таймера
if (EPIC_CHECK_TIMER16_1())
{
if (TIM16_GET_ARRM_INT_STATUS(htimer16_1_))
{
// необходимые действия при переполнении таймера
}
// очистить флаги прерывания от таймера 1
TIM16_CLEAR_INT_MASK(htimer16_1_, 0xFFFFFFFF);
}
return false;
}
```
Для корректной работы функции из примера необходимо подключить в скетче следующие файлы:
```
#include "mik32_hal_timer16.h"
#include "wiring_LL.h"
```
### Serial
Для работы доступно два последовательных интерфейса. Нулевой интерфейс доступен на выводах D0, D1, для работы с ним используется экземпляр класса под названием `Serial`. Нулевой интерфейс используется для вывода информации в Монитор порта в Arduino IDE.
Первый интерфейс доступен на выводах D7, D8, используемый экземпляр класса - `Serial1`.
Для работы доступно два последовательных интерфейса. Нулевой интерфейс используется экземпляром класса `Serial`. Информации в Монитор порта в Arduino IDE поступает через него. Первый интерфейс используется экземпляром класса `Serial1`. Выводы, на которых доступны указанные интерфейсы, перечислены в описании отдельных плат.
Доступны следующие макросы для настройки режима работы каждого интерфейса в функции `Serial.begin()`: `SERIAL_7N1`, `SERIAL_8N1`, `SERIAL_7N2`, `SERIAL_8N2`, `SERIAL_7E1`, `SERIAL_8E1`, `SERIAL_7E2`, `SERIAL_8E2`, `SERIAL_7O1`, `SERIAL_8O1`, `SERIAL_7O2`, `SERIAL_8O2`. Здесь длина данных - 7 или 8 бит; бит четности - нет(N), четный(E), нечетный(O); стоп бит - 1 или 2 бита.
### Переопределение функции main
В ArduinoIDE доступна возможность определить пользовательскую функцию `main()` в скетче. Для этого необходимо удалить из скетча функции `setup()` и `loop()` и определить свою функцию `int main(void){}`. Чтобы весь функционал пакета поддержки работал корректно, перед заходом в бесконечный цикл необходимо вызвать функцию `post_init()`, внутри которой глобально разрешаются прерывания. Пример переопределения представлен ниже.
![main_redefine_example_.png](docs/main_redefine_example_.png)
### Предупреждения об ошибках
Если в скетче используется интерфейс `Serial`, при возникновении ошибок при использовании какой-либо функции из пакета в порт может передаваться сообщение об этой ошибке с пояснением. Например, если в функцию будет передан некорректный номер цифрового вывода, предупреждение об этом появится в подключенном com порту.
По умолчанию вывод предупреждений включен. Если интерфейс `Serial` используется для коммуникации с другим устройством, вывод предупреждений можно отключить. Для этого в самом начале функции `void setup()` необходимо вызвать макрос `DISABLE_ERROR_MESSAGES();`. Вывод предупреждений можно включить обратно, вызвав макрос `ENABLE_ERROR_MESSAGES();` в любом месте программы.
### Библиотеки, входящие в состав пакета
## Библиотеки, входящие в состав пакета
Входящие в состав пакета библиотеки используют периферию микроконтроллера MIK32 Амур и/или адаптированы для работы с ним.
|Библиотека|Описание|Заметки|
|---------|---------|------|
|[SPI](https://docs.arduino.cc/language-reference/en/functions/communication/SPI/)|Библиотека для работы с интерфейсом SPI|Для работы используется встроенный SPI1. Доступные делители частоты - `SPI_CLOCK_DIV4`, `SPI_CLOCK_DIV8`, `SPI_CLOCK_DIV16`, `SPI_CLOCK_DIV32`, `SPI_CLOCK_DIV64`, `SPI_CLOCK_DIV128`, `SPI_CLOCK_DIV256`, обеспечивают частоту работы от 125 кГц до 8 МГц. Скорость работы по умолчанию - 4 МГц. Для задания режима и скорости работы рекомендуется использовать `SPISettings(uint32_t speedMaximum, uint8_t dataOrder, uint8_t dataMode)`, а не соответствующие отдельные функции|
|[SPI](https://docs.arduino.cc/language-reference/en/functions/communication/SPI/)|Библиотека для работы с интерфейсом SPI|Для работы доступно два экземпляра класса - SPI (используется аппаратный SPI1) и SPI1 (используется аппаратный SPI0). Выводы, на которых доступны интерфейсы, перечислены в описании каждой платы. Доступные делители частоты - `SPI_CLOCK_DIV2`, `SPI_CLOCK_DIV4`, `SPI_CLOCK_DIV8`, `SPI_CLOCK_DIV16`, `SPI_CLOCK_DIV32`, `SPI_CLOCK_DIV64`, `SPI_CLOCK_DIV128`, `SPI_CLOCK_DIV256`, обеспечивают частоту работы от 125 кГц до 16 МГц. Скорость работы по умолчанию - 4 МГц. Для задания режима и скорости работы рекомендуется использовать `SPISettings(uint32_t speedMaximum, uint8_t dataOrder, uint8_t dataMode)`, а не соответствующие отдельные функции|
|[Wire](https://docs.arduino.cc/language-reference/en/functions/communication/Wire/)|Библиотека для работы с интерфейсом I2C|Для работы используется встроенный I2C1. Доступные частоты работы интерфейса: 100 кГц (`WIRE_FREQ_100K`), 400 кГц (`WIRE_FREQ_400K`), 1000 кГц (`WIRE_FREQ_1000K`). Скорость работы по умолчанию - 100 кГц. В режиме работы в качестве ведомого устройства функции, заданные через `void onReceive( void (*)(int)` и `void onRequest( void (*)(void) )`, выполняются в прерывании|
|[SoftwareSerial](https://docs.arduino.cc/learn/built-in-libraries/software-serial/)|Библиотека, реализующая программный последовательный интерфейс.|Доступные скорости работы - от 300 до 57600 бод. Для отправки данных (TX) можно использовать любой цифровой вывод. Для приема данных (RX) можно использовать только выводы, поддерживающие прерывания. Обработчик прерывания и связанные с ним функции располагаются в памяти RAM|
|[EEPROM](https://docs.arduino.cc/learn/built-in-libraries/eeprom/)|Библиотека для работы с памятью EEPROM|Для использования доступно 1024 байта встроенной EEPROM памяти. Для корректной работы библиотеки обязательно вызывать функцию `void EEPROM.begin()` перед началом работы с памятью|
|[Servo](https://docs.arduino.cc/libraries/servo/)|Библиотека для работы с сервоприводом|Библиотека использует 16-битный таймер 2 и прерывания от него. Любой цифровой вывод подходит для управления сервоприводом. Одновременно можно использовать до 12 сервоприводов|
|[Servo](https://docs.arduino.cc/libraries/servo/)|Библиотека для работы с сервоприводом|Библиотека использует 16-битный таймер 2 и прерывания от него. Любой цифровой вывод подходит для управления сервоприводом. Одновременно можно использовать до 12 сервоприводов. Для работы библиотеки используется таймер timer16_2|
|[NeoPixel](https://docs.arduino.cc/libraries/adafruit-neopixel/)|Библиотека для работы с адресными светодиодами|Функция, выводящая состояние пикселей на цифровой вывод платы, перенесена в память RAM для корректной работы на MIK32 Амур|
|[MFRC522](https://docs.arduino.cc/libraries/mfrc522/)|Библиотека для работы с RFID картами|Исправлен баг, вызывающий ошибку компиляции в новых компиляторах gcc|
|[OneWire](https://docs.arduino.cc/libraries/onewire/)|Библиотека для работы с интерфейсом 1-Wire|В стандартную библиотеку добавлена поддержка микроконтроллера MIK32 Amur|
|[IRremote](https://docs.arduino.cc/libraries/irremote/)|Библиотека позволяет отправлять и принимать инфракрасные сигналы, используя определенный набор протоколов|В стандартную библиотеку добавлена поддержка микроконтроллера MIK32 Amur. При приеме данных используется прерывание таймера timer16_0, работает с любым цифровым выводом. Для отправки данных с помощью встроенного ШИМ для плат Elbear Ace-Uno используется вывод D3, для платы START-MIK32 - вывод P0_0|
|[FreeRTOS](https://docs.arduino.cc/libraries/freertos/)|Библиотека для работы с операционной системой реального времени FreeRTOS|В стандартную библиотеку добавлена поддержка микроконтроллера MIK32 Amur. Период системного тика составляет 10 мс и формируется с помощью машинного таймера SysTick|
## Протестированные библиотеки
|Библиотека|Описание|
|---------|---------|
|[RFID_MFRC522v2](https://docs.arduino.cc/libraries/rfid_mfrc522v2/)|Новая версия библиотеки MFRC522 для работы с RFID картами|
|[SD](https://www.arduino.cc/en/Reference/SD)|Библиотека, позволяющая считывать и записывать информацию на SD карты|
|[TimeLib](https://docs.arduino.cc/libraries/time/)|Библиотека для удобной работы с переменными времени|
|[Ds1302](https://reference.arduino.cc/reference/en/libraries/ds1302/)|Библиотека для работы с микросхемой часов реального времени DS1302|
|[DS1307RTC](https://docs.arduino.cc/libraries/ds1307rtc/)|Библиотека для работы с микросхемой часов реального времени DS1307|
|[microDS3231](https://docs.arduino.cc/libraries/microds3231/)|Легкая библиотека для работы с микросхемой часов реального времени DS3231|
|[Rtc](https://github.com/Makuna/Rtc/tree/master)|Библиотека для работы с разными микросхемами часов реального времени|
|[AHT10](https://github.com/enjoyneering/AHT10/tree/master)|Библиотека для работы с датчиками температуры и влажности AHT10, AHT15, AHT20|
|[DHT](https://docs.arduino.cc/libraries/dht-sensor-library/)|Библиотека для работы с датчиками температуры и влажности типа DHT|
|[Adafruit_BMP280](https://docs.arduino.cc/libraries/adafruit-bmp280-library/)|Библиотека для работы с датчиками давления и высоты BMP280|
|[MPU6050](https://reference.arduino.cc/reference/en/libraries/mpu6050/)|Библиотека для работы с акселерометром/гироскопом MPU6050|
|[Kalman](https://docs.arduino.cc/libraries/kalman-filter-library/)|Библиотека, реализующая фильтр Калмана|
|[LiquidCrystal_I2C](https://docs.arduino.cc/libraries/liquidcrystal-i2c/)|Библиотека для управления LCD дисплеями по интерфейсу I2C|
|[JoystickShield](https://github.com/sudar/JoystickShield/tree/master)|Библиотека для работы с шилдом JoystickShield|
|[RF24](https://docs.arduino.cc/libraries/rf24/)|Драйвер радиоустройств, библиотека для работы с микросхемами nRF24L01(+)|
|[Bonezegei_ULN2003_Stepper](https://docs.arduino.cc/libraries/bonezegei_uln2003_stepper/)|Библиотека драйвера шагового двигателя, управляемого микросхемой ULN2003|
|[Ethernet](https://docs.arduino.cc/libraries/ethernet/)|Библиотека, позволяющая использовать Ethernet шилд для подключения к Интернету|
Список библиотек, работа которых была протестирована на платах, входящих в состав пакета поддержки, доступен [здесь](./docs/tested_libs.md).
## Протестированные модули
Список модулей и шилдов, работа которых была протестирована на платах, входящих в состав пакета поддержки, доступен [здесь](./docs/tested_shields.md).
## Режим отладки
Для всех плат, входящих в состав пакета, доступен режим отладки скетча в Arduino IDE версии 2.3.4 на Windows 10 x64. Подготовка к работе в режиме отладки описана в [инструкции.](./docs/debug_description.md) Функция отладки является экспериментальной.
# Полезные ссылки
## Полезные ссылки
* [Описание плат ELBEAR](https://elron.tech/russian-arduino-compatible-board/)
* [Материалы по платам ELBEAR ACE-UNO](https://elron.tech/support/#elbear)
* [Телеграмм-канал компании (обновления по проекту ELBEAR и другим)](https://t.me/elrontech)
* [Материалы по платам ELBEAR ACE-NANO](https://elron.tech/support/#elbearacenano)
* [Материалы по платам ELSOMIK](https://elron.tech/support/#elsomik)
* [Материалы по плате START-MIK32](https://docs.mikron.ru/wiki/boards/start.html)
* [Телеграмм-канал компании](https://t.me/elrontech)
При возникновении вопросов или выявлении проблем можно оставить заявку [здесь](https://gitflic.ru/project/elron-tech/elbear_arduino_bsp/issue).

View File

@ -1,73 +1,161 @@
# See: https://arduino.github.io/arduino-cli/latest/platform-specification/
##############################################################
##################### Ace-Uno 8 Mb #####################
aceUno8Mb.name=Elbear Ace-Uno 8 Mb
##################### ACE-UNO 8 Mb #####################
aceUno8Mb.name=ELBEAR ACE-UNO 8 Mb
# tool for firmware update
aceUno8Mb.upload.tool=elbear_uploader
aceUno8Mb.upload.protocol=elbear_uploader
aceUno8Mb.upload.maximum_size=8388608
aceUno8Mb.upload.maximum_data_size=16384
aceUno8Mb.upload.speed=230400
# tool for bootloader update
aceUno8Mb.bootloader.tool=mik32_upload
aceUno8Mb.bootloader.tool.default=mik32_upload
aceUno8Mb.bootloader.file=ace-uno/bootloader.hex
aceUno8Mb.bootloader.file=elbear/bootloader.hex
aceUno8Mb.bootloader.interface=ftdi/mikron-link.cfg
aceUno8Mb.bootloader.params.verbose=
# build options
aceUno8Mb.build.mcu=MIK32_Amur
aceUno8Mb.build.f_cpu=32000000UL
aceUno8Mb.build.board=ACE_UNO_8MB
aceUno8Mb.build.core=arduino
aceUno8Mb.build.variant=standart
aceUno8Mb.build.variant=elbear_ace_uno
aceUno8Mb.build.extra_flags=
aceUno8Mb.build.flags=
##################### Ace-Uno 16 Mb #####################
aceUno16Mb.name=Elbear Ace-Uno 16 Mb
##################### ACE-UNO 16 Mb #####################
aceUno16Mb.name=ELBEAR ACE-UNO 16 Mb
# tool for firmware update
aceUno16Mb.upload.tool=elbear_uploader
aceUno16Mb.upload.protocol=elbear_uploader
aceUno16Mb.upload.maximum_size=16777216
aceUno16Mb.upload.maximum_data_size=16384
aceUno16Mb.upload.speed=230400
# tool for bootloader update
aceUno16Mb.bootloader.tool=mik32_upload
aceUno16Mb.bootloader.tool.default=mik32_upload
aceUno16Mb.bootloader.file=ace-uno/bootloader.hex
aceUno16Mb.bootloader.file=elbear/bootloader.hex
aceUno16Mb.bootloader.interface=ftdi/mikron-link.cfg
aceUno16Mb.bootloader.params.verbose=
# build options
aceUno16Mb.build.mcu=MIK32_Amur
aceUno16Mb.build.f_cpu=32000000UL
aceUno16Mb.build.board=ACE_UNO_16MB
aceUno16Mb.build.core=arduino
aceUno16Mb.build.variant=standart
aceUno16Mb.build.variant=elbear_ace_uno
aceUno16Mb.build.extra_flags=
aceUno16Mb.build.flags=
##################### Ace-Uno 32 Mb #####################
aceUno32Mb.name=Elbear Ace-Uno 32 Mb
##################### ACE-UNO 32 Mb #####################
aceUno32Mb.name=ELBEAR ACE-UNO 32 Mb
# tool for firmware update
aceUno32Mb.upload.tool=elbear_uploader
aceUno32Mb.upload.protocol=elbear_uploader
aceUno32Mb.upload.maximum_size=33554432
aceUno32Mb.upload.maximum_data_size=16384
aceUno32Mb.upload.speed=230400
# tool for bootloader update
aceUno32Mb.bootloader.tool=mik32_upload
aceUno32Mb.bootloader.tool.default=mik32_upload
aceUno32Mb.bootloader.file=ace-uno/bootloader.hex
aceUno32Mb.bootloader.file=elbear/bootloader.hex
aceUno32Mb.bootloader.interface=ftdi/mikron-link.cfg
aceUno32Mb.bootloader.params.verbose=
# build options
aceUno32Mb.build.mcu=MIK32_Amur
aceUno32Mb.build.f_cpu=32000000UL
aceUno32Mb.build.board=ACE_UNO_32MB
aceUno32Mb.build.core=arduino
aceUno32Mb.build.variant=standart
aceUno32Mb.build.variant=elbear_ace_uno
aceUno32Mb.build.extra_flags=
aceUno32Mb.build.flags=
aceUno32Mb.build.flags=
##################### ACE-NANO #####################
aceNano.name=ELBEAR ACE-NANO
# tool for firmware update
aceNano.upload.tool=elbear_uploader
aceNano.upload.protocol=elbear_uploader
aceNano.upload.maximum_size=8388608
aceNano.upload.maximum_data_size=16384
aceNano.upload.speed=230400
# tool for bootloader update
aceNano.bootloader.tool=mik32_upload
aceNano.bootloader.tool.default=mik32_upload
aceNano.bootloader.file=elbear/bootloader.hex
aceNano.bootloader.interface=ftdi/mikron-link.cfg
aceNano.bootloader.params.verbose=
# build options
aceNano.build.mcu=MIK32_Amur
aceNano.build.f_cpu=32000000UL
aceNano.build.board=ACE_NANO
aceNano.build.core=arduino
aceNano.build.variant=elbear_ace_nano
aceNano.build.extra_flags=
aceNano.build.flags=
##################### ELSOMIK #####################
elsomik.name=ELSOMIK
# tool for firmware update
elsomik.upload.tool=elbear_uploader
elsomik.upload.protocol=elbear_uploader
elsomik.upload.maximum_size=8388608
elsomik.upload.maximum_data_size=16384
elsomik.upload.speed=230400
# tool for bootloader update
elsomik.bootloader.tool=mik32_upload
elsomik.bootloader.tool.default=mik32_upload
elsomik.bootloader.file=elsomik/bootloader.hex
elsomik.bootloader.interface=ftdi/mikron-link.cfg
elsomik.bootloader.params.verbose=
# build options
elsomik.build.mcu=MIK32_Amur
elsomik.build.f_cpu=32000000UL
elsomik.build.board=ELSOMIK
elsomik.build.core=arduino
elsomik.build.variant=elsomik
elsomik.build.extra_flags=
elsomik.build.flags=
##################### START-MIK32-V1 #####################
start-mik32-v1.name=START-MIK32-V1
# tool for firmware update
start-mik32-v1.upload.tool=elbear_uploader
start-mik32-v1.upload.protocol=elbear_uploader
start-mik32-v1.upload.maximum_size=4194304
start-mik32-v1.upload.maximum_data_size=16384
start-mik32-v1.upload.speed=120000
# tool for bootloader update
start-mik32-v1.bootloader.tool=mik32_upload
start-mik32-v1.bootloader.tool.default=mik32_upload
start-mik32-v1.bootloader.file=start-mik32/bootloader.hex
start-mik32-v1.bootloader.interface=start-link.cfg
start-mik32-v1.bootloader.params.verbose=
# build options
start-mik32-v1.build.mcu=MIK32_Amur
start-mik32-v1.build.f_cpu=32000000UL
start-mik32-v1.build.board=START_MIK32_V1
start-mik32-v1.build.core=arduino
start-mik32-v1.build.variant=start
start-mik32-v1.build.extra_flags=
start-mik32-v1.build.flags=

View File

@ -0,0 +1,281 @@
:020000040100F9
:10000000FD6293820240FD12E39F02FE374100022F
:1000100013010100B711000293818193B71500010C
:10002000938585103716000113068613B706000264
:100030009386861539A083A2050023A0560091055A
:100040009106E3EAC5FEB70500019385850B3706E7
:10005000000113060621B70600029386060039A0A8
:1000600083A2050023A0560091059106E3EAC5FE90
:10007000B705000293858518370600021306464B24
:1000800021A023A005009105E3EDC5FEB702000203
:100090009382020C73905230B7000001E780600B2E
:1000A000B7000001E780600BB7100001E780E09324
:0800B00073005010F5BF8280BF
:1000B8000000000000000000000000000000000038
:1000C8000000000000000000000000000000000028
:1000D8000000000000000000000000000000000018
:1000E8000000000000000000000000000000000008
:1000F80000000000000000000000000000000000F8
:1001080000000000000000000000000000000000E7
:1001180000000000000000000000000000000000D7
:1001280000000000000000000000000000000000C7
:1001380000000000000000000000000000000000B7
:1001480000000000000000000000000000000000A7
:100158000000000000000000000000000000000097
:100168000000000000000000000000000000000087
:100178006F004000130141F806C00AC20EC412C63F
:1001880016C81ACA1ECC22CE26D02AD22ED432D6CF
:1001980036D83ADA3EDC42DEC6C0CAC2CEC4D2C6BF
:1001A800D6C8DACADECCE2CEE6D0EAD2EED4F2D6AF
:1001B800F6D8FADAFEDC97000000938000058290FA
:1001C80082401241A2413242C2425243E243724447
:1001D80082541255A2553256C2565257E257725897
:1001E80086481649A649364AC64A564BE64B764CC7
:1001F800865C165DA65D365EC65E565FE65F1301D9
:08020800C1077300203001A0C2
:100210003D432A876373C3029377F700BDEFADE5D3
:10022000937606FF3D8ABA960CC34CC30CC74CC7E5
:100230004107E36BD7FE11E28280B306C3408A0612
:100240009702000096966780A6002307B700A306D2
:10025000B7002306B700A305B7002305B700A30422
:10026000B7002304B700A303B7002303B700A3021A
:10027000B7002302B700A301B7002301B700A30012
:10028000B7002300B700828093F5F50F93968500A1
:10029000D58D93960501D58D61B79396270097026A
:1002A000000096968682E78086FA9680C1171D8F99
:1002B0003E96E374C3F8A5B7B70705000947D8CF42
:1002C000B7170500938707C0984385669386064055
:1002D000558F98C398471367074098C7B71708000A
:1002E0009387074023A0070023A2070023A4070049
:1002F0001307A008D8C77D57D8CF354798C3D84F24
:10030000935657018D8AE5DE8280B71708009387E0
:10031000074023A0070023A2070023A4070023A669
:1003200007007D57D8CF23A40702B717050093878E
:1003300007C09843F1769386F63F758F98C3984728
:100340001377F7BF98C7B7070500094798D382808E
:10035000B71708009387074088D7D84F137707044B
:100360006DDF828003A3418637150800B7450F0073
:1003700023A4018681470146130505409385152472
:100380000328C501B308F30013780802630A0802C2
:1003900011CE23A2118737470F0023A4F18613073C
:1003A00007246395E70005472387E184B717080012
:1003B00093870740C8534205418182800546C9B7EB
:1003C0008507E39DB7FE7DD2B7470F0093870724CB
:1003D00023A4F18623A21187F9B7411106C622C4CE
:1003E00026C2AA84EF007028E1689388086A014851
:1003F0008147014781460146B70520C726853794C6
:100400009800EF00F00B130414687D1419E40D45F7
:10041000B240224492444101828085452685EF0006
:10042000302605897DF10145E5B7411122C4130647
:1004300000109305F00F1385C18606C6D13B83A536
:1004400081849386C1861306001013850182EF0014
:1004500090341384C186814793050410130600105D
:10046000B306F4003387F50083C606000347070090
:10047000639AE6008507E395C7FE0545B24022442E
:10048000410182800145DDBF411126C293878184ED
:100490008C43B70700804AC0BE9523AEB18406C620
:1004A00022C4939745019384818489E7138501824F
:1004B000EF00302A8C409386C18613850182938693
:1004C000061013060010EF00102485371384C18630
:1004D00011E989472383F400B2402244924402493F
:1004E000410182809C4083D68185938707109CC000
:1004F00013060010B68763F4C600930700109387B5
:1005000007F01306100F9305F00F1305F410239C4A
:10051000F18413040420ED39A2853D461385C1966C
:10052000EF00D02822852244B240924402493D4641
:100530009305F00F4101E9B95D7113068002814511
:10054000280886C6F131BD47230CF1008947230EE8
:10055000F1003ED2E177938707082C080A85231A19
:10056000F102DD23B640616182805D71A2C4138512
:10057000018286C6A6C2CAC0EF00E06A1385018266
:10058000EF00C07D854513850182EF00700F8D4718
:10059000814463E3A700AA84894513850182EF00A3
:1005A000300E937725002A8689E713662500137697
:1005B000F60F9377060499C31376F60BA685138579
:1005C0000182EF00500FE1689388086A0148814773
:1005D000014781460146B705203813850182EF00A7
:1005E000206EE16838009388086A13080002854687
:1005F00081470146B70599EB138501822304010069
:10060000EF00006CB715000151469385450F680057
:10061000EF00D01913890182832709006C0051462D
:100620003ED085473ED26810C1673ED4EF00101817
:10063000B70607009C423707F1FF7D17F98F0810B6
:100640009CC22525B64026449644064961618280B5
:10065000411106C65D39113FB707008073905730CE
:10066000B70000808290B24041018280411122C4D3
:1006700006C69387818483C7670085461384818477
:10068000638ED70009476388E70023030400B24064
:100690002244410182801305000F5D39B71708001D
:1006A00093870740D84F218B09C7D84F136787001E
:1006B000D8CF793FD9BF411106C622C426C24AC04D
:1006C0008347350005476389E70611472A84638914
:1006D000E7009DC7B2402244924402494101828012
:1006E00083D7818591C34D3383474400034754002A
:1006F000E2074207BA9723A0F18623A4F184D9BF69
:1007000083D48185034604001385C19626959305FD
:100710004400EF00B00983470400BE94C204C180C6
:10072000239C91849307F00FE3F697FA2244B2409A
:1007300092440249410189BB3D45193983D78185DE
:1007400099E72244B24092440249410111B72D3B3E
:1007500083C7E184FDD7BDBF41119386818403DF48
:10076000460026C483A2818622C637150800B748F2
:100770000F0037430F004AC2814723AA018413099F
:10078000FFFF814E81468145814301480146138721
:100790008184130505409388182413030324138EC2
:1007A000C1A7636BE60363850E0009462303C700F8
:1007B00099C2A388F18499C123AA718463040800B3
:1007C00023A4518683476700A9E33244A244124917
:1007D0001385C1A74101C5B581420328C50113781E
:1007E0000802631908028502E39912FF99C2A388DF
:1007F000F18499C123AA7184B7470F009387072416
:1008000023A4F18685472303F7003244A24412490A
:1008100041018280E38C62FC03284502937FF80F3C
:10082000637D26011378F80FC29385453308CE0007
:100830002300F80105060548ADB7B307704093F7EC
:10084000F70F6394FF008546D5B7854EEDBF0111C4
:1008500026CA4EC652C4B7490F00371ADCBA22CC9A
:100860004AC856C25AC006CE938481849389F9231C
:10087000930A0006130B0009391AED3483A7418649
:10088000A383A40063F3F900E13383C7640099C331
:10089000F13BE5B783C67400638356096388660538
:1008A000930700036381F60603C701858D47998F7F
:1008B0008E07B357FA0093F7F70F639FF606930777
:1008C000170093F7F70F2388F1841147639DE70022
:1008D0003D45BD3C13850182093629CD1305000F26
:1008E000853C2388018423A2018641BF3D4523A284
:1008F000018623880184A93C0145993C0945893C2E
:100900000145B9349DBF3D4523A20186238801845A
:100910008134893C05052392A4003D45DDB73D4562
:1009200023A201862388018425343D3583C76400D2
:10093000A5F3E5B73D456DB7238801843DBF01119F
:1009400006CE22CCD53E13850182F12C138501827F
:100950003121E1689388086A01488147780085461B
:100960000146B705D9EB1385018223060100892EC4
:10097000E1689388086A014881470147814601463A
:10098000B70538FF13850182252EEFF0FF92C135A0
:100990000547AA876305E50209476300E5060545A3
:1009A00091EBB7060600DC4A7D771307F73FF98F16
:1009B000DCCA014582807D1719EB0D4582809306C4
:1009C000004037A7070013070712B7050500905D21
:1009D0007D8E75D2370606005C4A7D771307F73F98
:1009E000F98FD58F41115CCA02C613073006B24792
:1009F0006359F70001454101828085669386068030
:100A0000C9B7B24785073EC6DDB791476307F50210
:100A100063EAA7008547630AF50489476309F5047B
:100A200005458280A147E31DF5FE0947094501A858
:100A3000FD1781EFC8D20D45828005470D45B7A748
:100A4000070093870712B7060500905E798E6DD276
:100A50008A05C98D4111CCD202C613073006B247B0
:100A6000635AF7000145410182801147C9BF214700
:100A70000145F1B7B24785073EC6D5B70547AA87F6
:100A80006305E50209476304E506054591EBB706F2
:100A900006009C4A7D771307F73FF98F9CCA0145F2
:100AA00082807D1719EB0D4582809306004037A7A1
:100AB000070013070712B7050500905D7D8E75D2FC
:100AC000370706001C4B7D761306F63FF18FD58F56
:100AD0001CCB232C070085471CCF411102C61307EE
:100AE0003006B2476359F7000145410182808566AF
:100AF000938606806DBFB24785073EC6DDB711C934
:100B00008547630DF50205458280FD1791EB0D4584
:100B100082800946B7A7070093870712B70605002A
:100B2000985E718F7DD34111C8D602C61307300677
:100B3000B2476357F7000145410182800546D9BF9E
:100B4000B24785073EC6EDB7011126CAB7040600B5
:100B5000DC4806CE22CC4AC84EC652C456C2F19BCF
:100B6000DCC89C482A89C845F19B9CC8D84883C7E3
:100B7000C5012E84137737C08A07D98FDCC883C795
:100B8000D50198489A071377F7C393F7073CD98F95
:100B90009CC8FD3B0C44AA8A03454400BD35184857
:100BA000B70705002A8A98C358480850D8C3184C7C
:100BB00098C7E935AA8948509937834704002A879E
:100BC00093F6170089E6D44893E62600D4C893F636
:100BD000270099E637060600544A93E6160054CAE1
:100BE00093F6470099E637060600144A93E6260076
:100BF00014CAA18B99E7B70606009C4A93E7170031
:100C00009CCAF24062442320590123224901232433
:100C100039012326E900D244B249224A924A4A8540
:100C2000424905618280011106CE22CC02C402C66F
:100C30002147B707050037550800D8C705448D4739
:100C40008A85130505803EC022C2292A375508002F
:100C50009307C0038A851305058022C222C43EC0C3
:100C60001122F240624405618280411122C406C60D
:100C70002A84553F18405C4F93E707015CCF1C4422
:100C80001CCB5C4085CB1C43B7061000D58F1CC322
:100C9000144C5C48B240D606CE07D58F834604017B
:100CA000C206D58F8346C4012244E206D58F1CCFED
:100CB000410182801C43B706F0FFFD16F58FC1BFCE
:100CC000032305002A8E0325C30113650502232E85
:100CD000A3002324C3001396260149824D8E2326A8
:100CE00003012322C300139605016354060299C22F
:100CF0000545B1CB01476346D700639C08020D450B
:100D000082803386E700034606000507230AC300F6
:100D1000DDB799C2054505CB8147E3D0D7FE032651
:100D20000E00034546013306F70085072300A600A1
:100D3000EDB783270E00FD18DC4F93F70702D5DFD0
:100D400011656D8D11E18280B707070083C74701E8
:100D500013F585001D8D3335A00082801C4141476D
:100D6000D8CF8280B7470800938707402A8863045A
:100D7000F508B7570800938707806304F50A3747DB
:100D80000800630DE50A05458280331E1F01337696
:100D9000DE0129C683A345008843139318003396C8
:100DA0006F001346F6FF13F43300718D33146400A3
:100DB000418D88C3638B5302638C0302084303AEE7
:100DC000C500718D331E6E003365C50108C38842AE
:100DD000698E884533156500498E90C2850833D5E4
:100DE0001E0145F53244410182802326C801F9B72E
:100DF0002324C801E1B7B716050037170500B71758
:100E00000500938646C1130707C19387C7C083AE09
:100E100005008148054F8D4F914233D51E0105EDE8
:100E20008280B716050037170500B71705009386AF
:100E300006C21307C7C1938787C1D1BFB716050084
:100E400037170500B7170500938686C0130747C0FC
:100E5000938707C06DBF331E1F013376DE0119E291
:100E6000850865BF411122C635B7E1689388086AD5
:100E700001488147014781460146B705200689B5EB
:100E8000011106CEA307010089476393F502B70558
:100E90002035E1681307F1009388086A014881470B
:100EA00085460146313DF2400345F10005618280EF
:100EB000B7052005F9BF011106CE22CC26CA2306AC
:100EC000B100AA84A306C1004D37E1689388086A7F
:100ED00001487C00014789460146B78520012685E7
:100EE0000964F93B130414717D1419E40D45F240B3
:100EF0006244D24405618280854526855137058943
:100F000065F50145EDB7011106CE22CC26CA2E8427
:100F10004AC8AA84328936C6893FB247E168228628
:100F20009388086A01480147CA86B78580022685EA
:100F3000616479331304146A7D1411C485452685D0
:100F40008137058975F9F2406244D244424905610E
:100F50008280011106CE22CC26CA2EC6AA84313741
:100F60003246E1689388086A014881470147814613
:100F7000B705802026856164A1331304146A7D14AB
:100F800011C485452685ED3D058975F9F240624419
:100F9000D24405618280E16836879388086AB28608
:100FA00001482E868147B705800319BBB3C7A5004A
:100FB0008D8BB308C500B1E78D4763F4C704937701
:100FC00035002A87B9EB13F6C8FFB306E64093074E
:100FD000000263C8D706AE86BA876371C70203A84A
:100FE00006009107910623AE07FFE3EAC7FE9307C9
:100FF000F6FF998FF19B91073E97BE9563661701A7
:1010000082802A87637E150383C70500050785054F
:10101000A30FF7FEE39AE8FE828083C6050005076A
:1010200093773700A30FD7FE8505D1DF83C6050070
:10103000050793773700A30FD7FE8505F9FF61B742
:101040008280411122C61304000283A3050083A2FB
:10105000450083AF850003AFC50083AE050103AE35
:10106000450103A3850103A8C50194511307470255
:10107000B307E640232E77FC232057FE2322F7FFF9
:101080002324E7FF2326D7FF2328C7FF232A67FE51
:10109000232C07FF232ED7FE93854502E347F4FA5E
:1010A000AE86BA876371C70203A80600910791064E
:1010B00023AE07FFE3EAC7FE9307F6FF998FF19B84
:1010C00091073E97BE9563651701324441018280C6
:1010D00083C7050005078505A30FF7FEE387E8FE34
:1010E00083C7050005078505A30FF7FEE392E8FE19
:1010F000E9BF000020000000010000000300000024
:0811000006000000EB000000F6
:1011080000000700000000000000000000000000D0
:1011180000000000000000000000000000000000C7
:081128000000000000000000BF
:08113000000000800000000037
:0400000501000000F6
:00000001FF

View File

@ -0,0 +1,281 @@
:020000040100F9
:10000000FD6293820240FD12E39F02FE374100022F
:1000100013010100B711000293818193B71500010C
:10002000938585103716000113068613B706000264
:100030009386861539A083A2050023A0560091055A
:100040009106E3EAC5FEB70500019385850B3706E7
:10005000000113060621B70600029386060039A0A8
:1000600083A2050023A0560091059106E3EAC5FE90
:10007000B705000293858518370600021306464B24
:1000800021A023A005009105E3EDC5FEB702000203
:100090009382020C73905230B7000001E780600B2E
:1000A000B7000001E780600BB7100001E780E09324
:0800B00073005010F5BF8280BF
:1000B8000000000000000000000000000000000038
:1000C8000000000000000000000000000000000028
:1000D8000000000000000000000000000000000018
:1000E8000000000000000000000000000000000008
:1000F80000000000000000000000000000000000F8
:1001080000000000000000000000000000000000E7
:1001180000000000000000000000000000000000D7
:1001280000000000000000000000000000000000C7
:1001380000000000000000000000000000000000B7
:1001480000000000000000000000000000000000A7
:100158000000000000000000000000000000000097
:100168000000000000000000000000000000000087
:100178006F004000130141F806C00AC20EC412C63F
:1001880016C81ACA1ECC22CE26D02AD22ED432D6CF
:1001980036D83ADA3EDC42DEC6C0CAC2CEC4D2C6BF
:1001A800D6C8DACADECCE2CEE6D0EAD2EED4F2D6AF
:1001B800F6D8FADAFEDC97000000938000058290FA
:1001C80082401241A2413242C2425243E243724447
:1001D80082541255A2553256C2565257E257725897
:1001E80086481649A649364AC64A564BE64B764CC7
:1001F800865C165DA65D365EC65E565FE65F1301D9
:08020800C1077300203001A0C2
:100210003D432A876373C3029377F700BDEFADE5D3
:10022000937606FF3D8ABA960CC34CC30CC74CC7E5
:100230004107E36BD7FE11E28280B306C3408A0612
:100240009702000096966780A6002307B700A306D2
:10025000B7002306B700A305B7002305B700A30422
:10026000B7002304B700A303B7002303B700A3021A
:10027000B7002302B700A301B7002301B700A30012
:10028000B7002300B700828093F5F50F93968500A1
:10029000D58D93960501D58D61B79396270097026A
:1002A000000096968682E78086FA9680C1171D8F99
:1002B0003E96E374C3F8A5B7B70705000947D8CF42
:1002C000B7170500938707C0984385669386064055
:1002D000558F98C398471367074098C7B71708000A
:1002E0009387074023A0070023A2070023A4070049
:1002F0001307A008D8C77D57D8CF354798C3D84F24
:10030000935657018D8AE5DE8280B71708009387E0
:10031000074023A0070023A2070023A4070023A669
:1003200007007D57D8CF23A40702B717050093878E
:1003300007C09843F1769386F63F758F98C3984728
:100340001377F7BF98C7B7070500094798D382808E
:10035000B71708009387074088D7D84F137707044B
:100360006DDF828003A3418637150800B7450F0073
:1003700023A4018681470146130505409385152472
:100380000328C501B308F30013780802630A0802C2
:1003900011CE23A2118737470F0023A4F18613073C
:1003A00007246395E70005472387E184B717080012
:1003B00093870740C8534205418182800546C9B7EB
:1003C0008507E39DB7FE7DD2B7470F0093870724CB
:1003D00023A4F18623A21187F9B7411106C622C4CE
:1003E00026C2AA84EF007028E1689388086A014851
:1003F0008147014781460146B70520C726853794C6
:100400009800EF00F00B130414687D1419E40D45F7
:10041000B240224492444101828085452685EF0006
:10042000302605897DF10145E5B7411122C4130647
:1004300000109305F00F1385C18606C6D13B83A536
:1004400081849386C1861306001013850182EF0014
:1004500090341384C186814793050410130600105D
:10046000B306F4003387F50083C606000347070090
:10047000639AE6008507E395C7FE0545B24022442E
:10048000410182800145DDBF411126C293878184ED
:100490008C43B70700804AC0BE9523AEB18406C620
:1004A00022C4939745019384818489E7138501824F
:1004B000EF00302A8C409386C18613850182938693
:1004C000061013060010EF00102485371384C18630
:1004D00011E989472383F400B2402244924402493F
:1004E000410182809C4083D68185938707109CC000
:1004F00013060010B68763F4C600930700109387B5
:1005000007F01306100F9305F00F1305F410239C4A
:10051000F18413040420ED39A2853D461385C1966C
:10052000EF00D02822852244B240924402493D4641
:100530009305F00F4101E9B95D7113068002814511
:10054000280886C6F131BD47230CF1008947230EE8
:10055000F1003ED2E177938707082C080A85231A19
:10056000F102DD23B640616182805D71A2C4138512
:10057000018286C6A6C2CAC0EF00E06A1385018266
:10058000EF00C07D854513850182EF00700F8D4718
:10059000814463E3A700AA84894513850182EF00A3
:1005A000300E937725002A8689E713662500137697
:1005B000F60F9377060499C31376F60BA685138579
:1005C0000182EF00500FE1689388086A0148814773
:1005D000014781460146B705203813850182EF00A7
:1005E000206EE16838009388086A13080002854687
:1005F00081470146B70599EB138501822304010069
:10060000EF00006CB715000151469385450F680057
:10061000EF00D01913890182832709006C0051462D
:100620003ED085473ED26810C1673ED4EF00101817
:10063000B70607009C423707F1FF7D17F98F0810B6
:100640009CC22525B64026449644064961618280B5
:10065000411106C65D39113FB707008073905730CE
:10066000B70000808290B24041018280411122C4D3
:1006700006C69387818483C7670085461384818477
:10068000638ED70009476388E70023030400B24064
:100690002244410182801305000F5D39B71708001D
:1006A00093870740D84F218B09C7D84F136787001E
:1006B000D8CF793FD9BF411106C622C426C24AC04D
:1006C0008347350005476389E70611472A84638914
:1006D000E7009DC7B2402244924402494101828012
:1006E00083D7818591C34D3383474400034754002A
:1006F000E2074207BA9723A0F18623A4F184D9BF69
:1007000083D48185034604001385C19626959305FD
:100710004400EF00B00983470400BE94C204C180C6
:10072000239C91849307F00FE3F697FA2244B2409A
:1007300092440249410189BB3D45193983D78185DE
:1007400099E72244B24092440249410111B72D3B3E
:1007500083C7E184FDD7BDBF41119386818403DF48
:10076000460026C483A2818622C637150800B748F2
:100770000F0037430F004AC2814723AA018413099F
:10078000FFFF814E81468145814301480146138721
:100790008184130505409388182413030324138EC2
:1007A000C1A7636BE60363850E0009462303C700F8
:1007B00099C2A388F18499C123AA718463040800B3
:1007C00023A4518683476700A9E33244A244124917
:1007D0001385C1A74101C5B581420328C50113781E
:1007E0000802631908028502E39912FF99C2A388DF
:1007F000F18499C123AA7184B7470F009387072416
:1008000023A4F18685472303F7003244A24412490A
:1008100041018280E38C62FC03284502937FF80F3C
:10082000637D26011378F80FC29385453308CE0007
:100830002300F80105060548ADB7B307704093F7EC
:10084000F70F6394FF008546D5B7854EEDBF0111C4
:1008500026CA4EC652C4B7490F00371ADCBA22CC9A
:100860004AC856C25AC006CE938481849389F9231C
:10087000930A0006130B0009391AED3483A7418649
:10088000A383A40063F3F900E13383C7640099C331
:10089000F13BE5B783C67400638356096388660538
:1008A000930700036381F60603C701858D47998F7F
:1008B0008E07B357FA0093F7F70F639FF606930777
:1008C000170093F7F70F2388F1841147639DE70022
:1008D0003D45BD3C13850182093629CD1305000F26
:1008E000853C2388018423A2018641BF3D4523A284
:1008F000018623880184A93C0145993C0945893C2E
:100900000145B9349DBF3D4523A20186238801845A
:100910008134893C05052392A4003D45DDB73D4562
:1009200023A201862388018425343D3583C76400D2
:10093000A5F3E5B73D456DB7238801843DBF01119F
:1009400006CE22CCD53E13850182F12C138501827F
:100950003121E1689388086A01488147780085461B
:100960000146B705D9EB1385018223060100892EC4
:10097000E1689388086A014881470147814601463A
:10098000B70538FF13850182252EEFF0FF92C135A0
:100990000547AA876305E50209476300E5060545A3
:1009A00091EBB7060600DC4A7D771307F73FF98F16
:1009B000DCCA014582807D1719EB0D4582809306C4
:1009C000004037A7070013070712B7050500905D21
:1009D0007D8E75D2370606005C4A7D771307F73F98
:1009E000F98FD58F41115CCA02C613073006B24792
:1009F0006359F70001454101828085669386068030
:100A0000C9B7B24785073EC6DDB791476307F50210
:100A100063EAA7008547630AF50489476309F5047B
:100A200005458280A147E31DF5FE0947094501A858
:100A3000FD1781EFC8D20D45828005470D45B7A748
:100A4000070093870712B7060500905E798E6DD276
:100A50008A05C98D4111CCD202C613073006B247B0
:100A6000635AF7000145410182801147C9BF214700
:100A70000145F1B7B24785073EC6D5B70547AA87F6
:100A80006305E50209476304E506054591EBB706F2
:100A900006009C4A7D771307F73FF98F9CCA0145F2
:100AA00082807D1719EB0D4582809306004037A7A1
:100AB000070013070712B7050500905D7D8E75D2FC
:100AC000370706001C4B7D761306F63FF18FD58F56
:100AD0001CCB232C070085471CCF411102C61307EE
:100AE0003006B2476359F7000145410182808566AF
:100AF000938606806DBFB24785073EC6DDB711C934
:100B00008547630DF50205458280FD1791EB0D4584
:100B100082800946B7A7070093870712B70605002A
:100B2000985E718F7DD34111C8D602C61307300677
:100B3000B2476357F7000145410182800546D9BF9E
:100B4000B24785073EC6EDB7011126CAB7040600B5
:100B5000DC4806CE22CC4AC84EC652C456C2F19BCF
:100B6000DCC89C482A89C845F19B9CC8D84883C7E3
:100B7000C5012E84137737C08A07D98FDCC883C795
:100B8000D50198489A071377F7C393F7073CD98F95
:100B90009CC8FD3B0C44AA8A03454400BD35184857
:100BA000B70705002A8A98C358480850D8C3184C7C
:100BB00098C7E935AA8948509937834704002A879E
:100BC00093F6170089E6D44893E62600D4C893F636
:100BD000270099E637060600544A93E6160054CAE1
:100BE00093F6470099E637060600144A93E6260076
:100BF00014CAA18B99E7B70606009C4A93E7170031
:100C00009CCAF24062442320590123224901232433
:100C100039012326E900D244B249224A924A4A8540
:100C2000424905618280011106CE22CC02C402C66F
:100C30002147B707050037550800D8C705448D4739
:100C40008A85130505803EC022C2292A375508002F
:100C50009307C0038A851305058022C222C43EC0C3
:100C60001122F240624405618280411122C406C60D
:100C70002A84553F18405C4F93E707015CCF1C4422
:100C80001CCB5C4085CB1C43B7061000D58F1CC322
:100C9000144C5C48B240D606CE07D58F834604017B
:100CA000C206D58F8346C4012244E206D58F1CCFED
:100CB000410182801C43B706F0FFFD16F58FC1BFCE
:100CC000032305002A8E0325C30113650502232E85
:100CD000A3002324C3001396260149824D8E2326A8
:100CE00003012322C300139605016354060299C22F
:100CF0000545B1CB01476346D700639C08020D450B
:100D000082803386E700034606000507230AC300F6
:100D1000DDB799C2054505CB8147E3D0D7FE032651
:100D20000E00034546013306F70085072300A600A1
:100D3000EDB783270E00FD18DC4F93F70702D5DFD0
:100D400011656D8D11E18280B707070083C74701E8
:100D500013F585001D8D3335A00082801C4141476D
:100D6000D8CF8280B7470800938707402A8863045A
:100D7000F508B7570800938707806304F50A3747DB
:100D80000800630DE50A05458280331E1F01337696
:100D9000DE0129C683A345008843139318003396C8
:100DA0006F001346F6FF13F43300718D33146400A3
:100DB000418D88C3638B5302638C0302084303AEE7
:100DC000C500718D331E6E003365C50108C38842AE
:100DD000698E884533156500498E90C2850833D5E4
:100DE0001E0145F53244410182802326C801F9B72E
:100DF0002324C801E1B7B716050037170500B71758
:100E00000500938646C1130707C19387C7C083AE09
:100E100005008148054F8D4F914233D51E0105EDE8
:100E20008280B716050037170500B71705009386AF
:100E300006C21307C7C1938787C1D1BFB716050084
:100E400037170500B7170500938686C0130747C0FC
:100E5000938707C06DBF331E1F013376DE0119E291
:100E6000850865BF411122C635B7E1689388086AD5
:100E700001488147014781460146B705200689B5EB
:100E8000011106CEA307010089476393F502B70558
:100E90002035E1681307F1009388086A014881470B
:100EA00085460146313DF2400345F10005618280EF
:100EB000B7052005F9BF011106CE22CC26CA2306AC
:100EC000B100AA84A306C1004D37E1689388086A7F
:100ED00001487C00014789460146B78520012685E7
:100EE0000964F93B130414717D1419E40D45F240B3
:100EF0006244D24405618280854526855137058943
:100F000065F50145EDB7011106CE22CC26CA2E8427
:100F10004AC8AA84328936C6893FB247E168228628
:100F20009388086A01480147CA86B78580022685EA
:100F3000616479331304146A7D1411C485452685D0
:100F40008137058975F9F2406244D244424905610E
:100F50008280011106CE22CC26CA2EC6AA84313741
:100F60003246E1689388086A014881470147814613
:100F7000B705802026856164A1331304146A7D14AB
:100F800011C485452685ED3D058975F9F240624419
:100F9000D24405618280E16836879388086AB28608
:100FA00001482E868147B705800319BBB3C7A5004A
:100FB0008D8BB308C500B1E78D4763F4C704937701
:100FC00035002A87B9EB13F6C8FFB306E64093074E
:100FD000000263C8D706AE86BA876371C70203A84A
:100FE00006009107910623AE07FFE3EAC7FE9307C9
:100FF000F6FF998FF19B91073E97BE9563661701A7
:1010000082802A87637E150383C70500050785054F
:10101000A30FF7FEE39AE8FE828083C6050005076A
:1010200093773700A30FD7FE8505D1DF83C6050070
:10103000050793773700A30FD7FE8505F9FF61B742
:101040008280411122C61304000283A3050083A2FB
:10105000450083AF850003AFC50083AE050103AE35
:10106000450103A3850103A8C50194511307470255
:10107000B307E640232E77FC232057FE2322F7FFF9
:101080002324E7FF2326D7FF2328C7FF232A67FE51
:10109000232C07FF232ED7FE93854502E347F4FA5E
:1010A000AE86BA876371C70203A80600910791064E
:1010B00023AE07FFE3EAC7FE9307F6FF998FF19B84
:1010C00091073E97BE9563651701324441018280C6
:1010D00083C7050005078505A30FF7FEE387E8FE34
:1010E00083C7050005078505A30FF7FEE392E8FE19
:1010F000E9BF000020000000010000000300000024
:0811000006000000EB000000F6
:1011080000000700000000000000000000000000D0
:1011180000000000000000000000000000000000C7
:081128000000000000000000BF
:08113000000000800000000037
:0400000501000000F6
:00000001FF

View File

@ -1,10 +1,10 @@
:020000040100F9
:10000000FD62938202400100FD12E39E02FE374131
:10001000000213010100B701000293810100B7152E
:100020000001938505FF3716000113060602B70687
:100020000001938505003716000113060603B70685
:1000300000029386060039A083A2050023A0560083
:1000400091059106E3EAC5FEB71500019385050207
:100050003716000113060602B7060002938606262D
:1000400091059106E3EAC5FEB71500019385050306
:100050003716000113060603B7060002938606262C
:1000600039A083A2050023A0560091059106E3EA7A
:10007000C5FEB70500029385050337060002130687
:10008000062621A023A005009105E3EDC5FEB700DB
@ -34,7 +34,7 @@
:100200000947D8CFB7170500938707C0984385667D
:1002100093860640558F98C398471367074098C741
:10022000B71708009387074023A0070023A2070001
:1002300023A407001307A008D8C77D57D8CF354798
:1002300023A407001307B010D8C77D57D8CF354780
:1002400098C3D84F935657018D8AE5DE8280B71741
:1002500008009387074023A0070023A2070023A4D8
:10026000070023A607007D57D8CF23A40702B7179E
@ -50,38 +50,38 @@
:1003000093870740C85342054181828005467DBFDF
:100310008507E39DB7FE7DD2B7470F00938707247B
:1003200023A4F60423221705E9B7411106C622C407
:1003300026C2AA84EF00B022E1689388086A0148C7
:1003300026C2AA84EF003024E1689388086A014845
:100340008147014781460146B70520C72685379476
:100350009800EF003006130414687D1419E40D456D
:100350009800EF00B007130414687D1419E40D45EC
:10036000B240224492444101828085452685EF00B7
:10037000702005897DF10145E5B7411122C437049C
:10037000F02105897DF10145E5B7411122C437041B
:100380000002930704008C43B70700804AC0BE9563
:10039000B707000223AEB70206C626C293974501EF
:1003A000130404003709000289E713058900EF00F0
:1003B00090290C40B70400029386C4041306001071
:1003C00013058900EF0070231C4037070002835695
:1003B000102B0C40B70400029386C40413060010EF
:1003C00013058900EF00F0241C4037070002835614
:1003D0008703938707101CC013060010B68763F4C9
:1003E000C600930700101384C4041305F400938718
:1003F00007F01306100F814513040410231CF702A5
:10040000913BA2851385C4043D46EF0010282320AC
:10040000913BA2851385C4043D46EF00902923202B
:1004100004002322040023240400231604002307DD
:100420000400B240224492440249410182805D713D
:10043000130680028145280886C6293BBD47230C48
:10044000F1008947230EF1003ED2E1779387070838
:100450002C080A85231AF102E52BB64061618280DF
:100450002C080A85231AF102F52BB64061618280CF
:100460005D71A2C4370400021305840086C6A6C2CB
:10047000CAC0652513058400EF00807D85451305FE
:100480008400EF00300F8D47814463E3A700AA8406
:10049000894513058400EF00F00D937725002A8627
:10047000CAC0C12513058400EF00007F8545130520
:100480008400EF00B0108D47814463E3A700AA8485
:10049000894513058400EF00700F937725002A86A5
:1004A00089E7136625001376F60FA68513058400E9
:1004B000EF00B00FE1689388086A0148814701475F
:1004C00081460146B705203813058400E525E1681B
:1004B000EF003011E1689388086A014881470147DD
:1004C00081460146B7052038130584000127E168FD
:1004D00038009388086A1308000285468147014660
:1004E000B70599EB1305840023040100E125B71536
:1004F00000015146938505FD6800EF0010191309AE
:1004E000B70599EB1305840023040100C525B71552
:1004F00000015146938585FE6800EF00901A1309AC
:100500008400832709006C0051463ED085473ED2C7
:100510006810C1673ED4EF005017B70607009C4231
:100520003707F1FF7D17F98F08109CC20D2DB640DB
:100510006810C1673ED4EF00D018B70607009C42B0
:100520003707F1FF7D17F98F08109CC2A925B64047
:1005300026449644064961618280411106C6013B0A
:100540000537B707008073905730B700008082905E
:10055000B2404101828041113707000222C406C621
@ -96,7 +96,7 @@
:1005E0005400E2074207BA97370700022320F704B6
:1005F000370700022320F700E9B7370900028354C8
:1006000089030346050093054500370500021305DD
:10061000C5042695EF00700783470400BE94C2040A
:10061000C5042695EF00F00883470400BE94C20489
:10062000C180231C99029307F00FE3FC97F8224442
:10063000B24092440249410189B33D45A139B7070F
:10064000000283D7870391C30D3B2244B2409244FA
@ -132,11 +132,11 @@
:10082000A4003D45853CADBF3D45232209042388F6
:1008300004028D340D3583476400B5FFDDB73D45B7
:10084000C9B723880402A9BF011106CE22CCC53640
:100850003704000213058400C92413058400CD2E3B
:100850003704000213058400E92C130584002921C4
:10086000E1689388086A0148814778008546014617
:10087000B705D9EB1305840023060100252EE16896
:10087000B705D9EB1305840023060100812EE1683A
:100880009388086A01488147014781460146B705B8
:1008900038FF13058400392E9532F9350547AA87AC
:1008900038FF130584001D2E9532F9350547AA87C8
:1008A0006305E50209476300E506054591EBB706D8
:1008B0000600DC4A7D771307F73FF98FDCCA014554
:1008C00082807D1719EB0D4582809306004037A783
@ -152,110 +152,111 @@
:100960004111CCD202C613073006B247635AF700D2
:100970000145410182801147C9BF21470145F1B7B7
:10098000B24785073EC6D5B70547AA876305E50286
:1009900009476302E506054591EBB70606009C4A48
:1009900009476304E506054591EBB70606009C4A46
:1009A0007D771307F73FF98F9CCA014582807D1739
:1009B00019EB0D4582809306004037A70700130707
:1009C0000712B7050500905D7D8E75D237070600CA
:1009D0001C4B7D761306F63FF18FD58F1CCB8547D8
:1009E0001CCF411102C613073006B2476359F70006
:1009F0000145410182808566938606807DBFB247AE
:100A000085073EC6DDB711C98547630DF50205456B
:100A10008280FD1791EB0D4582800946B7A707003C
:100A200093870712B7060500985E718F7DD3411139
:100A3000C8D602C613073006B2476357F700014510
:100A4000410182800546D9BFB24785073EC6EDB752
:100A5000011126CAB7040600DC4806CE22CC4AC8DB
:100A60004EC652C456C2F19BDCC89C482A89C84570
:100A7000F19B9CC883C7C5012E848A07DCC883C745
:100A8000D5018A079CC8193D0C44AA8A0345440035
:100A900059351848B70705002A8A98C3584808509E
:100AA000D8C3184C98C7CD35AA894850A93F834769
:100AB00004002A8793F6170089E6D44893E62600B7
:100AC000D4C893F6270099E637060600544A93E601
:100AD000160054CA93F6470099E637060600144AF2
:100AE00093E6260014CAA18B99E7B70606009C4A34
:100AF00093E717009CCAF240624423205901232245
:100B00004901232439012326E900D244B249224A6B
:100B1000924A4A85424905618280011106CE22CC63
:100B200002C402C62147B707050037550800D8C7D9
:100B300005448D478A85130505803EC022C2292AB7
:100B4000375508009307C0038A851305058022C224
:100B500022C43EC01122F2406244056182804111EC
:100B600022C406C62A84553F18405C4F93E707010C
:100B70005CCF1C441CCB5C4085CB1C43B7061000EB
:100B8000D58F1CC3144C5C48B240D606CE07D58F17
:100B900083460401C206D58F8346C4012244E2067F
:100BA000D58F1CCF410182801C43B706F0FFFD1694
:100BB000F58FC1BF032305002A8E0325C3011365EA
:100BC0000502232EA3002324C30013962601498285
:100BD0004D8E232603012322C3001396050163547F
:100BE000060299C20545B1CB01476346D700639C15
:100BF00008020D4582803386E7000346060005079C
:100C0000230AC300DDB799C2054505CB8147E3D070
:100C1000D7FE03260E00034546013306F70085077D
:100C20002300A600EDB783270E00FD18DC4F93F7D5
:100C30000702D5DF11656D8D11E18280B7070700CE
:100C400083C7470113F585001D8D3335A0008280D1
:100C50001C414147D8CF8280B7470800938707409F
:100C60002A886304F508B757080093870780630450
:100C7000F50A37470800630DE50A05458280331EF3
:100C80001F013376DE0129C683A3450088431393F1
:100C9000180033966F001346F6FF13F43300718D7E
:100CA00033146400418D88C3638B5302638C030249
:100CB000084303AEC500718D331E6E003365C50158
:100CC00008C38842698E884533156500498E90C2F5
:100CD000850833D51E0145F5324441018280232623
:100CE000C801F9B72324C801E1B7B71605003717C3
:100CF0000500B7170500938646C1130707C1938700
:100D0000C7C083AE05008148054F8D4F914233D552
:100D10001E0105ED8280B716050037170500B717CD
:100D20000500938606C21307C7C1938787C1D1BF49
:100D3000B716050037170500B7170500938686C05C
:100D4000130747C0938707C06DBF331E1F0133765B
:100D5000DE0119E2850865BF411122C635B7E16899
:100D60009388086A01488147014781460146B705D3
:100D7000200689B5011106CEA307010089476393B8
:100D8000F502B7052035E1681307F1009388086A7A
:100D90000148814785460146313DF2400345F10057
:100DA00005618280B7052005F9BF011106CE22CC6E
:100DB00026CA2306B100AA84A306C1004D37E16804
:100DC0009388086A01487C00014789460146B78537
:100DD000200126850964F93B130414717D1419E47C
:100DE0000D45F2406244D2440561828085452685E6
:100DF0005137058965F50145EDB7011106CE22CCC5
:100E000026CA2E844AC8AA84328936C6893FB24788
:100E1000E16822869388086A01480147CA86B78537
:100E200080022685616479331304146A7D1411C429
:100E3000854526858137058975F9F2406244D2449B
:100E4000424905618280011106CE22CC26CA2EC6F7
:100E5000AA8431373246E1689388086A014881479D
:100E600001478146B705802026856164A1331304BC
:100E7000146A7D1411C485452685ED3D058975F9F3
:100E8000F2406244D24405618280B3C7A5008D8BD5
:100E9000B308C500B1E78D4763F4C7049377350005
:100EA0002A87B9EB13F6C8FFB306E64093070002A2
:100EB00063C8D706AE86BA876371C70203A8060067
:100EC0009107910623AE07FFE3EAC7FE9307F6FFFB
:100ED000998FF19B91073E97BE95636617018280BB
:100EE0002A87637E150383C7050005078505A30FC1
:100EF000F7FEE39AE8FE828083C605000507937734
:100F00003700A30FD7FE8505D1DF83C6050005078F
:100F100093773700A30FD7FE8505F9FF61B782806D
:100F2000411122C61304000283A3050083A24500D9
:100F300083AF850003AFC50083AE050103AE450155
:100F400003A3850103A8C501945113074702B30702
:100F5000E640232E77FC232057FE2322F7FF23248D
:100F6000E7FF2326D7FF2328C7FF232A67FE232C6A
:100F700007FF232ED7FE93854502E347F4FAAE869A
:100F8000BA876371C70203A806009107910623AED2
:100F900007FFE3EAC7FE9307F6FF998FF19B9107DE
:100FA0003E97BE956365170132444101828083C735
:100FB000050005078505A30FF7FEE387E8FE83C755
:100FC000050005078505A30FF7FEE392E8FEE9BFDC
:100FD00020000000010000000300000006000000E7
:100FE000EB00000000000000000000000000000016
:100FF000000000800000000000000700000000006A
:1010000000000000000000000000000000000000E0
:1009D0001C4B7D761306F63FF18FD58F1CCB232C55
:1009E000070085471CCF411102C613073006B247E6
:1009F0006359F70001454101828085669386068030
:100A00006DBFB24785073EC6DDB711C98547630D87
:100A1000F50205458280FD1791EB0D458280094660
:100A2000B7A7070093870712B7060500985E718F76
:100A30007DD34111C8D602C613073006B2476357AB
:100A4000F7000145410182800546D9BFB2478507BD
:100A50003EC6EDB7011126CAB7040600DC4806CE33
:100A600022CC4AC84EC652C456C2F19BDCC89C4830
:100A70002A89C845F19B9CC8D84883C7C5012E84E4
:100A8000137737C08A07D98FDCC883C7D501984848
:100A90009A071377F7C393F7073CD98F9CC8FD3BA0
:100AA0000C44AA8A03454400BD351848B707050021
:100AB0002A8A98C358480850D8C3184C98C7E935B3
:100AC000AA8948509937834704002A8793F617006C
:100AD00089E6D44893E62600D4C893F6270099E621
:100AE00037060600544A93E6160054CA93F64700A8
:100AF00099E637060600144A93E6260014CAA18B2D
:100B000099E7B70606009C4A93E717009CCAF24093
:100B10006244232059012322490123243901232639
:100B2000E900D244B249224A924A4A8542490561C3
:100B30008280011106CE22CC02C402C62147B7072B
:100B4000050037550800D8C705448D478A85130529
:100B500005803EC022C2292A375508009307C003EA
:100B60008A851305058022C222C43EC01122F240AC
:100B7000624405618280411122C406C62A84553F21
:100B800018405C4F93E707015CCF1C441CCB5C40D2
:100B900085CB1C43B7061000D58F1CC3144C5C4892
:100BA000B240D606CE07D58F83460401C206D58F44
:100BB0008346C4012244E206D58F1CCF41018280C6
:100BC0001C43B706F0FFFD16F58FC1BF03230500D8
:100BD0002A8E0325C30113650502232EA3002324B7
:100BE000C3001396260149824D8E2326030123223A
:100BF000C300139605016354060299C20545B1CBA3
:100C000001476346D700639C08020D458280338606
:100C1000E700034606000507230AC300DDB799C2B3
:100C2000054505CB8147E3D0D7FE03260E000345DB
:100C300046013306F70085072300A600EDB783279A
:100C40000E00FD18DC4F93F70702D5DF11656D8D9F
:100C500011E18280B707070083C7470113F58500BC
:100C60001D8D3335A00082801C414147D8CF828042
:100C7000B7470800938707402A886304F508B757E9
:100C80000800938707806304F50A37470800630D5F
:100C9000E50A05458280331E1F013376DE0129C631
:100CA00083A3450088431393180033966F001346BF
:100CB000F6FF13F43300718D33146400418D88C343
:100CC000638B5302638C0302084303AEC500718D2E
:100CD000331E6E003365C50108C38842698E88459E
:100CE00033156500498E90C2850833D51E0145F540
:100CF0003244410182802326C801F9B72324C80168
:100D0000E1B7B716050037170500B717050093863A
:100D100046C1130707C19387C7C083AE050081484A
:100D2000054F8D4F914233D51E0105ED8280B716D8
:100D3000050037170500B7170500938606C213078D
:100D4000C7C1938787C1D1BFB71605003717050004
:100D5000B7170500938686C0130747C0938707C05F
:100D60006DBF331E1F013376DE0119E2850865BFB2
:100D7000411122C635B7E1689388086A0148814766
:100D8000014781460146B705200689B5011106CE07
:100D9000A307010089476393F502B7052035E16891
:100DA0001307F1009388086A014881478546014688
:100DB000313DF2400345F10005618280B705200511
:100DC000F9BF011106CE22CC26CA2306B100AA849F
:100DD000A306C1004D37E1689388086A01487C008A
:100DE000014789460146B785200126850964F93BFC
:100DF000130414717D1419E40D45F2406244D24489
:100E000005618280854526855137058965F501454F
:100E1000EDB7011106CE22CC26CA2E844AC8AA8478
:100E2000328936C6893FB247E16822869388086ACC
:100E300001480147CA86B7858002268561647933F7
:100E40001304146A7D1411C48545268581370589EC
:100E500075F9F2406244D244424905618280011131
:100E600006CE22CC26CA2EC6AA8431373246E16885
:100E70009388086A0148814701478146B705802069
:100E800026856164A1331304146A7D1411C4854559
:100E90002685ED3D058975F9F2406244D24405612D
:100EA0008280B3C7A5008D8BB308C500B1E78D471D
:100EB00063F4C704937735002A87B9EB13F6C8FFAC
:100EC000B306E6409307000263C8D706AE86BA872A
:100ED0006371C70203A806009107910623AE07FFBE
:100EE000E3EAC7FE9307F6FF998FF19B91073E97C0
:100EF000BE956366170182802A87637E150383C7C8
:100F0000050005078505A30FF7FEE39AE8FE82803A
:100F100083C60500050793773700A30FD7FE850525
:100F2000D1DF83C60500050793773700A30FD7FEEF
:100F30008505F9FF61B78280411122C613040002C2
:100F400083A3050083A2450083AF850003AFC500DE
:100F500083AE050103AE450103A3850103A8C501C6
:100F6000945113074702B307E640232E77FC232052
:100F700057FE2322F7FF2324E7FF2326D7FF23284A
:100F8000C7FF232A67FE232C07FF232ED7FE938556
:100F90004502E347F4FAAE86BA876371C70203A835
:100FA00006009107910623AE07FFE3EAC7FE930709
:100FB000F6FF998FF19B91073E97BE9563651701E8
:100FC00032444101828083C7050005078505A30FD0
:100FD000F7FEE387E8FE83C7050005078505A30F35
:100FE000F7FEE392E8FEE9BF2000000001000000E8
:100FF0000300000006000000EB00000000000000FD
:101000000000008000000000000007000000000059
:1010100000000000000000000000000000000000D0
:1010200000000000000000000000000000000000C0
:0400000501000000F6
:00000001FF

View File

@ -8,10 +8,13 @@
#include "wiring_LL.h"
// HardwareSerial class objects for use in Arduino IDE
HardwareSerial Serial(0);
HardwareSerial Serial0(0);
#if SERIAL_PORT_QTY > 1
HardwareSerial Serial1(1);
#endif
// default interface
HardwareSerial& Serial = DEFAULT_SERIAL;
void serialEvent() __attribute__((weak));
bool Serial0_available() __attribute__((weak));
@ -56,7 +59,7 @@ void HardwareSerial::begin(unsigned long baud, uint8_t config)
// leaving the data length selected as 8 bits
// stop bit // stop bit = 1 - everything is zero, don't set anything
if (((config >> 3) & 0x01) == 1) // stop bit = 2
if ((config >> 3) & (0x01 == 1)) // stop bit = 2
reg2config |= UART_CONTROL2_STOP_1_M;
// turn on the receiver and transmitter, apply the parsed config
@ -144,7 +147,7 @@ extern "C" void __attribute__((optimize("O3"))) serial_interrupt_handler(uint8_t
{
if (uartNumInt == 0)
{
Serial.rx_complete_irq();
Serial0.rx_complete_irq();
}
else if ((uartNumInt == 1) && (SERIAL_PORT_QTY > 1))
{

View File

@ -103,10 +103,12 @@ class HardwareSerial : public Stream
inline void rx_complete_irq(void) __attribute__((always_inline, optimize("O3")));
};
extern HardwareSerial Serial;
extern HardwareSerial Serial0;
#if SERIAL_PORT_QTY > 1
extern HardwareSerial Serial1;
#endif
// default interface
extern HardwareSerial& Serial;
extern void serialEventRun(void) __attribute__((weak));

View File

@ -45,7 +45,7 @@ static void Timer16_Init(uint8_t prescaler)
htimer16_1.Trigger.TimeOut = TIMER16_TIMEOUT_DISABLE;
htimer16_1.Filter.ExternalClock = TIMER16_FILTER_NONE;
htimer16_1.Filter.Trigger = TIMER16_FILTER_NONE;
htimer16_1.Waveform.Enable = TIMER16_WAVEFORM_GENERATION_ENABLE;
htimer16_1.Waveform.Enable = TIMER16_WAVEFORM_GENERATION_DISABLE;
htimer16_1.Waveform.Polarity = TIMER16_WAVEFORM_POLARITY_NONINVERTED;
htimer16_1.EncoderMode = TIMER16_ENCODER_DISABLE;
HAL_Timer16_Init(&htimer16_1);
@ -79,6 +79,12 @@ static void calcFrequencyParams(FrequencyParams_t* params, unsigned int newFrequ
// start tone with frequency (in hertz) and duration (in milliseconds)
void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
{
if ((pin>=pinCommonQty()))
{
ErrorMsgHandler("tone(): pin number exceeds the total number of pins");
return;
}
if (!timerIsOn) // if tone is not generated at the moment
{
// calculate the parameters necessary to ensure a given frequency if the frequency has changed
@ -123,6 +129,12 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
// stop tone
void noTone(uint8_t pin)
{
if ((pin>=pinCommonQty()))
{
ErrorMsgHandler("noTone(): pin number exceeds the total number of pins");
return;
}
if (timerIsOn)
{
// pin to 0

View File

@ -6,6 +6,9 @@
#include "WInterrupts.h"
#include "wiring_LL.h"
// interrupts are enabled by default after setup()
static bool intIsEnabled = true;
typedef void (*voidFuncPtr)(void);
// empty irq handler
@ -18,33 +21,39 @@ static void nothing(void)
void interrupts(void)
{
GLOBAL_IRQ_ENABLE();
intIsEnabled = true;
}
// disable global interrupts
void noInterrupts(void)
{
GLOBAL_IRQ_DISABLE();
intIsEnabled = false;
}
// we can provide no more than 8 interrupts on gpio at the same time
static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] =
bool isInterruptsEnabled(void)
{
#if EXTERNAL_NUM_INTERRUPTS > 7
return intIsEnabled;
}
// we can provide no more than 8 interrupts on gpio at the same time
static volatile voidFuncPtr intFunc[EXTERNAL_INTERRUPTS_QTY] =
{
#if EXTERNAL_INTERRUPTS_QTY > 7
nothing,
#endif
#if EXTERNAL_NUM_INTERRUPTS > 6
#if EXTERNAL_INTERRUPTS_QTY > 6
nothing,
#endif
#if EXTERNAL_NUM_INTERRUPTS > 5
#if EXTERNAL_INTERRUPTS_QTY > 5
nothing,
#endif
#if EXTERNAL_NUM_INTERRUPTS > 4
#if EXTERNAL_INTERRUPTS_QTY > 4
nothing,
#endif
#if EXTERNAL_NUM_INTERRUPTS > 3
#if EXTERNAL_INTERRUPTS_QTY > 3
nothing,
#endif
#if EXTERNAL_NUM_INTERRUPTS > 2
#if EXTERNAL_INTERRUPTS_QTY > 2
nothing,
#endif
nothing,
@ -54,7 +63,7 @@ static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] =
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)
{
// if the interrupt number does not exceed the total number
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
if(interruptNum < EXTERNAL_INTERRUPTS_QTY)
{
intFunc[interruptNum] = userFunc; // save pointer to irq handler
@ -85,7 +94,7 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)
void detachInterrupt(uint8_t interruptNum)
{
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
if(interruptNum < EXTERNAL_INTERRUPTS_QTY)
{
// disable the interrupt in line
HAL_GPIO_DeInitInterruptLine(interruptToGpioIntLine(interruptNum));
@ -98,7 +107,7 @@ void detachInterrupt(uint8_t interruptNum)
// disable single interrupt
void disableInterrupt(uint8_t interruptNum)
{
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
if(interruptNum < EXTERNAL_INTERRUPTS_QTY)
// disable gpio interrupt line
GPIO_IRQ_LINE_DISABLE(interruptToGpioIntLine(interruptNum));
}
@ -106,7 +115,7 @@ void disableInterrupt(uint8_t interruptNum)
// enable single interrupt
void enableInterrupt(uint8_t interruptNum)
{
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
if(interruptNum < EXTERNAL_INTERRUPTS_QTY)
// enable gpio interrupt line
GPIO_IRQ_LINE_ENABLE(interruptToGpioIntLine(interruptNum));
}
@ -115,7 +124,7 @@ void enableInterrupt(uint8_t interruptNum)
void __attribute__((noinline, section(".ram_text"), optimize("O3"))) gpio_interrupt_handler(void)
{
// go through all the interrupts and call the handler for the triggered line
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
for (uint8_t i = 0; i < EXTERNAL_INTERRUPTS_QTY; i++)
{
if (GPIO_IRQ_LINE_STATE(interruptToGpioIntLine(i)))
intFunc[i]();

View File

@ -6,10 +6,12 @@ extern "C" {
#endif
#include <stdint.h>
#include "stdbool.h"
// enable/disable interrupts
void interrupts(void);
void noInterrupts(void);
bool isInterruptsEnabled(void);
// attach/detach interrupt to pin
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode);

View File

@ -3,9 +3,43 @@
#include "mik32_hal_irq.h"
#include "Arduino.h"
// --------------------- flash cache limit --------------------- //
#include "mcu32_memory_map.h"
#include "mik32_hal_spifi_w25.h"
// define board flash size
#if defined(ARDUINO_START_MIK32_V1)
#define FLASH_SIZE 0x00400000 // 4 Mb
#elif defined(ARDUINO_ACE_UNO_16MB)
#define FLASH_SIZE 0x01000000 // 16 Mb
#elif defined(ARDUINO_ACE_UNO_32MB)
#define FLASH_SIZE 0x02000000 // 32 Mb
#else
#define FLASH_SIZE 0x00800000 // 8 Mb
#endif
// define margin from flash end
#define FLASH_END_OFFSET 0x1000
// values from ld script
extern uint8_t __RODATA__[];
// RAM-function for updating flash cache limit by app size to improve performance
__attribute__((section(".ram_text"))) void updateCacheLimit(void)
{
uint32_t new_limit = (uintptr_t)__RODATA__ - SPIFI_BASE_ADDRESS;
// limit cache size by flash size with margin
if (new_limit > (FLASH_SIZE - FLASH_END_OFFSET))
new_limit = FLASH_SIZE - FLASH_END_OFFSET;
uint32_t MCMDbackup = SPIFI_CONFIG->MCMD; // save current value from MCMD
SPIFI_CONFIG->STAT |= SPIFI_CONFIG_STAT_RESET_M; // reset MCMD mode for writing new CLIMIT
SPIFI_CONFIG->CLIMIT = new_limit; // set new CLIMIT
SPIFI_CONFIG->MCMD = MCMDbackup; // restore MCMD value
}
// --------------------- init --------------------- //
// called before setup()
void pre_init(void)
// called from crt0.S before constructors initialization
extern "C" void SystemInit(void)
{
// set irq vector to ram region
write_csr(mtvec, 0x02000000);
@ -20,13 +54,15 @@ void pre_init(void)
// for delays
SysTick_Init();
// update flash cache limit by app size
updateCacheLimit();
}
// called after setup()
void post_init(void)
{
// enable global interrupts by default
interrupts();
if(isInterruptsEnabled()) // if user has called noInterrupts() in setup(), this value is false
interrupts(); // enable global interrupts
}
// --------------------- other --------------------- //

View File

@ -5,8 +5,7 @@ extern volatile bool use_error_messages;
#define DISABLE_ERROR_MESSAGES() (use_error_messages = false)
#define ENABLE_ERROR_MESSAGES() (use_error_messages = true)
// functions for init called before and after setup()
void pre_init(void) ;
// function for init called after setup()
void post_init(void);
#endif /* _BOARD_H_ */

View File

@ -2,9 +2,15 @@
#include "Arduino.h"
// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }
extern "C" int main(void) __attribute__((weak));
int main()
{
pre_init();
initVariant(); // for freeRTOS
setup();
post_init();
@ -12,6 +18,4 @@ int main()
{
loop();
}
}
}

View File

@ -36,6 +36,7 @@ extern "C" {
*/
typedef enum __HAL_PinsTypeDef
{
NOT_A_PIN = (0 << 0), /**< Не выбран пин. */
GPIO_PIN_0 = (1 << 0), /**< Выбран пин 0. */
GPIO_PIN_1 = (1 << 1), /**< Выбран пин 1. */
GPIO_PIN_2 = (1 << 2), /**< Выбран пин 2. */

View File

@ -144,8 +144,8 @@ typedef enum __HAL_Timer16_EncoderTypeDef
*/
typedef enum __HAL_Timer16_WaveformGenTypeDef
{
TIMER16_WAVEFORM_GENERATION_ENABLE = 0, /**< Выключить генерацию волновой формы. */
TIMER16_WAVEFORM_GENERATION_DISABLE = 1 /**< Включить генерацию волновой формы. */
TIMER16_WAVEFORM_GENERATION_ENABLE = 0, /**< Включить генерацию волновой формы. */
TIMER16_WAVEFORM_GENERATION_DISABLE = 1 /**< Выключить генерацию волновой формы. */
} HAL_Timer16_WaveformGenTypeDef;
/**

View File

@ -105,7 +105,7 @@ typedef enum __HAL_TSENS_ClockTypeDef
/**
* @brief Определение структуры TSENS Handle.
*/
typedef struct __SPI_HandleTypeDef
typedef struct __TSENS_HandleTypeDef
{
ANALOG_REG_TypeDef *Instance; /**< Адрес регистров блока управления аналоговой подсистемой. */
@ -119,7 +119,7 @@ typedef struct __SPI_HandleTypeDef
/**
* @brief Возвращаемая структура для функции @ref HAL_TSENS_SingleStart.
*/
typedef struct __WDT_ClockTypeDef
typedef struct __TSENS_ValueTypeDef
{
HAL_StatusTypeDef statusHAL; /**< Статус HAL. */

View File

@ -105,7 +105,7 @@ typedef struct __WDT_ClockTypeDef
} WDT_ClockTypeDef;
void HAL_RTC_MspInit(WDT_HandleTypeDef* hwdt);
void HAL_WDT_MspInit(WDT_HandleTypeDef* hwdt);
HAL_StatusTypeDef HAL_WDT_Init(WDT_HandleTypeDef *hwdt, uint32_t timeout);
HAL_StatusTypeDef HAL_WDT_Refresh(WDT_HandleTypeDef *hwdt, uint32_t timeout);
HAL_StatusTypeDef HAL_WDT_Start(WDT_HandleTypeDef *hwdt, uint32_t timeout);

View File

@ -3,14 +3,56 @@
uint16_t TimeOut = 20;
uint16_t WDT_prescale[] = {1, 2, 4, 16, 64, 256, 1024, 4096};
/**
* @brief Запись слова в регистр CON (конфигурация WDT)
* @param hwdt указатель на структуру WDT_HandleTypeDef, которая содержит
* информацию о конфигурации для модуля WDT.
* @param conValue 32-х битное слово
*/
static void __attribute__( ( noinline, section(".ram_text") ) ) HAL_WDT_Write_Word_To_CON(WDT_HandleTypeDef* hwdt, uint32_t conValue)
{
//Если позволить компилятору inlining, станет невозможно выделить функцию в отдельную секцию.
intptr_t ptr = (intptr_t)(hwdt->Instance);
/**
* Попытки избежать использования отдельной переменной-указателя, такие как:
* "sb a0,0x9C(%a0)\n\t"
* : "m" (*(hwdt->Instance))
* не работают из-за бага GCC (internal compiler error <...> riscv_print_operand_address)
* */
asm volatile(
"li a0,0x1E\n\t" //Store unlock byte somewhere
"sb a0,0x9C(%0)\n\t" //Write UNLOCK byte into WDT KEY register
"sw %1,0x84(%0)\n\t" //Write payload
:
: "r" (ptr), "r" (conValue)
: "a0"
);
}
/**
* @brief Запись байта в регистр KEY (пуск/остановка WDT)
* @param hwdt указатель на структуру WDT_HandleTypeDef, которая содержит
* информацию о конфигурации для модуля WDT.
* @param key байт для записи ( @ref WDT_KEY_START или @ref WDT_KEY_STOP )
*/
static void __attribute__( ( noinline, section(".ram_text") ) ) HAL_WDT_Write_Byte_To_KEY(WDT_HandleTypeDef* hwdt, uint8_t key)
{
intptr_t ptr = (intptr_t)(hwdt->Instance);
asm volatile(
"li a0,0x1E\n\t" //Store unlock byte somewhere
"sb a0,0x9C(%0)\n\t" //Write UNLOCK byte into WDT KEY register
"sb %1,0x9C(%0)\n\t" //Write payload
:
: "r" (ptr), "r" (key)
: "a0"
);
}
/**
* @brief Инициализация WDT MSP.
* @param hwdt указатель на структуру WDT_HandleTypeDef, которая содержит
* информацию о конфигурации для модуля WDT.
*
* информацию о конфигурации для модуля WDT.
*/
__attribute__((weak)) void HAL_RTC_MspInit(WDT_HandleTypeDef *hwdt)
__attribute__((weak)) void HAL_WDT_MspInit(WDT_HandleTypeDef *hwdt)
{
__HAL_PCC_WDT_CLK_ENABLE();
}
@ -82,7 +124,7 @@ HAL_StatusTypeDef HAL_WDT_Init(WDT_HandleTypeDef *hwdt, uint32_t timeout)
return HAL_ERROR;
}
HAL_RTC_MspInit(hwdt);
HAL_WDT_MspInit(hwdt);
if (HAL_WDT_Stop(hwdt, timeout) != HAL_OK)
@ -100,8 +142,7 @@ HAL_StatusTypeDef HAL_WDT_Init(WDT_HandleTypeDef *hwdt, uint32_t timeout)
}
uint32_t conValue = (wdtClock.divIndex << WDT_CON_PRESCALE_S) | WDT_CON_PRELOAD(wdtClock.tick);
hwdt->Instance->KEY = WDT_KEY_UNLOCK;
hwdt->Instance->CON = conValue;
HAL_WDT_Write_Word_To_CON(hwdt, conValue);
return HAL_OK;
}
@ -115,8 +156,7 @@ HAL_StatusTypeDef HAL_WDT_Init(WDT_HandleTypeDef *hwdt, uint32_t timeout)
*/
HAL_StatusTypeDef HAL_WDT_Refresh(WDT_HandleTypeDef *hwdt, uint32_t timeout)
{
hwdt->Instance->KEY = WDT_KEY_UNLOCK;
hwdt->Instance->KEY = WDT_KEY_START;
HAL_WDT_Write_Byte_To_KEY(hwdt, WDT_KEY_START);
while (timeout--)
{
@ -139,8 +179,7 @@ HAL_StatusTypeDef HAL_WDT_Refresh(WDT_HandleTypeDef *hwdt, uint32_t timeout)
*/
HAL_StatusTypeDef HAL_WDT_Start(WDT_HandleTypeDef *hwdt, uint32_t timeout)
{
hwdt->Instance->KEY = WDT_KEY_UNLOCK;
hwdt->Instance->KEY = WDT_KEY_START;
HAL_WDT_Write_Byte_To_KEY(hwdt, WDT_KEY_START);
while (timeout--)
{
@ -162,8 +201,7 @@ HAL_StatusTypeDef HAL_WDT_Start(WDT_HandleTypeDef *hwdt, uint32_t timeout)
*/
HAL_StatusTypeDef HAL_WDT_Stop(WDT_HandleTypeDef *hwdt, uint32_t timeout)
{
hwdt->Instance->KEY = WDT_KEY_UNLOCK;
hwdt->Instance->KEY = WDT_KEY_STOP;
HAL_WDT_Write_Byte_To_KEY(hwdt, WDT_KEY_STOP);
while (timeout--)
{
@ -185,8 +223,7 @@ HAL_StatusTypeDef HAL_WDT_Stop(WDT_HandleTypeDef *hwdt, uint32_t timeout)
void HAL_WDT_SetPrescale(WDT_HandleTypeDef *hwdt, HAL_WDT_Prescale prescale)
{
uint32_t conValue = (hwdt->Instance->CON & (~WDT_CON_PRESCALE_M)) | ((prescale << WDT_CON_PRESCALE_S) & WDT_CON_PRESCALE_M);
hwdt->Instance->KEY = WDT_KEY_UNLOCK;
hwdt->Instance->CON = conValue;
HAL_WDT_Write_Word_To_CON(hwdt, conValue);
}
/**
@ -198,6 +235,5 @@ void HAL_WDT_SetPrescale(WDT_HandleTypeDef *hwdt, HAL_WDT_Prescale prescale)
void HAL_WDT_SetPreload(WDT_HandleTypeDef *hwdt, HAL_WDT_Prescale preload)
{
uint32_t conValue = (hwdt->Instance->CON & (~WDT_CON_PRELOAD_M)) | WDT_CON_PRELOAD(preload);
hwdt->Instance->KEY = WDT_KEY_UNLOCK;
hwdt->Instance->CON = conValue;
HAL_WDT_Write_Word_To_CON(hwdt, conValue);
}

View File

@ -21,11 +21,10 @@ SECTIONS {
*crt0.S.o(.text .text.*)
*(.text.smallsysteminit)
*(.text.SmallSystemInit)
/*. = ORIGIN(rom) + 0xC0;*/
/*KEEP(*crt0.S.o(.trap_text))*/
*(.text)
*(.text.*)
PROVIDE(__RODATA__ = .);
*(.rodata)
*(.rodata.*)
. = ALIGN(CL_SIZE);
@ -123,6 +122,7 @@ SECTIONS {
PROVIDE(__STACK_START__ = .);
. += STACK_SIZE;
PROVIDE(__C_STACK_TOP__ = .);
PROVIDE(__freertos_irq_stack_top = .);
PROVIDE(__STACK_END__ = .);
} >ram

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,73 @@
#include "mik32_hal_irq.h"
#include "wiring_LL.h"
#include "mik32_hal_irq.h"
#include "wiring_LL.h"
// isr functions
extern void serial_interrupt_handler(uint8_t uartNumInt);
extern void gpio_interrupt_handler(void);
extern void tone_interrupt_handler(void);
void __attribute__((weak)) wire_interrupt_handler(void)
void __attribute__((weak)) wire_interrupt_handler(uint8_t num)
{
// dummy function for case when wire library is not in use
}
void __attribute__((weak)) servo_interrupt_handler(void)
{
// dummy function for case when wire library is not in use
// dummy function for case when servo library is not in use
}
void __attribute__((weak)) IRremote_interrupt_handler(void)
{
// dummy function for case when IRremote library is not in use
}
bool __attribute__((section(".ram_text"), weak)) ISR(void)
{
/*
A dummy function for the case when additional interrupts are not used in the project.
In the project, you need to create a function of the form:
extern "C" __attribute__((section(".ram_text"))) bool ISR(void)
{
if (EPIC_CHECK_TIMER16_1())
{
// timer16 is taken as an example
if (TIM16_GET_ARRM_INT_STATUS(htimer16_1_))
{
// necessary actions
}
// reset timer interrupt flags
TIM16_CLEAR_INT_MASK(htimer16_1_, 0xFFFFFFFF);
}
return false;
}
If you don't need to call standard trap_handler() code, you can return true from this function
and trap_handler() code will be missed. But you must carefully clear interrupt flags by yourself
in your custom ISR() function.
libraries required to use this example:
#include "mik32_hal_timer16.h"
#include "wiring_LL.h"
*/
return false;
}
// ---------------------------------------------- //
void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handler (void)
{
// custom interrupt
if(ISR())
{
// reset all interrupts and miss trap_handler() code
EPIC_CLEAR_ALL();
return;
}
// gpio interrupt
if (EPIC_CHECK_GPIO_IRQ())
gpio_interrupt_handler();
// IRremote timer interrupt
if (EPIC_CHECK_TIMER16_0())
IRremote_interrupt_handler();
// tone timer interrupt
if (EPIC_CHECK_TIMER16_1())
tone_interrupt_handler();
@ -36,10 +83,14 @@ void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handle
// uart1 interrupt
if (EPIC_CHECK_UART_1())
serial_interrupt_handler(1);
// i2c interrupt
// i2c0 interrupt
if (EPIC_CHECK_I2C_0())
wire_interrupt_handler(0);
// i2c1 interrupt
if (EPIC_CHECK_I2C_1())
wire_interrupt_handler();
wire_interrupt_handler(1);
// reset all interrupts
EPIC_CLEAR_ALL();

View File

@ -5,6 +5,7 @@
#include "mik32_hal_gpio.h"
#include "mik32_hal_scr1_timer.h"
#include "mik32_hal_timer16.h"
#include "pad_config.h"
// ----------------- COMMON ----------------- //
// convert pin mask from HAL_PinsTypeDef to pin number
@ -32,6 +33,7 @@
#define TIM16_DISABLE_INT_BY_MASK(htim16,intMask) (htim16.Instance->IER &= ~(intMask))
// ----------------- EPIC ----------------- //
#define EPIC_LEVEL_SET_BY_MASK(mask) (EPIC->MASK_LEVEL_SET |= mask)
#define EPIC_LEVEL_CLEAR_BY_MASK(mask) (EPIC->MASK_LEVEL_CLEAR |= mask)
#define EPIC_CLEAR_ALL() (EPIC->CLEAR = 0xFFFFFFFF)
@ -41,6 +43,8 @@
set_csr(mie, MIE_MEIE)
// ----------------- GPIO ----------------- //
#define GPIO_INPUT_MODE_PIN(GPIO_x, pinMask) ((GPIO_x)->DIRECTION_IN = (pinMask))
#define GPIO_OUTPUT_MODE_PIN(GPIO_x, pinMask) ((GPIO_x)->DIRECTION_OUT = (pinMask))
#define GPIO_SET_PIN(GPIO_x, pinMask) ((GPIO_x)->SET = (pinMask))
#define GPIO_CLEAR_PIN(GPIO_x, pinMask) ((GPIO_x)->CLEAR = (pinMask))
#define GPIO_TOGGLE_PIN(GPIO_x, pinMask) ((GPIO_x)->OUTPUT_ ^= pinMask)
@ -58,8 +62,6 @@
// return config of pin with pinNumber(0...16) in portReg (config, pupd, ds for ports 0...2)
#define PIN_GET_PAD_CONFIG(portReg, pinNumber) ((PAD_CONFIG->portReg >> (pinNumber<<1)) & 0b11)
#define PIN_SET_PAD_CONFIG(portReg, pinNumber, value) (PAD_CONFIG->portReg = (PAD_CONFIG->portReg & (~PAD_CONFIG_PIN_M(pinNumber))) \
| PAD_CONFIG_PIN(pinNumber, value))
| PAD_CONFIG_PIN(pinNumber, value))
#endif /* _WIRING_LL_H_ */

View File

@ -42,18 +42,8 @@ uint32_t analogRead(uint32_t PinNumber)
uint32_t adcChannel = analogInputToChannelNumber(PinNumber);
if (adcChannel != NC)
{
// if we use pin A5, we need to set SELA45 (1.15) to 1 to switch the output from A4 to A5
if (PinNumber == A5)
{
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_15, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_HIGH);
}
else if(PinNumber == A4)
{
// return the switch to A4 in case A5 was previously read
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_15, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_LOW);
}
additionalPinsInit(PinNumber);
// init channel
hadc.Init.Sel = adcChannel;
HAL_ADC_Init(&hadc);
@ -83,6 +73,7 @@ uint32_t analogRead(uint32_t PinNumber)
// extra least significant bits read from the ADC are discarded
value = (value >> (MCU_ADC_RESOLUTION - currentResolution));
}
additionalPinsDeinit(PinNumber);
}
else
ErrorMsgHandler("analogRead(): invalid analog pin number");
@ -96,7 +87,6 @@ uint32_t analogRead(uint32_t PinNumber)
#define PWM_RESOLUTION_DEFAULT 8
#define WRITE_VAL_MAX_DEFAULT ((1<<PWM_RESOLUTION_DEFAULT) - 1)
#define PWM_TOP_VAL_DEFAULT 32000 // corresponds 1000 Hz
#define PWM_FREQUENCY_MAX 1000000 // Hz
static TIMER32_HandleTypeDef htimer32;
static TIMER32_CHANNEL_HandleTypeDef htimer32_channel;
@ -114,43 +104,64 @@ It is recommended to enable the timer in the following order:
*/
void analogWrite(uint32_t PinNumber, uint32_t writeVal)
{
if (digitalPinHasPWM(PinNumber))
if (writeVal >= WriteValMax)
{
if (writeVal > WriteValMax) writeVal = WriteValMax;
// initialization of the required timer
htimer32.Instance = pwmPinToTimer(PinNumber);
htimer32.Top = pwmTopVal;
htimer32.State = TIMER32_STATE_DISABLE;
htimer32.Clock.Source = TIMER32_SOURCE_PRESCALER;
htimer32.Clock.Prescaler = 0; // Prescaler = 1
htimer32.InterruptMask = 0;
htimer32.CountMode = TIMER32_COUNTMODE_FORWARD;
HAL_Timer32_Init(&htimer32);
// gpio init as timer channel pin
HAL_GPIO_PinConfig(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber),
HAL_GPIO_MODE_TIMER_SERIAL, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
htimer32_channel.TimerInstance = htimer32.Instance;
htimer32_channel.ChannelIndex = pwmPinToTimerChannel(PinNumber);
htimer32_channel.PWM_Invert = TIMER32_CHANNEL_NON_INVERTED_PWM;
htimer32_channel.Mode = TIMER32_CHANNEL_MODE_PWM;
htimer32_channel.CaptureEdge = TIMER32_CHANNEL_CAPTUREEDGE_RISING;
htimer32_channel.OCR = (uint32_t) (((uint64_t)pwmTopVal * writeVal) / WriteValMax);
htimer32_channel.Noise = TIMER32_CHANNEL_FILTER_OFF;
HAL_Timer32_Channel_Init(&htimer32_channel);
// start timer with initialized channel
HAL_Timer32_Channel_Enable(&htimer32_channel);
HAL_Timer32_Value_Clear(&htimer32);
HAL_Timer32_Start(&htimer32);
pwmIsInited++; // increase inited channels qty
// if we need max value, use digitalWrite to supply constant level
digitalWrite(PinNumber, HIGH);
}
else if(PinNumber == 10) // pin d10 has pwm, but you cannot use it while spi is running
ErrorMsgHandler("analogWrite(): D10 cannot be used as PWM pin while SPI is running");
else
ErrorMsgHandler("analogWrite(): invalid pwm pin number");
{
// if we need less then max, use pwm
int8_t pwmState = digitalPinPwmIsOn(PinNumber);
if (pwmState > 0) // pin has pwm and pwm is already on
{
// we can only change writeVal if it is differ from current value
TIMER32_TypeDef* timer = pwmPinToTimer(PinNumber);
uint32_t newOCR = (uint32_t) (((uint64_t)pwmTopVal * writeVal) / WriteValMax);
if (timer->CHANNELS[pwmPinToTimerChannel(PinNumber)].OCR != newOCR)
{
// if new ocr differs from current, set new ocr
timer->CHANNELS[pwmPinToTimerChannel(PinNumber)].OCR = newOCR;
}
}
else if (pwmState == 0) // pin has pwm and pwm is off
{
// init pin as pwm
uint32_t OCRval = (pwmTopVal * writeVal) / WriteValMax;
// initialization of the required timer
htimer32.Instance = pwmPinToTimer(PinNumber);
htimer32.Top = pwmTopVal;
htimer32.State = TIMER32_STATE_DISABLE;
htimer32.Clock.Source = TIMER32_SOURCE_PRESCALER;
htimer32.Clock.Prescaler = 0; // Prescaler = 1
htimer32.InterruptMask = 0;
htimer32.CountMode = TIMER32_COUNTMODE_FORWARD;
HAL_Timer32_Init(&htimer32);
// gpio init as timer channel pin
HAL_GPIO_PinConfig(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber),
HAL_GPIO_MODE_TIMER_SERIAL, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
htimer32_channel.TimerInstance = htimer32.Instance;
htimer32_channel.ChannelIndex = pwmPinToTimerChannel(PinNumber);
htimer32_channel.PWM_Invert = TIMER32_CHANNEL_NON_INVERTED_PWM;
htimer32_channel.Mode = TIMER32_CHANNEL_MODE_PWM;
htimer32_channel.CaptureEdge = TIMER32_CHANNEL_CAPTUREEDGE_RISING;
htimer32_channel.OCR = OCRval;
htimer32_channel.Noise = TIMER32_CHANNEL_FILTER_OFF;
HAL_Timer32_Channel_Init(&htimer32_channel);
// start timer with initialized channel
HAL_Timer32_Channel_Enable(&htimer32_channel);
HAL_Timer32_Value_Clear(&htimer32);
HAL_Timer32_Start(&htimer32);
pwmIsInited++; // increase inited channels qty
}
else // pin doesn't have pwm
ErrorMsgHandler("analogWrite(): invalid pwm pin number");
}
}
// Set the resolution of analogWrite parameters
@ -180,14 +191,17 @@ It is recommended to turn off the timer in the following order:
- Write 0 to the INT_CLEAR register;
- Set TIM_EN to 0.
*/
// use only if digitalPinPwmIsOn(PinNumber) > 0
void analogWriteStop(uint32_t PinNumber)
{
if ((pwmIsInited > 0) && (digitalPinPwmIsOn(PinNumber)))
if ((pwmIsInited > 0))
{
// load the timer address and channel number corresponding to the specified pin
htimer32.Instance = pwmPinToTimer(PinNumber);
htimer32_channel.TimerInstance = htimer32.Instance;
htimer32_channel.ChannelIndex = pwmPinToTimerChannel(PinNumber);
htimer32.Instance->CHANNELS[htimer32_channel.ChannelIndex].OCR = 0;
htimer32_channel.TimerInstance = htimer32.Instance;
// deinit channel
HAL_Timer32_Channel_DeInit(&htimer32_channel);
pwmIsInited--; // decrease inited channels qty

View File

@ -23,12 +23,14 @@
#include <stdint.h>
#include "wiring_private.h"
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2
#define NC 0xFFFFFFFF // Not connected
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2
#define INPUT_PULLDOWN 0x3
#define NC 0xFFFFFFFF // Not connected
#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
@ -56,25 +58,23 @@ enum BitOrder
#define NOT_AN_INTERRUPT -1
// Math
#ifdef __cplusplus
#include <algorithm>
using std::min;
using std::max;
#else // C
#include <stdlib.h>
#ifndef abs
#define abs(x) ((x)>0?(x):-(x))
#endif // abs
#include <stdlib.h>
// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif
#ifndef abs
#define abs(x) ((x)>0?(x):-(x))
#endif // abs
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif // min
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif // min
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif // max
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif // max
#endif // __cplusplus
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)

View File

@ -19,6 +19,7 @@
#include "Arduino.h"
#include "pins_arduino.h"
#include "mik32_hal_gpio.h"
#include "wiring_LL.h"
#ifdef __cplusplus
extern "C" {
@ -36,67 +37,69 @@ void pinMode(uint32_t PinNumber, uint32_t PinMode)
return;
}
if (digitalPinHasPWM(PinNumber))
// if the pin can use PWM, disable PWM
if (digitalPinPwmIsOn(PinNumber) > 0 )
// if the pin use PWM, disable PWM
analogWriteStop(PinNumber);
// adjusting pins
if (PinNumber == BTN_BUILTIN)
// determine the port and the pin number in the port
GPIO_TypeDef *GPIO_addr = digitalPinToPort(PinNumber);
GPIO_InitStruct.Pin = digitalPinToBitMask(PinNumber);
// set up direction and pull up/down
switch (PinMode)
{
// always set the button to input, otherwise the controller may burn out when pressed
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
HAL_GPIO_Init(GPIO_2, &GPIO_InitStruct);
case INPUT:
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
break;
case INPUT_PULLUP:
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_UP;
break;
case INPUT_PULLDOWN:
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_DOWN;
break;
case OUTPUT:
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
break;
}
else // other pins
// init pin
HAL_GPIO_Init(GPIO_addr, &GPIO_InitStruct);
additionalPinsInit(PinNumber);
}
void fastPinMode(uint32_t PinNumber, uint32_t PinMode)
{
if ((PinNumber>=pinCommonQty()))
{
// determine the port and the pin number in the port
GPIO_TypeDef *GPIO_addr = digitalPinToPort(PinNumber);
GPIO_InitStruct.Pin = digitalPinToBitMask(PinNumber);
// set up direction and pull up/down
switch (PinMode)
{
case INPUT:
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
break;
case INPUT_PULLUP:
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_UP;
break;
case OUTPUT:
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
break;
}
// init pin
HAL_GPIO_Init(GPIO_addr, &GPIO_InitStruct);
// if we use pin A5, we need to set SELA45 (1.15) to 1 to switch the output from A4 to A5
if (PinNumber == A5)
{
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
HAL_GPIO_Init(GPIO_1, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_HIGH);
}
else if(PinNumber == A4)
{
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_OUTPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
HAL_GPIO_Init(GPIO_1, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_LOW);
}
ErrorMsgHandler("fastPinMode(): pin number exceeds the total number of pins");
return;
}
GPIO_TypeDef* port = digitalPinToPort(PinNumber);
HAL_PinsTypeDef pinMask = digitalPinToBitMask(PinNumber);
// set direction
if (PinMode == OUTPUT)
GPIO_OUTPUT_MODE_PIN(port, pinMask);
else
GPIO_INPUT_MODE_PIN(port, pinMask);
// set pullup
if (PinMode == INPUT_PULLUP)
{
uint8_t pos = PIN_MASK_TO_PIN_NUMBER(pinMask);
if (port == GPIO_0) PIN_SET_PAD_CONFIG(PORT_0_PUPD, pos, HAL_GPIO_PULL_UP);
else if (port == GPIO_1) PIN_SET_PAD_CONFIG(PORT_1_PUPD, pos, HAL_GPIO_PULL_UP);
else PIN_SET_PAD_CONFIG(PORT_2_PUPD, pos, HAL_GPIO_PULL_UP);
}
}
// write pin
void digitalWrite(uint32_t PinNumber, uint32_t Val)
__attribute__((noinline, section(".ram_text"))) void digitalWrite(uint32_t PinNumber, uint32_t Val)
{
if ((PinNumber>=pinCommonQty()))
{
@ -104,48 +107,59 @@ void digitalWrite(uint32_t PinNumber, uint32_t Val)
return;
}
if (digitalPinHasPWM(PinNumber))
// if the pin can use PWM, disable PWM
GPIO_TypeDef* port = digitalPinToPort(PinNumber);
HAL_PinsTypeDef mask = digitalPinToBitMask(PinNumber);
if (digitalPinPwmIsOn(PinNumber) > 0)
{
// if the pin use PWM, disable PWM
analogWriteStop(PinNumber);
// just in case let's move on to the hal library state terms
GPIO_PinState pinState = (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW;
if (PinNumber != BTN_BUILTIN) // don't write anything to the button
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), pinState);
// and configure pin as output
HAL_GPIO_PinConfig(port, mask, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
}
if (Val == HIGH)
GPIO_SET_PIN(port, mask);
else
GPIO_CLEAR_PIN(port, mask);
}
// read pin
int digitalRead(uint32_t PinNumber)
__attribute__((noinline, section(".ram_text"))) int digitalRead(uint32_t PinNumber)
{
if ((PinNumber>=pinCommonQty()))
{
ErrorMsgHandler("digitalRead(): pin number exceeds the total number of pins");
return -1;
}
if (digitalPinHasPWM(PinNumber))
// if the pin can use PWM, disable PWM
analogWriteStop(PinNumber);
GPIO_PinState pinState = HAL_GPIO_ReadPin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
int state = (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
return state;
if (digitalPinPwmIsOn(PinNumber) > 0)
// if the pin use PWM, disable PWM
analogWriteStop(PinNumber); // pin is configured as input here
return GPIO_READ_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
}
// toggle pin
void digitalToggle(uint32_t PinNumber)
__attribute__((noinline, section(".ram_text"))) void digitalToggle(uint32_t PinNumber)
{
if ((PinNumber>=pinCommonQty()))
{
ErrorMsgHandler("digitalToggle(): pin number exceeds the total number of pins");
return;
}
if (digitalPinHasPWM(PinNumber))
// if the pin can use PWM, disable PWM
GPIO_TypeDef* port = digitalPinToPort(PinNumber);
HAL_PinsTypeDef mask = digitalPinToBitMask(PinNumber);
if (digitalPinPwmIsOn(PinNumber) > 0)
{
// if the pin use PWM, disable PWM
analogWriteStop(PinNumber);
if (PinNumber != BTN_BUILTIN) // don't write anything to the button
HAL_GPIO_TogglePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
// and configure pin as output
HAL_GPIO_PinConfig(port, mask, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
}
GPIO_TOGGLE_PIN(port, mask);
}
#ifdef __cplusplus

View File

@ -26,26 +26,35 @@ extern "C" {
/**
* \brief Configures the specified pin to behave either as an input or an output.
*
* \param dwPin The number of the pin whose mode you wish to set
* \param dwMode Either INPUT, INPUT_PULLUP or OUTPUT
* \param PinNumber The number of the pin whose mode you wish to set
* \param PinMode Either INPUT, INPUT_PULLUP or OUTPUT
*/
void pinMode(uint32_t PinNumber, uint32_t PinMode);
/**
* \brief Configures the specified pin to behave either as an input or an output
* using quick macros and without calling checks
*
* \param PinNumber The number of the pin whose mode you wish to set
* \param PinMode Either INPUT, INPUT_PULLUP or OUTPUT
*/
void fastPinMode(uint32_t PinNumber, uint32_t PinMode);
/**
* \brief Write a HIGH or a LOW value to a digital pin.
*
* If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the
* corresponding value: 3.3V for HIGH, 0V (ground) for LOW.
*
* \param dwPin the pin number
* \param dwVal HIGH or LOW
* \param PinNumber the pin number
* \param PinMode HIGH or LOW
*/
void digitalWrite(uint32_t PinNumber, uint32_t Val);
/**
* \brief Reads the value from a specified digital pin, either HIGH or LOW.
*
* \param ulPin The number of the digital pin you want to read (int)
* \param PinNumber The number of the digital pin you want to read (int)
*
* \return HIGH or LOW
*/
@ -54,7 +63,7 @@ int digitalRead(uint32_t PinNumber);
/**
* \brief Toggle the value from a specified digital pin.
*
* \param ulPin The number of the digital pin you want to toggle (int)
* \param PinNumber The number of the digital pin you want to toggle (int)
*/
void digitalToggle(uint32_t PinNumber);

View File

@ -11,7 +11,7 @@ extern "C"{
#endif
// available interrupts number
#define EXTERNAL_NUM_INTERRUPTS 7
#define EXTERNAL_NUM_INTERRUPTS EXTERNAL_INTERRUPTS_QTY
typedef void (*voidFuncPtr)(void);

View File

@ -13,7 +13,7 @@ unsigned long pulseIn(int pin, int state, unsigned long timeout)
ErrorMsgHandler("pulseIn(): pin number exceeds the total number of pins");
return -1;
}
if (digitalPinHasPWM(pin))
if (digitalPinPwmIsOn(pin) > 0)
// pwm off
analogWriteStop(pin);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

BIN
docs/Bootloader_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

BIN
docs/Build_project_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

@ -0,0 +1,68 @@
# ELBEAR ACE-UNO
Особенности работы с платами ELBEAR ACE-UNO в среде программирования ArduinoIDE.
### Функциональное назначение выводов
![Pinout](pinout_uno.png)
### Цифровые выводы
На плате ELBEAR ACE-UNO доступны встроенные светодиод и кнопка. Для их использования необходимо воспользоваться макросами `LED_BUILTIN` и `BTN_BUILTIN`, передавая их в качестве аргументов функции вместо номера цифрового вывода. Макросу `LED_BUILTIN` соответствует номер вывода D22, а макросу `BTN_BUILTIN` - D23.
### Аналоговые выводы
Аналоговые выводы на плате могут использоваться как в аналоговом, так и в цифровом режиме.
Для использования вывода в качестве аналогового необходимо перевести соответствующий DIP-переключатель, расположенный рядом с аналоговыми выводами, в положение OFF. В этом режиме внешнее напряжение, подаваемое на вывод, будет понижаться резистивным делителем перед подачей на микроконтроллер.
Для использования вывода в качестве цифрового нужно перевести переключатель в положение ON. В этом случае напряжение с вывода платы передается на микроконтроллер без изменений. Вывод А5 недоступен для использования в качестве цифрового вывода.
Для аналоговых выводов режим цифрового вывода с подтяжкой к питанию(`INPUT_PULLUP`) не дает желаемого результата, так как на этих сигналах установлена неотключаемая подтяжка к земеле (10 кОм), а подтяжка к питанию внутри микроконтроллера осуществляется резистором 50 кОм. Для реализации такого режима на аналоговых выводах необходимо использовать внешний дополнительный резистор 1...2 кОм, подключенный к питанию.
Таблица соответствия выводов платы и номера DIP-переключателя представлена ниже. Переключатель 5 относится сразу к двум аналоговым выводам - А4, А5.
|Вывод|Номер переключателя|
|---------|---------|
|А0|1|
|А1|2|
|А2|3|
|А3|4|
|А4|5|
|А5|5|
#### ШИМ
На плате ELBEAR ACE-UNO доступно 8 выводов для формирования ШИМ-сигнала. Генерация сигнала осуществляется с помощью 32-битного таймера. Выводы, подключенные к одному и тому же таймеру, выдают ШИМ-сигнал одинаковой частоты.
Доступные выводы:
|Цифровой вывод|Используемый таймер|
|---------|---------|
|D3|таймер 1|
|D5|таймер 1|
|D6|таймер 1|
|D9|таймер 1|
|D10|таймер 2|
|D11|таймер 2|
|D12|таймер 2|
|D13|таймер 2|
Цифровые выводы D9, D10 не могут быть использованы для генерации ШИМ, если одновременно активен интерфейс SPI (при использовании экземпляра `SPI` недоступен ШИМ на выводе D10, при использовании экземпляра `SPI0` - на выводе D9). Это ограничение связано с особенностями работы микроконтроллера. Ограничение не распространяется на использование D9, D10 в качестве цифрового вывода при активном SPI.
### Прерывания
На плате ELBEAR ACE-UNO доступно 8 прерываний, настраиваемых функцией `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`:
|Цифровой вывод|Номер прерывания|
|---------|---------|
|D2|0|
|D3|1|
|D4|2|
|D5|3|
|D8|4|
|D9|5|
|A1|6|
|`BTN_BUILTIN`|7|
При использовании аналогового вывода A1 для работы с прерываниями необходимо предварительно перевести вывод в режим цифрового. Для этого нужно перевести DIP-переключатель номер 2 в положение ON.
### Serial
Интерфейс UART0 доступен на выводах D0, D1, для работы с ним используется экземпляр класса под названием `Serial`.
Интерфейс UART1 доступен на выводах D7, D8, используемый экземпляр класса - `Serial1`.
### SPI
Интерфейс SPI1 доступен на выводах D11, D12, D13. Для работы с ним используется экземпляр класса под названием `SPI`.
Интерфейс SPI0 доступен на выводах D3, D5, D6. Используемый экземпляр класса - `SPI0`.
### I2C
Интерфейс I2C1 доступен на выводах SDA и SCL, для работы с ним используется экземпляр класса под названием `Wire`.
## Драйверы
Для работы с платой по интерфейсу USB необходим драйвер для микросхемы CH340С, его можно скачать [здесь](https://www.wch-ic.com/downloads/CH341SER_ZIP.html). Были замечены ошибки при работе драйвера версии 2024 года, поэтому рекомендуется устанавливать драйвер более старой версии (например, 2019 года).
Подготовка к работе по интерфейсу JTAG и инструкция по записи начального загрузчика есть [здесь](Instructions.md).

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

BIN
docs/Flash_project_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
docs/Flash_project_jtag.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

BIN
docs/Install_board_.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

57
docs/Instructions.md Normal file
View File

@ -0,0 +1,57 @@
# Установка пакета и предварительная подготовка к работе
## Установка пакета в ArduinoIDE
1. Установите [Arduino IDE](https://www.arduino.cc/en/software).
2. Откройте меню `Файл -> Параметры`.
3. Вставьте данную ссылку в поле "Дополнительные ссылки для Менеджера плат":
`https://elron.tech/files/package_elbear_beta_index.json`
![Add_board](Add_board.PNG)
4. Откройте меню `Инструменты -> Плата -> Менеджер плат...`.
5. В поиске найдите пакет `MIK32 Boards (Arduino BSP by Elron)`, выберите нужную версию пакета и нажмите кнопку `Установить`.
![Install_board](Install_board_.PNG)
6. Процесс установки может занять некоторое время. Результаты установки отобразятся в поле `Вывод`, а так же во всплывающих уведомлениях.
![Installation_process](Installation_process_.PNG)
## Запись начального загрузчика через ArduinoIDE
Для загрузки скетчей по USB в ArduinoIDE необходимо, чтобы на плате был специальный начальный загрузчик ([elbear_fw_bootloader](https://gitflic.ru/project/elron-tech/elbear_fw_bootloader) для плат ELBEAR). Если он уже есть на плате, можно сразу переходить к работе. Если загрузчика еще нет или необходимо обновить его на плате, ниже описан процесс загрузки. Актуальная версия начального загрузчика входит в состав пакета поддержки для всех плат, отдельно скачивать его не нужно.
Платы ELBEAR ACE-UNO ревизии 1.1.0, ELBEAR ACE-NANO, ELSOMIK готовы к использованию в ArduinoIDE из коробки, так как поставляются с предварительно записанным начальным загрузчиком.
Для записи начального загрузчика:
1. Подключите плату к ПК по интерфейсу JTAG.
Для подключения плат ELBEAR, ELSOMIK потребуется программатор [ELJTAG](https://elron.tech/eljtag-programmator-risc-v-mcu/).
Для подключения платы START-MIK32 необходимо на плате перевести переключатель режима программатора (COM/JTAG) в положение JTAG и подключить плату к ПК через USB разъем.
2. В ArduinoIDE выберите программатор: `Инструменты -> Программатор -> mik32 uploader`.
![programmer](programmer.png)
3. Для записи начального загрузчика выберите `Инструменты -> Записать Загрузчик`.
![Bootloader](Bootloader_.png)
4. При возникновении проблем с загрузкой ознакомьтесь с разделом `Настройка программатора` в [инструкции](https://elron.tech/wp-content/uploads/2025/07/instrukcija_po_pervomu_zapusku_140725.pdf) по первому запуску платы ELBEAR ACE-UNO или с [документацией](https://docs.mikron.ru/wiki/boards/start.html) по запуску платы START-MIK32 (ссылки на документацию по плате START-MIK32 актуальны на июль 2025 года, если они не действительны, возможно найти актуальную информацию на сайте производителя - https://mikron.ru/).
Теперь можно загружать скетчи в плату по USB.
## Начало работы
1. Подключите плату к ПК по USB.
2. Откройте ArduinoIDE и загрузите необходимый скетч. Для начала работы можно воспользоваться готовыми примерами, например - `Файл -> Примеры -> 01.Basics -> Blink`.
![Blink_example](Blink_example.png)
3. Выберите активную плату - `Инструменты -> Плата`.
![Set_board](Set_board_.png)
4. Выберите используемый COM порт - `Инструменты -> Порт`.
![Set_port](Set_port_.png)
Выбранные плата и порт в ArduinoIDE должны отображаться следующим образом:
![Selected_board_port](Selected_board_port_.png)
5. Проверьте скетч, нажав соответствующую кнопку.
![Build_project](Build_project_.png)
6. Загрузите полученную прошивку на плату.
![Flash_project](Flash_project_.png)
7. При необходимости можно открыть терминал и получать сообщения от платы по интерфейсу Serial. Для этого добавьте в скетч работу с интерфейсом и после загрузки прошивки выберите `Инструменты -> Монитор порта`.
![Monitor](Monitor_.png)
## Загрузка скетчей через программатор
ArduinoIDE позволяет так же загружать скетчи через программатор. Для этого:
1. Подключите плату к ПК по интерфейсу JTAG.
Для подключения плат ELBEAR, ELSOMIK потребуется программатор [ELJTAG](https://elron.tech/eljtag-programmator-risc-v-mcu/).
Для подключения платы START-MIK32 необходимо на плате перевести переключатель режима программатора (COM/JTAG) в положение JTAG и подключить плату к ПК через USB разъем.
2. Откройте ArduinoIDE и загрузите необходимый скетч. Для начала работы можно воспользоваться готовыми примерами, например - `Файл -> Примеры -> 01.Basics -> Blink`.
3. Выберите активную плату - `Инструменты -> Плата`.
4. Выберите программатор - `Инструменты -> Программатор -> mik32 uploader`.
5. Проверьте скетч, нажав соответствующую кнопку.
6. Для загрузки скетча через программатор выберите - `Скетч -> Загрузить на плату при помощи программатора`.
![Flash_project_jtag](Flash_project_jtag.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

BIN
docs/Monitor_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
docs/Registers.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

BIN
docs/Set_board_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

BIN
docs/Set_port_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
docs/Start_V1_pinout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

View File

@ -0,0 +1,71 @@
# START-MIK32
Особенности работы с платой START-MIK32 в среде программирования ArduinoIDE.
### Функциональное назначение выводов
![Start_V1_pinout.png](Start_V1_pinout.png)
### Загрузка скетчей
Для загрузки скетчей в ArduinoIDE необходимо передвинуть переключатель режима программатора на плате в положение `COM`. Так же необходимо установить две перемычки на разъем 5 - первой перемычкой замкнуть выводы `COM_RX` и `MCU_TX`, а второй - выводы `COM_TX` и `MCU_RX`.
Для работы с платой по интерфейсу USB не требуется установка дополнительных драйверов.
Подготовка к работе по интерфейсу JTAG и инструкция по записи начального загрузчика есть [здесь](Instructions.md).
### Цифровые выводы
Выводы на плате START-MIK32 пронумерованы в соответствии с их принадлежностью к определенному GPIO-порту и конкретному пину внутри порта. Чтобы использовать цифровой вывод, необходимо передать в функцию номер порта и номер пина в формате `P0_1`, где "0" — это номер порта, а "1" — номер пина внутри порта. Например, для инициализации вывода 5 порта 2 на выход необходимо вызвать функцию `pinMode(P2_5, OUTPUT)`.
Для использования доступны следующие выводы: `P0_0 ... P0_15, P1_0 ... P1_15, P2_0 ... P2_7`.
На плате есть встроенные светодиоды и кнопка. Светодиоды подключены к выводам P0_3, P1_3. Кнопка подключена к выводу Р0_8. Для удобства при работе с ними можно воспользоваться макросами `LED_BUILTIN`(P0_3), `LED_BUILTIN1`(P1_3) и `BTN_BUILTIN`, передавая их в качестве аргументов функции вместо номера цифрового вывода.
### АЦП
На плате доступно 8 выводов, которые можно использовать в качестве каналов АЦП. Для работы с ними в функцию `analogRead()` необходимо передать номер канала или номер соответствующего цифрового вывода. Доступные каналы и их соответствие номерам выводов платы:
|Цифровой вывод|Номер канала АЦП|
|---------|---------|
|P1_5|A0|
|P1_7|A1|
|P0_2|A2|
|P0_4|A3|
|P0_7|A4|
|P0_9|A5|
|P0_11|A6|
|P0_13|A7|
#### ШИМ
На плате START-MIK32 в ArduinoIDE доступно 8 выводов для формирования ШИМ-сигнала. Генерация сигнала осуществляется с помощью 32-битного таймера. Выводы, подключенные к одному и тому же таймеру, выдают ШИМ-сигнал одинаковой частоты.
Доступные выводы:
|Цифровой вывод|Используемый таймер|
|---------|---------|
|P0_0|таймер 1|
|P0_1|таймер 1|
|P0_2|таймер 1|
|P0_3|таймер 1|
|P1_0|таймер 2|
|P1_1|таймер 2|
|P1_2|таймер 2|
|P1_3|таймер 2|
При использовании SPI формирование ШИМ сигнала на выводах P1_0 ... P1_3 недоступно.
### Прерывания
На плате START-MIK32 доступно 8 прерываний, настраиваемых функцией `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`:
|Цифровой вывод|Номер прерывания|
|---------|---------|
|`BTN_BUILTIN` (P0_8)|0|
|P1_9|1|
|P0_10|2|
|P1_15|3|
|P0_12|4|
|P0_13|5|
|P0_14|6|
|P0_15|7|
### Serial
Интерфейс UART0 доступен на выводах RX, TX и P0_5, P0_6. Для работы с ним используется экземпляр класса под названием `Serial`.
Интерфейс UART1 доступен на выводах P1_8, P1_9, используемый экземпляр класса - `Serial1`.
USB-UART преобразователь, установленный на плате, поддерживает стандартные скорости UART до 57600 бод. Нестандартные скорости должны быть кратны
12*32=384, например, 240000 бод, 768000 бод.
### SPI
Интерфейс SPI1 доступен на выводах MOSI, MISO, CLK и P1_0, P1_1, P1_2. Для работы с ним используется экземпляр класса под названием `SPI`.
Интерфейс SPI0 доступен на выводах P0_0, P0_1, P0_2. Используемый экземпляр класса - `SPI0`.
Для корректной работы аппаратного SPI микроконтроллер так же использует выводы P1_3 при работе SPI1 и P0_3 при работе SPI0. В связи с этим данные выводы недоступны для использования при работе соответствующего SPI.
### I2C
Интерфейс I2C1 доступен на выводах SDA, SCL и P1_12, P1_13, для работы с ним используется экземпляр класса под названием `Wire`.
Интерфейс I2C0 доступен на выводах P0_9, P0_10, используемый экземпляр класса - `Wire0`.

BIN
docs/_pinout_ElsomikOEM.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 KiB

BIN
docs/debug_console.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

47
docs/debug_description.md Normal file
View File

@ -0,0 +1,47 @@
! **Внимание** Данная инструкция проверена и работает с версией Arduino IDE версии 2.3.4 на Windows 10 x64. На других версиях Arduino IDE работоспособность неизвестна. Функция отладки является экспериментальной.
# Режим отладки в ArduinoIDE 2
Начиная с версии пакета 0.5.0 для всех плат, входящих в состав пакета, доступен режим отладки скетчей.
Для отладки плат ELBEAR ACE-UNO, ELBEAR ACE-NANO, ELSOMIK понадобится программатор [ELJTAG](https://elron.tech/eljtag-programmator-risc-v-mcu/). Плата START-MIK32 содержит встроенный программатор, для использования которого необходимо передвинуть переключатель режима программатора на плате в положение `JTAG`.
Режим отладки доступен в ArduinoIDE версии 2 и выше.
# Предварительная подготовка
Для отладки в Arduino IDE используется плагин Cortex-Debug. По умолчанию в IDE установлена версия 1.5.1, но с указанной версией режим отладки для плат из состава пакета работает некорректно. Для корректной работы необходимо использовать более новую версию плагина.
Для подготовки к работе в режиме отладки необходимо сделать следующее:
* Установить драйвера для работы с программатором, если ранее они не были установлены. Подробности можно найти в [инструкции](https://elron.tech/wp-content/uploads/2025/07/instrukcija_po_pervomu_zapusku_140725.pdf) по первому запуску платы ELBEAR ACE-UNO или в [документации](https://docs.mikron.ru/wiki/boards/start.html) по запуску платы START-MIK32.
* Скачать архив, содержащий небходимую версию Cortex-Debug и все его зависимости, по [ссылке](https://elron.tech/files/mik32_arduinoIDE_debug_plagins.zip).
* Содержимое архива переместить в папку `plugins` из папки с установленной ArduinoIDE. Примерный путь - `C:\Program Files\Arduino IDE\resources\app\plugins`. Содержимое архива (несколько файлов с расширением `.vsix`) разместить в указанной папке, не создавая промежуточных папок.
* Запустить ArduinoIDE и по инструкции, описанной ниже, запустить режим отладки.
* Удостовериться, что при запуске отладки в первой строке консоли отладки отображается нужная версия плагина - 1.12.1:
`Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage`
* При возникновении сложностей с вопросами можно обратиться в [телеграмм-канал компании](https://t.me/elrontech).
После установки новой версии плагина в строке меню и в области вывода информации появятся две новые вкладки - `MEMORY` и `xRTOS`. Это плагины, которые необходимы для работы Cortex-Debug. Они не используются непосредственно пользователем при работе, но удалять их нельзя, иначе режим отладки с установленной версией Cortex-Debug не запустится.
# Запуск отладки
Последовательность действий для запуска режима отладки:
1. В ArduinoIDE открыть скетч, который необходимо запустить в режиме отладки.
2. Выбрать нужную плату - `Инструменты -> Плата`.
3. Подключить плату к ПК через программатор. Для плат ELBEAR ACE-UNO, ELBEAR ACE-NANO, ELSOMIK использовать ELJTAG. На плате START-MIK32 передвинуть переключатель режима программатора в положение `JTAG`.
4. В ArduinoIDE выбрать используемый программатор - `Инструменты -> Программатор -> mik32 uploader`.
5. Активировать оптимизацию для отладки при сборке скетча - `Скетч -> Оптимизировать для отладки`. Если отладку запустить без указанной оптимизации, при пошаговом прохождении скетча могут возникнуть проблемы, например, с "перепрыгиванием" лишних строк кода, или значения некоторых переменных могут отображаться некорректно.
6. Скомпилировать скетч - `Скетч -> Проверить/Скомпилировать`.
7. Загрузить скетч на плату. Загружать скетч можно как по USB (`Скетч -> Загрузить на плату`), так и через программатор (`Скетч -> Загрузить на плату при помощи программатора`).
! При запуске отладки скетч не компилируется и не загружается на плату автоматически. Поэтому при внесении изменений в код необходимо вручную повторять пункты 6,7 перед запуском отладки.
8. Открыть панель отладочника в меню слева:
![Debug_panel.PNG](debug_panel.PNG)
После запуска отладки здесь будут доступны к просмотру стек вызовов функций, значения переменных, установленные точки останова, а также состояние периферийных регистров микроконтроллера.
9. Для запуска отладки необходимо нажать кнопку `Начать отладку` в верхней части экрана:
![Debug_start.PNG](debug_start.PNG)
При этом:
- Откроется новый терминал `gdb-server`, в котором запустится программа openocd. Терминал отображает статус соединения с микроконтроллером.
- Запустится режим отладки, а курсор выполнения программы остановится в начале функции `setup()`.
- Станут активными кнопки пошагового перемещения по программе.
- Во всех разделах на панели отладки обновится информация.
10. Для просмотра отладочной информации можно запустить консоль отладки. Для этого на панели отладки нужно нажать соответствующую кнопку:
![Debug_console.PNG](debug_console.PNG)
В [официальной статье](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-debugger/) подробно описано, как работать с точками останова и пошаговой отладкой кода. Помимо этого, режим отладки позволяет получить доступ к системным регистрам и регистрам периферии микроконтроллера.
![Registers.PNG](Registers.png)
При работе с платами, входящими в состав пакета, накладывается ограничение на доступное количество точек останова - одновременно можно использовать не более 2-х точек. При этом вторая точка останова становится доступной после запуска отладки, когда курсор выполнения программы остановится на функции `setup()`. Режим отладки не запустится, если в скетче уже установлены обе точки останова.

BIN
docs/debug_panel.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
docs/debug_start.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -0,0 +1,79 @@
# ELSOMIK
Особенности работы с платой ELSOMIK в среде программирования ArduinoIDE.
### Функциональное назначение выводов платы ELSOMIK OEM
![pinout_Elsomik_OEM.png](_pinout_ElsomikOEM.png)
### Функциональное назначение выводов платы ELSOMIK SE
![pinout_Elsomik_SE.png](pinout_ElsomikSE.png)
### Загрузка скетчей
На плате отсутствуют встроенные преобразователи, позволяющие загружать скетчи по USB через COM-порт, однако каждая плата поставляется с предварительно записанным начальным загрузчиком. Для записи скетчей через USB потребуется использование внешнего USB-UART преобразователя, подключаемого к выводам платы P0_5 (RX0) и P0_6 (TX0), которые соответствуют интерфейсу UART0. Для корректной работы так же может потребоваться установка на ПК драйвера для микросхемы, используемой в преобразователе USB-UART.
Перед загрузкой скетча необходимо кратковременно ввести контроллер в состояние RESET. Если используется USB-UART преобразователь с выведенным сигналом DTR, необходимо соединить DTR с выводом RST на плате через керамический конденсатор емкостью от 0,47 мкФ до 2,2 мкФ. В случае отсутствия сигнала DTR, необходимо вручную соединить вывод RST платы с землей и отпустить его непосредственно перед началом записи скетча.
Для записи начального загрузчика или загрузки скетчей с помощью программатора необходимо подключить программатор (например, [ELJTAG](https://elron.tech/eljtag-programmator-risc-v-mcu/)) к выводам TDO, TDI, TCK, TMS, TRST, GND, 3V3, RST. Инструкцию по использованию программатора в Arduino IDE можно найти [здесь](Instructions.md).
### Цифровые выводы
Выводы на плате ELSOMIK пронумерованы в соответствии с их принадлежностью к определенному GPIO-порту и конкретному пину внутри порта. Чтобы использовать цифровой вывод, необходимо передать в функцию номер порта и номер пина в формате `P0_1`, где "0" — это номер порта, а "1" — номер пина внутри порта. Например, для инициализации вывода 5 порта 1 на выход необходимо вызвать функцию `pinMode(P1_5, OUTPUT)`.
Для использования доступны следующие выводы: `P0_0 ... P0_15, P1_0 ... P1_15, P2_6, P2_7`. Выводы `P0_11 ... P0_15` на плате обозначены иначе, ниже представлена таблица соответствия:
|Обозначение на плате|Номер вывода|
|---------|---------|
|TDI|P0_11|
|TCK|P0_12|
|TMS|P0_13|
|TRST|P0_14|
|TDO|P0_15|
### АЦП
На плате доступно 8 выводов, которые можно использовать в качестве каналов АЦП. Для работы с ними в функцию `analogRead()` необходимо передать номер канала или номер соответствующего цифрового вывода. Доступные каналы и их соответствие номерам выводов платы:
|Цифровой вывод|Номер канала АЦП|
|---------|---------|
|P1_5|A0|
|P1_7|A1|
|P0_2|A2|
|P0_4|A3|
|P0_7|A4|
|P0_9|A5|
|P0_11|A6|
|P0_13|A7|
#### ШИМ
На плате ELSOMIK в ArduinoIDE доступно 8 выводов для формирования ШИМ-сигнала. Генерация сигнала осуществляется с помощью 32-битного таймера. Выводы, подключенные к одному и тому же таймеру, выдают ШИМ-сигнал одинаковой частоты.
Доступные выводы:
|Цифровой вывод|Используемый таймер|
|---------|---------|
|P0_0|таймер 1|
|P0_1|таймер 1|
|P0_2|таймер 1|
|P0_3|таймер 1|
|P1_0|таймер 2|
|P1_1|таймер 2|
|P1_2|таймер 2|
|P1_3|таймер 2|
При использовании SPI формирование ШИМ сигнала на выводах P1_0 ... P1_3 недоступно.
### Прерывания
На плате ELSOMIK доступно 8 прерываний, настраиваемых функцией `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`:
|Цифровой вывод|Номер прерывания|
|---------|---------|
|P0_8|0|
|P1_4|1|
|P1_5|2|
|P1_6|3|
|P1_9|4|
|P1_10|5|
|P1_15|6|
|P2_7|7|
### Serial
Интерфейс UART0 доступен на выводах P0_5, P0_6, для работы с ним используется экземпляр класса под названием `Serial`.
Интерфейс UART1 доступен на выводах P1_8, P1_9, используемый экземпляр класса - `Serial1`.
### SPI
Интерфейс SPI1 доступен на выводах P1_0, P1_1, P1_2. Для работы с ним используется экземпляр класса под названием `SPI`.
Интерфейс SPI0 доступен на выводах P0_0, P0_1, P0_2. Используемый экземпляр класса - `SPI0`.
Для корректной работы аппаратного SPI микроконтроллер так же использует выводы P1_3 при работе SPI1 и P0_3 при работе SPI0. В связи с этим данные выводы недоступны для использования при работе соответствующего SPI.
### I2C
Интерфейс I2C1 доступен на выводах P1_12, P1_13, для работы с ним используется экземпляр класса под названием `Wire`.
Интерфейс I2C0 доступен на выводах P0_9, P0_10, используемый экземпляр класса - `Wire0`.

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

71
docs/nano_description.md Normal file
View File

@ -0,0 +1,71 @@
# ELBEAR ACE-NANO
Особенности работы с платами ELBEAR ACE-NANO в среде программирования ArduinoIDE.
### Функциональное назначение выводов
![nano_pinout](nano_pinout.PNG)
### Цифровые выводы
На плате ELBEAR ACE-NANO доступен встроенный светодиод. Для его использования необходимо воспользоваться макросом `LED_BUILTIN`, передавая его в качестве аргумента функции вместо номера цифрового вывода. Макросу соответствует номер вывода D22.
### Аналоговые выводы
Аналоговые выводы на плате могут использоваться как в аналоговом, так и в цифровом режиме.
Для использования вывода в качестве аналогового необходимо перевести соответствующий DIP-переключатель, расположенный рядом с аналоговыми выводами, в положение OFF. В этом режиме внешнее напряжение, подаваемое на вывод, будет понижаться резистивным делителем перед подачей на микроконтроллер.
Для использования вывода в качестве цифрового нужно перевести переключатель в положение ON. В этом случае напряжение с вывода платы передается на микроконтроллер без изменений. Выводы А5, А6, А7 недоступны для использования в качестве цифровых выводов.
Выводы А4...А7 используют один и тот же канал АЦП, поэтому не могут использоваться одновременно.
Для аналоговых выводов режим цифрового вывода с подтяжкой к питанию(`INPUT_PULLUP`) не дает желаемого результата, так как на этих сигналах установлена неотключаемая подтяжка к земеле (10 кОм), а подтяжка к питанию внутри микроконтроллера осуществляется резистором 50 кОм. Для реализации такого режима на аналоговых выводах необходимо использовать внешний дополнительный резистор 1...2 кОм, подключенный к питанию.
Таблица соответствия выводов платы и номера DIP-переключателя представлена ниже. Переключатель 5 относится сразу к четырем аналоговым выводам - А4...А7.
|Вывод|Номер переключателя|
|---------|---------|
|А0|1|
|А1|2|
|А2|3|
|А3|4|
|А4|5|
|А5|5|
|А6|5|
|А7|5|
#### ШИМ
На плате ELBEAR ACE-NANO доступно 8 выводов для формирования ШИМ-сигнала. Генерация сигнала осуществляется с помощью 32-битного таймера. Выводы, подключенные к одному и тому же таймеру, выдают ШИМ-сигнал одинаковой частоты.
Доступные выводы:
|Цифровой вывод|Используемый таймер|
|---------|---------|
|D3|таймер 1|
|D5|таймер 1|
|D6|таймер 1|
|D9|таймер 1|
|D10|таймер 2|
|D11|таймер 2|
|D12|таймер 2|
|D13|таймер 2|
Цифровые выводы D9, D10 не могут быть использованы для генерации ШИМ, если одновременно активен интерфейс SPI (при использовании экземпляра `SPI` недоступен ШИМ на выводе D10, при использовании экземпляра `SPI0` - на выводе D9). Это ограничение связано с особенностями работы микроконтроллера. Ограничение не распространяется на использование D9, D10 в качестве цифрового вывода при активном SPI.
### Прерывания
На плате ELBEAR ACE-NANO доступно 8 прерываний, настраиваемых функцией `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`:
|Цифровой вывод|Номер прерывания|
|---------|---------|
|D2|0|
|D3|1|
|D4|2|
|D5|3|
|D6|4|
|D8|5|
|D9|6|
|A1|7|
При использовании аналогового вывода A1 для работы с прерываниями необходимо предварительно перевести вывод в режим цифрового. Для этого нужно перевести DIP-переключатель номер 2 в положение ON.
### Serial
Интерфейс UART0 доступен на выводах D0, D1, для работы с ним используется экземпляр класса под названием `Serial`.
Интерфейс UART1 доступен на выводах D7, D8, используемый экземпляр класса - `Serial1`.
### SPI
Интерфейс SPI1 доступен на выводах D11, D12, D13. Для работы с ним используется экземпляр класса под названием `SPI`.
Интерфейс SPI0 доступен на выводах D3, D5, D6. Используемый экземпляр класса - `SPI0`.
### I2C
Интерфейс I2C1 доступен на выводах A4 и A5, для работы с ним используется экземпляр класса под названием `Wire`.
## Драйверы
Для работы с платой по интерфейсу USB необходим драйвер для микросхемы CH343P, его можно скачать [здесь](https://www.wch-ic.com/downloads/CH343SER_ZIP.html).
Подготовка к работе по интерфейсу JTAG и инструкция по записи начального загрузчика есть [здесь](Instructions.md).

BIN
docs/nano_pinout.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 233 KiB

BIN
docs/pinout_ElsomikSE.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 KiB

BIN
docs/pinout_uno.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB

BIN
docs/programmer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

32
docs/tested_libs.md Normal file
View File

@ -0,0 +1,32 @@
# Протестированные библиотеки
|Библиотека|Описание|
|---------|---------|
|[RFID_MFRC522v2](https://docs.arduino.cc/libraries/rfid_mfrc522v2/)|Новая версия библиотеки MFRC522 для работы с RFID картами|
|[SD](https://www.arduino.cc/en/Reference/SD)|Библиотека, позволяющая считывать и записывать информацию на SD карты|
|[TimeLib](https://docs.arduino.cc/libraries/time/)|Библиотека для удобной работы с переменными времени|
|[Ds1302](https://reference.arduino.cc/reference/en/libraries/ds1302/)|Библиотека для работы с микросхемой часов реального времени DS1302|
|[DS1307RTC](https://docs.arduino.cc/libraries/ds1307rtc/)|Библиотека для работы с микросхемой часов реального времени DS1307|
|[microDS3231](https://docs.arduino.cc/libraries/microds3231/)|Легкая библиотека для работы с микросхемой часов реального времени DS3231|
|[Rtc](https://github.com/Makuna/Rtc/tree/master)|Библиотека для работы с разными микросхемами часов реального времени|
|[AHT10](https://github.com/enjoyneering/AHT10/tree/master)|Библиотека для работы с датчиками температуры и влажности AHT10, AHT15, AHT20|
|[DHT](https://docs.arduino.cc/libraries/dht-sensor-library/)|Библиотека для работы с датчиками температуры и влажности типа DHT|
|[Adafruit_BMP280](https://docs.arduino.cc/libraries/adafruit-bmp280-library/)|Библиотека для работы с датчиками давления и высоты BMP280|
|[MPU6050](https://reference.arduino.cc/reference/en/libraries/mpu6050/)|Библиотека для работы с акселерометром/гироскопом MPU6050|
|[Kalman](https://docs.arduino.cc/libraries/kalman-filter-library/)|Библиотека, реализующая фильтр Калмана|
|[LiquidCrystal_I2C](https://docs.arduino.cc/libraries/liquidcrystal-i2c/)|Библиотека для управления LCD дисплеями по интерфейсу I2C|
|[JoystickShield](https://github.com/sudar/JoystickShield/tree/master)|Библиотека для работы с шилдом JoystickShield|
|[RF24](https://docs.arduino.cc/libraries/rf24/)|Драйвер радиоустройств, библиотека для работы с микросхемами nRF24L01(+)|
|[Bonezegei_ULN2003_Stepper](https://docs.arduino.cc/libraries/bonezegei_uln2003_stepper/)|Библиотека драйвера шагового двигателя, управляемого микросхемой ULN2003|
|[Ethernet](https://docs.arduino.cc/libraries/ethernet/)|Библиотека, позволяющая использовать Ethernet шилд для подключения к Интернету|
|[AGS10_sensor](https://github.com/gina-seth/AGS10_sensor)|Библиотека для работы с датчиком газа AGS10|
|[TinyGPSPlus](https://docs.arduino.cc/libraries/tinygpsplus/)|Библиотека позволяет расшифровать данные GPS, сформированные по протоколу NMEA|
|[GPRS_Shield_Arduino](https://github.com/amperka/gprs-shield)|Библиотека для Arduino, позволяющая управлять GPRS Shieldом от Амперки|
|[Adafruit GFX](https://docs.arduino.cc/libraries/adafruit-gfx-library/)|Базовая графическая библиотека, от которой происходят все остальные графические библиотеки Adafruit|
|[Adafruit_SH110X](https://docs.arduino.cc/libraries/adafruit-sh110x/)|Библиотека драйверов SH110X OLED для монохромных дисплеев с драйверами SH1107 или SH1106G|
|[Adafruit_SSD1306](https://docs.arduino.cc/libraries/adafruit-ssd1306/)|Библиотека драйвера SSD1306 OLED для монохромных дисплеев с расширениями 128x64 и 128x32|
|[Adafruit_ST7789](https://docs.arduino.cc/libraries/adafruit-st7735-and-st7789-library/)|Библиотека для работы с дисплеем ST7789 по SPI|
|[Adafruit_ILI9341](https://docs.arduino.cc/libraries/adafruit-ili9341/)|Библиотека для работы с дисплеем Adafruit ILI9341|
|[TFT](https://docs.arduino.cc/libraries/tft/)|Графическая библиотека, совместимая с большинством TFT-дисплеев на базе чипа ST7735|
|[Adafruit_TCS34725](https://docs.arduino.cc/libraries/adafruit-tcs34725/)|Библиотека для работы с датчиком цвета с ИК-фильтром TCS34725|
|[DS18B20](https://docs.arduino.cc/libraries/ds18b20/)|Библиотека для работы с однопроводным датчиком температуры DS18B20|
|[CAN](https://docs.arduino.cc/libraries/can/)|Библиотека для передачи данных по шине CAN. Поддерживает модули на базе чипа MCP2515|

61
docs/tested_shields.md Normal file
View File

@ -0,0 +1,61 @@
## Модули, работающие без аппаратной модификации
|Модуль|Описание|Протестировано на|Ссылки на модуль|Материалы|
|---------|---------|------|---------|------|
|Датчик температуры DS18B20|Цифровой датчик|ELBEAR ACE-UNO,ELBEAR ACE-NANO, START-MIK32-V1|[Ozon](https://ozon.ru/t/dhmEm2y), [AliExpress](https://sl.aliexpress.ru/p?key=SMB63oS)|[Telegram](https://t.me/hutor_yanin/2612), [Gitflic](https://gitflic.ru/project/elron-tech/elbear_arduino_bsp/file?file=libraries%2FOneWire%2Fexamples%2FDS18x20_Temperature)|
|CAN-модуль MCP2515|CAN контроллер с SPI интерфейсом, модуль на базе MCP2515|ELBEAR ACE-UNO,ELBEAR ACE-NANO|[Ozon](https://ozon.ru/t/dhmEemf), [AliExpress](https://sl.aliexpress.ru/p?key=yeGH3aC)|[Telegram](https://t.me/hutor_yanin/2588), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_MCP2515_CAN)|
|Модуль лазерного дальномера VL53L0X|Подключение по I2C|ELBEAR ACE-UNO,ELBEAR ACE-NANO, START-MIK32-V1|[Ozon](https://ozon.ru/t/CKX9Vtg), [AliExpress](https://sl.aliexpress.ru/p?key=3yE73Ax)|[Telegram](https://t.me/hutor_yanin/2560), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FI2C_VL53L0X_test)|
|Модуль датчика температуры, давления BMP280|Цифровой датчик|ELBEAR ACE-UNO,ELBEAR ACE-NANO, START-MIK32-V1|[Ozon](https://ozon.ru/t/Q1zc8bJ), [AliExpress](https://sl.aliexpress.ru/p?key=N5WW3jN)|[Telegram](https://t.me/hutor_yanin/2536), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FI2C_BMP280_terminal)|
|Инфракрасный датчик движения (PIR)|Цифровой датчик. Протестированны разновидности: AM312, SR501, SR602 и SR505|ELBEAR ACE-NANO|[Ozon](https://ozon.ru/t/97BptDy), [AliExpress](https://sl.aliexpress.ru/p?key=oxyG3lk)|[Telegram](https://t.me/hutor_yanin/2417), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FReedSwitch_test)|
|Цифро-аналоговый преобразователь MCP4725 12 бит|Модуль MCP4725 представляет собой прецизионный 12-битный цифро-аналоговый преобразователь (ЦАП), подключение по I2C|ELBEAR ACE-UNO, START-MIK32-V1|[Ozon](https://ozon.ru/t/CK7qTXd), [AliExpress](https://sl.aliexpress.ru/p?key=ZW6s3Te)|[Telegram](https://t.me/hutor_yanin/1456), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FI2C_MCP4725_DAC_test)|
|Датчик температуры и влажности AHT10|Цифровой датчик, подключение по I2C|ELBEAR ACE-UNO, START-MIK32-V1|[Ozon](https://ozon.ru/t/amuSvQx), [AliExpress](https://sl.aliexpress.ru/p?key=TuCs33F)|[Telegram](https://t.me/hutor_yanin/1519?single), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FI2C_AHT10_terminal)|
|Датчик движения HW-MS03|Цифровой датчик|ELBEAR ACE-UNO, START-MIK32-V1|[Ozon](https://ozon.ru/t/RdiARs9), [AliExpress](https://sl.aliexpress.ru/p?key=G1bw3LH)|[Telegram](https://t.me/hutor_yanin/2376), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FHW_MS03_test&branch=master)|
|Bluetooth HC-05 (HC-06)|Bluetooth версия 2.0, подключение через UART|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/modul-bluetooth-hc-05-arduino-971282989), [AliExpress](https://sl.aliexpress.ru/p?key=1mn8GcF)|[Telegram](https://t.me/hutor_yanin/2309), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FHC-05_demo&branch=master)|
|Радиомодуль CC1101 433 МГц|Модуль работает как приёмо-передатчик, подключение через SPI|ELBEAR ACE-UNO, START-MIK32-V1|[Ozon](https://www.ozon.ru/product/radiomodul-priemoperedatchik-na-cc1101-s-sma-antennoy-433-mgts-do-380-m-1565278116), [AliExpress](https://sl.aliexpress.ru/p?key=2mtQG9C)|[Telegram](https://t.me/hutor_yanin/2329), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FCC1101&branch=master)|
|Радиомодуль nrf24L01 2.4 ГГц|Беспроводной приемопередатчик, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/radiomodul-nrf24l01-2-4-ggts-1420337483), [AliExpress](https://sl.aliexpress.ru/p?key=Pt0RGXV)|[Telegram](https://t.me/hutor_yanin/1643), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_nRF24L01_Transmitter&branch=master)|
|Дисплей 10-контактный 7-сегментный 3-значный|Без драйвера|Elbear ACE-UNO|[AliExpress](https://sl.aliexpress.ru/p?key=CXuRGJw)|[Telegram](https://t.me/hutor_yanin/2157), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FRenesasDriver_demo)|
|Цветной дисплей 170x320 1.9|Дисплей 1.9 дюйма с драйвером ST7789, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/tsvetnoy-displey-1-9-tft-lcd-170x320-st7789-spi-interfeys-1781570948), [AliExpress](https://sl.aliexpress.ru/p?key=YHuRGO8)|[Telegram](https://t.me/hutor_yanin/2121), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_ST7789_170_320)|
|Дисплей E-link 2.13 от Heltec|Электронная бумага сохраняет изображение после отключения питания, подключение через SPI|ELBEAR ACE-UNO, START-MIK32-V1| [AliExpress](https://sl.aliexpress.ru/p?key=XOuRGfZ)|[Telegram](https://t.me/hutor_yanin/2047), [YouTube](https://youtu.be/Gz6e2d85w1s), [VK Видео](https://vkvideo.ru/video119909267_456239207), [Дзен](https://dzen.ru/video/watch/679e25b2a722f84498194c84), [RuTube](https://rutube.ru/video/3d85842b7a54fc8e5a721c4b96392ade), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FHeltec_Elink&branch=master)|
|IPS дисплей 80x160 0.9|Дисплей 0.9 дюйма с драйвером ST7735, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/tsvetnoy-ips-tft-displey-na-st7735s-spi-80h160-0-96-933036270), [AliExpress](https://sl.aliexpress.ru/p?key=NjmRGBe)|[Telegram](https://t.me/hutor_yanin/2009), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_ST7735_80_160)|
|Цветной дисплей 320x240 3.2|Дисплей 3.2 дюйма с драйвером ILI9341, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/tsvetnoy-sensornyy-displey-3-2-tft-lcd-320x240-ili9341-spi-interfeys-1347211506), [AliExpress](https://sl.aliexpress.ru/p?key=xc0RG4f)|[Telegram](https://t.me/hutor_yanin/1654), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_ILI9341_graphicstest&branch=master)|
|Цветной дисплей 240x280 1.69|Дисплей 1.69 дюйма с драйвером ST7789, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/1-69-dyuymovyy-tft-displey-zhk-ekran-tsvetnoy-modul-240x280-st7789-v3-1376717173), [AliExpress](https://sl.aliexpress.ru/p?key=mH0RGWu)|[Telegram](https://t.me/hutor_yanin/1696), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_ST7789_240_280&branch=master)|
|Дисплей GMD12864-06D 128х64|Дисплей с драйвером ST7565, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/zhk-displey-gmd12864-06d-128h64-pikseley-razmer-62h46h6-8mm-chernyy-s-belymi-simvolami-1840705753), [AliExpress](https://sl.aliexpress.ru/p?key=gcQRGT7)|[Telegram](https://t.me/hutor_yanin/1736) [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_ST7565_HelloWorld&branch=master)|
|Дисплей GM12864-01A 128x64|Дисплей с драйвером ST7567, подключение через SPI|Elbear ACE-UNO|[AliExpress](https://sl.aliexpress.ru/p?key=rpmRGn7)|[Telegram](https://t.me/hutor_yanin/1960), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_ST7567_HelloAmur)|[Telegram](https://t.me/hutor_yanin/1736), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_ST7565_HelloWorld&branch=master)|
|OLED дисплей 0.96|Дисплей с драйвером SSD1306, подключение через I2C|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/0-96-dyuymovyy-oled-modul-128x64-ssd1306-drayver-iic-i2c-posledovatelnyy-4-kontaktnyy-belyy-1783177523), [AliExpress](https://sl.aliexpress.ru/p?key=6EkRGk6)|[Telegram](https://t.me/hutor_yanin/1804), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FI2C_SSD1306_test&branch=master)|
|OLED дисплей 1.3|Дисплей с драйвером SH1106, подключение через I2C|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/displey-oled-1-3-128-64-4kont-belye-simvoly-iic-i2c-1697780504), [AliExpress](https://sl.aliexpress.ru/p?key=5fkRGId)|[Telegram](https://t.me/hutor_yanin/1798), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FI2C_SH1106_128x64&branch=master)|
|LoRa модуль E32-170T30D|Модуль беспроводной передачи данных 433 МГц, подключение через USART|ELBEAR ACE-UNO, START-MIK32-V1|[AliExpress](https://sl.aliexpress.ru/p?key=ZyduGAA)|[Telegram](https://t.me/hutor_yanin/2347), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FLoRa_E32)|
|LoRa модуль SX1278|Модуль беспроводной передачи данных 433 МГц, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/radiomodul-lora-drf1278f-na-sx1278-433-mgts-do-15-km-1226159993), [AliExpress](https://sl.aliexpress.ru/p?key=cemRGz9)|[Telegram](https://t.me/hutor_yanin/1983), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FLoRa)|
|GPS модуль GP-02-Kit|Высокопроизводительный многорежимный спутниковый навигационный приемник BDS GNSS GPS, подключение через USART|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/vysokoproizvoditelnyy-mnogorezhimnyy-sputnikovyy-navigatsionnyy-priemnik-bds-gnss-soc-development-1817412682), [AliExpress](https://sl.aliexpress.ru/p?key=XSmRGno)|[Telegram](https://t.me/hutor_yanin/1914), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FGPS_GP_02_Satellites)|
|GPS шилд с NEO-6M|Шилд содержит модуль Neo-6m и модуль SD-карт, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/gps-plata-rasshireniya-6m-slot-dlya-sd-karty-antenna-1599001299), [AliExpress](https://sl.aliexpress.ru/p?key=Zc9RGc5)|[Telegram](https://t.me/hutor_yanin/1764), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FGPS_NEO_6_tiny&branch=master)|
|Гироскоп MPU6050|Модуль акселерометра и гироскопа, подключение через I2C|ELBEAR ACE-UNO|[Ozon](https://ozon.ru/t/ytk86Ht), [AliExpress](https://sl.aliexpress.ru/p?key=KM09GtU)|[Telegram](https://t.me/hutor_yanin/1593), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/blob?file=ElbearAceUno%2FMPU6050_surveyWithCalibration%2FMPU6050_surveyWithCalibration.ino&branch=master)|
|Электронный компас GY-271|Трехосевой цифровой компас на микросхеме HMC5883L|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/modul-gy-271-trehosevoy-tsifrovoy-kompas-na-mikrosheme-hmc5883l-561309323), [AliExpress](https://sl.aliexpress.ru/p?key=8RuRGMI)|[Telegram](https://t.me/hutor_yanin/2278), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FQMC5883L_GY-271_xyz)|
|Модуль датчика LSM6DS3|Модуль 3-осевого акселерометра и гироскопа, подключение через SPI|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/modul-3-osevogo-akselerometra-i-giroskopa-gy-lsm6ds3-1003876368), [AliExpress](https://sl.aliexpress.ru/p?key=4puRGGV)|[Telegram](https://t.me/hutor_yanin/2192), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSPI_LSM6DS3_demo)|
|Датчик касания (сенсорная кнопка) HTTM|Емкостная кнопка, цифровой сигнал|Elbear ACE-UNO|[AliExpress](https://sl.aliexpress.ru/p?key=q6mRGDT)|[Telegram](https://t.me/hutor_yanin/1890), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FImpactSensor_test)|
|Датчик касания (сенсорная кнопка) TTP223B|Емкостная кнопка, цифровой сигнал|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-kasaniya-sensornaya-knopka-ttp223b-arduino-1633188265), [AliExpress](https://sl.aliexpress.ru/p?key=C58RG9i)|[Telegram](https://t.me/hutor_yanin/1690), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FReedSwitch_test&branch=master)|
|Датчик температуры и влажности DHT11|Цифровой датчик содержит в себе АЦП для преобразования аналоговых значений влажности и температуры|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-vlazhnosti-i-temperatury-dht11-arduino-1317541347), [AliExpress](https://sl.aliexpress.ru/p?key=5D0RGGR)|[Telegram](https://t.me/hutor_yanin/1712), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FDHT11_readTempAndHumidity&branch=master)|
|Датчик температуры и влажности DHT22|Цифровой датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/modul-tsifrovogo-datchika-temperatury-i-vlazhnosti-dht22-am2302-933031851), [AliExpress](https://sl.aliexpress.ru/p?key=86jRG0b)|[Telegram](https://t.me/hutor_yanin/1865), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FDHT22_readTempAndHumidity)|
|Датчик цвета TCS34725|Цифровой датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-tsveta-na-tcs3472-775174995), [AliExpress](https://sl.aliexpress.ru/p?key=6lmRGlD)|[Telegram](https://t.me/hutor_yanin/1855), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2Ftcs3472_test)|
|Датчик качества воздуха AGS10|Цифровой датчик|Elbear ACE-UNO|[AliExpress](https://sl.aliexpress.ru/p?key=DgmRGXB)|[Telegram](https://t.me/hutor_yanin/1844), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FAGS10_readTVOC), [GitHub](https://github.com/ogneyar/AGS10_sensor)|
|Датчик пульса PulseSensor|Датчик сердечного ритма|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-pulsa-datchik-serdtsebieniya-pulsesensor-414624875), [AliExpress](https://sl.aliexpress.ru/p?key=takRG2E)|[Telegram](https://t.me/hutor_yanin/1821), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno2FSensorPulse_check), [GitHub](https://github.com/ogneyar/iarduino_SensorPulse)|
|Трансформаторный датчик тока ZMCT103C|Цифровой датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/transformatornyy-datchik-toka-zmct103c-reguliruemyy-278320605), [AliExpress](https://sl.aliexpress.ru/p?key=hykRGA9)|[Telegram](https://t.me/hutor_yanin/1796), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FZMCT103C_test&branch=master)|
|Датчик уровня воды|Аналоговый датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-urovnya-vody-zhidkosti-arduino-286889354), [AliExpress](https://sl.aliexpress.ru/p?key=fYkRGG0)|[Telegram](https://t.me/hutor_yanin/1791), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FImpactSensor_test&branch=master)|
|Модуль датчика удара KY-031 (HW-500)|Цифровой датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/modul-datchika-udara-ky-031-hw-500-dlya-arduino-1634989184), [AliExpress](https://sl.aliexpress.ru/p?key=JdEarUe)|[Telegram](https://t.me/hutor_yanin/1791), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FImpactSensor_test&branch=master)|
|Датчик вибрации (удара) SW-420|Mодуль датчика вибрации, цифровой сигнал|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-vibratsii-udara-sw-420-276668454), [AliExpress](https://sl.aliexpress.ru/p?key=RQeRGTR)|[Telegram](https://t.me/hutor_yanin/1589), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FReedSwitch_test&branch=master)|
|Датчик звука KY-037|Цифровой датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/modul-zvuka-s-mikrofonom-s-tsifrovym-i-analogovym-vyhodami-b75-ky-037-arduino-294305993), [AliExpress](https://sl.aliexpress.ru/p?key=oD9RGsu)|[Telegram](https://t.me/hutor_yanin/1768), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSoundSensor_led&branch=master)|
|Ультразвуковой датчик расстояния HC-SR04|Акустический датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/ultrazvukovoy-datchik-rasstoyaniya-hc-sr04-dalnomer-dlya-arduino-stm32-nodemcu-raspberry-982330663), [AliExpress](https://sl.aliexpress.ru/p?key=GwRRGSX)|[Telegram](https://t.me/hutor_yanin/1601), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FHC_SR04_test&branch=master)|
|Датчик препятствия KY-033 (HW-511)|Инфракрасный датчик, цифровой сигнал|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/modul-datchika-linii-ky-033-hw-511-dlya-arduino-1635031318), [AliExpress](https://sl.aliexpress.ru/p?key=sjQRG71)|[Telegram](https://t.me/hutor_yanin/1748), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FReedSwitch_test&branch=master)|
|Лазерный модуль KY-008|Цифровой датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/lazernyy-modul-ky-008-arduino-1167219696), [AliExpress](https://sl.aliexpress.ru/p?key=LvQRG8S)|[Telegram](https://t.me/innatomeya_STM32_Linux/258), [Telegram](https://t.me/hutor_yanin/1744), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FKY-008_test&branch=master)|
|Датчик освещенности TEMT6000|Аналоговый датчик|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-osveshchennosti-ampertok-temt6000-1-sht-501798149), [AliExpress](https://sl.aliexpress.ru/p?key=1TQRGpJ)|[Telegram](https://t.me/hutor_yanin/1741), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FTEMT6000_test&branch=master)|
|Датчик освещённости (фоторезистор)| Модуль с фоторезистором, цифровой сигнал|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-sveta-fotorezistor-arduino-832150968), [AliExpress](https://sl.aliexpress.ru/p?key=3weRGMu)|[Telegram](https://t.me/hutor_yanin/1690), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FReedSwitch_test&branch=master)|
|Модуль MAX3232|Модуль преобразователя RS232, подключение через USART|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/konverter-rs232-v-ttl-adapter-max3232-933520107), [AliExpress](https://sl.aliexpress.ru/p?key=Af1DrTQ)|[Telegram](https://t.me/hutor_yanin/1721)|
|Шаговый двигатель с драйвером ULN2003| - |Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/shagovyy-dvigatel-28byj-48-5v-s-drayverom-na-uln2003-933028639), [AliExpress](https://sl.aliexpress.ru/p?key=t6RRGjJ)|[Telegram](https://t.me/hutor_yanin/1603), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FStepper_ULN2003_basic&branch=master)|
|Модуль драйвера шагового двигателя DRV8833| - |Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/drv-8833-modul-drayvera-shagovogo-dvigatelya-motora-postoyannogo-toka-drayver-shagovogo-1572085339), [AliExpress](https://sl.aliexpress.ru/p?key=9G9RGYd)|[Telegram](https://t.me/hutor_yanin/1759), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FDRV8833_NL&branch=master), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FDRV8833_Stepper_NL&branch=master)|
|Motor Shield v.2|Драйвер моторов на двух микрочипах L293D|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/drayver-dvigatelya-dlya-arduino-arduino-motor-shield-v-2-1142991783), [AliExpress](https://sl.aliexpress.ru/p?key=aeRRGsO)|[Telegram](https://t.me/hutor_yanin/1626), [Gitflic](https://gitflic.ru/project/ogneyar/motorshield_amura)|
|Герконовый датчик магнитного поля G123-08|Модуль с герконовым датчиком, цифровой сигнал|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/gerkonovyy-datchik-magnitnogo-polya-g123-08-dlya-arduino-933032245), [AliExpress](https://sl.aliexpress.ru/p?key=FVeRGRF)|[Telegram](https://t.me/hutor_yanin/1589), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FReedSwitch_test&branch=master)|
|Датчик наклона SW520D|Модуль датчика наклона, цифровой сигнал|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/datchik-naklona-i-vibratsii-sw520d-dlya-arduino-1320666786), [AliExpress](https://sl.aliexpress.ru/p?key=jFeRGot)|[Telegram](https://t.me/hutor_yanin/1589), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FReedSwitch_test&branch=master)|
## Модули, требующие аппаратную модификацию
|Модуль|Описание|Требуемые изменеия|Протестировано на|Ссылки на модуль|Материалы|
|---------|---------|------|---------|------|------|
|GPRS шилд с SIM900|Позволяет подключиться к сотовой сети, подключение через USART|Для использования SoftwareSerial при работе с шилдом необходимо убрать перемычку с вывода TX на плате шилда и проводом подключить его к выводу платы, который поддерживает работу с прерываниями|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/plata-rasshireniya-gsm-gprs-shield-sim900-dlya-arduino-319034019), [AliExpress](https://sl.aliexpress.ru/p?key=ShjRGRZ)|[Telegram](https://t.me/hutor_yanin/1776), [YouTube](https://youtu.be/1TAkBW9u3uY), [VK Видео](https://vkvideo.ru/video119909267_456239202), [Дзен](https://dzen.ru/video/watch/67407260ca74f40671f8c7ee), [RuTube](https://rutube.ru/video/a626c1f30f3e464bb70ae27a4ad2d969), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FSIM900_sendSMS&branch=master)|
|Светодиодная матрица|Матрица с драйвером MAX7219|MAX7219 с АМУРом не заработала, матрицу приходится подключать напрямую, подпаиваясь к контактам|Elbear ACE-UNO|[Ozon](https://www.ozon.ru/product/svetodiodnaya-matritsa-arduino-s-drayverom-max7219-1161681177), [AliExpress](https://sl.aliexpress.ru/p?key=7tkRGjj)|[Telegram](https://t.me/hutor_yanin/1773), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FMatrix_led&branch=master)||
|Ethernet Shield W5500 v2.0|Позволяет подключиться к сети интернет до 100 МБит, подключение через SPI|Требуется припаять провода от ISCP разъёма к плате расширения|Elbear ACE-UNO|[AliExpress](https://sl.aliexpress.ru/p?key=JK0RGtp)|[Telegram](https://t.me/hutor_yanin/1463), [YouTube](https://youtu.be/fUFW2P_hY7E), [VK Видео](https://vk.com/video119909267_456239193), [RuTube](https://rutube.ru/video/afc7972188fa863f40fd860a3ee38954), [Gitflic](https://gitflic.ru/project/ogneyar/arduino/file?file=ElbearAceUno%2FEthernetShield_WebServer&branch=master)|

View File

@ -94,7 +94,7 @@ struct EEPROMClass{
uint16_t length() { return (uint16_t)EEPROM_LENGHT; }
template< typename T >
T &put(int idx, T &data)
const T &put(int idx, const T &data)
{
void* dataPointer = (void*)&data;
// check if idx is valid

View File

@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at phillip.stevens@gmail.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

View File

@ -0,0 +1,20 @@
Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,120 @@
#include <Arduino_FreeRTOS.h>
#include <semphr.h> // add the FreeRTOS functions for Semaphores (or Flags).
// Declare a mutex Semaphore Handle which we will use to manage the Serial Port.
// It will be used to ensure only one Task is accessing this resource at any time.
SemaphoreHandle_t xSerialSemaphore;
// define two Tasks for DigitalRead & AnalogRead
void TaskDigitalRead( void *pvParameters );
void TaskAnalogRead( void *pvParameters );
// the setup function runs once when you press reset or power the board
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// Semaphores are useful to stop a Task proceeding, where it should be paused to wait,
// because it is sharing a resource, such as the Serial port.
// Semaphores should only be used whilst the scheduler is running, but we can set it up here.
if ( xSerialSemaphore == NULL ) // Check to confirm that the Serial Semaphore has not already been created.
{
xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port
if ( ( xSerialSemaphore ) != NULL )
xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by "Giving" the Semaphore.
}
// Now set up two Tasks to run independently.
xTaskCreate(
TaskDigitalRead,
"DigitalRead", // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
NULL, // Parameters for the task
2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
NULL); // Task Handle
xTaskCreate(
TaskAnalogRead,
"AnalogRead", // A name just for humans
128, // Stack size
NULL, // Parameters for the task
1, // Priority
NULL); // Task Handle
// Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started.
}
void loop()
{
// Empty. Things are done in Tasks.
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskDigitalRead( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
/*
DigitalReadSerial
Reads a digital input on pin pushButton, prints the result to the serial monitor
This example code is in the public domain.
*/
#ifdef BTN_BUILTIN
uint8_t pushButton = BTN_BUILTIN;
#elif (defined(ARDUINO_ELSOMIK))
uint8_t pushButton = P0_0;
#else
uint8_t pushButton = 2;
#endif
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
for (;;) // A Task shall never return or exit.
{
// read the input pin:
int buttonState = digitalRead(pushButton);
// See if we can obtain or "Take" the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or "Take" the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don't want it getting stolen during the middle of a conversion.
// print out the state of the button:
Serial.println(buttonState);
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
vTaskDelay(1); // one tick delay (10ms) in between reads for stability
}
}
void TaskAnalogRead( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
for (;;)
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// See if we can obtain or "Take" the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or "Take" the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don't want it getting stolen during the middle of a conversion.
// print out the value you read:
Serial.println(sensorValue);
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
vTaskDelay(1); // one tick delay (10ms) in between reads for stability
}
}

View File

@ -0,0 +1,162 @@
/*
* Example of a basic FreeRTOS queue
* https://www.freertos.org/Embedded-RTOS-Queues.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
// Include queue support
#include <queue.h>
// Define a Array
int pinReadArray[4]={0,0,0,0};
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
//Function Declaration
void TaskBlink(void *pvParameters);
void TaskAnalogReadPin0(void *pvParameters);
void TaskAnalogReadPin1(void *pvParameters);
void TaskSerial(void *pvParameters);
/*
* Declaring a global variable of type QueueHandle_t
*
*/
QueueHandle_t arrayQueue;
void setup() {
/**
* Create a queue.
* https://www.freertos.org/a00116.html
*/
arrayQueue=xQueueCreate(10, // Queue length
sizeof(int)); // Queue item size
if(arrayQueue!=NULL){
// Create task that consumes the queue if it was created.
xTaskCreate(TaskSerial, // Task function
"PrintSerial", // Task name
128, // Stack size
NULL,
2, // Priority
NULL);
// Create task that publish data in the queue if it was created.
xTaskCreate(TaskAnalogReadPin0, // Task function
"AnalogRead1", // Task name
128, // Stack size
NULL,
1, // Priority
NULL);
// Create other task that publish data in the queue if it was created.
xTaskCreate(TaskAnalogReadPin1, // Task function
"AnalogRead2", // Task name
128, // Stack size
NULL,
1, // Priority
NULL);
xTaskCreate(TaskBlink, // Task function
"Blink", // Task name
128, // Stack size
NULL,
0, // Priority
NULL);
}
}
void loop() {}
/**
* Analog read task for Pin A0
* Reads an analog input on pin 0 and send the readed value through the queue.
* See Blink_AnalogRead example.
*/
void TaskAnalogReadPin0(void *pvParameters){
(void) pvParameters;
for (;;){
pinReadArray[0]=0;
pinReadArray[1]=analogRead(A0);
/**
* Post an item on a queue.
* https://www.freertos.org/a00117.html
*/
xQueueSend(arrayQueue,&pinReadArray,portMAX_DELAY);
// One tick delay (10ms) in between reads for stability
vTaskDelay(1);
}
}
/**
* Analog read task for Pin A1
* Reads an analog input on pin 1 and send the readed value through the queue.
* See Blink_AnalogRead example.
*/
void TaskAnalogReadPin1(void *pvParameters){
(void) pvParameters;
for (;;){
pinReadArray[2]=1;
pinReadArray[3]=analogRead(A1);
/**
* Post an item on a queue.
* https://www.freertos.org/a00117.html
*/
xQueueSend(arrayQueue,&pinReadArray,portMAX_DELAY);
// One tick delay (10ms) in between reads for stability
vTaskDelay(1);
}
}
/**
* Serial task.
* Prints the received items from the queue to the serial monitor.
*/
void TaskSerial(void *pvParameters){
(void) pvParameters;
// Init Arduino serial
Serial.begin(9600);
for (;;){
if(xQueueReceive(arrayQueue,&pinReadArray,portMAX_DELAY) == pdPASS ){
Serial.print("PIN:");
Serial.println(pinReadArray[0]);
Serial.print("value:");
Serial.println(pinReadArray[1]);
Serial.print("PIN:");
Serial.println(pinReadArray[2]);
Serial.print("value:");
Serial.println(pinReadArray[3]);
vTaskDelay(500/portTICK_PERIOD_MS);
}
}
}
/*
* Blink task.
* See Blink_AnalogRead example.
*/
void TaskBlink(void *pvParameters){
(void) pvParameters;
pinMode(blink_pin,OUTPUT);
digitalWrite(blink_pin,LOW);
for (;;){
digitalWrite(blink_pin,HIGH);
vTaskDelay(250/portTICK_PERIOD_MS);
digitalWrite(blink_pin,LOW);
vTaskDelay(250/portTICK_PERIOD_MS);
}
}

View File

@ -0,0 +1,95 @@
#include <Arduino_FreeRTOS.h>
// define two tasks for Blink & AnalogRead
void TaskBlink( void *pvParameters );
void TaskAnalogRead( void *pvParameters );
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
// the setup function runs once when you press reset or power the board
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// Now set up two tasks to run independently.
xTaskCreate(
TaskBlink,
"Blink", // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
NULL,
2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
NULL);
xTaskCreate(
TaskAnalogRead,
"AnalogRead",
128, // Stack size
NULL,
1, // Priority
NULL);
// Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
}
void loop()
{
// Empty. Things are done in Tasks.
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskBlink(void *pvParameters) // This is a task.
{
(void) pvParameters;
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most boards have an on-board LED you can control. You can use it via LED_BUILTIN macro.
If there is no led on board, you can set different pin to blink_pin variable.
*/
// initialize blink_pin as an output.
pinMode(blink_pin, OUTPUT);
for (;;) // A Task shall never return or exit.
{
digitalWrite(blink_pin, HIGH); // turn the pin on (HIGH is the voltage level)
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
digitalWrite(blink_pin, LOW); // turn the pin off by making the voltage LOW
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
}
}
void TaskAnalogRead(void *pvParameters) // This is a task.
{
(void) pvParameters;
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +3V3 and ground.
This example code is in the public domain.
*/
for (;;)
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}

View File

@ -0,0 +1,135 @@
/*
* Example of a basic FreeRTOS queue
* https://www.freertos.org/Embedded-RTOS-Queues.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
// Include queue support
#include <queue.h>
/*
* Declaring a global variable of type QueueHandle_t
*
*/
QueueHandle_t integerQueue;
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
void setup() {
/**
* Create a queue.
* https://www.freertos.org/a00116.html
*/
integerQueue = xQueueCreate(10, // Queue length
sizeof(int) // Queue item size
);
if (integerQueue != NULL) {
// Create task that consumes the queue if it was created.
xTaskCreate(TaskSerial, // Task function
"Serial", // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
NULL,
2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
NULL);
// Create task that publish data in the queue if it was created.
xTaskCreate(TaskAnalogRead, // Task function
"AnalogRead", // Task name
128, // Stack size
NULL,
1, // Priority
NULL);
}
xTaskCreate(TaskBlink, // Task function
"Blink", // Task name
128, // Stack size
NULL,
0, // Priority
NULL );
}
void loop() {}
/**
* Analog read task
* Reads an analog input on pin 0 and send the readed value through the queue.
* See Blink_AnalogRead example.
*/
void TaskAnalogRead(void *pvParameters)
{
(void) pvParameters;
for (;;)
{
// Read the input on analog pin 0:
int sensorValue = analogRead(A0);
/**
* Post an item on a queue.
* https://www.freertos.org/a00117.html
*/
xQueueSend(integerQueue, &sensorValue, portMAX_DELAY);
// One tick delay (10ms) in between reads for stability
vTaskDelay(1);
}
}
/**
* Serial task.
* Prints the received items from the queue to the serial monitor.
*/
void TaskSerial(void * pvParameters) {
(void) pvParameters;
// Init Arduino serial
Serial.begin(9600);
int valueFromQueue = 0;
for (;;)
{
/**
* Read an item from a queue.
* https://www.freertos.org/a00118.html
*/
if (xQueueReceive(integerQueue, &valueFromQueue, portMAX_DELAY) == pdPASS) {
Serial.println(valueFromQueue);
}
}
}
/*
* Blink task.
* See Blink_AnalogRead example.
*/
void TaskBlink(void *pvParameters)
{
(void) pvParameters;
pinMode(blink_pin, OUTPUT);
for (;;)
{
digitalWrite(blink_pin, HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(blink_pin, LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS );
}
}

View File

@ -0,0 +1,90 @@
/*
* Example of a Arduino interruption and RTOS Binary Semaphore
* https://www.freertos.org/Embedded-RTOS-Binary-Semaphores.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
// Include semaphore supoport
#include <semphr.h>
/*
* Declaring a global variable of type SemaphoreHandle_t
*
*/
SemaphoreHandle_t interruptSemaphore;
// set interrupt pin
#ifdef BTN_BUILTIN
uint8_t int_pin = BTN_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t int_pin = P0_8;
#else
uint8_t int_pin = 2;
#endif
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 3;
#endif
void setup() {
// Create task for Arduino led
xTaskCreate(TaskLed, // Task function
"Led", // Task name
128, // Stack size
NULL,
0, // Priority
NULL );
/**
* Create a binary semaphore.
* https://www.freertos.org/xSemaphoreCreateBinary.html
*/
interruptSemaphore = xSemaphoreCreateBinary();
if (interruptSemaphore != NULL) {
// Attach interrupt for Arduino digital pin
attachInterrupt(digitalPinToInterrupt(int_pin), interruptHandler, RISING);
}
}
void loop() {}
void interruptHandler() {
/**
* Give semaphore in the interrupt handler
* https://www.freertos.org/a00124.html
*/
xSemaphoreGiveFromISR(interruptSemaphore, NULL);
}
/*
* Led task.
*/
void TaskLed(void *pvParameters)
{
(void) pvParameters;
pinMode(blink_pin, OUTPUT);
for (;;) {
/**
* Take the semaphore.
* https://www.freertos.org/a00122.html
*/
if (xSemaphoreTake(interruptSemaphore, portMAX_DELAY) == pdPASS) {
digitalWrite(blink_pin, !digitalRead(blink_pin));
}
vTaskDelay(10);
}
}

View File

@ -0,0 +1,80 @@
/*
Example of a FreeRTOS mutex
https://www.freertos.org/Real-time-embedded-RTOS-mutexes.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
// Include mutex support
#include <semphr.h>
/*
Declaring a global variable of type SemaphoreHandle_t
*/
SemaphoreHandle_t mutex;
int globalCount = 0;
int task1Delay = 1250;
int task2Delay = 1000;
void setup() {
Serial.begin(9600);
/**
Create a mutex.
https://www.freertos.org/CreateMutex.html
*/
mutex = xSemaphoreCreateMutex();
if (mutex != NULL) {
Serial.println("Mutex created");
}
/**
Create tasks
*/
xTaskCreate(TaskMutex, // Task function
"Task1", // Task name for humans
128,
&task1Delay, // Task parameter
1, // Task priority
NULL);
xTaskCreate(TaskMutex, "Task2", 128, &task2Delay, 1, NULL);
}
void loop() {}
void TaskMutex(void *pvParameters)
{
TickType_t delayTime = *((TickType_t*)pvParameters); // Use task parameters to define delay
for (;;)
{
/**
Take mutex
https://www.freertos.org/a00122.html
*/
if (xSemaphoreTake(mutex, 10) == pdTRUE)
{
Serial.print(pcTaskGetName(NULL)); // Get task name
Serial.print(", Count read value: ");
Serial.print(globalCount);
globalCount++;
Serial.print(", Updated value: ");
Serial.print(globalCount);
Serial.println();
/**
Give mutex
https://www.freertos.org/a00123.html
*/
xSemaphoreGive(mutex);
}
vTaskDelay(delayTime / portTICK_PERIOD_MS);
}
}

View File

@ -0,0 +1,61 @@
/**
Example of a Arduino interruption and RTOS Task Notification.
https://www.freertos.org/RTOS_Task_Notification_As_Binary_Semaphore.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
/**
Declaring a global TaskHandle for the led task.
*/
TaskHandle_t taskNotificationHandler;
// set interrupt pin
#ifdef BTN_BUILTIN
uint8_t int_pin = BTN_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t int_pin = P0_8;
#else
uint8_t int_pin = 2;
#endif
void setup() {
// Create task for FreeRTOS notification
xTaskCreate(TaskNotification, // Task function
"Notification", // Task name
128, // Stack size
NULL,
3, // Priority
&taskNotificationHandler); // TaskHandle
}
void loop() {
}
/*
Notification task.
*/
void TaskNotification(void *pvParameters)
{
(void) pvParameters;
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(int_pin), digitalPinInterruptHandler, RISING);
for (;;) {
if (ulTaskNotifyTake(pdTRUE, portMAX_DELAY)) {
Serial.println("Notification received");
}
}
}
void digitalPinInterruptHandler() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(taskNotificationHandler, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

View File

@ -0,0 +1,149 @@
/*
* Example of a basic FreeRTOS queue
* https://www.freertos.org/Embedded-RTOS-Queues.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
// Include queue support
#include <queue.h>
// Define a Structure Array
struct Arduino{
int pin[2];
int ReadValue[2];
};
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
//Function Declaration
void Blink(void *pvParameters);
void POT(void *pvParameters);
void TaskSerial(void *pvParameters);
/*
* Declaring a global variable of type QueueHandle_t
*
*/
QueueHandle_t structArrayQueue;
void setup() {
/**
* Create a queue.
* https://www.freertos.org/a00116.html
*/
structArrayQueue=xQueueCreate(10, // Queue length
sizeof(struct Arduino)); // Queue item size
if(structArrayQueue!=NULL){
xTaskCreate(TaskBlink, // Task function
"Blink", // Task name
128, // Stack size
NULL,
0, // Priority
NULL);
// Create other task that publish data in the queue if it was created.
xTaskCreate(POT, // Task function
"AnalogRead", // Task name
128, // Stack size
NULL,
2, // Priority
NULL);
// Create task that consumes the queue if it was created.
xTaskCreate(TaskSerial, // Task function
"PrintSerial",// A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
NULL,
1, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
NULL);
}
}
void loop() {}
/*
* Blink task.
* See Blink_AnalogRead example.
*/
void TaskBlink(void *pvParameters){
(void) pvParameters;
pinMode(blink_pin,OUTPUT);
for(;;)
{
digitalWrite(blink_pin,HIGH);
vTaskDelay(250/portTICK_PERIOD_MS);
digitalWrite(blink_pin,LOW);
vTaskDelay(250/portTICK_PERIOD_MS);
}
}
/**
* Analog read task for Pin A0 and A1
* Reads an analog input on pin 0 and pin 1
* Send the readed value through the queue.
* See Blink_AnalogRead example.
*/
void POT(void *pvParameters){
(void) pvParameters;
pinMode(A0,INPUT);
pinMode(A1,INPUT);
for (;;){
// Read the input on analog pin 0:
struct Arduino currentVariable;
currentVariable.pin[0]=0;
currentVariable.pin[1]=1;
currentVariable.ReadValue[0]=analogRead(A0);
currentVariable.ReadValue[1]=analogRead(A1);
/**
* Post an item on a queue.
* https://www.freertos.org/a00117.html
*/
xQueueSend(structArrayQueue,&currentVariable,portMAX_DELAY);
// One tick delay (10ms) in between reads for stability
vTaskDelay(1);
}
}
/**
* Serial task.
* Prints the received items from the queue to the serial monitor.
*/
void TaskSerial(void *pvParameters){
(void) pvParameters;
// Init Arduino serial
Serial.begin(9600);
for (;;){
struct Arduino currentVariable;
/**
* Read an item from a queue.
* https://www.freertos.org/a00118.html
*/
if(xQueueReceive(structArrayQueue,&currentVariable,portMAX_DELAY) == pdPASS ){
for(int i=0; i<2; i++){
Serial.print("PIN:");
Serial.println(currentVariable.pin[i]);
Serial.print("value:");
Serial.println(currentVariable.ReadValue[i]);
}
}
vTaskDelay(500/portTICK_PERIOD_MS);
}
}

View File

@ -0,0 +1,183 @@
/*
* Example of a basic FreeRTOS queue
* https://www.freertos.org/Embedded-RTOS-Queues.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
// Include queue support
#include <queue.h>
// Define a struct
struct pinRead {
int pin;
int value;
};
/*
* Declaring a global variable of type QueueHandle_t
*
*/
QueueHandle_t structQueue;
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
void setup() {
/**
* Create a queue.
* https://www.freertos.org/a00116.html
*/
structQueue = xQueueCreate(10, // Queue length
sizeof(struct pinRead) // Queue item size
);
if (structQueue != NULL) {
// Create task that consumes the queue if it was created.
xTaskCreate(TaskSerial, // Task function
"Serial", // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
NULL,
2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
NULL);
// Create task that publish data in the queue if it was created.
xTaskCreate(TaskAnalogReadPin0, // Task function
"AnalogReadPin0", // Task name
128, // Stack size
NULL,
1, // Priority
NULL);
// Create other task that publish data in the queue if it was created.
xTaskCreate(TaskAnalogReadPin1, // Task function
"AnalogReadPin1", // Task name
128, // Stack size
NULL,
1, // Priority
NULL);
}
xTaskCreate(TaskBlink, // Task function
"Blink", // Task name
128, // Stack size
NULL,
0, // Priority
NULL );
}
void loop() {}
/**
* Analog read task for Pin A0
* Reads an analog input on pin 0 and send the readed value through the queue.
* See Blink_AnalogRead example.
*/
void TaskAnalogReadPin0(void *pvParameters)
{
(void) pvParameters;
for (;;)
{
// Read the input on analog pin 0:
struct pinRead currentPinRead;
currentPinRead.pin = 0;
currentPinRead.value = analogRead(A0);
/**
* Post an item on a queue.
* https://www.freertos.org/a00117.html
*/
xQueueSend(structQueue, &currentPinRead, portMAX_DELAY);
// One tick delay (10ms) in between reads for stability
vTaskDelay(1);
}
}
/**
* Analog read task for Pin A1
* Reads an analog input on pin 1 and send the readed value through the queue.
* See Blink_AnalogRead example.
*/
void TaskAnalogReadPin1(void *pvParameters)
{
(void) pvParameters;
for (;;)
{
// Read the input on analog pin 1:
struct pinRead currentPinRead;
currentPinRead.pin = 1;
currentPinRead.value = analogRead(A1);
/**
* Post an item on a queue.
* https://www.freertos.org/a00117.html
*/
xQueueSend(structQueue, &currentPinRead, portMAX_DELAY);
// One tick delay (10ms) in between reads for stability
vTaskDelay(1);
}
}
/**
* Serial task.
* Prints the received items from the queue to the serial monitor.
*/
void TaskSerial(void * pvParameters) {
(void) pvParameters;
// Init Arduino serial
Serial.begin(9600);
for (;;)
{
struct pinRead currentPinRead;
/**
* Read an item from a queue.
* https://www.freertos.org/a00118.html
*/
if (xQueueReceive(structQueue, &currentPinRead, portMAX_DELAY) == pdPASS) {
Serial.print("Pin: ");
Serial.print(currentPinRead.pin);
Serial.print(" Value: ");
Serial.println(currentPinRead.value);
}
}
}
/*
* Blink task.
* See Blink_AnalogRead example.
*/
void TaskBlink(void *pvParameters)
{
(void) pvParameters;
pinMode(blink_pin, OUTPUT);
for (;;)
{
digitalWrite(blink_pin, HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(blink_pin, LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS );
}
}

View File

@ -0,0 +1,89 @@
#include <Arduino_FreeRTOS.h>
//define task handles
TaskHandle_t TaskBlink_Handler;
TaskHandle_t TaskSerial_Handler;
// define two tasks for Blink & Serial
void TaskBlink( void *pvParameters );
void TaskSerial(void* pvParameters);
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
// the setup function runs once when you press reset or power the board
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// Now set up two tasks to run independently.
xTaskCreate(
TaskBlink,
"Blink", // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
NULL, // Parameters passed to the task function
2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
&TaskBlink_Handler); // Task handle
xTaskCreate(
TaskSerial,
"Serial",
128, // Stack size
NULL, // Parameters passed to the task function
1, // Priority
&TaskSerial_Handler); // Task handle
}
void loop()
{
// Empty. Things are done in Tasks.
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskSerial(void* pvParameters){
/*
Serial
Send "s" or "r" through the serial port to control the suspend and resume of the LED light task.
This example code is in the public domain.
*/
(void) pvParameters;
for (;;) // A Task shall never return or exit.
{
while(Serial.available()>0){
switch(Serial.read()){
case 's':
vTaskSuspend(TaskBlink_Handler);
Serial.println("Suspend!");
break;
case 'r':
vTaskResume(TaskBlink_Handler);
Serial.println("Resume!");
break;
}
vTaskDelay(1);
}
}
}
void TaskBlink(void *pvParameters) // This is a task.
{
(void) pvParameters;
pinMode(blink_pin, OUTPUT);
for (;;) // A Task shall never return or exit.
{
digitalWrite(blink_pin, HIGH); // turn the pin on (HIGH is the voltage level)
vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second
digitalWrite(blink_pin, LOW); // turn the pin off by making the voltage LOW
vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second
}
}

View File

@ -0,0 +1,155 @@
/*
* Example of FreeRTOS task utilities
* https://www.freertos.org/a00021.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
/**
* Task handlers
* https://www.freertos.org/a00019.html#xTaskHandle
*/
TaskHandle_t taskBlinkHandle;
TaskHandle_t taskDeletedHandle;
TaskHandle_t taskBlockedHandle;
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
void setup() {
/**
* Task creation
*/
xTaskCreate(TaskBlink, // Task function
"Blink", // Task name
128, // Stack size
NULL,
0, // Priority
&taskBlinkHandle); // Task handler
xTaskCreate(TaskSerial,
"Serial",
128,
NULL,
2,
NULL);
xTaskCreate(TaskDeleted,
"Deleted",
64,
NULL,
1,
&taskDeletedHandle);
xTaskCreate(TaskBlocked,
"Blocked",
64,
NULL,
1,
&taskBlockedHandle);
}
void loop() {}
/**
* Example of utilities usage
*/
void TaskSerial(void *pvParameters)
{
(void) pvParameters;
Serial.begin(9600);
for (;;)
{
Serial.println("======== Tasks status ========");
Serial.print("Tick count: ");
Serial.print(xTaskGetTickCount());
Serial.print(", Task count: ");
Serial.print(uxTaskGetNumberOfTasks());
Serial.println();
Serial.println();
// Serial task status
Serial.print("- TASK ");
Serial.print(pcTaskGetName(NULL)); // Get task name without handler https://www.freertos.org/a00021.html#pcTaskGetName
Serial.print(", High Watermark: ");
Serial.print(uxTaskGetStackHighWaterMark(NULL)); // https://www.freertos.org/uxTaskGetStackHighWaterMark.html
TaskHandle_t taskSerialHandle = xTaskGetCurrentTaskHandle(); // Get current task handle. https://www.freertos.org/a00021.html#xTaskGetCurrentTaskHandle
Serial.println();
Serial.print("- TASK ");
Serial.print(pcTaskGetName(taskBlinkHandle)); // Get task name with handler
Serial.print(", High Watermark: ");
Serial.print(uxTaskGetStackHighWaterMark(taskBlinkHandle));
Serial.println();
Serial.print("- TASK ");
Serial.print(pcTaskGetName(taskDeletedHandle));
Serial.print(", High Watermark: ");
Serial.print(uxTaskGetStackHighWaterMark(taskDeletedHandle));
Serial.println();
Serial.print("- TASK ");
Serial.print(pcTaskGetName(taskBlockedHandle));
Serial.print(", High Watermark: ");
Serial.print(uxTaskGetStackHighWaterMark(taskBlockedHandle));
Serial.println();
Serial.println();
vTaskDelay( 5000 / portTICK_PERIOD_MS );
}
}
/**
* Blocked tasks when run
*/
void TaskBlocked(void *pvParameters) {
(void) pvParameters;
for (;;)
{
vTaskDelay( 900000 / portTICK_PERIOD_MS );
}
}
/**
* Deleted tasks when run
*/
void TaskDeleted(void *pvParameters) {
(void) pvParameters;
vTaskDelete(NULL);
}
/*
* Blink task.
* See Blink_AnalogRead example.
*/
void TaskBlink(void *pvParameters)
{
(void) pvParameters;
pinMode(blink_pin, OUTPUT);
for (;;)
{
digitalWrite(blink_pin, HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(blink_pin, LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS );
}
}

View File

@ -0,0 +1,60 @@
# Syntax Coloring Map For FreeRTOS
# https://arduino.github.io/arduino-cli/library-specification/#keywords
# Formatted by a single true tab (not spaces)
# Datatypes (KEYWORD1)
StackType_t KEYWORD1
BaseType_t KEYWORD1
UBaseType_t KEYWORD1
TickType_t KEYWORD1
TaskHandle_t KEYWORD1
QueueHandle_t KEYWORD1
TimerHandle_t KEYWORD1
SemaphoreHandle_t KEYWORD1
StreamBufferHandle_t KEYWORD1
MessageBufferHandle_t KEYWORD1
EventGroupHandle_t KEYWORD1
# Methods and Functions (KEYWORD2)
xSemaphoreCreateMutex KEYWORD2
xSemaphoreCreateBinary KEYWORD2
xSemaphoreTake KEYWORD2
xSemaphoreTakeFromISR KEYWORD2
xSemaphoreGive KEYWORD2
xSemaphoreGiveFromISR KEYWORD2
xTaskCreate KEYWORD2
vTaskDelete KEYWORD2
vTaskDelay KEYWORD2
xTaskDelayUntil KEYWORD2
xQueueCreate KEYWORD2
xQueueSend KEYWORD2
xQueueReceive KEYWORD2
pcTaskGetName KEYWORD2
ulTaskNotifyTake KEYWORD2
vTaskNotifyGiveFromISR KEYWORD2
taskYIELD KEYWORD2
vTaskSuspend KEYWORD2
vTaskResume KEYWORD2
xTaskResumeFromISR KEYWORD2
xTaskGetTickCount KEYWORD2
xTaskGetTickCountFromISR KEYWORD2
uxTaskGetNumberOfTasks KEYWORD2
uxTaskGetStackHighWaterMark KEYWORD2
# Instances (KEYWORD2)
# Structures (KEYWORD3)
TaskParameters_t KEYWORD3
TaskStatus_t KEYWORD3
ListItem_t KEYWORD3
MiniListItem_t KEYWORD3
HeapStats_t KEYWORD3
# Constants (LITERAL1)
portUSE_WDTO LITERAL1
portTICK_PERIOD_MS LITERAL1
configTICK_RATE_HZ LITERAL1
configCPU_CLOCK_HZ LITERAL1
configMAX_PRIORITIES LITERAL1
configMINIMAL_STACK_SIZE LITERAL1

View File

@ -0,0 +1,11 @@
name=FreeRTOS
version=11.1.0-3
author=Richard Barry <info@freertos.org>
maintainer=Phillip Stevens <phillip.stevens@gmail.com>
sentence=FreeRTOS Real Time Operating System implemented for Arduino devices.
paragraph=The primary design goals are: Easy to use, Small footprint, Robust. Uses SysTick for 10ms resolution. Slow blink = stack overflow. Fast blink = heap malloc() failure.
category=Timing
url=https://github.com/feilipu/Arduino_FreeRTOS_Library
architectures=MIK32_Amur
license=MIT
includes=Arduino_FreeRTOS.h

View File

@ -0,0 +1,126 @@
This is a fork of Richard Barry's FreeRTOS, optimised for the Arduino Microchip ATmega devices.
It has been created to provide access to FreeRTOS capabilities, with full compatibility to the Arduino IDE environment.
It does this by keeping hands off almost everything, and only touching the minimum of hardware to be successful.
If you want to use FreeRTOS on the Renesas family of Arduino like the Arduino UNO R4, it is [already included](https://github.com/arduino/ArduinoCore-renesas/tree/main/libraries/Arduino_FreeRTOS) in the default Arduino IDE. All that is required is to include the header file `Arduino_FreeRTOS.h` provided by the Arduino IDE, and follow the information noted below.
## Usage & Further Reading
Read the short blog post on [Arduino FreeRTOS](https://feilipu.me/2015/11/24/arduino_freertos/) to get started. And there is another much older post on using [FreeRTOS with AVR](https://feilipu.me/2011/09/22/freertos-and-libraries-for-avr-atmega/), which may be useful to read too. There are some further posts I've written on [Hackster.IO](https://www.hackster.io/feilipu), but they're essentially the same content.
The canonical source for information is the [FreeRTOS Web Site](https://www.freertos.org/). Within this site, the [Getting Started](https://www.freertos.org/FreeRTOS-quick-start-guide.html) page is very useful. This is the source for FreeRTOS usage (as distinct from installing and using this Arduino Library).
My other [AVRfreeRTOS Sourceforge Repository](https://sourceforge.net/projects/avrfreertos/) or [AVRfreeRTOS Github](https://github.com/feilipu/avrfreertos) has plenty of examples, ranging from [blink](https://sourceforge.net/projects/avrfreertos/files/MegaBlink/) through to a [synthesiser](https://sourceforge.net/projects/avrfreertos/files/GA_Synth/).
This library was the genesis of [generalised support for the ATmega platform within FreeRTOS](https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/48), and improvement of the [stack depth type management](https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/942).
Over the past few years FreeRTOS development has become increasingly 32-bit orientated, now including symmetric multiprocessing, with little change or improvement for the 8-bit world. As such I'm treating this FreeRTOS V11.1.0 (updated April 22 2024) as my LTS release.
## General
FreeRTOS has a multitude of configuration options, which can be specified from within the FreeRTOSConfig.h file.
To keep commonality with all of the Arduino hardware options, some sensible defaults have been selected. Feel free to change these defaults as you gain experience with FreeRTOS.
Normally, the ATmega Watchdog Timer is used to generate 15ms time slices (Ticks). For applications requiring high precision timing, the Ticks can be sourced from a hardware timer or external clock. See chapter [Scheduler Tick Sources](./doc/tick_sources.md) for the configuration details.
Tasks that suspend or delay before their allocated time slice completes will revert execution back to the Scheduler.
The Arduino `delay()` function has been redefined to automatically use the FreeRTOS `vTaskDelay()` function when the delay required is one Tick or longer, by setting `configUSE_PORT_DELAY` to `1`, so that simple Arduino example sketches and tutorials work as expected. If you would like to measure a short millisecond delay of less than one Tick, then preferably use [`millis()`](https://www.arduino.cc/reference/en/language/functions/time/millis/) (or with greater granularity use [`micros()`](https://www.arduino.cc/reference/en/language/functions/time/micros/)) to achieve this outcome (for example see [BlinkWithoutDelay](https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay)). However, when the delay requested is less than one Tick then the original Arduino `delay()` function will be automatically selected.
The 8-bit ATmega Timer0 has been added as an option for the experienced user. Please examine the Timer0 source code example to figure out how to use it. Reconfiguring Timer0 for the FreeRTOS Tick will break Arduino `millis()` and `micros()` though, as these functions rely on the Arduino IDE configuring Timer0. Example support for the Logic Green hardware using Timer 3 is provided via an open PR.
Stack for the `loop()` function has been set at 192 Bytes. This can be configured by adjusting the `configMINIMAL_STACK_SIZE` parameter. If you have stack overflow issues just increase it (within the SRAM limitations of your hardware). Users should prefer to allocate larger structures, arrays, or buffers on the heap using `pvPortMalloc()`, rather than defining them locally on the stack. Ideally you should __not__ use `loop()` for your sketches, and then the Idle Task stack size can be reduced down to 92 Bytes which will save some valuable memory.
Memory for the heap is allocated by the normal C `malloc()` function, wrapped by the FreeRTOS `pvPortMalloc()` function. This option has been selected because it is automatically adjusted to use the capabilities of each device. Other heap allocation schemes are supported by FreeRTOS, and they can used with some additional configuration.
If you do not need to use FreeRTOS Timer API functions, then they can be disabled. This will remove the need for the Timer Task Stack, saving 92 Bytes of RAM.
## Upgrading
* [Upgrading to FreeRTOS-9](https://www.freertos.org/FreeRTOS-V9.html)
* [Upgrading to FreeRTOS-10](https://www.freertos.org/FreeRTOS-V10.html)
* [Symmetric Multiprocessing with FreeRTOS-11](https://www.freertos.org/2023/12/introducing-freertos-kernel-version-11-0-0-a-major-release-with-symmetric-multiprocessing-smp-support.html)
## Errors
* Stack Overflow: If any stack (for the `loop()` or) for any Task overflows, there will be a slow LED blink, with 4 second cycle.
* Heap Overflow: If any Task tries to allocate memory and that allocation fails, there will be a fast LED blink, with 100 millisecond cycle.
## Errata
Testing with the Software Serial library shows some incompatibilities at low baud rates (9600), due to the extended time this library disables the global interrupt. Use the hardware USARTs.
## Compatibility
* ATmega328 @ 16MHz : Arduino UNO R3, Arduino Duemilanove, Arduino Diecimila, etc.
* ATmega328 @ 16MHz : Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini
* ATmega328 @ 16MHz : Seeed Studio Stalker
* ATmega328 @ 16MHz : Freetronics Eleven
* ATmega328 @ 12MHz : Adafruit Pro Trinket 3V
* ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0
* ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro
* ATmega1284p @ 16MHz: Sanguino, WickedDevice WildFire
* ATmega1284p @ 24.576MHz : Seeed Studio Goldilocks Analogue
* ATmega2560 @ 16MHz : Arduino Mega, Arduino ADK
* ATmega2560 @ 16MHz : Seeed Studio ADK
The new megaAVR 0-Series devices (eg. ATmega4809) are not fully compatible with this library. Their Timer configuration is substantially different from previous devices, and forms part of a new __avr8x__ architecture. It may be a while until avr-libc is updated to include support for megaAVR devices, but when that happens further work will be added here.
The Arduino IDE supporting the Arduino UNO R4 already includes FreeRTOS as standard.
## Files & Configuration
* `Arduino_FreeRTOS.h` : Must always be `#include` first. It references other configuration files, and sets defaults where necessary.
* `FreeRTOSConfig.h` : Contains a multitude of API and environment configurations.
* `FreeRTOSVariant.h` : Contains the ATmega specific configurations for this port of FreeRTOS.
* `heap_3.c` : Contains the heap allocation scheme based on `malloc()`. Other schemes are available, but depend on user configuration for specific MCU choice.
### PlatformIO
[Arduino FreeRTOS](https://platformio.org/lib/show/507/FreeRTOS) is available in the [PlatformIO library manager](https://docs.platformio.org/en/latest/librarymanager/index.html) for use in a [PlatformIO project](https://docs.platformio.org/en/latest/projectconf/index.html).
Watchdog period is configurable using build-flags:
```python
build_flags =
-DportUSE_WDTO=WDTO_15MS
```
### Code of conduct
See the [Code of conduct](https://github.com/feilipu/Arduino_FreeRTOS_Library/blob/master/CODE_OF_CONDUCT.md).
## Contributors ✨
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-10-green.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://feilipu.me/"><img src="https://avatars.githubusercontent.com/u/3955592" width="100px;" alt=""/><br /><sub><b>Phillip Stevens</b></sub></a><br /><a title="Maintenance">🚧</a><a title="Code">💻</a><a title="Reviewed Pull Requests">👀</a><a title=Documentation">📖</a></td>
<td align="center"><a href="https://www.blackleg.es/"><img src="https://avatars.githubusercontent.com/u/4323228" width="100px;" alt=""/><br /><sub><b>Hector Espert</b></sub></a><br /><a title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Floessie"><img src="https://avatars.githubusercontent.com/u/10133457" width="100px;" alt=""/><br /><sub><b>Floessie</b></sub></a><br /><a title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Derekduke"><img src="https://avatars.githubusercontent.com/u/30068270" width="100px;" alt=""/><br /><sub><b>Derekduke</b></sub></a><br /><a title="Code">💻</a></td>
<td align="center"><a href="https://github.com/balaji"><img src="https://avatars.githubusercontent.com/u/29356302" width="100px;" alt=""/><br /><sub><b>Balaji.V</b></sub></a><br /><a title="Code">💻</a><a title=Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/neboskreb"><img src="https://avatars.githubusercontent.com/u/35344069" width="100px;" alt=""/><br /><sub><b>John Y. Pazekha</b></sub></a><br /><a title="Code">💻</a><a title=Documentation">📖</a></td>
<td align="center"><a href="https://github.com/gpb01"><img src="https://avatars.githubusercontent.com/u/4134059" width="100px;" alt=""/><br /><sub><b>Guglielmo Braguglia</b></sub></a><br /><a title="Code">💻</a><a title=Documentation">📖</a></td>
<td align="center"><a href="https://github.com/ShortArrow"><img src="https://avatars.githubusercontent.com/u/16986253" width="100px;" alt=""/><br /><sub><b>ShortArrow</b></sub></a><br /><a title=Documentation">📖</a></td>
<td align="center"><a href="https://github.com/altugbakan"><img src="https://avatars.githubusercontent.com/u/43248015" width="100px;" alt=""/><br /><sub><b>Altuğ Bakan</b></sub></a><br /><a title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ikatz-drizly"><img src="https://avatars.githubusercontent.com/u/87482555" width="100px;" alt=""/><br /><sub><b>Ian Katz</b></sub></a><br /><a title="Code">💻</a></td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,124 @@
/*
* Copyright (C) 2023, Syntacore Ltd.
* All Rights Reserved.
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "mcu32_memory_map.h"
#ifdef __cplusplus
}
#endif
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See https://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configMTIME_BASE_ADDRESS (SCR1_TIMER_BASE_ADDRESS + 0x8) // from scr1 core docs
#define configMTIMECMP_BASE_ADDRESS (SCR1_TIMER_BASE_ADDRESS + 0x10) // from scr1 core docs
/* Delay definition - here, the user can choose which delay implementation is required.
* The default is to change nothing. */
#define configUSE_PREEMPTION 1
#define configCPU_CLOCK_HZ ( ( uint32_t ) F_CPU ) // This F_CPU variable set by the environment
#define configTICK_RATE_HZ ( ( TickType_t ) 100 )
#define configMAX_PRIORITIES 4
#define configMINIMAL_STACK_SIZE 128
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configQUEUE_REGISTRY_SIZE 0
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 1
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_PORT_DELAY 0
/* Set the stack depth type to be uint16_t, otherwise it defaults to StackType_t */
#define configSTACK_DEPTH_TYPE uint16_t
/* Memory allocation related definitions. */
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configSUPPORT_STATIC_ALLOCATION 0
#define configTOTAL_HEAP_SIZE ( ( size_t ) 5*1024 )
/* don't define to reuse the stack allocated in the linker script via __freertos_irq_stack_top variable*/
// #define configISR_STACK_SIZE_WORDS 128
/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_MALLOC_FAILED_HOOK 1
/* Run time and task stats gathering related definitions. */
#define configUSE_TRACE_FACILITY 0
/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES-1 )
#define configTIMER_TASK_STACK_DEPTH 92
#define configTIMER_QUEUE_LENGTH 10
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
/* Set the following INCLUDE_* constants to 1 to incldue the named API function,
* or 0 to exclude the named API function. Most linkers will remove unused
* functions even when the constant is 1. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xTaskResumeFromISR 1
#define INCLUDE_xTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 0
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 0
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0
#define configMAX(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
#define configMIN(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
/**
* configASSERT macro: https://www.freertos.org/a00110.html#configASSERT
*/
#ifndef configASSERT
#define configDEFAULT_ASSERT 0
#else
/**
* Enable configASSERT macro if it is defined.
*/
#ifndef configDEFAULT_ASSERT
#define configDEFAULT_ASSERT 1
#endif
/**
* Define a hook method for configASSERT macro if configASSERT is enabled.
*/
#if configDEFAULT_ASSERT == 1
extern void vApplicationAssertHook();
#define configASSERT( x ) if (( x ) == 0) { vApplicationAssertHook(); }
#endif
#endif
#endif /* FREERTOS_CONFIG_H */

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2024 Phillip Stevens All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* This file is NOT part of the FreeRTOS distribution.
*
*/
#ifndef freeRTOSVariant_h
#define freeRTOSVariant_h
#ifndef INC_TASK_H
#include "Arduino_FreeRTOS.h"
#include "task.h"
#endif
void initVariant(void);
/*-----------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
void vApplicationIdleHook( void );
void vApplicationMallocFailedHook( void );
void vApplicationStackOverflowHook( TaskHandle_t xTask, char * pcTaskName );
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
configSTACK_DEPTH_TYPE * puxIdleTaskStackSize );
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
configSTACK_DEPTH_TYPE * puxTimerTaskStackSize );
#ifdef __cplusplus
}
#endif
#endif // freeRTOSVariant_h

View File

@ -0,0 +1,19 @@
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,884 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/* Standard includes. */
#include <stdlib.h>
/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
* all the API functions to use the MPU wrappers. That should only be done when
* task.h is included from an application file. */
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
/* FreeRTOS includes. */
#include "Arduino_FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "event_groups.h"
/* The MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
* for the header files above, but not in this file, in order to generate the
* correct privileged Vs unprivileged linkage and placement. */
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
/* This entire source file will be skipped if the application is not configured
* to include event groups functionality. This #if is closed at the very bottom
* of this file. If you want to include event groups then ensure
* configUSE_EVENT_GROUPS is set to 1 in FreeRTOSConfig.h. */
#if ( configUSE_EVENT_GROUPS == 1 )
typedef struct EventGroupDef_t
{
EventBits_t uxEventBits;
List_t xTasksWaitingForBits; /**< List of tasks waiting for a bit to be set. */
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxEventGroupNumber;
#endif
#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
uint8_t ucStaticallyAllocated; /**< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */
#endif
} EventGroup_t;
/*-----------------------------------------------------------*/
/*
* Test the bits set in uxCurrentEventBits to see if the wait condition is met.
* The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is
* pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor
* are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the
* wait condition is met if any of the bits set in uxBitsToWait for are also set
* in uxCurrentEventBits.
*/
static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
const EventBits_t uxBitsToWaitFor,
const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION;
/*-----------------------------------------------------------*/
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer )
{
EventGroup_t * pxEventBits;
traceENTER_xEventGroupCreateStatic( pxEventGroupBuffer );
/* A StaticEventGroup_t object must be provided. */
configASSERT( pxEventGroupBuffer );
#if ( configASSERT_DEFINED == 1 )
{
/* Sanity check that the size of the structure used to declare a
* variable of type StaticEventGroup_t equals the size of the real
* event group structure. */
volatile size_t xSize = sizeof( StaticEventGroup_t );
configASSERT( xSize == sizeof( EventGroup_t ) );
}
#endif /* configASSERT_DEFINED */
/* The user has provided a statically allocated event group - use it. */
/* MISRA Ref 11.3.1 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer;
if( pxEventBits != NULL )
{
pxEventBits->uxEventBits = 0;
vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
{
/* Both static and dynamic allocation can be used, so note that
* this event group was created statically in case the event group
* is later deleted. */
pxEventBits->ucStaticallyAllocated = pdTRUE;
}
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
traceEVENT_GROUP_CREATE( pxEventBits );
}
else
{
/* xEventGroupCreateStatic should only ever be called with
* pxEventGroupBuffer pointing to a pre-allocated (compile time
* allocated) StaticEventGroup_t variable. */
traceEVENT_GROUP_CREATE_FAILED();
}
traceRETURN_xEventGroupCreateStatic( pxEventBits );
return pxEventBits;
}
#endif /* configSUPPORT_STATIC_ALLOCATION */
/*-----------------------------------------------------------*/
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
EventGroupHandle_t xEventGroupCreate( void )
{
EventGroup_t * pxEventBits;
traceENTER_xEventGroupCreate();
/* MISRA Ref 11.5.1 [Malloc memory assignment] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
/* coverity[misra_c_2012_rule_11_5_violation] */
pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) );
if( pxEventBits != NULL )
{
pxEventBits->uxEventBits = 0;
vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
{
/* Both static and dynamic allocation can be used, so note this
* event group was allocated statically in case the event group is
* later deleted. */
pxEventBits->ucStaticallyAllocated = pdFALSE;
}
#endif /* configSUPPORT_STATIC_ALLOCATION */
traceEVENT_GROUP_CREATE( pxEventBits );
}
else
{
traceEVENT_GROUP_CREATE_FAILED();
}
traceRETURN_xEventGroupCreate( pxEventBits );
return pxEventBits;
}
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
/*-----------------------------------------------------------*/
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet,
const EventBits_t uxBitsToWaitFor,
TickType_t xTicksToWait )
{
EventBits_t uxOriginalBitValue, uxReturn;
EventGroup_t * pxEventBits = xEventGroup;
BaseType_t xAlreadyYielded;
BaseType_t xTimeoutOccurred = pdFALSE;
traceENTER_xEventGroupSync( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTicksToWait );
configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
configASSERT( uxBitsToWaitFor != 0 );
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
{
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
}
#endif
vTaskSuspendAll();
{
uxOriginalBitValue = pxEventBits->uxEventBits;
( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );
if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
{
/* All the rendezvous bits are now set - no need to block. */
uxReturn = ( uxOriginalBitValue | uxBitsToSet );
/* Rendezvous always clear the bits. They will have been cleared
* already unless this is the only task in the rendezvous. */
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
xTicksToWait = 0;
}
else
{
if( xTicksToWait != ( TickType_t ) 0 )
{
traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor );
/* Store the bits that the calling task is waiting for in the
* task's event list item so the kernel knows when a match is
* found. Then enter the blocked state. */
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );
/* This assignment is obsolete as uxReturn will get set after
* the task unblocks, but some compilers mistakenly generate a
* warning about uxReturn being returned without being set if the
* assignment is omitted. */
uxReturn = 0;
}
else
{
/* The rendezvous bits were not set, but no block time was
* specified - just return the current event bit value. */
uxReturn = pxEventBits->uxEventBits;
xTimeoutOccurred = pdTRUE;
}
}
}
xAlreadyYielded = xTaskResumeAll();
if( xTicksToWait != ( TickType_t ) 0 )
{
if( xAlreadyYielded == pdFALSE )
{
taskYIELD_WITHIN_API();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
/* The task blocked to wait for its required bits to be set - at this
* point either the required bits were set or the block time expired. If
* the required bits were set they will have been stored in the task's
* event list item, and they should now be retrieved then cleared. */
uxReturn = uxTaskResetEventItemValue();
if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
{
/* The task timed out, just return the current event bit value. */
taskENTER_CRITICAL();
{
uxReturn = pxEventBits->uxEventBits;
/* Although the task got here because it timed out before the
* bits it was waiting for were set, it is possible that since it
* unblocked another task has set the bits. If this is the case
* then it needs to clear the bits before exiting. */
if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
{
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
taskEXIT_CRITICAL();
xTimeoutOccurred = pdTRUE;
}
else
{
/* The task unblocked because the bits were set. */
}
/* Control bits might be set as the task had blocked should not be
* returned. */
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
}
traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred );
/* Prevent compiler warnings when trace macros are not used. */
( void ) xTimeoutOccurred;
traceRETURN_xEventGroupSync( uxReturn );
return uxReturn;
}
/*-----------------------------------------------------------*/
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToWaitFor,
const BaseType_t xClearOnExit,
const BaseType_t xWaitForAllBits,
TickType_t xTicksToWait )
{
EventGroup_t * pxEventBits = xEventGroup;
EventBits_t uxReturn, uxControlBits = 0;
BaseType_t xWaitConditionMet, xAlreadyYielded;
BaseType_t xTimeoutOccurred = pdFALSE;
traceENTER_xEventGroupWaitBits( xEventGroup, uxBitsToWaitFor, xClearOnExit, xWaitForAllBits, xTicksToWait );
/* Check the user is not attempting to wait on the bits used by the kernel
* itself, and that at least one bit is being requested. */
configASSERT( xEventGroup );
configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
configASSERT( uxBitsToWaitFor != 0 );
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
{
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
}
#endif
vTaskSuspendAll();
{
const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;
/* Check to see if the wait condition is already met or not. */
xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );
if( xWaitConditionMet != pdFALSE )
{
/* The wait condition has already been met so there is no need to
* block. */
uxReturn = uxCurrentEventBits;
xTicksToWait = ( TickType_t ) 0;
/* Clear the wait bits if requested to do so. */
if( xClearOnExit != pdFALSE )
{
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else if( xTicksToWait == ( TickType_t ) 0 )
{
/* The wait condition has not been met, but no block time was
* specified, so just return the current value. */
uxReturn = uxCurrentEventBits;
xTimeoutOccurred = pdTRUE;
}
else
{
/* The task is going to block to wait for its required bits to be
* set. uxControlBits are used to remember the specified behaviour of
* this call to xEventGroupWaitBits() - for use when the event bits
* unblock the task. */
if( xClearOnExit != pdFALSE )
{
uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
if( xWaitForAllBits != pdFALSE )
{
uxControlBits |= eventWAIT_FOR_ALL_BITS;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
/* Store the bits that the calling task is waiting for in the
* task's event list item so the kernel knows when a match is
* found. Then enter the blocked state. */
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );
/* This is obsolete as it will get set after the task unblocks, but
* some compilers mistakenly generate a warning about the variable
* being returned without being set if it is not done. */
uxReturn = 0;
traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor );
}
}
xAlreadyYielded = xTaskResumeAll();
if( xTicksToWait != ( TickType_t ) 0 )
{
if( xAlreadyYielded == pdFALSE )
{
taskYIELD_WITHIN_API();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
/* The task blocked to wait for its required bits to be set - at this
* point either the required bits were set or the block time expired. If
* the required bits were set they will have been stored in the task's
* event list item, and they should now be retrieved then cleared. */
uxReturn = uxTaskResetEventItemValue();
if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
{
taskENTER_CRITICAL();
{
/* The task timed out, just return the current event bit value. */
uxReturn = pxEventBits->uxEventBits;
/* It is possible that the event bits were updated between this
* task leaving the Blocked state and running again. */
if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
{
if( xClearOnExit != pdFALSE )
{
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else
{
mtCOVERAGE_TEST_MARKER();
}
xTimeoutOccurred = pdTRUE;
}
taskEXIT_CRITICAL();
}
else
{
/* The task unblocked because the bits were set. */
}
/* The task blocked so control bits may have been set. */
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
}
traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred );
/* Prevent compiler warnings when trace macros are not used. */
( void ) xTimeoutOccurred;
traceRETURN_xEventGroupWaitBits( uxReturn );
return uxReturn;
}
/*-----------------------------------------------------------*/
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToClear )
{
EventGroup_t * pxEventBits = xEventGroup;
EventBits_t uxReturn;
traceENTER_xEventGroupClearBits( xEventGroup, uxBitsToClear );
/* Check the user is not attempting to clear the bits used by the kernel
* itself. */
configASSERT( xEventGroup );
configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
taskENTER_CRITICAL();
{
traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );
/* The value returned is the event group value prior to the bits being
* cleared. */
uxReturn = pxEventBits->uxEventBits;
/* Clear the bits. */
pxEventBits->uxEventBits &= ~uxBitsToClear;
}
taskEXIT_CRITICAL();
traceRETURN_xEventGroupClearBits( uxReturn );
return uxReturn;
}
/*-----------------------------------------------------------*/
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToClear )
{
BaseType_t xReturn;
traceENTER_xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear );
traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );
xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL );
traceRETURN_xEventGroupClearBitsFromISR( xReturn );
return xReturn;
}
#endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
/*-----------------------------------------------------------*/
EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
{
UBaseType_t uxSavedInterruptStatus;
EventGroup_t const * const pxEventBits = xEventGroup;
EventBits_t uxReturn;
traceENTER_xEventGroupGetBitsFromISR( xEventGroup );
/* MISRA Ref 4.7.1 [Return value shall be checked] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
/* coverity[misra_c_2012_directive_4_7_violation] */
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
{
uxReturn = pxEventBits->uxEventBits;
}
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
traceRETURN_xEventGroupGetBitsFromISR( uxReturn );
return uxReturn;
}
/*-----------------------------------------------------------*/
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet )
{
ListItem_t * pxListItem;
ListItem_t * pxNext;
ListItem_t const * pxListEnd;
List_t const * pxList;
EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
EventGroup_t * pxEventBits = xEventGroup;
BaseType_t xMatchFound = pdFALSE;
traceENTER_xEventGroupSetBits( xEventGroup, uxBitsToSet );
/* Check the user is not attempting to set the bits used by the kernel
* itself. */
configASSERT( xEventGroup );
configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
pxList = &( pxEventBits->xTasksWaitingForBits );
pxListEnd = listGET_END_MARKER( pxList );
vTaskSuspendAll();
{
traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet );
pxListItem = listGET_HEAD_ENTRY( pxList );
/* Set the bits. */
pxEventBits->uxEventBits |= uxBitsToSet;
/* See if the new bit value should unblock any tasks. */
while( pxListItem != pxListEnd )
{
pxNext = listGET_NEXT( pxListItem );
uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem );
xMatchFound = pdFALSE;
/* Split the bits waited for from the control bits. */
uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )
{
/* Just looking for single bit being set. */
if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )
{
xMatchFound = pdTRUE;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )
{
/* All bits are set. */
xMatchFound = pdTRUE;
}
else
{
/* Need all bits to be set, but not all the bits were set. */
}
if( xMatchFound != pdFALSE )
{
/* The bits match. Should the bits be cleared on exit? */
if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )
{
uxBitsToClear |= uxBitsWaitedFor;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
/* Store the actual event flag value in the task's event list
* item before removing the task from the event list. The
* eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows
* that is was unblocked due to its required bits matching, rather
* than because it timed out. */
vTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );
}
/* Move onto the next list item. Note pxListItem->pxNext is not
* used here as the list item may have been removed from the event list
* and inserted into the ready/pending reading list. */
pxListItem = pxNext;
}
/* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT
* bit was set in the control word. */
pxEventBits->uxEventBits &= ~uxBitsToClear;
}
( void ) xTaskResumeAll();
traceRETURN_xEventGroupSetBits( pxEventBits->uxEventBits );
return pxEventBits->uxEventBits;
}
/*-----------------------------------------------------------*/
void vEventGroupDelete( EventGroupHandle_t xEventGroup )
{
EventGroup_t * pxEventBits = xEventGroup;
const List_t * pxTasksWaitingForBits;
traceENTER_vEventGroupDelete( xEventGroup );
configASSERT( pxEventBits );
pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
vTaskSuspendAll();
{
traceEVENT_GROUP_DELETE( xEventGroup );
while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )
{
/* Unblock the task, returning 0 as the event list is being deleted
* and cannot therefore have any bits set. */
configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );
vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );
}
}
( void ) xTaskResumeAll();
#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
{
/* The event group can only have been allocated dynamically - free
* it again. */
vPortFree( pxEventBits );
}
#elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
{
/* The event group could have been allocated statically or
* dynamically, so check before attempting to free the memory. */
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
{
vPortFree( pxEventBits );
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
traceRETURN_vEventGroupDelete();
}
/*-----------------------------------------------------------*/
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
StaticEventGroup_t ** ppxEventGroupBuffer )
{
BaseType_t xReturn;
EventGroup_t * pxEventBits = xEventGroup;
traceENTER_xEventGroupGetStaticBuffer( xEventGroup, ppxEventGroupBuffer );
configASSERT( pxEventBits );
configASSERT( ppxEventGroupBuffer );
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
{
/* Check if the event group was statically allocated. */
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
{
/* MISRA Ref 11.3.1 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
xReturn = pdTRUE;
}
else
{
xReturn = pdFALSE;
}
}
#else /* configSUPPORT_DYNAMIC_ALLOCATION */
{
/* Event group must have been statically allocated. */
/* MISRA Ref 11.3.1 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
xReturn = pdTRUE;
}
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
traceRETURN_xEventGroupGetStaticBuffer( xReturn );
return xReturn;
}
#endif /* configSUPPORT_STATIC_ALLOCATION */
/*-----------------------------------------------------------*/
/* For internal use only - execute a 'set bits' command that was pended from
* an interrupt. */
void vEventGroupSetBitsCallback( void * pvEventGroup,
uint32_t ulBitsToSet )
{
traceENTER_vEventGroupSetBitsCallback( pvEventGroup, ulBitsToSet );
/* MISRA Ref 11.5.4 [Callback function parameter] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
/* coverity[misra_c_2012_rule_11_5_violation] */
( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet );
traceRETURN_vEventGroupSetBitsCallback();
}
/*-----------------------------------------------------------*/
/* For internal use only - execute a 'clear bits' command that was pended from
* an interrupt. */
void vEventGroupClearBitsCallback( void * pvEventGroup,
uint32_t ulBitsToClear )
{
traceENTER_vEventGroupClearBitsCallback( pvEventGroup, ulBitsToClear );
/* MISRA Ref 11.5.4 [Callback function parameter] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
/* coverity[misra_c_2012_rule_11_5_violation] */
( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear );
traceRETURN_vEventGroupClearBitsCallback();
}
/*-----------------------------------------------------------*/
static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
const EventBits_t uxBitsToWaitFor,
const BaseType_t xWaitForAllBits )
{
BaseType_t xWaitConditionMet = pdFALSE;
if( xWaitForAllBits == pdFALSE )
{
/* Task only has to wait for one bit within uxBitsToWaitFor to be
* set. Is one already set? */
if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )
{
xWaitConditionMet = pdTRUE;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else
{
/* Task has to wait for all the bits in uxBitsToWaitFor to be set.
* Are they set already? */
if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
{
xWaitConditionMet = pdTRUE;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
return xWaitConditionMet;
}
/*-----------------------------------------------------------*/
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet,
BaseType_t * pxHigherPriorityTaskWoken )
{
BaseType_t xReturn;
traceENTER_xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken );
traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );
xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken );
traceRETURN_xEventGroupSetBitsFromISR( xReturn );
return xReturn;
}
#endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
/*-----------------------------------------------------------*/
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxEventGroupGetNumber( void * xEventGroup )
{
UBaseType_t xReturn;
/* MISRA Ref 11.5.2 [Opaque pointer] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
/* coverity[misra_c_2012_rule_11_5_violation] */
EventGroup_t const * pxEventBits = ( EventGroup_t * ) xEventGroup;
traceENTER_uxEventGroupGetNumber( xEventGroup );
if( xEventGroup == NULL )
{
xReturn = 0;
}
else
{
xReturn = pxEventBits->uxEventGroupNumber;
}
traceRETURN_uxEventGroupGetNumber( xReturn );
return xReturn;
}
#endif /* configUSE_TRACE_FACILITY */
/*-----------------------------------------------------------*/
#if ( configUSE_TRACE_FACILITY == 1 )
void vEventGroupSetNumber( void * xEventGroup,
UBaseType_t uxEventGroupNumber )
{
traceENTER_vEventGroupSetNumber( xEventGroup, uxEventGroupNumber );
/* MISRA Ref 11.5.2 [Opaque pointer] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
/* coverity[misra_c_2012_rule_11_5_violation] */
( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber;
traceRETURN_vEventGroupSetNumber();
}
#endif /* configUSE_TRACE_FACILITY */
/*-----------------------------------------------------------*/
/* This entire source file will be skipped if the application is not configured
* to include event groups functionality. If you want to include event groups
* then ensure configUSE_EVENT_GROUPS is set to 1 in FreeRTOSConfig.h. */
#endif /* configUSE_EVENT_GROUPS == 1 */

View File

@ -0,0 +1,857 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef EVENT_GROUPS_H
#define EVENT_GROUPS_H
#ifndef INC_ARDUINO_FREERTOS_H
#error "include Arduino_FreeRTOS.h" must appear in source files before "include event_groups.h"
#endif
/* FreeRTOS includes. */
#include "timers.h"
/* The following bit fields convey control information in a task's event list
* item value. It is important they don't clash with the
* taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */
#if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
#define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint16_t ) 0x0100U )
#define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint16_t ) 0x0200U )
#define eventWAIT_FOR_ALL_BITS ( ( uint16_t ) 0x0400U )
#define eventEVENT_BITS_CONTROL_BYTES ( ( uint16_t ) 0xff00U )
#elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
#define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint32_t ) 0x01000000U )
#define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint32_t ) 0x02000000U )
#define eventWAIT_FOR_ALL_BITS ( ( uint32_t ) 0x04000000U )
#define eventEVENT_BITS_CONTROL_BYTES ( ( uint32_t ) 0xff000000U )
#elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS )
#define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint64_t ) 0x0100000000000000U )
#define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint64_t ) 0x0200000000000000U )
#define eventWAIT_FOR_ALL_BITS ( ( uint64_t ) 0x0400000000000000U )
#define eventEVENT_BITS_CONTROL_BYTES ( ( uint64_t ) 0xff00000000000000U )
#endif /* if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS ) */
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/**
* An event group is a collection of bits to which an application can assign a
* meaning. For example, an application may create an event group to convey
* the status of various CAN bus related events in which bit 0 might mean "A CAN
* message has been received and is ready for processing", bit 1 might mean "The
* application has queued a message that is ready for sending onto the CAN
* network", and bit 2 might mean "It is time to send a SYNC message onto the
* CAN network" etc. A task can then test the bit values to see which events
* are active, and optionally enter the Blocked state to wait for a specified
* bit or a group of specified bits to be active. To continue the CAN bus
* example, a CAN controlling task can enter the Blocked state (and therefore
* not consume any processing time) until either bit 0, bit 1 or bit 2 are
* active, at which time the bit that was actually active would inform the task
* which action it had to take (process a received message, send a message, or
* send a SYNC).
*
* The event groups implementation contains intelligence to avoid race
* conditions that would otherwise occur were an application to use a simple
* variable for the same purpose. This is particularly important with respect
* to when a bit within an event group is to be cleared, and when bits have to
* be set and then tested atomically - as is the case where event groups are
* used to create a synchronisation point between multiple tasks (a
* 'rendezvous').
*/
/**
* event_groups.h
*
* Type by which event groups are referenced. For example, a call to
* xEventGroupCreate() returns an EventGroupHandle_t variable that can then
* be used as a parameter to other event group functions.
*
* \defgroup EventGroupHandle_t EventGroupHandle_t
* \ingroup EventGroup
*/
struct EventGroupDef_t;
typedef struct EventGroupDef_t * EventGroupHandle_t;
/*
* The type that holds event bits always matches TickType_t - therefore the
* number of bits it holds is set by configTICK_TYPE_WIDTH_IN_BITS (16 bits if set to 0,
* 32 bits if set to 1, 64 bits if set to 2.
*
* \defgroup EventBits_t EventBits_t
* \ingroup EventGroup
*/
typedef TickType_t EventBits_t;
/**
* event_groups.h
* @code{c}
* EventGroupHandle_t xEventGroupCreate( void );
* @endcode
*
* Create a new event group.
*
* Internally, within the FreeRTOS implementation, event groups use a [small]
* block of memory, in which the event group's structure is stored. If an event
* groups is created using xEventGroupCreate() then the required memory is
* automatically dynamically allocated inside the xEventGroupCreate() function.
* (see https://www.FreeRTOS.org/a00111.html). If an event group is created
* using xEventGroupCreateStatic() then the application writer must instead
* provide the memory that will get used by the event group.
* xEventGroupCreateStatic() therefore allows an event group to be created
* without using any dynamic memory allocation.
*
* Although event groups are not related to ticks, for internal implementation
* reasons the number of bits available for use in an event group is dependent
* on the configTICK_TYPE_WIDTH_IN_BITS setting in FreeRTOSConfig.h. If
* configTICK_TYPE_WIDTH_IN_BITS is 0 then each event group contains 8 usable bits (bit
* 0 to bit 7). If configTICK_TYPE_WIDTH_IN_BITS is set to 1 then each event group has
* 24 usable bits (bit 0 to bit 23). If configTICK_TYPE_WIDTH_IN_BITS is set to 2 then
* each event group has 56 usable bits (bit 0 to bit 53). The EventBits_t type
* is used to store event bits within an event group.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupCreate()
* to be available.
*
* @return If the event group was created then a handle to the event group is
* returned. If there was insufficient FreeRTOS heap available to create the
* event group then NULL is returned. See https://www.FreeRTOS.org/a00111.html
*
* Example usage:
* @code{c}
* // Declare a variable to hold the created event group.
* EventGroupHandle_t xCreatedEventGroup;
*
* // Attempt to create the event group.
* xCreatedEventGroup = xEventGroupCreate();
*
* // Was the event group created successfully?
* if( xCreatedEventGroup == NULL )
* {
* // The event group was not created because there was insufficient
* // FreeRTOS heap available.
* }
* else
* {
* // The event group was created.
* }
* @endcode
* \defgroup xEventGroupCreate xEventGroupCreate
* \ingroup EventGroup
*/
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
#endif
/**
* event_groups.h
* @code{c}
* EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer );
* @endcode
*
* Create a new event group.
*
* Internally, within the FreeRTOS implementation, event groups use a [small]
* block of memory, in which the event group's structure is stored. If an event
* groups is created using xEventGroupCreate() then the required memory is
* automatically dynamically allocated inside the xEventGroupCreate() function.
* (see https://www.FreeRTOS.org/a00111.html). If an event group is created
* using xEventGroupCreateStatic() then the application writer must instead
* provide the memory that will get used by the event group.
* xEventGroupCreateStatic() therefore allows an event group to be created
* without using any dynamic memory allocation.
*
* Although event groups are not related to ticks, for internal implementation
* reasons the number of bits available for use in an event group is dependent
* on the configTICK_TYPE_WIDTH_IN_BITS setting in FreeRTOSConfig.h. If
* configTICK_TYPE_WIDTH_IN_BITS is 0 then each event group contains 8 usable bits (bit
* 0 to bit 7). If configTICK_TYPE_WIDTH_IN_BITS is set to 1 then each event group has
* 24 usable bits (bit 0 to bit 23). If configTICK_TYPE_WIDTH_IN_BITS is set to 2 then
* each event group has 56 usable bits (bit 0 to bit 53). The EventBits_t type
* is used to store event bits within an event group.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupCreateStatic()
* to be available.
*
* @param pxEventGroupBuffer pxEventGroupBuffer must point to a variable of type
* StaticEventGroup_t, which will be then be used to hold the event group's data
* structures, removing the need for the memory to be allocated dynamically.
*
* @return If the event group was created then a handle to the event group is
* returned. If pxEventGroupBuffer was NULL then NULL is returned.
*
* Example usage:
* @code{c}
* // StaticEventGroup_t is a publicly accessible structure that has the same
* // size and alignment requirements as the real event group structure. It is
* // provided as a mechanism for applications to know the size of the event
* // group (which is dependent on the architecture and configuration file
* // settings) without breaking the strict data hiding policy by exposing the
* // real event group internals. This StaticEventGroup_t variable is passed
* // into the xSemaphoreCreateEventGroupStatic() function and is used to store
* // the event group's data structures
* StaticEventGroup_t xEventGroupBuffer;
*
* // Create the event group without dynamically allocating any memory.
* xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
* @endcode
*/
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer ) PRIVILEGED_FUNCTION;
#endif
/**
* event_groups.h
* @code{c}
* EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
* const EventBits_t uxBitsToWaitFor,
* const BaseType_t xClearOnExit,
* const BaseType_t xWaitForAllBits,
* const TickType_t xTicksToWait );
* @endcode
*
* [Potentially] block to wait for one or more bits to be set within a
* previously created event group.
*
* This function cannot be called from an interrupt.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupWaitBits()
* to be available.
*
* @param xEventGroup The event group in which the bits are being tested. The
* event group must have previously been created using a call to
* xEventGroupCreate().
*
* @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
* inside the event group. For example, to wait for bit 0 and/or bit 2 set
* uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set
* uxBitsToWaitFor to 0x07. Etc.
*
* @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within
* uxBitsToWaitFor that are set within the event group will be cleared before
* xEventGroupWaitBits() returns if the wait condition was met (if the function
* returns for a reason other than a timeout). If xClearOnExit is set to
* pdFALSE then the bits set in the event group are not altered when the call to
* xEventGroupWaitBits() returns.
*
* @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then
* xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor
* are set or the specified block time expires. If xWaitForAllBits is set to
* pdFALSE then xEventGroupWaitBits() will return when any one of the bits set
* in uxBitsToWaitFor is set or the specified block time expires. The block
* time is specified by the xTicksToWait parameter.
*
* @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
* for one/all (depending on the xWaitForAllBits value) of the bits specified by
* uxBitsToWaitFor to become set. A value of portMAX_DELAY can be used to block
* indefinitely (provided INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
*
* @return The value of the event group at the time either the bits being waited
* for became set, or the block time expired. Test the return value to know
* which bits were set. If xEventGroupWaitBits() returned because its timeout
* expired then not all the bits being waited for will be set. If
* xEventGroupWaitBits() returned because the bits it was waiting for were set
* then the returned value is the event group value before any bits were
* automatically cleared in the case that xClearOnExit parameter was set to
* pdTRUE.
*
* Example usage:
* @code{c}
* #define BIT_0 ( 1 << 0 )
* #define BIT_4 ( 1 << 4 )
*
* void aFunction( EventGroupHandle_t xEventGroup )
* {
* EventBits_t uxBits;
* const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
*
* // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
* // the event group. Clear the bits before exiting.
* uxBits = xEventGroupWaitBits(
* xEventGroup, // The event group being tested.
* BIT_0 | BIT_4, // The bits within the event group to wait for.
* pdTRUE, // BIT_0 and BIT_4 should be cleared before returning.
* pdFALSE, // Don't wait for both bits, either bit will do.
* xTicksToWait ); // Wait a maximum of 100ms for either bit to be set.
*
* if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
* {
* // xEventGroupWaitBits() returned because both bits were set.
* }
* else if( ( uxBits & BIT_0 ) != 0 )
* {
* // xEventGroupWaitBits() returned because just BIT_0 was set.
* }
* else if( ( uxBits & BIT_4 ) != 0 )
* {
* // xEventGroupWaitBits() returned because just BIT_4 was set.
* }
* else
* {
* // xEventGroupWaitBits() returned because xTicksToWait ticks passed
* // without either BIT_0 or BIT_4 becoming set.
* }
* }
* @endcode
* \defgroup xEventGroupWaitBits xEventGroupWaitBits
* \ingroup EventGroup
*/
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToWaitFor,
const BaseType_t xClearOnExit,
const BaseType_t xWaitForAllBits,
TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
/**
* event_groups.h
* @code{c}
* EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
* @endcode
*
* Clear bits within an event group. This function cannot be called from an
* interrupt.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupClearBits()
* to be available.
*
* @param xEventGroup The event group in which the bits are to be cleared.
*
* @param uxBitsToClear A bitwise value that indicates the bit or bits to clear
* in the event group. For example, to clear bit 3 only, set uxBitsToClear to
* 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09.
*
* @return The value of the event group before the specified bits were cleared.
*
* Example usage:
* @code{c}
* #define BIT_0 ( 1 << 0 )
* #define BIT_4 ( 1 << 4 )
*
* void aFunction( EventGroupHandle_t xEventGroup )
* {
* EventBits_t uxBits;
*
* // Clear bit 0 and bit 4 in xEventGroup.
* uxBits = xEventGroupClearBits(
* xEventGroup, // The event group being updated.
* BIT_0 | BIT_4 );// The bits being cleared.
*
* if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
* {
* // Both bit 0 and bit 4 were set before xEventGroupClearBits() was
* // called. Both will now be clear (not set).
* }
* else if( ( uxBits & BIT_0 ) != 0 )
* {
* // Bit 0 was set before xEventGroupClearBits() was called. It will
* // now be clear.
* }
* else if( ( uxBits & BIT_4 ) != 0 )
* {
* // Bit 4 was set before xEventGroupClearBits() was called. It will
* // now be clear.
* }
* else
* {
* // Neither bit 0 nor bit 4 were set in the first place.
* }
* }
* @endcode
* \defgroup xEventGroupClearBits xEventGroupClearBits
* \ingroup EventGroup
*/
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
/**
* event_groups.h
* @code{c}
* BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
* @endcode
*
* A version of xEventGroupClearBits() that can be called from an interrupt.
*
* Setting bits in an event group is not a deterministic operation because there
* are an unknown number of tasks that may be waiting for the bit or bits being
* set. FreeRTOS does not allow nondeterministic operations to be performed
* while interrupts are disabled, so protects event groups that are accessed
* from tasks by suspending the scheduler rather than disabling interrupts. As
* a result event groups cannot be accessed directly from an interrupt service
* routine. Therefore xEventGroupClearBitsFromISR() sends a message to the
* timer task to have the clear operation performed in the context of the timer
* task.
*
* @note If this function returns pdPASS then the timer task is ready to run
* and a portYIELD_FROM_ISR(pdTRUE) should be executed to perform the needed
* clear on the event group. This behavior is different from
* xEventGroupSetBitsFromISR because the parameter xHigherPriorityTaskWoken is
* not present.
*
* @param xEventGroup The event group in which the bits are to be cleared.
*
* @param uxBitsToClear A bitwise value that indicates the bit or bits to clear.
* For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3
* and bit 0 set uxBitsToClear to 0x09.
*
* @return If the request to execute the function was posted successfully then
* pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
* if the timer service queue was full.
*
* Example usage:
* @code{c}
* #define BIT_0 ( 1 << 0 )
* #define BIT_4 ( 1 << 4 )
*
* // An event group which it is assumed has already been created by a call to
* // xEventGroupCreate().
* EventGroupHandle_t xEventGroup;
*
* void anInterruptHandler( void )
* {
* // Clear bit 0 and bit 4 in xEventGroup.
* xResult = xEventGroupClearBitsFromISR(
* xEventGroup, // The event group being updated.
* BIT_0 | BIT_4 ); // The bits being set.
*
* if( xResult == pdPASS )
* {
* // The message was posted successfully.
* portYIELD_FROM_ISR(pdTRUE);
* }
* }
* @endcode
* \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR
* \ingroup EventGroup
*/
#if ( configUSE_TRACE_FACILITY == 1 )
BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
#else
#define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) \
xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) ( xEventGroup ), ( uint32_t ) ( uxBitsToClear ), NULL )
#endif
/**
* event_groups.h
* @code{c}
* EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
* @endcode
*
* Set bits within an event group.
* This function cannot be called from an interrupt. xEventGroupSetBitsFromISR()
* is a version that can be called from an interrupt.
*
* Setting bits in an event group will automatically unblock tasks that are
* blocked waiting for the bits.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupSetBits()
* to be available.
*
* @param xEventGroup The event group in which the bits are to be set.
*
* @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
* For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
* and bit 0 set uxBitsToSet to 0x09.
*
* @return The value of the event group at the time the call to
* xEventGroupSetBits() returns. There are two reasons why the returned value
* might have the bits specified by the uxBitsToSet parameter cleared. First,
* if setting a bit results in a task that was waiting for the bit leaving the
* blocked state then it is possible the bit will be cleared automatically
* (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any
* unblocked (or otherwise Ready state) task that has a priority above that of
* the task that called xEventGroupSetBits() will execute and may change the
* event group value before the call to xEventGroupSetBits() returns.
*
* Example usage:
* @code{c}
* #define BIT_0 ( 1 << 0 )
* #define BIT_4 ( 1 << 4 )
*
* void aFunction( EventGroupHandle_t xEventGroup )
* {
* EventBits_t uxBits;
*
* // Set bit 0 and bit 4 in xEventGroup.
* uxBits = xEventGroupSetBits(
* xEventGroup, // The event group being updated.
* BIT_0 | BIT_4 );// The bits being set.
*
* if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
* {
* // Both bit 0 and bit 4 remained set when the function returned.
* }
* else if( ( uxBits & BIT_0 ) != 0 )
* {
* // Bit 0 remained set when the function returned, but bit 4 was
* // cleared. It might be that bit 4 was cleared automatically as a
* // task that was waiting for bit 4 was removed from the Blocked
* // state.
* }
* else if( ( uxBits & BIT_4 ) != 0 )
* {
* // Bit 4 remained set when the function returned, but bit 0 was
* // cleared. It might be that bit 0 was cleared automatically as a
* // task that was waiting for bit 0 was removed from the Blocked
* // state.
* }
* else
* {
* // Neither bit 0 nor bit 4 remained set. It might be that a task
* // was waiting for both of the bits to be set, and the bits were
* // cleared as the task left the Blocked state.
* }
* }
* @endcode
* \defgroup xEventGroupSetBits xEventGroupSetBits
* \ingroup EventGroup
*/
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION;
/**
* event_groups.h
* @code{c}
* BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
* @endcode
*
* A version of xEventGroupSetBits() that can be called from an interrupt.
*
* Setting bits in an event group is not a deterministic operation because there
* are an unknown number of tasks that may be waiting for the bit or bits being
* set. FreeRTOS does not allow nondeterministic operations to be performed in
* interrupts or from critical sections. Therefore xEventGroupSetBitsFromISR()
* sends a message to the timer task to have the set operation performed in the
* context of the timer task - where a scheduler lock is used in place of a
* critical section.
*
* @param xEventGroup The event group in which the bits are to be set.
*
* @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
* For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
* and bit 0 set uxBitsToSet to 0x09.
*
* @param pxHigherPriorityTaskWoken As mentioned above, calling this function
* will result in a message being sent to the timer daemon task. If the
* priority of the timer daemon task is higher than the priority of the
* currently running task (the task the interrupt interrupted) then
* *pxHigherPriorityTaskWoken will be set to pdTRUE by
* xEventGroupSetBitsFromISR(), indicating that a context switch should be
* requested before the interrupt exits. For that reason
* *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
* example code below.
*
* @return If the request to execute the function was posted successfully then
* pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
* if the timer service queue was full.
*
* Example usage:
* @code{c}
* #define BIT_0 ( 1 << 0 )
* #define BIT_4 ( 1 << 4 )
*
* // An event group which it is assumed has already been created by a call to
* // xEventGroupCreate().
* EventGroupHandle_t xEventGroup;
*
* void anInterruptHandler( void )
* {
* BaseType_t xHigherPriorityTaskWoken, xResult;
*
* // xHigherPriorityTaskWoken must be initialised to pdFALSE.
* xHigherPriorityTaskWoken = pdFALSE;
*
* // Set bit 0 and bit 4 in xEventGroup.
* xResult = xEventGroupSetBitsFromISR(
* xEventGroup, // The event group being updated.
* BIT_0 | BIT_4 // The bits being set.
* &xHigherPriorityTaskWoken );
*
* // Was the message posted successfully?
* if( xResult == pdPASS )
* {
* // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
* // switch should be requested. The macro used is port specific and
* // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
* // refer to the documentation page for the port being used.
* portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
* }
* }
* @endcode
* \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR
* \ingroup EventGroup
*/
#if ( configUSE_TRACE_FACILITY == 1 )
BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet,
BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
#else
#define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) \
xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) ( xEventGroup ), ( uint32_t ) ( uxBitsToSet ), ( pxHigherPriorityTaskWoken ) )
#endif
/**
* event_groups.h
* @code{c}
* EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
* const EventBits_t uxBitsToSet,
* const EventBits_t uxBitsToWaitFor,
* TickType_t xTicksToWait );
* @endcode
*
* Atomically set bits within an event group, then wait for a combination of
* bits to be set within the same event group. This functionality is typically
* used to synchronise multiple tasks, where each task has to wait for the other
* tasks to reach a synchronisation point before proceeding.
*
* This function cannot be used from an interrupt.
*
* The function will return before its block time expires if the bits specified
* by the uxBitsToWait parameter are set, or become set within that time. In
* this case all the bits specified by uxBitsToWait will be automatically
* cleared before the function returns.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupSync()
* to be available.
*
* @param xEventGroup The event group in which the bits are being tested. The
* event group must have previously been created using a call to
* xEventGroupCreate().
*
* @param uxBitsToSet The bits to set in the event group before determining
* if, and possibly waiting for, all the bits specified by the uxBitsToWait
* parameter are set.
*
* @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
* inside the event group. For example, to wait for bit 0 and bit 2 set
* uxBitsToWaitFor to 0x05. To wait for bits 0 and bit 1 and bit 2 set
* uxBitsToWaitFor to 0x07. Etc.
*
* @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
* for all of the bits specified by uxBitsToWaitFor to become set.
*
* @return The value of the event group at the time either the bits being waited
* for became set, or the block time expired. Test the return value to know
* which bits were set. If xEventGroupSync() returned because its timeout
* expired then not all the bits being waited for will be set. If
* xEventGroupSync() returned because all the bits it was waiting for were
* set then the returned value is the event group value before any bits were
* automatically cleared.
*
* Example usage:
* @code{c}
* // Bits used by the three tasks.
* #define TASK_0_BIT ( 1 << 0 )
* #define TASK_1_BIT ( 1 << 1 )
* #define TASK_2_BIT ( 1 << 2 )
*
* #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT )
*
* // Use an event group to synchronise three tasks. It is assumed this event
* // group has already been created elsewhere.
* EventGroupHandle_t xEventBits;
*
* void vTask0( void *pvParameters )
* {
* EventBits_t uxReturn;
* TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
*
* for( ;; )
* {
* // Perform task functionality here.
*
* // Set bit 0 in the event flag to note this task has reached the
* // sync point. The other two tasks will set the other two bits defined
* // by ALL_SYNC_BITS. All three tasks have reached the synchronisation
* // point when all the ALL_SYNC_BITS are set. Wait a maximum of 100ms
* // for this to happen.
* uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait );
*
* if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS )
* {
* // All three tasks reached the synchronisation point before the call
* // to xEventGroupSync() timed out.
* }
* }
* }
*
* void vTask1( void *pvParameters )
* {
* for( ;; )
* {
* // Perform task functionality here.
*
* // Set bit 1 in the event flag to note this task has reached the
* // synchronisation point. The other two tasks will set the other two
* // bits defined by ALL_SYNC_BITS. All three tasks have reached the
* // synchronisation point when all the ALL_SYNC_BITS are set. Wait
* // indefinitely for this to happen.
* xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY );
*
* // xEventGroupSync() was called with an indefinite block time, so
* // this task will only reach here if the synchronisation was made by all
* // three tasks, so there is no need to test the return value.
* }
* }
*
* void vTask2( void *pvParameters )
* {
* for( ;; )
* {
* // Perform task functionality here.
*
* // Set bit 2 in the event flag to note this task has reached the
* // synchronisation point. The other two tasks will set the other two
* // bits defined by ALL_SYNC_BITS. All three tasks have reached the
* // synchronisation point when all the ALL_SYNC_BITS are set. Wait
* // indefinitely for this to happen.
* xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY );
*
* // xEventGroupSync() was called with an indefinite block time, so
* // this task will only reach here if the synchronisation was made by all
* // three tasks, so there is no need to test the return value.
* }
* }
*
* @endcode
* \defgroup xEventGroupSync xEventGroupSync
* \ingroup EventGroup
*/
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet,
const EventBits_t uxBitsToWaitFor,
TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
/**
* event_groups.h
* @code{c}
* EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
* @endcode
*
* Returns the current value of the bits in an event group. This function
* cannot be used from an interrupt.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupGetBits()
* to be available.
*
* @param xEventGroup The event group being queried.
*
* @return The event group bits at the time xEventGroupGetBits() was called.
*
* \defgroup xEventGroupGetBits xEventGroupGetBits
* \ingroup EventGroup
*/
#define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( ( xEventGroup ), 0 )
/**
* event_groups.h
* @code{c}
* EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
* @endcode
*
* A version of xEventGroupGetBits() that can be called from an ISR.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupGetBitsFromISR()
* to be available.
*
* @param xEventGroup The event group being queried.
*
* @return The event group bits at the time xEventGroupGetBitsFromISR() was called.
*
* \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR
* \ingroup EventGroup
*/
EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
/**
* event_groups.h
* @code{c}
* void xEventGroupDelete( EventGroupHandle_t xEventGroup );
* @endcode
*
* Delete an event group that was previously created by a call to
* xEventGroupCreate(). Tasks that are blocked on the event group will be
* unblocked and obtain 0 as the event group's value.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for vEventGroupDelete()
* to be available.
*
* @param xEventGroup The event group being deleted.
*/
void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
/**
* event_groups.h
* @code{c}
* BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
* StaticEventGroup_t ** ppxEventGroupBuffer );
* @endcode
*
* Retrieve a pointer to a statically created event groups's data structure
* buffer. It is the same buffer that is supplied at the time of creation.
*
* The configUSE_EVENT_GROUPS configuration constant must be set to 1 for xEventGroupGetStaticBuffer()
* to be available.
*
* @param xEventGroup The event group for which to retrieve the buffer.
*
* @param ppxEventGroupBuffer Used to return a pointer to the event groups's
* data structure buffer.
*
* @return pdTRUE if the buffer was retrieved, pdFALSE otherwise.
*/
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
StaticEventGroup_t ** ppxEventGroupBuffer ) PRIVILEGED_FUNCTION;
#endif /* configSUPPORT_STATIC_ALLOCATION */
/* For internal use only. */
void vEventGroupSetBitsCallback( void * pvEventGroup,
uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION;
void vEventGroupClearBitsCallback( void * pvEventGroup,
uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxEventGroupGetNumber( void * xEventGroup ) PRIVILEGED_FUNCTION;
void vEventGroupSetNumber( void * xEventGroup,
UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION;
#endif
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* EVENT_GROUPS_H */

View File

@ -0,0 +1,69 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* The FreeRTOS kernel's RISC-V port is split between the the code that is
* common across all currently supported RISC-V chips (implementations of the
* RISC-V ISA), and code that tailors the port to a specific RISC-V chip:
*
* + FreeRTOS\Source\portable\GCC\RISC-V\portASM.S contains the code that
* is common to all currently supported RISC-V chips. There is only one
* portASM.S file because the same file is built for all RISC-V target chips.
*
* + Header files called freertos_risc_v_chip_specific_extensions.h contain the
* code that tailors the FreeRTOS kernel's RISC-V port to a specific RISC-V
* chip. There are multiple freertos_risc_v_chip_specific_extensions.h files
* as there are multiple RISC-V chip implementations.
*
* !!!NOTE!!!
* TAKE CARE TO INCLUDE THE CORRECT freertos_risc_v_chip_specific_extensions.h
* HEADER FILE FOR THE CHIP IN USE. This is done using the assembler's (not the
* compiler's!) include path. For example, if the chip in use includes a core
* local interrupter (CLINT) and does not include any chip specific register
* extensions then add the path below to the assembler's include path:
* FreeRTOS\Source\portable\GCC\RISC-V\chip_specific_extensions\RISCV_MTIME_CLINT_no_extensions
*
*/
#ifndef __FREERTOS_RISC_V_EXTENSIONS_H__
#define __FREERTOS_RISC_V_EXTENSIONS_H__
#define portasmHAS_SIFIVE_CLINT 0
#define portasmHAS_MTIME 1
#define portasmADDITIONAL_CONTEXT_SIZE 0
.macro portasmSAVE_ADDITIONAL_REGISTERS
/* No additional registers to save, so this macro does nothing. */
.endm
.macro portasmRESTORE_ADDITIONAL_REGISTERS
/* No additional registers to restore, so this macro does nothing. */
.endm
#endif /* __FREERTOS_RISC_V_EXTENSIONS_H__ */

View File

@ -0,0 +1,165 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* The simplest possible implementation of pvPortMalloc(). Note that this
* implementation does NOT allow allocated memory to be freed again.
*
* See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the
* memory management pages of https://www.FreeRTOS.org for more information.
*/
#include <stdlib.h>
/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
* all the API functions to use the MPU wrappers. That should only be done when
* task.h is included from an application file. */
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
#include "Arduino_FreeRTOS.h"
#include "task.h"
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
#error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
#endif
/* A few bytes might be lost to byte aligning the heap start address. */
#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT )
/* Allocate the memory for the heap. */
#if ( configAPPLICATION_ALLOCATED_HEAP == 1 )
/* The application writer has already defined the array used for the RTOS
* heap - probably so it can be placed in a special segment or address. */
extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
#else
static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
#endif /* configAPPLICATION_ALLOCATED_HEAP */
/* Index into the ucHeap array. */
static size_t xNextFreeByte = ( size_t ) 0U;
/*-----------------------------------------------------------*/
void * pvPortMalloc( size_t xWantedSize )
{
void * pvReturn = NULL;
static uint8_t * pucAlignedHeap = NULL;
/* Ensure that blocks are always aligned. */
#if ( portBYTE_ALIGNMENT != 1 )
{
if( xWantedSize & portBYTE_ALIGNMENT_MASK )
{
/* Byte alignment required. Check for overflow. */
if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) ) > xWantedSize )
{
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
}
else
{
xWantedSize = 0;
}
}
}
#endif /* if ( portBYTE_ALIGNMENT != 1 ) */
vTaskSuspendAll();
{
if( pucAlignedHeap == NULL )
{
/* Ensure the heap starts on a correctly aligned boundary. */
pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
}
/* Check there is enough room left for the allocation and. */
if( ( xWantedSize > 0 ) && /* valid size */
( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) &&
( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) ) /* Check for overflow. */
{
/* Return the next free byte then increment the index past this
* block. */
pvReturn = pucAlignedHeap + xNextFreeByte;
xNextFreeByte += xWantedSize;
}
traceMALLOC( pvReturn, xWantedSize );
}
( void ) xTaskResumeAll();
#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
{
if( pvReturn == NULL )
{
vApplicationMallocFailedHook();
}
}
#endif
return pvReturn;
}
/*-----------------------------------------------------------*/
void vPortFree( void * pv )
{
/* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and
* heap_4.c for alternative implementations, and the memory management pages of
* https://www.FreeRTOS.org for more information. */
( void ) pv;
/* Force an assert as it is invalid to call this function. */
configASSERT( pv == NULL );
}
/*-----------------------------------------------------------*/
void vPortInitialiseBlocks( void )
{
/* Only required when static memory is not cleared. */
xNextFreeByte = ( size_t ) 0;
}
/*-----------------------------------------------------------*/
size_t xPortGetFreeHeapSize( void )
{
return( configADJUSTED_HEAP_SIZE - xNextFreeByte );
}
/*-----------------------------------------------------------*/
/*
* Reset the state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vPortHeapResetState( void )
{
xNextFreeByte = ( size_t ) 0U;
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,245 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#include <stdlib.h>
/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
* all the API functions to use the MPU wrappers. That should only be done when
* task.h is included from an application file. */
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
#include "Arduino_FreeRTOS.h"
#include "list.h"
/* The MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be
* defined for the header files above, but not in this file, in order to
* generate the correct privileged Vs unprivileged linkage and placement. */
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
/*-----------------------------------------------------------
* PUBLIC LIST API documented in list.h
*----------------------------------------------------------*/
void vListInitialise( List_t * const pxList )
{
traceENTER_vListInitialise( pxList );
/* The list structure contains a list item which is used to mark the
* end of the list. To initialise the list the list end is inserted
* as the only list entry. */
pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd );
listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( &( pxList->xListEnd ) );
/* The list end value is the highest possible value in the list to
* ensure it remains at the end of the list. */
pxList->xListEnd.xItemValue = portMAX_DELAY;
/* The list end next and previous pointers point to itself so we know
* when the list is empty. */
pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd );
pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );
/* Initialize the remaining fields of xListEnd when it is a proper ListItem_t */
#if ( configUSE_MINI_LIST_ITEM == 0 )
{
pxList->xListEnd.pvOwner = NULL;
pxList->xListEnd.pxContainer = NULL;
listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( &( pxList->xListEnd ) );
}
#endif
pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
/* Write known values into the list if
* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
traceRETURN_vListInitialise();
}
/*-----------------------------------------------------------*/
void vListInitialiseItem( ListItem_t * const pxItem )
{
traceENTER_vListInitialiseItem( pxItem );
/* Make sure the list item is not recorded as being on a list. */
pxItem->pxContainer = NULL;
/* Write known values into the list item if
* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
traceRETURN_vListInitialiseItem();
}
/*-----------------------------------------------------------*/
void vListInsertEnd( List_t * const pxList,
ListItem_t * const pxNewListItem )
{
ListItem_t * const pxIndex = pxList->pxIndex;
traceENTER_vListInsertEnd( pxList, pxNewListItem );
/* Only effective when configASSERT() is also defined, these tests may catch
* the list data structures being overwritten in memory. They will not catch
* data errors caused by incorrect configuration or use of FreeRTOS. */
listTEST_LIST_INTEGRITY( pxList );
listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
/* Insert a new list item into pxList, but rather than sort the list,
* makes the new list item the last item to be removed by a call to
* listGET_OWNER_OF_NEXT_ENTRY(). */
pxNewListItem->pxNext = pxIndex;
pxNewListItem->pxPrevious = pxIndex->pxPrevious;
/* Only used during decision coverage testing. */
mtCOVERAGE_TEST_DELAY();
pxIndex->pxPrevious->pxNext = pxNewListItem;
pxIndex->pxPrevious = pxNewListItem;
/* Remember which list the item is in. */
pxNewListItem->pxContainer = pxList;
( pxList->uxNumberOfItems ) = ( UBaseType_t ) ( pxList->uxNumberOfItems + 1U );
traceRETURN_vListInsertEnd();
}
/*-----------------------------------------------------------*/
void vListInsert( List_t * const pxList,
ListItem_t * const pxNewListItem )
{
ListItem_t * pxIterator;
const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
traceENTER_vListInsert( pxList, pxNewListItem );
/* Only effective when configASSERT() is also defined, these tests may catch
* the list data structures being overwritten in memory. They will not catch
* data errors caused by incorrect configuration or use of FreeRTOS. */
listTEST_LIST_INTEGRITY( pxList );
listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
/* Insert the new list item into the list, sorted in xItemValue order.
*
* If the list already contains a list item with the same item value then the
* new list item should be placed after it. This ensures that TCBs which are
* stored in ready lists (all of which have the same xItemValue value) get a
* share of the CPU. However, if the xItemValue is the same as the back marker
* the iteration loop below will not end. Therefore the value is checked
* first, and the algorithm slightly modified if necessary. */
if( xValueOfInsertion == portMAX_DELAY )
{
pxIterator = pxList->xListEnd.pxPrevious;
}
else
{
/* *** NOTE ***********************************************************
* If you find your application is crashing here then likely causes are
* listed below. In addition see https://www.FreeRTOS.org/FAQHelp.html for
* more tips, and ensure configASSERT() is defined!
* https://www.FreeRTOS.org/a00110.html#configASSERT
*
* 1) Stack overflow -
* see https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
* 2) Incorrect interrupt priority assignment, especially on Cortex-M
* parts where numerically high priority values denote low actual
* interrupt priorities, which can seem counter intuitive. See
* https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html and the definition
* of configMAX_SYSCALL_INTERRUPT_PRIORITY on
* https://www.FreeRTOS.org/a00110.html
* 3) Calling an API function from within a critical section or when
* the scheduler is suspended, or calling an API function that does
* not end in "FromISR" from an interrupt.
* 4) Using a queue or semaphore before it has been initialised or
* before the scheduler has been started (are interrupts firing
* before vTaskStartScheduler() has been called?).
* 5) If the FreeRTOS port supports interrupt nesting then ensure that
* the priority of the tick interrupt is at or below
* configMAX_SYSCALL_INTERRUPT_PRIORITY.
**********************************************************************/
for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext )
{
/* There is nothing to do here, just iterating to the wanted
* insertion position. */
}
}
pxNewListItem->pxNext = pxIterator->pxNext;
pxNewListItem->pxNext->pxPrevious = pxNewListItem;
pxNewListItem->pxPrevious = pxIterator;
pxIterator->pxNext = pxNewListItem;
/* Remember which list the item is in. This allows fast removal of the
* item later. */
pxNewListItem->pxContainer = pxList;
( pxList->uxNumberOfItems ) = ( UBaseType_t ) ( pxList->uxNumberOfItems + 1U );
traceRETURN_vListInsert();
}
/*-----------------------------------------------------------*/
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
{
/* The list item knows which list it is in. Obtain the list from the list
* item. */
List_t * const pxList = pxItemToRemove->pxContainer;
traceENTER_uxListRemove( pxItemToRemove );
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
/* Only used during decision coverage testing. */
mtCOVERAGE_TEST_DELAY();
/* Make sure the index is left pointing to a valid item. */
if( pxList->pxIndex == pxItemToRemove )
{
pxList->pxIndex = pxItemToRemove->pxPrevious;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
pxItemToRemove->pxContainer = NULL;
( pxList->uxNumberOfItems ) = ( UBaseType_t ) ( pxList->uxNumberOfItems - 1U );
traceRETURN_uxListRemove( pxList->uxNumberOfItems );
return pxList->uxNumberOfItems;
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,511 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* This is the list implementation used by the scheduler. While it is tailored
* heavily for the schedulers needs, it is also available for use by
* application code.
*
* list_ts can only store pointers to list_item_ts. Each ListItem_t contains a
* numeric value (xItemValue). Most of the time the lists are sorted in
* ascending item value order.
*
* Lists are created already containing one list item. The value of this
* item is the maximum possible that can be stored, it is therefore always at
* the end of the list and acts as a marker. The list member pxHead always
* points to this marker - even though it is at the tail of the list. This
* is because the tail contains a wrap back pointer to the true head of
* the list.
*
* In addition to it's value, each list item contains a pointer to the next
* item in the list (pxNext), a pointer to the list it is in (pxContainer)
* and a pointer to back to the object that contains it. These later two
* pointers are included for efficiency of list manipulation. There is
* effectively a two way link between the object containing the list item and
* the list item itself.
*
*
* \page ListIntroduction List Implementation
* \ingroup FreeRTOSIntro
*/
#ifndef LIST_H
#define LIST_H
#ifndef INC_ARDUINO_FREERTOS_H
#error "Arduino_FreeRTOS.h must be included before list.h"
#endif
/*
* The list structure members are modified from within interrupts, and therefore
* by rights should be declared volatile. However, they are only modified in a
* functionally atomic way (within critical sections of with the scheduler
* suspended) and are either passed by reference into a function or indexed via
* a volatile variable. Therefore, in all use cases tested so far, the volatile
* qualifier can be omitted in order to provide a moderate performance
* improvement without adversely affecting functional behaviour. The assembly
* instructions generated by the IAR, ARM and GCC compilers when the respective
* compiler's options were set for maximum optimisation has been inspected and
* deemed to be as intended. That said, as compiler technology advances, and
* especially if aggressive cross module optimisation is used (a use case that
* has not been exercised to any great extend) then it is feasible that the
* volatile qualifier will be needed for correct optimisation. It is expected
* that a compiler removing essential code because, without the volatile
* qualifier on the list structure members and with aggressive cross module
* optimisation, the compiler deemed the code unnecessary will result in
* complete and obvious failure of the scheduler. If this is ever experienced
* then the volatile qualifier can be inserted in the relevant places within the
* list structures by simply defining configLIST_VOLATILE to volatile in
* FreeRTOSConfig.h (as per the example at the bottom of this comment block).
* If configLIST_VOLATILE is not defined then the preprocessor directives below
* will simply #define configLIST_VOLATILE away completely.
*
* To use volatile list structure members then add the following line to
* FreeRTOSConfig.h (without the quotes):
* "#define configLIST_VOLATILE volatile"
*/
#ifndef configLIST_VOLATILE
#define configLIST_VOLATILE
#endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Macros that can be used to place known values within the list structures,
* then check that the known values do not get corrupted during the execution of
* the application. These may catch the list data structures being overwritten in
* memory. They will not catch data errors caused by incorrect configuration or
* use of FreeRTOS.*/
#if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 )
/* Define the macros to do nothing. */
#define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE
#define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE
#define listFIRST_LIST_INTEGRITY_CHECK_VALUE
#define listSECOND_LIST_INTEGRITY_CHECK_VALUE
#define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )
#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )
#define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList )
#define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList )
#define listTEST_LIST_ITEM_INTEGRITY( pxItem )
#define listTEST_LIST_INTEGRITY( pxList )
#else /* if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 ) */
/* Define macros that add new members into the list structures. */
#define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue1;
#define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue2;
#define listFIRST_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue1;
#define listSECOND_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue2;
/* Define macros that set the new structure members to known values. */
#define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue1 = pdINTEGRITY_CHECK_VALUE
#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue2 = pdINTEGRITY_CHECK_VALUE
#define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) ( pxList )->xListIntegrityValue1 = pdINTEGRITY_CHECK_VALUE
#define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) ( pxList )->xListIntegrityValue2 = pdINTEGRITY_CHECK_VALUE
/* Define macros that will assert if one of the structure members does not
* contain its expected value. */
#define listTEST_LIST_ITEM_INTEGRITY( pxItem ) configASSERT( ( ( pxItem )->xListItemIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxItem )->xListItemIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )
#define listTEST_LIST_INTEGRITY( pxList ) configASSERT( ( ( pxList )->xListIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxList )->xListIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )
#endif /* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES */
/*
* Definition of the only type of object that a list can contain.
*/
struct xLIST;
struct xLIST_ITEM
{
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /**< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
configLIST_VOLATILE TickType_t xItemValue; /**< The value being listed. In most cases this is used to sort the list in ascending order. */
struct xLIST_ITEM * configLIST_VOLATILE pxNext; /**< Pointer to the next ListItem_t in the list. */
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; /**< Pointer to the previous ListItem_t in the list. */
void * pvOwner; /**< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */
struct xLIST * configLIST_VOLATILE pxContainer; /**< Pointer to the list in which this list item is placed (if any). */
listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE /**< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
};
typedef struct xLIST_ITEM ListItem_t;
#if ( configUSE_MINI_LIST_ITEM == 1 )
struct xMINI_LIST_ITEM
{
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /**< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
configLIST_VOLATILE TickType_t xItemValue;
struct xLIST_ITEM * configLIST_VOLATILE pxNext;
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;
};
typedef struct xMINI_LIST_ITEM MiniListItem_t;
#else
typedef struct xLIST_ITEM MiniListItem_t;
#endif
/*
* Definition of the type of queue used by the scheduler.
*/
typedef struct xLIST
{
listFIRST_LIST_INTEGRITY_CHECK_VALUE /**< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
configLIST_VOLATILE UBaseType_t uxNumberOfItems;
ListItem_t * configLIST_VOLATILE pxIndex; /**< Used to walk through the list. Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY (). */
MiniListItem_t xListEnd; /**< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */
listSECOND_LIST_INTEGRITY_CHECK_VALUE /**< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
} List_t;
/*
* Access macro to set the owner of a list item. The owner of a list item
* is the object (usually a TCB) that contains the list item.
*
* \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
* \ingroup LinkedList
*/
#define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) )
/*
* Access macro to get the owner of a list item. The owner of a list item
* is the object (usually a TCB) that contains the list item.
*
* \page listGET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
* \ingroup LinkedList
*/
#define listGET_LIST_ITEM_OWNER( pxListItem ) ( ( pxListItem )->pvOwner )
/*
* Access macro to set the value of the list item. In most cases the value is
* used to sort the list in ascending order.
*
* \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE
* \ingroup LinkedList
*/
#define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) )
/*
* Access macro to retrieve the value of the list item. The value can
* represent anything - for example the priority of a task, or the time at
* which a task should be unblocked.
*
* \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
* \ingroup LinkedList
*/
#define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue )
/*
* Access macro to retrieve the value of the list item at the head of a given
* list.
*
* \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
* \ingroup LinkedList
*/
#define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext->xItemValue )
/*
* Return the list item at the head of the list.
*
* \page listGET_HEAD_ENTRY listGET_HEAD_ENTRY
* \ingroup LinkedList
*/
#define listGET_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext )
/*
* Return the next list item.
*
* \page listGET_NEXT listGET_NEXT
* \ingroup LinkedList
*/
#define listGET_NEXT( pxListItem ) ( ( pxListItem )->pxNext )
/*
* Return the list item that marks the end of the list
*
* \page listGET_END_MARKER listGET_END_MARKER
* \ingroup LinkedList
*/
#define listGET_END_MARKER( pxList ) ( ( ListItem_t const * ) ( &( ( pxList )->xListEnd ) ) )
/*
* Access macro to determine if a list contains any items. The macro will
* only have the value true if the list is empty.
*
* \page listLIST_IS_EMPTY listLIST_IS_EMPTY
* \ingroup LinkedList
*/
#define listLIST_IS_EMPTY( pxList ) ( ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) ? pdTRUE : pdFALSE )
/*
* Access macro to return the number of items in the list.
*/
#define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems )
/*
* Access function to obtain the owner of the next entry in a list.
*
* The list member pxIndex is used to walk through a list. Calling
* listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list
* and returns that entry's pxOwner parameter. Using multiple calls to this
* function it is therefore possible to move through every item contained in
* a list.
*
* The pxOwner parameter of a list item is a pointer to the object that owns
* the list item. In the scheduler this is normally a task control block.
* The pxOwner parameter effectively creates a two way link between the list
* item and its owner.
*
* @param pxTCB pxTCB is set to the address of the owner of the next list item.
* @param pxList The list from which the next item owner is to be returned.
*
* \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
* \ingroup LinkedList
*/
#if ( configNUMBER_OF_CORES == 1 )
#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
do { \
List_t * const pxConstList = ( pxList ); \
/* Increment the index to the next item and return the item, ensuring */ \
/* we don't return the marker used at the end of the list. */ \
( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
if( ( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) ) \
{ \
( pxConstList )->pxIndex = ( pxConstList )->xListEnd.pxNext; \
} \
( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \
} while( 0 )
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
/* This function is not required in SMP. FreeRTOS SMP scheduler doesn't use
* pxIndex and it should always point to the xListEnd. Not defining this macro
* here to prevent updating pxIndex.
*/
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
/*
* Version of uxListRemove() that does not return a value. Provided as a slight
* optimisation for xTaskIncrementTick() by being inline.
*
* Remove an item from a list. The list item has a pointer to the list that
* it is in, so only the list item need be passed into the function.
*
* @param uxListRemove The item to be removed. The item will remove itself from
* the list pointed to by it's pxContainer parameter.
*
* @return The number of items that remain in the list after the list item has
* been removed.
*
* \page listREMOVE_ITEM listREMOVE_ITEM
* \ingroup LinkedList
*/
#define listREMOVE_ITEM( pxItemToRemove ) \
do { \
/* The list item knows which list it is in. Obtain the list from the list \
* item. */ \
List_t * const pxList = ( pxItemToRemove )->pxContainer; \
\
( pxItemToRemove )->pxNext->pxPrevious = ( pxItemToRemove )->pxPrevious; \
( pxItemToRemove )->pxPrevious->pxNext = ( pxItemToRemove )->pxNext; \
/* Make sure the index is left pointing to a valid item. */ \
if( pxList->pxIndex == ( pxItemToRemove ) ) \
{ \
pxList->pxIndex = ( pxItemToRemove )->pxPrevious; \
} \
\
( pxItemToRemove )->pxContainer = NULL; \
( ( pxList )->uxNumberOfItems ) = ( UBaseType_t ) ( ( ( pxList )->uxNumberOfItems ) - 1U ); \
} while( 0 )
/*
* Inline version of vListInsertEnd() to provide slight optimisation for
* xTaskIncrementTick().
*
* Insert a list item into a list. The item will be inserted in a position
* such that it will be the last item within the list returned by multiple
* calls to listGET_OWNER_OF_NEXT_ENTRY.
*
* The list member pxIndex is used to walk through a list. Calling
* listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list.
* Placing an item in a list using vListInsertEnd effectively places the item
* in the list position pointed to by pxIndex. This means that every other
* item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
* the pxIndex parameter again points to the item being inserted.
*
* @param pxList The list into which the item is to be inserted.
*
* @param pxNewListItem The list item to be inserted into the list.
*
* \page listINSERT_END listINSERT_END
* \ingroup LinkedList
*/
#define listINSERT_END( pxList, pxNewListItem ) \
do { \
ListItem_t * const pxIndex = ( pxList )->pxIndex; \
\
/* Only effective when configASSERT() is also defined, these tests may catch \
* the list data structures being overwritten in memory. They will not catch \
* data errors caused by incorrect configuration or use of FreeRTOS. */ \
listTEST_LIST_INTEGRITY( ( pxList ) ); \
listTEST_LIST_ITEM_INTEGRITY( ( pxNewListItem ) ); \
\
/* Insert a new list item into ( pxList ), but rather than sort the list, \
* makes the new list item the last item to be removed by a call to \
* listGET_OWNER_OF_NEXT_ENTRY(). */ \
( pxNewListItem )->pxNext = pxIndex; \
( pxNewListItem )->pxPrevious = pxIndex->pxPrevious; \
\
pxIndex->pxPrevious->pxNext = ( pxNewListItem ); \
pxIndex->pxPrevious = ( pxNewListItem ); \
\
/* Remember which list the item is in. */ \
( pxNewListItem )->pxContainer = ( pxList ); \
\
( ( pxList )->uxNumberOfItems ) = ( UBaseType_t ) ( ( ( pxList )->uxNumberOfItems ) + 1U ); \
} while( 0 )
/*
* Access function to obtain the owner of the first entry in a list. Lists
* are normally sorted in ascending item value order.
*
* This function returns the pxOwner member of the first item in the list.
* The pxOwner parameter of a list item is a pointer to the object that owns
* the list item. In the scheduler this is normally a task control block.
* The pxOwner parameter effectively creates a two way link between the list
* item and its owner.
*
* @param pxList The list from which the owner of the head item is to be
* returned.
*
* \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY
* \ingroup LinkedList
*/
#define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( ( &( ( pxList )->xListEnd ) )->pxNext->pvOwner )
/*
* Check to see if a list item is within a list. The list item maintains a
* "container" pointer that points to the list it is in. All this macro does
* is check to see if the container and the list match.
*
* @param pxList The list we want to know if the list item is within.
* @param pxListItem The list item we want to know if is in the list.
* @return pdTRUE if the list item is in the list, otherwise pdFALSE.
*/
#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( ( pxListItem )->pxContainer == ( pxList ) ) ? ( pdTRUE ) : ( pdFALSE ) )
/*
* Return the list a list item is contained within (referenced from).
*
* @param pxListItem The list item being queried.
* @return A pointer to the List_t object that references the pxListItem
*/
#define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pxContainer )
/*
* This provides a crude means of knowing if a list has been initialised, as
* pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise()
* function.
*/
#define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY )
/*
* Must be called before a list is used! This initialises all the members
* of the list structure and inserts the xListEnd item into the list as a
* marker to the back of the list.
*
* @param pxList Pointer to the list being initialised.
*
* \page vListInitialise vListInitialise
* \ingroup LinkedList
*/
void vListInitialise( List_t * const pxList ) PRIVILEGED_FUNCTION;
/*
* Must be called before a list item is used. This sets the list container to
* null so the item does not think that it is already contained in a list.
*
* @param pxItem Pointer to the list item being initialised.
*
* \page vListInitialiseItem vListInitialiseItem
* \ingroup LinkedList
*/
void vListInitialiseItem( ListItem_t * const pxItem ) PRIVILEGED_FUNCTION;
/*
* Insert a list item into a list. The item will be inserted into the list in
* a position determined by its item value (ascending item value order).
*
* @param pxList The list into which the item is to be inserted.
*
* @param pxNewListItem The item that is to be placed in the list.
*
* \page vListInsert vListInsert
* \ingroup LinkedList
*/
void vListInsert( List_t * const pxList,
ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION;
/*
* Insert a list item into a list. The item will be inserted in a position
* such that it will be the last item within the list returned by multiple
* calls to listGET_OWNER_OF_NEXT_ENTRY.
*
* The list member pxIndex is used to walk through a list. Calling
* listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list.
* Placing an item in a list using vListInsertEnd effectively places the item
* in the list position pointed to by pxIndex. This means that every other
* item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
* the pxIndex parameter again points to the item being inserted.
*
* @param pxList The list into which the item is to be inserted.
*
* @param pxNewListItem The list item to be inserted into the list.
*
* \page vListInsertEnd vListInsertEnd
* \ingroup LinkedList
*/
void vListInsertEnd( List_t * const pxList,
ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION;
/*
* Remove an item from a list. The list item has a pointer to the list that
* it is in, so only the list item need be passed into the function.
*
* @param uxListRemove The item to be removed. The item will remove itself from
* the list pointed to by it's pxContainer parameter.
*
* @return The number of items that remain in the list after the list item has
* been removed.
*
* \page uxListRemove uxListRemove
* \ingroup LinkedList
*/
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) PRIVILEGED_FUNCTION;
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* ifndef LIST_H */

View File

@ -0,0 +1,967 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* Message buffers build functionality on top of FreeRTOS stream buffers.
* Whereas stream buffers are used to send a continuous stream of data from one
* task or interrupt to another, message buffers are used to send variable
* length discrete messages from one task or interrupt to another. Their
* implementation is light weight, making them particularly suited for interrupt
* to task and core to core communication scenarios.
*
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
* implementation (so also the message buffer implementation, as message buffers
* are built on top of stream buffers) assumes there is only one task or
* interrupt that will write to the buffer (the writer), and only one task or
* interrupt that will read from the buffer (the reader). It is safe for the
* writer and reader to be different tasks or interrupts, but, unlike other
* FreeRTOS objects, it is not safe to have multiple different writers or
* multiple different readers. If there are to be multiple different writers
* then the application writer must place each call to a writing API function
* (such as xMessageBufferSend()) inside a critical section and set the send
* block time to 0. Likewise, if there are to be multiple different readers
* then the application writer must place each call to a reading API function
* (such as xMessageBufferRead()) inside a critical section and set the receive
* timeout to 0.
*
* Message buffers hold variable length messages. To enable that, when a
* message is written to the message buffer an additional sizeof( size_t ) bytes
* are also written to store the message's length (that happens internally, with
* the API function). sizeof( size_t ) is typically 4 bytes on a 32-bit
* architecture, so writing a 10 byte message to a message buffer on a 32-bit
* architecture will actually reduce the available space in the message buffer
* by 14 bytes (10 byte are used by the message, and 4 bytes to hold the length
* of the message).
*/
#ifndef FREERTOS_MESSAGE_BUFFER_H
#define FREERTOS_MESSAGE_BUFFER_H
#ifndef INC_ARDUINO_FREERTOS_H
#error "include Arduino_FreeRTOS.h must appear in source files before include message_buffer.h"
#endif
/* Message buffers are built on top of stream buffers. */
#include "stream_buffer.h"
/* *INDENT-OFF* */
#if defined( __cplusplus )
extern "C" {
#endif
/* *INDENT-ON* */
/**
* Type by which message buffers are referenced. For example, a call to
* xMessageBufferCreate() returns an MessageBufferHandle_t variable that can
* then be used as a parameter to xMessageBufferSend(), xMessageBufferReceive(),
* etc. Message buffer is essentially built as a stream buffer hence its handle
* is also set to same type as a stream buffer handle.
*/
typedef StreamBufferHandle_t MessageBufferHandle_t;
/*-----------------------------------------------------------*/
/**
* message_buffer.h
*
* @code{c}
* MessageBufferHandle_t xMessageBufferCreate( size_t xBufferSizeBytes );
* @endcode
*
* Creates a new message buffer using dynamically allocated memory. See
* xMessageBufferCreateStatic() for a version that uses statically allocated
* memory (memory that is allocated at compile time).
*
* configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in
* FreeRTOSConfig.h for xMessageBufferCreate() to be available.
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferCreate() to be available.
*
* @param xBufferSizeBytes The total number of bytes (not messages) the message
* buffer will be able to hold at any one time. When a message is written to
* the message buffer an additional sizeof( size_t ) bytes are also written to
* store the message's length. sizeof( size_t ) is typically 4 bytes on a
* 32-bit architecture, so on most 32-bit architectures a 10 byte message will
* take up 14 bytes of message buffer space.
*
* @param pxSendCompletedCallback Callback invoked when a send operation to the
* message buffer is complete. If the parameter is NULL or xMessageBufferCreate()
* is called without the parameter, then it will use the default implementation
* provided by sbSEND_COMPLETED macro. To enable the callback,
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
*
* @param pxReceiveCompletedCallback Callback invoked when a receive operation from
* the message buffer is complete. If the parameter is NULL or xMessageBufferCreate()
* is called without the parameter, it will use the default implementation provided
* by sbRECEIVE_COMPLETED macro. To enable the callback,
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
*
* @return If NULL is returned, then the message buffer cannot be created
* because there is insufficient heap memory available for FreeRTOS to allocate
* the message buffer data structures and storage area. A non-NULL value being
* returned indicates that the message buffer has been created successfully -
* the returned value should be stored as the handle to the created message
* buffer.
*
* Example use:
* @code{c}
*
* void vAFunction( void )
* {
* MessageBufferHandle_t xMessageBuffer;
* const size_t xMessageBufferSizeBytes = 100;
*
* // Create a message buffer that can hold 100 bytes. The memory used to hold
* // both the message buffer structure and the messages themselves is allocated
* // dynamically. Each message added to the buffer consumes an additional 4
* // bytes which are used to hold the length of the message.
* xMessageBuffer = xMessageBufferCreate( xMessageBufferSizeBytes );
*
* if( xMessageBuffer == NULL )
* {
* // There was not enough heap memory space available to create the
* // message buffer.
* }
* else
* {
* // The message buffer was created successfully and can now be used.
* }
*
* @endcode
* \defgroup xMessageBufferCreate xMessageBufferCreate
* \ingroup MessageBufferManagement
*/
#define xMessageBufferCreate( xBufferSizeBytes ) \
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( size_t ) 0, sbTYPE_MESSAGE_BUFFER, NULL, NULL )
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
#define xMessageBufferCreateWithCallback( xBufferSizeBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( size_t ) 0, sbTYPE_MESSAGE_BUFFER, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
#endif
/**
* message_buffer.h
*
* @code{c}
* MessageBufferHandle_t xMessageBufferCreateStatic( size_t xBufferSizeBytes,
* uint8_t *pucMessageBufferStorageArea,
* StaticMessageBuffer_t *pxStaticMessageBuffer );
* @endcode
* Creates a new message buffer using statically allocated memory. See
* xMessageBufferCreate() for a version that uses dynamically allocated memory.
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferCreateStatic() to be available.
*
* @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the
* pucMessageBufferStorageArea parameter. When a message is written to the
* message buffer an additional sizeof( size_t ) bytes are also written to store
* the message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit
* architecture, so on most 32-bit architecture a 10 byte message will take up
* 14 bytes of message buffer space. The maximum number of bytes that can be
* stored in the message buffer is actually (xBufferSizeBytes - 1).
*
* @param pucMessageBufferStorageArea Must point to a uint8_t array that is at
* least xBufferSizeBytes big. This is the array to which messages are
* copied when they are written to the message buffer.
*
* @param pxStaticMessageBuffer Must point to a variable of type
* StaticMessageBuffer_t, which will be used to hold the message buffer's data
* structure.
*
* @param pxSendCompletedCallback Callback invoked when a new message is sent to the message buffer.
* If the parameter is NULL or xMessageBufferCreate() is called without the parameter, then it will use the default
* implementation provided by sbSEND_COMPLETED macro. To enable the callback,
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
*
* @param pxReceiveCompletedCallback Callback invoked when a message is read from a
* message buffer. If the parameter is NULL or xMessageBufferCreate() is called without the parameter, it will
* use the default implementation provided by sbRECEIVE_COMPLETED macro. To enable the callback,
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
*
* @return If the message buffer is created successfully then a handle to the
* created message buffer is returned. If either pucMessageBufferStorageArea or
* pxStaticmessageBuffer are NULL then NULL is returned.
*
* Example use:
* @code{c}
*
* // Used to dimension the array used to hold the messages. The available space
* // will actually be one less than this, so 999.
#define STORAGE_SIZE_BYTES 1000
*
* // Defines the memory that will actually hold the messages within the message
* // buffer.
* static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
*
* // The variable used to hold the message buffer structure.
* StaticMessageBuffer_t xMessageBufferStruct;
*
* void MyFunction( void )
* {
* MessageBufferHandle_t xMessageBuffer;
*
* xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucStorageBuffer ),
* ucStorageBuffer,
* &xMessageBufferStruct );
*
* // As neither the pucMessageBufferStorageArea or pxStaticMessageBuffer
* // parameters were NULL, xMessageBuffer will not be NULL, and can be used to
* // reference the created message buffer in other message buffer API calls.
*
* // Other code that uses the message buffer can go here.
* }
*
* @endcode
* \defgroup xMessageBufferCreateStatic xMessageBufferCreateStatic
* \ingroup MessageBufferManagement
*/
#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) \
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, sbTYPE_MESSAGE_BUFFER, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), NULL, NULL )
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
#define xMessageBufferCreateStaticWithCallback( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, sbTYPE_MESSAGE_BUFFER, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
#endif
/**
* message_buffer.h
*
* @code{c}
* BaseType_t xMessageBufferGetStaticBuffers( MessageBufferHandle_t xMessageBuffer,
* uint8_t ** ppucMessageBufferStorageArea,
* StaticMessageBuffer_t ** ppxStaticMessageBuffer );
* @endcode
*
* Retrieve pointers to a statically created message buffer's data structure
* buffer and storage area buffer. These are the same buffers that are supplied
* at the time of creation.
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferGetStaticBuffers() to be available.
*
* @param xMessageBuffer The message buffer for which to retrieve the buffers.
*
* @param ppucMessageBufferStorageArea Used to return a pointer to the
* message buffer's storage area buffer.
*
* @param ppxStaticMessageBuffer Used to return a pointer to the message
* buffer's data structure buffer.
*
* @return pdTRUE if buffers were retrieved, pdFALSE otherwise..
*
* \defgroup xMessageBufferGetStaticBuffers xMessageBufferGetStaticBuffers
* \ingroup MessageBufferManagement
*/
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
#define xMessageBufferGetStaticBuffers( xMessageBuffer, ppucMessageBufferStorageArea, ppxStaticMessageBuffer ) \
xStreamBufferGetStaticBuffers( ( xMessageBuffer ), ( ppucMessageBufferStorageArea ), ( ppxStaticMessageBuffer ) )
#endif /* configSUPPORT_STATIC_ALLOCATION */
/**
* message_buffer.h
*
* @code{c}
* size_t xMessageBufferSend( MessageBufferHandle_t xMessageBuffer,
* const void *pvTxData,
* size_t xDataLengthBytes,
* TickType_t xTicksToWait );
* @endcode
*
* Sends a discrete message to the message buffer. The message can be any
* length that fits within the buffer's free space, and is copied into the
* buffer.
*
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
* implementation (so also the message buffer implementation, as message buffers
* are built on top of stream buffers) assumes there is only one task or
* interrupt that will write to the buffer (the writer), and only one task or
* interrupt that will read from the buffer (the reader). It is safe for the
* writer and reader to be different tasks or interrupts, but, unlike other
* FreeRTOS objects, it is not safe to have multiple different writers or
* multiple different readers. If there are to be multiple different writers
* then the application writer must place each call to a writing API function
* (such as xMessageBufferSend()) inside a critical section and set the send
* block time to 0. Likewise, if there are to be multiple different readers
* then the application writer must place each call to a reading API function
* (such as xMessageBufferRead()) inside a critical section and set the receive
* block time to 0.
*
* Use xMessageBufferSend() to write to a message buffer from a task. Use
* xMessageBufferSendFromISR() to write to a message buffer from an interrupt
* service routine (ISR).
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferSend() to be available.
*
* @param xMessageBuffer The handle of the message buffer to which a message is
* being sent.
*
* @param pvTxData A pointer to the message that is to be copied into the
* message buffer.
*
* @param xDataLengthBytes The length of the message. That is, the number of
* bytes to copy from pvTxData into the message buffer. When a message is
* written to the message buffer an additional sizeof( size_t ) bytes are also
* written to store the message's length. sizeof( size_t ) is typically 4 bytes
* on a 32-bit architecture, so on most 32-bit architecture setting
* xDataLengthBytes to 20 will reduce the free space in the message buffer by 24
* bytes (20 bytes of message data and 4 bytes to hold the message length).
*
* @param xTicksToWait The maximum amount of time the calling task should remain
* in the Blocked state to wait for enough space to become available in the
* message buffer, should the message buffer have insufficient space when
* xMessageBufferSend() is called. The calling task will never block if
* xTicksToWait is zero. The block time is specified in tick periods, so the
* absolute time it represents is dependent on the tick frequency. The macro
* pdMS_TO_TICKS() can be used to convert a time specified in milliseconds into
* a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will cause
* the task to wait indefinitely (without timing out), provided
* INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any
* CPU time when they are in the Blocked state.
*
* @return The number of bytes written to the message buffer. If the call to
* xMessageBufferSend() times out before there was enough space to write the
* message into the message buffer then zero is returned. If the call did not
* time out then xDataLengthBytes is returned.
*
* Example use:
* @code{c}
* void vAFunction( MessageBufferHandle_t xMessageBuffer )
* {
* size_t xBytesSent;
* uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
* char *pcStringToSend = "String to send";
* const TickType_t x100ms = pdMS_TO_TICKS( 100 );
*
* // Send an array to the message buffer, blocking for a maximum of 100ms to
* // wait for enough space to be available in the message buffer.
* xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
*
* if( xBytesSent != sizeof( ucArrayToSend ) )
* {
* // The call to xMessageBufferSend() times out before there was enough
* // space in the buffer for the data to be written.
* }
*
* // Send the string to the message buffer. Return immediately if there is
* // not enough space in the buffer.
* xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
*
* if( xBytesSent != strlen( pcStringToSend ) )
* {
* // The string could not be added to the message buffer because there was
* // not enough free space in the buffer.
* }
* }
* @endcode
* \defgroup xMessageBufferSend xMessageBufferSend
* \ingroup MessageBufferManagement
*/
#define xMessageBufferSend( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) \
xStreamBufferSend( ( xMessageBuffer ), ( pvTxData ), ( xDataLengthBytes ), ( xTicksToWait ) )
/**
* message_buffer.h
*
* @code{c}
* size_t xMessageBufferSendFromISR( MessageBufferHandle_t xMessageBuffer,
* const void *pvTxData,
* size_t xDataLengthBytes,
* BaseType_t *pxHigherPriorityTaskWoken );
* @endcode
*
* Interrupt safe version of the API function that sends a discrete message to
* the message buffer. The message can be any length that fits within the
* buffer's free space, and is copied into the buffer.
*
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
* implementation (so also the message buffer implementation, as message buffers
* are built on top of stream buffers) assumes there is only one task or
* interrupt that will write to the buffer (the writer), and only one task or
* interrupt that will read from the buffer (the reader). It is safe for the
* writer and reader to be different tasks or interrupts, but, unlike other
* FreeRTOS objects, it is not safe to have multiple different writers or
* multiple different readers. If there are to be multiple different writers
* then the application writer must place each call to a writing API function
* (such as xMessageBufferSend()) inside a critical section and set the send
* block time to 0. Likewise, if there are to be multiple different readers
* then the application writer must place each call to a reading API function
* (such as xMessageBufferRead()) inside a critical section and set the receive
* block time to 0.
*
* Use xMessageBufferSend() to write to a message buffer from a task. Use
* xMessageBufferSendFromISR() to write to a message buffer from an interrupt
* service routine (ISR).
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferSendFromISR() to be available.
*
* @param xMessageBuffer The handle of the message buffer to which a message is
* being sent.
*
* @param pvTxData A pointer to the message that is to be copied into the
* message buffer.
*
* @param xDataLengthBytes The length of the message. That is, the number of
* bytes to copy from pvTxData into the message buffer. When a message is
* written to the message buffer an additional sizeof( size_t ) bytes are also
* written to store the message's length. sizeof( size_t ) is typically 4 bytes
* on a 32-bit architecture, so on most 32-bit architecture setting
* xDataLengthBytes to 20 will reduce the free space in the message buffer by 24
* bytes (20 bytes of message data and 4 bytes to hold the message length).
*
* @param pxHigherPriorityTaskWoken It is possible that a message buffer will
* have a task blocked on it waiting for data. Calling
* xMessageBufferSendFromISR() can make data available, and so cause a task that
* was waiting for data to leave the Blocked state. If calling
* xMessageBufferSendFromISR() causes a task to leave the Blocked state, and the
* unblocked task has a priority higher than the currently executing task (the
* task that was interrupted), then, internally, xMessageBufferSendFromISR()
* will set *pxHigherPriorityTaskWoken to pdTRUE. If
* xMessageBufferSendFromISR() sets this value to pdTRUE, then normally a
* context switch should be performed before the interrupt is exited. This will
* ensure that the interrupt returns directly to the highest priority Ready
* state task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it
* is passed into the function. See the code example below for an example.
*
* @return The number of bytes actually written to the message buffer. If the
* message buffer didn't have enough free space for the message to be stored
* then 0 is returned, otherwise xDataLengthBytes is returned.
*
* Example use:
* @code{c}
* // A message buffer that has already been created.
* MessageBufferHandle_t xMessageBuffer;
*
* void vAnInterruptServiceRoutine( void )
* {
* size_t xBytesSent;
* char *pcStringToSend = "String to send";
* BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
*
* // Attempt to send the string to the message buffer.
* xBytesSent = xMessageBufferSendFromISR( xMessageBuffer,
* ( void * ) pcStringToSend,
* strlen( pcStringToSend ),
* &xHigherPriorityTaskWoken );
*
* if( xBytesSent != strlen( pcStringToSend ) )
* {
* // The string could not be added to the message buffer because there was
* // not enough free space in the buffer.
* }
*
* // If xHigherPriorityTaskWoken was set to pdTRUE inside
* // xMessageBufferSendFromISR() then a task that has a priority above the
* // priority of the currently executing task was unblocked and a context
* // switch should be performed to ensure the ISR returns to the unblocked
* // task. In most FreeRTOS ports this is done by simply passing
* // xHigherPriorityTaskWoken into portYIELD_FROM_ISR(), which will test the
* // variables value, and perform the context switch if necessary. Check the
* // documentation for the port in use for port specific instructions.
* portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
* }
* @endcode
* \defgroup xMessageBufferSendFromISR xMessageBufferSendFromISR
* \ingroup MessageBufferManagement
*/
#define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) \
xStreamBufferSendFromISR( ( xMessageBuffer ), ( pvTxData ), ( xDataLengthBytes ), ( pxHigherPriorityTaskWoken ) )
/**
* message_buffer.h
*
* @code{c}
* size_t xMessageBufferReceive( MessageBufferHandle_t xMessageBuffer,
* void *pvRxData,
* size_t xBufferLengthBytes,
* TickType_t xTicksToWait );
* @endcode
*
* Receives a discrete message from a message buffer. Messages can be of
* variable length and are copied out of the buffer.
*
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
* implementation (so also the message buffer implementation, as message buffers
* are built on top of stream buffers) assumes there is only one task or
* interrupt that will write to the buffer (the writer), and only one task or
* interrupt that will read from the buffer (the reader). It is safe for the
* writer and reader to be different tasks or interrupts, but, unlike other
* FreeRTOS objects, it is not safe to have multiple different writers or
* multiple different readers. If there are to be multiple different writers
* then the application writer must place each call to a writing API function
* (such as xMessageBufferSend()) inside a critical section and set the send
* block time to 0. Likewise, if there are to be multiple different readers
* then the application writer must place each call to a reading API function
* (such as xMessageBufferRead()) inside a critical section and set the receive
* block time to 0.
*
* Use xMessageBufferReceive() to read from a message buffer from a task. Use
* xMessageBufferReceiveFromISR() to read from a message buffer from an
* interrupt service routine (ISR).
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferReceive() to be available.
*
* @param xMessageBuffer The handle of the message buffer from which a message
* is being received.
*
* @param pvRxData A pointer to the buffer into which the received message is
* to be copied.
*
* @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData
* parameter. This sets the maximum length of the message that can be received.
* If xBufferLengthBytes is too small to hold the next message then the message
* will be left in the message buffer and 0 will be returned.
*
* @param xTicksToWait The maximum amount of time the task should remain in the
* Blocked state to wait for a message, should the message buffer be empty.
* xMessageBufferReceive() will return immediately if xTicksToWait is zero and
* the message buffer is empty. The block time is specified in tick periods, so
* the absolute time it represents is dependent on the tick frequency. The
* macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds
* into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will
* cause the task to wait indefinitely (without timing out), provided
* INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any
* CPU time when they are in the Blocked state.
*
* @return The length, in bytes, of the message read from the message buffer, if
* any. If xMessageBufferReceive() times out before a message became available
* then zero is returned. If the length of the message is greater than
* xBufferLengthBytes then the message will be left in the message buffer and
* zero is returned.
*
* Example use:
* @code{c}
* void vAFunction( MessageBuffer_t xMessageBuffer )
* {
* uint8_t ucRxData[ 20 ];
* size_t xReceivedBytes;
* const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
*
* // Receive the next message from the message buffer. Wait in the Blocked
* // state (so not using any CPU processing time) for a maximum of 100ms for
* // a message to become available.
* xReceivedBytes = xMessageBufferReceive( xMessageBuffer,
* ( void * ) ucRxData,
* sizeof( ucRxData ),
* xBlockTime );
*
* if( xReceivedBytes > 0 )
* {
* // A ucRxData contains a message that is xReceivedBytes long. Process
* // the message here....
* }
* }
* @endcode
* \defgroup xMessageBufferReceive xMessageBufferReceive
* \ingroup MessageBufferManagement
*/
#define xMessageBufferReceive( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) \
xStreamBufferReceive( ( xMessageBuffer ), ( pvRxData ), ( xBufferLengthBytes ), ( xTicksToWait ) )
/**
* message_buffer.h
*
* @code{c}
* size_t xMessageBufferReceiveFromISR( MessageBufferHandle_t xMessageBuffer,
* void *pvRxData,
* size_t xBufferLengthBytes,
* BaseType_t *pxHigherPriorityTaskWoken );
* @endcode
*
* An interrupt safe version of the API function that receives a discrete
* message from a message buffer. Messages can be of variable length and are
* copied out of the buffer.
*
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
* implementation (so also the message buffer implementation, as message buffers
* are built on top of stream buffers) assumes there is only one task or
* interrupt that will write to the buffer (the writer), and only one task or
* interrupt that will read from the buffer (the reader). It is safe for the
* writer and reader to be different tasks or interrupts, but, unlike other
* FreeRTOS objects, it is not safe to have multiple different writers or
* multiple different readers. If there are to be multiple different writers
* then the application writer must place each call to a writing API function
* (such as xMessageBufferSend()) inside a critical section and set the send
* block time to 0. Likewise, if there are to be multiple different readers
* then the application writer must place each call to a reading API function
* (such as xMessageBufferRead()) inside a critical section and set the receive
* block time to 0.
*
* Use xMessageBufferReceive() to read from a message buffer from a task. Use
* xMessageBufferReceiveFromISR() to read from a message buffer from an
* interrupt service routine (ISR).
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferReceiveFromISR() to be available.
*
* @param xMessageBuffer The handle of the message buffer from which a message
* is being received.
*
* @param pvRxData A pointer to the buffer into which the received message is
* to be copied.
*
* @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData
* parameter. This sets the maximum length of the message that can be received.
* If xBufferLengthBytes is too small to hold the next message then the message
* will be left in the message buffer and 0 will be returned.
*
* @param pxHigherPriorityTaskWoken It is possible that a message buffer will
* have a task blocked on it waiting for space to become available. Calling
* xMessageBufferReceiveFromISR() can make space available, and so cause a task
* that is waiting for space to leave the Blocked state. If calling
* xMessageBufferReceiveFromISR() causes a task to leave the Blocked state, and
* the unblocked task has a priority higher than the currently executing task
* (the task that was interrupted), then, internally,
* xMessageBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE.
* If xMessageBufferReceiveFromISR() sets this value to pdTRUE, then normally a
* context switch should be performed before the interrupt is exited. That will
* ensure the interrupt returns directly to the highest priority Ready state
* task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is
* passed into the function. See the code example below for an example.
*
* @return The length, in bytes, of the message read from the message buffer, if
* any.
*
* Example use:
* @code{c}
* // A message buffer that has already been created.
* MessageBuffer_t xMessageBuffer;
*
* void vAnInterruptServiceRoutine( void )
* {
* uint8_t ucRxData[ 20 ];
* size_t xReceivedBytes;
* BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
*
* // Receive the next message from the message buffer.
* xReceivedBytes = xMessageBufferReceiveFromISR( xMessageBuffer,
* ( void * ) ucRxData,
* sizeof( ucRxData ),
* &xHigherPriorityTaskWoken );
*
* if( xReceivedBytes > 0 )
* {
* // A ucRxData contains a message that is xReceivedBytes long. Process
* // the message here....
* }
*
* // If xHigherPriorityTaskWoken was set to pdTRUE inside
* // xMessageBufferReceiveFromISR() then a task that has a priority above the
* // priority of the currently executing task was unblocked and a context
* // switch should be performed to ensure the ISR returns to the unblocked
* // task. In most FreeRTOS ports this is done by simply passing
* // xHigherPriorityTaskWoken into portYIELD_FROM_ISR(), which will test the
* // variables value, and perform the context switch if necessary. Check the
* // documentation for the port in use for port specific instructions.
* portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
* }
* @endcode
* \defgroup xMessageBufferReceiveFromISR xMessageBufferReceiveFromISR
* \ingroup MessageBufferManagement
*/
#define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) \
xStreamBufferReceiveFromISR( ( xMessageBuffer ), ( pvRxData ), ( xBufferLengthBytes ), ( pxHigherPriorityTaskWoken ) )
/**
* message_buffer.h
*
* @code{c}
* void vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer );
* @endcode
*
* Deletes a message buffer that was previously created using a call to
* xMessageBufferCreate() or xMessageBufferCreateStatic(). If the message
* buffer was created using dynamic memory (that is, by xMessageBufferCreate()),
* then the allocated memory is freed.
*
* A message buffer handle must not be used after the message buffer has been
* deleted.
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* vMessageBufferDelete() to be available.
*
* @param xMessageBuffer The handle of the message buffer to be deleted.
*
*/
#define vMessageBufferDelete( xMessageBuffer ) \
vStreamBufferDelete( xMessageBuffer )
/**
* message_buffer.h
* @code{c}
* BaseType_t xMessageBufferIsFull( MessageBufferHandle_t xMessageBuffer );
* @endcode
*
* Tests to see if a message buffer is full. A message buffer is full if it
* cannot accept any more messages, of any size, until space is made available
* by a message being removed from the message buffer.
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferIsFull() to be available.
*
* @param xMessageBuffer The handle of the message buffer being queried.
*
* @return If the message buffer referenced by xMessageBuffer is full then
* pdTRUE is returned. Otherwise pdFALSE is returned.
*/
#define xMessageBufferIsFull( xMessageBuffer ) \
xStreamBufferIsFull( xMessageBuffer )
/**
* message_buffer.h
* @code{c}
* BaseType_t xMessageBufferIsEmpty( MessageBufferHandle_t xMessageBuffer );
* @endcode
*
* Tests to see if a message buffer is empty (does not contain any messages).
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferIsEmpty() to be available.
*
* @param xMessageBuffer The handle of the message buffer being queried.
*
* @return If the message buffer referenced by xMessageBuffer is empty then
* pdTRUE is returned. Otherwise pdFALSE is returned.
*
*/
#define xMessageBufferIsEmpty( xMessageBuffer ) \
xStreamBufferIsEmpty( xMessageBuffer )
/**
* message_buffer.h
* @code{c}
* BaseType_t xMessageBufferReset( MessageBufferHandle_t xMessageBuffer );
* @endcode
*
* Resets a message buffer to its initial empty state, discarding any message it
* contained.
*
* A message buffer can only be reset if there are no tasks blocked on it.
*
* Use xMessageBufferReset() to reset a message buffer from a task.
* Use xMessageBufferResetFromISR() to reset a message buffer from an
* interrupt service routine (ISR).
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferReset() to be available.
*
* @param xMessageBuffer The handle of the message buffer being reset.
*
* @return If the message buffer was reset then pdPASS is returned. If the
* message buffer could not be reset because either there was a task blocked on
* the message queue to wait for space to become available, or to wait for a
* a message to be available, then pdFAIL is returned.
*
* \defgroup xMessageBufferReset xMessageBufferReset
* \ingroup MessageBufferManagement
*/
#define xMessageBufferReset( xMessageBuffer ) \
xStreamBufferReset( xMessageBuffer )
/**
* message_buffer.h
* @code{c}
* BaseType_t xMessageBufferResetFromISR( MessageBufferHandle_t xMessageBuffer );
* @endcode
*
* An interrupt safe version of the API function that resets the message buffer.
* Resets a message buffer to its initial empty state, discarding any message it
* contained.
*
* A message buffer can only be reset if there are no tasks blocked on it.
*
* Use xMessageBufferReset() to reset a message buffer from a task.
* Use xMessageBufferResetFromISR() to reset a message buffer from an
* interrupt service routine (ISR).
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferResetFromISR() to be available.
*
* @param xMessageBuffer The handle of the message buffer being reset.
*
* @return If the message buffer was reset then pdPASS is returned. If the
* message buffer could not be reset because either there was a task blocked on
* the message queue to wait for space to become available, or to wait for a
* a message to be available, then pdFAIL is returned.
*
* \defgroup xMessageBufferResetFromISR xMessageBufferResetFromISR
* \ingroup MessageBufferManagement
*/
#define xMessageBufferResetFromISR( xMessageBuffer ) \
xStreamBufferResetFromISR( xMessageBuffer )
/**
* message_buffer.h
* @code{c}
* size_t xMessageBufferSpaceAvailable( MessageBufferHandle_t xMessageBuffer );
* @endcode
* Returns the number of bytes of free space in the message buffer.
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferSpaceAvailable() to be available.
*
* @param xMessageBuffer The handle of the message buffer being queried.
*
* @return The number of bytes that can be written to the message buffer before
* the message buffer would be full. When a message is written to the message
* buffer an additional sizeof( size_t ) bytes are also written to store the
* message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit
* architecture, so if xMessageBufferSpacesAvailable() returns 10, then the size
* of the largest message that can be written to the message buffer is 6 bytes.
*
* \defgroup xMessageBufferSpaceAvailable xMessageBufferSpaceAvailable
* \ingroup MessageBufferManagement
*/
#define xMessageBufferSpaceAvailable( xMessageBuffer ) \
xStreamBufferSpacesAvailable( xMessageBuffer )
#define xMessageBufferSpacesAvailable( xMessageBuffer ) \
xStreamBufferSpacesAvailable( xMessageBuffer ) /* Corrects typo in original macro name. */
/**
* message_buffer.h
* @code{c}
* size_t xMessageBufferNextLengthBytes( MessageBufferHandle_t xMessageBuffer );
* @endcode
* Returns the length (in bytes) of the next message in a message buffer.
* Useful if xMessageBufferReceive() returned 0 because the size of the buffer
* passed into xMessageBufferReceive() was too small to hold the next message.
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferNextLengthBytes() to be available.
*
* @param xMessageBuffer The handle of the message buffer being queried.
*
* @return The length (in bytes) of the next message in the message buffer, or 0
* if the message buffer is empty.
*
* \defgroup xMessageBufferNextLengthBytes xMessageBufferNextLengthBytes
* \ingroup MessageBufferManagement
*/
#define xMessageBufferNextLengthBytes( xMessageBuffer ) \
xStreamBufferNextMessageLengthBytes( xMessageBuffer )
/**
* message_buffer.h
*
* @code{c}
* BaseType_t xMessageBufferSendCompletedFromISR( MessageBufferHandle_t xMessageBuffer, BaseType_t *pxHigherPriorityTaskWoken );
* @endcode
*
* For advanced users only.
*
* The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when
* data is sent to a message buffer or stream buffer. If there was a task that
* was blocked on the message or stream buffer waiting for data to arrive then
* the sbSEND_COMPLETED() macro sends a notification to the task to remove it
* from the Blocked state. xMessageBufferSendCompletedFromISR() does the same
* thing. It is provided to enable application writers to implement their own
* version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME.
*
* See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
* additional information.
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferSendCompletedFromISR() to be available.
*
* @param xMessageBuffer The handle of the stream buffer to which data was
* written.
*
* @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
* initialised to pdFALSE before it is passed into
* xMessageBufferSendCompletedFromISR(). If calling
* xMessageBufferSendCompletedFromISR() removes a task from the Blocked state,
* and the task has a priority above the priority of the currently running task,
* then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
* context switch should be performed before exiting the ISR.
*
* @return If a task was removed from the Blocked state then pdTRUE is returned.
* Otherwise pdFALSE is returned.
*
* \defgroup xMessageBufferSendCompletedFromISR xMessageBufferSendCompletedFromISR
* \ingroup StreamBufferManagement
*/
#define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) \
xStreamBufferSendCompletedFromISR( ( xMessageBuffer ), ( pxHigherPriorityTaskWoken ) )
/**
* message_buffer.h
*
* @code{c}
* BaseType_t xMessageBufferReceiveCompletedFromISR( MessageBufferHandle_t xMessageBuffer, BaseType_t *pxHigherPriorityTaskWoken );
* @endcode
*
* For advanced users only.
*
* The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when
* data is read out of a message buffer or stream buffer. If there was a task
* that was blocked on the message or stream buffer waiting for data to arrive
* then the sbRECEIVE_COMPLETED() macro sends a notification to the task to
* remove it from the Blocked state. xMessageBufferReceiveCompletedFromISR()
* does the same thing. It is provided to enable application writers to
* implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT
* ANY OTHER TIME.
*
* See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
* additional information.
*
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xMessageBufferReceiveCompletedFromISR() to be available.
*
* @param xMessageBuffer The handle of the stream buffer from which data was
* read.
*
* @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
* initialised to pdFALSE before it is passed into
* xMessageBufferReceiveCompletedFromISR(). If calling
* xMessageBufferReceiveCompletedFromISR() removes a task from the Blocked state,
* and the task has a priority above the priority of the currently running task,
* then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
* context switch should be performed before exiting the ISR.
*
* @return If a task was removed from the Blocked state then pdTRUE is returned.
* Otherwise pdFALSE is returned.
*
* \defgroup xMessageBufferReceiveCompletedFromISR xMessageBufferReceiveCompletedFromISR
* \ingroup StreamBufferManagement
*/
#define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) \
xStreamBufferReceiveCompletedFromISR( ( xMessageBuffer ), ( pxHigherPriorityTaskWoken ) )
/* *INDENT-OFF* */
#if defined( __cplusplus )
} /* extern "C" */
#endif
/* *INDENT-ON* */
#endif /* !defined( FREERTOS_MESSAGE_BUFFER_H ) */

View File

@ -0,0 +1,289 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef MPU_WRAPPERS_H
#define MPU_WRAPPERS_H
/* This file redefines API functions to be called through a wrapper macro, but
* only for ports that are using the MPU. */
#if ( portUSING_MPU_WRAPPERS == 1 )
/* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is
* included from queue.c or task.c to prevent it from having an effect within
* those files. */
#ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
/*
* Map standard (non MPU) API functions to equivalents that start
* "MPU_". This will cause the application code to call the MPU_
* version, which wraps the non-MPU version with privilege promoting
* then demoting code, so the kernel code always runs will full
* privileges.
*/
/* Map standard task.h API functions to the MPU equivalents. */
#define vTaskDelay MPU_vTaskDelay
#define xTaskDelayUntil MPU_xTaskDelayUntil
#define xTaskAbortDelay MPU_xTaskAbortDelay
#define uxTaskPriorityGet MPU_uxTaskPriorityGet
#define eTaskGetState MPU_eTaskGetState
#define vTaskGetInfo MPU_vTaskGetInfo
#define vTaskSuspend MPU_vTaskSuspend
#define vTaskResume MPU_vTaskResume
#define xTaskGetTickCount MPU_xTaskGetTickCount
#define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks
#define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark
#define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2
#define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag
#define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag
#define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer
#define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer
#define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle
#define uxTaskGetSystemState MPU_uxTaskGetSystemState
#define ulTaskGetIdleRunTimeCounter MPU_ulTaskGetIdleRunTimeCounter
#define ulTaskGetIdleRunTimePercent MPU_ulTaskGetIdleRunTimePercent
#define xTaskGenericNotify MPU_xTaskGenericNotify
#define xTaskGenericNotifyWait MPU_xTaskGenericNotifyWait
#define ulTaskGenericNotifyTake MPU_ulTaskGenericNotifyTake
#define xTaskGenericNotifyStateClear MPU_xTaskGenericNotifyStateClear
#define ulTaskGenericNotifyValueClear MPU_ulTaskGenericNotifyValueClear
#define vTaskSetTimeOutState MPU_vTaskSetTimeOutState
#define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut
#define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle
#define xTaskGetSchedulerState MPU_xTaskGetSchedulerState
#if ( configUSE_MPU_WRAPPERS_V1 == 0 )
#define ulTaskGetRunTimeCounter MPU_ulTaskGetRunTimeCounter
#define ulTaskGetRunTimePercent MPU_ulTaskGetRunTimePercent
#endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
/* Privileged only wrappers for Task APIs. These are needed so that
* the application can use opaque handles maintained in mpu_wrappers.c
* with all the APIs. */
#define xTaskCreate MPU_xTaskCreate
#define xTaskCreateStatic MPU_xTaskCreateStatic
#define vTaskDelete MPU_vTaskDelete
#define vTaskPrioritySet MPU_vTaskPrioritySet
#define xTaskGetHandle MPU_xTaskGetHandle
#define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook
#if ( configUSE_MPU_WRAPPERS_V1 == 0 )
#define pcTaskGetName MPU_pcTaskGetName
#define xTaskCreateRestricted MPU_xTaskCreateRestricted
#define xTaskCreateRestrictedStatic MPU_xTaskCreateRestrictedStatic
#define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
#define xTaskGetStaticBuffers MPU_xTaskGetStaticBuffers
#define uxTaskPriorityGetFromISR MPU_uxTaskPriorityGetFromISR
#define uxTaskBasePriorityGet MPU_uxTaskBasePriorityGet
#define uxTaskBasePriorityGetFromISR MPU_uxTaskBasePriorityGetFromISR
#define xTaskResumeFromISR MPU_xTaskResumeFromISR
#define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR
#define xTaskGenericNotifyFromISR MPU_xTaskGenericNotifyFromISR
#define vTaskGenericNotifyGiveFromISR MPU_vTaskGenericNotifyGiveFromISR
#endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
/* Map standard queue.h API functions to the MPU equivalents. */
#define xQueueGenericSend MPU_xQueueGenericSend
#define xQueueReceive MPU_xQueueReceive
#define xQueuePeek MPU_xQueuePeek
#define xQueueSemaphoreTake MPU_xQueueSemaphoreTake
#define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting
#define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable
#define xQueueGetMutexHolder MPU_xQueueGetMutexHolder
#define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive
#define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive
#define xQueueAddToSet MPU_xQueueAddToSet
#define xQueueSelectFromSet MPU_xQueueSelectFromSet
#if ( configQUEUE_REGISTRY_SIZE > 0 )
#define vQueueAddToRegistry MPU_vQueueAddToRegistry
#define vQueueUnregisterQueue MPU_vQueueUnregisterQueue
#define pcQueueGetName MPU_pcQueueGetName
#endif /* #if ( configQUEUE_REGISTRY_SIZE > 0 ) */
/* Privileged only wrappers for Queue APIs. These are needed so that
* the application can use opaque handles maintained in mpu_wrappers.c
* with all the APIs. */
#define vQueueDelete MPU_vQueueDelete
#define xQueueCreateMutex MPU_xQueueCreateMutex
#define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic
#define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore
#define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic
#define xQueueGenericCreate MPU_xQueueGenericCreate
#define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic
#define xQueueGenericReset MPU_xQueueGenericReset
#define xQueueCreateSet MPU_xQueueCreateSet
#define xQueueRemoveFromSet MPU_xQueueRemoveFromSet
#if ( configUSE_MPU_WRAPPERS_V1 == 0 )
#define xQueueGenericGetStaticBuffers MPU_xQueueGenericGetStaticBuffers
#define xQueueGenericSendFromISR MPU_xQueueGenericSendFromISR
#define xQueueGiveFromISR MPU_xQueueGiveFromISR
#define xQueuePeekFromISR MPU_xQueuePeekFromISR
#define xQueueReceiveFromISR MPU_xQueueReceiveFromISR
#define xQueueIsQueueEmptyFromISR MPU_xQueueIsQueueEmptyFromISR
#define xQueueIsQueueFullFromISR MPU_xQueueIsQueueFullFromISR
#define uxQueueMessagesWaitingFromISR MPU_uxQueueMessagesWaitingFromISR
#define xQueueGetMutexHolderFromISR MPU_xQueueGetMutexHolderFromISR
#define xQueueSelectFromSetFromISR MPU_xQueueSelectFromSetFromISR
#endif /* if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
/* Map standard timer.h API functions to the MPU equivalents. */
#define pvTimerGetTimerID MPU_pvTimerGetTimerID
#define vTimerSetTimerID MPU_vTimerSetTimerID
#define xTimerIsTimerActive MPU_xTimerIsTimerActive
#define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle
#define xTimerGenericCommandFromTask MPU_xTimerGenericCommandFromTask
#define pcTimerGetName MPU_pcTimerGetName
#define vTimerSetReloadMode MPU_vTimerSetReloadMode
#define uxTimerGetReloadMode MPU_uxTimerGetReloadMode
#define xTimerGetPeriod MPU_xTimerGetPeriod
#define xTimerGetExpiryTime MPU_xTimerGetExpiryTime
/* Privileged only wrappers for Timer APIs. These are needed so that
* the application can use opaque handles maintained in mpu_wrappers.c
* with all the APIs. */
#if ( configUSE_MPU_WRAPPERS_V1 == 0 )
#define xTimerGetReloadMode MPU_xTimerGetReloadMode
#define xTimerCreate MPU_xTimerCreate
#define xTimerCreateStatic MPU_xTimerCreateStatic
#define xTimerGetStaticBuffer MPU_xTimerGetStaticBuffer
#define xTimerGenericCommandFromISR MPU_xTimerGenericCommandFromISR
#endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
/* Map standard event_group.h API functions to the MPU equivalents. */
#define xEventGroupWaitBits MPU_xEventGroupWaitBits
#define xEventGroupClearBits MPU_xEventGroupClearBits
#define xEventGroupSetBits MPU_xEventGroupSetBits
#define xEventGroupSync MPU_xEventGroupSync
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
#define uxEventGroupGetNumber MPU_uxEventGroupGetNumber
#define vEventGroupSetNumber MPU_vEventGroupSetNumber
#endif /* #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
/* Privileged only wrappers for Event Group APIs. These are needed so that
* the application can use opaque handles maintained in mpu_wrappers.c
* with all the APIs. */
#define xEventGroupCreate MPU_xEventGroupCreate
#define xEventGroupCreateStatic MPU_xEventGroupCreateStatic
#define vEventGroupDelete MPU_vEventGroupDelete
#if ( configUSE_MPU_WRAPPERS_V1 == 0 )
#define xEventGroupGetStaticBuffer MPU_xEventGroupGetStaticBuffer
#define xEventGroupClearBitsFromISR MPU_xEventGroupClearBitsFromISR
#define xEventGroupSetBitsFromISR MPU_xEventGroupSetBitsFromISR
#define xEventGroupGetBitsFromISR MPU_xEventGroupGetBitsFromISR
#endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
/* Map standard message/stream_buffer.h API functions to the MPU
* equivalents. */
#define xStreamBufferSend MPU_xStreamBufferSend
#define xStreamBufferReceive MPU_xStreamBufferReceive
#define xStreamBufferIsFull MPU_xStreamBufferIsFull
#define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty
#define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable
#define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable
#define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel
#define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes
/* Privileged only wrappers for Stream Buffer APIs. These are needed so that
* the application can use opaque handles maintained in mpu_wrappers.c
* with all the APIs. */
#define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate
#define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic
#define vStreamBufferDelete MPU_vStreamBufferDelete
#define xStreamBufferReset MPU_xStreamBufferReset
#if ( configUSE_MPU_WRAPPERS_V1 == 0 )
#define xStreamBufferGetStaticBuffers MPU_xStreamBufferGetStaticBuffers
#define xStreamBufferSendFromISR MPU_xStreamBufferSendFromISR
#define xStreamBufferReceiveFromISR MPU_xStreamBufferReceiveFromISR
#define xStreamBufferSendCompletedFromISR MPU_xStreamBufferSendCompletedFromISR
#define xStreamBufferReceiveCompletedFromISR MPU_xStreamBufferReceiveCompletedFromISR
#define xStreamBufferResetFromISR MPU_xStreamBufferResetFromISR
#endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
#if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
#define vGrantAccessToTask( xTask, xTaskToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToGrantAccess ) )
#define vRevokeAccessToTask( xTask, xTaskToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToRevokeAccess ) )
#define vGrantAccessToSemaphore( xTask, xSemaphoreToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToGrantAccess ) )
#define vRevokeAccessToSemaphore( xTask, xSemaphoreToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToRevokeAccess ) )
#define vGrantAccessToQueue( xTask, xQueueToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToGrantAccess ) )
#define vRevokeAccessToQueue( xTask, xQueueToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToRevokeAccess ) )
#define vGrantAccessToQueueSet( xTask, xQueueSetToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToGrantAccess ) )
#define vRevokeAccessToQueueSet( xTask, xQueueSetToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToRevokeAccess ) )
#define vGrantAccessToEventGroup( xTask, xEventGroupToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToGrantAccess ) )
#define vRevokeAccessToEventGroup( xTask, xEventGroupToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToRevokeAccess ) )
#define vGrantAccessToStreamBuffer( xTask, xStreamBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToGrantAccess ) )
#define vRevokeAccessToStreamBuffer( xTask, xStreamBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToRevokeAccess ) )
#define vGrantAccessToMessageBuffer( xTask, xMessageBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToGrantAccess ) )
#define vRevokeAccessToMessageBuffer( xTask, xMessageBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToRevokeAccess ) )
#define vGrantAccessToTimer( xTask, xTimerToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToGrantAccess ) )
#define vRevokeAccessToTimer( xTask, xTimerToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToRevokeAccess ) )
#endif /* #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) */
#endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
#define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) )
#define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
#define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) )
#else /* portUSING_MPU_WRAPPERS */
#if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) // Mega with 2560
#define PRIVILEGED_FUNCTION __attribute__ ((hot))
#define PRIVILEGED_DATA
#define FREERTOS_SYSTEM_CALL __attribute__ ((hot))
#define portUSING_MPU_WRAPPERS 0
#elif defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega664P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284PA__) // Goldilocks with 1284p
#define PRIVILEGED_FUNCTION __attribute__ ((hot))
#define PRIVILEGED_DATA
#define FREERTOS_SYSTEM_CALL __attribute__ ((hot))
#define portUSING_MPU_WRAPPERS 0
#else // Uno with 328p or Leonardo with 32u4
#define PRIVILEGED_FUNCTION __attribute__ ((hot))
#define PRIVILEGED_DATA
#define FREERTOS_SYSTEM_CALL __attribute__ ((hot))
#define portUSING_MPU_WRAPPERS 0
#endif
#endif /* portUSING_MPU_WRAPPERS */
#endif /* MPU_WRAPPERS_H */

View File

@ -0,0 +1,204 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*-----------------------------------------------------------
* Implementation of functions defined in portable.h for the RISC-V port.
*----------------------------------------------------------*/
/* Scheduler includes. */
#include "Arduino_FreeRTOS.h"
#include "task.h"
#include "portmacro.h"
/* Standard includes. */
#include "string.h"
#ifdef configCLINT_BASE_ADDRESS
#warning "The configCLINT_BASE_ADDRESS constant has been deprecated. configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS are currently being derived from the (possibly 0) configCLINT_BASE_ADDRESS setting. Please update to define configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS directly in place of configCLINT_BASE_ADDRESS. See www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html"
#endif
#ifndef configMTIME_BASE_ADDRESS
#warning "configMTIME_BASE_ADDRESS must be defined in FreeRTOSConfig.h. If the target chip includes a memory-mapped mtime register then set configMTIME_BASE_ADDRESS to the mapped address. Otherwise set configMTIME_BASE_ADDRESS to 0. See www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html"
#endif
#ifndef configMTIMECMP_BASE_ADDRESS
#warning "configMTIMECMP_BASE_ADDRESS must be defined in FreeRTOSConfig.h. If the target chip includes a memory-mapped mtimecmp register then set configMTIMECMP_BASE_ADDRESS to the mapped address. Otherwise set configMTIMECMP_BASE_ADDRESS to 0. See www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html"
#endif
/* Let the user override the pre-loading of the initial RA. */
#ifdef configTASK_RETURN_ADDRESS
#define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
#else
#define portTASK_RETURN_ADDRESS 0
#endif
/* The stack used by interrupt service routines. Set configISR_STACK_SIZE_WORDS
* to use a statically allocated array as the interrupt stack. Alternative leave
* configISR_STACK_SIZE_WORDS undefined and update the linker script so that a
* linker variable names __freertos_irq_stack_top has the same value as the top
* of the stack used by main. Using the linker script method will repurpose the
* stack that was used by main before the scheduler was started for use as the
* interrupt stack after the scheduler has started. */
#ifdef configISR_STACK_SIZE_WORDS
static __attribute__( ( aligned( 16 ) ) ) StackType_t xISRStack[ configISR_STACK_SIZE_WORDS ] = { 0 };
const StackType_t xISRStackTop = ( StackType_t ) &( xISRStack[ configISR_STACK_SIZE_WORDS & ~portBYTE_ALIGNMENT_MASK ] );
/* Don't use 0xa5 as the stack fill bytes as that is used by the kernel for
* the task stacks, and so will legitimately appear in many positions within
* the ISR stack. */
#define portISR_STACK_FILL_BYTE 0xee
#else
extern const uint32_t __freertos_irq_stack_top[];
const StackType_t xISRStackTop = ( StackType_t ) __freertos_irq_stack_top;
#endif
/*
* Setup the timer to generate the tick interrupts. The implementation in this
* file is weak to allow application writers to change the timer used to
* generate the tick interrupt.
*/
void vPortSetupTimerInterrupt( void ) __attribute__( ( weak ) );
/*-----------------------------------------------------------*/
/* Used to program the machine timer compare register. */
uint64_t ullNextTime = 0ULL;
const uint64_t * pullNextTime = &ullNextTime;
const size_t uxTimerIncrementsForOneTick = ( size_t ) ( ( configCPU_CLOCK_HZ ) / ( configTICK_RATE_HZ ) ); /* Assumes increment won't go over 32-bits. */
const size_t ullMachineTimerCompareRegisterBase = configMTIMECMP_BASE_ADDRESS;
volatile uint64_t * pullMachineTimerCompareRegister = NULL;
/* Holds the critical nesting value - deliberately non-zero at start up to
* ensure interrupts are not accidentally enabled before the scheduler starts. */
size_t xCriticalNesting = ( size_t ) 0xaaaaaaaa;
size_t * pxCriticalNesting = &xCriticalNesting;
/* Used to catch tasks that attempt to return from their implementing function. */
size_t xTaskReturnAddress = ( size_t ) portTASK_RETURN_ADDRESS;
/* Set configCHECK_FOR_STACK_OVERFLOW to 3 to add ISR stack checking to task
* stack checking. A problem in the ISR stack will trigger an assert, not call
* the stack overflow hook function (because the stack overflow hook is specific
* to a task stack, not the ISR stack). */
#if defined( configISR_STACK_SIZE_WORDS ) && ( configCHECK_FOR_STACK_OVERFLOW > 2 )
#warning "This path not tested, or even compiled yet."
static const uint8_t ucExpectedStackBytes[] =
{
portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, \
portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, \
portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, \
portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, \
portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE, portISR_STACK_FILL_BYTE
}; \
#define portCHECK_ISR_STACK() configASSERT( ( memcmp( ( void * ) xISRStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) == 0 ) )
#else /* if defined( configISR_STACK_SIZE_WORDS ) && ( configCHECK_FOR_STACK_OVERFLOW > 2 ) */
/* Define the function away. */
#define portCHECK_ISR_STACK()
#endif /* configCHECK_FOR_STACK_OVERFLOW > 2 */
/*-----------------------------------------------------------*/
#if ( configMTIME_BASE_ADDRESS != 0 ) && ( configMTIMECMP_BASE_ADDRESS != 0 )
void vPortSetupTimerInterrupt( void )
{
uint32_t ulCurrentTimeHigh, ulCurrentTimeLow;
volatile uint32_t * const pulTimeHigh = ( volatile uint32_t * const ) ( ( configMTIME_BASE_ADDRESS ) + 4UL ); /* 8-byte type so high 32-bit word is 4 bytes up. */
volatile uint32_t * const pulTimeLow = ( volatile uint32_t * const ) ( configMTIME_BASE_ADDRESS );
pullMachineTimerCompareRegister = ( volatile uint64_t * ) ( ullMachineTimerCompareRegisterBase );
do
{
ulCurrentTimeHigh = *pulTimeHigh;
ulCurrentTimeLow = *pulTimeLow;
} while( ulCurrentTimeHigh != *pulTimeHigh );
ullNextTime = ( uint64_t ) ulCurrentTimeHigh;
ullNextTime <<= 32ULL; /* High 4-byte word is 32-bits up. */
ullNextTime |= ( uint64_t ) ulCurrentTimeLow;
ullNextTime += ( uint64_t ) uxTimerIncrementsForOneTick;
*pullMachineTimerCompareRegister = ullNextTime;
/* Prepare the time to use after the next tick interrupt. */
ullNextTime += ( uint64_t ) uxTimerIncrementsForOneTick;
}
#endif /* ( configMTIME_BASE_ADDRESS != 0 ) && ( configMTIME_BASE_ADDRESS != 0 ) */
/*-----------------------------------------------------------*/
BaseType_t xPortStartScheduler( void )
{
extern void xPortStartFirstTask( void );
#if ( configASSERT_DEFINED == 1 )
{
/* Check alignment of the interrupt stack - which is the same as the
* stack that was being used by main() prior to the scheduler being
* started. */
configASSERT( ( xISRStackTop & portBYTE_ALIGNMENT_MASK ) == 0 );
#ifdef configISR_STACK_SIZE_WORDS
{
memset( ( void * ) xISRStack, portISR_STACK_FILL_BYTE, sizeof( xISRStack ) );
}
#endif /* configISR_STACK_SIZE_WORDS */
}
#endif /* configASSERT_DEFINED */
/* If there is a CLINT then it is ok to use the default implementation
* in this file, otherwise vPortSetupTimerInterrupt() must be implemented to
* configure whichever clock is to be used to generate the tick interrupt. */
vPortSetupTimerInterrupt();
#if ( ( configMTIME_BASE_ADDRESS != 0 ) && ( configMTIMECMP_BASE_ADDRESS != 0 ) )
{
/* Enable mtime and external interrupts. 1<<7 for timer interrupt,
* 1<<11 for external interrupt. _RB_ What happens here when mtime is
* not present as with pulpino? */
__asm volatile ( "csrs mie, %0" ::"r" ( 0x880 ) );
}
#endif /* ( configMTIME_BASE_ADDRESS != 0 ) && ( configMTIMECMP_BASE_ADDRESS != 0 ) */
xPortStartFirstTask();
/* Should not get here as after calling xPortStartFirstTask() only tasks
* should be executing. */
return pdFAIL;
}
/*-----------------------------------------------------------*/
void vPortEndScheduler( void )
{
/* Not implemented. */
for( ; ; )
{
}
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,385 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* The FreeRTOS kernel's RISC-V port is split between the the code that is
* common across all currently supported RISC-V chips (implementations of the
* RISC-V ISA), and code which tailors the port to a specific RISC-V chip:
*
* + The code that is common to all RISC-V chips is implemented in
* FreeRTOS\Source\portable\GCC\RISC-V-RV32\portASM.S. There is only one
* portASM.S file because the same file is used no matter which RISC-V chip is
* in use.
*
* + The code that tailors the kernel's RISC-V port to a specific RISC-V
* chip is implemented in freertos_risc_v_chip_specific_extensions.h. There
* is one freertos_risc_v_chip_specific_extensions.h that can be used with any
* RISC-V chip that both includes a standard CLINT and does not add to the
* base set of RISC-V registers. There are additional
* freertos_risc_v_chip_specific_extensions.h files for RISC-V implementations
* that do not include a standard CLINT or do add to the base set of RISC-V
* registers.
*
* CARE MUST BE TAKEN TO INCLDUE THE CORRECT
* freertos_risc_v_chip_specific_extensions.h HEADER FILE FOR THE CHIP
* IN USE. To include the correct freertos_risc_v_chip_specific_extensions.h
* header file ensure the path to the correct header file is in the assembler's
* include path.
*
* This freertos_risc_v_chip_specific_extensions.h is for use on RISC-V chips
* that include a standard CLINT and do not add to the base set of RISC-V
* registers.
*
*/
#include "portContext.h"
/* Check the freertos_risc_v_chip_specific_extensions.h and/or command line
definitions. */
#if defined( portasmHAS_CLINT ) && defined( portasmHAS_MTIME )
#error The portasmHAS_CLINT constant has been deprecated. Please replace it with portasmHAS_MTIME. portasmHAS_CLINT and portasmHAS_MTIME cannot both be defined at once. See https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html
#endif
#ifdef portasmHAS_CLINT
#warning The portasmHAS_CLINT constant has been deprecated. Please replace it with portasmHAS_MTIME and portasmHAS_SIFIVE_CLINT. For now portasmHAS_MTIME and portasmHAS_SIFIVE_CLINT are derived from portasmHAS_CLINT. See https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html
#define portasmHAS_MTIME portasmHAS_CLINT
#define portasmHAS_SIFIVE_CLINT portasmHAS_CLINT
#endif
#ifndef portasmHAS_MTIME
#error freertos_risc_v_chip_specific_extensions.h must define portasmHAS_MTIME to either 1 (MTIME clock present) or 0 (MTIME clock not present). See https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html
#endif
#ifndef portasmHAS_SIFIVE_CLINT
#define portasmHAS_SIFIVE_CLINT 0
#endif
.global xPortStartFirstTask
.global pxPortInitialiseStack
.global freertos_risc_v_exception_handler
.global freertos_risc_v_interrupt_handler
.global freertos_risc_v_mtimer_interrupt_handler
.global raw_trap_handler
.extern vTaskSwitchContext
.extern xTaskIncrementTick
.extern pullMachineTimerCompareRegister
.extern pullNextTime
.extern uxTimerIncrementsForOneTick /* size_t type so 32-bit on 32-bit core and 64-bits on 64-bit core. */
.extern xTaskReturnAddress
.extern trap_handler
.weak freertos_risc_v_application_exception_handler
.weak freertos_risc_v_application_interrupt_handler
/*-----------------------------------------------------------*/
.macro portUPDATE_MTIMER_COMPARE_REGISTER
load_x a0, pullMachineTimerCompareRegister /* Load address of compare register into a0. */
load_x a1, pullNextTime /* Load the address of ullNextTime into a1. */
#if( __riscv_xlen == 32 )
/* Update the 64-bit mtimer compare match value in two 32-bit writes. */
li a4, -1
lw a2, 0(a1) /* Load the low word of ullNextTime into a2. */
lw a3, 4(a1) /* Load the high word of ullNextTime into a3. */
sw a4, 0(a0) /* Low word no smaller than old value to start with - will be overwritten below. */
sw a3, 4(a0) /* Store high word of ullNextTime into compare register. No smaller than new value. */
sw a2, 0(a0) /* Store low word of ullNextTime into compare register. */
lw t0, uxTimerIncrementsForOneTick /* Load the value of ullTimerIncrementForOneTick into t0 (could this be optimized by storing in an array next to pullNextTime?). */
add a4, t0, a2 /* Add the low word of ullNextTime to the timer increments for one tick (assumes timer increment for one tick fits in 32-bits). */
sltu t1, a4, a2 /* See if the sum of low words overflowed (what about the zero case?). */
add t2, a3, t1 /* Add overflow to high word of ullNextTime. */
sw a4, 0(a1) /* Store new low word of ullNextTime. */
sw t2, 4(a1) /* Store new high word of ullNextTime. */
#endif /* __riscv_xlen == 32 */
#if( __riscv_xlen == 64 )
/* Update the 64-bit mtimer compare match value. */
ld t2, 0(a1) /* Load ullNextTime into t2. */
sd t2, 0(a0) /* Store ullNextTime into compare register. */
ld t0, uxTimerIncrementsForOneTick /* Load the value of ullTimerIncrementForOneTick into t0 (could this be optimized by storing in an array next to pullNextTime?). */
add t4, t0, t2 /* Add ullNextTime to the timer increments for one tick. */
sd t4, 0(a1) /* Store ullNextTime. */
#endif /* __riscv_xlen == 64 */
.endm
/*-----------------------------------------------------------*/
/*
* Unlike other ports pxPortInitialiseStack() is written in assembly code as it
* needs access to the portasmADDITIONAL_CONTEXT_SIZE constant. The prototype
* for the function is as per the other ports:
* StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters );
*
* As per the standard RISC-V ABI pxTopOfStack is passed in in a0, pxCode in
* a1, and pvParameters in a2. The new top of stack is passed out in a0.
*
* RISC-V maps registers to ABI names as follows (X1 to X31 integer registers
* for the 'I' profile, X1 to X15 for the 'E' profile, currently I assumed).
*
* Register ABI Name Description Saver
* x0 zero Hard-wired zero -
* x1 ra Return address Caller
* x2 sp Stack pointer Callee
* x3 gp Global pointer -
* x4 tp Thread pointer -
* x5-7 t0-2 Temporaries Caller
* x8 s0/fp Saved register/Frame pointer Callee
* x9 s1 Saved register Callee
* x10-11 a0-1 Function Arguments/return values Caller
* x12-17 a2-7 Function arguments Caller
* x18-27 s2-11 Saved registers Callee
* x28-31 t3-6 Temporaries Caller
*
* The RISC-V context is saved to FreeRTOS tasks in the following stack frame,
* where the global and thread pointers are currently assumed to be constant so
* are not saved:
*
* mstatus
* xCriticalNesting
* x31
* x30
* x29
* x28
* x27
* x26
* x25
* x24
* x23
* x22
* x21
* x20
* x19
* x18
* x17
* x16
* x15
* x14
* x13
* x12
* x11
* pvParameters
* x9
* x8
* x7
* x6
* x5
* portTASK_RETURN_ADDRESS
* [chip specific registers go here]
* pxCode
*/
pxPortInitialiseStack:
csrr t0, mstatus /* Obtain current mstatus value. */
andi t0, t0, ~0x8 /* Ensure interrupts are disabled when the stack is restored within an ISR. Required when a task is created after the schedulre has been started, otherwise interrupts would be disabled anyway. */
addi t1, x0, 0x188 /* Generate the value 0x1880, which are the MPIE and MPP bits to set in mstatus. */
slli t1, t1, 4
or t0, t0, t1 /* Set MPIE and MPP bits in mstatus value. */
addi a0, a0, -portWORD_SIZE
store_x t0, 0(a0) /* mstatus onto the stack. */
addi a0, a0, -portWORD_SIZE /* Space for critical nesting count. */
store_x x0, 0(a0) /* Critical nesting count starts at 0 for every task. */
#ifdef __riscv_32e
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x10-x15. */
#else
addi a0, a0, -(22 * portWORD_SIZE) /* Space for registers x10-x31. */
#endif
store_x a2, 0(a0) /* Task parameters (pvParameters parameter) goes into register X10/a0 on the stack. */
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x5-x9 + taskReturnAddress. */
load_x t0, xTaskReturnAddress
store_x t0, 0(a0) /* Return address onto the stack. */
addi t0, x0, portasmADDITIONAL_CONTEXT_SIZE /* The number of chip specific additional registers. */
chip_specific_stack_frame: /* First add any chip specific registers to the stack frame being created. */
beq t0, x0, 1f /* No more chip specific registers to save. */
addi a0, a0, -portWORD_SIZE /* Make space for chip specific register. */
store_x x0, 0(a0) /* Give the chip specific register an initial value of zero. */
addi t0, t0, -1 /* Decrement the count of chip specific registers remaining. */
j chip_specific_stack_frame /* Until no more chip specific registers. */
1:
addi a0, a0, -portWORD_SIZE
store_x a1, 0(a0) /* mret value (pxCode parameter) onto the stack. */
ret
/*-----------------------------------------------------------*/
xPortStartFirstTask:
load_x sp, pxCurrentTCB /* Load pxCurrentTCB. */
load_x sp, 0( sp ) /* Read sp from first TCB member. */
load_x x1, 0( sp ) /* Note for starting the scheduler the exception return address is used as the function return address. */
portasmRESTORE_ADDITIONAL_REGISTERS /* Defined in freertos_risc_v_chip_specific_extensions.h to restore any registers unique to the RISC-V implementation. */
load_x x7, 4 * portWORD_SIZE( sp ) /* t2 */
load_x x8, 5 * portWORD_SIZE( sp ) /* s0/fp */
load_x x9, 6 * portWORD_SIZE( sp ) /* s1 */
load_x x10, 7 * portWORD_SIZE( sp ) /* a0 */
load_x x11, 8 * portWORD_SIZE( sp ) /* a1 */
load_x x12, 9 * portWORD_SIZE( sp ) /* a2 */
load_x x13, 10 * portWORD_SIZE( sp ) /* a3 */
load_x x14, 11 * portWORD_SIZE( sp ) /* a4 */
load_x x15, 12 * portWORD_SIZE( sp ) /* a5 */
#ifndef __riscv_32e
load_x x16, 13 * portWORD_SIZE( sp ) /* a6 */
load_x x17, 14 * portWORD_SIZE( sp ) /* a7 */
load_x x18, 15 * portWORD_SIZE( sp ) /* s2 */
load_x x19, 16 * portWORD_SIZE( sp ) /* s3 */
load_x x20, 17 * portWORD_SIZE( sp ) /* s4 */
load_x x21, 18 * portWORD_SIZE( sp ) /* s5 */
load_x x22, 19 * portWORD_SIZE( sp ) /* s6 */
load_x x23, 20 * portWORD_SIZE( sp ) /* s7 */
load_x x24, 21 * portWORD_SIZE( sp ) /* s8 */
load_x x25, 22 * portWORD_SIZE( sp ) /* s9 */
load_x x26, 23 * portWORD_SIZE( sp ) /* s10 */
load_x x27, 24 * portWORD_SIZE( sp ) /* s11 */
load_x x28, 25 * portWORD_SIZE( sp ) /* t3 */
load_x x29, 26 * portWORD_SIZE( sp ) /* t4 */
load_x x30, 27 * portWORD_SIZE( sp ) /* t5 */
load_x x31, 28 * portWORD_SIZE( sp ) /* t6 */
#endif
load_x x5, portCRITICAL_NESTING_OFFSET * portWORD_SIZE( sp ) /* Obtain xCriticalNesting value for this task from task's stack. */
load_x x6, pxCriticalNesting /* Load the address of xCriticalNesting into x6. */
store_x x5, 0( x6 ) /* Restore the critical nesting value for this task. */
load_x x5, portMSTATUS_OFFSET * portWORD_SIZE( sp ) /* Initial mstatus into x5 (t0). */
addi x5, x5, 0x08 /* Set MIE bit so the first task starts with interrupts enabled - required as returns with ret not eret. */
csrrw x0, mstatus, x5 /* Interrupts enabled from here! */
load_x x5, 2 * portWORD_SIZE( sp ) /* Initial x5 (t0) value. */
load_x x6, 3 * portWORD_SIZE( sp ) /* Initial x6 (t1) value. */
addi sp, sp, portCONTEXT_SIZE
ret
/*-----------------------------------------------------------*/
freertos_risc_v_application_exception_handler:
csrr t0, mcause /* For viewing in the debugger only. */
csrr t1, mepc /* For viewing in the debugger only */
csrr t2, mstatus /* For viewing in the debugger only */
j .
/*-----------------------------------------------------------*/
freertos_risc_v_application_interrupt_handler:
csrr t0, mcause /* For viewing in the debugger only. */
csrr t1, mepc /* For viewing in the debugger only */
csrr t2, mstatus /* For viewing in the debugger only */
j .
/*-----------------------------------------------------------*/
.section .text.freertos_risc_v_exception_handler
freertos_risc_v_exception_handler:
portcontextSAVE_EXCEPTION_CONTEXT
/* a0 now contains mcause. */
li t0, 11 /* 11 == environment call. */
bne a0, t0, other_exception /* Not an M environment call, so some other exception. */
call vTaskSwitchContext
portcontextRESTORE_CONTEXT
other_exception:
call freertos_risc_v_application_exception_handler
portcontextRESTORE_CONTEXT
/*-----------------------------------------------------------*/
.section .text.freertos_risc_v_interrupt_handler
freertos_risc_v_interrupt_handler:
portcontextSAVE_INTERRUPT_CONTEXT
call freertos_risc_v_application_interrupt_handler
portcontextRESTORE_CONTEXT
/*-----------------------------------------------------------*/
.section .text.freertos_risc_v_mtimer_interrupt_handler
freertos_risc_v_mtimer_interrupt_handler:
portcontextSAVE_INTERRUPT_CONTEXT
portUPDATE_MTIMER_COMPARE_REGISTER
call xTaskIncrementTick
beqz a0, exit_without_context_switch /* Don't switch context if incrementing tick didn't unblock a task. */
call vTaskSwitchContext
exit_without_context_switch:
portcontextRESTORE_CONTEXT
/*-----------------------------------------------------------*/
.section .ram_text
.align 8
raw_trap_handler: /*Intercept trap from weak function from crt0.s*/
portcontextSAVE_CONTEXT_INTERNAL
csrr a0, mcause
csrr a1, mepc
bge a0, x0, synchronous_exception
asynchronous_interrupt:
store_x a1, 0( sp ) /* Asynchronous interrupt so save unmodified exception return address. */
load_x sp, xISRStackTop /* Switch to ISR stack. */
j handle_interrupt
synchronous_exception:
addi a1, a1, 4 /* Synchronous so update exception return address to the instruction after the instruction that generated the exeption. */
store_x a1, 0( sp ) /* Save updated exception return address. */
load_x sp, xISRStackTop /* Switch to ISR stack. */
j handle_exception
handle_interrupt:
#if( portasmHAS_MTIME != 0 )
test_if_mtimer: /* If there is a CLINT then the mtimer is used to generate the tick interrupt. */
addi t0, x0, 1
slli t0, t0, __riscv_xlen - 1 /* LSB is already set, shift into MSB. Shift 31 on 32-bit or 63 on 64-bit cores. */
addi t1, t0, 7 /* 0x8000[]0007 == machine timer interrupt. */
bne a0, t1, application_interrupt_handler
portUPDATE_MTIMER_COMPARE_REGISTER
call xTaskIncrementTick
beqz a0, processed_source /* Don't switch context if incrementing tick didn't unblock a task. */
call vTaskSwitchContext
j processed_source
#endif /* portasmHAS_MTIME */
application_interrupt_handler:
call trap_handler
j processed_source
handle_exception:
/* a0 contains mcause. */
li t0, 11 /* 11 == environment call. */
bne a0, t0, application_exception_handler /* Not an M environment call, so some other exception. */
call vTaskSwitchContext
j processed_source
application_exception_handler:
call freertos_risc_v_application_exception_handler
j processed_source /* No other exceptions handled yet. */
processed_source:
portcontextRESTORE_CONTEXT
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,192 @@
/*
* FreeRTOS Kernel V11.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef PORTCONTEXT_H
#define PORTCONTEXT_H
#if __riscv_xlen == 64
#define portWORD_SIZE 8
#define store_x sd
#define load_x ld
#elif __riscv_xlen == 32
#define store_x sw
#define load_x lw
#define portWORD_SIZE 4
#else
#error Assembler did not define __riscv_xlen
#endif
#include "freertos_risc_v_chip_specific_extensions.h"
/* Only the standard core registers are stored by default. Any additional
* registers must be saved by the portasmSAVE_ADDITIONAL_REGISTERS and
* portasmRESTORE_ADDITIONAL_REGISTERS macros - which can be defined in a chip
* specific version of freertos_risc_v_chip_specific_extensions.h. See the
* notes at the top of portASM.S file. */
#ifdef __riscv_32e
#define portCONTEXT_SIZE ( 15 * portWORD_SIZE )
#define portCRITICAL_NESTING_OFFSET 13
#define portMSTATUS_OFFSET 14
#else
#define portCONTEXT_SIZE ( 31 * portWORD_SIZE )
#define portCRITICAL_NESTING_OFFSET 29
#define portMSTATUS_OFFSET 30
#endif
/*-----------------------------------------------------------*/
.extern pxCurrentTCB
.extern xISRStackTop
.extern xCriticalNesting
.extern pxCriticalNesting
/*-----------------------------------------------------------*/
.macro portcontextSAVE_CONTEXT_INTERNAL
addi sp, sp, -portCONTEXT_SIZE
store_x x1, 1 * portWORD_SIZE( sp )
store_x x5, 2 * portWORD_SIZE( sp )
store_x x6, 3 * portWORD_SIZE( sp )
store_x x7, 4 * portWORD_SIZE( sp )
store_x x8, 5 * portWORD_SIZE( sp )
store_x x9, 6 * portWORD_SIZE( sp )
store_x x10, 7 * portWORD_SIZE( sp )
store_x x11, 8 * portWORD_SIZE( sp )
store_x x12, 9 * portWORD_SIZE( sp )
store_x x13, 10 * portWORD_SIZE( sp )
store_x x14, 11 * portWORD_SIZE( sp )
store_x x15, 12 * portWORD_SIZE( sp )
#ifndef __riscv_32e
store_x x16, 13 * portWORD_SIZE( sp )
store_x x17, 14 * portWORD_SIZE( sp )
store_x x18, 15 * portWORD_SIZE( sp )
store_x x19, 16 * portWORD_SIZE( sp )
store_x x20, 17 * portWORD_SIZE( sp )
store_x x21, 18 * portWORD_SIZE( sp )
store_x x22, 19 * portWORD_SIZE( sp )
store_x x23, 20 * portWORD_SIZE( sp )
store_x x24, 21 * portWORD_SIZE( sp )
store_x x25, 22 * portWORD_SIZE( sp )
store_x x26, 23 * portWORD_SIZE( sp )
store_x x27, 24 * portWORD_SIZE( sp )
store_x x28, 25 * portWORD_SIZE( sp )
store_x x29, 26 * portWORD_SIZE( sp )
store_x x30, 27 * portWORD_SIZE( sp )
store_x x31, 28 * portWORD_SIZE( sp )
#endif /* ifndef __riscv_32e */
load_x t0, xCriticalNesting /* Load the value of xCriticalNesting into t0. */
store_x t0, portCRITICAL_NESTING_OFFSET * portWORD_SIZE( sp ) /* Store the critical nesting value to the stack. */
csrr t0, mstatus /* Required for MPIE bit. */
store_x t0, portMSTATUS_OFFSET * portWORD_SIZE( sp )
portasmSAVE_ADDITIONAL_REGISTERS /* Defined in freertos_risc_v_chip_specific_extensions.h to save any registers unique to the RISC-V implementation. */
load_x t0, pxCurrentTCB /* Load pxCurrentTCB. */
store_x sp, 0 ( t0 ) /* Write sp to first TCB member. */
.endm
/*-----------------------------------------------------------*/
.macro portcontextSAVE_EXCEPTION_CONTEXT
portcontextSAVE_CONTEXT_INTERNAL
csrr a0, mcause
csrr a1, mepc
addi a1, a1, 4 /* Synchronous so update exception return address to the instruction after the instruction that generated the exception. */
store_x a1, 0 ( sp ) /* Save updated exception return address. */
load_x sp, xISRStackTop /* Switch to ISR stack. */
.endm
/*-----------------------------------------------------------*/
.macro portcontextSAVE_INTERRUPT_CONTEXT
portcontextSAVE_CONTEXT_INTERNAL
csrr a0, mcause
csrr a1, mepc
store_x a1, 0 ( sp ) /* Asynchronous interrupt so save unmodified exception return address. */
load_x sp, xISRStackTop /* Switch to ISR stack. */
.endm
/*-----------------------------------------------------------*/
.macro portcontextRESTORE_CONTEXT
load_x t1, pxCurrentTCB /* Load pxCurrentTCB. */
load_x sp, 0 ( t1 ) /* Read sp from first TCB member. */
/* Load mepc with the address of the instruction in the task to run next. */
load_x t0, 0 ( sp )
csrw mepc, t0
/* Defined in freertos_risc_v_chip_specific_extensions.h to restore any registers unique to the RISC-V implementation. */
portasmRESTORE_ADDITIONAL_REGISTERS
/* Load mstatus with the interrupt enable bits used by the task. */
load_x t0, portMSTATUS_OFFSET * portWORD_SIZE( sp )
csrw mstatus, t0 /* Required for MPIE bit. */
load_x t0, portCRITICAL_NESTING_OFFSET * portWORD_SIZE( sp ) /* Obtain xCriticalNesting value for this task from task's stack. */
load_x t1, pxCriticalNesting /* Load the address of xCriticalNesting into t1. */
store_x t0, 0 ( t1 ) /* Restore the critical nesting value for this task. */
load_x x1, 1 * portWORD_SIZE( sp )
load_x x5, 2 * portWORD_SIZE( sp )
load_x x6, 3 * portWORD_SIZE( sp )
load_x x7, 4 * portWORD_SIZE( sp )
load_x x8, 5 * portWORD_SIZE( sp )
load_x x9, 6 * portWORD_SIZE( sp )
load_x x10, 7 * portWORD_SIZE( sp )
load_x x11, 8 * portWORD_SIZE( sp )
load_x x12, 9 * portWORD_SIZE( sp )
load_x x13, 10 * portWORD_SIZE( sp )
load_x x14, 11 * portWORD_SIZE( sp )
load_x x15, 12 * portWORD_SIZE( sp )
#ifndef __riscv_32e
load_x x16, 13 * portWORD_SIZE( sp )
load_x x17, 14 * portWORD_SIZE( sp )
load_x x18, 15 * portWORD_SIZE( sp )
load_x x19, 16 * portWORD_SIZE( sp )
load_x x20, 17 * portWORD_SIZE( sp )
load_x x21, 18 * portWORD_SIZE( sp )
load_x x22, 19 * portWORD_SIZE( sp )
load_x x23, 20 * portWORD_SIZE( sp )
load_x x24, 21 * portWORD_SIZE( sp )
load_x x25, 22 * portWORD_SIZE( sp )
load_x x26, 23 * portWORD_SIZE( sp )
load_x x27, 24 * portWORD_SIZE( sp )
load_x x28, 25 * portWORD_SIZE( sp )
load_x x29, 26 * portWORD_SIZE( sp )
load_x x30, 27 * portWORD_SIZE( sp )
load_x x31, 28 * portWORD_SIZE( sp )
#endif /* ifndef __riscv_32e */
addi sp, sp, portCONTEXT_SIZE
mret
.endm
/*-----------------------------------------------------------*/
#endif /* PORTCONTEXT_H */

Some files were not shown because too many files have changed in this diff Show More