![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
host/Source/App/console.c@23:12e6183f04d4, 2016-02-03 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Feb 03 10:44:42 2016 +0300
- Revision:
- 23:12e6183f04d4
[thyz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kovalev_D |
23:12e6183f04d4 | 1 | #include "console.h" |
Kovalev_D |
23:12e6183f04d4 | 2 | #include "lpc17xx.h" |
Kovalev_D |
23:12e6183f04d4 | 3 | #include "CyclesSync.h" |
Kovalev_D |
23:12e6183f04d4 | 4 | #define FOSC 12000000 |
Kovalev_D |
23:12e6183f04d4 | 5 | |
Kovalev_D |
23:12e6183f04d4 | 6 | #define FCCLK (FOSC * 8) |
Kovalev_D |
23:12e6183f04d4 | 7 | |
Kovalev_D |
23:12e6183f04d4 | 8 | #define FCCO (FCCLK * 3) |
Kovalev_D |
23:12e6183f04d4 | 9 | |
Kovalev_D |
23:12e6183f04d4 | 10 | #define FPCLK (FCCLK / 4) |
Kovalev_D |
23:12e6183f04d4 | 11 | |
Kovalev_D |
23:12e6183f04d4 | 12 | #define UART0_BPS 38400 |
Kovalev_D |
23:12e6183f04d4 | 13 | |
Kovalev_D |
23:12e6183f04d4 | 14 | |
Kovalev_D |
23:12e6183f04d4 | 15 | |
Kovalev_D |
23:12e6183f04d4 | 16 | unsigned int BuffOut[1024]; |
Kovalev_D |
23:12e6183f04d4 | 17 | |
Kovalev_D |
23:12e6183f04d4 | 18 | unsigned int InputIndexBO; |
Kovalev_D |
23:12e6183f04d4 | 19 | unsigned int OutputIndexBO; |
Kovalev_D |
23:12e6183f04d4 | 20 | |
Kovalev_D |
23:12e6183f04d4 | 21 | |
Kovalev_D |
23:12e6183f04d4 | 22 | |
Kovalev_D |
23:12e6183f04d4 | 23 | unsigned int BuffIn[1024]; |
Kovalev_D |
23:12e6183f04d4 | 24 | |
Kovalev_D |
23:12e6183f04d4 | 25 | unsigned int InputIndexBI; |
Kovalev_D |
23:12e6183f04d4 | 26 | unsigned int OutputIndexBI; |
Kovalev_D |
23:12e6183f04d4 | 27 | |
Kovalev_D |
23:12e6183f04d4 | 28 | //unsigned int OLD_OutputIndex; |
Kovalev_D |
23:12e6183f04d4 | 29 | |
Kovalev_D |
23:12e6183f04d4 | 30 | void UART0_Init_m (void)///èíèéöèàëèçàöèÿ íóëåâîãî óàðòà |
Kovalev_D |
23:12e6183f04d4 | 31 | { |
Kovalev_D |
23:12e6183f04d4 | 32 | uint16_t usFdiv; |
Kovalev_D |
23:12e6183f04d4 | 33 | /* UART0 */ |
Kovalev_D |
23:12e6183f04d4 | 34 | LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */ |
Kovalev_D |
23:12e6183f04d4 | 35 | LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */ |
Kovalev_D |
23:12e6183f04d4 | 36 | |
Kovalev_D |
23:12e6183f04d4 | 37 | LPC_UART0->LCR = 0x83; |
Kovalev_D |
23:12e6183f04d4 | 38 | usFdiv = (FPCLK / 16) / UART0_BPS; |
Kovalev_D |
23:12e6183f04d4 | 39 | LPC_UART0->DLM = usFdiv / 256; |
Kovalev_D |
23:12e6183f04d4 | 40 | LPC_UART0->DLL = usFdiv % 256; |
Kovalev_D |
23:12e6183f04d4 | 41 | LPC_UART0->LCR = 0x03; |
Kovalev_D |
23:12e6183f04d4 | 42 | LPC_UART0->FCR = 0x06; |
Kovalev_D |
23:12e6183f04d4 | 43 | } |
Kovalev_D |
23:12e6183f04d4 | 44 | |
Kovalev_D |
23:12e6183f04d4 | 45 | int UART0_SendByte_m (int ucData) |
Kovalev_D |
23:12e6183f04d4 | 46 | { |
Kovalev_D |
23:12e6183f04d4 | 47 | //while (!(LPC_UART0->LSR & 0x20)){}; |
Kovalev_D |
23:12e6183f04d4 | 48 | |
Kovalev_D |
23:12e6183f04d4 | 49 | return (LPC_UART0->THR = ucData); |
Kovalev_D |
23:12e6183f04d4 | 50 | } |
Kovalev_D |
23:12e6183f04d4 | 51 | void ClearBuffout(void) //î÷èñòêà áóôåðà íà âûäà÷ó(ñáðîñ óêàçàòåëåé) |
Kovalev_D |
23:12e6183f04d4 | 52 | { |
Kovalev_D |
23:12e6183f04d4 | 53 | InputIndexBO=0; |
Kovalev_D |
23:12e6183f04d4 | 54 | OutputIndexBO=0; |
Kovalev_D |
23:12e6183f04d4 | 55 | } |
Kovalev_D |
23:12e6183f04d4 | 56 | void SendToBuffByte(unsigned int *input) // çàïèñü â áóôåð íà âûäà÷ó îäíîãî çíà÷åíèÿ èíò(áåççíàêîâîãî) |
Kovalev_D |
23:12e6183f04d4 | 57 | { |
Kovalev_D |
23:12e6183f04d4 | 58 | InputIndexBO++; |
Kovalev_D |
23:12e6183f04d4 | 59 | InputIndexBO &= 0x3ff; |
Kovalev_D |
23:12e6183f04d4 | 60 | BuffOut[InputIndexBO]=*input; |
Kovalev_D |
23:12e6183f04d4 | 61 | } |
Kovalev_D |
23:12e6183f04d4 | 62 | void SendToBuff(unsigned char *input, unsigned int size)//çàïèñü íåñêîëüêèõ çíà÷åíèé ñ óêàçàíèåì ðàçìåðíîñòè çàïèñè â áóôåð íà âûäà÷ó. |
Kovalev_D |
23:12e6183f04d4 | 63 | { |
Kovalev_D |
23:12e6183f04d4 | 64 | unsigned int i; |
Kovalev_D |
23:12e6183f04d4 | 65 | for(i=0;i<size;i++) |
Kovalev_D |
23:12e6183f04d4 | 66 | { |
Kovalev_D |
23:12e6183f04d4 | 67 | InputIndexBO++; |
Kovalev_D |
23:12e6183f04d4 | 68 | InputIndexBO &= 0x3ff; |
Kovalev_D |
23:12e6183f04d4 | 69 | BuffOut[InputIndexBO]=*input++; |
Kovalev_D |
23:12e6183f04d4 | 70 | } |
Kovalev_D |
23:12e6183f04d4 | 71 | } |
Kovalev_D |
23:12e6183f04d4 | 72 | |
Kovalev_D |
23:12e6183f04d4 | 73 | |
Kovalev_D |
23:12e6183f04d4 | 74 | void SendToBuffStr(char *s)//çàïèñü ñòðîêè (êîíåö îòñëåæèâàåòñÿ ïî íóëþ) â áóôåð íà âûäà÷ó. |
Kovalev_D |
23:12e6183f04d4 | 75 | { |
Kovalev_D |
23:12e6183f04d4 | 76 | while (*s != 0) |
Kovalev_D |
23:12e6183f04d4 | 77 | { |
Kovalev_D |
23:12e6183f04d4 | 78 | InputIndexBO++; |
Kovalev_D |
23:12e6183f04d4 | 79 | InputIndexBO &= 0x3ff; |
Kovalev_D |
23:12e6183f04d4 | 80 | BuffOut[InputIndexBO]=*s++; |
Kovalev_D |
23:12e6183f04d4 | 81 | } |
Kovalev_D |
23:12e6183f04d4 | 82 | } |
Kovalev_D |
23:12e6183f04d4 | 83 | |
Kovalev_D |
23:12e6183f04d4 | 84 | |
Kovalev_D |
23:12e6183f04d4 | 85 | void TakeFromBuff(void)//ïåðåäà÷à èç áóôåðà íà âûäà÷ó. |
Kovalev_D |
23:12e6183f04d4 | 86 | { |
Kovalev_D |
23:12e6183f04d4 | 87 | if((OutputIndexBO != InputIndexBO) && (LPC_UART0 -> LSR & 0x20)) |
Kovalev_D |
23:12e6183f04d4 | 88 | { |
Kovalev_D |
23:12e6183f04d4 | 89 | OutputIndexBO++; |
Kovalev_D |
23:12e6183f04d4 | 90 | OutputIndexBO &= 0x3ff; |
Kovalev_D |
23:12e6183f04d4 | 91 | LPC_UART0->THR = BuffOut[OutputIndexBO]; |
Kovalev_D |
23:12e6183f04d4 | 92 | } |
Kovalev_D |
23:12e6183f04d4 | 93 | } |
Kovalev_D |
23:12e6183f04d4 | 94 | |
Kovalev_D |
23:12e6183f04d4 | 95 | |
Kovalev_D |
23:12e6183f04d4 | 96 | |
Kovalev_D |
23:12e6183f04d4 | 97 | /* |
Kovalev_D |
23:12e6183f04d4 | 98 | void UART0_SendString (char *s) |
Kovalev_D |
23:12e6183f04d4 | 99 | { |
Kovalev_D |
23:12e6183f04d4 | 100 | while (*s != 0) |
Kovalev_D |
23:12e6183f04d4 | 101 | { |
Kovalev_D |
23:12e6183f04d4 | 102 | InputIndex++; |
Kovalev_D |
23:12e6183f04d4 | 103 | InputIndex &= 0x3ff; |
Kovalev_D |
23:12e6183f04d4 | 104 | BuffOut[InputIndex]=*s++; |
Kovalev_D |
23:12e6183f04d4 | 105 | } |
Kovalev_D |
23:12e6183f04d4 | 106 | } |
Kovalev_D |
23:12e6183f04d4 | 107 | */ |
Kovalev_D |
23:12e6183f04d4 | 108 | |
Kovalev_D |
23:12e6183f04d4 | 109 | void ClearBuffIn(void) |
Kovalev_D |
23:12e6183f04d4 | 110 | { |
Kovalev_D |
23:12e6183f04d4 | 111 | InputIndexBI=0; |
Kovalev_D |
23:12e6183f04d4 | 112 | OutputIndexBI=0; |
Kovalev_D |
23:12e6183f04d4 | 113 | } |
Kovalev_D |
23:12e6183f04d4 | 114 | |
Kovalev_D |
23:12e6183f04d4 | 115 | void BuffDataReady(void) |
Kovalev_D |
23:12e6183f04d4 | 116 | { |
Kovalev_D |
23:12e6183f04d4 | 117 | if((OutputIndexBI != InputIndexBI) && (!(LPC_UART0 -> LSR & 0x01))) |
Kovalev_D |
23:12e6183f04d4 | 118 | { |
Kovalev_D |
23:12e6183f04d4 | 119 | |
Kovalev_D |
23:12e6183f04d4 | 120 | } |
Kovalev_D |
23:12e6183f04d4 | 121 | } |
Kovalev_D |
23:12e6183f04d4 | 122 | void ReadDataInBuff(void) |
Kovalev_D |
23:12e6183f04d4 | 123 | { |
Kovalev_D |
23:12e6183f04d4 | 124 | while (LPC_UART0->LSR & 0x01) |
Kovalev_D |
23:12e6183f04d4 | 125 | { |
Kovalev_D |
23:12e6183f04d4 | 126 | BuffIn[InputIndexBI] = LPC_UART0->RBR; |
Kovalev_D |
23:12e6183f04d4 | 127 | InputIndexBI++; |
Kovalev_D |
23:12e6183f04d4 | 128 | } |
Kovalev_D |
23:12e6183f04d4 | 129 | } |
Kovalev_D |
23:12e6183f04d4 | 130 | |
Kovalev_D |
23:12e6183f04d4 | 131 | |
Kovalev_D |
23:12e6183f04d4 | 132 | |
Kovalev_D |
23:12e6183f04d4 | 133 | |
Kovalev_D |
23:12e6183f04d4 | 134 | |
Kovalev_D |
23:12e6183f04d4 | 135 | |
Kovalev_D |
23:12e6183f04d4 | 136 | |
Kovalev_D |
23:12e6183f04d4 | 137 | |
Kovalev_D |
23:12e6183f04d4 | 138 | |
Kovalev_D |
23:12e6183f04d4 | 139 | |
Kovalev_D |
23:12e6183f04d4 | 140 | |
Kovalev_D |
23:12e6183f04d4 | 141 | |
Kovalev_D |
23:12e6183f04d4 | 142 | |
Kovalev_D |
23:12e6183f04d4 | 143 | |
Kovalev_D |
23:12e6183f04d4 | 144 | |
Kovalev_D |
23:12e6183f04d4 | 145 |