123
Fork of LG by
DeviceServicePort.c@149:abbf7663d27d, 2016-05-03 (annotated)
- Committer:
- Diletant
- Date:
- Tue May 03 05:12:26 2016 +0000
- Revision:
- 149:abbf7663d27d
- Child:
- 156:e68ee0bcdcda
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 | 149:abbf7663d27d | 13 | void InitServicePortWithDefaults(void) |
Diletant | 149:abbf7663d27d | 14 | { |
Diletant | 149:abbf7663d27d | 15 | device.service.port.transmitter.baudRate = 921600; |
Diletant | 149:abbf7663d27d | 16 | } |
Diletant | 149:abbf7663d27d | 17 | |
Diletant | 149:abbf7663d27d | 18 | void InitServicePort(void){ |
Diletant | 149:abbf7663d27d | 19 | uint32_t Fdiv; |
Diletant | 149:abbf7663d27d | 20 | uint32_t pclkdiv, pclk; |
Diletant | 149:abbf7663d27d | 21 | |
Diletant | 149:abbf7663d27d | 22 | LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */ |
Diletant | 149:abbf7663d27d | 23 | LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */ |
Diletant | 149:abbf7663d27d | 24 | |
Diletant | 149:abbf7663d27d | 25 | /* By default, the PCLKSELx value is zero, thus, the PCLK for all the peripherals is 1/4 of the SystemFrequency. */ |
Diletant | 149:abbf7663d27d | 26 | /* Bit 6,7 are for UART0 */ |
Diletant | 149:abbf7663d27d | 27 | pclkdiv = (LPC_SC->PCLKSEL0 >> 6) & 0x03; |
Diletant | 149:abbf7663d27d | 28 | switch ( pclkdiv ) { |
Diletant | 149:abbf7663d27d | 29 | case 0x00: |
Diletant | 149:abbf7663d27d | 30 | default: |
Diletant | 149:abbf7663d27d | 31 | pclk = SystemCoreClock1/4; |
Diletant | 149:abbf7663d27d | 32 | break; |
Diletant | 149:abbf7663d27d | 33 | case 0x01: |
Diletant | 149:abbf7663d27d | 34 | pclk = SystemCoreClock1; |
Diletant | 149:abbf7663d27d | 35 | break; |
Diletant | 149:abbf7663d27d | 36 | case 0x02: |
Diletant | 149:abbf7663d27d | 37 | pclk = SystemCoreClock1/2; |
Diletant | 149:abbf7663d27d | 38 | break; |
Diletant | 149:abbf7663d27d | 39 | case 0x03: |
Diletant | 149:abbf7663d27d | 40 | pclk = SystemCoreClock1/8; |
Diletant | 149:abbf7663d27d | 41 | break; |
Diletant | 149:abbf7663d27d | 42 | } |
Diletant | 149:abbf7663d27d | 43 | |
Diletant | 149:abbf7663d27d | 44 | device.service.port.LCR = 0x83; |
Diletant | 149:abbf7663d27d | 45 | LPC_UART0->LCR = device.service.port.LCR; |
Diletant | 149:abbf7663d27d | 46 | |
Diletant | 149:abbf7663d27d | 47 | Fdiv = ((pclk / 16) / device.service.port.transmitter.baudRate) + 1; |
Diletant | 149:abbf7663d27d | 48 | |
Diletant | 149:abbf7663d27d | 49 | device.service.port.DLM = Fdiv / 256; |
Diletant | 149:abbf7663d27d | 50 | LPC_UART0->DLM = device.service.port.DLM; |
Diletant | 149:abbf7663d27d | 51 | device.service.port.DLL = Fdiv % 256; |
Diletant | 149:abbf7663d27d | 52 | LPC_UART0->DLL = device.service.port.DLL; |
Diletant | 149:abbf7663d27d | 53 | |
Diletant | 149:abbf7663d27d | 54 | device.service.port.LCR = 0x03; |
Diletant | 149:abbf7663d27d | 55 | LPC_UART0->LCR = device.service.port.LCR; |
Diletant | 149:abbf7663d27d | 56 | device.service.port.FCR = 0x07; |
Diletant | 149:abbf7663d27d | 57 | LPC_UART0->FCR = device.service.port.FCR; |
Diletant | 149:abbf7663d27d | 58 | } |
Diletant | 149:abbf7663d27d | 59 | |
Diletant | 149:abbf7663d27d | 60 | void Concole(void) |
Diletant | 149:abbf7663d27d | 61 | { |
Diletant | 149:abbf7663d27d | 62 | if (ConOutPnt != ConOutCur) |
Diletant | 149:abbf7663d27d | 63 | if (LPC_UART0->LSR & 0x20){ |
Diletant | 149:abbf7663d27d | 64 | LPC_UART0->THR = OutCon[ConOutCur]; |
Diletant | 149:abbf7663d27d | 65 | ConOutCur++; |
Diletant | 149:abbf7663d27d | 66 | ConOutCur = ConOutCur & 0x3ff; |
Diletant | 149:abbf7663d27d | 67 | } |
Diletant | 149:abbf7663d27d | 68 | if (LPC_UART0->LSR & 0x01){ |
Diletant | 149:abbf7663d27d | 69 | InCon[ConInCur] = (LPC_UART0->RBR); |
Diletant | 149:abbf7663d27d | 70 | ConInCur++; |
Diletant | 149:abbf7663d27d | 71 | ConInCur = ConInCur & 0x3ff; |
Diletant | 149:abbf7663d27d | 72 | } |
Diletant | 149:abbf7663d27d | 73 | } |
Diletant | 149:abbf7663d27d | 74 | |
Diletant | 149:abbf7663d27d | 75 | int ReadConcole(char *s) |
Diletant | 149:abbf7663d27d | 76 | { |
Diletant | 149:abbf7663d27d | 77 | int i = 0; |
Diletant | 149:abbf7663d27d | 78 | while (ConInPnt != ConInCur){ |
Diletant | 149:abbf7663d27d | 79 | (*s++) = InCon[ConInPnt]; |
Diletant | 149:abbf7663d27d | 80 | ConInPnt++; ConInPnt = ConInPnt & 0x3ff; |
Diletant | 149:abbf7663d27d | 81 | i++; |
Diletant | 149:abbf7663d27d | 82 | } |
Diletant | 149:abbf7663d27d | 83 | (*s++) = 0; |
Diletant | 149:abbf7663d27d | 84 | return i; |
Diletant | 149:abbf7663d27d | 85 | } |
Diletant | 149:abbf7663d27d | 86 | |
Diletant | 149:abbf7663d27d | 87 | void WriteConcole(char *s) |
Diletant | 149:abbf7663d27d | 88 | { |
Diletant | 149:abbf7663d27d | 89 | while (*s != 0){ |
Diletant | 149:abbf7663d27d | 90 | OutCon[ConOutPnt] = (*s++); |
Diletant | 149:abbf7663d27d | 91 | ConOutPnt++; ConOutPnt = ConOutPnt & 0x3ff; |
Diletant | 149:abbf7663d27d | 92 | } |
Diletant | 149:abbf7663d27d | 93 | } |