v0.5.0 #19
22
README.md
@ -8,8 +8,10 @@
|
||||
|
||||
## Платы, входящие в состав пакета
|
||||
Пакет включает в себя поддержку следующих плат:
|
||||
- [Elbear Ace-Uno](./docs/Elbear_description.md) 8 Mb / 16 Mb / 32 Mb
|
||||
- [START-MIK32](./docs/Start_mik32_description.md)
|
||||
- [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)
|
||||
|
||||
## Особенности использования пакета в ArduinoIDE
|
||||
### Цифровые выводы
|
||||
@ -49,13 +51,16 @@
|
||||
|
||||
|Библиотека|Описание|Заметки|
|
||||
|---------|---------|------|
|
||||
|[SPI](https://docs.arduino.cc/language-reference/en/functions/communication/SPI/)|Библиотека для работы с интерфейсом SPI|Для работы используется встроенный SPI1. Доступные делители частоты - `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)`, а не соответствующие отдельные функции|
|
||||
|[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|
|
||||
|
||||
## Протестированные библиотеки
|
||||
|Библиотека|Описание|
|
||||
@ -87,13 +92,18 @@
|
||||
|[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|
|
||||
|
||||
## Протестированные модули
|
||||
Список модулей и шилдов, работа которых была протестирована на платах, входящих в состав пакета поддержки, доступен [здесь](./docs/tested_shields.md).
|
||||
|
||||
# Режим отладки
|
||||
Для всех плат, входящих в состав пакета, доступен режим отладки скетча в ArduinoIDE версии 2. Подготовка к работе в режиме отладки описана в [инструкции.](./docs/debug_description.md)
|
||||
|
||||
# Полезные ссылки
|
||||
* [Материалы по платам ELBEAR ACE-UNO](https://elron.tech/support/#elbear)
|
||||
* [Телеграмм-канал компании (обновления по проекту ELBEAR и другим)](https://t.me/elrontech)
|
||||
* [Материалы по платам ELSOMIK](https://elron.tech/support/#elsomik)
|
||||
* [Материалы по плате START-MIK32](https://wiki.mik32.ru/%D0%9E%D1%82%D0%BB%D0%B0%D0%B4%D0%BE%D1%87%D0%BD%D0%B0%D1%8F_%D0%BF%D0%BB%D0%B0%D1%82%D0%B0_%D0%A1%D1%82%D0%B0%D1%80%D1%82)
|
||||
* [Телеграмм-канал компании](https://t.me/elrontech)
|
||||
|
||||
При возникновении вопросов или выявлении проблем можно оставить заявку [здесь](https://gitflic.ru/project/elron-tech/elbear_arduino_bsp/issue).
|
||||
|
||||
70
boards.txt
@ -1,8 +1,8 @@
|
||||
# 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
|
||||
@ -14,7 +14,7 @@ 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=
|
||||
|
||||
@ -28,8 +28,8 @@ 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
|
||||
@ -41,7 +41,7 @@ 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=
|
||||
|
||||
@ -55,8 +55,8 @@ 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
|
||||
@ -68,7 +68,7 @@ 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=
|
||||
|
||||
@ -81,6 +81,58 @@ aceUno32Mb.build.variant=elbear_ace_uno
|
||||
aceUno32Mb.build.extra_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
|
||||
|
||||
261
bootloaders/elsomik/bootloader.hex
Normal file
@ -0,0 +1,261 @@
|
||||
:020000040100F9
|
||||
:10000000FD62938202400100FD12E39E02FE374131
|
||||
:10001000000213010100B701000293810100B7152E
|
||||
:100020000001938505FF3716000113060602B70687
|
||||
:1000300000029386060039A083A2050023A0560083
|
||||
:1000400091059106E3EAC5FEB71500019385050207
|
||||
:100050003716000113060602B7060002938606262D
|
||||
:1000600039A083A2050023A0560091059106E3EA7A
|
||||
:10007000C5FEB70500029385050337060002130687
|
||||
:10008000062621A023A005009105E3EDC5FEB700DB
|
||||
:100090000001E780C00AB7000001E780C00AB7107E
|
||||
:1000A0000001E780808473005010F5BF828000005B
|
||||
:1000B0000000000000000000000000000000000040
|
||||
:1000C0006F004000197106C20AC40EC612C816CAD3
|
||||
:1000D0001ACC1ECE22D026D22AD42ED632D836DA48
|
||||
:1000E0003ADC3EDEC2C0C6C2CAC4CEC6D2C8D6CA78
|
||||
:1000F000DACCDECEE2D0E6D2EAD4EED6F2D8F6DA28
|
||||
:10010000FADCFEDE970000009380E00482909240CB
|
||||
:100110002241B2414242D2426243F24302549254DB
|
||||
:100120002255B2554256D2566257F2570648964863
|
||||
:100130002649B649464AD64A664BF64B065C965C5B
|
||||
:10014000265DB65D465ED65E665FF65F096173004A
|
||||
:10015000203001A03D432A876373C3029377F700E1
|
||||
:10016000BDEFADE5937606FF3D8ABA960CC34CC34E
|
||||
:100170000CC74CC74107E36BD7FE11E28280B30680
|
||||
:10018000C3408A069702000096966780A600230760
|
||||
:10019000B700A306B7002306B700A305B7002305E1
|
||||
:1001A000B700A304B7002304B700A303B7002303D9
|
||||
:1001B000B700A302B7002302B700A301B7002301D1
|
||||
:1001C000B700A300B7002300B700828093F5F50FB6
|
||||
:1001D00093968500D58D93960501D58D61B793963D
|
||||
:1001E00027009702000096968682E78086FA96801E
|
||||
:1001F000C1171D8F3E96E374C3F8A5B7B707050076
|
||||
:100200000947D8CFB7170500938707C0984385667D
|
||||
:1002100093860640558F98C398471367074098C741
|
||||
:10022000B71708009387074023A0070023A2070001
|
||||
:1002300023A407001307A008D8C77D57D8CF354798
|
||||
:1002400098C3D84F935657018D8AE5DE8280B71741
|
||||
:1002500008009387074023A0070023A2070023A4D8
|
||||
:10026000070023A607007D57D8CF23A40702B7179E
|
||||
:100270000500938707C09843F1769386F63F758F04
|
||||
:1002800098C398471377F7BF98C7B7070500094782
|
||||
:1002900098D38280B71708009387074088D7D84F34
|
||||
:1002A000137707046DDF82803707000203234704BA
|
||||
:1002B000B706000237150800B7450F0023A406044F
|
||||
:1002C0008147014613050540938515240328C50180
|
||||
:1002D000B308F30013780802630C080205C2232256
|
||||
:1002E000170537470F0023A4F60413070724639765
|
||||
:1002F000E700B707000205472383E700B7170800A8
|
||||
:1003000093870740C85342054181828005467DBFDF
|
||||
:100310008507E39DB7FE7DD2B7470F00938707247B
|
||||
:1003200023A4F60423221705E9B7411106C622C407
|
||||
:1003300026C2AA84EF00B022E1689388086A0148C7
|
||||
:100340008147014781460146B70520C72685379476
|
||||
:100350009800EF003006130414687D1419E40D456D
|
||||
:10036000B240224492444101828085452685EF00B7
|
||||
:10037000702005897DF10145E5B7411122C437049C
|
||||
:100380000002930704008C43B70700804AC0BE9563
|
||||
:10039000B707000223AEB70206C626C293974501EF
|
||||
:1003A000130404003709000289E713058900EF00F0
|
||||
:1003B00090290C40B70400029386C4041306001071
|
||||
:1003C00013058900EF0070231C4037070002835695
|
||||
:1003D0008703938707101CC013060010B68763F4C9
|
||||
:1003E000C600930700101384C4041305F400938718
|
||||
:1003F00007F01306100F814513040410231CF702A5
|
||||
:10040000913BA2851385C4043D46EF0010282320AC
|
||||
:1004100004002322040023240400231604002307DD
|
||||
:100420000400B240224492440249410182805D713D
|
||||
:10043000130680028145280886C6293BBD47230C48
|
||||
:10044000F1008947230EF1003ED2E1779387070838
|
||||
:100450002C080A85231AF102E52BB64061618280DF
|
||||
:100460005D71A2C4370400021305840086C6A6C2CB
|
||||
:10047000CAC0652513058400EF00807D85451305FE
|
||||
:100480008400EF00300F8D47814463E3A700AA8406
|
||||
:10049000894513058400EF00F00D937725002A8627
|
||||
:1004A00089E7136625001376F60FA68513058400E9
|
||||
:1004B000EF00B00FE1689388086A0148814701475F
|
||||
:1004C00081460146B705203813058400E525E1681B
|
||||
:1004D00038009388086A1308000285468147014660
|
||||
:1004E000B70599EB1305840023040100E125B71536
|
||||
:1004F00000015146938505FD6800EF0010191309AE
|
||||
:100500008400832709006C0051463ED085473ED2C7
|
||||
:100510006810C1673ED4EF005017B70607009C4231
|
||||
:100520003707F1FF7D17F98F08109CC20D2DB640DB
|
||||
:1005300026449644064961618280411106C6013B0A
|
||||
:100540000537B707008073905730B700008082905E
|
||||
:10055000B2404101828041113707000222C406C621
|
||||
:100560009307070083C76700854613040700638E5F
|
||||
:10057000D70009476388E70023030400B240224400
|
||||
:10058000410182801305000F3133B71708009387AC
|
||||
:100590000740D84F218B09C7D84F13678700D8CFA2
|
||||
:1005A000693FD9BF411106C622C426C24AC083474B
|
||||
:1005B000350005476383E70811472A846389E7000C
|
||||
:1005C0008DCFB24022449244024941018280B70754
|
||||
:1005D000000283D7870391C34D3383474400034709
|
||||
:1005E0005400E2074207BA97370700022320F704B6
|
||||
:1005F000370700022320F700E9B7370900028354C8
|
||||
:1006000089030346050093054500370500021305DD
|
||||
:10061000C5042695EF00700783470400BE94C2040A
|
||||
:10062000C180231C99029307F00FE3FC97F8224442
|
||||
:10063000B24092440249410189B33D45A139B7070F
|
||||
:10064000000283D7870391C30D3B2244B2409244FA
|
||||
:1006500002494101DDB53707000241119306070049
|
||||
:1006600003DF460026C4B704000283A2840422C626
|
||||
:100670003715080037040002B7480F0037430F0052
|
||||
:10068000370E00024AC28147232A04021309FFFFE2
|
||||
:10069000814E814681458143014801461307070089
|
||||
:1006A000130505409388182413030324130ECE1555
|
||||
:1006B000636FE60363850E0009462303C70089C6FE
|
||||
:1006C000B7060002A388F60299C1232A74026304C4
|
||||
:1006D000080023A4540483476700A9E73244A244D6
|
||||
:1006E0001249370500021305C515410165BD814258
|
||||
:1006F0000328C50113780802631B08028502E399E9
|
||||
:1007000012FF89C6B7060002A388F60299C1232A00
|
||||
:100710007402B7470F009387072423A4F404854786
|
||||
:100720002303F7003244A244124941018280E38A44
|
||||
:1007300062FC03284502937FF80F637D260113783E
|
||||
:10074000F80FC29385453308CE002300F801050653
|
||||
:100750000548B9BFB307704093F7F70F6394FF00E4
|
||||
:100760008546D5B7854EEDBF011122CC4EC652C489
|
||||
:1007700037040002B7490F00371ADCBA26CA4AC844
|
||||
:1007800056C25AC006CE13040400370900029389EA
|
||||
:10079000F923930A0003B7040002391A370B000249
|
||||
:1007A000213683274904A303A40063F3F9007133BE
|
||||
:1007B0008347640099C34533E5B783467400638873
|
||||
:1007C0005605930700066381F60603C704038D47A9
|
||||
:1007D000998F8E07B357FA0093F7F70F6393F606D6
|
||||
:1007E0009307170093F7F70F2388F4021147639DCF
|
||||
:1007F000E7003D45453413058B00053E29C113052F
|
||||
:10080000000F493C238804022322090451BF3D45BF
|
||||
:100810002322090423880402B53C793405052312F8
|
||||
:10082000A4003D45853CADBF3D45232209042388F6
|
||||
:1008300004028D340D3583476400B5FFDDB73D45B7
|
||||
:10084000C9B723880402A9BF011106CE22CCC53640
|
||||
:100850003704000213058400C92413058400CD2E3B
|
||||
:10086000E1689388086A0148814778008546014617
|
||||
:10087000B705D9EB1305840023060100252EE16896
|
||||
:100880009388086A01488147014781460146B705B8
|
||||
:1008900038FF13058400392E9532F9350547AA87AC
|
||||
:1008A0006305E50209476300E506054591EBB706D8
|
||||
:1008B0000600DC4A7D771307F73FF98FDCCA014554
|
||||
:1008C00082807D1719EB0D4582809306004037A783
|
||||
:1008D000070013070712B7050500905D7D8E75D2DE
|
||||
:1008E000370606005C4A7D771307F73FF98FD58FEF
|
||||
:1008F00041115CCA02C613073006B2476359F700BC
|
||||
:10090000014541018280856693860680C9B7B2475A
|
||||
:1009100085073EC6DDB791476307F50263EAA70086
|
||||
:100920008547630AF50489476309F5040545828014
|
||||
:10093000A147E31DF5FE0947094501A8FD1781EF11
|
||||
:10094000C8D20D45828005470D45B7A7070093879C
|
||||
:100950000712B7060500905E798E6DD28A05C98DA3
|
||||
:100960004111CCD202C613073006B247635AF700D2
|
||||
:100970000145410182801147C9BF21470145F1B7B7
|
||||
:10098000B24785073EC6D5B70547AA876305E50286
|
||||
:1009900009476302E506054591EBB70606009C4A48
|
||||
: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
|
||||
:1010100000000000000000000000000000000000D0
|
||||
:0400000501000000F6
|
||||
:00000001FF
|
||||
@ -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
|
||||
|
||||
@ -2,8 +2,14 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
// Weak empty variant initialization function.
|
||||
// May be redefined by variant files.
|
||||
void initVariant() __attribute__((weak));
|
||||
void initVariant() { }
|
||||
|
||||
int main()
|
||||
{
|
||||
initVariant(); // for freeRTOS
|
||||
setup();
|
||||
post_init();
|
||||
|
||||
|
||||
@ -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. */
|
||||
|
||||
@ -123,6 +123,7 @@ SECTIONS {
|
||||
PROVIDE(__STACK_START__ = .);
|
||||
. += STACK_SIZE;
|
||||
PROVIDE(__C_STACK_TOP__ = .);
|
||||
PROVIDE(__freertos_irq_stack_top = .);
|
||||
PROVIDE(__STACK_END__ = .);
|
||||
} >ram
|
||||
|
||||
|
||||
23943
cores/arduino/mik32/shared/svd/mik32v2.svd
Normal file
@ -5,7 +5,7 @@
|
||||
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
|
||||
}
|
||||
@ -13,6 +13,10 @@ void __attribute__((weak)) servo_interrupt_handler(void)
|
||||
{
|
||||
// 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
|
||||
}
|
||||
|
||||
void __attribute__((weak)) ISR(void)
|
||||
{
|
||||
@ -21,13 +25,16 @@ void __attribute__((weak)) ISR(void)
|
||||
In the project, you need to create a function of the form:
|
||||
extern "C" void ISR()
|
||||
{
|
||||
// timer16 is taken as an example
|
||||
if (TIM16_GET_ARRM_INT_STATUS(htimer16_1_))
|
||||
if (EPIC_CHECK_TIMER16_1())
|
||||
{
|
||||
// necessary actions
|
||||
// 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);
|
||||
}
|
||||
// reset timer interrupt flags
|
||||
TIM16_CLEAR_INT_MASK(htimer16_1_, 0xFFFFFFFF);
|
||||
}
|
||||
libraries required to use this example:
|
||||
#include "mik32_hal_timer16.h"
|
||||
@ -46,6 +53,10 @@ void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handle
|
||||
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();
|
||||
@ -62,9 +73,12 @@ void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handle
|
||||
if (EPIC_CHECK_UART_1())
|
||||
serial_interrupt_handler(1);
|
||||
|
||||
// i2c interrupt
|
||||
// i2c0 interrupt
|
||||
if (EPIC_CHECK_I2C_0())
|
||||
wire_interrupt_handler(0);
|
||||
|
||||
if (EPIC_CHECK_I2C_1())
|
||||
wire_interrupt_handler();
|
||||
wire_interrupt_handler(1);
|
||||
|
||||
// reset all interrupts
|
||||
EPIC_CLEAR_ALL();
|
||||
|
||||
@ -73,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");
|
||||
@ -86,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;
|
||||
@ -170,7 +170,7 @@ It is recommended to turn off the timer in the following order:
|
||||
*/
|
||||
void analogWriteStop(uint32_t PinNumber)
|
||||
{
|
||||
if ((pwmIsInited > 0) && (digitalPinPwmIsOn(PinNumber)))
|
||||
if (digitalPinHasPWM(PinNumber) && (pwmIsInited > 0) && digitalPinPwmIsOn(PinNumber))
|
||||
{
|
||||
// load the timer address and channel number corresponding to the specified pin
|
||||
htimer32.Instance = pwmPinToTimer(PinNumber);
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include "Arduino.h"
|
||||
#include "pins_arduino.h"
|
||||
#include "mik32_hal_gpio.h"
|
||||
#include "wiring_LL.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -66,51 +67,82 @@ void pinMode(uint32_t PinNumber, uint32_t PinMode)
|
||||
additionalPinsInit(PinNumber);
|
||||
}
|
||||
|
||||
void fastPinMode(uint32_t PinNumber, uint32_t PinMode)
|
||||
{
|
||||
if ((PinNumber>=pinCommonQty()))
|
||||
{
|
||||
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()))
|
||||
{
|
||||
ErrorMsgHandler("digitalWrite(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
|
||||
if (digitalPinHasPWM(PinNumber))
|
||||
|
||||
if (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
|
||||
if (Val == HIGH)
|
||||
GPIO_SET_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
else
|
||||
GPIO_CLEAR_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
// 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 (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
GPIO_PinState pinState = HAL_GPIO_ReadPin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
return (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
|
||||
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 (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
HAL_GPIO_TogglePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
|
||||
GPIO_TOGGLE_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
# Elbear Ace-Uno
|
||||
Особенности работы с платами Elbear Ace-Uno в среде программирования ArduinoIDE.
|
||||
# ELBEAR ACE-UNO
|
||||
Особенности работы с платами ELBEAR ACE-UNO в среде программирования ArduinoIDE.
|
||||
### Функциональное назначение выводов
|
||||

|
||||

|
||||
### Цифровые выводы
|
||||
На плате Elbear Ace-Uno доступны встроенные светодиод и кнопка. Для их использования необходимо воспользоваться макросами `LED_BUILTIN` и `BTN_BUILTIN`, передавая их в качестве аргументов функции вместо номера цифрового вывода. Макросу `LED_BUILTIN` соответствует номер вывода D22, а макросу `BTN_BUILTIN` - D23.
|
||||
На плате ELBEAR ACE-UNO доступны встроенные светодиод и кнопка. Для их использования необходимо воспользоваться макросами `LED_BUILTIN` и `BTN_BUILTIN`, передавая их в качестве аргументов функции вместо номера цифрового вывода. Макросу `LED_BUILTIN` соответствует номер вывода D22, а макросу `BTN_BUILTIN` - D23.
|
||||
### Аналоговые выводы
|
||||
Выводы A0...A5 на плате могут использоваться как в аналоговом, так и в цифровом режиме.
|
||||
Для использования вывода в качестве аналогового необходимо перевести соответствующий DIP-переключатель, расположенный рядом с аналоговыми выводами, в положение OFF. В этом режиме внешнее напряжение, подаваемое на вывод, будет понижаться резистивным делителем перед подачей на микроконтроллер.
|
||||
@ -18,10 +18,10 @@
|
||||
|А4|5|
|
||||
|А5|5|
|
||||
#### ШИМ
|
||||
На плате Elbear Ace-Uno доступно 8 выводов для формирования ШИМ-сигнала: D3, D5, D6, D9...D13. Генерация сигнала осуществляется с помощью 32-битного таймера. Выводы D3, D5, D6, D9 подключены к таймеру 1, выводы D10...D13 подключены к таймеру 2. Выводы, подключенные к одному и тому же таймеру, выдают ШИМ-сигнал одинаковой частоты.
|
||||
Цифровой вывод D10 не может быть использован для генерации ШИМ, если одновременно активен интерфейс SPI. Это ограничение связано с особенностями работы микроконтроллера. Ограничение не распространяется на использование D10 в качестве цифрового вывода при активном SPI.
|
||||
На плате ELBEAR ACE-UNO доступно 8 выводов для формирования ШИМ-сигнала: D3, D5, D6, D9...D13. Генерация сигнала осуществляется с помощью 32-битного таймера. Выводы D3, D5, D6, D9 подключены к таймеру 1, выводы D10...D13 подключены к таймеру 2. Выводы, подключенные к одному и тому же таймеру, выдают ШИМ-сигнал одинаковой частоты.
|
||||
Цифровые выводы D9, D10 не могут быть использованы для генерации ШИМ, если одновременно активен интерфейс SPI (при использовании экземпляра `SPI` недоступен ШИМ на выводе D10, при использовании экземпляра `SPI1` - на выводе D9). Это ограничение связано с особенностями работы микроконтроллера. Ограничение не распространяется на использование D9, D10 в качестве цифрового вывода при активном SPI.
|
||||
### Прерывания
|
||||
На плате Elbear Ace-Uno доступно 8 прерываний, настраиваемых функцией `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`:
|
||||
На плате ELBEAR ACE-UNO доступно 8 прерываний, настраиваемых функцией `void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)`:
|
||||
|
||||
|Цифровой вывод|Номер прерывания|
|
||||
|---------|---------|
|
||||
@ -38,4 +38,8 @@
|
||||
|
||||
### Serial
|
||||
Интерфейс UART0 доступен на выводах D0, D1, для работы с ним используется экземпляр класса под названием `Serial`.
|
||||
Интерфейс UART1 доступен на выводах D7, D8, используемый экземпляр класса - `Serial1`.
|
||||
Интерфейс UART1 доступен на выводах D7, D8, используемый экземпляр класса - `Serial1`.
|
||||
|
||||
### SPI
|
||||
Интерфейс SPI1 доступен на выводах D11, D12, D13. Для работы с ним используется экземпляр класса под названием `SPI`.
|
||||
Интерфейс SPI0 доступен на выводах D3, D5, D6. Используемый экземпляр класса - `SPI1`.
|
||||
BIN
docs/Pinout_nano.PNG
Normal file
|
After Width: | Height: | Size: 1.0 MiB |
BIN
docs/Registers.png
Normal file
|
After Width: | Height: | Size: 102 KiB |
@ -56,4 +56,9 @@
|
||||
Интерфейс UART0 доступен на выводах P0_5, P0_6, для работы с ним используется экземпляр класса под названием `Serial`.
|
||||
Интерфейс UART1 доступен на выводах P1_8, P1_9, используемый экземпляр класса - `Serial1`.
|
||||
USB-UART преобразователь, установленный на плате, поддерживает стандартные скорости UART до 57600 бод. Нестандартные скорости должны быть кратны
|
||||
12*32=384, например, 240000 бод, 768000 бод.
|
||||
12*32=384, например, 240000 бод, 768000 бод.
|
||||
|
||||
### SPI
|
||||
Интерфейс SPI1 доступен на выводах P1_0, P1_1, P1_2. Для работы с ним используется экземпляр класса под названием `SPI`.
|
||||
Интерфейс SPI0 доступен на выводах P0_0, P0_1, P0_2. Используемый экземпляр класса - `SPI1`.
|
||||
Для корректной работы аппаратного SPI микроконтроллер так же использует выводы P1_3 при работе SPI1 и P0_3 при работе SPI0. В связи с этим данные выводы недоступны для использования при работе соответствующего SPI.
|
||||
BIN
docs/debug_console.PNG
Normal file
|
After Width: | Height: | Size: 120 KiB |
45
docs/debug_description.md
Normal file
@ -0,0 +1,45 @@
|
||||
# Режим отладки в 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/2024/05/instrukcija-po-pervomu-zapusku.pdf) по первому запуску платы ELBEAR ACE-UNO или в [документации](https://wiki.mik32.ru/%D0%9E%D1%82%D0%BB%D0%B0%D0%B4%D0%BE%D1%87%D0%BD%D0%B0%D1%8F_%D0%BF%D0%BB%D0%B0%D1%82%D0%B0_%D0%A1%D1%82%D0%B0%D1%80%D1%82) по запуску платы 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. Открыть панель отладочника в меню слева:
|
||||

|
||||
После запуска отладки здесь будут доступны к просмотру стек вызовов функций, значения переменных, установленные точки останова, а также состояние периферийных регистров микроконтроллера.
|
||||
9. Для запуска отладки необходимо нажать кнопку `Начать отладку` в верхней части экрана:
|
||||

|
||||
При этом:
|
||||
- Откроется новый терминал `gdb-server`, в котором запустится программа openocd. Терминал отображает статус соединения с микроконтроллером.
|
||||
- Запустится режим отладки, а курсор выполнения программы остановится в начале функции `setup()`.
|
||||
- Станут активными кнопки пошагового перемещения по программе.
|
||||
- Во всех разделах на панели отладки обновится информация.
|
||||
10. Для просмотра отладочной информации можно запустить консоль отладки. Для этого на панели отладки нужно нажать соответствующую кнопку:
|
||||

|
||||
|
||||
В [официальной статье](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-debugger/) подробно описано, как работать с точками останова и пошаговой отладкой кода. Помимо этого, режим отладки позволяет получить доступ к системным регистрам и регистрам периферии микроконтроллера.
|
||||

|
||||
|
||||
При работе с платами, входящими в состав пакета, накладывается ограничение на доступное количество точек останова - одновременно можно использовать не более 2-х точек. При этом вторая точка останова становится доступной после запуска отладки, когда курсор выполнения программы остановится на функции `setup()`. Режим отладки не запустится, если в скетче уже установлены обе точки останова.
|
||||
BIN
docs/debug_panel.PNG
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
docs/debug_start.PNG
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
docs/elsomikOEM_pinout.png
Normal file
|
After Width: | Height: | Size: 168 KiB |
BIN
docs/elsomikSE_pinout.png
Normal file
|
After Width: | Height: | Size: 175 KiB |
90
docs/elsomik_description.md
Normal file
@ -0,0 +1,90 @@
|
||||
# ELSOMIK
|
||||
Особенности работы с платой ELSOMIK в среде программирования ArduinoIDE.
|
||||
### Функциональное назначение выводов для плат ELSOMIK OEM и ELSOMIK SE
|
||||

|
||||

|
||||
|Номер вывода|Доступные функции|Номер вывода|Доступные функции|
|
||||
|---------|---------|---------|---------|
|
||||
|P0_0|PWM, MISO0|P1_0|PWM, MISO1|
|
||||
|P0_1|PWM, MOSI0|P1_1|PWM, MOSI1|
|
||||
|P0_2|PWM, SCLK0, ADC2|P1_2|PWM, SCLK1|
|
||||
|P0_3|PWM, NSS0|P1_3|PWM, NSS1|
|
||||
|P0_4|ADC3|P1_4|INT1|
|
||||
|P0_5|RX0|P1_5|ADC0, INT2|
|
||||
|P0_6|TX0|P1_6|INT3|
|
||||
|P0_7|ADC4|P1_7|ADC1|
|
||||
|P0_8|INT0|P1_8|RX1|
|
||||
|P0_9|SDA0, ADC5|P1_9|TX1, INT4|
|
||||
|P0_10|SCL0|P1_10|INT5|
|
||||
|P0_11|TDI, ADC6|P1_11|REF|
|
||||
|P0_12|TCK|P1_12|SDA1|
|
||||
|P0_13|TMS, ADC7|P1_13|SCL1|
|
||||
|P0_14|TRST|P1_14|-|
|
||||
|P0_15|TDO|P1_15|INT6|
|
||||
|P2_6|-|P2_7|INT7|
|
||||
|
||||
### Загрузка скетчей
|
||||
На плате отсутствуют встроенные преобразователи, позволяющие загружать скетчи по USB через COM-порт, однако каждая плата поставляется с предварительно записанным начальным загрузчиком. Для записи скетчей через USB потребуется использование внешнего USB-UART преобразователя, подключаемого к выводам платы P0_5 (RX0) и P0_6 (TX0), которые соответствуют интерфейсу UART0.
|
||||
Перед загрузкой скетча необходимо кратковременно ввести контроллер в состояние RESET. Если используется USB-UART преобразователь с выведенным сигналом DTR, необходимо соединить DTR с выводом RST на плате через керамический конденсатор емкостью от 0,47 мкФ до 2,2 мкФ. В случае отсутствия сигнала DTR, необходимо вручную соединить вывод RST платы с землей и отпустить его непосредственно перед началом записи скетча.
|
||||
### Цифровые выводы
|
||||
Выводы на плате 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. Используемый экземпляр класса - `SPI1`.
|
||||
Для корректной работы аппаратного SPI микроконтроллер так же использует выводы P1_3 при работе SPI1 и P0_3 при работе SPI0. В связи с этим данные выводы недоступны для использования при работе соответствующего SPI.
|
||||
48
docs/nano_description.md
Normal file
@ -0,0 +1,48 @@
|
||||
# ELBEAR ACE-NANO
|
||||
Особенности работы с платами ELBEAR ACE-NANO в среде программирования ArduinoIDE.
|
||||
### Функциональное назначение выводов
|
||||

|
||||
### Цифровые выводы
|
||||
На плате ELBEAR ACE-NANO доступен встроенный светодиод. Для его использования необходимо воспользоваться макросом `LED_BUILTIN`, передавая его в качестве аргумента функции вместо номера цифрового вывода. Макросу соответствует номер вывода D22.
|
||||
### Аналоговые выводы
|
||||
Выводы A0...A7 на плате могут использоваться как в аналоговом, так и в цифровом режиме.
|
||||
Для использования вывода в качестве аналогового необходимо перевести соответствующий DIP-переключатель, расположенный рядом с аналоговыми выводами, в положение OFF. В этом режиме внешнее напряжение, подаваемое на вывод, будет понижаться резистивным делителем перед подачей на микроконтроллер.
|
||||
Для использования вывода в качестве цифрового нужно перевести переключатель в положение ON. В этом случае напряжение с вывода платы передается на микроконтроллер без изменений.
|
||||
Выводы А4...А7 используют один и тот же канал АЦП, поэтому не могут использоваться одновременно.
|
||||
Таблица соответствия выводов платы и номера DIP-переключателя представлена ниже. Переключатель 5 относится сразу к четырем аналоговым выводам - А4...А7.
|
||||
|Вывод|Номер переключателя|
|
||||
|---------|---------|
|
||||
|А0|1|
|
||||
|А1|2|
|
||||
|А2|3|
|
||||
|А3|4|
|
||||
|А4|5|
|
||||
|А5|5|
|
||||
|А6|5|
|
||||
|А7|5|
|
||||
#### ШИМ
|
||||
На плате ELBEAR ACE-NANO доступно 8 выводов для формирования ШИМ-сигнала: D3, D5, D6, D9...D13. Генерация сигнала осуществляется с помощью 32-битного таймера. Выводы D3, D5, D6, D9 подключены к таймеру 1, выводы D10...D13 подключены к таймеру 2. Выводы, подключенные к одному и тому же таймеру, выдают ШИМ-сигнал одинаковой частоты.
|
||||
Цифровые выводы D9, D10 не могут быть использованы для генерации ШИМ, если одновременно активен интерфейс SPI (при использовании экземпляра `SPI` недоступен ШИМ на выводе D10, при использовании экземпляра `SPI1` - на выводе 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. Используемый экземпляр класса - `SPI1`.
|
||||
BIN
docs/pinout.PNG
|
Before Width: | Height: | Size: 233 KiB |
BIN
docs/uno_pinout.png
Normal file
|
After Width: | Height: | Size: 2.3 MiB |
76
libraries/FreeRTOS/CODE_OF_CONDUCT.md
Normal 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
|
||||
20
libraries/FreeRTOS/LICENSE
Normal 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.
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
162
libraries/FreeRTOS/examples/ArrayQueue/ArrayQueue.ino
Normal 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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
135
libraries/FreeRTOS/examples/IntegerQueue/IntegerQueue.ino
Normal 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 );
|
||||
}
|
||||
}
|
||||
90
libraries/FreeRTOS/examples/Interrupts/Interrupts.ino
Normal 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);
|
||||
}
|
||||
}
|
||||
80
libraries/FreeRTOS/examples/Mutex/Mutex.ino
Normal 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);
|
||||
}
|
||||
}
|
||||
61
libraries/FreeRTOS/examples/Notifications/Notifications.ino
Normal 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);
|
||||
}
|
||||
149
libraries/FreeRTOS/examples/StructArray/StructArray.ino
Normal 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,¤tVariable,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,¤tVariable,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);
|
||||
}
|
||||
}
|
||||
183
libraries/FreeRTOS/examples/StructQueue/StructQueue.ino
Normal 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, ¤tPinRead, 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, ¤tPinRead, 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, ¤tPinRead, 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 );
|
||||
}
|
||||
}
|
||||
89
libraries/FreeRTOS/examples/TaskStatus/TaskStatus.ino
Normal 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
|
||||
}
|
||||
}
|
||||
155
libraries/FreeRTOS/examples/TaskUtilities/TaskUtilities.ino
Normal 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 );
|
||||
}
|
||||
}
|
||||
60
libraries/FreeRTOS/keywords.txt
Normal 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
|
||||
11
libraries/FreeRTOS/library.properties
Normal 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
|
||||
126
libraries/FreeRTOS/readme.md
Normal 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 -->
|
||||
[](#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!
|
||||
3326
libraries/FreeRTOS/src/Arduino_FreeRTOS.h
Normal file
124
libraries/FreeRTOS/src/FreeRTOSConfig.h
Normal 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 */
|
||||
57
libraries/FreeRTOS/src/FreeRTOSVariant.h
Normal 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
|
||||
19
libraries/FreeRTOS/src/LICENSE.md
Normal 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.
|
||||
884
libraries/FreeRTOS/src/event_groups.c
Normal 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 */
|
||||
857
libraries/FreeRTOS/src/event_groups.h
Normal 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 */
|
||||
@ -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__ */
|
||||
165
libraries/FreeRTOS/src/heap_1.c
Normal 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;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
245
libraries/FreeRTOS/src/list.c
Normal 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;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
511
libraries/FreeRTOS/src/list.h
Normal 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 */
|
||||
967
libraries/FreeRTOS/src/message_buffer.h
Normal 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 ) */
|
||||
289
libraries/FreeRTOS/src/mpu_wrappers.h
Normal 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 */
|
||||
204
libraries/FreeRTOS/src/port.c
Normal 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( ; ; )
|
||||
{
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
385
libraries/FreeRTOS/src/portASM.S
Normal 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
|
||||
/*-----------------------------------------------------------*/
|
||||
192
libraries/FreeRTOS/src/portContext.h
Normal 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 */
|
||||
295
libraries/FreeRTOS/src/portable.h
Normal file
@ -0,0 +1,295 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
* Portable layer API. Each function must be defined for each port.
|
||||
*----------------------------------------------------------*/
|
||||
|
||||
#ifndef PORTABLE_H
|
||||
#define PORTABLE_H
|
||||
|
||||
/* Each FreeRTOS port has a unique portmacro.h header file. Originally a
|
||||
* pre-processor definition was used to ensure the pre-processor found the correct
|
||||
* portmacro.h file for the port being used. That scheme was deprecated in favour
|
||||
* of setting the compiler's include path such that it found the correct
|
||||
* portmacro.h file - removing the need for the constant and allowing the
|
||||
* portmacro.h file to be located anywhere in relation to the port being used.
|
||||
* Purely for reasons of backward compatibility the old method is still valid, but
|
||||
* to make it clear that new projects should not use it, support for the port
|
||||
* specific constants has been moved into the deprecated_definitions.h header
|
||||
* file. */
|
||||
//#include "deprecated_definitions.h"
|
||||
|
||||
/* If portENTER_CRITICAL is not defined then including deprecated_definitions.h
|
||||
* did not result in a portmacro.h header file being included - and it should be
|
||||
* included here. In this case the path to the correct portmacro.h header file
|
||||
* must be set in the compiler's include path. */
|
||||
#ifndef portENTER_CRITICAL
|
||||
#include "portmacro.h"
|
||||
#endif
|
||||
|
||||
#if portBYTE_ALIGNMENT == 32
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x001f )
|
||||
#elif portBYTE_ALIGNMENT == 16
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x000f )
|
||||
#elif portBYTE_ALIGNMENT == 8
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0007 )
|
||||
#elif portBYTE_ALIGNMENT == 4
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0003 )
|
||||
#elif portBYTE_ALIGNMENT == 2
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0001 )
|
||||
#elif portBYTE_ALIGNMENT == 1
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0000 )
|
||||
#else /* if portBYTE_ALIGNMENT == 32 */
|
||||
#error "Invalid portBYTE_ALIGNMENT definition"
|
||||
#endif /* if portBYTE_ALIGNMENT == 32 */
|
||||
|
||||
#ifndef portUSING_MPU_WRAPPERS
|
||||
#define portUSING_MPU_WRAPPERS 0
|
||||
#endif
|
||||
|
||||
#ifndef portNUM_CONFIGURABLE_REGIONS
|
||||
#define portNUM_CONFIGURABLE_REGIONS 1
|
||||
#endif
|
||||
|
||||
#ifndef portHAS_STACK_OVERFLOW_CHECKING
|
||||
#define portHAS_STACK_OVERFLOW_CHECKING 0
|
||||
#endif
|
||||
|
||||
#ifndef portARCH_NAME
|
||||
#define portARCH_NAME NULL
|
||||
#endif
|
||||
|
||||
#ifndef configSTACK_DEPTH_TYPE
|
||||
#define configSTACK_DEPTH_TYPE StackType_t
|
||||
#endif
|
||||
|
||||
#if configUSE_PORT_DELAY == 1
|
||||
/*
|
||||
* If configUSE_PORT_DELAY is defined,
|
||||
* delay() is implemented as either the Arduino delay()
|
||||
* if the delay is less than one Tick, or
|
||||
* otherwise as FreeRTOS vTaskDelay() for longer delays.
|
||||
*/
|
||||
|
||||
#ifndef delay
|
||||
#define delay vPortDelay
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef configSTACK_ALLOCATION_FROM_SEPARATE_HEAP
|
||||
/* Defaults to 0 for backward compatibility. */
|
||||
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
|
||||
#endif
|
||||
|
||||
#include "mpu_wrappers.h"
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/*
|
||||
* Setup the stack of a new task so it is ready to be placed under the
|
||||
* scheduler control. The registers have to be placed on the stack in
|
||||
* the order that the port expects to find them.
|
||||
*
|
||||
*/
|
||||
#if ( portUSING_MPU_WRAPPERS == 1 )
|
||||
#if ( portHAS_STACK_OVERFLOW_CHECKING == 1 )
|
||||
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
|
||||
StackType_t * pxEndOfStack,
|
||||
TaskFunction_t pxCode,
|
||||
void * pvParameters,
|
||||
BaseType_t xRunPrivileged,
|
||||
xMPU_SETTINGS * xMPUSettings ) PRIVILEGED_FUNCTION;
|
||||
#else
|
||||
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
|
||||
TaskFunction_t pxCode,
|
||||
void * pvParameters,
|
||||
BaseType_t xRunPrivileged,
|
||||
xMPU_SETTINGS * xMPUSettings ) PRIVILEGED_FUNCTION;
|
||||
#endif /* if ( portHAS_STACK_OVERFLOW_CHECKING == 1 ) */
|
||||
#else /* if ( portUSING_MPU_WRAPPERS == 1 ) */
|
||||
#if ( portHAS_STACK_OVERFLOW_CHECKING == 1 )
|
||||
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
|
||||
StackType_t * pxEndOfStack,
|
||||
TaskFunction_t pxCode,
|
||||
void * pvParameters ) PRIVILEGED_FUNCTION;
|
||||
#else
|
||||
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
|
||||
TaskFunction_t pxCode,
|
||||
void * pvParameters ) PRIVILEGED_FUNCTION;
|
||||
#endif
|
||||
#endif /* if ( portUSING_MPU_WRAPPERS == 1 ) */
|
||||
|
||||
/* Used by heap_5.c to define the start address and size of each memory region
|
||||
* that together comprise the total FreeRTOS heap space. */
|
||||
typedef struct HeapRegion
|
||||
{
|
||||
uint8_t * pucStartAddress;
|
||||
size_t xSizeInBytes;
|
||||
} HeapRegion_t;
|
||||
|
||||
/* Used to pass information about the heap out of vPortGetHeapStats(). */
|
||||
typedef struct xHeapStats
|
||||
{
|
||||
size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */
|
||||
size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
|
||||
size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
|
||||
size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */
|
||||
size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */
|
||||
size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */
|
||||
size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */
|
||||
} HeapStats_t;
|
||||
|
||||
/*
|
||||
* Used to define multiple heap regions for use by heap_5.c. This function
|
||||
* must be called before any calls to pvPortMalloc() - not creating a task,
|
||||
* queue, semaphore, mutex, software timer, event group, etc. will result in
|
||||
* pvPortMalloc being called.
|
||||
*
|
||||
* pxHeapRegions passes in an array of HeapRegion_t structures - each of which
|
||||
* defines a region of memory that can be used as the heap. The array is
|
||||
* terminated by a HeapRegions_t structure that has a size of 0. The region
|
||||
* with the lowest start address must appear first in the array.
|
||||
*/
|
||||
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/*
|
||||
* Returns a HeapStats_t structure filled with information about the current
|
||||
* heap state.
|
||||
*/
|
||||
void vPortGetHeapStats( HeapStats_t * pxHeapStats );
|
||||
|
||||
/*
|
||||
* Map to the memory management routines required for the port.
|
||||
*/
|
||||
void * pvPortMalloc( size_t xWantedSize ) PRIVILEGED_FUNCTION;
|
||||
void * pvPortCalloc( size_t xNum,
|
||||
size_t xSize ) PRIVILEGED_FUNCTION;
|
||||
void vPortFree( void * pv ) PRIVILEGED_FUNCTION;
|
||||
void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
|
||||
size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;
|
||||
size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;
|
||||
|
||||
#if ( configSTACK_ALLOCATION_FROM_SEPARATE_HEAP == 1 )
|
||||
void * pvPortMallocStack( size_t xSize ) PRIVILEGED_FUNCTION;
|
||||
void vPortFreeStack( void * pv ) PRIVILEGED_FUNCTION;
|
||||
#else
|
||||
#define pvPortMallocStack pvPortMalloc
|
||||
#define vPortFreeStack vPortFree
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This function resets the internal state of the heap module. It must be called
|
||||
* by the application before restarting the scheduler.
|
||||
*/
|
||||
void vPortHeapResetState( void ) PRIVILEGED_FUNCTION;
|
||||
|
||||
#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
|
||||
|
||||
/**
|
||||
* task.h
|
||||
* @code{c}
|
||||
* void vApplicationMallocFailedHook( void )
|
||||
* @endcode
|
||||
*
|
||||
* This hook function is called when allocation failed.
|
||||
*/
|
||||
void vApplicationMallocFailedHook( void );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Setup the hardware ready for the scheduler to take control. This generally
|
||||
* sets up a tick interrupt and sets timers for the correct tick frequency.
|
||||
*/
|
||||
BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/*
|
||||
* Undo any hardware/ISR setup that was performed by xPortStartScheduler() so
|
||||
* the hardware is left in its original condition after the scheduler stops
|
||||
* executing.
|
||||
*/
|
||||
void vPortEndScheduler( void ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/*
|
||||
* The structures and methods of manipulating the MPU are contained within the
|
||||
* port layer.
|
||||
*
|
||||
* Fills the xMPUSettings structure with the memory region information
|
||||
* contained in xRegions.
|
||||
*/
|
||||
#if ( portUSING_MPU_WRAPPERS == 1 )
|
||||
struct xMEMORY_REGION;
|
||||
void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
|
||||
const struct xMEMORY_REGION * const xRegions,
|
||||
StackType_t * pxBottomOfStack,
|
||||
configSTACK_DEPTH_TYPE uxStackDepth ) PRIVILEGED_FUNCTION;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Checks if the calling task is authorized to access the given buffer.
|
||||
*
|
||||
* @param pvBuffer The buffer which the calling task wants to access.
|
||||
* @param ulBufferLength The length of the pvBuffer.
|
||||
* @param ulAccessRequested The permissions that the calling task wants.
|
||||
*
|
||||
* @return pdTRUE if the calling task is authorized to access the buffer,
|
||||
* pdFALSE otherwise.
|
||||
*/
|
||||
#if ( portUSING_MPU_WRAPPERS == 1 )
|
||||
BaseType_t xPortIsAuthorizedToAccessBuffer( const void * pvBuffer,
|
||||
uint32_t ulBufferLength,
|
||||
uint32_t ulAccessRequested ) PRIVILEGED_FUNCTION;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Checks if the calling task is authorized to access the given kernel object.
|
||||
*
|
||||
* @param lInternalIndexOfKernelObject The index of the kernel object in the kernel
|
||||
* object handle pool.
|
||||
*
|
||||
* @return pdTRUE if the calling task is authorized to access the kernel object,
|
||||
* pdFALSE otherwise.
|
||||
*/
|
||||
#if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
|
||||
|
||||
BaseType_t xPortIsAuthorizedToAccessKernelObject( int32_t lInternalIndexOfKernelObject ) PRIVILEGED_FUNCTION;
|
||||
|
||||
#endif
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* PORTABLE_H */
|
||||
206
libraries/FreeRTOS/src/portmacro.h
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* 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 PORTMACRO_H
|
||||
#define PORTMACRO_H
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
* Port specific definitions.
|
||||
*
|
||||
* The settings in this file configure FreeRTOS correctly for the
|
||||
* given hardware and compiler.
|
||||
*
|
||||
* These settings should not be altered.
|
||||
*-----------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* Type definitions. */
|
||||
#if __riscv_xlen == 64
|
||||
#define portSTACK_TYPE uint64_t
|
||||
#define portBASE_TYPE int64_t
|
||||
#define portUBASE_TYPE uint64_t
|
||||
#define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffUL
|
||||
#define portPOINTER_SIZE_TYPE uint64_t
|
||||
#elif __riscv_xlen == 32
|
||||
#define portSTACK_TYPE uint32_t
|
||||
#define portBASE_TYPE int32_t
|
||||
#define portUBASE_TYPE uint32_t
|
||||
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
|
||||
#else /* if __riscv_xlen == 64 */
|
||||
#error "Assembler did not define __riscv_xlen"
|
||||
#endif /* if __riscv_xlen == 64 */
|
||||
|
||||
typedef portSTACK_TYPE StackType_t;
|
||||
typedef portBASE_TYPE BaseType_t;
|
||||
typedef portUBASE_TYPE UBaseType_t;
|
||||
typedef portUBASE_TYPE TickType_t;
|
||||
|
||||
/* Legacy type definitions. */
|
||||
#define portCHAR char
|
||||
#define portFLOAT float
|
||||
#define portDOUBLE double
|
||||
#define portLONG long
|
||||
#define portSHORT short
|
||||
|
||||
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
|
||||
* not need to be guarded with a critical section. */
|
||||
#define portTICK_TYPE_IS_ATOMIC 1
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Architecture specifics. */
|
||||
#define portSTACK_GROWTH ( -1 )
|
||||
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
|
||||
#ifdef __riscv_32e
|
||||
#define portBYTE_ALIGNMENT 8 /* RV32E uses RISC-V EABI with reduced stack alignment requirements */
|
||||
#else
|
||||
#define portBYTE_ALIGNMENT 16
|
||||
#endif
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Scheduler utilities. */
|
||||
extern void vTaskSwitchContext( void );
|
||||
#define portYIELD() __asm volatile ( "ecall" );
|
||||
#define portEND_SWITCHING_ISR( xSwitchRequired ) \
|
||||
do \
|
||||
{ \
|
||||
if( xSwitchRequired != pdFALSE ) \
|
||||
{ \
|
||||
traceISR_EXIT_TO_SCHEDULER(); \
|
||||
vTaskSwitchContext(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
traceISR_EXIT(); \
|
||||
} \
|
||||
} while( 0 )
|
||||
#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Critical section management. */
|
||||
#define portCRITICAL_NESTING_IN_TCB 0
|
||||
|
||||
#define portDISABLE_INTERRUPTS() __asm volatile ( "csrc mstatus, 8" )
|
||||
#define portENABLE_INTERRUPTS() __asm volatile ( "csrs mstatus, 8" )
|
||||
|
||||
extern size_t xCriticalNesting;
|
||||
#define portENTER_CRITICAL() \
|
||||
{ \
|
||||
portDISABLE_INTERRUPTS(); \
|
||||
xCriticalNesting++; \
|
||||
}
|
||||
|
||||
#define portEXIT_CRITICAL() \
|
||||
{ \
|
||||
xCriticalNesting--; \
|
||||
if( xCriticalNesting == 0 ) \
|
||||
{ \
|
||||
portENABLE_INTERRUPTS(); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Architecture specific optimisations. */
|
||||
#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
|
||||
#endif
|
||||
|
||||
#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
|
||||
|
||||
/* Check the configuration. */
|
||||
#if ( configMAX_PRIORITIES > 32 )
|
||||
#error "configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice."
|
||||
#endif
|
||||
|
||||
/* Store/clear the ready priorities in a bit map. */
|
||||
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
|
||||
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - __builtin_clz( uxReadyPriorities ) )
|
||||
|
||||
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
|
||||
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Task function macros as described on the FreeRTOS.org WEB site. These are
|
||||
* not necessary for to use this port. They are defined so the common demo
|
||||
* files (which build with all the ports) will build. */
|
||||
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
|
||||
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#define portNOP() __asm volatile ( " nop " )
|
||||
#define portINLINE __inline
|
||||
|
||||
#ifndef portFORCE_INLINE
|
||||
#define portFORCE_INLINE inline __attribute__( ( always_inline ) )
|
||||
#endif
|
||||
|
||||
#define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" )
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* configCLINT_BASE_ADDRESS is a legacy definition that was replaced by the
|
||||
* configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS definitions. For
|
||||
* backward compatibility derive the newer definitions from the old if the old
|
||||
* definition is found. */
|
||||
#if defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS ) && ( configCLINT_BASE_ADDRESS == 0 )
|
||||
|
||||
/* Legacy case where configCLINT_BASE_ADDRESS was defined as 0 to indicate
|
||||
* there was no CLINT. Equivalent now is to set the MTIME and MTIMECMP
|
||||
* addresses to 0. */
|
||||
#define configMTIME_BASE_ADDRESS ( 0 )
|
||||
#define configMTIMECMP_BASE_ADDRESS ( 0 )
|
||||
#elif defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS )
|
||||
|
||||
/* Legacy case where configCLINT_BASE_ADDRESS was set to the base address of
|
||||
* the CLINT. Equivalent now is to derive the MTIME and MTIMECMP addresses
|
||||
* from the CLINT address. */
|
||||
#define configMTIME_BASE_ADDRESS ( ( configCLINT_BASE_ADDRESS ) + 0xBFF8UL )
|
||||
#define configMTIMECMP_BASE_ADDRESS ( ( configCLINT_BASE_ADDRESS ) + 0x4000UL )
|
||||
#elif !defined( configMTIME_BASE_ADDRESS ) || !defined( configMTIMECMP_BASE_ADDRESS )
|
||||
#error "configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS must be defined in FreeRTOSConfig.h. Set them to zero if there is no MTIME (machine time) clock. See www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html"
|
||||
#endif /* if defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS ) && ( configCLINT_BASE_ADDRESS == 0 ) */
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#endif /* PORTMACRO_H */
|
||||
138
libraries/FreeRTOS/src/projdefs.h
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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 PROJDEFS_H
|
||||
#define PROJDEFS_H
|
||||
|
||||
/*
|
||||
* Defines the prototype to which task functions must conform. Defined in this
|
||||
* file to ensure the type is known before portable.h is included.
|
||||
*/
|
||||
typedef void (* TaskFunction_t)( void * arg );
|
||||
|
||||
/* Converts a time in milliseconds to a time in ticks. This macro can be
|
||||
* overridden by a macro of the same name defined in FreeRTOSConfig.h in case the
|
||||
* definition here is not suitable for your application. */
|
||||
#ifndef pdMS_TO_TICKS
|
||||
#define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( uint64_t ) ( xTimeInMs ) * ( uint64_t ) configTICK_RATE_HZ ) / ( uint64_t ) 1000U ) )
|
||||
#endif
|
||||
|
||||
/* Converts a time in ticks to a time in milliseconds. This macro can be
|
||||
* overridden by a macro of the same name defined in FreeRTOSConfig.h in case the
|
||||
* definition here is not suitable for your application. */
|
||||
#ifndef pdTICKS_TO_MS
|
||||
#define pdTICKS_TO_MS( xTimeInTicks ) ( ( TickType_t ) ( ( ( uint64_t ) ( xTimeInTicks ) * ( uint64_t ) 1000U ) / ( uint64_t ) configTICK_RATE_HZ ) )
|
||||
#endif
|
||||
|
||||
#define pdFALSE ( ( BaseType_t ) 0 )
|
||||
#define pdTRUE ( ( BaseType_t ) 1 )
|
||||
#define pdFALSE_SIGNED ( ( BaseType_t ) 0 )
|
||||
#define pdTRUE_SIGNED ( ( BaseType_t ) 1 )
|
||||
#define pdFALSE_UNSIGNED ( ( UBaseType_t ) 0 )
|
||||
#define pdTRUE_UNSIGNED ( ( UBaseType_t ) 1 )
|
||||
|
||||
#define pdPASS ( pdTRUE )
|
||||
#define pdFAIL ( pdFALSE )
|
||||
#define errQUEUE_EMPTY ( ( BaseType_t ) 0 )
|
||||
#define errQUEUE_FULL ( ( BaseType_t ) 0 )
|
||||
|
||||
/* FreeRTOS error definitions. */
|
||||
#define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 )
|
||||
#define errQUEUE_BLOCKED ( -4 )
|
||||
#define errQUEUE_YIELD ( -5 )
|
||||
|
||||
/* Macros used for basic data corruption checks. */
|
||||
#ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES
|
||||
#define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0
|
||||
#endif
|
||||
|
||||
#if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
|
||||
#define pdINTEGRITY_CHECK_VALUE 0x5a5a
|
||||
#elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
|
||||
#define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL
|
||||
#elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS )
|
||||
#define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5a5a5a5a5aULL
|
||||
#else
|
||||
#error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
|
||||
#endif
|
||||
|
||||
/* The following errno values are used by FreeRTOS+ components, not FreeRTOS
|
||||
* itself. */
|
||||
#define pdFREERTOS_ERRNO_NONE 0 /* No errors */
|
||||
#define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */
|
||||
#define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */
|
||||
#define pdFREERTOS_ERRNO_EIO 5 /* I/O error */
|
||||
#define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */
|
||||
#define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */
|
||||
#define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */
|
||||
#define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */
|
||||
#define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */
|
||||
#define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */
|
||||
#define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */
|
||||
#define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */
|
||||
#define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */
|
||||
#define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */
|
||||
#define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */
|
||||
#define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */
|
||||
#define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */
|
||||
#define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */
|
||||
#define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */
|
||||
#define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */
|
||||
#define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */
|
||||
#define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */
|
||||
#define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */
|
||||
#define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */
|
||||
#define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */
|
||||
#define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */
|
||||
#define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */
|
||||
#define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||
#define pdFREERTOS_ERRNO_EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */
|
||||
#define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */
|
||||
#define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */
|
||||
#define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */
|
||||
#define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */
|
||||
#define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */
|
||||
#define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */
|
||||
#define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */
|
||||
#define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */
|
||||
#define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */
|
||||
#define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */
|
||||
#define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */
|
||||
|
||||
/* The following endian values are used by FreeRTOS+ components, not FreeRTOS
|
||||
* itself. */
|
||||
#define pdFREERTOS_LITTLE_ENDIAN 0
|
||||
#define pdFREERTOS_BIG_ENDIAN 1
|
||||
|
||||
/* Re-defining endian values for generic naming. */
|
||||
#define pdLITTLE_ENDIAN pdFREERTOS_LITTLE_ENDIAN
|
||||
#define pdBIG_ENDIAN pdFREERTOS_BIG_ENDIAN
|
||||
|
||||
|
||||
#endif /* PROJDEFS_H */
|
||||
3054
libraries/FreeRTOS/src/queue.c
Normal file
1784
libraries/FreeRTOS/src/queue.h
Normal file
1215
libraries/FreeRTOS/src/semphr.h
Normal file
141
libraries/FreeRTOS/src/stack_macros.h
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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 STACK_MACROS_H
|
||||
#define STACK_MACROS_H
|
||||
|
||||
/*
|
||||
* Call the stack overflow hook function if the stack of the task being swapped
|
||||
* out is currently overflowed, or looks like it might have overflowed in the
|
||||
* past.
|
||||
*
|
||||
* Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
|
||||
* the current stack state only - comparing the current top of stack value to
|
||||
* the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
|
||||
* will also cause the last few stack bytes to be checked to ensure the value
|
||||
* to which the bytes were set when the task was created have not been
|
||||
* overwritten. Note this second test does not guarantee that an overflowed
|
||||
* stack will always be recognised.
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* portSTACK_LIMIT_PADDING is a number of extra words to consider to be in
|
||||
* use on the stack.
|
||||
*/
|
||||
#ifndef portSTACK_LIMIT_PADDING
|
||||
#define portSTACK_LIMIT_PADDING 0
|
||||
#endif
|
||||
|
||||
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )
|
||||
|
||||
/* Only the current stack state is to be checked. */
|
||||
#define taskCHECK_FOR_STACK_OVERFLOW() \
|
||||
do { \
|
||||
/* Is the currently saved stack pointer within the stack limit? */ \
|
||||
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
|
||||
{ \
|
||||
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
|
||||
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )
|
||||
|
||||
/* Only the current stack state is to be checked. */
|
||||
#define taskCHECK_FOR_STACK_OVERFLOW() \
|
||||
do { \
|
||||
\
|
||||
/* Is the currently saved stack pointer within the stack limit? */ \
|
||||
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
|
||||
{ \
|
||||
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
|
||||
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
|
||||
|
||||
#define taskCHECK_FOR_STACK_OVERFLOW() \
|
||||
do { \
|
||||
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
|
||||
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \
|
||||
\
|
||||
if( ( pulStack[ 0 ] != ulCheckValue ) || \
|
||||
( pulStack[ 1 ] != ulCheckValue ) || \
|
||||
( pulStack[ 2 ] != ulCheckValue ) || \
|
||||
( pulStack[ 3 ] != ulCheckValue ) ) \
|
||||
{ \
|
||||
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
|
||||
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
|
||||
|
||||
#define taskCHECK_FOR_STACK_OVERFLOW() \
|
||||
do { \
|
||||
int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
|
||||
static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
|
||||
\
|
||||
\
|
||||
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
|
||||
\
|
||||
/* Has the extremity of the task stack ever been written over? */ \
|
||||
if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
|
||||
{ \
|
||||
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
|
||||
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Remove stack overflow macro if not being used. */
|
||||
#ifndef taskCHECK_FOR_STACK_OVERFLOW
|
||||
#define taskCHECK_FOR_STACK_OVERFLOW()
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* STACK_MACROS_H */
|
||||
1719
libraries/FreeRTOS/src/stream_buffer.c
Normal file
1280
libraries/FreeRTOS/src/stream_buffer.h
Normal file
3745
libraries/FreeRTOS/src/task.h
Normal file
8693
libraries/FreeRTOS/src/tasks.c
Normal file
1336
libraries/FreeRTOS/src/timers.c
Normal file
1430
libraries/FreeRTOS/src/timers.h
Normal file
216
libraries/FreeRTOS/src/variantHooks.cpp
Normal file
@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "Arduino_FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#include "mik32_hal_scr1_timer.h"
|
||||
|
||||
extern void setup(void);
|
||||
extern void loop(void);
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void initVariant(void)
|
||||
{
|
||||
setup(); // the normal Arduino setup() function is run here.
|
||||
post_init();
|
||||
vTaskStartScheduler(); // initialise and run the freeRTOS scheduler. Execution should never return here.
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
#if ( configUSE_IDLE_HOOK == 1 )
|
||||
/*
|
||||
* Call the user defined loop() function from within the idle task.
|
||||
* This allows the application designer to add background functionality
|
||||
* without the overhead of a separate task.
|
||||
*
|
||||
* NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES, CALL A FUNCTION THAT MIGHT BLOCK.
|
||||
*
|
||||
*/
|
||||
void vApplicationIdleHook( void ) __attribute__ ((weak));
|
||||
|
||||
void vApplicationIdleHook( void )
|
||||
{
|
||||
loop(); // the normal Arduino loop() function is run here.
|
||||
}
|
||||
|
||||
#else
|
||||
void loop() {} //Empty loop function
|
||||
#endif /* configUSE_IDLE_HOOK == 1 */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ( configUSE_MALLOC_FAILED_HOOK == 1 || configCHECK_FOR_STACK_OVERFLOW >= 1 || configDEFAULT_ASSERT == 1 )
|
||||
|
||||
/**
|
||||
* Private function to enable board led to use it in application hooks
|
||||
*/
|
||||
void prvSetMainLedOn( void )
|
||||
{
|
||||
#if defined (LED_BUILTIN)
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Private function to blink board led to use it in application hooks
|
||||
*/
|
||||
void prvBlinkMainLed( void )
|
||||
{
|
||||
#if defined (LED_BUILTIN)
|
||||
digitalToggle(LED_BUILTIN);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Usage:
|
||||
called by task system when a malloc failure is noticed
|
||||
Description:
|
||||
Malloc failure handler -- Shut down all interrupts, send serious complaint
|
||||
to command port. FAST Blink on main LED.
|
||||
Arguments:
|
||||
pxTask - pointer to task handle
|
||||
pcTaskName - pointer to task name
|
||||
Results:
|
||||
<none>
|
||||
Notes:
|
||||
This routine will never return.
|
||||
This routine is referenced in the task.c file of FreeRTOS as an extern.
|
||||
\*---------------------------------------------------------------------------*/
|
||||
void vApplicationMallocFailedHook( void ) __attribute__ ((weak));
|
||||
|
||||
void vApplicationMallocFailedHook( void )
|
||||
{
|
||||
prvSetMainLedOn(); // Main LED on.
|
||||
|
||||
for(;;)
|
||||
{
|
||||
delay(50);
|
||||
prvBlinkMainLed(); // Main LED fast blink.
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* configUSE_MALLOC_FAILED_HOOK == 1 */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
#if ( configCHECK_FOR_STACK_OVERFLOW >= 1 )
|
||||
|
||||
void vApplicationStackOverflowHook( TaskHandle_t xTask,
|
||||
char * pcTaskName ) __attribute__ ((weak));
|
||||
|
||||
void vApplicationStackOverflowHook( TaskHandle_t xTask __attribute__ ((unused)),
|
||||
char * pcTaskName __attribute__ ((unused)) )
|
||||
{
|
||||
|
||||
prvSetMainLedOn(); // Main LED on.
|
||||
|
||||
for(;;)
|
||||
{
|
||||
delay(2000);
|
||||
prvBlinkMainLed(); // Main LED slow blink.
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* configCHECK_FOR_STACK_OVERFLOW >= 1 */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION >= 1 )
|
||||
|
||||
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
|
||||
StackType_t ** ppxIdleTaskStackBuffer,
|
||||
configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) __attribute__ ((weak));
|
||||
|
||||
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
|
||||
StackType_t ** ppxIdleTaskStackBuffer,
|
||||
configSTACK_DEPTH_TYPE * puxIdleTaskStackSize )
|
||||
{
|
||||
static StaticTask_t xIdleTaskTCB;
|
||||
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
|
||||
|
||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
|
||||
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
|
||||
*puxIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||
}
|
||||
|
||||
#if ( configUSE_TIMERS >= 1 )
|
||||
|
||||
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
|
||||
StackType_t ** ppxTimerTaskStackBuffer,
|
||||
configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) __attribute__ ((weak));
|
||||
|
||||
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
|
||||
StackType_t ** ppxTimerTaskStackBuffer,
|
||||
configSTACK_DEPTH_TYPE * puxTimerTaskStackSize )
|
||||
{
|
||||
static StaticTask_t xTimerTaskTCB;
|
||||
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
|
||||
|
||||
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
|
||||
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
|
||||
*puxTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
||||
}
|
||||
|
||||
#endif /* configUSE_TIMERS >= 1 */
|
||||
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION >= 1 */
|
||||
|
||||
/**
|
||||
* configASSERT default implementation
|
||||
*/
|
||||
#if configDEFAULT_ASSERT == 1
|
||||
|
||||
void vApplicationAssertHook() {
|
||||
|
||||
taskDISABLE_INTERRUPTS(); // Disable task interrupts
|
||||
|
||||
prvSetMainLedOn(); // Main LED on.
|
||||
for(;;)
|
||||
{
|
||||
delay(100);
|
||||
prvBlinkMainLed(); // Led off.
|
||||
|
||||
delay(2000);
|
||||
prvBlinkMainLed(); // Led on.
|
||||
|
||||
delay(100);
|
||||
prvBlinkMainLed(); // Led off
|
||||
|
||||
delay(100);
|
||||
prvBlinkMainLed(); // Led on.
|
||||
}
|
||||
}
|
||||
#endif
|
||||
47
libraries/IRremote/Contributing.md
Normal file
@ -0,0 +1,47 @@
|
||||
# Contributing
|
||||
This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work.
|
||||
|
||||
If you want to contribute to this project:
|
||||
- Report bugs and errors
|
||||
- Ask for enhancements
|
||||
- Create issues and pull requests
|
||||
- Tell other people about this library
|
||||
- Contribute new protocols
|
||||
|
||||
## Guidelines
|
||||
The following are some guidelines to observe when creating discussions / PRs:
|
||||
#### Be friendly
|
||||
It is important that we can all enjoy a safe space as we are all working on the same project and **it is okay for people to have different ideas**.
|
||||
#### Use reasonable titles
|
||||
Refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile:.
|
||||
#### Use the formatting style
|
||||
We use the original [C Style by Kerninghan / Ritchie](https://en.wikipedia.org/wiki/Indentation_style#K&R_style) in [variant: 1TBS (OTBS)](https://en.wikipedia.org/wiki/Indentation_style#Variant:_1TBS_(OTBS)).<br/>
|
||||
In short: 4 spaces indentation, no tabs, opening braces on the same line, braces are mandatory on all if/while/do, no hard line length limit.<br/>
|
||||
To beautify your code, you may use the online formatter [here](https://www.freecodeformat.com/c-format.php).
|
||||
#### Cover **all** occurences of the problem / addition you address with your PR
|
||||
Do not forget the documentation like it is done for existing code. Code changes without proper documentation will be rejected!
|
||||
|
||||
## Adding new protocols
|
||||
To add a new protocol is quite straightforward. Best is too look at the existing protocols to find a similar one and modify it.<br/>
|
||||
As a rule of thumb, it is easier to work with a description of the protocol rather than trying to entirely reverse-engineer the protocol.
|
||||
Please include a link to the description in the header, if you found one.<br/>
|
||||
The **durations** you receive are likely to be longer for marks and shorter for spaces than the protocol suggests,
|
||||
but this depends on the receiver circuit in use. Most protocols use multiples of one time-unit for marks and spaces like e.g. [NEC](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_NEC.hpp#L62). It's easy to be off-by-one with the last bit, since the last space is not recorded by IRremote.
|
||||
|
||||
Try to make use of the template functions `decodePulseDistanceData()` and `sendPulseDistanceData()`.
|
||||
If your protocol supports address and code fields, try to reflect this in your api like it is done in [`sendNEC(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aIsRepeat)`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_NEC.hpp#L96)
|
||||
and [`decodeNEC()`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_NEC.hpp#L194).<br/>
|
||||
|
||||
### Integration
|
||||
To integrate your protocol, you need to extend the two functions `decode()` and `getProtocolString()` in *IRreceice.hpp*,
|
||||
add macros and function declarations for sending and receiving and extend the `enum decode_type_t` in *IRremote.h*.<br/>
|
||||
And at least it would be wonderful if you can provide an example how to use the new protocol.
|
||||
A detailed description can be found in the [ir_Template.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_Template.hpp#L11) file.
|
||||
|
||||
### Creating API documentation
|
||||
To generate the API documentation, Doxygen, as well as [Graphviz](http://www.graphviz.org/) should be installed.
|
||||
(Note that on Windows, it is useful to specify the installer to add Graphviz to PATH or to do it manually.
|
||||
With Doxygen and Graphviz installed, issue the command
|
||||
`doxygen` from the command line in the main project directory, which will
|
||||
generate the API documentation in HTML format.
|
||||
The just generated `docs/index.html` can now be opened in a browser.
|
||||
36
libraries/IRremote/Contributors.md
Normal file
@ -0,0 +1,36 @@
|
||||
## Contributors
|
||||
These are the active contributors of this project that you may contact if there is anything you need help with or if you have suggestions.
|
||||
|
||||
- [ArminJo](https://github.com/ArminJo) Maintainer
|
||||
- [z3t0](https://github.com/z3t0) the main contributor until version 2.4.0.
|
||||
* Email: zetoslab@gmail.com
|
||||
- [shirriff](https://github.com/shirriff): An amazing person who worked to create this awesome library and provide unending support
|
||||
- [Informatic](https://github.com/Informatic)
|
||||
- [fmeschia](https://github.com/fmeschia)
|
||||
- [PaulStoffregen](https://github.com/paulstroffregen)
|
||||
- [crash7](https://github.com/crash7)
|
||||
- [Neco777](https://github.com/neco777)
|
||||
- [Lauszus](https://github.com/lauszus)
|
||||
- [csBlueChip](https://github.com/csbluechip) contributed major and vital changes to the code base.
|
||||
- [Sebazzz](https://github.com/sebazz)
|
||||
- [lumbric](https://github.com/lumbric)
|
||||
- [ElectricRCAircraftGuy](https://github.com/electricrcaircraftguy)
|
||||
- [philipphenkel](https://github.com/philipphenkel)
|
||||
- [MCUdude](https://github.com/MCUdude)
|
||||
- [adamlhumphreys](https://github.com/adamlhumphreys) (code space improvements)
|
||||
- [marcmerlin](https://github.com/marcmerlin) (ESP32 port)
|
||||
- [MrBryonMiller](https://github.com/MrBryonMiller)
|
||||
- [bengtmartensson](https://github.com/bengtmartensson) providing support
|
||||
- [AnalysIR](https:/github.com/AnalysIR) providing support
|
||||
- [eshicks4](https://github.com/eshicks4)
|
||||
- [Jim-2249](https://github.com/Jim-2249)
|
||||
- [pmalasp](https://github.com/pmalasp )
|
||||
- [ElectronicsArchiver}(https://github.com/ElectronicsArchiver) improving documentation
|
||||
- [Stephen Humphries](https://github.com/sjahu)Fix for: Prevent long delay caused by overflow when frame duration < repeat period #1028
|
||||
- [Daniel Wallner](https://github.com/danielwallner) Bang & Olufsen protocol.
|
||||
- [slott](https://stackoverflow.com/users/11680056/sklott) Seeduino print(unsigned long long...) support.
|
||||
- [Joe Ostrander](https://github.com/joeostrander) Added support for attiny1614.
|
||||
- [Buzzerb](https://github.com/Buzzerb) Added Extended NEC protocol to TinyIR and making it more consistent.
|
||||
- [akellai](https://github.com/akellai) Added ESP 3.0 support.
|
||||
|
||||
Note: Please let [ArminJo](https://github.com/ArminJo) know if you have been missed.
|
||||
2500
libraries/IRremote/Doxyfile
Normal file
25
libraries/IRremote/LICENSE
Normal file
@ -0,0 +1,25 @@
|
||||
MIT License
|
||||
|
||||
(c) Copyright 2009 Ken Shirriff http://www.righto.com
|
||||
(c) Copyright 2016 Rafi Khan
|
||||
(c) Copyright 2020-2022 Armin Joachimsmeyer et al.
|
||||
|
||||
http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
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.
|
||||
1097
libraries/IRremote/README.md
Normal file
401
libraries/IRremote/changelog.md
Normal file
@ -0,0 +1,401 @@
|
||||
# Changelog
|
||||
The latest version may not be released!
|
||||
See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-IRremote/commits/master
|
||||
|
||||
# 4.4.1
|
||||
- Support for ESP 3.0 by akellai.
|
||||
- restartTimer() now uses variable sMicrosAtLastStopTimer to keep track of uncounted ticks between stopTimer() and restartTimer().
|
||||
- Removed functions addTicksToInternalTickCounter() and addMicrosToInternalTickCounter(), which were added in 4.1.0.
|
||||
- Version 2.2.0 of TinyIR with new TinyReceiverDecode() function to be used as drop in for IrReceiver.decode().
|
||||
- Support of RC6A.
|
||||
|
||||
# 4.4.0
|
||||
- Using 8 bit raw timing buffer for all timings except frame gap (former rawbuf[0]).
|
||||
- Renamed decodedIRData.initialGap to decodedIRData.initialGapTicks.
|
||||
- sendNEC() and sendNEC2() now accepts 16 bit command to better map to NECext protocol found in IRDB databases.
|
||||
- ir_DistanceWidthProtocol() now decodes up to 10 ms mark or spaces if RAM is bigger than 2 k.
|
||||
- Improved sensitivity and decoding of PULSE_DISTANCE + PULSE_WIDTH protocols.
|
||||
- Changed TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING to TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT.
|
||||
- Improved examples AllProtocolsOnLCD, UnitTest and SimpleReceiver.
|
||||
- New functions decodePulseDistanceWidthData() with 6 parameters and decodePulseDistanceWidthDataStrict() with 7 parameters.
|
||||
|
||||
# 4.3.2
|
||||
- Added sendSonyMSB(unsigned long data, int nbits) as a clone of sendSony(unsigned long data, int nbits) to be more consistent.
|
||||
- Added sendSamsungMSB(unsigned long data, int nbits) as a clone of sendSAMSUNG(unsigned long data, int nbits) to be more consistent.
|
||||
- Added ESP32 core 3.x error message.
|
||||
|
||||
# 4.3.1
|
||||
- Fixed overflow bug for rawlen > 254.
|
||||
- Removed deprecated sendPulseDistance... functions with parameter aSendStopBit.
|
||||
|
||||
# 4.3.0
|
||||
- Removed default value USE_DEFAULT_FEEDBACK_LED_PIN for last parameter of IRsend::begin(bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin).
|
||||
Therefore IrSender.begin(DISABLE_LED_FEEDBACK) will not longer work!
|
||||
- Added convenience function isIRReceiverAttachedForTinyReceiver().
|
||||
- Added Extended NEC Protocol macro to TinyIR by Buzzerb.
|
||||
- Fixed sendSamsung() / sendSamsungLG() bug.
|
||||
- Added functions stopTimer(), restartTimer() and restartTimerWithTicksToAdd().
|
||||
- Added rawlen and initialGap to IRData.
|
||||
- Added ReceiveAndSendHobToHood example.
|
||||
- Changed RECORD_GAP_MICROS default value from 5000 to 8000.
|
||||
|
||||
# 4.2.1
|
||||
- Fix wrong type of tEnableLEDFeedback in IRSend.hpp and IRReceive.hpp.
|
||||
- TinyReceiver 2.0
|
||||
- New TinyIRReceiverData which is filled with address, command and flags.
|
||||
- Removed parameters address, command and flags from callback handleReceivedTinyIRData() and printTinyReceiverResultMinimal().
|
||||
- Callback function now only enabled if USE_CALLBACK_FOR_TINY_RECEIVER is activated.
|
||||
- Fix changing IR_SEND_PIN dynamically for ESP32.
|
||||
- Fix wrong type of tEnableLEDFeedback.
|
||||
- Support for ESP32-C3.
|
||||
|
||||
# 4.2.0
|
||||
- The old decode function is renamed to decode_old(decode_results *aResults). decode (decode_results *aResults) is only available in IRremote.h and prints a message.
|
||||
- Added DECODE_ONKYO, to force 16 bit command and data decoding.
|
||||
- Enable Bang&Olufsen 455 kHz if SEND_PWM_BY_TIMER is defined.
|
||||
- Fixed bug: TinyReceiver throwing ISR not in IRAM on ESP8266.
|
||||
- Usage of ATTinyCore pin numbering scheme e.g. PIN_PB2.
|
||||
- Added ARDUINO_ARCH_NRF52 to support Seeed XIAO nRF52840 Sense.
|
||||
- First untested support of Uno R4.
|
||||
- Extraced version macros to IRVersion.h.
|
||||
|
||||
## 4.1.2
|
||||
- Workaround for ESP32 RTOS delay() timing bug influencing the mark() function.
|
||||
|
||||
## 4.1.1
|
||||
- SAMD51 use timer3 if timer5 not available.
|
||||
- Disabled #define LOCAL_DEBUG in IRReceive.hpp, which was accidently enabled at 4.1.0.
|
||||
|
||||
## 4.1.0
|
||||
- Fixed bug in printing durations > 64535 in printIRResultRawFormatted().
|
||||
- Narrowed constraints for RC5 RC6 number of bits.
|
||||
- Changed the first parameter of printTinyReceiverResultMinimal() to &Serial.
|
||||
- Removed 3 Serial prints for deprecation warnings to fix #1094.
|
||||
- Version 1.2.0 of TinyIR. Now FAST protocol with 40 ms period and shorter header space.
|
||||
- Removed field "bool hasStopBit" and parameter "bool aSendStopBit" from PulseDistanceWidthProtocolConstants structure and related functions.
|
||||
- Changed a lot of "unsigned int" types to "uint16_t" types.
|
||||
- Improved overflow handling.
|
||||
- Improved software PWM generation.
|
||||
- Added FAST protocol.
|
||||
- Improved handling of PULSE_DISTANCE + PULSE_WIDTH protocols.
|
||||
- New example ReceiveAndSendDistanceWidth.
|
||||
- Removed the automatic restarting of the receiver timer after sending with SEND_PWM_BY_TIMER enabled.
|
||||
- Split ISR into ISR and function IRPinChangeInterruptHandler().
|
||||
- Added functions addTicksToInternalTickCounter() and addMicrosToInternalTickCounter().
|
||||
|
||||
## 4.0.0
|
||||
- Added decoding of PulseDistanceWidth protocols and therefore changed function decodeDistance() to decodeDistanceWidth() and filename ir_DistanceProtocol.hpp to ir_DistanceWidthProtocol.hpp.
|
||||
- Removed static function printIRSendUsage(), but kept class function printIRSendUsage().
|
||||
- Changed type of decodedRawData and decodedRawDataArray which is now 64 bit for 32 bit platforms.
|
||||
- Added receiver callback functionality and registerReceiveCompleteCallback() function.
|
||||
- Introduced common structure PulseDistanceWidthProtocolConstants.
|
||||
- Where possible, changed all send and decode functions to use PulseDistanceWidthProtocolConstants.
|
||||
- Improved MSB/LSB handling
|
||||
- New convenience fuctions bitreverse32Bit() and bitreverseOneByte().
|
||||
- Improved Magiquest protocol.
|
||||
- Fix for #1028 - Prevent long delay caused by overflow when frame duration < repeat period - Thanks to Stephen Humphries!
|
||||
- Support for ATtiny816 - Thanks to elockman.
|
||||
- Added Bang&Olufsen protocol. #1030.
|
||||
- Third parameter of function "void begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin)" is not optional anymore and this function is now only available if IR_SEND_PIN is not defined. #1033.
|
||||
- Fixed bug in sendSony() for command parameter > 0x7F;
|
||||
- Fixed bug with swapped LG2 header mark and space.
|
||||
- Disabled strict checks while decoding. They can be enabled by defining DECODE_STRICT_CHECKS.
|
||||
- Merged the 2 decode pulse width and distance functions.
|
||||
- Changed macro names _REPEAT_SPACE to _REPEAT_DISTANCE.
|
||||
- Improved TinyIRReceiver,added FAST protocol for it and added TinyIRSender.hpp and TinySender example, renamed TinyReceiver.h to TinyIR.h.
|
||||
- Added DISABLE_CODE_FOR_RECEIVER to save program memory and RAM if receiving functionality is not required.
|
||||
- Extracted protocol functions used by receive and send to IRProtocol.hpp.
|
||||
- Analyzed Denon code table and therefore changed Denon from MSB to LSB first.
|
||||
- Renamed sendRC6(aRawData...) to sendRC6Raw( aRawData...).
|
||||
- Support for seeduino which lacks the print(unsigned long long...) method. Thanks to sklott https://stackoverflow.com/users/11680056/sklott
|
||||
- Added support for attiny1614 by Joe Ostrander.
|
||||
- Fixed SEND_PWM_BY_TIMER for ATtiny167 thanks to freskpe.
|
||||
- Improved SHARP repeat decoding.
|
||||
- Replaced macros TIMER_EN/DISABLE_RECEIVE_INTR and EN/DISABLE_SEND_PWM_BY_TIMER by functions.
|
||||
- Added SAMSUNG48 protocol and sendSamsung48() function.
|
||||
|
||||
## 3.9.0
|
||||
- Improved documentation with the help of [ElectronicsArchiver}(https://github.com/ElectronicsArchiver).
|
||||
- Added NEC2 protocol.
|
||||
- Improved Magiquest protocol.
|
||||
- Renamed sendSamsungRepeat() to sendSamsungLGRepeat().
|
||||
- Added function sendPulseDistanceWidth().
|
||||
- Improved repeat detection for some protocols.
|
||||
|
||||
## 3.8.0
|
||||
- Changed Samsung repeat handling. Old handling is available as SamsungLG.
|
||||
- Added function printIRSendUsage().
|
||||
- Reduced output size and improved format of printIRResultRawFormatted() to fasten up output (and getting repeats properly decoded).
|
||||
- Fixed Bug in sendDenonRaw() and improved decodeDenon().
|
||||
- Fixed potential bug in SendBiphase data for 1 bit.
|
||||
- Fixed bug in send for RP4020.
|
||||
- Fixed pin mapping problems especially for Teensy 2.0.
|
||||
- Added support for decoding of "special" NEC repeats.
|
||||
- Added SAMD51 support.
|
||||
- Improved pin mapping for TinyReceiver.
|
||||
|
||||
## 3.7.1
|
||||
- SendRaw now supports bufferlenght > 255.
|
||||
- Improved DistanceProtocol decoder output.
|
||||
- Fixed ESP32 send bug for 2.x ESP32 cores.
|
||||
|
||||
## 3.7.0
|
||||
- Changed TOLERANCE to TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING and documented it.
|
||||
- Changed last uint8_t to uint_fast8_t and uint16_t to unsigned integer.
|
||||
- Improved MagiQuest protocol.
|
||||
- Improved prints and documentation.
|
||||
- Added IrReceiver.restartAfterSend() and inserted it in every send(). Closes #989
|
||||
- Use IRAM_ATTR instead of deprecated ICACHE_RAM_ATTR for ESP8266.
|
||||
- Removed pulse width decoding from ir_DistanceProtocol.
|
||||
|
||||
## 3.6.1
|
||||
- Switched Bose internal protocol timing for 0 and 1 -> old 1 timing is now 0 and vice versa.
|
||||
|
||||
## 3.6.0
|
||||
- Separated enable flag of send and receive feedback LED. Inspired by PR#970 from luvaihassanali.
|
||||
- RP2040 support added.
|
||||
- Refactored IRTimer.hpp.
|
||||
- Refactored IR_SEND_PIN and IrSender.sendPin handling.
|
||||
- Renamed IR_SEND_DUTY_CYCLE to IR_SEND_DUTY_CYCLE_PERCENT.
|
||||
- Fixed bugs for SEND_PWM_BY_TIMER active.
|
||||
|
||||
## 3.5.2
|
||||
- Improved support for Teensy boards by Paul Stoffregen.
|
||||
|
||||
## 3.5.1
|
||||
- Renamed INFO_PRINT to IR_INFO_PRINT as well as for DEBUG and TRACE.
|
||||
- Fixed error with DEBUG in TinyIRReceiver.hpp.
|
||||
- Support for ATmega88 see issue #923. Thanks to Dolmant.
|
||||
- NO_LED_FEEDBACK_CODE replaces and extends DISABLE_LED_FEEDBACK_FOR_RECEIVE.
|
||||
- Removed NO_LEGACY_COMPATIBILITY macro, it was useless now.
|
||||
- Fix ESP32 send bug see issue #927.
|
||||
|
||||
## 3.5.0
|
||||
- Improved ir_DistanceProtocol.
|
||||
- Tone for ESP32.
|
||||
- last phase renamed *.cpp.h to .hpp.
|
||||
- No deprecation print for ATtinies.
|
||||
- Renamed ac_LG.cpp to ac_LG.hpp.
|
||||
- Maintained MagiQuest by E. Stuart Hicks.
|
||||
- Improved print Pronto by Asuki Kono.
|
||||
- Added printActiveIRProtocols() function.
|
||||
- Used IR_SEND_PIN to reduce code size and improved send timing for AVR.
|
||||
|
||||
## 3.4.0
|
||||
- Added LG2 protocol.
|
||||
- Added ATtiny167 (Digispark Pro) support.
|
||||
- Renamed *.cpp.h to .hpp.
|
||||
- organized carrier frequencies.
|
||||
- Compiler switch USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN added.
|
||||
- Moved blink13() back to IRrecv class.
|
||||
- Added Kaseikyo convenience functions like sendKaseikyo_Denon().
|
||||
- Improved / adjusted LG protocol and added class Aircondition_LG based on real hardware supplied by makerspace 201 (https://wiki.hackerspaces.org/ZwoNullEins) from Cologne.
|
||||
- Improved universal decoder for pulse distance protocols to support more than 32 bits.
|
||||
- Added mbed support.
|
||||
|
||||
## 3.3.0
|
||||
- Fix errors if LED_BUILTIN is not defined.
|
||||
- Fixed error for AVR timer1. Thanks to alexbarcelo.
|
||||
- New example IRremoteExtensionTest.
|
||||
- Enabled megaAVR 0-series devices.
|
||||
- Added universal decoder for pulse distance protocols.
|
||||
|
||||
## 3.2.0
|
||||
- Fix for ESP32 send Error, removed `USE_SOFT_SEND_PWM` macro.
|
||||
- Added Onkyo protocol.
|
||||
- Support for old 2.x code by backwards compatible `decode(decode_results *aResults)` function.
|
||||
- Removed USE_OLD_DECODE macro and added NO_LEGACY_COMPATIBILITY macro.
|
||||
- Added ATtiny1604 support.
|
||||
- New SendAndReceive example.
|
||||
- Added ESP8266 support.
|
||||
- Extended DEBUG output.
|
||||
|
||||
## 3.1.0
|
||||
- Generation of PWM by software is active by default.
|
||||
- Removed decode_results results.
|
||||
- Renamed most irparams_struct values.
|
||||
- Fixed LG send bug and added unit test.
|
||||
- Replaced `#define DECODE_NEC 1/0` by defining/not defining.
|
||||
- Use LED_BUILTIN instead of FEEDBACK_LED if FeedbackLEDPin is 0.
|
||||
- Use F_CPU instead of SYSCLOCK.
|
||||
- Removed SENDPIN_ON and SENDPIN_OFF macros.
|
||||
|
||||
- Refactored board specific code for timer and feedback LED.
|
||||
- Extracted common LED feedback functions and implemented feedback for send.
|
||||
- MATCH_MARK() etc. now available as matchMark().
|
||||
- Added STM32F1 by (by Roger Clark) support.
|
||||
- Added stm32 (by ST) support. Thanks to Paolo Malaspina.
|
||||
- Added ATtiny88 support.
|
||||
|
||||
## 3.0.2
|
||||
- Bug fix for USE_OLD_DECODE.
|
||||
- Increase RECORD_GAP_MICROS to 11000.
|
||||
- Fix overflow message. (#793).
|
||||
- Improved handling for HASH decoder.
|
||||
- Tested for ATtiny85.
|
||||
- Added `printIRResultMinimal()`.
|
||||
- Added missing IRAM_ATTR for ESP32.
|
||||
- Adapted to TinyCore 0.0.7.
|
||||
- Fixed decodeSony 20 bit bug #811.
|
||||
- Replaced delayMicroseconds with customDelayMicroseconds and removed NoInterrupt() for send functions, removed SPIN_WAIT macro, sleepMicros() and sleepUntilMicros().
|
||||
- Fixed LG checksum error.
|
||||
- Fixed JVC repeat error.
|
||||
|
||||
## 3.0.0 + 3.0.1 2021/02
|
||||
- New LSB first decoders are default.
|
||||
- Added SendRaw with byte data.
|
||||
- Fixed resume bug if irparams.rawlen >= RAW_BUFFER_LENGTH. Thanks to Iosif Peterfi
|
||||
- Added `dumpPronto(String *aString, unsigned int frequency)` with String object as argument. Thanks to Iosif Peterfi
|
||||
- Removed Test2 example.
|
||||
- Fixed swapped cases in `getProtocolString()`. Thanks to Jim-2249
|
||||
- Added compile option `IR_INPUT_IS_ACTIVE_HIGH`. Thanks to Jim-2249
|
||||
- Corrected template. Thanks to Jim-2249
|
||||
- Introduced standard decode and send functions.
|
||||
- Added compatibility with tone for AVR's.
|
||||
- New TinyIRreceiver does not require a timer.
|
||||
- New MinimalReceiver and IRDispatcherDemo examples.
|
||||
- Added TinyCore 32 / ATtiny3217 support.
|
||||
- Added Apple protocol.
|
||||
|
||||
## 2.8.1 2020/10
|
||||
- Fixed bug in Sony decode introduced in 2.8.0.
|
||||
|
||||
## 2.8.0 2020/10
|
||||
- Changed License to MIT see https://github.com/Arduino-IRremote/Arduino-IRremote/issues/397.
|
||||
- Added ATtiny timer 1 support.
|
||||
- Changed wrong return code signature of decodePulseDistanceData() and its handling.
|
||||
- Removed Mitsubishi protocol, since the implementation is in contradiction with all documentation I found and therefore supposed to be wrong.
|
||||
- Removed AIWA implementation, since it is only for 1 device and at least the sending was implemented wrong.
|
||||
- Added Lego_PF decode.
|
||||
- Changed internal usage of custom_delay_usec.
|
||||
- Moved dump/print functions from example to irReceiver.
|
||||
- irPronto.cpp: Using Print instead of Stream saves 1020 bytes program memory. Changed from & to * parameter type to be more transparent and consistent with other code of IRremote.
|
||||
|
||||
## 2.7.0 2020/09
|
||||
- Added ATmega328PB support.
|
||||
- Renamed hardware specific macro and function names.
|
||||
- Renamed `USE_SOFT_CARRIER`, `USE_NO_CARRIER`, `DUTY_CYCLE` macros to `USE_SOFT_SEND_PWM`, `USE_NO_SEND_PWM`, `IR_SEND_DUTY_CYCLE`.
|
||||
- Removed blocking wait for ATmega32U4 Serial in examples.
|
||||
- Deactivated default debug output.
|
||||
- Optimized types in sendRC5ext and sendSharpAlt.
|
||||
- Added `DECODE_NEC_STANDARD` and `SEND_NEC_STANDARD`.
|
||||
- Renamed all IRrecv* examples to IRreceive*.
|
||||
- Added functions `printIRResultShort(&Serial)` and `getProtocolString(decode_type_t aDecodeType)`.
|
||||
- Added flag `decodedIRData.isRepeat`.
|
||||
- Updated examples.
|
||||
|
||||
## 2.6.1 2020/08
|
||||
- Adjusted JVC and LG timing.
|
||||
- Fixed 4809 bug.
|
||||
|
||||
## 2.6.0 2020/08
|
||||
- Added support for MagiQuest IR wands.
|
||||
- Corrected Samsung timing.
|
||||
- NEC repeat implementation.
|
||||
- Formatting and changing `TIMER_CONFIG_KHZ` and `TIMER_CONFIG_NORMAL` macros to static functions.
|
||||
- Added `IRAM_ATTR` for ESP32 ISR.
|
||||
- Removed `#define HAS_AVR_INTERRUPT_H`.
|
||||
- Changed Receiver States. Now starting with 0.
|
||||
- Changed switch to if / else if in IRRemote.cpp because of ESP32 compiler bug.
|
||||
- Changed `DEBUG` handling since compiler warns about empty "IF" or "ELSE" statements in IRRemote.cpp.
|
||||
|
||||
## 2.5.0 2020/06
|
||||
- Corrected keywords.txt.
|
||||
- BoseWave protocol added PR #690.
|
||||
- Formatting comply to the new stylesheet.
|
||||
- Renamed "boarddefs.h" [ISSUE #375](https://github.com/Arduino-IRremote/Arduino-IRremote/issues/375).
|
||||
- Renamed `SEND_PIN` to `IR_SEND_PIN`.
|
||||
- Renamed state macros.
|
||||
- Enabled `DUTY_CYCLE` for send signal.
|
||||
- Added sending for ESP32.
|
||||
- Changed rawlen from uint8_t to unsigned int allowing bigger receive buffer and renamed `RAWBUF` to `RAW_BUFFER_LENGTH`.
|
||||
- Introduced `USE_NO_CARRIER` for simulating an IR receiver.
|
||||
Changes from #283 by bengtmartensson
|
||||
- Added function sendRaw_P() for sending data from flash.
|
||||
Changes from #268 by adamlhumphreys
|
||||
- Optimized by reducing floating point operations as suggested by madmalkav (#193).
|
||||
- Optimized with macros when using default `MICROS_PER_TICK` and `TOLERANCE`.
|
||||
- Made decodeHash as a settable protocol defined by `DECODE_HASH`.
|
||||
- Added Philips Extended RC-5 protocol support [PR #522] (https://github.com/Arduino-IRremote/Arduino-IRremote/pull/522)
|
||||
|
||||
## 2.4.0 - 2017/08/10
|
||||
- Cleanup of hardware dependencies. Merge in SAM support [PR #437](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/437)
|
||||
|
||||
## 2.3.3 - 2017/03/31
|
||||
- Added ESP32 IR receive support [PR #427](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/425)
|
||||
|
||||
## 2.2.3 - 2017/03/27
|
||||
- Fix calculation of pause length in LEGO PF protocol [PR #427](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/427)
|
||||
|
||||
## 2.2.2 - 2017/01/20
|
||||
- Fixed naming bug [PR #398](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/398)
|
||||
|
||||
## 2.2.1 - 2016/07/27
|
||||
- Added tests for Lego Power Functions Protocol [PR #336](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/336)
|
||||
|
||||
## 2.2.0 - 2016/06/28
|
||||
- Added support for ATmega8535
|
||||
- Added support for ATmega16
|
||||
- Added support for ATmega32
|
||||
- Added support for ATmega164
|
||||
- Added support for ATmega324
|
||||
- Added support for ATmega644
|
||||
- Added support for ATmega1284
|
||||
- Added support for ATmega64
|
||||
- Added support for ATmega128
|
||||
|
||||
[PR](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/324)
|
||||
|
||||
## 2.1.1 - 2016/05/04
|
||||
- Added Lego Power Functions Protocol [PR #309](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/309)
|
||||
|
||||
## 2.1.0 - 2016/02/20
|
||||
- Improved Debugging [PR #258](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/258)
|
||||
- Display TIME instead of TICKS [PR #258](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/258)
|
||||
|
||||
## 2.0.4 - 2016/02/20
|
||||
- Add Panasonic and JVC to IRrecord example [PR](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/54)
|
||||
|
||||
## 2.0.3 - 2016/02/20
|
||||
- Change IRSend Raw parameter to const [PR](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/227)
|
||||
|
||||
## 2.0.2 - 2015/12/02
|
||||
- Added IRremoteInfo Sketch - [PR](https://github.com/Arduino-IRremote/Arduino-IRremote/pull/241)
|
||||
- Enforcing changelog.md
|
||||
|
||||
## 2.0.1 - 2015/07/26 - [Release](https://github.com/shirriff/Arduino-IRremote/releases/tag/BETA)
|
||||
### Changes
|
||||
- Updated README
|
||||
- Updated Contributors
|
||||
- Fixed #110 Mess
|
||||
- Created Gitter Room
|
||||
- Added Gitter Badge
|
||||
- Standardised Code Base
|
||||
- Clean Debug Output
|
||||
- Optimized Send Loops
|
||||
- Modularized Design
|
||||
- Optimized and Updated Examples
|
||||
- Improved Documentation
|
||||
- Fixed and Improved many coding errors
|
||||
- Fixed Aiwa RC-T501 Decoding
|
||||
- Fixed Interrupt on ATmega8
|
||||
- Switched to Stable Release of PlatformIO
|
||||
|
||||
### Additions
|
||||
- Added Aiwa RC-T501 Protocol
|
||||
- Added Denon Protocol
|
||||
- Added Pronto Support
|
||||
- Added compile options
|
||||
- Added Template For New Protocols
|
||||
- Added this changelog
|
||||
- Added Teensy LC Support
|
||||
- Added ATtiny84 Support
|
||||
- Added ATtiny85 Support
|
||||
- Added isIdle method
|
||||
|
||||
### Deletions
|
||||
- Removed (Fixed) #110
|
||||
- Broke Teensy 3 / 3.1 Support
|
||||
|
||||
### Not Working
|
||||
- Teensy 3 / 3.1 Support is in Development
|
||||
100
libraries/IRremote/examples/ControlRelay/ControlRelay.ino
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* ControlRelay.cpp
|
||||
*
|
||||
* Toggles an output pin at each command received
|
||||
* An IR detector/demodulator must be connected to the input RECV_PIN.
|
||||
* Initially coded 2009 Ken Shirriff http://www.righto.com
|
||||
*
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2009-2021 Ken Shirriff, Armin Joachimsmeyer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
//#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
|
||||
#include <IRremote.hpp>
|
||||
|
||||
#define RELAY_PIN 5 // P0_4
|
||||
#define IR_RECEIVE_PIN 4 // P0_1
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
pinMode(RELAY_PIN, OUTPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
// Just to know which program is running on my Arduino
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
|
||||
|
||||
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
|
||||
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
|
||||
|
||||
Serial.print(F("Ready to receive IR signals of protocols: "));
|
||||
printActiveIRProtocols(&Serial);
|
||||
Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
|
||||
}
|
||||
|
||||
int on = 0;
|
||||
unsigned long last = millis();
|
||||
|
||||
void loop() {
|
||||
if (IrReceiver.decode()) {
|
||||
// If it's been at least 1/4 second since the last
|
||||
// IR received, toggle the relay
|
||||
if (millis() - last > 250) {
|
||||
on = !on;
|
||||
Serial.print(F("Switch relay "));
|
||||
if (on) {
|
||||
digitalWrite(RELAY_PIN, HIGH);
|
||||
Serial.println(F("on"));
|
||||
} else {
|
||||
digitalWrite(RELAY_PIN, LOW);
|
||||
Serial.println(F("off"));
|
||||
}
|
||||
|
||||
IrReceiver.printIRResultShort(&Serial);
|
||||
IrReceiver.printIRSendUsage(&Serial);
|
||||
Serial.println();
|
||||
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
|
||||
// We have an unknown protocol, print more info
|
||||
Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
|
||||
IrReceiver.printIRResultRawFormatted(&Serial, true);
|
||||
}
|
||||
|
||||
}
|
||||
last = millis();
|
||||
IrReceiver.resume(); // Enable receiving of the next value
|
||||
}
|
||||
}
|
||||
349
libraries/IRremote/examples/ControlRelay/PinDefinitionsAndMore.h
Normal file
@ -0,0 +1,349 @@
|
||||
/*
|
||||
* PinDefinitionsAndMore.h
|
||||
*
|
||||
* Contains pin definitions for IRremote examples for various platforms
|
||||
* as well as definitions for feedback LED and tone() and includes
|
||||
*
|
||||
* Copyright (C) 2021-2023 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* Arduino-IRremote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pin mapping table for different platforms
|
||||
*
|
||||
* Platform IR input IR output Tone Core/Pin schema
|
||||
* --------------------------------------------------------------
|
||||
* DEFAULT/AVR 2 3 4 Arduino
|
||||
* ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore
|
||||
* ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore
|
||||
* ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core
|
||||
* ATtiny84 |PB2 |PA4 |PA3 ATTinyCore
|
||||
* ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore
|
||||
* ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore
|
||||
* ATtiny1604 2 3|PA5 %
|
||||
* ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore
|
||||
* ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore
|
||||
* SAMD21 3 4 5
|
||||
* ESP8266 14|D5 12|D6 %
|
||||
* ESP32 15 4 27
|
||||
* ESP32-C3 2 3 4
|
||||
* BluePill PA6 PA7 PA3
|
||||
* APOLLO3 11 12 5
|
||||
* RP2040 3|GPIO15 4|GPIO16 5|GPIO17
|
||||
*/
|
||||
//#define _IR_MEASURE_TIMING // For debugging purposes.
|
||||
|
||||
#if defined(__AVR__)
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore.
|
||||
#define IR_RECEIVE_PIN PIN_PB0
|
||||
#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board.
|
||||
#define TONE_PIN PIN_PB3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB3
|
||||
|
||||
# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut"
|
||||
// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source.
|
||||
# if defined(ARDUINO_AVR_DIGISPARKPRO)
|
||||
// For use with Digispark original core
|
||||
#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9
|
||||
//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8
|
||||
#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5
|
||||
#define _IR_TIMING_TEST_PIN 10 // PA4
|
||||
# else
|
||||
// For use with ATTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8
|
||||
#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5
|
||||
# endif
|
||||
|
||||
# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
#define IR_RECEIVE_PIN PIN_PB2 // INT0
|
||||
#define IR_SEND_PIN PIN_PA4
|
||||
#define TONE_PIN PIN_PA3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PA5
|
||||
|
||||
# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
// Pin 6 is TX, pin 7 is RX
|
||||
#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1
|
||||
#define IR_SEND_PIN PIN_PD4 // 4
|
||||
#define TONE_PIN PIN_PB1 // 9
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB0 // 8
|
||||
|
||||
# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore
|
||||
// Tiny Core Dev board
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // use 18 instead of PIN_PA1 for TinyCore32
|
||||
#define IR_SEND_PIN PIN_PA2 // 19
|
||||
#define TONE_PIN PIN_PA3 // 20
|
||||
#define APPLICATION_PIN PIN_PA0 // 0
|
||||
#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32
|
||||
|
||||
# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 14
|
||||
#define IR_SEND_PIN PIN_PA1 // 16
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PB5 // 4
|
||||
|
||||
# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 8
|
||||
#define IR_SEND_PIN PIN_PA3 // 10
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
|
||||
# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN PIN_PA7 // 3
|
||||
#define APPLICATION_PIN PIN_PB2 // 5
|
||||
|
||||
#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone()
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|
||||
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|
||||
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|
||||
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|
||||
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
|
||||
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \
|
||||
|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \
|
||||
|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \
|
||||
|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 13
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc.
|
||||
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit
|
||||
// We have no built in LED at pin 13 -> reuse RX LED
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN LED_BUILTIN_RX
|
||||
# endif
|
||||
# endif // defined(__AVR_ATtiny25__)...
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4
|
||||
// To be compatible with Uno R3.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW
|
||||
#define IR_RECEIVE_PIN 14 // D5
|
||||
#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED
|
||||
#define _IR_TIMING_TEST_PIN 2 // D4
|
||||
#define APPLICATION_PIN 13 // D7
|
||||
|
||||
#define tone(...) void() // tone() inhibits receive timer
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it#
|
||||
|
||||
#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 10
|
||||
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV)
|
||||
#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working...
|
||||
#define IR_RECEIVE_PIN 6
|
||||
#define IR_SEND_PIN 7
|
||||
#define TONE_PIN 10
|
||||
#define APPLICATION_PIN 18
|
||||
|
||||
#elif defined(ESP32)
|
||||
#include <Arduino.h>
|
||||
|
||||
// tone() is included in ESP32 core since 2.0.2
|
||||
#if !defined(ESP_ARDUINO_VERSION_VAL)
|
||||
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678
|
||||
#endif
|
||||
#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer.
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
}
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
delay(aDuration);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
void noTone(uint8_t aPinNumber){
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
|
||||
#define IR_RECEIVE_PIN 15 // D15
|
||||
#define IR_SEND_PIN 4 // D4
|
||||
#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1
|
||||
#define APPLICATION_PIN 16 // RX2 pin
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill
|
||||
// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone()
|
||||
#define IR_RECEIVE_PIN PA6
|
||||
#define IR_RECEIVE_PIN_STRING "PA6"
|
||||
#define IR_SEND_PIN PA7
|
||||
#define IR_SEND_PIN_STRING "PA7"
|
||||
#define TONE_PIN PA3
|
||||
#define _IR_TIMING_TEST_PIN PA5
|
||||
#define APPLICATION_PIN PA2
|
||||
#define APPLICATION_PIN_STRING "PA2"
|
||||
# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8)
|
||||
// BluePill LED is active low
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW
|
||||
# endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards
|
||||
#define IR_RECEIVE_PIN 11
|
||||
#define IR_SEND_PIN 12
|
||||
#define TONE_PIN 5
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED
|
||||
// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect
|
||||
#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
|
||||
#define IR_SEND_PIN 4 // GPIO16
|
||||
#define TONE_PIN 5
|
||||
#define APPLICATION_PIN 6
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 8
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
|
||||
#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3)
|
||||
#define IR_SEND_PIN 16 // GPIO16
|
||||
#define TONE_PIN 17
|
||||
#define APPLICATION_PIN 18
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 20
|
||||
|
||||
// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN
|
||||
// and use the external reset with 1 kOhm to ground to enter UF2 mode
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN 6
|
||||
|
||||
#elif defined(PARTICLE) // !!!UNTESTED!!!
|
||||
#define IR_RECEIVE_PIN A4
|
||||
#define IR_SEND_PIN A5 // Particle supports multiple pins
|
||||
|
||||
#define LED_BUILTIN D7
|
||||
|
||||
/*
|
||||
* 4 times the same (default) layout for easy adaption in the future
|
||||
*/
|
||||
#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0)
|
||||
// On the Zero and others we switch explicitly to SerialUSB
|
||||
#define Serial SerialUSB
|
||||
#endif
|
||||
|
||||
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
|
||||
// Attention!!! D2 and D4 are swapped on these boards!!!
|
||||
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 24 // PB11
|
||||
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 25 // PB03
|
||||
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
|
||||
|
||||
#elif defined (NRF51) // BBC micro:bit
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define APPLICATION_PIN 1
|
||||
#define _IR_TIMING_TEST_PIN 4
|
||||
|
||||
#define tone(...) void() // no tone() available
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
#else
|
||||
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
|
||||
// Default valued for unidentified boards
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
#endif // defined(ESP8266)
|
||||
|
||||
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)
|
||||
#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation
|
||||
#else
|
||||
# if defined(SEND_PWM_BY_TIMER)
|
||||
#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (FLASHEND)
|
||||
#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* DemoIRCommandMapping.h
|
||||
*
|
||||
* IR remote button codes, strings, and functions to call
|
||||
*
|
||||
* Copyright (C) 2019-2022 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _IR_COMMAND_MAPPING_H
|
||||
#define _IR_COMMAND_MAPPING_H
|
||||
|
||||
#include <Arduino.h>
|
||||
//#include "Commands.h" // includes all the commands used in the mapping arrays below
|
||||
|
||||
/*
|
||||
* !!! Choose your remote !!!
|
||||
*/
|
||||
//#define USE_KEYES_REMOTE_CLONE With number pad and direction control switched, will be taken as default
|
||||
//#define USE_KEYES_REMOTE
|
||||
#if !defined(USE_KEYES_REMOTE) && !defined(USE_KEYES_REMOTE_CLONE)
|
||||
#define USE_KEYES_REMOTE_CLONE // the one you can buy at aliexpress
|
||||
#endif
|
||||
|
||||
#if (defined(USE_KEYES_REMOTE) && defined(USE_KEYES_REMOTE_CLONE))
|
||||
#error "Please choose only one remote for compile"
|
||||
#endif
|
||||
|
||||
#if defined(USE_KEYES_REMOTE_CLONE)
|
||||
#define IR_REMOTE_NAME "KEYES_CLONE"
|
||||
// Codes for the KEYES CLONE remote control with 17 keys with number pad above direction control
|
||||
#if defined(USE_IRMP_LIBRARY)
|
||||
#define IR_ADDRESS 0xFF00 // IRMP interprets NEC addresses always as 16 bit
|
||||
#else
|
||||
#define IR_ADDRESS 0x00
|
||||
#endif
|
||||
|
||||
#define IR_UP 0x18
|
||||
#define IR_DOWN 0x52
|
||||
#define IR_RIGHT 0x5A
|
||||
#define IR_LEFT 0x08
|
||||
#define IR_OK 0x1C
|
||||
|
||||
#define IR_1 0x45
|
||||
#define IR_2 0x46
|
||||
#define IR_3 0x47
|
||||
#define IR_4 0x44
|
||||
#define IR_5 0x40
|
||||
#define IR_6 0x43
|
||||
#define IR_7 0x07
|
||||
#define IR_8 0x15
|
||||
#define IR_9 0x09
|
||||
#define IR_0 0x19
|
||||
|
||||
#define IR_STAR 0x16
|
||||
#define IR_HASH 0x0D
|
||||
/*
|
||||
* SECOND:
|
||||
* IR button to command mapping for better reading. IR buttons should only referenced here.
|
||||
*/
|
||||
#define COMMAND_ON IR_UP
|
||||
#define COMMAND_OFF IR_DOWN
|
||||
#define COMMAND_INCREASE_BLINK IR_RIGHT
|
||||
#define COMMAND_DECREASE_BLINK IR_LEFT
|
||||
|
||||
#define COMMAND_START IR_OK
|
||||
#define COMMAND_STOP IR_HASH
|
||||
#define COMMAND_RESET IR_STAR
|
||||
#define COMMAND_BLINK IR_0
|
||||
#define COMMAND_TONE1 IR_1
|
||||
|
||||
#define COMMAND_TONE2 IR_2
|
||||
#define COMMAND_TONE3 IR_3
|
||||
//#define IR_4
|
||||
//#define IR_5
|
||||
//#define IR_6
|
||||
//#define IR_7
|
||||
//#define IR_8
|
||||
//#define IR_9
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(USE_KEYES_REMOTE)
|
||||
#define IR_REMOTE_NAME "KEYES"
|
||||
/*
|
||||
* FIRST:
|
||||
* IR code to button mapping for better reading. IR codes should only referenced here.
|
||||
*/
|
||||
// Codes for the KEYES remote control with 17 keys and direction control above number pad
|
||||
#if defined(USE_IRMP_LIBRARY)
|
||||
#define IR_ADDRESS 0xFF00 // IRMP interprets NEC addresses always as 16 bit
|
||||
#else
|
||||
#define IR_ADDRESS 0x00
|
||||
#endif
|
||||
|
||||
#define IR_UP 0x46
|
||||
#define IR_DOWN 0x15
|
||||
#define IR_RIGHT 0x43
|
||||
#define IR_LEFT 0x44
|
||||
#define IR_OK 0x40
|
||||
|
||||
#define IR_1 0x16
|
||||
#define IR_2 0x19
|
||||
#define IR_3 0x0D
|
||||
#define IR_4 0x0C
|
||||
#define IR_5 0x18
|
||||
#define IR_6 0x5E
|
||||
#define IR_7 0x08
|
||||
#define IR_8 0x1C
|
||||
#define IR_9 0x5A
|
||||
#define IR_0 0x52
|
||||
|
||||
#define IR_STAR 0x42
|
||||
#define IR_HASH 0x4A
|
||||
|
||||
/*
|
||||
* SECOND:
|
||||
* IR button to command mapping for better reading. IR buttons should only referenced here.
|
||||
*/
|
||||
#define COMMAND_ON IR_UP
|
||||
#define COMMAND_OFF IR_DOWN
|
||||
#define COMMAND_INCREASE_BLINK IR_RIGHT
|
||||
#define COMMAND_DECREASE_BLINK IR_LEFT
|
||||
|
||||
#define COMMAND_RESET IR_OK
|
||||
#define COMMAND_STOP IR_HASH
|
||||
#define COMMAND_STOP IR_STAR
|
||||
#define COMMAND_BLINK IR_0
|
||||
#define COMMAND_TONE2 IR_1
|
||||
|
||||
#define COMMAND_TONE1 IR_2
|
||||
#define COMMAND_TONE2 IR_3
|
||||
#define COMMAND_TONE2 IR_4
|
||||
#define COMMAND_TONE2 IR_5
|
||||
#define COMMAND_TONE2 IR_6
|
||||
#define COMMAND_TONE2 IR_7
|
||||
#define COMMAND_TONE2 IR_8
|
||||
#define COMMAND_TONE2 IR_9
|
||||
#endif
|
||||
|
||||
/*
|
||||
* THIRD:
|
||||
* Main mapping of commands to C functions
|
||||
*/
|
||||
|
||||
// IR strings of functions for output
|
||||
static const char LEDon[] PROGMEM ="LED on";
|
||||
static const char LEDoff[] PROGMEM ="LED off";
|
||||
|
||||
static const char blink20times[] PROGMEM ="blink 20 times";
|
||||
static const char blinkStart[] PROGMEM ="blink start";
|
||||
|
||||
static const char increaseBlink[] PROGMEM ="increase blink frequency";
|
||||
static const char decreaseBlink[] PROGMEM ="decrease blink frequency";
|
||||
|
||||
static const char tone2200[] PROGMEM ="tone 2200";
|
||||
static const char tone1800[] PROGMEM ="tone 1800";
|
||||
static const char printMenu[] PROGMEM ="printMenu";
|
||||
|
||||
static const char reset[] PROGMEM ="reset";
|
||||
static const char stop[] PROGMEM ="stop";
|
||||
|
||||
// not used yet
|
||||
static const char test[] PROGMEM ="test";
|
||||
static const char pattern[] PROGMEM ="pattern";
|
||||
static const char unknown[] PROGMEM ="unknown";
|
||||
|
||||
/*
|
||||
* Main mapping array of commands to C functions and command strings
|
||||
*/
|
||||
const struct IRToCommandMappingStruct IRMapping[] = { /**/
|
||||
{ COMMAND_BLINK, IR_COMMAND_FLAG_BLOCKING, &doLedBlink20times, blink20times }, /**/
|
||||
{ COMMAND_STOP, IR_COMMAND_FLAG_BLOCKING, &doStop, stop },
|
||||
|
||||
/*
|
||||
* Short commands, which can be executed always
|
||||
*/
|
||||
{ COMMAND_TONE1, IR_COMMAND_FLAG_BLOCKING, &doTone1800, tone1800 }, /**/
|
||||
{ COMMAND_TONE3, IR_COMMAND_FLAG_BLOCKING, &doPrintMenu, printMenu }, /**/
|
||||
{ COMMAND_ON, IR_COMMAND_FLAG_NON_BLOCKING, &doLedOn, LEDon }, /**/
|
||||
{ COMMAND_OFF, IR_COMMAND_FLAG_NON_BLOCKING, &doLedOff, LEDoff }, /**/
|
||||
{ COMMAND_START, IR_COMMAND_FLAG_NON_BLOCKING, &doLedBlinkStart, blinkStart }, /**/
|
||||
{ COMMAND_RESET, IR_COMMAND_FLAG_NON_BLOCKING, &doResetBlinkFrequency, reset },
|
||||
|
||||
/*
|
||||
* Repeatable short commands
|
||||
*/
|
||||
{ COMMAND_TONE2, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doTone2200, tone2200 }, /**/
|
||||
{ COMMAND_INCREASE_BLINK, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doIncreaseBlinkFrequency, increaseBlink }, /**/
|
||||
{ COMMAND_DECREASE_BLINK, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doDecreaseBlinkFrequency, decreaseBlink } };
|
||||
|
||||
#endif // _IR_COMMAND_MAPPING_H
|
||||
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* IRCommandDispatcher.h
|
||||
*
|
||||
* Library to process IR commands by calling functions specified in a mapping array.
|
||||
*
|
||||
* To run this example you need to install the "IRremote" or "IRMP" library under "Tools -> Manage Libraries..." or "Ctrl+Shift+I"
|
||||
*
|
||||
* Copyright (C) 2019-2024 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of ServoEasing https://github.com/ArminJo/ServoEasing.
|
||||
* This file is part of IRMP https://github.com/IRMP-org/IRMP.
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* IRCommandDispatcher is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*/
|
||||
|
||||
#ifndef _IR_COMMAND_DISPATCHER_H
|
||||
#define _IR_COMMAND_DISPATCHER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* For command mapping file
|
||||
*/
|
||||
#define IR_COMMAND_FLAG_BLOCKING 0x00 // default - blocking command, repeat not accepted, only one command at a time. Stops an already running command.
|
||||
#define IR_COMMAND_FLAG_REPEATABLE 0x01 // repeat accepted
|
||||
#define IR_COMMAND_FLAG_NON_BLOCKING 0x02 // Non blocking (short) command that can be processed any time and may interrupt other IR commands - used for stop, set direction etc.
|
||||
#define IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING (IR_COMMAND_FLAG_REPEATABLE | IR_COMMAND_FLAG_NON_BLOCKING)
|
||||
#define IR_COMMAND_FLAG_BEEP 0x04 // Do a single short beep before executing command. May not be useful for short or repeating commands.
|
||||
#define IR_COMMAND_FLAG_BLOCKING_BEEP (IR_COMMAND_FLAG_BLOCKING | IR_COMMAND_FLAG_BEEP)
|
||||
|
||||
|
||||
#if !defined(IS_STOP_REQUESTED)
|
||||
#define IS_STOP_REQUESTED IRDispatcher.requestToStopReceived
|
||||
#endif
|
||||
#if !defined(RETURN_IF_STOP)
|
||||
#define RETURN_IF_STOP if (IRDispatcher.requestToStopReceived) return
|
||||
#endif
|
||||
#if !defined(BREAK_IF_STOP)
|
||||
#define BREAK_IF_STOP if (IRDispatcher.requestToStopReceived) break
|
||||
#endif
|
||||
#if !defined(DELAY_AND_RETURN_IF_STOP)
|
||||
#define DELAY_AND_RETURN_IF_STOP(aDurationMillis) if (IRDispatcher.delayAndCheckForStop(aDurationMillis)) return
|
||||
#endif
|
||||
|
||||
// Basic mapping structure
|
||||
struct IRToCommandMappingStruct {
|
||||
#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT)
|
||||
uint16_t IRCode;
|
||||
#else
|
||||
uint8_t IRCode;
|
||||
#endif
|
||||
uint8_t Flags;
|
||||
void (*CommandToCall)();
|
||||
const char *CommandString;
|
||||
};
|
||||
|
||||
struct IRDataForCommandDispatcherStruct {
|
||||
uint16_t address; // to distinguish between multiple senders
|
||||
#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT)
|
||||
uint16_t command;
|
||||
#else
|
||||
uint8_t command;
|
||||
#endif
|
||||
bool isRepeat;
|
||||
uint32_t MillisOfLastCode; // millis() of last IR command -including repeats!- received - for timeouts etc.
|
||||
volatile bool isAvailable; // flag for a polling interpreting function, that a new command has arrived. Is set true by library and set false by main loop.
|
||||
};
|
||||
|
||||
/*
|
||||
* Special codes (hopefully) not sent by the remote - otherwise please redefine it here
|
||||
*/
|
||||
#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT)
|
||||
#define COMMAND_EMPTY 0xFFFF // code no command
|
||||
#else
|
||||
#define COMMAND_EMPTY 0xFF // code no command
|
||||
#endif
|
||||
|
||||
class IRCommandDispatcher {
|
||||
public:
|
||||
void init();
|
||||
void printIRInfo(Print *aSerial);
|
||||
|
||||
bool checkAndRunNonBlockingCommands();
|
||||
bool checkAndRunSuspendedBlockingCommands();
|
||||
#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT)
|
||||
void setNextBlockingCommand(uint16_t aBlockingCommandToRunNext);
|
||||
#else
|
||||
void setNextBlockingCommand(uint8_t aBlockingCommandToRunNext);
|
||||
#endif
|
||||
bool delayAndCheckForStop(uint16_t aDelayMillis);
|
||||
|
||||
// The main dispatcher function
|
||||
void checkAndCallCommand(bool aCallBlockingCommandImmediately);
|
||||
|
||||
void printIRCommandString(Print *aSerial);
|
||||
void setRequestToStopReceived(bool aRequestToStopReceived = true);
|
||||
|
||||
#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT)
|
||||
uint16_t currentBlockingCommandCalled = COMMAND_EMPTY; // The code for the current called command
|
||||
uint16_t lastBlockingCommandCalled = COMMAND_EMPTY; // The code for the last called command. Can be evaluated by main loop
|
||||
uint16_t BlockingCommandToRunNext = COMMAND_EMPTY; // Storage for command currently suspended to allow the current command to end, before it is called by main loop
|
||||
#else
|
||||
uint8_t currentBlockingCommandCalled = COMMAND_EMPTY; // The code for the current called command
|
||||
uint8_t lastBlockingCommandCalled = COMMAND_EMPTY; // The code for the last called command. Can be evaluated by main loop
|
||||
uint8_t BlockingCommandToRunNext = COMMAND_EMPTY; // Storage for command currently suspended to allow the current command to end, before it is called by main loop
|
||||
#endif
|
||||
bool justCalledBlockingCommand = false; // Flag that a blocking command was received and called - is set before call of command
|
||||
/*
|
||||
* Flag for running blocking commands to terminate. To check, you can use "if (IRDispatcher.requestToStopReceived) return;" (available as macro RETURN_IF_STOP).
|
||||
* It is set if a blocking IR command received, which cannot be executed directly. Can be reset by main loop, if command has stopped.
|
||||
* It is reset before executing a blocking command.
|
||||
*/
|
||||
volatile bool requestToStopReceived;
|
||||
/*
|
||||
* This flag must be true, if we have a function, which want to interpret the IR codes by itself e.g. the calibrate function of QuadrupedControl
|
||||
*/
|
||||
bool doNotUseDispatcher = false;
|
||||
|
||||
struct IRDataForCommandDispatcherStruct IRReceivedData;
|
||||
|
||||
};
|
||||
|
||||
extern IRCommandDispatcher IRDispatcher;
|
||||
|
||||
#endif // _IR_COMMAND_DISPATCHER_H
|
||||
@ -0,0 +1,366 @@
|
||||
/*
|
||||
* IRCommandDispatcher.hpp
|
||||
*
|
||||
* Library to process IR commands by calling functions specified in a mapping array.
|
||||
* Commands can be tagged as blocking or non blocking.
|
||||
*
|
||||
* To run this example you need to install the "IRremote" or "IRMP" library.
|
||||
* Install it under "Tools -> Manage Libraries..." or "Ctrl+Shift+I"
|
||||
*
|
||||
* The IR library calls a callback function, which executes a non blocking command directly in ISR (Interrupt Service Routine) context!
|
||||
* A blocking command is stored and sets a stop flag for an already running blocking function to terminate.
|
||||
* The blocking command can in turn be executed by main loop by calling IRDispatcher.checkAndRunSuspendedBlockingCommands().
|
||||
*
|
||||
* Copyright (C) 2019-2024 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of ServoEasing https://github.com/ArminJo/ServoEasing.
|
||||
* This file is part of IRMP https://github.com/IRMP-org/IRMP.
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* IRCommandDispatcher is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Program behavior is modified by the following macros
|
||||
* USE_TINY_IR_RECEIVER
|
||||
* USE_IRMP_LIBRARY
|
||||
* IR_COMMAND_HAS_MORE_THAN_8_BIT
|
||||
*/
|
||||
|
||||
#ifndef _IR_COMMAND_DISPATCHER_HPP
|
||||
#define _IR_COMMAND_DISPATCHER_HPP
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "IRCommandDispatcher.h"
|
||||
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
/*
|
||||
* Enable this to see information on each call.
|
||||
* Since there should be no library which uses Serial, it should only be enabled for development purposes.
|
||||
*/
|
||||
#if defined(INFO) && !defined(LOCAL_INFO)
|
||||
#define LOCAL_INFO
|
||||
#else
|
||||
//#define LOCAL_INFO // This enables info output only for this file
|
||||
#endif
|
||||
#if defined(DEBUG) && !defined(LOCAL_DEBUG)
|
||||
#define LOCAL_DEBUG
|
||||
// Propagate debug level
|
||||
#define LOCAL_INFO
|
||||
#else
|
||||
//#define LOCAL_DEBUG // This enables debug output only for this file
|
||||
#endif
|
||||
|
||||
IRCommandDispatcher IRDispatcher;
|
||||
|
||||
#if defined(LOCAL_INFO)
|
||||
#define CD_INFO_PRINT(...) Serial.print(__VA_ARGS__);
|
||||
#define CD_INFO_PRINTLN(...) Serial.println(__VA_ARGS__);
|
||||
#else
|
||||
#define CD_INFO_PRINT(...) void();
|
||||
#define CD_INFO_PRINTLN(...) void();
|
||||
#endif
|
||||
|
||||
#if defined(USE_TINY_IR_RECEIVER)
|
||||
#define USE_CALLBACK_FOR_TINY_RECEIVER // Call the fixed function "void handleReceivedTinyIRData()" each time a frame or repeat is received.
|
||||
#include "TinyIRReceiver.hpp" // included in "IRremote" library
|
||||
|
||||
void IRCommandDispatcher::init() {
|
||||
initPCIInterruptForTinyReceiver();
|
||||
}
|
||||
|
||||
/*
|
||||
* @return true, if IR Receiver is attached
|
||||
*/
|
||||
void IRCommandDispatcher::printIRInfo(Print *aSerial) {
|
||||
aSerial->println();
|
||||
// For available IR commands see IRCommandMapping.h https://github.com/ArminJo/PWMMotorControl/blob/master/examples/SmartCarFollower/IRCommandMapping.h
|
||||
aSerial->print(F("Listening to IR remote of type "));
|
||||
aSerial->print(IR_REMOTE_NAME);
|
||||
aSerial->println(F(" at pin " STR(IR_RECEIVE_PIN)));
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the TinyReceiver callback function, which is called if a complete command was received
|
||||
* It checks for right address and then call the dispatcher
|
||||
*/
|
||||
# if defined(ESP8266) || defined(ESP32)
|
||||
IRAM_ATTR
|
||||
# endif
|
||||
void handleReceivedTinyIRData() {
|
||||
IRDispatcher.IRReceivedData.address = TinyIRReceiverData.Address;
|
||||
IRDispatcher.IRReceivedData.command = TinyIRReceiverData.Command;
|
||||
IRDispatcher.IRReceivedData.isRepeat = TinyIRReceiverData.Flags & IRDATA_FLAGS_IS_REPEAT;
|
||||
IRDispatcher.IRReceivedData.MillisOfLastCode = millis();
|
||||
|
||||
# if defined(LOCAL_INFO)
|
||||
printTinyReceiverResultMinimal(&Serial);
|
||||
# endif
|
||||
|
||||
if (TinyIRReceiverData.Address == IR_ADDRESS) { // IR_ADDRESS is defined in *IRCommandMapping.h
|
||||
IRDispatcher.IRReceivedData.isAvailable = true;
|
||||
if(!IRDispatcher.doNotUseDispatcher) {
|
||||
/*
|
||||
* Only short (non blocking) commands are executed directly in ISR (Interrupt Service Routine) context,
|
||||
* others are stored for main loop which calls checkAndRunSuspendedBlockingCommands()
|
||||
*/
|
||||
IRDispatcher.checkAndCallCommand(false);
|
||||
}
|
||||
|
||||
} else {
|
||||
CD_INFO_PRINT(F("Wrong address. Expected 0x"));
|
||||
CD_INFO_PRINTLN(IR_ADDRESS, HEX);
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(USE_IRMP_LIBRARY)
|
||||
# if !defined(IRMP_USE_COMPLETE_CALLBACK)
|
||||
# error IRMP_USE_COMPLETE_CALLBACK must be activated for IRMP library
|
||||
# endif
|
||||
|
||||
void IRCommandDispatcher::init() {
|
||||
irmp_init();
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the callback function, which is called if a complete command was received
|
||||
*/
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
IRAM_ATTR
|
||||
#endif
|
||||
void handleReceivedIRData() {
|
||||
IRMP_DATA tTeporaryData;
|
||||
irmp_get_data(&tTeporaryData);
|
||||
IRDispatcher.IRReceivedData.address = tTeporaryData.address;
|
||||
IRDispatcher.IRReceivedData.command = tTeporaryData.command;
|
||||
IRDispatcher.IRReceivedData.isRepeat = tTeporaryData.flags & IRMP_FLAG_REPETITION;
|
||||
IRDispatcher.IRReceivedData.MillisOfLastCode = millis();
|
||||
|
||||
CD_INFO_PRINT(F("A=0x"));
|
||||
CD_INFO_PRINT(IRDispatcher.IRReceivedData.address, HEX);
|
||||
CD_INFO_PRINT(F(" C=0x"));
|
||||
CD_INFO_PRINT(IRDispatcher.IRReceivedData.command, HEX);
|
||||
if (IRDispatcher.IRReceivedData.isRepeat) {
|
||||
CD_INFO_PRINT(F("R"));
|
||||
}
|
||||
CD_INFO_PRINTLN();
|
||||
|
||||
// To enable delay() for commands
|
||||
# if !defined(ARDUINO_ARCH_MBED)
|
||||
interrupts(); // be careful with always executable commands which lasts longer than the IR repeat duration.
|
||||
# endif
|
||||
|
||||
if (IRDispatcher.IRReceivedData.address == IR_ADDRESS) {
|
||||
IRDispatcher.checkAndCallCommand(true);
|
||||
} else {
|
||||
CD_INFO_PRINT(F("Wrong address. Expected 0x"));
|
||||
CD_INFO_PRINTLN(IR_ADDRESS, HEX);
|
||||
}
|
||||
}
|
||||
#endif // elif defined(USE_IRMP_LIBRARY)
|
||||
|
||||
/*
|
||||
* The main dispatcher function called by IR-ISR, main loop and checkAndRunSuspendedBlockingCommands()
|
||||
* Non blocking commands are executed directly, blocking commands are executed if enabled by parameter and no other command is just running.
|
||||
* Otherwise request to stop (requestToStopReceived) is set and command is stored for main loop to be later execute by checkAndRunSuspendedBlockingCommands().
|
||||
* Sets flags justCalledRegularIRCommand, executingBlockingCommand, requestToStopReceived
|
||||
* @param aCallBlockingCommandImmediately Run blocking command directly, if no other command is just running. Should be false if called by ISR in order not to block ISR.
|
||||
*/
|
||||
void IRCommandDispatcher::checkAndCallCommand(bool aCallBlockingCommandImmediately) {
|
||||
if (IRReceivedData.command == COMMAND_EMPTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Search for command in Array of IRToCommandMappingStruct
|
||||
*/
|
||||
for (uint_fast8_t i = 0; i < sizeof(IRMapping) / sizeof(struct IRToCommandMappingStruct); ++i) {
|
||||
if (IRReceivedData.command == IRMapping[i].IRCode) {
|
||||
/*
|
||||
* Command found
|
||||
*/
|
||||
#if defined(LOCAL_INFO)
|
||||
const __FlashStringHelper *tCommandName = reinterpret_cast<const __FlashStringHelper*>(IRMapping[i].CommandString);
|
||||
#endif
|
||||
/*
|
||||
* Check for repeat and if repeat is allowed for the current command
|
||||
*/
|
||||
if (IRReceivedData.isRepeat && !(IRMapping[i].Flags & IR_COMMAND_FLAG_REPEATABLE)) {
|
||||
#if defined(LOCAL_DEBUG)
|
||||
Serial.print(F("Repeats of command \""));
|
||||
Serial.print(tCommandName);
|
||||
Serial.println("\" not accepted");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do not accept recursive call of the same command
|
||||
*/
|
||||
if (currentBlockingCommandCalled == IRReceivedData.command) {
|
||||
#if defined(LOCAL_DEBUG)
|
||||
Serial.print(F("Recursive command \""));
|
||||
Serial.print(tCommandName);
|
||||
Serial.println("\" not accepted");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute commands
|
||||
*/
|
||||
bool tIsNonBlockingCommand = (IRMapping[i].Flags & IR_COMMAND_FLAG_NON_BLOCKING);
|
||||
if (tIsNonBlockingCommand) {
|
||||
// short command here, just call
|
||||
CD_INFO_PRINT(F("Run non blocking command: "));
|
||||
CD_INFO_PRINTLN(tCommandName);
|
||||
#if defined(BUZZER_PIN) && defined(USE_TINY_IR_RECEIVER)
|
||||
/*
|
||||
* Do (non blocking) buzzer feedback before command is executed
|
||||
*/
|
||||
if(IRMapping[i].Flags & IR_COMMAND_FLAG_BEEP) {
|
||||
tone(BUZZER_PIN, 2200, 50);
|
||||
}
|
||||
#endif
|
||||
IRMapping[i].CommandToCall();
|
||||
} else {
|
||||
/*
|
||||
* Blocking command here
|
||||
*/
|
||||
if (aCallBlockingCommandImmediately && currentBlockingCommandCalled == COMMAND_EMPTY) {
|
||||
/*
|
||||
* Here no blocking command was running and we are called from main loop
|
||||
*/
|
||||
requestToStopReceived = false; // Do not stop the command executed now
|
||||
justCalledBlockingCommand = true;
|
||||
currentBlockingCommandCalled = IRReceivedData.command; // set lock for recursive calls
|
||||
lastBlockingCommandCalled = IRReceivedData.command; // set history, can be evaluated by main loop
|
||||
/*
|
||||
* This call is blocking!!!
|
||||
*/
|
||||
CD_INFO_PRINT(F("Run blocking command: "));
|
||||
CD_INFO_PRINTLN(tCommandName);
|
||||
|
||||
#if defined(BUZZER_PIN) && defined(USE_TINY_IR_RECEIVER)
|
||||
/*
|
||||
* Do (non blocking) buzzer feedback before command is executed
|
||||
*/
|
||||
if(IRMapping[i].Flags & IR_COMMAND_FLAG_BEEP) {
|
||||
tone(BUZZER_PIN, 2200, 50);
|
||||
}
|
||||
#endif
|
||||
|
||||
IRMapping[i].CommandToCall();
|
||||
#if defined(TRACE)
|
||||
Serial.println(F("End of blocking command"));
|
||||
#endif
|
||||
currentBlockingCommandCalled = COMMAND_EMPTY;
|
||||
} else {
|
||||
/*
|
||||
* Called by ISR or another command still running.
|
||||
* Do not run command directly, but set request to stop to true and store command
|
||||
* for main loop to execute by checkAndRunSuspendedBlockingCommands()
|
||||
*/
|
||||
BlockingCommandToRunNext = IRReceivedData.command;
|
||||
requestToStopReceived = true; // to stop running command
|
||||
CD_INFO_PRINT(F("Requested stop and stored blocking command "));
|
||||
CD_INFO_PRINT(tCommandName);
|
||||
CD_INFO_PRINTLN(F(" as next command to run."));
|
||||
}
|
||||
}
|
||||
break; // command found
|
||||
} // if (IRReceivedData.command == IRMapping[i].IRCode)
|
||||
} // for loop
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Intended to be called from main loop
|
||||
* @return true, if command was called
|
||||
*/
|
||||
bool IRCommandDispatcher::checkAndRunSuspendedBlockingCommands() {
|
||||
/*
|
||||
* Take last rejected command and call associated function
|
||||
*/
|
||||
if (BlockingCommandToRunNext != COMMAND_EMPTY) {
|
||||
|
||||
CD_INFO_PRINT(F("Run stored command=0x"));
|
||||
CD_INFO_PRINTLN(BlockingCommandToRunNext, HEX);
|
||||
|
||||
IRReceivedData.command = BlockingCommandToRunNext;
|
||||
BlockingCommandToRunNext = COMMAND_EMPTY;
|
||||
IRReceivedData.isRepeat = false;
|
||||
requestToStopReceived = false; // Do not stop the command executed now
|
||||
checkAndCallCommand(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Not used internally
|
||||
*/
|
||||
#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT)
|
||||
void IRCommandDispatcher::setNextBlockingCommand(uint16_t aBlockingCommandToRunNext)
|
||||
#else
|
||||
void IRCommandDispatcher::setNextBlockingCommand(uint8_t aBlockingCommandToRunNext)
|
||||
#endif
|
||||
{
|
||||
CD_INFO_PRINT(F("Set next command to run to 0x"));
|
||||
CD_INFO_PRINTLN(aBlockingCommandToRunNext, HEX);
|
||||
BlockingCommandToRunNext = aBlockingCommandToRunNext;
|
||||
requestToStopReceived = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Special delay function for the IRCommandDispatcher. Returns prematurely if requestToStopReceived is set.
|
||||
* To be used in blocking functions as delay
|
||||
* @return true - as soon as stop received
|
||||
*/
|
||||
bool IRCommandDispatcher::delayAndCheckForStop(uint16_t aDelayMillis) {
|
||||
uint32_t tStartMillis = millis();
|
||||
do {
|
||||
if (requestToStopReceived) {
|
||||
return true;
|
||||
}
|
||||
} while (millis() - tStartMillis < aDelayMillis);
|
||||
return false;
|
||||
}
|
||||
|
||||
void IRCommandDispatcher::printIRCommandString(Print *aSerial) {
|
||||
for (uint_fast8_t i = 0; i < sizeof(IRMapping) / sizeof(struct IRToCommandMappingStruct); ++i) {
|
||||
if (IRReceivedData.command == IRMapping[i].IRCode) {
|
||||
aSerial->println(reinterpret_cast<const __FlashStringHelper*>(IRMapping[i].CommandString));
|
||||
return;
|
||||
}
|
||||
}
|
||||
aSerial->println(reinterpret_cast<const __FlashStringHelper*>(unknown));
|
||||
}
|
||||
|
||||
void IRCommandDispatcher::setRequestToStopReceived(bool aRequestToStopReceived) {
|
||||
requestToStopReceived = aRequestToStopReceived;
|
||||
}
|
||||
|
||||
#if defined(LOCAL_DEBUG)
|
||||
#undef LOCAL_DEBUG
|
||||
#endif
|
||||
#if defined(LOCAL_INFO)
|
||||
#undef LOCAL_INFO
|
||||
#endif
|
||||
#endif // _IR_COMMAND_DISPATCHER_HPP
|
||||
@ -0,0 +1,249 @@
|
||||
/*
|
||||
* IRDispatcherDemo.cpp
|
||||
*
|
||||
* Receives NEC IR commands and maps them to different actions by means of a mapping array.
|
||||
*
|
||||
* Copyright (C) 2020-2021 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of IRMP https://github.com/IRMP-org/IRMP.
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* IRMP is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/*
|
||||
* Choose the library to be used for IR receiving
|
||||
*/
|
||||
#define USE_TINY_IR_RECEIVER // Recommended, but only for NEC protocol!!! If disabled and IRMP_INPUT_PIN is defined, the IRMP library is used for decoding
|
||||
//#define TINY_RECEIVER_USE_ARDUINO_ATTACH_INTERRUPT // Requires additional 112 bytes program memory + 4 bytes RAM
|
||||
|
||||
//#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
|
||||
|
||||
#define IR_RECEIVE_PIN 4 // P0_1
|
||||
#define TONE_PIN 5 // P0_2
|
||||
|
||||
// Some kind of auto detect library if USE_TINY_IR_RECEIVER is deactivated
|
||||
#if !defined(USE_TINY_IR_RECEIVER)
|
||||
# if defined(IR_RECEIVE_PIN)
|
||||
#define USE_TINY_IR_RECEIVER
|
||||
# elif !defined(USE_IRMP_LIBRARY) && defined(IRMP_INPUT_PIN)
|
||||
#define USE_IRMP_LIBRARY
|
||||
# else
|
||||
#error No IR library selected
|
||||
# endif
|
||||
#endif
|
||||
|
||||
//#define NO_LED_FEEDBACK_CODE // You can set it here, before the include of IRCommandDispatcher below
|
||||
|
||||
#if defined(USE_TINY_IR_RECEIVER)
|
||||
//#define NO_LED_FEEDBACK_CODE // Activate this if you want to suppress LED feedback or if you do not have a LED. This saves 14 bytes code and 2 clock cycles per interrupt.
|
||||
|
||||
#elif defined(USE_IRMP_LIBRARY)
|
||||
/*
|
||||
* IRMP version
|
||||
*/
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IRMP_USE_COMPLETE_CALLBACK 1 // Enable callback functionality. It is required if IRMP library is used.
|
||||
|
||||
//#define IRMP_ENABLE_PIN_CHANGE_INTERRUPT // Enable interrupt functionality (not for all protocols) - requires around 376 additional bytes of program memory
|
||||
|
||||
#define IRMP_PROTOCOL_NAMES 1 // Enable protocol number mapping to protocol strings - requires some program memory. Must before #include <irmp*>
|
||||
|
||||
#define IRMP_SUPPORT_NEC_PROTOCOL 1 // this enables only one protocol
|
||||
//#define IRMP_SUPPORT_KASEIKYO_PROTOCOL 1
|
||||
|
||||
/*
|
||||
* After setting the definitions we can include the code and compile it.
|
||||
*/
|
||||
#include <irmp.hpp>
|
||||
void handleReceivedIRData();
|
||||
void irmp_tone(uint8_t _pin, unsigned int frequency, unsigned long duration);
|
||||
#endif // #if defined(USE_IRMP_LIBRARY)
|
||||
|
||||
bool doBlink = false;
|
||||
uint16_t sBlinkDelay = 200;
|
||||
|
||||
void doPrintMenu();
|
||||
void doLedOn();
|
||||
void doLedOff();
|
||||
void doIncreaseBlinkFrequency();
|
||||
void doDecreaseBlinkFrequency();
|
||||
void doStop();
|
||||
void doResetBlinkFrequency();
|
||||
void doLedBlinkStart();
|
||||
void doLedBlink20times();
|
||||
void doTone1800();
|
||||
void doTone2200();
|
||||
|
||||
/*
|
||||
* Set definitions and include IRCommandDispatcher library after the declaration of all commands to map
|
||||
*/
|
||||
#define INFO // to see some informative output
|
||||
#include "IRCommandDispatcher.h" // Only for required declarations, the library itself is included below after the definitions of the commands
|
||||
#include "DemoIRCommandMapping.h" // must be included before IRCommandDispatcher.hpp to define IR_ADDRESS and IRMapping and string "unknown".
|
||||
#include "IRCommandDispatcher.hpp"
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
// Just to know which program is running on my Arduino
|
||||
#if defined(USE_TINY_IR_RECEIVER)
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing TinyIRReceiver"));
|
||||
#elif defined(USE_IRREMOTE_LIBRARY)
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing IRremote library version " VERSION_IRREMOTE));
|
||||
#elif defined(USE_IRMP_LIBRARY)
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing IRMP library version " VERSION_IRMP));
|
||||
#endif
|
||||
|
||||
// play feedback tone before setup, since it kills the IR timer settings
|
||||
tone(TONE_PIN, 1000, 50);
|
||||
delay(50);
|
||||
|
||||
IRDispatcher.init(); // This just calls irmp_init()
|
||||
#if defined(USE_TINY_IR_RECEIVER)
|
||||
Serial.println(F("Ready to receive NEC IR signals at pin " STR(IR_RECEIVE_PIN)));
|
||||
#else
|
||||
irmp_register_complete_callback_function(&handleReceivedIRData); // fixed function in IRCommandDispatcher.hpp
|
||||
|
||||
Serial.print(F("Ready to receive IR signals of protocols: "));
|
||||
irmp_print_active_protocols(&Serial);
|
||||
Serial.println(F("at pin " STR(IRMP_INPUT_PIN)));
|
||||
#endif
|
||||
|
||||
Serial.print(F("Listening to commands of IR remote of type "));
|
||||
Serial.println(IR_REMOTE_NAME);
|
||||
doPrintMenu();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
IRDispatcher.checkAndRunSuspendedBlockingCommands();
|
||||
|
||||
if (doBlink) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
DELAY_AND_RETURN_IF_STOP(sBlinkDelay);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
DELAY_AND_RETURN_IF_STOP(sBlinkDelay);
|
||||
}
|
||||
|
||||
if (millis() - IRDispatcher.IRReceivedData.MillisOfLastCode > 120000) {
|
||||
//Short beep as remainder, if we did not receive any command in the last 2 minutes
|
||||
IRDispatcher.IRReceivedData.MillisOfLastCode += 120000;
|
||||
doTone1800();
|
||||
}
|
||||
|
||||
// delay(10);
|
||||
}
|
||||
|
||||
void doPrintMenu() {
|
||||
Serial.println();
|
||||
Serial.println(F("Press 1 for tone 1800 Hz"));
|
||||
Serial.println(F("Press 2 for tone 2200 Hz"));
|
||||
Serial.println(F("Press 3 for this Menu"));
|
||||
Serial.println(F("Press 0 for LED blink 20 times"));
|
||||
Serial.println(F("Press UP for LED on"));
|
||||
Serial.println(F("Press DOWN for LED off"));
|
||||
Serial.println(F("Press OK for LED blink start"));
|
||||
Serial.println(F("Press RIGHT for LED increase blink frequency"));
|
||||
Serial.println(F("Press LEFT for LED decrease blink frequency"));
|
||||
Serial.println(F("Press STAR for reset blink frequency"));
|
||||
Serial.println(F("Press HASH for stop"));
|
||||
Serial.println();
|
||||
}
|
||||
/*
|
||||
* Here the actions that are matched to IR keys
|
||||
*/
|
||||
void doLedOn() {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
doBlink = false;
|
||||
}
|
||||
void doLedOff() {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
doBlink = false;
|
||||
}
|
||||
void doIncreaseBlinkFrequency() {
|
||||
doBlink = true;
|
||||
if (sBlinkDelay > 5) {
|
||||
sBlinkDelay -= sBlinkDelay / 4;
|
||||
}
|
||||
}
|
||||
void doDecreaseBlinkFrequency() {
|
||||
doBlink = true;
|
||||
sBlinkDelay += sBlinkDelay / 4;
|
||||
}
|
||||
void doStop() {
|
||||
doBlink = false;
|
||||
}
|
||||
void doResetBlinkFrequency() {
|
||||
sBlinkDelay = 200;
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
void doLedBlinkStart() {
|
||||
doBlink = true;
|
||||
}
|
||||
/*
|
||||
* This is a blocking function and checks periodically for stop
|
||||
*/
|
||||
void doLedBlink20times() {
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
DELAY_AND_RETURN_IF_STOP(200);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
DELAY_AND_RETURN_IF_STOP(200);
|
||||
}
|
||||
}
|
||||
|
||||
void doTone1800() {
|
||||
#if defined(USE_IRMP_LIBRARY) && !defined(IRMP_ENABLE_PIN_CHANGE_INTERRUPT)
|
||||
irmp_tone(TONE_PIN, 1800, 200);
|
||||
#else
|
||||
# if !defined(ESP8266) && !defined(NRF5) // tone() stops timer 1 for ESP8266
|
||||
tone(TONE_PIN, 1800, 200);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void doTone2200() {
|
||||
#if defined(USE_IRMP_LIBRARY) && !defined(IRMP_ENABLE_PIN_CHANGE_INTERRUPT)
|
||||
// use IRMP compatible function for tone()
|
||||
irmp_tone(TONE_PIN, 2200, 50);
|
||||
#else
|
||||
# if !defined(ESP8266) && !defined(NRF5) // tone() stops timer 1 for ESP8266
|
||||
tone(TONE_PIN, 2200, 50);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(USE_IRMP_LIBRARY)
|
||||
/*
|
||||
* Convenience IRMP compatible wrapper function for Arduino tone() if IRMP_ENABLE_PIN_CHANGE_INTERRUPT is NOT activated
|
||||
* It currently disables the receiving of repeats
|
||||
*/
|
||||
void irmp_tone(uint8_t _pin, unsigned int frequency, unsigned long duration) {
|
||||
tone(_pin, frequency, duration);
|
||||
}
|
||||
#endif // #if defined(USE_IRMP_LIBRARY)
|
||||
@ -0,0 +1,349 @@
|
||||
/*
|
||||
* PinDefinitionsAndMore.h
|
||||
*
|
||||
* Contains pin definitions for IRremote examples for various platforms
|
||||
* as well as definitions for feedback LED and tone() and includes
|
||||
*
|
||||
* Copyright (C) 2021-2023 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* Arduino-IRremote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pin mapping table for different platforms
|
||||
*
|
||||
* Platform IR input IR output Tone Core/Pin schema
|
||||
* --------------------------------------------------------------
|
||||
* DEFAULT/AVR 2 3 4 Arduino
|
||||
* ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore
|
||||
* ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore
|
||||
* ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core
|
||||
* ATtiny84 |PB2 |PA4 |PA3 ATTinyCore
|
||||
* ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore
|
||||
* ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore
|
||||
* ATtiny1604 2 3|PA5 %
|
||||
* ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore
|
||||
* ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore
|
||||
* SAMD21 3 4 5
|
||||
* ESP8266 14|D5 12|D6 %
|
||||
* ESP32 15 4 27
|
||||
* ESP32-C3 2 3 4
|
||||
* BluePill PA6 PA7 PA3
|
||||
* APOLLO3 11 12 5
|
||||
* RP2040 3|GPIO15 4|GPIO16 5|GPIO17
|
||||
*/
|
||||
//#define _IR_MEASURE_TIMING // For debugging purposes.
|
||||
|
||||
#if defined(__AVR__)
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore.
|
||||
#define IR_RECEIVE_PIN PIN_PB0
|
||||
#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board.
|
||||
#define TONE_PIN PIN_PB3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB3
|
||||
|
||||
# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut"
|
||||
// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source.
|
||||
# if defined(ARDUINO_AVR_DIGISPARKPRO)
|
||||
// For use with Digispark original core
|
||||
#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9
|
||||
//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8
|
||||
#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5
|
||||
#define _IR_TIMING_TEST_PIN 10 // PA4
|
||||
# else
|
||||
// For use with ATTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8
|
||||
#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5
|
||||
# endif
|
||||
|
||||
# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
#define IR_RECEIVE_PIN PIN_PB2 // INT0
|
||||
#define IR_SEND_PIN PIN_PA4
|
||||
#define TONE_PIN PIN_PA3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PA5
|
||||
|
||||
# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
// Pin 6 is TX, pin 7 is RX
|
||||
#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1
|
||||
#define IR_SEND_PIN PIN_PD4 // 4
|
||||
#define TONE_PIN PIN_PB1 // 9
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB0 // 8
|
||||
|
||||
# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore
|
||||
// Tiny Core Dev board
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // use 18 instead of PIN_PA1 for TinyCore32
|
||||
#define IR_SEND_PIN PIN_PA2 // 19
|
||||
#define TONE_PIN PIN_PA3 // 20
|
||||
#define APPLICATION_PIN PIN_PA0 // 0
|
||||
#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32
|
||||
|
||||
# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 14
|
||||
#define IR_SEND_PIN PIN_PA1 // 16
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PB5 // 4
|
||||
|
||||
# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 8
|
||||
#define IR_SEND_PIN PIN_PA3 // 10
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
|
||||
# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN PIN_PA7 // 3
|
||||
#define APPLICATION_PIN PIN_PB2 // 5
|
||||
|
||||
#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone()
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|
||||
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|
||||
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|
||||
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|
||||
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
|
||||
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \
|
||||
|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \
|
||||
|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \
|
||||
|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 13
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc.
|
||||
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit
|
||||
// We have no built in LED at pin 13 -> reuse RX LED
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN LED_BUILTIN_RX
|
||||
# endif
|
||||
# endif // defined(__AVR_ATtiny25__)...
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4
|
||||
// To be compatible with Uno R3.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW
|
||||
#define IR_RECEIVE_PIN 14 // D5
|
||||
#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED
|
||||
#define _IR_TIMING_TEST_PIN 2 // D4
|
||||
#define APPLICATION_PIN 13 // D7
|
||||
|
||||
#define tone(...) void() // tone() inhibits receive timer
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it#
|
||||
|
||||
#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 10
|
||||
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV)
|
||||
#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working...
|
||||
#define IR_RECEIVE_PIN 6
|
||||
#define IR_SEND_PIN 7
|
||||
#define TONE_PIN 10
|
||||
#define APPLICATION_PIN 18
|
||||
|
||||
#elif defined(ESP32)
|
||||
#include <Arduino.h>
|
||||
|
||||
// tone() is included in ESP32 core since 2.0.2
|
||||
#if !defined(ESP_ARDUINO_VERSION_VAL)
|
||||
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678
|
||||
#endif
|
||||
#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer.
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
}
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
delay(aDuration);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
void noTone(uint8_t aPinNumber){
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
|
||||
#define IR_RECEIVE_PIN 15 // D15
|
||||
#define IR_SEND_PIN 4 // D4
|
||||
#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1
|
||||
#define APPLICATION_PIN 16 // RX2 pin
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill
|
||||
// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone()
|
||||
#define IR_RECEIVE_PIN PA6
|
||||
#define IR_RECEIVE_PIN_STRING "PA6"
|
||||
#define IR_SEND_PIN PA7
|
||||
#define IR_SEND_PIN_STRING "PA7"
|
||||
#define TONE_PIN PA3
|
||||
#define _IR_TIMING_TEST_PIN PA5
|
||||
#define APPLICATION_PIN PA2
|
||||
#define APPLICATION_PIN_STRING "PA2"
|
||||
# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8)
|
||||
// BluePill LED is active low
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW
|
||||
# endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards
|
||||
#define IR_RECEIVE_PIN 11
|
||||
#define IR_SEND_PIN 12
|
||||
#define TONE_PIN 5
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED
|
||||
// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect
|
||||
#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
|
||||
#define IR_SEND_PIN 4 // GPIO16
|
||||
#define TONE_PIN 5
|
||||
#define APPLICATION_PIN 6
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 8
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
|
||||
#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3)
|
||||
#define IR_SEND_PIN 16 // GPIO16
|
||||
#define TONE_PIN 17
|
||||
#define APPLICATION_PIN 18
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 20
|
||||
|
||||
// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN
|
||||
// and use the external reset with 1 kOhm to ground to enter UF2 mode
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN 6
|
||||
|
||||
#elif defined(PARTICLE) // !!!UNTESTED!!!
|
||||
#define IR_RECEIVE_PIN A4
|
||||
#define IR_SEND_PIN A5 // Particle supports multiple pins
|
||||
|
||||
#define LED_BUILTIN D7
|
||||
|
||||
/*
|
||||
* 4 times the same (default) layout for easy adaption in the future
|
||||
*/
|
||||
#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0)
|
||||
// On the Zero and others we switch explicitly to SerialUSB
|
||||
#define Serial SerialUSB
|
||||
#endif
|
||||
|
||||
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
|
||||
// Attention!!! D2 and D4 are swapped on these boards!!!
|
||||
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 24 // PB11
|
||||
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 25 // PB03
|
||||
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
|
||||
|
||||
#elif defined (NRF51) // BBC micro:bit
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define APPLICATION_PIN 1
|
||||
#define _IR_TIMING_TEST_PIN 4
|
||||
|
||||
#define tone(...) void() // no tone() available
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
#else
|
||||
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
|
||||
// Default valued for unidentified boards
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
#endif // defined(ESP8266)
|
||||
|
||||
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)
|
||||
#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation
|
||||
#else
|
||||
# if defined(SEND_PWM_BY_TIMER)
|
||||
#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (FLASHEND)
|
||||
#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* IRremoteExtensionClass.cpp
|
||||
*
|
||||
* Example for a class which itself uses the IRrecv class from IRremote
|
||||
*
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021-2024 Armin Joachimsmeyer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
/*
|
||||
* !!! The value of RAW_BUFFER_LENGTH (and some other macros) must be the same in all compile units !!!
|
||||
* Otherwise you may get warnings like "type 'struct IRData' itself violates the C++ One Definition Rule"
|
||||
*/
|
||||
#if !defined(RAW_BUFFER_LENGTH)
|
||||
// For air condition remotes it requires 750. Default is 200.
|
||||
# if (defined(RAMEND) && RAMEND <= 0x4FF) || (defined(RAMSIZE) && RAMSIZE < 0x4FF)
|
||||
#define RAW_BUFFER_LENGTH 360
|
||||
# elif (defined(RAMEND) && RAMEND <= 0x8FF) || (defined(RAMSIZE) && RAMSIZE < 0x8FF)
|
||||
#define RAW_BUFFER_LENGTH 750
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "IRremoteExtensionClass.h"
|
||||
|
||||
IRExtensionClass::IRExtensionClass(IRrecv *aIrReceiver) {
|
||||
MyIrReceiver = aIrReceiver;
|
||||
}
|
||||
bool IRExtensionClass::decode() {
|
||||
return MyIrReceiver->decode();
|
||||
}
|
||||
|
||||
bool IRExtensionClass::printIRResultShort(Print *aSerial, bool aPrintRepeatGap, bool aCheckForRecordGapsMicros) {
|
||||
return MyIrReceiver->printIRResultShort(aSerial, aPrintRepeatGap, aCheckForRecordGapsMicros);
|
||||
}
|
||||
|
||||
void IRExtensionClass::resume() {
|
||||
Serial.println(F("Call resume()"));
|
||||
MyIrReceiver->resume();
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* IRremoteExtensionClass.h
|
||||
*
|
||||
* Example for a class which itself uses the IRrecv class from IRremote
|
||||
*
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2021-2024 Armin Joachimsmeyer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
#define USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE
|
||||
#include <IRremote.hpp>
|
||||
|
||||
class IRExtensionClass
|
||||
{
|
||||
public:
|
||||
IRrecv * MyIrReceiver;
|
||||
IRExtensionClass(IRrecv * aIrReceiver);
|
||||
bool decode();
|
||||
bool printIRResultShort(Print *aSerial, bool aPrintRepeatGap = true, bool aCheckForRecordGapsMicros = true);
|
||||
void resume();
|
||||
};
|
||||
|
||||
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* IRremoteExtensionTest.cpp
|
||||
* Simple test using the IRremoteExtensionClass.
|
||||
*
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Armin Joachimsmeyer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
#if !defined(RAW_BUFFER_LENGTH)
|
||||
#define RAW_BUFFER_LENGTH 750
|
||||
#endif
|
||||
|
||||
#include <IRremote.hpp>
|
||||
|
||||
#include "IRremoteExtensionClass.h"
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
|
||||
#define IR_RECEIVE_PIN 4 // 4 P1_9
|
||||
|
||||
/*
|
||||
* Create the class, which itself uses the IRrecv class from IRremote
|
||||
*/
|
||||
IRExtensionClass IRExtension(&IrReceiver);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
// Just to know which program is running on my Arduino
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
|
||||
|
||||
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
|
||||
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
|
||||
|
||||
Serial.print(F("Ready to receive IR signals of protocols: "));
|
||||
printActiveIRProtocols(&Serial);
|
||||
Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (IRExtension.decode()) {
|
||||
IRExtension.printIRResultShort(&Serial);
|
||||
IrReceiver.printIRSendUsage(&Serial);
|
||||
IRExtension.resume(); // Use the extended function provided by IRExtension class
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
@ -0,0 +1,349 @@
|
||||
/*
|
||||
* PinDefinitionsAndMore.h
|
||||
*
|
||||
* Contains pin definitions for IRremote examples for various platforms
|
||||
* as well as definitions for feedback LED and tone() and includes
|
||||
*
|
||||
* Copyright (C) 2021-2023 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* Arduino-IRremote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pin mapping table for different platforms
|
||||
*
|
||||
* Platform IR input IR output Tone Core/Pin schema
|
||||
* --------------------------------------------------------------
|
||||
* DEFAULT/AVR 2 3 4 Arduino
|
||||
* ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore
|
||||
* ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore
|
||||
* ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core
|
||||
* ATtiny84 |PB2 |PA4 |PA3 ATTinyCore
|
||||
* ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore
|
||||
* ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore
|
||||
* ATtiny1604 2 3|PA5 %
|
||||
* ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore
|
||||
* ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore
|
||||
* SAMD21 3 4 5
|
||||
* ESP8266 14|D5 12|D6 %
|
||||
* ESP32 15 4 27
|
||||
* ESP32-C3 2 3 4
|
||||
* BluePill PA6 PA7 PA3
|
||||
* APOLLO3 11 12 5
|
||||
* RP2040 3|GPIO15 4|GPIO16 5|GPIO17
|
||||
*/
|
||||
//#define _IR_MEASURE_TIMING // For debugging purposes.
|
||||
|
||||
#if defined(__AVR__)
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore.
|
||||
#define IR_RECEIVE_PIN PIN_PB0
|
||||
#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board.
|
||||
#define TONE_PIN PIN_PB3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB3
|
||||
|
||||
# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut"
|
||||
// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source.
|
||||
# if defined(ARDUINO_AVR_DIGISPARKPRO)
|
||||
// For use with Digispark original core
|
||||
#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9
|
||||
//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8
|
||||
#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5
|
||||
#define _IR_TIMING_TEST_PIN 10 // PA4
|
||||
# else
|
||||
// For use with ATTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8
|
||||
#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5
|
||||
# endif
|
||||
|
||||
# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
#define IR_RECEIVE_PIN PIN_PB2 // INT0
|
||||
#define IR_SEND_PIN PIN_PA4
|
||||
#define TONE_PIN PIN_PA3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PA5
|
||||
|
||||
# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
// Pin 6 is TX, pin 7 is RX
|
||||
#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1
|
||||
#define IR_SEND_PIN PIN_PD4 // 4
|
||||
#define TONE_PIN PIN_PB1 // 9
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB0 // 8
|
||||
|
||||
# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore
|
||||
// Tiny Core Dev board
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // use 18 instead of PIN_PA1 for TinyCore32
|
||||
#define IR_SEND_PIN PIN_PA2 // 19
|
||||
#define TONE_PIN PIN_PA3 // 20
|
||||
#define APPLICATION_PIN PIN_PA0 // 0
|
||||
#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32
|
||||
|
||||
# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 14
|
||||
#define IR_SEND_PIN PIN_PA1 // 16
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PB5 // 4
|
||||
|
||||
# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 8
|
||||
#define IR_SEND_PIN PIN_PA3 // 10
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
|
||||
# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN PIN_PA7 // 3
|
||||
#define APPLICATION_PIN PIN_PB2 // 5
|
||||
|
||||
#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone()
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|
||||
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|
||||
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|
||||
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|
||||
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
|
||||
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \
|
||||
|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \
|
||||
|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \
|
||||
|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 13
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc.
|
||||
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit
|
||||
// We have no built in LED at pin 13 -> reuse RX LED
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN LED_BUILTIN_RX
|
||||
# endif
|
||||
# endif // defined(__AVR_ATtiny25__)...
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4
|
||||
// To be compatible with Uno R3.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW
|
||||
#define IR_RECEIVE_PIN 14 // D5
|
||||
#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED
|
||||
#define _IR_TIMING_TEST_PIN 2 // D4
|
||||
#define APPLICATION_PIN 13 // D7
|
||||
|
||||
#define tone(...) void() // tone() inhibits receive timer
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it#
|
||||
|
||||
#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 10
|
||||
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV)
|
||||
#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working...
|
||||
#define IR_RECEIVE_PIN 6
|
||||
#define IR_SEND_PIN 7
|
||||
#define TONE_PIN 10
|
||||
#define APPLICATION_PIN 18
|
||||
|
||||
#elif defined(ESP32)
|
||||
#include <Arduino.h>
|
||||
|
||||
// tone() is included in ESP32 core since 2.0.2
|
||||
#if !defined(ESP_ARDUINO_VERSION_VAL)
|
||||
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678
|
||||
#endif
|
||||
#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer.
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
}
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
delay(aDuration);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
void noTone(uint8_t aPinNumber){
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
|
||||
#define IR_RECEIVE_PIN 15 // D15
|
||||
#define IR_SEND_PIN 4 // D4
|
||||
#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1
|
||||
#define APPLICATION_PIN 16 // RX2 pin
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill
|
||||
// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone()
|
||||
#define IR_RECEIVE_PIN PA6
|
||||
#define IR_RECEIVE_PIN_STRING "PA6"
|
||||
#define IR_SEND_PIN PA7
|
||||
#define IR_SEND_PIN_STRING "PA7"
|
||||
#define TONE_PIN PA3
|
||||
#define _IR_TIMING_TEST_PIN PA5
|
||||
#define APPLICATION_PIN PA2
|
||||
#define APPLICATION_PIN_STRING "PA2"
|
||||
# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8)
|
||||
// BluePill LED is active low
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW
|
||||
# endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards
|
||||
#define IR_RECEIVE_PIN 11
|
||||
#define IR_SEND_PIN 12
|
||||
#define TONE_PIN 5
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED
|
||||
// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect
|
||||
#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
|
||||
#define IR_SEND_PIN 4 // GPIO16
|
||||
#define TONE_PIN 5
|
||||
#define APPLICATION_PIN 6
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 8
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
|
||||
#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3)
|
||||
#define IR_SEND_PIN 16 // GPIO16
|
||||
#define TONE_PIN 17
|
||||
#define APPLICATION_PIN 18
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 20
|
||||
|
||||
// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN
|
||||
// and use the external reset with 1 kOhm to ground to enter UF2 mode
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN 6
|
||||
|
||||
#elif defined(PARTICLE) // !!!UNTESTED!!!
|
||||
#define IR_RECEIVE_PIN A4
|
||||
#define IR_SEND_PIN A5 // Particle supports multiple pins
|
||||
|
||||
#define LED_BUILTIN D7
|
||||
|
||||
/*
|
||||
* 4 times the same (default) layout for easy adaption in the future
|
||||
*/
|
||||
#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0)
|
||||
// On the Zero and others we switch explicitly to SerialUSB
|
||||
#define Serial SerialUSB
|
||||
#endif
|
||||
|
||||
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
|
||||
// Attention!!! D2 and D4 are swapped on these boards!!!
|
||||
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 24 // PB11
|
||||
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 25 // PB03
|
||||
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
|
||||
|
||||
#elif defined (NRF51) // BBC micro:bit
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define APPLICATION_PIN 1
|
||||
#define _IR_TIMING_TEST_PIN 4
|
||||
|
||||
#define tone(...) void() // no tone() available
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
#else
|
||||
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
|
||||
// Default valued for unidentified boards
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
#endif // defined(ESP8266)
|
||||
|
||||
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)
|
||||
#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation
|
||||
#else
|
||||
# if defined(SEND_PWM_BY_TIMER)
|
||||
#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (FLASHEND)
|
||||
#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
244
libraries/IRremote/examples/IRremoteInfo/IRremoteInfo.ino
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* IRremote: IRremoteInfo - prints relevant config info & settings for IRremote over serial
|
||||
* Intended to help identify & troubleshoot the various settings of IRremote
|
||||
* For example, sometimes users are unsure of which pin is used for Tx or the RAW_BUFFER_LENGTH value
|
||||
* This example can be used to assist the user directly or with support.
|
||||
* Intended to help identify & troubleshoot the various settings of IRremote
|
||||
* Hopefully this utility will be a useful tool for support & troubleshooting for IRremote
|
||||
* Check out the blog post describing the sketch via http://www.analysir.com/blog/2015/11/28/helper-utility-for-troubleshooting-irremote/
|
||||
* Version 1.0 November 2015
|
||||
* Original Author: AnalysIR - IR software & modules for Makers & Pros, visit http://www.AnalysIR.com
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
//#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 240 bytes program memory if IrSender.write is used
|
||||
//#define SEND_PWM_BY_TIMER
|
||||
//#define USE_NO_SEND_PWM
|
||||
//#define NO_LED_FEEDBACK_CODE // saves 566 bytes program memory
|
||||
|
||||
#include <IRremote.hpp>
|
||||
|
||||
// Function declarations for non Arduino IDE's
|
||||
void dumpHeader();
|
||||
void dumpRAW_BUFFER_LENGTH();
|
||||
void dumpTIMER();
|
||||
void dumpTimerPin();
|
||||
void dumpClock();
|
||||
void dumpPlatform();
|
||||
void dumpPulseParams();
|
||||
void dumpSignalParams();
|
||||
void dumpArduinoIDE();
|
||||
void dumpDebugMode();
|
||||
void dumpProtocols();
|
||||
void dumpFooter();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
// Just to know which program is running on my Arduino
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
|
||||
|
||||
//Runs only once per restart of the Arduino.
|
||||
dumpHeader();
|
||||
dumpRAW_BUFFER_LENGTH();
|
||||
dumpClock();
|
||||
dumpPlatform();
|
||||
dumpPulseParams();
|
||||
dumpSignalParams();
|
||||
dumpDebugMode();
|
||||
dumpProtocols();
|
||||
dumpFooter();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//nothing to do!
|
||||
}
|
||||
|
||||
void dumpRAW_BUFFER_LENGTH() {
|
||||
Serial.print(F("RAW_BUFFER_LENGTH: "));
|
||||
Serial.println(RAW_BUFFER_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
void dumpClock() {
|
||||
#if defined(F_CPU)
|
||||
Serial.print(F("MCU Clock: "));
|
||||
Serial.println(F_CPU);
|
||||
#endif
|
||||
}
|
||||
|
||||
void dumpPlatform() {
|
||||
Serial.print(F("MCU Platform: "));
|
||||
|
||||
#if defined(MIK32V2)
|
||||
Serial.println(F("MIK32 Amur"));
|
||||
#endif
|
||||
}
|
||||
|
||||
void dumpPulseParams() {
|
||||
Serial.print(F("Mark Excess: "));
|
||||
Serial.print(MARK_EXCESS_MICROS);
|
||||
;
|
||||
Serial.println(F(" uSecs"));
|
||||
Serial.print(F("Microseconds per tick: "));
|
||||
Serial.print(MICROS_PER_TICK);
|
||||
;
|
||||
Serial.println(F(" uSecs"));
|
||||
Serial.print(F("Measurement tolerance: "));
|
||||
Serial.print(TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT);
|
||||
Serial.println(F("%"));
|
||||
}
|
||||
|
||||
void dumpSignalParams() {
|
||||
Serial.print(F("Minimum Gap between IR Signals: "));
|
||||
Serial.print(RECORD_GAP_MICROS);
|
||||
Serial.println(F(" uSecs"));
|
||||
}
|
||||
|
||||
void dumpDebugMode() {
|
||||
Serial.print(F("Debug Mode: "));
|
||||
#if DEBUG
|
||||
Serial.println(F("ON"));
|
||||
#else
|
||||
Serial.println(F("OFF (Normal)"));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void dumpProtocols() {
|
||||
|
||||
Serial.println();
|
||||
Serial.print(F("IR PROTOCOLS "));
|
||||
Serial.print(F("SEND "));
|
||||
Serial.println(F("DECODE"));
|
||||
Serial.print(F("============= "));
|
||||
Serial.print(F("======== "));
|
||||
Serial.println(F("========"));
|
||||
Serial.print(F("RC5: "));
|
||||
#if defined(DECODE_RC5)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("RC6: "));
|
||||
#if defined(DECODE_RC6)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("NEC: "));
|
||||
#if defined(DECODE_NEC)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("SONY: "));
|
||||
#if defined(DECODE_SONY)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("PANASONIC: "));
|
||||
#if defined(DECODE_PANASONIC)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("JVC: "));
|
||||
#if defined(DECODE_JVC)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("SAMSUNG: "));
|
||||
#if defined(DECODE_SAMSUNG)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("LG: "));
|
||||
#if defined(DECODE_LG)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("DENON: "));
|
||||
#if defined(DECODE_DENON)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_EXOTIC_PROTOCOLS) // saves around 2000 bytes program memory
|
||||
|
||||
Serial.print(F("BANG_OLUFSEN: "));
|
||||
#if defined(DECODE_BEO)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("BOSEWAVE: "));
|
||||
#if defined(DECODE_BOSEWAVE)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("WHYNTER: "));
|
||||
#if defined(DECODE_WHYNTER)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
|
||||
Serial.print(F("FAST: "));
|
||||
#if defined(DECODE_FAST)
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void printDecodeEnabled(int flag) {
|
||||
if (flag) {
|
||||
Serial.println(F("Enabled"));
|
||||
} else {
|
||||
Serial.println(F("Disabled"));
|
||||
}
|
||||
}
|
||||
|
||||
void dumpHeader() {
|
||||
Serial.println(F("IRremoteInfo - by AnalysIR (http://www.AnalysIR.com/)"));
|
||||
Serial.println(
|
||||
F(
|
||||
"- A helper sketch to assist in troubleshooting issues with the library by reviewing the settings within the IRremote library"));
|
||||
Serial.println(
|
||||
F(
|
||||
"- Prints out the important settings within the library, which can be configured to suit the many supported platforms"));
|
||||
Serial.println(F("- When seeking on-line support, please post or upload the output of this sketch, where appropriate"));
|
||||
Serial.println();
|
||||
Serial.println(F("IRremote Library Settings"));
|
||||
Serial.println(F("========================="));
|
||||
}
|
||||
|
||||
void dumpFooter() {
|
||||
Serial.println();
|
||||
Serial.println(F("Notes: "));
|
||||
Serial.println(F("- Most of the settings above can be configured in the following files included as part of the library"));
|
||||
Serial.println(F("- IRremoteInt.h"));
|
||||
Serial.println(F("- IRremote.h"));
|
||||
Serial.println(
|
||||
F("- You can save SRAM by disabling the Decode or Send features for any protocol (Near the top of IRremoteInt.h)"));
|
||||
}
|
||||
@ -0,0 +1,349 @@
|
||||
/*
|
||||
* PinDefinitionsAndMore.h
|
||||
*
|
||||
* Contains pin definitions for IRremote examples for various platforms
|
||||
* as well as definitions for feedback LED and tone() and includes
|
||||
*
|
||||
* Copyright (C) 2021-2023 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* Arduino-IRremote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pin mapping table for different platforms
|
||||
*
|
||||
* Platform IR input IR output Tone Core/Pin schema
|
||||
* --------------------------------------------------------------
|
||||
* DEFAULT/AVR 2 3 4 Arduino
|
||||
* ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore
|
||||
* ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore
|
||||
* ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core
|
||||
* ATtiny84 |PB2 |PA4 |PA3 ATTinyCore
|
||||
* ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore
|
||||
* ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore
|
||||
* ATtiny1604 2 3|PA5 %
|
||||
* ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore
|
||||
* ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore
|
||||
* SAMD21 3 4 5
|
||||
* ESP8266 14|D5 12|D6 %
|
||||
* ESP32 15 4 27
|
||||
* ESP32-C3 2 3 4
|
||||
* BluePill PA6 PA7 PA3
|
||||
* APOLLO3 11 12 5
|
||||
* RP2040 3|GPIO15 4|GPIO16 5|GPIO17
|
||||
*/
|
||||
//#define _IR_MEASURE_TIMING // For debugging purposes.
|
||||
|
||||
#if defined(__AVR__)
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore.
|
||||
#define IR_RECEIVE_PIN PIN_PB0
|
||||
#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board.
|
||||
#define TONE_PIN PIN_PB3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB3
|
||||
|
||||
# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut"
|
||||
// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source.
|
||||
# if defined(ARDUINO_AVR_DIGISPARKPRO)
|
||||
// For use with Digispark original core
|
||||
#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9
|
||||
//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8
|
||||
#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5
|
||||
#define _IR_TIMING_TEST_PIN 10 // PA4
|
||||
# else
|
||||
// For use with ATTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8
|
||||
#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5
|
||||
# endif
|
||||
|
||||
# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
#define IR_RECEIVE_PIN PIN_PB2 // INT0
|
||||
#define IR_SEND_PIN PIN_PA4
|
||||
#define TONE_PIN PIN_PA3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PA5
|
||||
|
||||
# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
// Pin 6 is TX, pin 7 is RX
|
||||
#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1
|
||||
#define IR_SEND_PIN PIN_PD4 // 4
|
||||
#define TONE_PIN PIN_PB1 // 9
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB0 // 8
|
||||
|
||||
# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore
|
||||
// Tiny Core Dev board
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // use 18 instead of PIN_PA1 for TinyCore32
|
||||
#define IR_SEND_PIN PIN_PA2 // 19
|
||||
#define TONE_PIN PIN_PA3 // 20
|
||||
#define APPLICATION_PIN PIN_PA0 // 0
|
||||
#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32
|
||||
|
||||
# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 14
|
||||
#define IR_SEND_PIN PIN_PA1 // 16
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PB5 // 4
|
||||
|
||||
# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 8
|
||||
#define IR_SEND_PIN PIN_PA3 // 10
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
|
||||
# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN PIN_PA7 // 3
|
||||
#define APPLICATION_PIN PIN_PB2 // 5
|
||||
|
||||
#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone()
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|
||||
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|
||||
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|
||||
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|
||||
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
|
||||
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \
|
||||
|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \
|
||||
|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \
|
||||
|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 13
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc.
|
||||
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit
|
||||
// We have no built in LED at pin 13 -> reuse RX LED
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN LED_BUILTIN_RX
|
||||
# endif
|
||||
# endif // defined(__AVR_ATtiny25__)...
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4
|
||||
// To be compatible with Uno R3.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW
|
||||
#define IR_RECEIVE_PIN 14 // D5
|
||||
#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED
|
||||
#define _IR_TIMING_TEST_PIN 2 // D4
|
||||
#define APPLICATION_PIN 13 // D7
|
||||
|
||||
#define tone(...) void() // tone() inhibits receive timer
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it#
|
||||
|
||||
#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 10
|
||||
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV)
|
||||
#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working...
|
||||
#define IR_RECEIVE_PIN 6
|
||||
#define IR_SEND_PIN 7
|
||||
#define TONE_PIN 10
|
||||
#define APPLICATION_PIN 18
|
||||
|
||||
#elif defined(ESP32)
|
||||
#include <Arduino.h>
|
||||
|
||||
// tone() is included in ESP32 core since 2.0.2
|
||||
#if !defined(ESP_ARDUINO_VERSION_VAL)
|
||||
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678
|
||||
#endif
|
||||
#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer.
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
}
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
delay(aDuration);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
void noTone(uint8_t aPinNumber){
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
|
||||
#define IR_RECEIVE_PIN 15 // D15
|
||||
#define IR_SEND_PIN 4 // D4
|
||||
#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1
|
||||
#define APPLICATION_PIN 16 // RX2 pin
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill
|
||||
// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone()
|
||||
#define IR_RECEIVE_PIN PA6
|
||||
#define IR_RECEIVE_PIN_STRING "PA6"
|
||||
#define IR_SEND_PIN PA7
|
||||
#define IR_SEND_PIN_STRING "PA7"
|
||||
#define TONE_PIN PA3
|
||||
#define _IR_TIMING_TEST_PIN PA5
|
||||
#define APPLICATION_PIN PA2
|
||||
#define APPLICATION_PIN_STRING "PA2"
|
||||
# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8)
|
||||
// BluePill LED is active low
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW
|
||||
# endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards
|
||||
#define IR_RECEIVE_PIN 11
|
||||
#define IR_SEND_PIN 12
|
||||
#define TONE_PIN 5
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED
|
||||
// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect
|
||||
#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
|
||||
#define IR_SEND_PIN 4 // GPIO16
|
||||
#define TONE_PIN 5
|
||||
#define APPLICATION_PIN 6
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 8
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
|
||||
#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3)
|
||||
#define IR_SEND_PIN 16 // GPIO16
|
||||
#define TONE_PIN 17
|
||||
#define APPLICATION_PIN 18
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 20
|
||||
|
||||
// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN
|
||||
// and use the external reset with 1 kOhm to ground to enter UF2 mode
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN 6
|
||||
|
||||
#elif defined(PARTICLE) // !!!UNTESTED!!!
|
||||
#define IR_RECEIVE_PIN A4
|
||||
#define IR_SEND_PIN A5 // Particle supports multiple pins
|
||||
|
||||
#define LED_BUILTIN D7
|
||||
|
||||
/*
|
||||
* 4 times the same (default) layout for easy adaption in the future
|
||||
*/
|
||||
#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0)
|
||||
// On the Zero and others we switch explicitly to SerialUSB
|
||||
#define Serial SerialUSB
|
||||
#endif
|
||||
|
||||
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
|
||||
// Attention!!! D2 and D4 are swapped on these boards!!!
|
||||
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 24 // PB11
|
||||
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 25 // PB03
|
||||
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
|
||||
|
||||
#elif defined (NRF51) // BBC micro:bit
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define APPLICATION_PIN 1
|
||||
#define _IR_TIMING_TEST_PIN 4
|
||||
|
||||
#define tone(...) void() // no tone() available
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
#else
|
||||
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
|
||||
// Default valued for unidentified boards
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
#endif // defined(ESP8266)
|
||||
|
||||
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)
|
||||
#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation
|
||||
#else
|
||||
# if defined(SEND_PWM_BY_TIMER)
|
||||
#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (FLASHEND)
|
||||
#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
248
libraries/IRremote/examples/ReceiveAndSend/ReceiveAndSend.ino
Normal file
@ -0,0 +1,248 @@
|
||||
/*
|
||||
* ReceiveAndSend.cpp
|
||||
*
|
||||
* Record and play back last received IR signal at button press.
|
||||
* The logic is:
|
||||
* If the button is pressed, send the IR code.
|
||||
* If an IR code is received, record it.
|
||||
* If the protocol is unknown or not enabled, store it as raw data for later sending.
|
||||
*
|
||||
* An example for simultaneous receiving and sending is in the UnitTest example.
|
||||
*
|
||||
* An IR detector/demodulator must be connected to the input IR_RECEIVE_PIN.
|
||||
*
|
||||
* A button must be connected between the input SEND_BUTTON_PIN and ground.
|
||||
* A visible LED can be connected to STATUS_PIN to provide status.
|
||||
*
|
||||
* See also https://dronebotworkshop.com/ir-remotes/#ReceiveAndSend_Code
|
||||
*
|
||||
* Initially coded 2009 Ken Shirriff http://www.righto.com
|
||||
*
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2009-2024 Ken Shirriff, Armin Joachimsmeyer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
/*
|
||||
* Specify which protocol(s) should be used for decoding.
|
||||
* If no protocol is defined, all protocols (except Bang&Olufsen) are active.
|
||||
* This must be done before the #include <IRremote.hpp>
|
||||
*/
|
||||
//#define DECODE_DENON // Includes Sharp
|
||||
//#define DECODE_JVC
|
||||
//#define DECODE_KASEIKYO
|
||||
//#define DECODE_PANASONIC // alias for DECODE_KASEIKYO
|
||||
//#define DECODE_LG
|
||||
#define DECODE_NEC // Includes Apple and Onkyo
|
||||
//#define DECODE_SAMSUNG
|
||||
//#define DECODE_SONY
|
||||
//#define DECODE_RC5
|
||||
//#define DECODE_RC6
|
||||
|
||||
//#define DECODE_BOSEWAVE
|
||||
//#define DECODE_LEGO_PF
|
||||
//#define DECODE_MAGIQUEST
|
||||
//#define DECODE_WHYNTER
|
||||
//#define DECODE_FAST
|
||||
//
|
||||
|
||||
#if !defined(RAW_BUFFER_LENGTH)
|
||||
#define RAW_BUFFER_LENGTH 750
|
||||
#endif
|
||||
|
||||
//#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory.
|
||||
//#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active
|
||||
//#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory
|
||||
//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols
|
||||
//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM.
|
||||
//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition
|
||||
|
||||
// MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding,
|
||||
// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142.
|
||||
#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules.
|
||||
|
||||
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
|
||||
|
||||
#define IR_RECEIVE_PIN 4 // P0_1
|
||||
#define IR_SEND_PIN 3 // P0_0
|
||||
|
||||
int SEND_BUTTON_PIN = BTN_BUILTIN;
|
||||
int BTN_ACTIVE_STATE = LOW; // HIGH for Elbear boards, LOW for start board
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
|
||||
#include <IRremote.hpp>
|
||||
|
||||
int DELAY_BETWEEN_REPEAT = 50;
|
||||
|
||||
// Storage for the recorded code
|
||||
struct storedIRDataStruct {
|
||||
IRData receivedIRData;
|
||||
// extensions for sendRaw
|
||||
uint8_t rawCode[RAW_BUFFER_LENGTH]; // The durations if raw
|
||||
uint8_t rawCodeLength; // The length of the code
|
||||
} sStoredIRData;
|
||||
|
||||
bool sSendButtonWasActive;
|
||||
|
||||
void storeCode();
|
||||
void sendCode(storedIRDataStruct *aIRDataToSend);
|
||||
|
||||
void setup() {
|
||||
pinMode(SEND_BUTTON_PIN, INPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
// Just to know which program is running on my Arduino
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
|
||||
|
||||
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
|
||||
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
|
||||
Serial.print(F("Ready to receive IR signals of protocols: "));
|
||||
printActiveIRProtocols(&Serial);
|
||||
Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
|
||||
|
||||
IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin
|
||||
Serial.print(F("Ready to send IR signals at pin " STR(IR_SEND_PIN) " on press of button at pin "));
|
||||
Serial.println(SEND_BUTTON_PIN);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// If button pressed, send the code.
|
||||
bool tSendButtonIsActive = (digitalRead(SEND_BUTTON_PIN) == BTN_ACTIVE_STATE); // Button pin is active LOW
|
||||
/*
|
||||
* Check for current button state
|
||||
*/
|
||||
if (tSendButtonIsActive) {
|
||||
if (!sSendButtonWasActive) {
|
||||
Serial.println(F("Stop receiving"));
|
||||
IrReceiver.stop();
|
||||
}
|
||||
/*
|
||||
* Button pressed -> send stored data
|
||||
*/
|
||||
Serial.print(F("Button pressed, now sending "));
|
||||
if (sSendButtonWasActive == tSendButtonIsActive) {
|
||||
Serial.print(F("repeat "));
|
||||
sStoredIRData.receivedIRData.flags = IRDATA_FLAGS_IS_REPEAT;
|
||||
} else {
|
||||
sStoredIRData.receivedIRData.flags = IRDATA_FLAGS_EMPTY;
|
||||
}
|
||||
Serial.flush(); // To avoid disturbing the software PWM generation by serial output interrupts
|
||||
sendCode(&sStoredIRData);
|
||||
delay(DELAY_BETWEEN_REPEAT); // Wait a bit between retransmissions
|
||||
|
||||
} else if (sSendButtonWasActive) {
|
||||
/*
|
||||
* Button is just released -> activate receiving
|
||||
*/
|
||||
// Restart receiver
|
||||
Serial.println(F("Button released -> start receiving"));
|
||||
IrReceiver.start();
|
||||
|
||||
} else if (IrReceiver.decode()) {
|
||||
/*
|
||||
* Button is not pressed and data available -> store received data and resume
|
||||
*/
|
||||
storeCode();
|
||||
IrReceiver.resume(); // resume receiver
|
||||
}
|
||||
|
||||
sSendButtonWasActive = tSendButtonIsActive;
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// Stores the code for later playback in sStoredIRData
|
||||
// Most of this code is just logging
|
||||
void storeCode() {
|
||||
if (IrReceiver.decodedIRData.rawDataPtr->rawlen < 4) {
|
||||
Serial.print(F("Ignore data with rawlen="));
|
||||
Serial.println(IrReceiver.decodedIRData.rawDataPtr->rawlen);
|
||||
return;
|
||||
}
|
||||
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) {
|
||||
Serial.println(F("Ignore repeat"));
|
||||
return;
|
||||
}
|
||||
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_AUTO_REPEAT) {
|
||||
Serial.println(F("Ignore autorepeat"));
|
||||
return;
|
||||
}
|
||||
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_PARITY_FAILED) {
|
||||
Serial.println(F("Ignore parity error"));
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Copy decoded data
|
||||
*/
|
||||
sStoredIRData.receivedIRData = IrReceiver.decodedIRData;
|
||||
|
||||
if (sStoredIRData.receivedIRData.protocol == UNKNOWN) {
|
||||
Serial.print(F("Received unknown code and store "));
|
||||
Serial.print(IrReceiver.decodedIRData.rawDataPtr->rawlen - 1);
|
||||
Serial.println(F(" timing entries as raw "));
|
||||
IrReceiver.printIRResultRawFormatted(&Serial, true); // Output the results in RAW format
|
||||
sStoredIRData.rawCodeLength = IrReceiver.decodedIRData.rawDataPtr->rawlen - 1;
|
||||
/*
|
||||
* Store the current raw data in a dedicated array for later usage
|
||||
*/
|
||||
IrReceiver.compensateAndStoreIRResultInArray(sStoredIRData.rawCode);
|
||||
} else {
|
||||
IrReceiver.printIRResultShort(&Serial);
|
||||
IrReceiver.printIRSendUsage(&Serial);
|
||||
sStoredIRData.receivedIRData.flags = 0; // clear flags -esp. repeat- for later sending
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void sendCode(storedIRDataStruct *aIRDataToSend) {
|
||||
if (aIRDataToSend->receivedIRData.protocol == UNKNOWN /* i.e. raw */) {
|
||||
// Assume 38 KHz
|
||||
IrSender.sendRaw(aIRDataToSend->rawCode, aIRDataToSend->rawCodeLength, 38);
|
||||
|
||||
Serial.print(F("raw "));
|
||||
Serial.print(aIRDataToSend->rawCodeLength);
|
||||
Serial.println(F(" marks or spaces"));
|
||||
} else {
|
||||
|
||||
/*
|
||||
* Use the write function, which does the switch for different protocols
|
||||
*/
|
||||
IrSender.write(&aIRDataToSend->receivedIRData);
|
||||
printIRResultShort(&Serial, &aIRDataToSend->receivedIRData, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,349 @@
|
||||
/*
|
||||
* PinDefinitionsAndMore.h
|
||||
*
|
||||
* Contains pin definitions for IRremote examples for various platforms
|
||||
* as well as definitions for feedback LED and tone() and includes
|
||||
*
|
||||
* Copyright (C) 2021-2023 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* Arduino-IRremote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pin mapping table for different platforms
|
||||
*
|
||||
* Platform IR input IR output Tone Core/Pin schema
|
||||
* --------------------------------------------------------------
|
||||
* DEFAULT/AVR 2 3 4 Arduino
|
||||
* ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore
|
||||
* ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore
|
||||
* ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core
|
||||
* ATtiny84 |PB2 |PA4 |PA3 ATTinyCore
|
||||
* ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore
|
||||
* ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore
|
||||
* ATtiny1604 2 3|PA5 %
|
||||
* ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore
|
||||
* ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore
|
||||
* SAMD21 3 4 5
|
||||
* ESP8266 14|D5 12|D6 %
|
||||
* ESP32 15 4 27
|
||||
* ESP32-C3 2 3 4
|
||||
* BluePill PA6 PA7 PA3
|
||||
* APOLLO3 11 12 5
|
||||
* RP2040 3|GPIO15 4|GPIO16 5|GPIO17
|
||||
*/
|
||||
//#define _IR_MEASURE_TIMING // For debugging purposes.
|
||||
|
||||
#if defined(__AVR__)
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore.
|
||||
#define IR_RECEIVE_PIN PIN_PB0
|
||||
#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board.
|
||||
#define TONE_PIN PIN_PB3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB3
|
||||
|
||||
# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut"
|
||||
// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source.
|
||||
# if defined(ARDUINO_AVR_DIGISPARKPRO)
|
||||
// For use with Digispark original core
|
||||
#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9
|
||||
//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8
|
||||
#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5
|
||||
#define _IR_TIMING_TEST_PIN 10 // PA4
|
||||
# else
|
||||
// For use with ATTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8
|
||||
#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5
|
||||
# endif
|
||||
|
||||
# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
#define IR_RECEIVE_PIN PIN_PB2 // INT0
|
||||
#define IR_SEND_PIN PIN_PA4
|
||||
#define TONE_PIN PIN_PA3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PA5
|
||||
|
||||
# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
// Pin 6 is TX, pin 7 is RX
|
||||
#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1
|
||||
#define IR_SEND_PIN PIN_PD4 // 4
|
||||
#define TONE_PIN PIN_PB1 // 9
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB0 // 8
|
||||
|
||||
# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore
|
||||
// Tiny Core Dev board
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // use 18 instead of PIN_PA1 for TinyCore32
|
||||
#define IR_SEND_PIN PIN_PA2 // 19
|
||||
#define TONE_PIN PIN_PA3 // 20
|
||||
#define APPLICATION_PIN PIN_PA0 // 0
|
||||
#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32
|
||||
|
||||
# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 14
|
||||
#define IR_SEND_PIN PIN_PA1 // 16
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PB5 // 4
|
||||
|
||||
# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 8
|
||||
#define IR_SEND_PIN PIN_PA3 // 10
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
|
||||
# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN PIN_PA7 // 3
|
||||
#define APPLICATION_PIN PIN_PB2 // 5
|
||||
|
||||
#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone()
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|
||||
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|
||||
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|
||||
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|
||||
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
|
||||
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \
|
||||
|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \
|
||||
|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \
|
||||
|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 13
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc.
|
||||
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit
|
||||
// We have no built in LED at pin 13 -> reuse RX LED
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN LED_BUILTIN_RX
|
||||
# endif
|
||||
# endif // defined(__AVR_ATtiny25__)...
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4
|
||||
// To be compatible with Uno R3.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW
|
||||
#define IR_RECEIVE_PIN 14 // D5
|
||||
#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED
|
||||
#define _IR_TIMING_TEST_PIN 2 // D4
|
||||
#define APPLICATION_PIN 13 // D7
|
||||
|
||||
#define tone(...) void() // tone() inhibits receive timer
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it#
|
||||
|
||||
#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 10
|
||||
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV)
|
||||
#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working...
|
||||
#define IR_RECEIVE_PIN 6
|
||||
#define IR_SEND_PIN 7
|
||||
#define TONE_PIN 10
|
||||
#define APPLICATION_PIN 18
|
||||
|
||||
#elif defined(ESP32)
|
||||
#include <Arduino.h>
|
||||
|
||||
// tone() is included in ESP32 core since 2.0.2
|
||||
#if !defined(ESP_ARDUINO_VERSION_VAL)
|
||||
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678
|
||||
#endif
|
||||
#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer.
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
}
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
delay(aDuration);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
void noTone(uint8_t aPinNumber){
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
|
||||
#define IR_RECEIVE_PIN 15 // D15
|
||||
#define IR_SEND_PIN 4 // D4
|
||||
#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1
|
||||
#define APPLICATION_PIN 16 // RX2 pin
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill
|
||||
// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone()
|
||||
#define IR_RECEIVE_PIN PA6
|
||||
#define IR_RECEIVE_PIN_STRING "PA6"
|
||||
#define IR_SEND_PIN PA7
|
||||
#define IR_SEND_PIN_STRING "PA7"
|
||||
#define TONE_PIN PA3
|
||||
#define _IR_TIMING_TEST_PIN PA5
|
||||
#define APPLICATION_PIN PA2
|
||||
#define APPLICATION_PIN_STRING "PA2"
|
||||
# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8)
|
||||
// BluePill LED is active low
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW
|
||||
# endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards
|
||||
#define IR_RECEIVE_PIN 11
|
||||
#define IR_SEND_PIN 12
|
||||
#define TONE_PIN 5
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED
|
||||
// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect
|
||||
#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
|
||||
#define IR_SEND_PIN 4 // GPIO16
|
||||
#define TONE_PIN 5
|
||||
#define APPLICATION_PIN 6
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 8
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
|
||||
#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3)
|
||||
#define IR_SEND_PIN 16 // GPIO16
|
||||
#define TONE_PIN 17
|
||||
#define APPLICATION_PIN 18
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 20
|
||||
|
||||
// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN
|
||||
// and use the external reset with 1 kOhm to ground to enter UF2 mode
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN 6
|
||||
|
||||
#elif defined(PARTICLE) // !!!UNTESTED!!!
|
||||
#define IR_RECEIVE_PIN A4
|
||||
#define IR_SEND_PIN A5 // Particle supports multiple pins
|
||||
|
||||
#define LED_BUILTIN D7
|
||||
|
||||
/*
|
||||
* 4 times the same (default) layout for easy adaption in the future
|
||||
*/
|
||||
#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0)
|
||||
// On the Zero and others we switch explicitly to SerialUSB
|
||||
#define Serial SerialUSB
|
||||
#endif
|
||||
|
||||
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
|
||||
// Attention!!! D2 and D4 are swapped on these boards!!!
|
||||
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 24 // PB11
|
||||
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 25 // PB03
|
||||
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
|
||||
|
||||
#elif defined (NRF51) // BBC micro:bit
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define APPLICATION_PIN 1
|
||||
#define _IR_TIMING_TEST_PIN 4
|
||||
|
||||
#define tone(...) void() // no tone() available
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
#else
|
||||
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
|
||||
// Default valued for unidentified boards
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
#endif // defined(ESP8266)
|
||||
|
||||
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)
|
||||
#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation
|
||||
#else
|
||||
# if defined(SEND_PWM_BY_TIMER)
|
||||
#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (FLASHEND)
|
||||
#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
@ -0,0 +1,191 @@
|
||||
/*
|
||||
* ReceiveAndSendDistanceWidth.cpp
|
||||
*
|
||||
* Record and play back last received distance width IR signal at button press.
|
||||
* Using DistanceWidthProtocol covers a lot of known and unknown IR protocols,
|
||||
* and requires less memory than raw protocol.
|
||||
*
|
||||
* The logic is:
|
||||
* If the button is pressed, send the IR code.
|
||||
* If an IR code is received, record it.
|
||||
*
|
||||
* An example for simultaneous receiving and sending is in the UnitTest example.
|
||||
*
|
||||
* An IR detector/demodulator must be connected to the input IR_RECEIVE_PIN.
|
||||
*
|
||||
* A button must be connected between the input SEND_BUTTON_PIN and ground.
|
||||
* A visible LED can be connected to STATUS_PIN to provide status.
|
||||
*
|
||||
* See also https://dronebotworkshop.com/ir-remotes/#ReceiveAndSendDistanceWidth_Code
|
||||
*
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Armin Joachimsmeyer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
#if !defined(IR_SEND_PIN)
|
||||
#define IR_SEND_PIN 3 // P0_0
|
||||
#endif
|
||||
|
||||
#define IR_RECEIVE_PIN 4 // P0_1
|
||||
|
||||
#define SEND_BUTTON_PIN BTN_BUILTIN
|
||||
#define BTN_ACTIVE_STATE HIGH // HIGH for Elbear boards, LOW for Start board
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Specify DistanceWidthProtocol for decoding. This must be done before the #include <IRremote.hpp>
|
||||
*/
|
||||
#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols
|
||||
//
|
||||
#if !defined(RAW_BUFFER_LENGTH)
|
||||
#define RAW_BUFFER_LENGTH 750
|
||||
#endif
|
||||
|
||||
//#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory
|
||||
//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols
|
||||
//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM.
|
||||
//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition
|
||||
|
||||
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
|
||||
|
||||
#include <IRremote.hpp>
|
||||
|
||||
#define DELAY_BETWEEN_REPEATS_MILLIS 70
|
||||
|
||||
// Storage for the recorded code, pre-filled with NEC data
|
||||
IRRawDataType sDecodedRawDataArray[RAW_DATA_ARRAY_SIZE] = { 0x7B34ED12 }; // Initialize with NEC address 0x12 and command 0x34
|
||||
DistanceWidthTimingInfoStruct sDistanceWidthTimingInfo = { 9000, 4500, 560, 1690, 560, 560 }; // Initialize with NEC timing
|
||||
uint8_t sNumberOfBits = 32;
|
||||
|
||||
bool sSendButtonWasActive;
|
||||
|
||||
void setup() {
|
||||
pinMode(SEND_BUTTON_PIN, INPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
// Just to know which program is running on my Arduino
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
|
||||
|
||||
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
|
||||
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
|
||||
Serial.println(F("Ready to receive pulse distance/width coded IR signals at pin " STR(IR_RECEIVE_PIN)));
|
||||
|
||||
IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin
|
||||
Serial.print(F("Ready to send IR signals at pin " STR(IR_SEND_PIN) " on press of button at pin "));
|
||||
Serial.println(SEND_BUTTON_PIN);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// If button pressed, send the code.
|
||||
bool tSendButtonIsActive = (digitalRead(SEND_BUTTON_PIN) == BTN_ACTIVE_STATE);
|
||||
|
||||
/*
|
||||
* Check for current button state
|
||||
*/
|
||||
if (tSendButtonIsActive) {
|
||||
if (!sSendButtonWasActive) {
|
||||
Serial.println(F("Stop receiving"));
|
||||
IrReceiver.stop();
|
||||
}
|
||||
/*
|
||||
* Button pressed -> send stored data
|
||||
*/
|
||||
Serial.print(F("Button pressed, now sending "));
|
||||
Serial.print(sNumberOfBits);
|
||||
Serial.print(F(" bits 0x"));
|
||||
Serial.print(sDecodedRawDataArray[0], HEX);
|
||||
Serial.print(F(" with sendPulseDistanceWidthFromArray timing="));
|
||||
IrReceiver.printDistanceWidthTimingInfo(&Serial, &sDistanceWidthTimingInfo);
|
||||
Serial.println();
|
||||
Serial.flush(); // To avoid disturbing the software PWM generation by serial output interrupts
|
||||
|
||||
IrSender.sendPulseDistanceWidthFromArray(38, &sDistanceWidthTimingInfo, &sDecodedRawDataArray[0], sNumberOfBits,
|
||||
#if defined(USE_MSB_DECODING_FOR_DISTANCE_DECODER)
|
||||
PROTOCOL_IS_MSB_FIRST
|
||||
#else
|
||||
PROTOCOL_IS_LSB_FIRST
|
||||
#endif
|
||||
, 100, 0);
|
||||
|
||||
delay(DELAY_BETWEEN_REPEATS_MILLIS); // Wait a bit between retransmissions
|
||||
|
||||
} else if (sSendButtonWasActive) {
|
||||
/*
|
||||
* Button is just released -> activate receiving
|
||||
*/
|
||||
// Restart receiver
|
||||
Serial.println(F("Button released -> start receiving"));
|
||||
IrReceiver.start();
|
||||
|
||||
} else if (IrReceiver.decode()) {
|
||||
/*
|
||||
* Button is not pressed and data available -> store received data and resume
|
||||
* DistanceWidthTimingInfo and sNumberOfBits should be constant for all keys of the same IR remote / protocol
|
||||
*/
|
||||
IrReceiver.printIRResultShort(&Serial);
|
||||
if (IrReceiver.decodedIRData.protocol != UNKNOWN) {
|
||||
IrReceiver.printIRSendUsage(&Serial);
|
||||
|
||||
if (memcmp(&sDistanceWidthTimingInfo, &IrReceiver.decodedIRData.DistanceWidthTimingInfo,
|
||||
sizeof(sDistanceWidthTimingInfo)) != 0) {
|
||||
Serial.print(F("Store new timing info data="));
|
||||
IrReceiver.printDistanceWidthTimingInfo(&Serial, &IrReceiver.decodedIRData.DistanceWidthTimingInfo);
|
||||
Serial.println();
|
||||
sDistanceWidthTimingInfo = IrReceiver.decodedIRData.DistanceWidthTimingInfo; // copy content here
|
||||
} else {
|
||||
Serial.print(F("Timing did not change, so we can reuse already stored timing info."));
|
||||
}
|
||||
if (sNumberOfBits != IrReceiver.decodedIRData.numberOfBits) {
|
||||
Serial.print(F("Store new numberOfBits="));
|
||||
sNumberOfBits = IrReceiver.decodedIRData.numberOfBits;
|
||||
Serial.println(IrReceiver.decodedIRData.numberOfBits);
|
||||
}
|
||||
if (sDecodedRawDataArray[0] != IrReceiver.decodedIRData.decodedRawDataArray[0]) {
|
||||
*sDecodedRawDataArray = *IrReceiver.decodedIRData.decodedRawDataArray; // copy content here
|
||||
Serial.print(F("Store new sDecodedRawDataArray[0]=0x"));
|
||||
Serial.println(IrReceiver.decodedIRData.decodedRawDataArray[0], HEX);
|
||||
}
|
||||
}
|
||||
IrReceiver.resume(); // resume receiver
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
sSendButtonWasActive = tSendButtonIsActive;
|
||||
delay(100);
|
||||
}
|
||||
@ -0,0 +1,178 @@
|
||||
START ../src/ReceiveDemo.cpp from Feb 24 2023
|
||||
Using library version 4.1.0
|
||||
Enabling IRin...
|
||||
Ready to receive IR signals of protocols: NEC/NEC2/Onkyo/Apple, Panasonic/Kaseikyo, Denon/Sharp, Sony, RC5, RC6, LG, JVC, Samsung, FAST, Whynter, Lego Power Functions, Bosewave , MagiQuest, Universal Pulse Distance Width, Hash at pin 2
|
||||
|
||||
If you connect debug pin 5 to ground, raw data is always printed
|
||||
5000 us is the (minimum) gap, after which the start of a new IR packet is assumed
|
||||
20 us are subtracted from all marks and added to all spaces for decoding
|
||||
|
||||
Protocol=NEC Address=0x2 Command=0x34 Raw-Data=0xCB34FD02 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x2, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x102, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x102, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=NEC Address=0x80 Command=0x45 Raw-Data=0xBA457F80 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x80, 0x45, <numberOfRepeats>);
|
||||
|
||||
Protocol=NEC Address=0x4 Command=0x8 Raw-Data=0xF708FB04 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x4, 0x8, <numberOfRepeats>);
|
||||
|
||||
Protocol=Onkyo Address=0x102 Command=0x304 Raw-Data=0x3040102 32 bits LSB first
|
||||
Send with: IrSender.sendOnkyo(0x102, 0x304, <numberOfRepeats>);
|
||||
|
||||
Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x102, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Panasonic Address=0xB Command=0x10 Raw-Data=0xA01000B0 48 bits LSB first
|
||||
Send with: IrSender.sendPanasonic(0xB, 0x10, <numberOfRepeats>);
|
||||
|
||||
Protocol=Panasonic Address=0xB Command=0x10 Raw-Data=0xA01000B0 48 bits LSB first
|
||||
Send with: IrSender.sendPanasonic(0xB, 0x10, <numberOfRepeats>);
|
||||
|
||||
Protocol=Panasonic Address=0xB Command=0x10 Raw-Data=0xA01000B0 48 bits LSB first
|
||||
Send with: IrSender.sendPanasonic(0xB, 0x10, <numberOfRepeats>);
|
||||
|
||||
Protocol=PulseDistance Raw-Data=0x5A 72 bits LSB first
|
||||
Send with:
|
||||
uint32_t tRawData[]={0x87654321, 0xAFEDCBA9, 0x5A};
|
||||
IrSender.sendPulseDistanceWidthFromArray(38, 8850, 4400, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, <RepeatPeriodMillis>, <numberOfRepeats>);
|
||||
|
||||
Protocol=PulseWidth Raw-Data=0xDCBA9 52 bits LSB first
|
||||
Send with:
|
||||
uint32_t tRawData[]={0x87654321, 0xDCBA9};
|
||||
IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 600, 300, 350, 600, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST, <RepeatPeriodMillis>, <numberOfRepeats>);
|
||||
|
||||
Protocol=PulseWidth Raw-Data=0x87654321 32 bits LSB first
|
||||
Send with: IrSender.sendPulseDistanceWidth(38, 1000, 500, 600, 300, 350, 300, 0x87654321, 32, PROTOCOL_IS_LSB_FIRST, <RepeatPeriodMillis>, <numberOfRepeats>);
|
||||
|
||||
Protocol=Onkyo Address=0x102 Command=0x5634 Raw-Data=0x56340102 32 bits LSB first
|
||||
Send with: IrSender.sendOnkyo(0x102, 0x5634, <numberOfRepeats>);
|
||||
|
||||
Protocol=Apple Address=0x2 Command=0x34 Raw-Data=0x23487EE 32 bits LSB first
|
||||
Send with: IrSender.sendApple(0x2, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Panasonic Address=0x102 Command=0x34 Raw-Data=0x4341020 48 bits LSB first
|
||||
Send with: IrSender.sendPanasonic(0x102, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Kaseikyo Address=0x102 Command=0x34 Extra=0x4711 Raw-Data=0x7341023 48 bits LSB first
|
||||
Send with: IrSender.sendKaseikyo(0x102, 0x34, <numberOfRepeats>, 0x4711);
|
||||
|
||||
Protocol=Kaseikyo_Denon Address=0x102 Command=0x34 Raw-Data=0x4341020 48 bits LSB first
|
||||
Send with: IrSender.sendKaseikyo_Denon(0x102, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Denon Address=0x2 Command=0x34 Raw-Data=0x682 15 bits LSB first
|
||||
Send with: IrSender.sendDenon(0x2, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Denon Address=0x2 Command=0x34 Auto-Repeat gap=45650us Raw-Data=0x7962 15 bits LSB first
|
||||
|
||||
Protocol=Sharp Address=0x2 Command=0x34 Raw-Data=0x4682 15 bits LSB first
|
||||
Send with: IrSender.sendSharp(0x2, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Sharp Address=0x2 Command=0x34 Auto-Repeat gap=46400us Raw-Data=0x3962 15 bits LSB first
|
||||
|
||||
Protocol=Sony Address=0x2 Command=0x34 Raw-Data=0x134 12 bits LSB first
|
||||
Send with: IrSender.sendSony(0x2, 0x34, 2, 12);
|
||||
|
||||
Protocol=Sony Address=0x2 Command=0x34 Raw-Data=0x134 15 bits LSB first
|
||||
Send with: IrSender.sendSony(0x2, 0x34, 2, 15);
|
||||
|
||||
Protocol=Sony Address=0x102 Command=0x34 Raw-Data=0x8134 20 bits LSB first
|
||||
Send with: IrSender.sendSony(0x102, 0x34, 2, 20);
|
||||
|
||||
Protocol=Samsung Address=0x102 Command=0x34 Raw-Data=0xCB340102 32 bits LSB first
|
||||
Send with: IrSender.sendSamsung(0x102, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Samsung Address=0x102 Command=0x5634 Raw-Data=0x56340102 32 bits LSB first
|
||||
Send with: IrSender.sendSamsung(0x102, 0x5634, <numberOfRepeats>);
|
||||
|
||||
Protocol=Samsung48 Address=0x102 Command=0x5634 Raw-Data=0xA956 48 bits LSB first
|
||||
Send with: IrSender.sendSamsung48(0x102, 0x5634, <numberOfRepeats>);
|
||||
|
||||
Protocol=RC5 Address=0x2 Command=0x34 Raw-Data=0x10B4 13 bits MSB first
|
||||
Send with: IrSender.sendRC5(0x2, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=RC5 Address=0x2 Command=0x74 Toggle=1 Raw-Data=0x8B4 13 bits MSB first
|
||||
Send with: IrSender.sendRC5(0x2, 0x74, <numberOfRepeats>);
|
||||
|
||||
Protocol=RC6 Address=0x2 Command=0x34 Raw-Data=0x234 20 bits MSB first
|
||||
Send with: IrSender.sendRC6(0x2, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Samsung Address=0x102 Command=0x34 Raw-Data=0xCB340102 32 bits LSB first
|
||||
Send with: IrSender.sendSamsung(0x102, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=JVC Address=0x2 Command=0x34 Raw-Data=0x3402 16 bits LSB first
|
||||
Send with: IrSender.sendJVC(0x2, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Samsung Address=0x102 Command=0x5634 Raw-Data=0x56340102 32 bits LSB first
|
||||
Send with: IrSender.sendSamsung(0x102, 0x5634, <numberOfRepeats>);
|
||||
|
||||
Protocol=LG Address=0x2 Command=0x5634 Raw-Data=0x256342 28 bits MSB first
|
||||
Send with: IrSender.sendLG(0x2, 0x5634, <numberOfRepeats>);
|
||||
|
||||
Protocol=MagiQuest Address=0x102 Command=0x34 Raw-Data=0x6BCD0102 56 bits MSB first
|
||||
Send with: IrSender.sendMagiQuest(0x6BCD0102, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=BoseWave Address=0x0 Command=0x34 Raw-Data=0xCB34 16 bits LSB first
|
||||
Send with: IrSender.sendBoseWave(0x0, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=FAST Address=0x0 Command=0x34 Raw-Data=0xCB34 16 bits LSB first
|
||||
Send with: IrSender.sendFAST(0x0, 0x34, <numberOfRepeats>);
|
||||
|
||||
Protocol=Lego Address=0x2 Command=0x14 Raw-Data=0x2148 16 bits MSB first
|
||||
Send with: IrSender.sendLego(0x2, 0x14, <numberOfRepeats>);
|
||||
|
||||
Protocol=Lego Address=0x2 Command=0x14 Auto-Repeat gap=180450us Raw-Data=0x2148 16 bits MSB first
|
||||
|
||||
Protocol=Lego Address=0x2 Command=0x14 Auto-Repeat gap=179350us Raw-Data=0x2148 16 bits MSB first
|
||||
|
||||
Protocol=Lego Address=0x2 Command=0x14 Auto-Repeat gap=179200us Raw-Data=0x2148 16 bits MSB first
|
||||
|
||||
Protocol=Lego Address=0x2 Command=0x14 Auto-Repeat gap=179150us Raw-Data=0x2148 16 bits MSB first
|
||||
|
||||
Overflow detected
|
||||
Try to increase the "RAW_BUFFER_LENGTH" value of 600 in ../src/ReceiveDemo.cpp
|
||||
|
||||
Protocol=NEC Address=0x3 Command=0x45 Raw-Data=0xBA45FC03 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x3, 0x45, <numberOfRepeats>);
|
||||
|
||||
Protocol=NEC Address=0x3 Command=0x45 Repeat gap=43250us
|
||||
|
||||
Protocol=NEC Address=0x203 Command=0x45 Raw-Data=0xBA450203 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x203, 0x45, <numberOfRepeats>);
|
||||
|
||||
Protocol=NEC Address=0x203 Command=0x45 Repeat gap=47550us
|
||||
|
||||
Protocol=NEC Address=0x203 Command=0x45 Raw-Data=0xBA450203 32 bits LSB first
|
||||
Send with: IrSender.sendNEC(0x203, 0x45, <numberOfRepeats>);
|
||||
|
||||
Protocol=NEC2 Address=0x203 Command=0x45 Repeat gap=46500us Raw-Data=0xBA450203 32 bits LSB first
|
||||
|
||||
Protocol=Onkyo Address=0x203 Command=0x6745 Raw-Data=0x67450203 32 bits LSB first
|
||||
Send with: IrSender.sendOnkyo(0x203, 0x6745, <numberOfRepeats>);
|
||||
|
||||
Protocol=Onkyo Address=0x203 Command=0x6745 Repeat gap=46550us
|
||||
|
||||
Protocol=Apple Address=0x3 Command=0x45 Raw-Data=0x34587EE 32 bits LSB first
|
||||
Send with: IrSender.sendApple(0x3, 0x45, <numberOfRepeats>);
|
||||
|
||||
Protocol=Apple Address=0x3 Command=0x45 Repeat gap=31550us
|
||||
|
||||
Protocol=Panasonic Address=0x203 Command=0x45 Raw-Data=0x55452030 48 bits LSB first
|
||||
Send with: IrSender.sendPanasonic(0x203, 0x45, <numberOfRepeats>);
|
||||
|
||||
Protocol=Panasonic Address=0x203 Command=0x45 Repeat gap=72550us Raw-Data=0x55452030 48 bits LSB first
|
||||
|
||||
Protocol=Kaseikyo Address=0x203 Command=0x45 Extra=0x4711 Raw-Data=0x56452033 48 bits LSB first
|
||||
Send with: IrSender.sendKaseikyo(0x203, 0x45, <numberOfRepeats>, 0x4711);
|
||||
|
||||
Protocol=Kaseikyo Address=0x203 Command=0x45 Extra=0x4711 Repeat gap=66750us Raw-Data=0x56452033 48 bits LSB first
|
||||
|
||||
Protocol=Kaseikyo_Denon Address=0x203 Command=0x45 Raw-Data=0x55452030 48 bits LSB first
|
||||
Send with: IrSender.sendKaseikyo_Denon(0x203, 0x45, <numberOfRepeats>);
|
||||
|
||||
Protocol=Kaseikyo_Denon Address=0x203 Command=0x45 Repeat gap=68300us Raw-Data=0x55452030 48 bits LSB first
|
||||
349
libraries/IRremote/examples/ReceiveDemo/PinDefinitionsAndMore.h
Normal file
@ -0,0 +1,349 @@
|
||||
/*
|
||||
* PinDefinitionsAndMore.h
|
||||
*
|
||||
* Contains pin definitions for IRremote examples for various platforms
|
||||
* as well as definitions for feedback LED and tone() and includes
|
||||
*
|
||||
* Copyright (C) 2021-2023 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* Arduino-IRremote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pin mapping table for different platforms
|
||||
*
|
||||
* Platform IR input IR output Tone Core/Pin schema
|
||||
* --------------------------------------------------------------
|
||||
* DEFAULT/AVR 2 3 4 Arduino
|
||||
* ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore
|
||||
* ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore
|
||||
* ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core
|
||||
* ATtiny84 |PB2 |PA4 |PA3 ATTinyCore
|
||||
* ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore
|
||||
* ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore
|
||||
* ATtiny1604 2 3|PA5 %
|
||||
* ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore
|
||||
* ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore
|
||||
* SAMD21 3 4 5
|
||||
* ESP8266 14|D5 12|D6 %
|
||||
* ESP32 15 4 27
|
||||
* ESP32-C3 2 3 4
|
||||
* BluePill PA6 PA7 PA3
|
||||
* APOLLO3 11 12 5
|
||||
* RP2040 3|GPIO15 4|GPIO16 5|GPIO17
|
||||
*/
|
||||
//#define _IR_MEASURE_TIMING // For debugging purposes.
|
||||
|
||||
#if defined(__AVR__)
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore.
|
||||
#define IR_RECEIVE_PIN PIN_PB0
|
||||
#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board.
|
||||
#define TONE_PIN PIN_PB3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB3
|
||||
|
||||
# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut"
|
||||
// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source.
|
||||
# if defined(ARDUINO_AVR_DIGISPARKPRO)
|
||||
// For use with Digispark original core
|
||||
#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9
|
||||
//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8
|
||||
#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5
|
||||
#define _IR_TIMING_TEST_PIN 10 // PA4
|
||||
# else
|
||||
// For use with ATTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8
|
||||
#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5
|
||||
# endif
|
||||
|
||||
# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
#define IR_RECEIVE_PIN PIN_PB2 // INT0
|
||||
#define IR_SEND_PIN PIN_PA4
|
||||
#define TONE_PIN PIN_PA3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PA5
|
||||
|
||||
# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
// Pin 6 is TX, pin 7 is RX
|
||||
#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1
|
||||
#define IR_SEND_PIN PIN_PD4 // 4
|
||||
#define TONE_PIN PIN_PB1 // 9
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB0 // 8
|
||||
|
||||
# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore
|
||||
// Tiny Core Dev board
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // use 18 instead of PIN_PA1 for TinyCore32
|
||||
#define IR_SEND_PIN PIN_PA2 // 19
|
||||
#define TONE_PIN PIN_PA3 // 20
|
||||
#define APPLICATION_PIN PIN_PA0 // 0
|
||||
#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32
|
||||
|
||||
# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 14
|
||||
#define IR_SEND_PIN PIN_PA1 // 16
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PB5 // 4
|
||||
|
||||
# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 8
|
||||
#define IR_SEND_PIN PIN_PA3 // 10
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
|
||||
# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN PIN_PA7 // 3
|
||||
#define APPLICATION_PIN PIN_PB2 // 5
|
||||
|
||||
#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone()
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|
||||
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|
||||
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|
||||
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|
||||
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
|
||||
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \
|
||||
|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \
|
||||
|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \
|
||||
|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 13
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc.
|
||||
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit
|
||||
// We have no built in LED at pin 13 -> reuse RX LED
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN LED_BUILTIN_RX
|
||||
# endif
|
||||
# endif // defined(__AVR_ATtiny25__)...
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4
|
||||
// To be compatible with Uno R3.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW
|
||||
#define IR_RECEIVE_PIN 14 // D5
|
||||
#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED
|
||||
#define _IR_TIMING_TEST_PIN 2 // D4
|
||||
#define APPLICATION_PIN 13 // D7
|
||||
|
||||
#define tone(...) void() // tone() inhibits receive timer
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it#
|
||||
|
||||
#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 10
|
||||
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV)
|
||||
#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working...
|
||||
#define IR_RECEIVE_PIN 6
|
||||
#define IR_SEND_PIN 7
|
||||
#define TONE_PIN 10
|
||||
#define APPLICATION_PIN 18
|
||||
|
||||
#elif defined(ESP32)
|
||||
#include <Arduino.h>
|
||||
|
||||
// tone() is included in ESP32 core since 2.0.2
|
||||
#if !defined(ESP_ARDUINO_VERSION_VAL)
|
||||
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678
|
||||
#endif
|
||||
#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer.
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
}
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
delay(aDuration);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
void noTone(uint8_t aPinNumber){
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
|
||||
#define IR_RECEIVE_PIN 15 // D15
|
||||
#define IR_SEND_PIN 4 // D4
|
||||
#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1
|
||||
#define APPLICATION_PIN 16 // RX2 pin
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill
|
||||
// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone()
|
||||
#define IR_RECEIVE_PIN PA6
|
||||
#define IR_RECEIVE_PIN_STRING "PA6"
|
||||
#define IR_SEND_PIN PA7
|
||||
#define IR_SEND_PIN_STRING "PA7"
|
||||
#define TONE_PIN PA3
|
||||
#define _IR_TIMING_TEST_PIN PA5
|
||||
#define APPLICATION_PIN PA2
|
||||
#define APPLICATION_PIN_STRING "PA2"
|
||||
# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8)
|
||||
// BluePill LED is active low
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW
|
||||
# endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards
|
||||
#define IR_RECEIVE_PIN 11
|
||||
#define IR_SEND_PIN 12
|
||||
#define TONE_PIN 5
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED
|
||||
// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect
|
||||
#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
|
||||
#define IR_SEND_PIN 4 // GPIO16
|
||||
#define TONE_PIN 5
|
||||
#define APPLICATION_PIN 6
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 8
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
|
||||
#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3)
|
||||
#define IR_SEND_PIN 16 // GPIO16
|
||||
#define TONE_PIN 17
|
||||
#define APPLICATION_PIN 18
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 20
|
||||
|
||||
// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN
|
||||
// and use the external reset with 1 kOhm to ground to enter UF2 mode
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN 6
|
||||
|
||||
#elif defined(PARTICLE) // !!!UNTESTED!!!
|
||||
#define IR_RECEIVE_PIN A4
|
||||
#define IR_SEND_PIN A5 // Particle supports multiple pins
|
||||
|
||||
#define LED_BUILTIN D7
|
||||
|
||||
/*
|
||||
* 4 times the same (default) layout for easy adaption in the future
|
||||
*/
|
||||
#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0)
|
||||
// On the Zero and others we switch explicitly to SerialUSB
|
||||
#define Serial SerialUSB
|
||||
#endif
|
||||
|
||||
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
|
||||
// Attention!!! D2 and D4 are swapped on these boards!!!
|
||||
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 24 // PB11
|
||||
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 25 // PB03
|
||||
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
|
||||
|
||||
#elif defined (NRF51) // BBC micro:bit
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define APPLICATION_PIN 1
|
||||
#define _IR_TIMING_TEST_PIN 4
|
||||
|
||||
#define tone(...) void() // no tone() available
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
#else
|
||||
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
|
||||
// Default valued for unidentified boards
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
#endif // defined(ESP8266)
|
||||
|
||||
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)
|
||||
#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation
|
||||
#else
|
||||
# if defined(SEND_PWM_BY_TIMER)
|
||||
#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (FLASHEND)
|
||||
#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
230
libraries/IRremote/examples/ReceiveDemo/ReceiveDemo.ino
Normal file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* ReceiveDemo.cpp
|
||||
*
|
||||
* Demonstrates receiving IR codes with the IRremote library and the use of the Arduino tone() function with this library.
|
||||
* Long press of one IR button (receiving of multiple repeats for one command) is detected.
|
||||
* If debug button is pressed (pin connected to ground) a long output is generated, which may disturb detecting of repeats.
|
||||
*
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Armin Joachimsmeyer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/*
|
||||
* Specify which protocol(s) should be used for decoding.
|
||||
* If no protocol is defined, all protocols (except Bang&Olufsen) are active.
|
||||
* This must be done before the #include <IRremote.hpp>
|
||||
*/
|
||||
//#define DECODE_DENON // Includes Sharp
|
||||
//#define DECODE_JVC
|
||||
//#define DECODE_KASEIKYO
|
||||
//#define DECODE_PANASONIC // alias for DECODE_KASEIKYO
|
||||
//#define DECODE_LG
|
||||
//#define DECODE_ONKYO // Decodes only Onkyo and not NEC or Apple
|
||||
//#define DECODE_NEC // Includes Apple and Onkyo
|
||||
//#define DECODE_SAMSUNG
|
||||
//#define DECODE_SONY
|
||||
//#define DECODE_RC5
|
||||
//#define DECODE_RC6
|
||||
//#define DECODE_BOSEWAVE
|
||||
//#define DECODE_LEGO_PF
|
||||
//#define DECODE_MAGIQUEST
|
||||
//#define DECODE_WHYNTER
|
||||
//#define DECODE_FAST
|
||||
//#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols
|
||||
//#define DECODE_HASH // special decoder for all protocols
|
||||
//#define DECODE_BEO // This protocol must always be enabled manually, i.e. it is NOT enabled if no protocol is defined. It prevents decoding of SONY!
|
||||
// etc. see IRremote.hpp
|
||||
//
|
||||
|
||||
|
||||
//#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory
|
||||
//#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory.
|
||||
//#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active
|
||||
//#define IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK // saves 32 bytes program memory
|
||||
|
||||
// MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding,
|
||||
// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142.
|
||||
//#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 40 is taken for the cheap VS1838 module her, since we have high intensity.
|
||||
|
||||
#if defined(DECODE_BEO)
|
||||
#define RECORD_GAP_MICROS 16000 // always get the complete frame in the receive buffer, but this prevents decoding of SONY!
|
||||
#endif
|
||||
//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols
|
||||
|
||||
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
|
||||
|
||||
#include <IRremote.hpp>
|
||||
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
|
||||
#define IR_RECEIVE_PIN 4 // P0_1
|
||||
|
||||
|
||||
void handleOverflow();
|
||||
bool detectLongPress(uint16_t aLongPressDurationMillis);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
// Just to know which program is running on my Arduino
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
|
||||
|
||||
// In case the interrupt driver crashes on setup, give a clue
|
||||
// to the user what's going on.
|
||||
Serial.println(F("Enabling IRin..."));
|
||||
|
||||
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
|
||||
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
|
||||
|
||||
Serial.print(F("Ready to receive IR signals of protocols: "));
|
||||
printActiveIRProtocols(&Serial);
|
||||
Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
|
||||
|
||||
Serial.print(F("FeedbackLED at pin "));
|
||||
Serial.println(LED_BUILTIN); // Works also for ESP32: static const uint8_t LED_BUILTIN = 8; #define LED_BUILTIN LED_BUILTIN
|
||||
|
||||
// infos for receive
|
||||
Serial.print(RECORD_GAP_MICROS);
|
||||
Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed"));
|
||||
Serial.print(MARK_EXCESS_MICROS);
|
||||
Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding"));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/*
|
||||
* Check if received data is available and if yes, try to decode it.
|
||||
* Decoded result is in the IrReceiver.decodedIRData structure.
|
||||
*
|
||||
* E.g. command is in IrReceiver.decodedIRData.command
|
||||
* address is in command is in IrReceiver.decodedIRData.address
|
||||
* and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
|
||||
*/
|
||||
if (IrReceiver.decode()) {
|
||||
Serial.println();
|
||||
|
||||
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
|
||||
handleOverflow();
|
||||
} else {
|
||||
/*
|
||||
* No overflow here.
|
||||
* Stop receiver, print short info and send usage and start receiver again
|
||||
*/
|
||||
|
||||
if (IrReceiver.decodedIRData.protocol == UNKNOWN)
|
||||
{
|
||||
// We have debug enabled or an unknown protocol, print extended info
|
||||
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
|
||||
Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
|
||||
}
|
||||
IrReceiver.printIRResultRawFormatted(&Serial, true);
|
||||
}
|
||||
if (IrReceiver.decodedIRData.protocol != UNKNOWN)
|
||||
{
|
||||
/*
|
||||
* The info output for a successful receive
|
||||
*/
|
||||
IrReceiver.printIRResultShort(&Serial);
|
||||
IrReceiver.printIRSendUsage(&Serial);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* !!!Important!!! Enable receiving of the next value, because receiving
|
||||
* has stopped after the end of the current received data packet.
|
||||
* Do it here, to preserve raw data for printing with printIRResultRawFormatted()
|
||||
*/
|
||||
IrReceiver.resume();
|
||||
|
||||
/*
|
||||
* Finally check the received data and perform actions according to the received address and commands
|
||||
*/
|
||||
if (IrReceiver.decodedIRData.address == 0) {
|
||||
if (IrReceiver.decodedIRData.command == 0x10) {
|
||||
// do something
|
||||
} else if (IrReceiver.decodedIRData.command == 0x11) {
|
||||
// do something else
|
||||
}
|
||||
}
|
||||
|
||||
// Check if repeats of the IR command was sent for more than 1000 ms
|
||||
if (detectLongPress(1000)) {
|
||||
Serial.print(F("Command 0x"));
|
||||
Serial.print(IrReceiver.decodedIRData.command, HEX);
|
||||
Serial.println(F(" was repeated for more than 2 seconds"));
|
||||
}
|
||||
} // if (IrReceiver.decode())
|
||||
|
||||
/*
|
||||
* Your code here
|
||||
* For all users of the FastLed library, use this code for strip.show() to improve receiving performance (which is still not 100%):
|
||||
* if (IrReceiver.isIdle()) {
|
||||
* strip.show();
|
||||
* }
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void handleOverflow() {
|
||||
Serial.println(F("Overflow detected"));
|
||||
Serial.println(F("Try to increase the \"RAW_BUFFER_LENGTH\" value of " STR(RAW_BUFFER_LENGTH) " in " __FILE__));
|
||||
// see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
|
||||
|
||||
IrReceiver.stopTimer();
|
||||
// tone(TONE_PIN, 1100, 10);
|
||||
// delay(50);
|
||||
// tone(TONE_PIN, 1100, 10);
|
||||
delay(50);
|
||||
IrReceiver.restartTimer();
|
||||
}
|
||||
|
||||
unsigned long sMillisOfFirstReceive;
|
||||
bool sLongPressJustDetected;
|
||||
/**
|
||||
* True once we received the consecutive repeats for more than aLongPressDurationMillis milliseconds.
|
||||
* The first frame, which is no repeat, is NOT counted for the duration!
|
||||
* @return true once after the repeated IR command was received for longer than aLongPressDurationMillis milliseconds, false otherwise.
|
||||
*/
|
||||
bool detectLongPress(uint16_t aLongPressDurationMillis) {
|
||||
if (!sLongPressJustDetected && (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) {
|
||||
/*
|
||||
* Here the repeat flag is set (which implies, that command is the same as the previous one)
|
||||
*/
|
||||
if (millis() - aLongPressDurationMillis > sMillisOfFirstReceive) {
|
||||
sLongPressJustDetected = true; // Long press here
|
||||
}
|
||||
} else {
|
||||
// No repeat here
|
||||
sMillisOfFirstReceive = millis();
|
||||
sLongPressJustDetected = false;
|
||||
}
|
||||
return sLongPressJustDetected; // No long press here
|
||||
}
|
||||
|
||||
349
libraries/IRremote/examples/ReceiveDump/PinDefinitionsAndMore.h
Normal file
@ -0,0 +1,349 @@
|
||||
/*
|
||||
* PinDefinitionsAndMore.h
|
||||
*
|
||||
* Contains pin definitions for IRremote examples for various platforms
|
||||
* as well as definitions for feedback LED and tone() and includes
|
||||
*
|
||||
* Copyright (C) 2021-2023 Armin Joachimsmeyer
|
||||
* armin.joachimsmeyer@gmail.com
|
||||
*
|
||||
* This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
* Arduino-IRremote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pin mapping table for different platforms
|
||||
*
|
||||
* Platform IR input IR output Tone Core/Pin schema
|
||||
* --------------------------------------------------------------
|
||||
* DEFAULT/AVR 2 3 4 Arduino
|
||||
* ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore
|
||||
* ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore
|
||||
* ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core
|
||||
* ATtiny84 |PB2 |PA4 |PA3 ATTinyCore
|
||||
* ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore
|
||||
* ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore
|
||||
* ATtiny1604 2 3|PA5 %
|
||||
* ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore
|
||||
* ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore
|
||||
* SAMD21 3 4 5
|
||||
* ESP8266 14|D5 12|D6 %
|
||||
* ESP32 15 4 27
|
||||
* ESP32-C3 2 3 4
|
||||
* BluePill PA6 PA7 PA3
|
||||
* APOLLO3 11 12 5
|
||||
* RP2040 3|GPIO15 4|GPIO16 5|GPIO17
|
||||
*/
|
||||
//#define _IR_MEASURE_TIMING // For debugging purposes.
|
||||
|
||||
#if defined(__AVR__)
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore.
|
||||
#define IR_RECEIVE_PIN PIN_PB0
|
||||
#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board.
|
||||
#define TONE_PIN PIN_PB3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB3
|
||||
|
||||
# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut"
|
||||
// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source.
|
||||
# if defined(ARDUINO_AVR_DIGISPARKPRO)
|
||||
// For use with Digispark original core
|
||||
#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9
|
||||
//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8
|
||||
#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5
|
||||
#define _IR_TIMING_TEST_PIN 10 // PA4
|
||||
# else
|
||||
// For use with ATTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards
|
||||
#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8
|
||||
#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5
|
||||
# endif
|
||||
|
||||
# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
#define IR_RECEIVE_PIN PIN_PB2 // INT0
|
||||
#define IR_SEND_PIN PIN_PA4
|
||||
#define TONE_PIN PIN_PA3
|
||||
#define _IR_TIMING_TEST_PIN PIN_PA5
|
||||
|
||||
# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore.
|
||||
#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory.
|
||||
// Pin 6 is TX, pin 7 is RX
|
||||
#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1
|
||||
#define IR_SEND_PIN PIN_PD4 // 4
|
||||
#define TONE_PIN PIN_PB1 // 9
|
||||
#define _IR_TIMING_TEST_PIN PIN_PB0 // 8
|
||||
|
||||
# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore
|
||||
// Tiny Core Dev board
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock
|
||||
// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // use 18 instead of PIN_PA1 for TinyCore32
|
||||
#define IR_SEND_PIN PIN_PA2 // 19
|
||||
#define TONE_PIN PIN_PA3 // 20
|
||||
#define APPLICATION_PIN PIN_PA0 // 0
|
||||
#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32
|
||||
|
||||
# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 14
|
||||
#define IR_SEND_PIN PIN_PA1 // 16
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output
|
||||
#define LED_BUILTIN PIN_PB5 // 4
|
||||
|
||||
# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA1 // 8
|
||||
#define IR_SEND_PIN PIN_PA3 // 10
|
||||
#define TONE_PIN PIN_PA5 // 1
|
||||
#define APPLICATION_PIN PIN_PA4 // 0
|
||||
|
||||
# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore
|
||||
#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN PIN_PA7 // 3
|
||||
#define APPLICATION_PIN PIN_PB2 // 5
|
||||
|
||||
#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone()
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \
|
||||
|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \
|
||||
|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \
|
||||
|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \
|
||||
|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \
|
||||
|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \
|
||||
|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \
|
||||
|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \
|
||||
|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 13
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc.
|
||||
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit
|
||||
// We have no built in LED at pin 13 -> reuse RX LED
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN LED_BUILTIN_RX
|
||||
# endif
|
||||
# endif // defined(__AVR_ATtiny25__)...
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4
|
||||
// To be compatible with Uno R3.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW
|
||||
#define IR_RECEIVE_PIN 14 // D5
|
||||
#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED
|
||||
#define _IR_TIMING_TEST_PIN 2 // D4
|
||||
#define APPLICATION_PIN 13 // D7
|
||||
|
||||
#define tone(...) void() // tone() inhibits receive timer
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it#
|
||||
|
||||
#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI)
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 10
|
||||
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV)
|
||||
#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working...
|
||||
#define IR_RECEIVE_PIN 6
|
||||
#define IR_SEND_PIN 7
|
||||
#define TONE_PIN 10
|
||||
#define APPLICATION_PIN 18
|
||||
|
||||
#elif defined(ESP32)
|
||||
#include <Arduino.h>
|
||||
|
||||
// tone() is included in ESP32 core since 2.0.2
|
||||
#if !defined(ESP_ARDUINO_VERSION_VAL)
|
||||
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678
|
||||
#endif
|
||||
#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer.
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
}
|
||||
void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){
|
||||
ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency);
|
||||
delay(aDuration);
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
void noTone(uint8_t aPinNumber){
|
||||
ledcWriteTone(TONE_LEDC_CHANNEL, 0);
|
||||
}
|
||||
#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2)
|
||||
|
||||
#define IR_RECEIVE_PIN 15 // D15
|
||||
#define IR_SEND_PIN 4 // D4
|
||||
#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1
|
||||
#define APPLICATION_PIN 16 // RX2 pin
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill
|
||||
// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone()
|
||||
#define IR_RECEIVE_PIN PA6
|
||||
#define IR_RECEIVE_PIN_STRING "PA6"
|
||||
#define IR_SEND_PIN PA7
|
||||
#define IR_SEND_PIN_STRING "PA7"
|
||||
#define TONE_PIN PA3
|
||||
#define _IR_TIMING_TEST_PIN PA5
|
||||
#define APPLICATION_PIN PA2
|
||||
#define APPLICATION_PIN_STRING "PA2"
|
||||
# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8)
|
||||
// BluePill LED is active low
|
||||
#define FEEDBACK_LED_IS_ACTIVE_LOW
|
||||
# endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards
|
||||
#define IR_RECEIVE_PIN 11
|
||||
#define IR_SEND_PIN 12
|
||||
#define TONE_PIN 5
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED
|
||||
// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect
|
||||
#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
|
||||
#define IR_SEND_PIN 4 // GPIO16
|
||||
#define TONE_PIN 5
|
||||
#define APPLICATION_PIN 6
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 8
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
|
||||
#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3)
|
||||
#define IR_SEND_PIN 16 // GPIO16
|
||||
#define TONE_PIN 17
|
||||
#define APPLICATION_PIN 18
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 20
|
||||
|
||||
// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN
|
||||
// and use the external reset with 1 kOhm to ground to enter UF2 mode
|
||||
#undef LED_BUILTIN
|
||||
#define LED_BUILTIN 6
|
||||
|
||||
#elif defined(PARTICLE) // !!!UNTESTED!!!
|
||||
#define IR_RECEIVE_PIN A4
|
||||
#define IR_SEND_PIN A5 // Particle supports multiple pins
|
||||
|
||||
#define LED_BUILTIN D7
|
||||
|
||||
/*
|
||||
* 4 times the same (default) layout for easy adaption in the future
|
||||
*/
|
||||
#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc.
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
|
||||
#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0)
|
||||
// On the Zero and others we switch explicitly to SerialUSB
|
||||
#define Serial SerialUSB
|
||||
#endif
|
||||
|
||||
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
|
||||
// Attention!!! D2 and D4 are swapped on these boards!!!
|
||||
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 24 // PB11
|
||||
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
|
||||
//#undef LED_BUILTIN
|
||||
//#define LED_BUILTIN 25 // PB03
|
||||
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
|
||||
|
||||
#elif defined (NRF51) // BBC micro:bit
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define APPLICATION_PIN 1
|
||||
#define _IR_TIMING_TEST_PIN 4
|
||||
|
||||
#define tone(...) void() // no tone() available
|
||||
#define noTone(a) void()
|
||||
#define TONE_PIN 42 // Dummy for examples using it
|
||||
|
||||
#else
|
||||
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
|
||||
// Default valued for unidentified boards
|
||||
#define IR_RECEIVE_PIN 2
|
||||
#define IR_SEND_PIN 3
|
||||
#define TONE_PIN 4
|
||||
#define APPLICATION_PIN 5
|
||||
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
|
||||
#define _IR_TIMING_TEST_PIN 7
|
||||
#endif // defined(ESP8266)
|
||||
|
||||
#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)
|
||||
#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation
|
||||
#else
|
||||
# if defined(SEND_PWM_BY_TIMER)
|
||||
#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (FLASHEND)
|
||||
#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
161
libraries/IRremote/examples/ReceiveDump/ReceiveDump.ino
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* ReceiveDump.cpp
|
||||
*
|
||||
* Dumps the received signal in different flavors.
|
||||
* Since the printing takes so much time (200 ms @115200 for NEC protocol, 70ms for NEC repeat),
|
||||
* repeat signals may be skipped or interpreted as UNKNOWN.
|
||||
*
|
||||
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
*
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2024 Armin Joachimsmeyer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
|
||||
// #include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
*/
|
||||
#if !defined(STR_HELPER)
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
|
||||
#define IR_RECEIVE_PIN 4 // P0_1
|
||||
|
||||
|
||||
#if !defined(RAW_BUFFER_LENGTH)
|
||||
// For air condition remotes it requires 750. Default is 200.
|
||||
#define RAW_BUFFER_LENGTH 730 // this allows usage of 16 bit raw buffer, for RECORD_GAP_MICROS > 20000
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding,
|
||||
* to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142.
|
||||
*
|
||||
* You can change this value accordingly to the receiver module you use.
|
||||
* The required value can be derived from the timings printed here.
|
||||
* Keep in mind that the timings may change with the distance
|
||||
* between sender and receiver as well as with the ambient light intensity.
|
||||
*/
|
||||
#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules.
|
||||
|
||||
//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols
|
||||
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
|
||||
|
||||
#include <IRremote.hpp>
|
||||
|
||||
//+=============================================================================
|
||||
// Configure the Arduino
|
||||
//
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.begin(9600); // Status message will be sent to PC at 9600 baud
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
// Just to know which program is running on my Arduino
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
|
||||
|
||||
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
|
||||
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
|
||||
|
||||
Serial.print(F("Ready to receive IR signals of protocols: "));
|
||||
printActiveIRProtocols(&Serial);
|
||||
Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
|
||||
|
||||
// infos for receive
|
||||
Serial.print(RECORD_GAP_MICROS);
|
||||
Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed"));
|
||||
Serial.print(MARK_EXCESS_MICROS);
|
||||
Serial.println();
|
||||
Serial.println(F("Because of the verbose output (>200 ms at 115200 baud), repeats are not dumped correctly!"));
|
||||
Serial.println();
|
||||
Serial.println(
|
||||
F(
|
||||
"If you receive protocol NEC, Samsung or LG, run also ReceiveDemo to check if your actual protocol is eventually NEC2 or SamsungLG, which is determined by the repeats"));
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
//+=============================================================================
|
||||
// The repeating section of the code
|
||||
//
|
||||
void loop() {
|
||||
if (IrReceiver.decode()) { // Grab an IR code
|
||||
// At 115200 baud, printing takes 200 ms for NEC protocol and 70 ms for NEC repeat
|
||||
Serial.println(); // blank line between entries
|
||||
Serial.println(); // 2 blank lines between entries
|
||||
IrReceiver.printIRResultShort(&Serial);
|
||||
// Check if the buffer overflowed
|
||||
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
|
||||
Serial.println(F("Try to increase the \"RAW_BUFFER_LENGTH\" value of " STR(RAW_BUFFER_LENGTH) " in " __FILE__));
|
||||
// see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
|
||||
} else {
|
||||
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
|
||||
Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
|
||||
}
|
||||
Serial.println();
|
||||
IrReceiver.printIRSendUsage(&Serial);
|
||||
Serial.println();
|
||||
Serial.println(F("Raw result in internal ticks (50 us) - with leading gap"));
|
||||
IrReceiver.printIRResultRawFormatted(&Serial, false); // Output the results in RAW format
|
||||
Serial.println(F("Raw result in microseconds - with leading gap"));
|
||||
IrReceiver.printIRResultRawFormatted(&Serial, true); // Output the results in RAW format
|
||||
Serial.println(); // blank line between entries
|
||||
Serial.print(F("Result as internal 8bit ticks (50 us) array - compensated with MARK_EXCESS_MICROS="));
|
||||
Serial.println(MARK_EXCESS_MICROS);
|
||||
IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, false); // Output the results as uint8_t source code array of ticks
|
||||
Serial.print(F("Result as microseconds array - compensated with MARK_EXCESS_MICROS="));
|
||||
Serial.println(MARK_EXCESS_MICROS);
|
||||
IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, true); // Output the results as uint16_t source code array of micros
|
||||
IrReceiver.printIRResultAsCVariables(&Serial); // Output address and data as source code variables
|
||||
Serial.println(); // blank line between entries
|
||||
|
||||
IrReceiver.compensateAndPrintIRResultAsPronto(&Serial);
|
||||
|
||||
/*
|
||||
* Example for using the compensateAndStorePronto() function.
|
||||
* Creating this String requires 2210 bytes program memory and 10 bytes RAM for the String class.
|
||||
* The String object itself requires additional 440 bytes RAM from the heap.
|
||||
* This values are for an Arduino Uno.
|
||||
*/
|
||||
// Serial.println(); // blank line between entries
|
||||
// String ProntoHEX = F("Pronto HEX contains: "); // Assign string to ProtoHex string object
|
||||
// if (int size = IrReceiver.compensateAndStorePronto(&ProntoHEX)) { // Dump the content of the IReceiver Pronto HEX to the String object
|
||||
// // Append compensateAndStorePronto() size information to the String object (requires 50 bytes heap)
|
||||
// ProntoHEX += F("\r\nProntoHEX is "); // Add codes size information to the String object
|
||||
// ProntoHEX += size;
|
||||
// ProntoHEX += F(" characters long and contains "); // Add codes count information to the String object
|
||||
// ProntoHEX += size / 5;
|
||||
// ProntoHEX += F(" codes");
|
||||
// Serial.println(ProntoHEX.c_str()); // Print to the serial console the whole String object
|
||||
// Serial.println(); // blank line between entries
|
||||
// }
|
||||
}
|
||||
IrReceiver.resume(); // Prepare for the next IR frame
|
||||
}
|
||||
}
|
||||
52
libraries/IRremote/examples/ReceiveDump/ReceiveDump.log
Normal file
@ -0,0 +1,52 @@
|
||||
START ../src/ReceiveDump.cpp from Nov 12 2022
|
||||
Using library version 4.0.0
|
||||
Ready to receive IR signals of protocols: NEC/NEC2/Onkyo/Apple, Panasonic/Kaseikyo, Denon/Sharp, Sony, RC5, RC6, LG, JVC, Samsung, Whynter, Lego Power Functions, Bosewave , MagiQuest, Universal Pulse Distance Width, Hash at pin 2
|
||||
5000 us is the (minimum) gap, after which the start of a new IR packet is assumed
|
||||
20 us are subtracted from all marks and added to all spaces for decoding
|
||||
|
||||
|
||||
Protocol=Samsung Address=0x707 Command=0x4 Raw-Data=0xFB040707 32 bits LSB first
|
||||
|
||||
Send with: IrSender.sendSamsung(0x707, 0x4, <numberOfRepeats>);
|
||||
|
||||
Raw result in internal ticks (50 us) - with leading gap
|
||||
rawData[68]:
|
||||
-27948
|
||||
+90,-84
|
||||
+12,-32 +12,-32 +12,-32 +12,-11
|
||||
+11,-11 +11,-11 +11,-11 +11,-11
|
||||
+12,-32 +12,-32 +12,-32 +12,-10
|
||||
+12,-10 +12,-10 +12,-10 +12,-11
|
||||
+11,-11 +11,-11 +11,-33 +11,-11
|
||||
+11,-11 +11,-11 +11,-11 +11,-11
|
||||
+12,-32 +12,-32 +12,-10 +12,-32
|
||||
+12,-32 +12,-32 +12,-32 +12,-32
|
||||
+12
|
||||
Sum: 1200
|
||||
Raw result in microseconds - with leading gap
|
||||
rawData[68]:
|
||||
-1397400
|
||||
+4500,-4200
|
||||
+ 600,-1600 + 600,-1600 + 600,-1600 + 600,- 550
|
||||
+ 550,- 550 + 550,- 550 + 550,- 550 + 550,- 550
|
||||
+ 600,-1600 + 600,-1600 + 600,-1600 + 600,- 500
|
||||
+ 600,- 500 + 600,- 500 + 600,- 500 + 600,- 550
|
||||
+ 550,- 550 + 550,- 550 + 550,-1650 + 550,- 550
|
||||
+ 550,- 550 + 550,- 550 + 550,- 550 + 550,- 550
|
||||
+ 600,-1600 + 600,-1600 + 600,- 500 + 600,-1600
|
||||
+ 600,-1600 + 600,-1600 + 600,-1600 + 600,-1600
|
||||
+ 600
|
||||
Sum: 60000
|
||||
|
||||
Result as internal ticks (50 us) array - compensated with MARK_EXCESS_MICROS=20
|
||||
uint8_t rawTicks[67] = {90,84, 12,32, 12,32, 12,32, 12,11, 11,11, 11,11, 11,11, 11,11, 12,32, 12,32, 12,32, 12,10, 12,10, 12,10, 12,10, 12,11, 11,11, 11,11, 11,33, 11,11, 11,11, 11,11, 11,11, 11,11, 12,32, 12,32, 12,10, 12,32, 12,32, 12,32, 12,32, 12,32, 12}; // Protocol=Samsung Address=0x707 Command=0x4 Raw-Data=0xFB040707 32 bits LSB first
|
||||
|
||||
Result as microseconds array - compensated with MARK_EXCESS_MICROS=20
|
||||
uint16_t rawData[67] = {4480,4220, 580,1620, 580,1620, 580,1620, 580,570, 530,570, 530,570, 530,570, 530,570, 580,1620, 580,1620, 580,1620, 580,520, 580,520, 580,520, 580,520, 580,570, 530,570, 530,570, 530,1670, 530,570, 530,570, 530,570, 530,570, 530,570, 580,1620, 580,1620, 580,520, 580,1620, 580,1620, 580,1620, 580,1620, 580,1620, 580}; // Protocol=Samsung Address=0x707 Command=0x4 Raw-Data=0xFB040707 32 bits LSB first
|
||||
|
||||
uint16_t address = 0x707;
|
||||
uint16_t command = 0x4;
|
||||
uint32_t data = 0xFB040707;
|
||||
|
||||
Pronto Hex as string
|
||||
char prontoData[] = "0000 006D 0022 0000 00AE 00A1 0018 003D 0018 003D 0018 003D 0018 0014 0016 0014 0016 0014 0016 0014 0016 0014 0018 003D 0018 003D 0018 003D 0018 0012 0018 0012 0018 0012 0018 0012 0018 0014 0016 0014 0016 0014 0016 003F 0016 0014 0016 0014 0016 0014 0016 0014 0016 0014 0018 003D 0018 003D 0018 0012 0018 003D 0018 003D 0018 003D 0018 003D 0018 003D 0018 06C3 ";
|
||||