123
Fork of LG by
DeviceServicePort.c@167:bedc0a9d559a, 2016-06-05 (annotated)
- Committer:
- Diletant
- Date:
- Sun Jun 05 11:03:33 2016 +0000
- Revision:
- 167:bedc0a9d559a
- Parent:
- 156:e68ee0bcdcda
- Child:
- 182:2bd8ec44998f
Device & ... update. Not final!!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Diletant | 149:abbf7663d27d | 1 | #include "Device.h" |
Diletant | 149:abbf7663d27d | 2 | extern Device device; |
Diletant | 149:abbf7663d27d | 3 | extern unsigned int SystemCoreClock1; |
Diletant | 149:abbf7663d27d | 4 | |
Diletant | 149:abbf7663d27d | 5 | extern char InCon[1024]; |
Diletant | 149:abbf7663d27d | 6 | extern char OutCon[1024]; |
Diletant | 149:abbf7663d27d | 7 | |
Diletant | 149:abbf7663d27d | 8 | extern unsigned int ConInPnt; |
Diletant | 149:abbf7663d27d | 9 | extern unsigned int ConInCur; |
Diletant | 149:abbf7663d27d | 10 | extern unsigned int ConOutPnt; |
Diletant | 149:abbf7663d27d | 11 | extern unsigned int ConOutCur; |
Diletant | 149:abbf7663d27d | 12 | |
Diletant | 167:bedc0a9d559a | 13 | void InitServicePortDefaultSettings(void) { |
Diletant | 156:e68ee0bcdcda | 14 | device.controller.uart[0].settings.baudRate = 921600; |
Diletant | 149:abbf7663d27d | 15 | } |
Diletant | 149:abbf7663d27d | 16 | |
Diletant | 167:bedc0a9d559a | 17 | void InitServicePortState(void){ |
Diletant | 167:bedc0a9d559a | 18 | } |
Diletant | 167:bedc0a9d559a | 19 | |
Diletant | 167:bedc0a9d559a | 20 | void DeviceStartServicePort(void){ |
Diletant | 149:abbf7663d27d | 21 | uint32_t Fdiv; |
Diletant | 149:abbf7663d27d | 22 | uint32_t pclkdiv, pclk; |
Diletant | 149:abbf7663d27d | 23 | |
Diletant | 149:abbf7663d27d | 24 | LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */ |
Diletant | 149:abbf7663d27d | 25 | LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */ |
Diletant | 149:abbf7663d27d | 26 | |
Diletant | 149:abbf7663d27d | 27 | /* By default, the PCLKSELx value is zero, thus, the PCLK for all the peripherals is 1/4 of the SystemFrequency. */ |
Diletant | 149:abbf7663d27d | 28 | /* Bit 6,7 are for UART0 */ |
Diletant | 149:abbf7663d27d | 29 | pclkdiv = (LPC_SC->PCLKSEL0 >> 6) & 0x03; |
Diletant | 149:abbf7663d27d | 30 | switch ( pclkdiv ) { |
Diletant | 149:abbf7663d27d | 31 | case 0x00: |
Diletant | 149:abbf7663d27d | 32 | default: |
Diletant | 149:abbf7663d27d | 33 | pclk = SystemCoreClock1/4; |
Diletant | 149:abbf7663d27d | 34 | break; |
Diletant | 149:abbf7663d27d | 35 | case 0x01: |
Diletant | 149:abbf7663d27d | 36 | pclk = SystemCoreClock1; |
Diletant | 149:abbf7663d27d | 37 | break; |
Diletant | 149:abbf7663d27d | 38 | case 0x02: |
Diletant | 149:abbf7663d27d | 39 | pclk = SystemCoreClock1/2; |
Diletant | 149:abbf7663d27d | 40 | break; |
Diletant | 149:abbf7663d27d | 41 | case 0x03: |
Diletant | 149:abbf7663d27d | 42 | pclk = SystemCoreClock1/8; |
Diletant | 149:abbf7663d27d | 43 | break; |
Diletant | 149:abbf7663d27d | 44 | } |
Diletant | 149:abbf7663d27d | 45 | |
Diletant | 156:e68ee0bcdcda | 46 | device.controller.uart[0].state.LCR = 0x83; |
Diletant | 156:e68ee0bcdcda | 47 | LPC_UART0->LCR = device.controller.uart[0].state.LCR; |
Diletant | 149:abbf7663d27d | 48 | |
Diletant | 156:e68ee0bcdcda | 49 | Fdiv = ((pclk / 16) / device.controller.uart[0].settings.baudRate) + 1; |
Diletant | 149:abbf7663d27d | 50 | |
Diletant | 156:e68ee0bcdcda | 51 | device.controller.uart[0].state.DLM = Fdiv / 256; |
Diletant | 156:e68ee0bcdcda | 52 | LPC_UART0->DLM = device.controller.uart[0].state.DLM; |
Diletant | 156:e68ee0bcdcda | 53 | device.controller.uart[0].state.DLL = Fdiv % 256; |
Diletant | 156:e68ee0bcdcda | 54 | LPC_UART0->DLL = device.controller.uart[0].state.DLL; |
Diletant | 149:abbf7663d27d | 55 | |
Diletant | 156:e68ee0bcdcda | 56 | device.controller.uart[0].state.LCR = 0x03; |
Diletant | 156:e68ee0bcdcda | 57 | LPC_UART0->LCR = device.controller.uart[0].state.LCR; |
Diletant | 156:e68ee0bcdcda | 58 | device.controller.uart[0].state.FCR = 0x07; |
Diletant | 156:e68ee0bcdcda | 59 | LPC_UART0->FCR = device.controller.uart[0].state.FCR; |
Diletant | 149:abbf7663d27d | 60 | } |
Diletant | 149:abbf7663d27d | 61 | |
Diletant | 149:abbf7663d27d | 62 | void Concole(void) |
Diletant | 149:abbf7663d27d | 63 | { |
Diletant | 149:abbf7663d27d | 64 | if (ConOutPnt != ConOutCur) |
Diletant | 149:abbf7663d27d | 65 | if (LPC_UART0->LSR & 0x20){ |
Diletant | 149:abbf7663d27d | 66 | LPC_UART0->THR = OutCon[ConOutCur]; |
Diletant | 149:abbf7663d27d | 67 | ConOutCur++; |
Diletant | 149:abbf7663d27d | 68 | ConOutCur = ConOutCur & 0x3ff; |
Diletant | 149:abbf7663d27d | 69 | } |
Diletant | 149:abbf7663d27d | 70 | if (LPC_UART0->LSR & 0x01){ |
Diletant | 149:abbf7663d27d | 71 | InCon[ConInCur] = (LPC_UART0->RBR); |
Diletant | 149:abbf7663d27d | 72 | ConInCur++; |
Diletant | 149:abbf7663d27d | 73 | ConInCur = ConInCur & 0x3ff; |
Diletant | 149:abbf7663d27d | 74 | } |
Diletant | 149:abbf7663d27d | 75 | } |
Diletant | 149:abbf7663d27d | 76 | |
Diletant | 156:e68ee0bcdcda | 77 | int ReadConcole(void) |
Diletant | 149:abbf7663d27d | 78 | { |
Diletant | 156:e68ee0bcdcda | 79 | uint16_t i = 0; |
Diletant | 149:abbf7663d27d | 80 | while (ConInPnt != ConInCur){ |
Diletant | 156:e68ee0bcdcda | 81 | device.service.buffer[i] = InCon[ConInPnt]; |
Diletant | 156:e68ee0bcdcda | 82 | //(*s++) = InCon[ConInPnt]; |
Diletant | 149:abbf7663d27d | 83 | ConInPnt++; ConInPnt = ConInPnt & 0x3ff; |
Diletant | 149:abbf7663d27d | 84 | i++; |
Diletant | 149:abbf7663d27d | 85 | } |
Diletant | 156:e68ee0bcdcda | 86 | //(*s++) = 0; |
Diletant | 156:e68ee0bcdcda | 87 | device.service.buffer[i] = 0; |
Diletant | 149:abbf7663d27d | 88 | return i; |
Diletant | 149:abbf7663d27d | 89 | } |
Diletant | 149:abbf7663d27d | 90 | |
Diletant | 156:e68ee0bcdcda | 91 | //void WriteConcole(char *s) |
Diletant | 156:e68ee0bcdcda | 92 | void WriteConcole(void) { |
Diletant | 156:e68ee0bcdcda | 93 | uint16_t i = 0; |
Diletant | 156:e68ee0bcdcda | 94 | //while (*s != 0){ |
Diletant | 156:e68ee0bcdcda | 95 | while (device.service.buffer[i] != 0){ |
Diletant | 156:e68ee0bcdcda | 96 | //OutCon[ConOutPnt] = (*s++); |
Diletant | 156:e68ee0bcdcda | 97 | OutCon[ConOutPnt] = device.service.buffer[i]; |
Diletant | 149:abbf7663d27d | 98 | ConOutPnt++; ConOutPnt = ConOutPnt & 0x3ff; |
Diletant | 156:e68ee0bcdcda | 99 | i++; |
Diletant | 149:abbf7663d27d | 100 | } |
Diletant | 149:abbf7663d27d | 101 | } |