forked from Elron_dev/elbear_arduino_bsp
Добавлена библиотека softSerial. Общий обработчик прерываний, а также некоторые обработчики прерываний конкретных модулей перенесены в память ram
- добавлена библиотека softwareSerial. Скорость работы до 57600 включительно и на отправку, и на прием. - в bootloader добавлена проверка контрольной суммы - добавлен файл wiringLL.h, в котором собраны некоторые макросы. Этими макросами заменены функции в местах, чувствительных к длительности выполнения кода. - общие функции обработки прерываний перенесены в ram память для увеличения скорости выполнения. Так же в память ram перенесены функции обработки прерываний модулей WInterrupt (прерывания от gpio), модуля tone, модуля softwareSerial - добавлен файл-заглушка util/delay.h, необходимый для некоторых библиотек
This commit is contained in:
parent
a7468870fc
commit
47c01383e6
@ -1,15 +1,15 @@
|
|||||||
:020000040100F9
|
:020000040100F9
|
||||||
:10000000FD62938202400100FD12E39E02FE374131
|
:10000000FD62938202400100FD12E39E02FE374131
|
||||||
:10001000000213010100B701000293810100B7152E
|
:10001000000213010100B701000293810100B7152E
|
||||||
:100020000001938505F137160001130606F4B706A3
|
:100020000001938505FF3716000113060602B70687
|
||||||
:1000300000029386060039A083A2050023A0560083
|
:1000300000029386060039A083A2050023A0560083
|
||||||
:1000400091059106E3EAC5FEB7150001938505F415
|
:1000400091059106E3EAC5FEB71500019385050207
|
||||||
:1000500037160001130606F4B7060002938606263B
|
:100050003716000113060602B7060002938606262D
|
||||||
:1000600039A083A2050023A0560091059106E3EA7A
|
:1000600039A083A2050023A0560091059106E3EA7A
|
||||||
:10007000C5FEB70500029385050337060002130687
|
:10007000C5FEB70500029385050337060002130687
|
||||||
:10008000062621A023A005009105E3EDC5FEB700DB
|
:10008000062621A023A005009105E3EDC5FEB700DB
|
||||||
:100090000001E780C00AB7000001E780C00AB7008E
|
:100090000001E780C00AB7000001E780C00AB7107E
|
||||||
:1000A0000001E780007273005010F5BF82800000ED
|
:1000A0000001E780808473005010F5BF828000005B
|
||||||
:1000B0000000000000000000000000000000000040
|
:1000B0000000000000000000000000000000000040
|
||||||
:1000C0006F004000197106C20AC40EC612C816CAD3
|
:1000C0006F004000197106C20AC40EC612C816CAD3
|
||||||
:1000D0001ACC1ECE22D026D22AD42ED632D836DA48
|
:1000D0001ACC1ECE22D026D22AD42ED632D836DA48
|
||||||
@ -32,216 +32,230 @@
|
|||||||
:1001E00027009702000096968682E78086FA96801E
|
:1001E00027009702000096968682E78086FA96801E
|
||||||
:1001F000C1171D8F3E96E374C3F8A5B7B707050076
|
:1001F000C1171D8F3E96E374C3F8A5B7B707050076
|
||||||
:100200000947D8CFB7170500938707C0984385667D
|
:100200000947D8CFB7170500938707C0984385667D
|
||||||
:1002100093860640558F98C3B71708009387074009
|
:1002100093860640558F98C398471367074098C741
|
||||||
:1002200023A0070023A2070023A407001307A008A8
|
:10022000B71708009387074023A0070023A2070001
|
||||||
:10023000D8C77D57D8CF354798C3D84F9356570165
|
:1002300023A407001307A008D8C77D57D8CF354798
|
||||||
:100240008D8AE5DE8280B71708009387074023A0D8
|
:1002400098C3D84F935657018D8AE5DE8280B71741
|
||||||
:10025000070023A2070023A4070023A607007D5759
|
:1002500008009387074023A0070023A2070023A4D8
|
||||||
:10026000D8CF23A40702B7170500938707C0984388
|
:10026000070023A607007D57D8CF23A40702B7179E
|
||||||
:10027000F1769386F63F758F98C3B7070500D84F80
|
:100270000500938707C09843F1769386F63F758F04
|
||||||
:1002800023AE07008280B71708009387074088D7FE
|
:1002800098C398471377F7BF98C7B7070500094782
|
||||||
:10029000D84F137707046DDF828037070002B71548
|
:1002900098D38280B71708009387074088D7D84F34
|
||||||
:1002A000080037460F0023200704814781469385C5
|
:1002A000137707046DDF82803707000203234704BA
|
||||||
:1002B000054013061624C84D137505020DC991CECD
|
:1002B000B706000237150800B7450F0023A406044F
|
||||||
:1002C0002320F70437470F00130707246397E7003D
|
:1002C0008147014613050540938515240328C50180
|
||||||
:1002D000B707000205472383E700B7170800938795
|
:1002D000B308F30013780802630C080205C2232256
|
||||||
:1002E0000740C8534205418182808546E9B78507AA
|
:1002E000170537470F0023A4F60413070724639765
|
||||||
:1002F000E39DC7FEFDD2B7470F0093870724232055
|
:1002F000E700B707000205472383E700B7170800A8
|
||||||
:10030000F704F9B74111B707000222C413870700A9
|
:1003000093870740C85342054181828005467DBFDF
|
||||||
:1003100006C6834667000547138407006390E6021C
|
:100310008507E39DB7FE7DD2B7470F00938707247B
|
||||||
:100320001305000F8D37B717080093870740D84F84
|
:1003200023A4F60423221705E9B7411106C622C407
|
||||||
:10033000218B09C7D84F13678700D8CF2303040048
|
:1003300026C2AA84EF00B022E1689388086A0148C7
|
||||||
:10034000B240224441018280411106C622C426C225
|
:100340008147014781460146B70520C72685379476
|
||||||
:10035000AA84EF009013E1689388086A01488147F6
|
:100350009800EF003006130414687D1419E40D456D
|
||||||
:10036000014781460146B70520C726853794980086
|
:10036000B240224492444101828085452685EF00B7
|
||||||
:10037000EF000077130414687D1419E40D45B240B2
|
:10037000702005897DF10145E5B7411122C437049C
|
||||||
:10038000224492444101828085452685EF00501128
|
:100380000002930704008C43B70700804AC0BE9563
|
||||||
:1003900005897DF10145E5B7411122C4370400020A
|
:10039000B707000223AEB70206C626C293974501EF
|
||||||
:1003A000930704008C43B70700804AC0BE95B70787
|
:1003A000130404003709000289E713058900EF00F0
|
||||||
:1003B000000223ACB70206C626C293974501130478
|
:1003B00090290C40B70400029386C4041306001071
|
||||||
:1003C00004003709000289E713058900EF00701A5D
|
:1003C00013058900EF0070231C4037070002835695
|
||||||
:1003D0000C40B70400029386440413060010130572
|
:1003D0008703938707101CC013060010B68763F4C9
|
||||||
:1003E0008900EF0050141C40370700028356470372
|
:1003E000C600930700101384C4041305F400938718
|
||||||
:1003F000938707101CC013060010B68763F4C6006D
|
:1003F00007F01306100F814513040410231CF702A5
|
||||||
:1004000093070010138444041305F400938707F046
|
:10040000913BA2851385C4043D46EF0010282320AC
|
||||||
:100410001306100F814513040410231AF7021D3B25
|
:1004100004002322040023240400231604002307DD
|
||||||
:10042000A285138544043D46EF00F0182320040004
|
:100420000400B240224492440249410182805D713D
|
||||||
:1004300023220400232404002316040023070400BD
|
:10043000130680028145280886C6293BBD47230C48
|
||||||
:10044000B240224492440249410182805D71130608
|
:10044000F1008947230EF1003ED2E1779387070838
|
||||||
:1004500080028145280886C6F539BD47230CF10086
|
:100450002C080A85231AF102E52BB64061618280DF
|
||||||
:100460008947230EF1003ED2E177938707082C08D5
|
:100460005D71A2C4370400021305840086C6A6C2CB
|
||||||
:100470000A85231AF1021923B640616182805D71F9
|
:10047000CAC0652513058400EF00807D85451305FE
|
||||||
:10048000A2C4370400021305840086C6A6C2652BE9
|
:100480008400EF00300F8D47814463E3A700AA8406
|
||||||
:1004900013058400E525894513058400EF0050000D
|
:10049000894513058400EF00F00D937725002A8627
|
||||||
:1004A0009377250085E3AA84854513058400EF0032
|
:1004A00089E7136625001376F60FA68513058400E9
|
||||||
:1004B000207F13E62400AA851376F60F1305840027
|
:1004B000EF00B00FE1689388086A0148814701475F
|
||||||
:1004C000EF007001E1689388086A0148814701479D
|
:1004C00081460146B705203813058400E525E1681B
|
||||||
:1004D00081460146B7052038130584001125E168DF
|
:1004D00038009388086A1308000285468147014660
|
||||||
:1004E00038009388086A1308000285468147014650
|
:1004E000B70599EB1305840023040100E125B71536
|
||||||
:1004F000B70599EB1305840023040100D523B71534
|
:1004F00000015146938505FD6800EF0010191309AE
|
||||||
:10050000000151469385C5EF6800EF00D00A9304BF
|
:100500008400832709006C0051463ED085473ED2C7
|
||||||
:1005100084009C406C0051463ED085473ED2681016
|
:100510006810C1673ED4EF005017B70607009C4231
|
||||||
:10052000C1673ED4EF003009B70607009C42370789
|
:100520003707F1FF7D17F98F08109CC20D2DB640DB
|
||||||
:10053000F1FF7D17F98F08109CC2812BB64026442D
|
:1005300026449644064961618280411106C6013B0A
|
||||||
:10054000964461618280411106C6F5390D3FB707B7
|
:100540000537B707008073905730B700008082905E
|
||||||
:10055000008073905730B70000808290B240410114
|
:10055000B2404101828041113707000222C406C621
|
||||||
:100560008280411106C622C426C24AC08347350094
|
:100560009307070083C76700854613040700638E5F
|
||||||
:1005700005476383E70811472A846389E7008DCF25
|
:10057000D70009476388E70023030400B240224400
|
||||||
:10058000B24022449244024941018280B7070002EE
|
:10058000410182801305000F3133B71708009387AC
|
||||||
:1005900083D7470391C30935834744000347540079
|
:100590000740D84F218B09C7D84F13678700D8CFA2
|
||||||
:1005A000E2074207BA9737070002232EF702370700
|
:1005A000693FD9BF411106C622C426C24AC083474B
|
||||||
:1005B00000022320F700E9B73709000283544903FA
|
:1005B000350005476383E70811472A846389E7000C
|
||||||
:1005C0000346050093054500370500021305450461
|
:1005C0008DCFB24022449244024941018280B70754
|
||||||
:1005D0002695EF00407E83470400BE94C204C1808C
|
:1005D000000283D7870391C34D3383474400034709
|
||||||
:1005E000231A99029307F00FE3FC97F82244B240D4
|
:1005E0005400E2074207BA97370700022320F704B6
|
||||||
:1005F0009244024941014DB33D457131B7070002B4
|
:1005F000370700022320F700E9B7370900028354C8
|
||||||
:1006000083D7470391C3493B2244B24092440249F5
|
:1006000089030346050093054500370500021305DD
|
||||||
:10061000410115BF3707000293070700B705000225
|
:10061000C5042695EF00700783470400BE94C2040A
|
||||||
:1006200003DE470083A705043716080037450F008F
|
:10062000C180231C99029307F00FE3FC97F8224442
|
||||||
:1006300037480F00B708000201438146130707003F
|
:10063000B24092440249410189B33D45A139B7070F
|
||||||
:10064000130606401305152413080824938848153B
|
:10064000000283D7870391C30D3B2244B2409244FA
|
||||||
:1006500063EEC6016304030023A0F504834767002B
|
:1006500002494101DDB53707000241119306070049
|
||||||
:10066000A9E73705000213054515E5BD81470323BA
|
:1006600003DF460026C4B704000283A2840422C626
|
||||||
:10067000C60113730302631F03008507E399A7FEF6
|
:100670003715080037040002B7480F0037430F0052
|
||||||
:10068000B7470F009387072423A0F504854723036A
|
:10068000370E00024AC28147232A04021309FFFFE2
|
||||||
:10069000F7008280E38607FF832E46023383D8006B
|
:10069000814E814681458143014801461307070089
|
||||||
:1006A00085062300D301054365B78280011122CC62
|
:1006A000130505409388182413030324130ECE1555
|
||||||
:1006B0003704000226CA4AC84EC652C406CE1304E6
|
:1006B000636FE60363850E0009462303C70089C6FE
|
||||||
:1006C0000400930400061309E00FB7090002130A9F
|
:1006C000B7060002A388F60299C1232A74026304C4
|
||||||
:1006D0000003E136834764001375F50FA303A400FC
|
:1006D000080023A4540483476700A9E73244A244D6
|
||||||
:1006E00099C30D31FDB7630F950063042503E31231
|
:1006E0001249370500021305C515410165BD814258
|
||||||
:1006F00045FF3D45493E553605052312A4003D45BD
|
:1006F0000328C50113780802631B08028502E399E9
|
||||||
:100700005936C1BF3D454136313783476400F1FB5F
|
:1007000012FF89C6B7060002A388F60299C1232A00
|
||||||
:10071000FDB7138589000D397DD11305000FCDB7C5
|
:100710007402B7470F009387072423A4F404854786
|
||||||
:10072000011106CE22CC1D333704000213058400CC
|
:100720002303F7003244A244124941018280E38A44
|
||||||
:10073000192E130584009921E1689388086A0148FD
|
:1007300062FC03284502937FF80F637D260113783E
|
||||||
:100740008147780085460146B705D9EB130584003B
|
:10074000F80FC29385453308CE002300F801050653
|
||||||
:10075000230601007126E168814701478146014671
|
:100750000548B9BFB307704093F7F70F6394FF00E4
|
||||||
:10076000B70538FF9388086A0148130584008D2E69
|
:100760008546D5B7854EEDBF011122CC4EC652C489
|
||||||
:10077000713437070002B715080037460F002320F1
|
:1007700037040002B7490F00371ADCBA26CA4AC844
|
||||||
:100780000704814781469385054013061624C84D0A
|
:1007800056C25AC006CE13040400370900029389EA
|
||||||
:100790001375050211CD85CA2320F70437470F00D2
|
:10079000F923930A0003B7040002391A370B000249
|
||||||
:1007A000130707246391E702793B01A08546C5B78B
|
:1007A000213683274904A303A40063F3F9007133BE
|
||||||
:1007B0008507E39DC7FE81CAB7470F0093870724CB
|
:1007B0008347640099C34533E5B783467400638873
|
||||||
:1007C0002320F704D5B7DD350547AA876305E50281
|
:1007C0005605930700066381F60603C704038D47A9
|
||||||
:1007D00009476300E506054591EBB7060600DC4ACC
|
:1007D000998F8E07B357FA0093F7F70F6393F606D6
|
||||||
:1007E0007D771307F73FF98FDCCA014582807D17BB
|
:1007E0009307170093F7F70F2388F4021147639DCF
|
||||||
:1007F00019EB0D4582809306004037A707001307C9
|
:1007F000E7003D45453413058B00053E29C113052F
|
||||||
:100800000712B7050500905D7D8E75D2370606008C
|
:10080000000F493C238804022322090451BF3D45BF
|
||||||
:100810005C4A7D771307F73FF98FD58F41115CCA8A
|
:100810002322090423880402B53C793405052312F8
|
||||||
:1008200002C613073006B2476359F700014541017C
|
:10082000A4003D45853CADBF3D45232209042388F6
|
||||||
:100830008280856693860680C9B7B24785073EC623
|
:1008300004028D340D3583476400B5FFDDB73D45B7
|
||||||
:10084000DDB791476307F50263EAA7008547630AAE
|
:10084000C9B723880402A9BF011106CE22CCC53640
|
||||||
:10085000F50489476309F50405458280A147E31D36
|
:100850003704000213058400C92413058400CD2E3B
|
||||||
:10086000F5FE0947094501A8FD1781EFC8D20D45DE
|
:10086000E1689388086A0148814778008546014617
|
||||||
:10087000828005470D45B7A7070093870712B70683
|
:10087000B705D9EB1305840023060100252EE16896
|
||||||
:100880000500905E798E6DD28A05C98D4111CCD25A
|
:100880009388086A01488147014781460146B705B8
|
||||||
:1008900002C613073006B247635AF700014541010B
|
:1008900038FF13058400392E9532F9350547AA87AC
|
||||||
:1008A00082801147C9BF21470145F1B7B24785078B
|
:1008A0006305E50209476300E506054591EBB706D8
|
||||||
:1008B0003EC6D5B70547AA876305E5020947630227
|
:1008B0000600DC4A7D771307F73FF98FDCCA014554
|
||||||
:1008C000E506054591EBB70606009C4A7D771307C0
|
:1008C00082807D1719EB0D4582809306004037A783
|
||||||
:1008D000F73FF98F9CCA014582807D1719EB0D45C2
|
:1008D000070013070712B7050500905D7D8E75D2DE
|
||||||
:1008E00082809306004037A7070013070712B70559
|
:1008E000370606005C4A7D771307F73FF98FD58FEF
|
||||||
:1008F0000500905D7D8E75D2370706001C4B7D7616
|
:1008F00041115CCA02C613073006B2476359F700BC
|
||||||
:100900001306F63FF18FD58F1CCB85471CCF4111C5
|
:10090000014541018280856693860680C9B7B2475A
|
||||||
:1009100002C613073006B2476359F700014541018B
|
:1009100085073EC6DDB791476307F50263EAA70086
|
||||||
:1009200082808566938606807DBFB24785073EC676
|
:100920008547630AF50489476309F5040545828014
|
||||||
:10093000DDB711C98547630DF50205458280FD17B6
|
:10093000A147E31DF5FE0947094501A8FD1781EF11
|
||||||
:1009400091EB0D4582800946B7A7070093870712F0
|
:10094000C8D20D45828005470D45B7A7070093879C
|
||||||
:10095000B7060500985E718F7DD34111C8D602C6D7
|
:100950000712B7060500905E798E6DD28A05C98DA3
|
||||||
:1009600013073006B2476357F70001454101828003
|
:100960004111CCD202C613073006B247635AF700D2
|
||||||
:100970000546D9BFB24785073EC6EDB7011126CA65
|
:100970000145410182801147C9BF21470145F1B7B7
|
||||||
:10098000B7040600DC4806CE22CC4AC84EC652C484
|
:10098000B24785073EC6D5B70547AA876305E50286
|
||||||
:1009900056C2F19BDCC89C482A89C845F19B9CC87B
|
:1009900009476302E506054591EBB70606009C4A48
|
||||||
:1009A00083C7C5012E848A07DCC883C7D5018A079F
|
:1009A0007D771307F73FF98F9CCA014582807D1739
|
||||||
:1009B0009CC8193D0C44AA8A03454400593518487F
|
:1009B00019EB0D4582809306004037A70700130707
|
||||||
:1009C000B70705002A8A98C358480850D8C3184C5E
|
:1009C0000712B7050500905D7D8E75D237070600CA
|
||||||
:1009D00098C7CD35AA894850A93F834704002A8784
|
:1009D0001C4B7D761306F63FF18FD58F1CCB8547D8
|
||||||
:1009E00093F6170089E6D44893E62600D4C893F618
|
:1009E0001CCF411102C613073006B2476359F70006
|
||||||
:1009F000270099E637060600544A93E6160054CAC3
|
:1009F0000145410182808566938606807DBFB247AE
|
||||||
:100A000093F6470099E637060600144A93E6260057
|
:100A000085073EC6DDB711C98547630DF50205456B
|
||||||
:100A100014CAA18B99E7B70606009C4A93E7170012
|
:100A10008280FD1791EB0D4582800946B7A707003C
|
||||||
:100A20009CCAF24062442320590123224901232415
|
:100A200093870712B7060500985E718F7DD3411139
|
||||||
:100A300039012326E900D244B249224A924A4A8522
|
:100A3000C8D602C613073006B2476357F700014510
|
||||||
:100A4000424905618280011106CE22CC02C402C651
|
:100A4000410182800546D9BFB24785073EC6EDB752
|
||||||
:100A50002147B707050037550800D8C705448D471B
|
:100A5000011126CAB7040600DC4806CE22CC4AC8DB
|
||||||
:100A60008A85130505803EC022C2292A3755080011
|
:100A60004EC652C456C2F19BDCC89C482A89C84570
|
||||||
:100A70009307C0038A851305058022C222C43EC0A5
|
:100A7000F19B9CC883C7C5012E848A07DCC883C745
|
||||||
:100A80001122F240624405618280411122C406C6EF
|
:100A8000D5018A079CC8193D0C44AA8A0345440035
|
||||||
:100A90002A84553F18405C4F93E707015CCF1C4404
|
:100A900059351848B70705002A8A98C3584808509E
|
||||||
:100AA0001CCB5C4085CB1C43B7061000D58F1CC304
|
:100AA000D8C3184C98C7CD35AA894850A93F834769
|
||||||
:100AB000144C5C48B240D606CE07D58F834604015D
|
:100AB00004002A8793F6170089E6D44893E62600B7
|
||||||
:100AC000C206D58F8346C4012244E206D58F1CCFCF
|
:100AC000D4C893F6270099E637060600544A93E601
|
||||||
:100AD000410182801C43B706F0FFFD16F58FC1BFB0
|
:100AD000160054CA93F6470099E637060600144AF2
|
||||||
:100AE000032305002A8E0325C30113650502232E67
|
:100AE00093E6260014CAA18B99E7B70606009C4A34
|
||||||
:100AF000A3002324C3001396260149824D8E23268A
|
:100AF00093E717009CCAF240624423205901232245
|
||||||
:100B000003012322C300139605016354060299C210
|
:100B00004901232439012326E900D244B249224A6B
|
||||||
:100B10000545B1CB01476346D700639C08020D45EC
|
:100B1000924A4A85424905618280011106CE22CC63
|
||||||
:100B200082803386E700034606000507230AC300D8
|
:100B200002C402C62147B707050037550800D8C7D9
|
||||||
:100B3000DDB799C2054505CB8147E3D0D7FE032633
|
:100B300005448D478A85130505803EC022C2292AB7
|
||||||
:100B40000E00034546013306F70085072300A60083
|
:100B4000375508009307C0038A851305058022C224
|
||||||
:100B5000EDB783270E00FD18DC4F93F70702D5DFB2
|
:100B500022C43EC01122F2406244056182804111EC
|
||||||
:100B600011656D8D11E18280B707070083C74701CA
|
:100B600022C406C62A84553F18405C4F93E707010C
|
||||||
:100B700013F585001D8D3335A00082801C4141474F
|
:100B70005CCF1C441CCB5C4085CB1C43B7061000EB
|
||||||
:100B8000D8CF8280B7470800938707402A8863043C
|
:100B8000D58F1CC3144C5C48B240D606CE07D58F17
|
||||||
:100B9000F508B7570800938707806304F50A3747BD
|
:100B900083460401C206D58F8346C4012244E2067F
|
||||||
:100BA0000800630DE50A05458280331E1F01337678
|
:100BA000D58F1CCF410182801C43B706F0FFFD1694
|
||||||
:100BB000DE0129C683A345008843139318003396AA
|
:100BB000F58FC1BF032305002A8E0325C3011365EA
|
||||||
:100BC0006F001346F6FF13F43300718D3314640085
|
:100BC0000502232EA3002324C30013962601498285
|
||||||
:100BD000418D88C3638B5302638C0302084303AEC9
|
:100BD0004D8E232603012322C3001396050163547F
|
||||||
:100BE000C500718D331E6E003365C50108C3884290
|
:100BE000060299C20545B1CB01476346D700639C15
|
||||||
:100BF000698E884533156500498E90C2850833D5C6
|
:100BF00008020D4582803386E7000346060005079C
|
||||||
:100C00001E0145F53244410182802326C801F9B70F
|
:100C0000230AC300DDB799C2054505CB8147E3D070
|
||||||
:100C10002324C801E1B7B716050037170500B71739
|
:100C1000D7FE03260E00034546013306F70085077D
|
||||||
:100C20000500938646C1130707C19387C7C083AEEB
|
:100C20002300A600EDB783270E00FD18DC4F93F7D5
|
||||||
:100C300005008148054F8D4F914233D51E0105EDCA
|
:100C30000702D5DF11656D8D11E18280B7070700CE
|
||||||
:100C40008280B716050037170500B7170500938691
|
:100C400083C7470113F585001D8D3335A0008280D1
|
||||||
:100C500006C21307C7C1938787C1D1BFB716050066
|
:100C50001C414147D8CF8280B7470800938707409F
|
||||||
:100C600037170500B7170500938686C0130747C0DE
|
:100C60002A886304F508B757080093870780630450
|
||||||
:100C7000938707C06DBF331E1F013376DE0119E273
|
:100C7000F50A37470800630DE50A05458280331EF3
|
||||||
:100C8000850865BF411122C635B7E1689388086AB7
|
:100C80001F013376DE0129C683A3450088431393F1
|
||||||
:100C900001488147014781460146B705200689B5CD
|
:100C9000180033966F001346F6FF13F43300718D7E
|
||||||
:100CA000011106CEA307010089476393F502B7053A
|
:100CA00033146400418D88C3638B5302638C030249
|
||||||
:100CB0002035E1681307F1009388086A01488147ED
|
:100CB000084303AEC500718D331E6E003365C50158
|
||||||
:100CC00085460146313DF2400345F10005618280D1
|
:100CC00008C38842698E884533156500498E90C2F5
|
||||||
:100CD000B7052005F9BF011106CE22CC26CA23068E
|
:100CD000850833D51E0145F5324441018280232623
|
||||||
:100CE000B100AA84A306C1004D37E1689388086A61
|
:100CE000C801F9B72324C801E1B7B71605003717C3
|
||||||
:100CF00001487C00014789460146B78520012685C9
|
:100CF0000500B7170500938646C1130707C1938700
|
||||||
:100D00000964F93B130414717D1419E40D45F24094
|
:100D0000C7C083AE05008148054F8D4F914233D552
|
||||||
:100D10006244D24405618280854526855137058924
|
:100D10001E0105ED8280B716050037170500B717CD
|
||||||
:100D200065F50145EDB7011106CE22CC26CA2E8409
|
:100D20000500938606C21307C7C1938787C1D1BF49
|
||||||
:100D30004AC8AA84328936C6893FB247E16822860A
|
:100D3000B716050037170500B7170500938686C05C
|
||||||
:100D40009388086A01480147CA86B78580022685CC
|
:100D4000130747C0938707C06DBF331E1F0133765B
|
||||||
:100D5000616479331304146A7D1411C485452685B2
|
:100D5000DE0119E2850865BF411122C635B7E16899
|
||||||
:100D60008137058975F9F2406244D24442490561F0
|
:100D60009388086A01488147014781460146B705D3
|
||||||
:100D70008280011106CE22CC26CA2EC6AA84313723
|
:100D7000200689B5011106CEA307010089476393B8
|
||||||
:100D80003246E1689388086A0148814701478146F5
|
:100D8000F502B7052035E1681307F1009388086A7A
|
||||||
:100D9000B705802026856164A1331304146A7D148D
|
:100D90000148814785460146313DF2400345F10057
|
||||||
:100DA00011C485452685ED3D058975F9F2406244FB
|
:100DA00005618280B7052005F9BF011106CE22CC6E
|
||||||
:100DB000D24405618280B3C7A5008D8BB308C500FE
|
:100DB00026CA2306B100AA84A306C1004D37E16804
|
||||||
:100DC000B1E78D4763F4C704937735002A87B9EB01
|
:100DC0009388086A01487C00014789460146B78537
|
||||||
:100DD00013F6C8FFB306E6409307000263C8D706C0
|
:100DD000200126850964F93B130414717D1419E47C
|
||||||
:100DE000AE86BA876371C70203A806009107910611
|
:100DE0000D45F2406244D2440561828085452685E6
|
||||||
:100DF00023AE07FFE3EAC7FE9307F6FF998FF19B47
|
:100DF0005137058965F50145EDB7011106CE22CCC5
|
||||||
:100E000091073E97BE956366170182802A87637EAD
|
:100E000026CA2E844AC8AA84328936C6893FB24788
|
||||||
:100E1000150383C7050005078505A30FF7FEE39AB1
|
:100E1000E16822869388086A01480147CA86B78537
|
||||||
:100E2000E8FE828083C60500050793773700A30F8D
|
:100E200080022685616479331304146A7D1411C429
|
||||||
:100E3000D7FE8505D1DF83C6050005079377370008
|
:100E3000854526858137058975F9F2406244D2449B
|
||||||
:100E4000A30FD7FE8505F9FF61B78280411122C645
|
:100E4000424905618280011106CE22CC26CA2EC6F7
|
||||||
:100E50001304000283A3050083A2450083AF85002D
|
:100E5000AA8431373246E1689388086A014881479D
|
||||||
:100E600003AFC50083AE050103AE450103A38501B1
|
:100E600001478146B705802026856164A1331304BC
|
||||||
:100E700003A8C501945113074702B307E640232E88
|
:100E7000146A7D1411C485452685ED3D058975F9F3
|
||||||
:100E800077FC232057FE2322F7FF2324E7FF2326A6
|
:100E8000F2406244D24405618280B3C7A5008D8BD5
|
||||||
:100E9000D7FF2328C7FF232A67FE232C07FF232E13
|
:100E9000B308C500B1E78D4763F4C7049377350005
|
||||||
:100EA000D7FE93854502E347F4FAAE86BA876371AD
|
:100EA0002A87B9EB13F6C8FFB306E64093070002A2
|
||||||
:100EB000C70203A806009107910623AE07FFE3EAE5
|
:100EB00063C8D706AE86BA876371C70203A8060067
|
||||||
:100EC000C7FE9307F6FF998FF19B91073E97BE955A
|
:100EC0009107910623AE07FFE3EAC7FE9307F6FFFB
|
||||||
:100ED0006365170132444101828083C7050005071D
|
:100ED000998FF19B91073E97BE95636617018280BB
|
||||||
:100EE0008505A30FF7FEE387E8FE83C70500050726
|
:100EE0002A87637E150383C7050005078505A30FC1
|
||||||
:100EF0008505A30FF7FEE392E8FEE9BF200000009E
|
:100EF000F7FEE39AE8FE828083C605000507937734
|
||||||
:100F0000010000000300000006000000EB000000EC
|
:100F00003700A30FD7FE8505D1DF83C6050005078F
|
||||||
:100F10000000008000010000000007000000000049
|
:100F100093773700A30FD7FE8505F9FF61B782806D
|
||||||
:100F200000000000000000000000000000000000C1
|
:100F2000411122C61304000283A3050083A24500D9
|
||||||
:100F300000000000000000000000000000000000B1
|
:100F300083AF850003AFC50083AE050103AE450155
|
||||||
|
:100F400003A3850103A8C501945113074702B30702
|
||||||
|
:100F5000E640232E77FC232057FE2322F7FF23248D
|
||||||
|
:100F6000E7FF2326D7FF2328C7FF232A67FE232C6A
|
||||||
|
:100F700007FF232ED7FE93854502E347F4FAAE869A
|
||||||
|
:100F8000BA876371C70203A806009107910623AED2
|
||||||
|
:100F900007FFE3EAC7FE9307F6FF998FF19B9107DE
|
||||||
|
:100FA0003E97BE956365170132444101828083C735
|
||||||
|
:100FB000050005078505A30FF7FEE387E8FE83C755
|
||||||
|
:100FC000050005078505A30FF7FEE392E8FEE9BFDC
|
||||||
|
:100FD00020000000010000000300000006000000E7
|
||||||
|
:100FE000EB00000000000000000000000000000016
|
||||||
|
:100FF000000000800000000000000700000000006A
|
||||||
|
:1010000000000000000000000000000000000000E0
|
||||||
|
:1010100000000000000000000000000000000000D0
|
||||||
:0400000501000000F6
|
:0400000501000000F6
|
||||||
:00000001FF
|
:00000001FF
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include <uart_lib.h>
|
#include <uart_lib.h>
|
||||||
#include "mik32_hal_irq.h"
|
#include "mik32_hal_irq.h"
|
||||||
|
#include "wiring_LL.h"
|
||||||
|
|
||||||
// HardwareSerial class objects for use in Arduino IDE
|
// HardwareSerial class objects for use in Arduino IDE
|
||||||
HardwareSerial Serial(0);
|
HardwareSerial Serial(0);
|
||||||
@ -127,9 +127,9 @@ void HardwareSerial::rx_complete_irq(void)
|
|||||||
unsigned char c;
|
unsigned char c;
|
||||||
// while there is something to receive, put the data into the buffer
|
// while there is something to receive, put the data into the buffer
|
||||||
// and edit the buffer index
|
// and edit the buffer index
|
||||||
while (!UART_IsRxFifoEmpty(uart))
|
while(!UART_IS_RX_FIFO_EMPTY(uart))
|
||||||
{
|
{
|
||||||
c = UART_ReadByte(uart);
|
c = UART_READ_BYTE(uart);
|
||||||
if (i != _rx_buffer_tail)
|
if (i != _rx_buffer_tail)
|
||||||
{
|
{
|
||||||
// write if there is space in the buffer
|
// write if there is space in the buffer
|
||||||
@ -140,7 +140,7 @@ void HardwareSerial::rx_complete_irq(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wrapper for use in С-files
|
// wrapper for use in С-files
|
||||||
extern "C" void serial_handler_wrapper(uint8_t uartNumInt)
|
extern "C" void __attribute__((optimize("O3"))) serial_interrupt_handler(uint8_t uartNumInt)
|
||||||
{
|
{
|
||||||
if (uartNumInt == 0)
|
if (uartNumInt == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -100,7 +100,7 @@ class HardwareSerial : public Stream
|
|||||||
using Print::write; // pull in write(str)
|
using Print::write; // pull in write(str)
|
||||||
operator bool() { return isInited; }
|
operator bool() { return isInited; }
|
||||||
|
|
||||||
void rx_complete_irq(void);
|
inline void rx_complete_irq(void) __attribute__((always_inline, optimize("O3")));
|
||||||
};
|
};
|
||||||
|
|
||||||
extern HardwareSerial Serial;
|
extern HardwareSerial Serial;
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "mik32_hal_timer16.h"
|
#include "mik32_hal_timer16.h"
|
||||||
#include "mik32_hal_irq.h"
|
#include "mik32_hal_irq.h"
|
||||||
|
#include "wiring_LL.h"
|
||||||
|
|
||||||
#define PRESCALERS_QTY 7
|
#define PRESCALERS_QTY 7
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -100,7 +101,7 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
|
|||||||
HAL_EPIC_MaskLevelSet(HAL_EPIC_TIMER16_1_MASK);
|
HAL_EPIC_MaskLevelSet(HAL_EPIC_TIMER16_1_MASK);
|
||||||
|
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)timer_pin_port, timer_pin_mask, GPIO_PIN_LOW);
|
GPIO_CLEAR_PIN((GPIO_TypeDef *)timer_pin_port, timer_pin_mask);
|
||||||
|
|
||||||
HAL_Timer16_Counter_Start_IT(&htimer16_1, frequencyParams.period_ticks);
|
HAL_Timer16_Counter_Start_IT(&htimer16_1, frequencyParams.period_ticks);
|
||||||
timerIsOn = true;
|
timerIsOn = true;
|
||||||
@ -125,9 +126,9 @@ void noTone(uint8_t pin)
|
|||||||
if (timerIsOn)
|
if (timerIsOn)
|
||||||
{
|
{
|
||||||
// pin to 0
|
// pin to 0
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)timer_pin_port, timer_pin_mask, GPIO_PIN_LOW);
|
GPIO_CLEAR_PIN((GPIO_TypeDef *)timer_pin_port, timer_pin_mask);
|
||||||
HAL_Timer16_Disable(&htimer16_1); // disable timer
|
TIM16_DISABLE(htimer16_1);
|
||||||
HAL_EPIC_MaskLevelClear(HAL_EPIC_TIMER16_1_MASK);
|
EPIC_LEVEL_CLEAR_BY_MASK(HAL_EPIC_TIMER16_1_MASK);
|
||||||
pinMode(pin, INPUT); // deinit pin
|
pinMode(pin, INPUT); // deinit pin
|
||||||
timer_pin = -1; // reset to default
|
timer_pin = -1; // reset to default
|
||||||
timerIsOn = false;
|
timerIsOn = false;
|
||||||
@ -135,25 +136,26 @@ void noTone(uint8_t pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// irq handler
|
// irq handler
|
||||||
extern "C" void tone_interrupt_handler(void)
|
extern "C" void __attribute__((noinline, section(".ram_text"), optimize("O3"))) tone_interrupt_handler(void)
|
||||||
{
|
{
|
||||||
if(HAL_Timer16_GetInterruptStatus_ARRM(&htimer16_1))
|
if (TIM16_GET_ARRM_INT_STATUS(htimer16_1))
|
||||||
{
|
{
|
||||||
// timer period has passed, change the pin state
|
// timer period has passed, change the pin state
|
||||||
if (timer_toggle_count != 0)
|
if (timer_toggle_count != 0)
|
||||||
{
|
{
|
||||||
HAL_GPIO_TogglePin((GPIO_TypeDef*)timer_pin_port, timer_pin_mask);
|
GPIO_TOGGLE_PIN((GPIO_TypeDef*)timer_pin_port, timer_pin_mask);
|
||||||
|
|
||||||
if (timer_toggle_count > 0)
|
if (timer_toggle_count > 0)
|
||||||
timer_toggle_count--;
|
timer_toggle_count--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// turn off if the specified duration has passed
|
// turn off if the specified duration has passed
|
||||||
HAL_GPIO_WritePin((GPIO_TypeDef *)timer_pin_port, timer_pin_mask, GPIO_PIN_LOW);
|
GPIO_CLEAR_PIN((GPIO_TypeDef *)timer_pin_port, timer_pin_mask);
|
||||||
noTone(timer_pin);
|
TIM16_DISABLE(htimer16_1);
|
||||||
|
EPIC_LEVEL_CLEAR_BY_MASK(HAL_EPIC_TIMER16_1_MASK);
|
||||||
|
timerIsOn = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// reset timer interrupt flags
|
// reset timer interrupt flags
|
||||||
HAL_Timer16_ClearInterruptMask(&htimer16_1, 0xFFFFFFFF);
|
TIM16_CLEAR_INT_MASK(htimer16_1, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
@ -4,6 +4,7 @@
|
|||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
#include "wiring_digital.h"
|
#include "wiring_digital.h"
|
||||||
#include "WInterrupts.h"
|
#include "WInterrupts.h"
|
||||||
|
#include "wiring_LL.h"
|
||||||
|
|
||||||
extern void ErrorMsgHandler(const char * msg);
|
extern void ErrorMsgHandler(const char * msg);
|
||||||
|
|
||||||
@ -18,13 +19,13 @@ static void nothing(void)
|
|||||||
// enable global interrupts
|
// enable global interrupts
|
||||||
void interrupts(void)
|
void interrupts(void)
|
||||||
{
|
{
|
||||||
HAL_IRQ_EnableInterrupts();
|
GLOBAL_IRQ_ENABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable global interrupts
|
// disable global interrupts
|
||||||
void noInterrupts(void)
|
void noInterrupts(void)
|
||||||
{
|
{
|
||||||
HAL_IRQ_DisableInterrupts();
|
GLOBAL_IRQ_DISABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
// we can provide no more than 8 interrupts on gpio at the same time
|
// we can provide no more than 8 interrupts on gpio at the same time
|
||||||
@ -100,33 +101,26 @@ void detachInterrupt(uint8_t interruptNum)
|
|||||||
void disableInterrupt(uint8_t interruptNum)
|
void disableInterrupt(uint8_t interruptNum)
|
||||||
{
|
{
|
||||||
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
|
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
|
||||||
{
|
|
||||||
int irq_line_num = interruptToGpioIntLine(interruptNum) >> GPIO_IRQ_LINE_S;
|
|
||||||
// disable gpio interrupt line
|
// disable gpio interrupt line
|
||||||
GPIO_IRQ->ENABLE_CLEAR = (1 << irq_line_num);
|
GPIO_IRQ_LINE_DISABLE(interruptToGpioIntLine(interruptNum));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable single interrupt
|
// enable single interrupt
|
||||||
void enableInterrupt(uint8_t interruptNum)
|
void enableInterrupt(uint8_t interruptNum)
|
||||||
{
|
{
|
||||||
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
|
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
|
||||||
{
|
|
||||||
int irq_line_num = interruptToGpioIntLine(interruptNum) >> GPIO_IRQ_LINE_S;
|
|
||||||
// enable gpio interrupt line
|
// enable gpio interrupt line
|
||||||
GPIO_IRQ->ENABLE_SET = (1 << irq_line_num);
|
GPIO_IRQ_LINE_ENABLE(interruptToGpioIntLine(interruptNum));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// common gpio interrupt handler
|
// common gpio interrupt handler
|
||||||
void gpio_interrupts_handler(void)
|
void __attribute__((noinline, section(".ram_text"), optimize("O3"))) gpio_interrupt_handler(void)
|
||||||
{
|
{
|
||||||
// go through all the interrupts and call the handler for the triggered line
|
// go through all the interrupts and call the handler for the triggered line
|
||||||
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
|
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
|
||||||
{
|
{
|
||||||
if (HAL_GPIO_LineInterruptState(interruptToGpioIntLine(i)))
|
if (GPIO_IRQ_LINE_STATE(interruptToGpioIntLine(i)))
|
||||||
intFunc[i]();
|
intFunc[i]();
|
||||||
}
|
}
|
||||||
|
GPIO_IRQ_CLEAR_ALL();
|
||||||
HAL_GPIO_ClearInterrupts();
|
|
||||||
}
|
}
|
||||||
@ -19,6 +19,8 @@
|
|||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma GCC diagnostic ignored "-Wrestrict" // для GCC и Clang
|
||||||
|
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "itoa.h"
|
#include "itoa.h"
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "mik32_hal_pcc.h"
|
#include "mik32_hal_pcc.h"
|
||||||
|
#include "mik32_hal_irq.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
// --------------------- init --------------------- //
|
// --------------------- init --------------------- //
|
||||||
// called before setup()
|
// called before setup()
|
||||||
void pre_init(void)
|
void pre_init(void)
|
||||||
{
|
{
|
||||||
|
// set irq vector to ram region
|
||||||
|
write_csr(mtvec, 0x02000000);
|
||||||
|
|
||||||
HAL_Init();
|
HAL_Init();
|
||||||
|
|
||||||
// gpio clock
|
// gpio clock
|
||||||
@ -29,8 +33,10 @@ void post_init(void)
|
|||||||
// print text if Serial is enabled
|
// print text if Serial is enabled
|
||||||
extern "C" void ErrorMsgHandler(const char * msg)
|
extern "C" void ErrorMsgHandler(const char * msg)
|
||||||
{
|
{
|
||||||
|
#ifdef HardwareSerial_h
|
||||||
if(Serial)
|
if(Serial)
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,33 +10,49 @@ MEMORY {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STACK_SIZE = 1024;
|
STACK_SIZE = 1024;
|
||||||
|
HEAP_SIZE = 1024;
|
||||||
|
|
||||||
CL_SIZE = 16;
|
CL_SIZE = 16;
|
||||||
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
.text ORIGIN(ram) : {
|
.text ORIGIN(ram) : {
|
||||||
PROVIDE(__TEXT_START__ = .);
|
PROVIDE(__TEXT_START__ = .);
|
||||||
*crt0.o(.text .text.*)
|
*crt0.S.o(.text .text.*)
|
||||||
*(.text.smallsysteminit)
|
*(.text.smallsysteminit)
|
||||||
*(.text.SmallSystemInit)
|
*(.text.SmallSystemInit)
|
||||||
. = ORIGIN(ram) + 0xC0;
|
. = ORIGIN(ram) + 0xC0;
|
||||||
KEEP(*crt0.o(.trap_text))
|
KEEP(*crt0.S.o(.trap_text))
|
||||||
|
|
||||||
*(.text)
|
*(.text)
|
||||||
*(.text.*)
|
*(.text.*)
|
||||||
*(.rodata)
|
*(.rodata)
|
||||||
*(.rodata.*)
|
*(.rodata.*)
|
||||||
. = ALIGN(CL_SIZE);
|
. = ALIGN(CL_SIZE);
|
||||||
PROVIDE(__TEXT_END__ = .);
|
|
||||||
} >ram
|
} >ram
|
||||||
|
|
||||||
|
.init_array (READONLY) :
|
||||||
|
{
|
||||||
|
PROVIDE_HIDDEN (__init_array_start = .);
|
||||||
|
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
|
||||||
|
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
|
||||||
|
PROVIDE_HIDDEN (__init_array_end = .);
|
||||||
|
|
||||||
|
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||||
|
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
|
||||||
|
KEEP(*(.fini_array))
|
||||||
|
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||||
|
|
||||||
|
PROVIDE(__TEXT_END__ = .);
|
||||||
|
} >ram AT>ram
|
||||||
|
|
||||||
.data :
|
.data :
|
||||||
AT( __TEXT_END__ ) {
|
AT( __TEXT_END__ ) {
|
||||||
PROVIDE(__DATA_START__ = .);
|
PROVIDE(__DATA_START__ = .);
|
||||||
_gp = .;
|
_gp = .;
|
||||||
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*)
|
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*)
|
||||||
*(.sdata .sdata.* .gnu.linkonce.s.*)
|
*(.sdata .sdata.* .sdata* .sdata*.* .gnu.linkonce.s.*)
|
||||||
*(.data .data.*)
|
*(.data .data.*)
|
||||||
|
*(.ramfunc)
|
||||||
. = ALIGN(CL_SIZE);
|
. = ALIGN(CL_SIZE);
|
||||||
} >ram
|
} >ram
|
||||||
|
|
||||||
@ -72,12 +88,19 @@ SECTIONS {
|
|||||||
PROVIDE(__BSS_END__ = .);
|
PROVIDE(__BSS_END__ = .);
|
||||||
} >ram
|
} >ram
|
||||||
|
|
||||||
|
.heap : {
|
||||||
|
PROVIDE(__heap_start = .);
|
||||||
|
. += HEAP_SIZE;
|
||||||
|
. = ALIGN(CL_SIZE);
|
||||||
|
PROVIDE(__heap_end = .);
|
||||||
|
} >ram
|
||||||
|
|
||||||
_end = .;
|
_end = .;
|
||||||
PROVIDE(__end = .);
|
PROVIDE(__end = .);
|
||||||
|
|
||||||
/* End of uninitalized data segement */
|
/* End of uninitalized data segement */
|
||||||
|
|
||||||
.stack ORIGIN(ram) + LENGTH(ram) - STACK_SIZE : {
|
.stack ORIGIN(ram) + LENGTH(ram) - STACK_SIZE: {
|
||||||
FILL(0);
|
FILL(0);
|
||||||
PROVIDE(__STACK_START__ = .);
|
PROVIDE(__STACK_START__ = .);
|
||||||
. += STACK_SIZE;
|
. += STACK_SIZE;
|
||||||
|
|||||||
@ -21,8 +21,8 @@ SECTIONS {
|
|||||||
*crt0.S.o(.text .text.*)
|
*crt0.S.o(.text .text.*)
|
||||||
*(.text.smallsysteminit)
|
*(.text.smallsysteminit)
|
||||||
*(.text.SmallSystemInit)
|
*(.text.SmallSystemInit)
|
||||||
. = ORIGIN(rom) + 0xC0;
|
/*. = ORIGIN(rom) + 0xC0;*/
|
||||||
KEEP(*crt0.S.o(.trap_text))
|
/*KEEP(*crt0.S.o(.trap_text))*/
|
||||||
|
|
||||||
*(.text)
|
*(.text)
|
||||||
*(.text.*)
|
*(.text.*)
|
||||||
@ -50,15 +50,17 @@ SECTIONS {
|
|||||||
AT( __TEXT_END__ ) {
|
AT( __TEXT_END__ ) {
|
||||||
PROVIDE(__DATA_START__ = .);
|
PROVIDE(__DATA_START__ = .);
|
||||||
_gp = .;
|
_gp = .;
|
||||||
|
. = ORIGIN(ram) + 0xC0;
|
||||||
|
KEEP(*crt0.S.o(.trap_text))
|
||||||
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*)
|
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*)
|
||||||
*(.sdata .sdata.* .sdata* .sdata*.* .gnu.linkonce.s.*)
|
*(.sdata .sdata.* .sdata* .sdata*.* .gnu.linkonce.s.*)
|
||||||
*(.data .data.*)
|
*(.data .data.*)
|
||||||
. = ALIGN(CL_SIZE);
|
. = ALIGN(CL_SIZE);
|
||||||
|
PROVIDE(__DATA_END__ = .);
|
||||||
} >ram
|
} >ram
|
||||||
|
|
||||||
__DATA_IMAGE_START__ = LOADADDR(.data);
|
__DATA_IMAGE_START__ = LOADADDR(.data);
|
||||||
__DATA_IMAGE_END__ = LOADADDR(.data) + SIZEOF(.data);
|
__DATA_IMAGE_END__ = LOADADDR(.data) + SIZEOF(.data);
|
||||||
ASSERT(__DATA_IMAGE_END__ < ORIGIN(rom) + LENGTH(rom), "Data image overflows rom section")
|
|
||||||
|
|
||||||
/* thread-local data segment */
|
/* thread-local data segment */
|
||||||
.tdata : {
|
.tdata : {
|
||||||
@ -84,10 +86,26 @@ SECTIONS {
|
|||||||
|
|
||||||
.bss : {
|
.bss : {
|
||||||
*(.bss .bss.*)
|
*(.bss .bss.*)
|
||||||
|
*(COMMON)
|
||||||
. = ALIGN(CL_SIZE);
|
. = ALIGN(CL_SIZE);
|
||||||
PROVIDE(__BSS_END__ = .);
|
PROVIDE(__BSS_END__ = .);
|
||||||
} >ram
|
} >ram
|
||||||
|
|
||||||
|
/* Code intended to be copied to REGION_RAM before execution */
|
||||||
|
.ram_text :
|
||||||
|
AT( ALIGN(__DATA_IMAGE_END__, CL_SIZE) ) {
|
||||||
|
PROVIDE(__RAM_TEXT_START__ = .);
|
||||||
|
*(.ram_text)
|
||||||
|
. = ALIGN(CL_SIZE);
|
||||||
|
PROVIDE(__RAM_TEXT_END__ = .);
|
||||||
|
} > ram
|
||||||
|
|
||||||
|
__RAM_TEXT_IMAGE_START__ = LOADADDR(.ram_text);
|
||||||
|
__RAM_TEXT_IMAGE_END__ = LOADADDR(.ram_text) + SIZEOF(.ram_text);
|
||||||
|
ASSERT(__RAM_TEXT_IMAGE_END__ < ORIGIN(rom) + LENGTH(rom), "rom segment overflows")
|
||||||
|
|
||||||
|
ASSERT(__RAM_TEXT_END__ < ORIGIN(ram) + LENGTH(ram) - STACK_SIZE - HEAP_SIZE, "REGION_RAM section overflows")
|
||||||
|
|
||||||
.heap : {
|
.heap : {
|
||||||
PROVIDE(__heap_start = .);
|
PROVIDE(__heap_start = .);
|
||||||
. += HEAP_SIZE;
|
. += HEAP_SIZE;
|
||||||
|
|||||||
@ -62,6 +62,11 @@ memset_2:
|
|||||||
|
|
||||||
_start:
|
_start:
|
||||||
|
|
||||||
|
li t0, 128000
|
||||||
|
start_loop_delay:
|
||||||
|
nop
|
||||||
|
addi t0, t0, -1
|
||||||
|
bnez t0, start_loop_delay
|
||||||
# Init stack and global pointer
|
# Init stack and global pointer
|
||||||
#
|
#
|
||||||
la_abs sp, __C_STACK_TOP__
|
la_abs sp, __C_STACK_TOP__
|
||||||
@ -74,20 +79,19 @@ _start:
|
|||||||
la_abs a3, __DATA_START__
|
la_abs a3, __DATA_START__
|
||||||
memcpy a1, a2, a3, t0
|
memcpy a1, a2, a3, t0
|
||||||
|
|
||||||
|
# Init ramfunc
|
||||||
|
#
|
||||||
|
la_abs a1, __RAM_TEXT_IMAGE_START__
|
||||||
|
la_abs a2, __RAM_TEXT_IMAGE_END__
|
||||||
|
la_abs a3, __RAM_TEXT_START__
|
||||||
|
memcpy a1, a2, a3, t0
|
||||||
|
|
||||||
# Clear bss
|
# Clear bss
|
||||||
#
|
#
|
||||||
la_abs a1, __BSS_START__
|
la_abs a1, __BSS_START__
|
||||||
la_abs a2, __BSS_END__
|
la_abs a2, __BSS_END__
|
||||||
memset a1, a2, zero
|
memset a1, a2, zero
|
||||||
|
|
||||||
#ifdef MIK32V0
|
|
||||||
# Enable pad_config clocking
|
|
||||||
#
|
|
||||||
li t0, (1 << 3)
|
|
||||||
li t1, 0x50014
|
|
||||||
sw t0, (t1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
jalr_abs ra, SmallSystemInit
|
jalr_abs ra, SmallSystemInit
|
||||||
jalr_abs ra, SystemInit
|
jalr_abs ra, SystemInit
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
#include "mik32_hal_irq.h"
|
#include "mik32_hal_irq.h"
|
||||||
|
#include "wiring_LL.h"
|
||||||
|
|
||||||
// isr functions
|
// isr functions
|
||||||
extern void serial_handler_wrapper(uint8_t uartNumInt);
|
extern void serial_interrupt_handler(uint8_t uartNumInt);
|
||||||
extern void gpio_interrupts_handler(void);
|
extern void gpio_interrupt_handler(void);
|
||||||
extern void tone_interrupt_handler(void);
|
extern void tone_interrupt_handler(void);
|
||||||
void __attribute__((weak)) wire_handler_wrapper(void)
|
void __attribute__((weak)) wire_interrupt_handler(void)
|
||||||
{
|
{
|
||||||
// dummy function for case when wire library is not in use
|
// dummy function for case when wire library is not in use
|
||||||
}
|
}
|
||||||
@ -14,8 +15,12 @@ void __attribute__((weak)) servo_handler_wrapper(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------- //
|
// ---------------------------------------------- //
|
||||||
void trap_handler(void)
|
void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handler (void)
|
||||||
{
|
{
|
||||||
|
// gpio interrupt
|
||||||
|
if (EPIC_CHECK_GPIO_IRQ())
|
||||||
|
gpio_interrupt_handler();
|
||||||
|
|
||||||
// tone timer interrupt
|
// tone timer interrupt
|
||||||
if (EPIC_CHECK_TIMER16_1())
|
if (EPIC_CHECK_TIMER16_1())
|
||||||
tone_interrupt_handler();
|
tone_interrupt_handler();
|
||||||
@ -26,20 +31,16 @@ void trap_handler(void)
|
|||||||
|
|
||||||
// uart0 interrupt
|
// uart0 interrupt
|
||||||
if (EPIC_CHECK_UART_0())
|
if (EPIC_CHECK_UART_0())
|
||||||
serial_handler_wrapper(0);
|
serial_interrupt_handler(0);
|
||||||
|
|
||||||
// uart1 interrupt
|
// uart1 interrupt
|
||||||
if (EPIC_CHECK_UART_1())
|
if (EPIC_CHECK_UART_1())
|
||||||
serial_handler_wrapper(1);
|
serial_interrupt_handler(1);
|
||||||
|
|
||||||
// gpio interrupt
|
|
||||||
if (EPIC_CHECK_GPIO_IRQ())
|
|
||||||
gpio_interrupts_handler();
|
|
||||||
|
|
||||||
// i2c interrupt
|
// i2c interrupt
|
||||||
if (EPIC_CHECK_I2C_1())
|
if (EPIC_CHECK_I2C_1())
|
||||||
wire_handler_wrapper();
|
wire_interrupt_handler();
|
||||||
|
|
||||||
// reset all interrupts
|
// reset all interrupts
|
||||||
HAL_EPIC_Clear(0xFFFFFFFF);
|
EPIC_CLEAR_ALL();
|
||||||
}
|
}
|
||||||
|
|||||||
6
cores/arduino/util/delay.h
Normal file
6
cores/arduino/util/delay.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __DELAY_H_
|
||||||
|
#define __DELAY_H_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // __DELAY_H_
|
||||||
64
cores/arduino/wiring_LL.h
Normal file
64
cores/arduino/wiring_LL.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#ifndef _WIRING_LL_H_
|
||||||
|
#define _WIRING_LL_H_
|
||||||
|
|
||||||
|
#include "mik32_hal_irq.h"
|
||||||
|
#include "mik32_hal_gpio.h"
|
||||||
|
#include "mik32_hal_scr1_timer.h"
|
||||||
|
#include "mik32_hal_timer16.h"
|
||||||
|
|
||||||
|
// ----------------- COMMON ----------------- //
|
||||||
|
// convert pin mask from HAL_PinsTypeDef to pin number
|
||||||
|
#define PIN_MASK_TO_PIN_NUMBER(mask) \
|
||||||
|
({ \
|
||||||
|
uint8_t pos; \
|
||||||
|
for (pos = 0; pos < 16; pos++) \
|
||||||
|
if ((mask >> pos) & 1) \
|
||||||
|
break; \
|
||||||
|
pos; \
|
||||||
|
})
|
||||||
|
|
||||||
|
// ----------------- SYSTICK ----------------- //
|
||||||
|
// get ticks from systick
|
||||||
|
#define SYSTICK_GET_TICKS() ((uint64_t)(SCR1_TIMER->MTIMEH)<<32 | SCR1_TIMER->MTIME)
|
||||||
|
|
||||||
|
// ----------------- UART ----------------- //
|
||||||
|
#define UART_READ_BYTE(pUart) ((uint16_t)pUart->RXDATA)
|
||||||
|
#define UART_IS_RX_FIFO_EMPTY(pUart) ((pUart->FLAGS & UART_FLAGS_RXNE_M) == 0)
|
||||||
|
|
||||||
|
// ----------------- TIMER16 ----------------- //
|
||||||
|
#define TIM16_DISABLE(htim16) (htim16.Instance->CR &= ~TIMER16_CR_ENABLE_M)
|
||||||
|
#define TIM16_CLEAR_INT_MASK(htim16, intMask) (htim16.Instance->ICR = intMask)
|
||||||
|
#define TIM16_GET_ARRM_INT_STATUS(htim16) ((bool)((htim16.Instance->ISR & htim16.Instance->IER) & TIMER16_ISR_ARR_MATCH_M))
|
||||||
|
|
||||||
|
// ----------------- EPIC ----------------- //
|
||||||
|
#define EPIC_LEVEL_CLEAR_BY_MASK(mask) (EPIC->MASK_LEVEL_CLEAR |= mask)
|
||||||
|
#define EPIC_CLEAR_ALL() (EPIC->CLEAR = 0xFFFFFFFF)
|
||||||
|
|
||||||
|
// ----------------- IRQ ----------------- //
|
||||||
|
#define GLOBAL_IRQ_DISABLE() (clear_csr(mie, MIE_MEIE))
|
||||||
|
#define GLOBAL_IRQ_ENABLE() set_csr(mstatus, MSTATUS_MIE); \
|
||||||
|
set_csr(mie, MIE_MEIE)
|
||||||
|
|
||||||
|
// ----------------- GPIO ----------------- //
|
||||||
|
#define GPIO_SET_PIN(GPIO_x, pinMask) ((GPIO_x)->SET = (pinMask))
|
||||||
|
#define GPIO_CLEAR_PIN(GPIO_x, pinMask) ((GPIO_x)->CLEAR = (pinMask))
|
||||||
|
#define GPIO_TOGGLE_PIN(GPIO_x, pinMask) ((GPIO_x)->OUTPUT_ ^= pinMask)
|
||||||
|
#define GPIO_READ_PIN(GPIO_x, pinMask) (((GPIO_x)->SET & (pinMask)) != (uint32_t)GPIO_PIN_LOW ? GPIO_PIN_HIGH : GPIO_PIN_LOW)
|
||||||
|
// get pin state by it's number
|
||||||
|
#define GPIO_GET_PIN_STATE(GPIO_x, pinNumber) (((GPIO_x)->OUTPUT_ >> pinNumber) & 0b1)
|
||||||
|
|
||||||
|
// ----------------- GPIO IRQ ----------------- //
|
||||||
|
#define GPIO_IRQ_LINE_ENABLE(lineMask) ( GPIO_IRQ->ENABLE_SET = (1 << (lineMask >> GPIO_IRQ_LINE_S)) )
|
||||||
|
#define GPIO_IRQ_LINE_DISABLE(lineMask) ( GPIO_IRQ->ENABLE_CLEAR = (1 << (lineMask >> GPIO_IRQ_LINE_S)) )
|
||||||
|
#define GPIO_IRQ_LINE_STATE(lineMask) ((GPIO_IRQ->INTERRUPT & (1 << (lineMask >> GPIO_IRQ_LINE_S))) != 0)
|
||||||
|
#define GPIO_IRQ_CLEAR_ALL() ( GPIO_IRQ->CLEAR = 0b11111111)
|
||||||
|
|
||||||
|
// ----------------- PIN CONFIG ----------------- //
|
||||||
|
// return config of pin with pinNumber(0...16) in portReg (config, pupd, ds for ports 0...2)
|
||||||
|
#define PIN_GET_PAD_CONFIG(portReg, pinNumber) ((PAD_CONFIG->portReg >> (pinNumber<<1)) & 0b11)
|
||||||
|
#define PIN_SET_PAD_CONFIG(portReg, pinNumber, value) (PAD_CONFIG->portReg = (PAD_CONFIG->portReg & (~PAD_CONFIG_PIN_M(pinNumber))) \
|
||||||
|
| PAD_CONFIG_PIN(pinNumber, value))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _WIRING_LL_H_ */
|
||||||
@ -39,6 +39,11 @@ void SysTick_Init(void)
|
|||||||
HAL_SCR1_Timer_Init(&hscr1_timer); // Ticks are 32 MHz
|
HAL_SCR1_Timer_Init(&hscr1_timer); // Ticks are 32 MHz
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t SysTick_GetTicks(void)
|
||||||
|
{
|
||||||
|
return TICKS_IN_SYSTIMER;
|
||||||
|
}
|
||||||
|
|
||||||
// number of microseconds since start of the program
|
// number of microseconds since start of the program
|
||||||
uint32_t micros(void)
|
uint32_t micros(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,6 +34,12 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
void SysTick_Init(void);
|
void SysTick_Init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Returns the number of ticks since the Arduino board began running the current program.
|
||||||
|
|
||||||
|
* \return Number of ticks since the program started
|
||||||
|
*/
|
||||||
|
uint64_t SysTick_GetTicks(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Returns the number of milliseconds since the Arduino board began running the current program.
|
* \brief Returns the number of milliseconds since the Arduino board began running the current program.
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
Software serial multiple serial test
|
||||||
|
|
||||||
|
Receives from the hardware serial, sends to software serial.
|
||||||
|
Receives from software serial, sends to hardware serial.
|
||||||
|
|
||||||
|
The circuit:
|
||||||
|
* RX is digital pin 2 (connect to TX of other device)
|
||||||
|
* TX is digital pin 6 (connect to RX of other device)
|
||||||
|
|
||||||
|
Note:
|
||||||
|
Not all pins on the Elbear Ace-Uno support interrupts,
|
||||||
|
so only the following can be used for RX:
|
||||||
|
2, 3, 4, 5, 8, 9
|
||||||
|
|
||||||
|
created back in the mists of time
|
||||||
|
modified 25 May 2012
|
||||||
|
by Tom Igoe
|
||||||
|
based on Mikal Hart's example
|
||||||
|
|
||||||
|
This example code is in the public domain.
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
SoftwareSerial mySerial(2, 6); // RX, TX
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Open serial communications and wait for port to open:
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) ; // wait for serial port to connect. Needed for native USB port only
|
||||||
|
Serial.println("Goodnight moon!");
|
||||||
|
|
||||||
|
// set the data rate for the SoftwareSerial port
|
||||||
|
mySerial.begin(9600);
|
||||||
|
mySerial.println("Hello, world?");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() { // run over and over
|
||||||
|
while (mySerial.available())
|
||||||
|
Serial.write(mySerial.read());
|
||||||
|
|
||||||
|
while (Serial.available())
|
||||||
|
mySerial.write(Serial.read());
|
||||||
|
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
Software serial multiple serial test
|
||||||
|
|
||||||
|
Receives from the two software serial ports,
|
||||||
|
sends to the hardware serial port.
|
||||||
|
|
||||||
|
In order to listen on a software port, you call port.listen().
|
||||||
|
When using two software serial ports, you have to switch ports
|
||||||
|
by listen()ing on each one in turn. Pick a logical time to switch
|
||||||
|
ports, like the end of an expected transmission, or when the
|
||||||
|
buffer is empty. This example switches ports when there is nothing
|
||||||
|
more to read from a port
|
||||||
|
|
||||||
|
The circuit:
|
||||||
|
Two devices which communicate serially are needed.
|
||||||
|
* First serial device's TX attached to digital pin 2(RX), RX to pin 6(TX)
|
||||||
|
* Second serial device's TX attached to digital pin 8(RX), RX to pin 10(TX)
|
||||||
|
|
||||||
|
Note:
|
||||||
|
Not all pins on the Elbear Ace-Uno support interrupts,
|
||||||
|
so only the following can be used for RX:
|
||||||
|
2, 3, 4, 5, 8, 9
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
|
// software serial #1: RX = digital pin 2, TX = digital pin 6
|
||||||
|
SoftwareSerial portOne(2, 6);
|
||||||
|
// software serial #2: RX = digital pin 8, TX = digital pin 10
|
||||||
|
SoftwareSerial portTwo(8, 10);
|
||||||
|
|
||||||
|
// active port is changed by user button pressing
|
||||||
|
volatile bool isPortOneActive = true;
|
||||||
|
void btn_pressed_callback(void)
|
||||||
|
{
|
||||||
|
// change active port
|
||||||
|
if (isPortOneActive)
|
||||||
|
{
|
||||||
|
portTwo.listen();
|
||||||
|
Serial.println("Port two is listening");
|
||||||
|
isPortOneActive = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
portOne.listen();
|
||||||
|
Serial.println("Port one is listening");
|
||||||
|
isPortOneActive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Open serial communications and wait for port to open
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
; // wait for serial port to connect. Needed for native USB port only
|
||||||
|
}
|
||||||
|
|
||||||
|
// attach interrupt to user button
|
||||||
|
attachInterrupt(digitalPinToInterrupt(BTN_BUILTIN), btn_pressed_callback, FALLING);
|
||||||
|
|
||||||
|
// Start each software serial port
|
||||||
|
portOne.begin(57600);
|
||||||
|
portTwo.begin(57600);
|
||||||
|
|
||||||
|
// First listen to port one
|
||||||
|
portOne.listen();
|
||||||
|
isPortOneActive = true;
|
||||||
|
Serial.println("Port one is listening");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// check data from port one
|
||||||
|
if (portOne.available())
|
||||||
|
{
|
||||||
|
Serial.println("Data from port one:");
|
||||||
|
// while there is data coming in, read it
|
||||||
|
// and send to the hardware serial port
|
||||||
|
while (portOne.available() > 0)
|
||||||
|
Serial.write((char)portOne.read());
|
||||||
|
|
||||||
|
// blank line to separate data from the two ports
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check data from port two
|
||||||
|
if (portTwo.available())
|
||||||
|
{
|
||||||
|
Serial.println("Data from port two:");
|
||||||
|
// while there is data coming in, read it
|
||||||
|
// and send to the hardware serial port
|
||||||
|
while (portTwo.available() > 0)
|
||||||
|
Serial.write((char)portTwo.read());
|
||||||
|
|
||||||
|
// blank line to separate data from the two ports
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
30
libraries/SoftwareSerial/keywords.txt
Normal file
30
libraries/SoftwareSerial/keywords.txt
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#######################################
|
||||||
|
# Syntax Coloring Map for SoftwareSerial
|
||||||
|
# (formerly NewSoftSerial)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Datatypes (KEYWORD1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
SoftwareSerial KEYWORD1
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Methods and Functions (KEYWORD2)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
begin KEYWORD2
|
||||||
|
end KEYWORD2
|
||||||
|
read KEYWORD2
|
||||||
|
write KEYWORD2
|
||||||
|
available KEYWORD2
|
||||||
|
isListening KEYWORD2
|
||||||
|
overflow KEYWORD2
|
||||||
|
flush KEYWORD2
|
||||||
|
listen KEYWORD2
|
||||||
|
peek KEYWORD2
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Constants (LITERAL1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
10
libraries/SoftwareSerial/library.properties
Normal file
10
libraries/SoftwareSerial/library.properties
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
name=SoftwareSerial
|
||||||
|
version=0.0.0
|
||||||
|
author=Arduino
|
||||||
|
maintainer=Arduino <info@arduino.cc>
|
||||||
|
sentence=Enables serial communication on any digital pin.
|
||||||
|
paragraph=The SoftwareSerial library has been developed to allow serial communication on any digital pin of the board, using software to replicate the functionality of the hardware UART. It is possible to have multiple software serial ports with speeds up to 115200 bps.
|
||||||
|
category=Communication
|
||||||
|
url=http://www.arduino.cc/en/Reference/SoftwareSerial
|
||||||
|
architectures=MIK32_Amur
|
||||||
|
|
||||||
361
libraries/SoftwareSerial/src/SoftwareSerial.cpp
Normal file
361
libraries/SoftwareSerial/src/SoftwareSerial.cpp
Normal file
@ -0,0 +1,361 @@
|
|||||||
|
/*
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
The latest version of this library can always be found at
|
||||||
|
http://arduiniana.org.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
#include "wiring_LL.h"
|
||||||
|
|
||||||
|
#define MAX_SOFT_SERIAL_SPEED 115200
|
||||||
|
#define MIN_SOFT_SERIAL_SPEED 300
|
||||||
|
|
||||||
|
// Statics
|
||||||
|
// static variable is common to all class instances
|
||||||
|
SoftwareSerial *SoftwareSerial::active_object = 0;
|
||||||
|
uint8_t SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
|
||||||
|
volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0;
|
||||||
|
volatile uint8_t SoftwareSerial::_receive_buffer_head = 0;
|
||||||
|
|
||||||
|
// Private methods
|
||||||
|
|
||||||
|
// function placed in ram. Should not call other function placed in flash
|
||||||
|
void SoftwareSerial::tunedDelay(uint32_t delayTicks) // .ram_text
|
||||||
|
{
|
||||||
|
if (delayTicks > 1)
|
||||||
|
{
|
||||||
|
uint64_t startTicks = SYSTICK_GET_TICKS();
|
||||||
|
while ((SYSTICK_GET_TICKS() - startTicks) < delayTicks)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function sets the current object as the "listening"
|
||||||
|
// one and returns true if it replaces another
|
||||||
|
bool SoftwareSerial::listen()
|
||||||
|
{
|
||||||
|
if (!_rx_delay_stopbit)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (active_object != this)
|
||||||
|
{
|
||||||
|
if (active_object)
|
||||||
|
active_object->stopListening();
|
||||||
|
|
||||||
|
_buffer_overflow = false;
|
||||||
|
_receive_buffer_head = _receive_buffer_tail = 0;
|
||||||
|
active_object = this;
|
||||||
|
|
||||||
|
setRxIntMsk(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop listening. Returns true if we were actually listening.
|
||||||
|
bool SoftwareSerial::stopListening()
|
||||||
|
{
|
||||||
|
if (active_object == this)
|
||||||
|
{
|
||||||
|
setRxIntMsk(false);
|
||||||
|
active_object = NULL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// The receive routine called by the interrupt handler
|
||||||
|
//
|
||||||
|
void SoftwareSerial::recv() // .ram_text
|
||||||
|
{
|
||||||
|
// If RX line is high, then we don't see any start bit
|
||||||
|
// so interrupt is probably not for us
|
||||||
|
bool rxState = (bool)GPIO_READ_PIN((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receiveBitMask);
|
||||||
|
if (_inverse_logic ? rxState : !rxState)
|
||||||
|
{
|
||||||
|
// Disable further interrupts during reception, this prevents triggering another interrupt
|
||||||
|
// directly after we return, which can cause problems at higher baudrates.
|
||||||
|
setRxIntMsk(false); // __always_inline__
|
||||||
|
|
||||||
|
// Wait approximately 1/2 of a bit width to "center" the sample
|
||||||
|
if (_rx_delay_centering > 0)
|
||||||
|
tunedDelay(_rx_delay_centering); // .ram_text
|
||||||
|
|
||||||
|
// Read each of the 8 bits
|
||||||
|
uint8_t data = 0;
|
||||||
|
for (uint8_t i=8; i > 0; --i)
|
||||||
|
{
|
||||||
|
tunedDelay(_rx_delay_intrabit);
|
||||||
|
data >>= 1;
|
||||||
|
if (GPIO_READ_PIN((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receiveBitMask))
|
||||||
|
data |= 0x80;
|
||||||
|
}
|
||||||
|
if (_inverse_logic)
|
||||||
|
data = ~data;
|
||||||
|
|
||||||
|
// if buffer full, set the overflow flag and return
|
||||||
|
uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
|
||||||
|
if (next != _receive_buffer_head)
|
||||||
|
{
|
||||||
|
// save new data in buffer: tail points to where byte goes
|
||||||
|
_receive_buffer[_receive_buffer_tail] = data; // save new byte
|
||||||
|
_receive_buffer_tail = next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_buffer_overflow = true;
|
||||||
|
|
||||||
|
// skip the stop bit
|
||||||
|
tunedDelay(_rx_delay_stopbit);
|
||||||
|
|
||||||
|
// Re-enable interrupts when we're sure to be inside the stop bit
|
||||||
|
setRxIntMsk(true);
|
||||||
|
}
|
||||||
|
GPIO_IRQ_CLEAR_ALL();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t SoftwareSerial::rx_pin_read()
|
||||||
|
{
|
||||||
|
return (uint8_t)GPIO_READ_PIN((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receiveBitMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interrupt handling
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
void SoftwareSerial::handle_interrupt() // .ram_text
|
||||||
|
{
|
||||||
|
if (active_object)
|
||||||
|
{
|
||||||
|
active_object->recv(); // .ram_text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void __attribute__((noinline, section(".ram_text"))) softSerial_interrupt_handler(void)
|
||||||
|
{
|
||||||
|
SoftwareSerial::handle_interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Constructor
|
||||||
|
//
|
||||||
|
SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) :
|
||||||
|
_rx_delay_centering(0),
|
||||||
|
_rx_delay_intrabit(0),
|
||||||
|
_rx_delay_stopbit(0),
|
||||||
|
_tx_delay(0),
|
||||||
|
_buffer_overflow(false),
|
||||||
|
_inverse_logic(inverse_logic)
|
||||||
|
{
|
||||||
|
_transmitPin = transmitPin;
|
||||||
|
_receivePin = receivePin;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Destructor
|
||||||
|
//
|
||||||
|
SoftwareSerial::~SoftwareSerial()
|
||||||
|
{
|
||||||
|
end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftwareSerial::setTX(uint8_t tx)
|
||||||
|
{
|
||||||
|
// save pin and port info
|
||||||
|
_transmitBitMask = (uint16_t)digitalPinToBitMask(tx);
|
||||||
|
_transmitPortRegister = (uint32_t)digitalPinToPort(tx);
|
||||||
|
// set state before tx pin initialization to prevent false start bit
|
||||||
|
if (_inverse_logic)
|
||||||
|
GPIO_CLEAR_PIN((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)_transmitBitMask);
|
||||||
|
else
|
||||||
|
GPIO_SET_PIN((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)_transmitBitMask);
|
||||||
|
// init pin as output
|
||||||
|
pinMode(tx, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftwareSerial::setRX(uint8_t rx)
|
||||||
|
{
|
||||||
|
// save pin, port and gpio_line info
|
||||||
|
_receiveBitMask = (uint16_t)digitalPinToBitMask(rx);
|
||||||
|
_receivePortRegister = (uint32_t)digitalPinToPort(rx);
|
||||||
|
_int_maskLine = digitalPinToGpioIntLine(_receivePin);
|
||||||
|
|
||||||
|
// attach interrupt to rx pin if available
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_receivePin), softSerial_interrupt_handler, _inverse_logic ? RISING : FALLING);
|
||||||
|
// turn on pull up for rx if logic is not inverse
|
||||||
|
if (!_inverse_logic)
|
||||||
|
{
|
||||||
|
uint8_t pinNumber = PIN_MASK_TO_PIN_NUMBER(_receiveBitMask);
|
||||||
|
if (((GPIO_TypeDef*)_receivePortRegister) == GPIO_0)
|
||||||
|
PIN_SET_PAD_CONFIG(PORT_0_PUPD, pinNumber, HAL_GPIO_PULL_UP);
|
||||||
|
else if (((GPIO_TypeDef*)_receivePortRegister) == GPIO_1)
|
||||||
|
PIN_SET_PAD_CONFIG(PORT_1_PUPD, pinNumber, HAL_GPIO_PULL_UP);
|
||||||
|
}
|
||||||
|
// turn off int line for while (it turning on in attachInterrupt())
|
||||||
|
GPIO_IRQ_LINE_DISABLE(_int_maskLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t SoftwareSerial::subtract_cap(uint32_t num, uint16_t sub)
|
||||||
|
{
|
||||||
|
if (num > sub)
|
||||||
|
return num - sub;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Public methods
|
||||||
|
//
|
||||||
|
void SoftwareSerial::begin(long speed)
|
||||||
|
{
|
||||||
|
// delays are empirical values here
|
||||||
|
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
|
||||||
|
|
||||||
|
// limit speed
|
||||||
|
if (speed > MAX_SOFT_SERIAL_SPEED) speed = MAX_SOFT_SERIAL_SPEED;
|
||||||
|
if (speed < MIN_SOFT_SERIAL_SPEED) speed = MIN_SOFT_SERIAL_SPEED;
|
||||||
|
|
||||||
|
// Precalculate the various delays in number of ticks
|
||||||
|
uint32_t bit_delay = F_CPU / speed;
|
||||||
|
|
||||||
|
// init tx
|
||||||
|
setTX(_transmitPin);
|
||||||
|
_tx_delay = subtract_cap(bit_delay, 35); // 1 bit delay while transmitting data
|
||||||
|
|
||||||
|
// init rx only when we have a valid INT for this pin
|
||||||
|
if (digitalPinToInterrupt(_receivePin) != NOT_AN_INTERRUPT)
|
||||||
|
{
|
||||||
|
// set pin config
|
||||||
|
setRX(_receivePin);
|
||||||
|
|
||||||
|
// We want to have a total delay of 1.5 bit time from start bit. Inside the loop, we already
|
||||||
|
// wait for 1 bit time, so here we wait for 0.5 bit time
|
||||||
|
_rx_delay_centering = subtract_cap(bit_delay / 2, 315);
|
||||||
|
|
||||||
|
// 1 bit time
|
||||||
|
_rx_delay_intrabit = subtract_cap(bit_delay, 60);
|
||||||
|
|
||||||
|
// This delay aims at 3/4 of a bit time, meaning the end of the delay will be at 1/4th of the stopbit.
|
||||||
|
// This allows some extra time for ISR cleanup, which makes 115200 baud at 16Mhz work more reliably
|
||||||
|
_rx_delay_stopbit = subtract_cap(bit_delay * 3 / 4, 142);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ErrorMsgHandler("SoftwareSerial.begin(): Rx pin does not support interrupts, use different pin");
|
||||||
|
|
||||||
|
tunedDelay(_tx_delay); // if we were low this establishes the end
|
||||||
|
|
||||||
|
listen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftwareSerial::setRxIntMsk(bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
GPIO_IRQ_LINE_ENABLE(_int_maskLine);
|
||||||
|
else
|
||||||
|
GPIO_IRQ_LINE_DISABLE(_int_maskLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftwareSerial::end()
|
||||||
|
{
|
||||||
|
stopListening();
|
||||||
|
}
|
||||||
|
|
||||||
|
// function placed in ram. Should not call other function placed in flash
|
||||||
|
size_t SoftwareSerial::write(uint8_t byte)
|
||||||
|
{
|
||||||
|
if (_tx_delay == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (_inverse_logic)
|
||||||
|
byte = ~byte;
|
||||||
|
|
||||||
|
GLOBAL_IRQ_DISABLE(); // turn off interrupts for a clean txmit
|
||||||
|
|
||||||
|
// Write the start bit
|
||||||
|
if (_inverse_logic)
|
||||||
|
GPIO_SET_PIN((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)_transmitBitMask);
|
||||||
|
else
|
||||||
|
GPIO_CLEAR_PIN((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)_transmitBitMask);
|
||||||
|
tunedDelay(_tx_delay); // wait start bit
|
||||||
|
|
||||||
|
// Write each of the 8 bits in LSB mode
|
||||||
|
for (uint8_t i = 8; i > 0; --i)
|
||||||
|
{
|
||||||
|
if (byte & 1) // choose bit
|
||||||
|
GPIO_SET_PIN((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)_transmitBitMask);
|
||||||
|
else
|
||||||
|
GPIO_CLEAR_PIN((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)_transmitBitMask);
|
||||||
|
tunedDelay(_tx_delay);
|
||||||
|
byte >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore pin to natural state - stop bit
|
||||||
|
if (_inverse_logic)
|
||||||
|
GPIO_CLEAR_PIN((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)_transmitBitMask);
|
||||||
|
else
|
||||||
|
GPIO_SET_PIN((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)_transmitBitMask);
|
||||||
|
|
||||||
|
// enable interrupts
|
||||||
|
GLOBAL_IRQ_ENABLE();
|
||||||
|
|
||||||
|
tunedDelay(_tx_delay); // wait stop bit
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read data from buffer
|
||||||
|
int SoftwareSerial::read()
|
||||||
|
{
|
||||||
|
if (!isListening())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Empty buffer?
|
||||||
|
if (_receive_buffer_head == _receive_buffer_tail)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Read from "head"
|
||||||
|
uint8_t data = _receive_buffer[_receive_buffer_head]; // grab next byte
|
||||||
|
_receive_buffer_head = (_receive_buffer_head + 1) % _SS_MAX_RX_BUFF;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SoftwareSerial::available()
|
||||||
|
{
|
||||||
|
if (!isListening())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return ((unsigned int)(_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head)) % _SS_MAX_RX_BUFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftwareSerial::flush()
|
||||||
|
{
|
||||||
|
// There is no tx buffering, simply return
|
||||||
|
}
|
||||||
|
|
||||||
|
int SoftwareSerial::peek()
|
||||||
|
{
|
||||||
|
if (!isListening())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Empty buffer?
|
||||||
|
if (_receive_buffer_head == _receive_buffer_tail)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Read from "head"
|
||||||
|
return _receive_buffer[_receive_buffer_head];
|
||||||
|
}
|
||||||
109
libraries/SoftwareSerial/src/SoftwareSerial.h
Normal file
109
libraries/SoftwareSerial/src/SoftwareSerial.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
SoftwareSerial.h
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
The latest version of this library can always be found at
|
||||||
|
http://arduiniana.org.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SoftwareSerial_h
|
||||||
|
#define SoftwareSerial_h
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <Stream.h>
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _SS_MAX_RX_BUFF
|
||||||
|
#define _SS_MAX_RX_BUFF 64 // RX buffer size
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef GCC_VERSION
|
||||||
|
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class SoftwareSerial : public Stream
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// per object data
|
||||||
|
uint8_t _receivePin;
|
||||||
|
uint16_t _receiveBitMask;
|
||||||
|
uint32_t _receivePortRegister;
|
||||||
|
uint8_t _transmitPin;
|
||||||
|
uint16_t _transmitBitMask;
|
||||||
|
uint32_t _transmitPortRegister;
|
||||||
|
uint8_t _int_maskLine;
|
||||||
|
|
||||||
|
// must never be 0!
|
||||||
|
uint32_t _rx_delay_centering;
|
||||||
|
uint32_t _rx_delay_intrabit;
|
||||||
|
uint32_t _rx_delay_stopbit;
|
||||||
|
uint32_t _tx_delay;
|
||||||
|
|
||||||
|
uint16_t _buffer_overflow:1;
|
||||||
|
uint16_t _inverse_logic:1;
|
||||||
|
|
||||||
|
// static data
|
||||||
|
static uint8_t _receive_buffer[_SS_MAX_RX_BUFF];
|
||||||
|
static volatile uint8_t _receive_buffer_tail;
|
||||||
|
static volatile uint8_t _receive_buffer_head;
|
||||||
|
static SoftwareSerial *active_object;
|
||||||
|
|
||||||
|
// private methods
|
||||||
|
void recv() __attribute__((noinline, section(".ram_text")));
|
||||||
|
uint8_t rx_pin_read();
|
||||||
|
void setTX(uint8_t transmitPin);
|
||||||
|
void setRX(uint8_t receivePin);
|
||||||
|
inline void setRxIntMsk(bool enable) __attribute__((__always_inline__));
|
||||||
|
|
||||||
|
// Return num - sub, or 1 if the result would be < 1
|
||||||
|
static uint32_t subtract_cap(uint32_t num, uint16_t sub);
|
||||||
|
|
||||||
|
// private static method for timing
|
||||||
|
static void tunedDelay(uint32_t delayTicks) __attribute__((noinline, section(".ram_text")));
|
||||||
|
|
||||||
|
public:
|
||||||
|
// public methods
|
||||||
|
SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
|
||||||
|
~SoftwareSerial();
|
||||||
|
void begin(long speed);
|
||||||
|
bool listen();
|
||||||
|
void end();
|
||||||
|
bool isListening() { return this == active_object; }
|
||||||
|
bool stopListening();
|
||||||
|
bool overflow()
|
||||||
|
{
|
||||||
|
bool ret = _buffer_overflow;
|
||||||
|
if (ret)
|
||||||
|
_buffer_overflow = false;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
int peek();
|
||||||
|
|
||||||
|
virtual size_t write(uint8_t byte) __attribute__((noinline, section(".ram_text")));
|
||||||
|
virtual int read();
|
||||||
|
virtual int available();
|
||||||
|
virtual void flush();
|
||||||
|
operator bool() { return true; }
|
||||||
|
|
||||||
|
using Print::write;
|
||||||
|
|
||||||
|
// public only for easy access by interrupt handlers
|
||||||
|
static void handle_interrupt() __attribute__((noinline, section(".ram_text")));
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -309,7 +309,7 @@ void TwoWire::onRequest( void (*function)(void) )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// С function for trap handler
|
// С function for trap handler
|
||||||
extern "C" void wire_handler_wrapper(void)
|
extern "C" void __attribute__((optimize("O3"))) wire_interrupt_handler(void)
|
||||||
{
|
{
|
||||||
twi_interruptHandler();
|
twi_interruptHandler();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -323,7 +323,7 @@ void twi_attachSlaveTxEvent( void (*function)(void) )
|
|||||||
* Input none
|
* Input none
|
||||||
* Output none
|
* Output none
|
||||||
*/
|
*/
|
||||||
void twi_interruptHandler(void)
|
void __attribute__((optimize("O3"))) twi_interruptHandler(void)
|
||||||
{
|
{
|
||||||
uint32_t int_mask = HAL_I2C_Get_CR1_Content(&hi2c) & I2C_INTMASK; // interrupts allowed
|
uint32_t int_mask = HAL_I2C_Get_CR1_Content(&hi2c) & I2C_INTMASK; // interrupts allowed
|
||||||
uint32_t interrupt_status = HAL_I2C_Get_Interrupts_Status(&hi2c); // current flags
|
uint32_t interrupt_status = HAL_I2C_Get_Interrupts_Status(&hi2c); // current flags
|
||||||
|
|||||||
@ -15,7 +15,7 @@ compiler.elf2hex.cmd={compiler.prefix}objcopy
|
|||||||
|
|
||||||
# Include directories and defines
|
# Include directories and defines
|
||||||
compiler.MIK32_Amur.extra_include= "-I{build.core.path}/avr/" "-I{build.core.path}/mik32/shared/include/" "-I{build.core.path}/mik32/shared/periphery/" "-I{build.core.path}/mik32/shared/runtime/" "-I{build.core.path}/mik32/shared/libs/" "-I{build.core.path}/mik32/hal/core/Include/" "-I{build.core.path}/mik32/hal/peripherals/Include/" "-I{build.core.path}/mik32/hal/utilities/Include/"
|
compiler.MIK32_Amur.extra_include= "-I{build.core.path}/avr/" "-I{build.core.path}/mik32/shared/include/" "-I{build.core.path}/mik32/shared/periphery/" "-I{build.core.path}/mik32/shared/runtime/" "-I{build.core.path}/mik32/shared/libs/" "-I{build.core.path}/mik32/hal/core/Include/" "-I{build.core.path}/mik32/hal/peripherals/Include/" "-I{build.core.path}/mik32/hal/utilities/Include/"
|
||||||
compiler.define="-DMCU_{build.mcu}" "-DF_CPU={build.f_cpu}" "-DARDUINO={runtime.ide.version}" "-DARDUINO_{build.board}" "-DARDUINO_ARCH_{build.arch}" "-DMIK32V2" "-D__ELBEAR_ACE_UNO__" "-D__RISC_V__" "-D__ARDUINO_ARC__" "-D__CPU_ARC__"
|
compiler.define="-DMCU_{build.mcu}" "-DF_CPU={build.f_cpu}" "-DARDUINO={runtime.ide.version}" "-DARDUINO_{build.board}" "-DARDUINO_ARCH_{build.arch}" "-DMIK32V2" "-D__ARDUINO_ARC__" "-D__CPU_ARC__"
|
||||||
|
|
||||||
build.flags.optimize=-Os
|
build.flags.optimize=-Os
|
||||||
build.ldscript=spifi_cpp.ld
|
build.ldscript=spifi_cpp.ld
|
||||||
@ -46,7 +46,7 @@ archive_file_path={build.path}/{archive_file}
|
|||||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}"
|
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}"
|
||||||
|
|
||||||
# Combine gc-sections, archives, and objects
|
# Combine gc-sections, archives, and objects
|
||||||
recipe.c.combine.pattern= "{compiler.path}{compiler.c.elf.cmd}" -o "{build.path}/{build.project_name}.elf" -T "{build.core.path}/mik32/shared/ldscripts/{build.ldscript}" {compiler.c.elf.flags} -Map={build.path}/{build.project_name}.map -Wl,--gc-sections "-L{build.path}" -Wl,--start-group {object_files} -Wl,--whole-archive "{archive_file_path}" -Wl,--no-whole-archive -lc -Wl,--end-group
|
recipe.c.combine.pattern= "{compiler.path}{compiler.c.elf.cmd}" -o "{build.path}/{build.project_name}.elf" -T "{build.core.path}/mik32/shared/ldscripts/{build.ldscript}" {compiler.c.elf.flags} -Map={build.path}/{build.project_name}.map -Wl,--gc-sections -Wl,--no-warn-rwx-segments "-L{build.path}" -Wl,--start-group {object_files} -Wl,--whole-archive "{archive_file_path}" -Wl,--no-whole-archive -lc -Wl,--end-group
|
||||||
|
|
||||||
# Create output (.bin file)
|
# Create output (.bin file)
|
||||||
recipe.objcopy.bin.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.elf2bin.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
|
recipe.objcopy.bin.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.elf2bin.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
|
||||||
|
|||||||
@ -109,16 +109,24 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
|||||||
#define WIRE_FREQ_1000K 1000000
|
#define WIRE_FREQ_1000K 1000000
|
||||||
|
|
||||||
// interrupts
|
// interrupts
|
||||||
|
extern uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3];
|
||||||
// determines the board pin number by interrupt number
|
// determines the board pin number by interrupt number
|
||||||
uint32_t interruptToDigitalPin(uint8_t interruptNum);
|
#define interruptToDigitalPin(interruptNum) (interruptInfo[interruptNum][0])
|
||||||
|
// determines gpio interrupt line by interrupt number
|
||||||
|
#define interruptToGpioIntLine(interruptNum) ((uint8_t)interruptInfo[interruptNum][1])
|
||||||
|
// determines gpio interrupt mux by interrupt number
|
||||||
|
#define interruptToGpioIntMux(interruptNum) ((uint8_t)interruptInfo[interruptNum][2])
|
||||||
// determines interrupt number by the board pin number
|
// determines interrupt number by the board pin number
|
||||||
int8_t digitalPinToInterrupt(uint32_t digPinNumber);
|
int8_t digitalPinToInterrupt(uint32_t digPinNumber);
|
||||||
// determines gpio interrupt line by interrupt number
|
|
||||||
uint32_t interruptToGpioIntLine(uint8_t interruptNum);
|
|
||||||
// determines interrupt number by the gpio interrupt line
|
// determines interrupt number by the gpio interrupt line
|
||||||
int8_t gpioIntLineToInterrupt(uint32_t gpioIntLine);
|
int8_t gpioIntLineToInterrupt(uint32_t gpioIntLine);
|
||||||
// determines gpio interrupt mux by interrupt number
|
// determines gpio interrupt mux by the board pin number
|
||||||
uint32_t interruptToGpioIntMux(uint8_t interruptNum);
|
int8_t digitalPinToGpioIntMux(uint8_t digPinNumber);
|
||||||
|
// determines gpio interrupt line by the board pin number
|
||||||
|
int8_t digitalPinToGpioIntLine(uint8_t digPinNumber);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
#include "mik32_hal_adc.h"
|
#include "mik32_hal_adc.h"
|
||||||
#include "wiring_analog.h"
|
#include "wiring_analog.h"
|
||||||
|
#include "wiring_LL.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -107,10 +108,6 @@ volatile uint32_t* portInputRegister(GPIO_TypeDef* GPIO_x)
|
|||||||
return &GPIO_x->STATE;
|
return &GPIO_x->STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return config of pin with pinShift(0...16) in portReg (config, pupd, ds for ports 0...2)
|
|
||||||
#define PIN_PAD_CONFIG(portReg, pinShift) ((PAD_CONFIG->portReg >> (pinShift<<1)) & 0b11)
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------- ADC ---------------------- //
|
// ---------------------- ADC ---------------------- //
|
||||||
// determines the ADC channel number by the board pin number
|
// determines the ADC channel number by the board pin number
|
||||||
uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
||||||
@ -168,9 +165,9 @@ bool digitalPinPwmIsOn(uint8_t digitalPin)
|
|||||||
uint8_t pinShift = pwmPinToGpioPinShift(digitalPin);
|
uint8_t pinShift = pwmPinToGpioPinShift(digitalPin);
|
||||||
|
|
||||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
||||||
config = PIN_PAD_CONFIG(PORT_0_CFG, pinShift);
|
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||||
else
|
else
|
||||||
config = PIN_PAD_CONFIG(PORT_1_CFG, pinShift);
|
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||||
|
|
||||||
if (config == 2)
|
if (config == 2)
|
||||||
return true;
|
return true;
|
||||||
@ -216,9 +213,9 @@ HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- interrupts ---------------------- //
|
// ---------------------- interrupts ---------------------- //
|
||||||
// interrupt table
|
// interrupt table is stored in ram to improve performance
|
||||||
// index = interrupt number. In each row {digitalPinNumber, IntLineValue, IntMuxValue}
|
// index = interrupt number. In each row {digitalPinNumber, IntLineValue, IntMuxValue}
|
||||||
const uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3] =
|
uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3] =
|
||||||
{
|
{
|
||||||
{ 2, GPIO_LINE_2, GPIO_MUX_LINE_2_PORT0_10}, // INT0
|
{ 2, GPIO_LINE_2, GPIO_MUX_LINE_2_PORT0_10}, // INT0
|
||||||
{ 3, GPIO_LINE_0, GPIO_MUX_LINE_0_PORT0_0}, // INT1
|
{ 3, GPIO_LINE_0, GPIO_MUX_LINE_0_PORT0_0}, // INT1
|
||||||
@ -229,19 +226,23 @@ const uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3] =
|
|||||||
{BTN_BUILTIN, GPIO_LINE_6, GPIO_MUX_LINE_6_PORT2_6}, // INT6 (button)
|
{BTN_BUILTIN, GPIO_LINE_6, GPIO_MUX_LINE_6_PORT2_6}, // INT6 (button)
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t interruptToDigitalPin(uint8_t interruptNum)
|
int8_t digitalPinToGpioIntMux(uint8_t digPinNumber)
|
||||||
{
|
{
|
||||||
return interruptInfo[interruptNum][0];
|
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
|
||||||
|
{
|
||||||
|
if (interruptInfo[i][0] == digPinNumber)
|
||||||
|
return interruptInfo[i][2];
|
||||||
|
}
|
||||||
|
return NOT_AN_INTERRUPT;
|
||||||
}
|
}
|
||||||
|
int8_t digitalPinToGpioIntLine(uint8_t digPinNumber)
|
||||||
uint32_t interruptToGpioIntLine(uint8_t interruptNum)
|
|
||||||
{
|
{
|
||||||
return (uint32_t)interruptInfo[interruptNum][1];
|
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
|
||||||
}
|
{
|
||||||
|
if (interruptInfo[i][0] == digPinNumber)
|
||||||
uint32_t interruptToGpioIntMux(uint8_t interruptNum)
|
return interruptInfo[i][1];
|
||||||
{
|
}
|
||||||
return (uint32_t)interruptInfo[interruptNum][2];
|
return NOT_AN_INTERRUPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t gpioIntLineToInterrupt(uint32_t gpioIntLine)
|
int8_t gpioIntLineToInterrupt(uint32_t gpioIntLine)
|
||||||
@ -265,25 +266,20 @@ int8_t digitalPinToInterrupt(uint32_t digPinNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- SPI ---------------------- //
|
// ---------------------- SPI ---------------------- //
|
||||||
// pins shift in registers
|
|
||||||
#define PIN_3_SHIFT 3
|
|
||||||
#define PIN_4_SHIFT 4
|
|
||||||
#define PORT1_GET_PAD_PUPD(pinShift) ((PAD_CONFIG->PORT_1_PUPD >> (pinShift<<1)) & 0b11)
|
|
||||||
#define PORT1_GET_GPIO_STATE(pinShift) ((GPIO_1->OUTPUT_ >> pinShift) & 0b1)
|
|
||||||
|
|
||||||
void spi_onBegin(void)
|
void spi_onBegin(void)
|
||||||
{
|
{
|
||||||
// On Elbear Ace-Uno rev1.1.0 there is a seller on pin 1.6 which replace D10 from spi NSS pin 1.3 to pin 1.4,
|
// On Elbear Ace-Uno rev1.1.0 there is a seller on pin 1.6 which replace D10 from spi NSS pin 1.3 to pin 1.4,
|
||||||
// because spi needs pin 1.3 for correct work
|
// because spi needs pin 1.3 for correct work
|
||||||
|
|
||||||
// replace config from 1.3 to 1.4
|
// replace config from 1.3 to 1.4
|
||||||
uint8_t config = PIN_PAD_CONFIG(PORT_1_CFG, PIN_3_SHIFT);
|
uint8_t config = PIN_GET_PAD_CONFIG(PORT_1_CFG, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_3));
|
||||||
if (config == 0) // common gpio
|
if (config == 0) // common gpio
|
||||||
{
|
{
|
||||||
// get info from pin gpio1.3 and set config to gpio1.4
|
// get info from pin gpio1.3 and set config to gpio1.4
|
||||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_4, HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_3),
|
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_4, HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_3),
|
||||||
(HAL_GPIO_PullTypeDef)PORT1_GET_PAD_PUPD(PIN_3_SHIFT), HAL_GPIO_DS_2MA);
|
(HAL_GPIO_PullTypeDef)PIN_GET_PAD_CONFIG(PORT_1_PUPD, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_3)),
|
||||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_4, (GPIO_PinState)PORT1_GET_GPIO_STATE(PIN_3_SHIFT));
|
HAL_GPIO_DS_2MA);
|
||||||
|
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_4, (GPIO_PinState)GPIO_GET_PIN_STATE(GPIO_1, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_3)));
|
||||||
|
|
||||||
// pin D10 was switched to different gpio and can be used further
|
// pin D10 was switched to different gpio and can be used further
|
||||||
}
|
}
|
||||||
@ -304,8 +300,8 @@ void spi_onEnd(void)
|
|||||||
{
|
{
|
||||||
// get info from pin gpio1.4 and set config to gpio1.3
|
// get info from pin gpio1.4 and set config to gpio1.3
|
||||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_3, HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_4),
|
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_3, HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_4),
|
||||||
(HAL_GPIO_PullTypeDef)PORT1_GET_PAD_PUPD(PIN_4_SHIFT), HAL_GPIO_DS_2MA);
|
(HAL_GPIO_PullTypeDef)PIN_GET_PAD_CONFIG(PORT_1_PUPD, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_4)), HAL_GPIO_DS_2MA);
|
||||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_3, (GPIO_PinState)PORT1_GET_GPIO_STATE(PIN_4_SHIFT));
|
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_3, (GPIO_PinState)GPIO_GET_PIN_STATE(GPIO_1, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_4)));
|
||||||
|
|
||||||
// switch seller back to pin 1.3
|
// switch seller back to pin 1.3
|
||||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_6, GPIO_PIN_LOW);
|
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_6, GPIO_PIN_LOW);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user