![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
configs.cpp@33:735fd60e96d8, 2014-09-30 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 30 11:37:31 2014 +0000
- Revision:
- 33:735fd60e96d8
- Parent:
- 26:725cbbedadd5
- Child:
- 74:81c47fff88a5
versao 1 do protocolo de comunicao udp pra comunicao externa com a header e consequentemente, criacao do bootloader
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "configs.h" |
klauss | 0:4d17cd9c8f9d | 2 | #include "mbed.h" |
klauss | 0:4d17cd9c8f9d | 3 | #include <stdint.h> |
klauss | 0:4d17cd9c8f9d | 4 | #include "UART3Interrupt.h" |
klauss | 0:4d17cd9c8f9d | 5 | #include "parallelcpld.h" |
klauss | 0:4d17cd9c8f9d | 6 | |
klauss | 26:725cbbedadd5 | 7 | QSPIFileSystem qspifs("qspi"); // file system |
klauss | 33:735fd60e96d8 | 8 | Watchdog wdt; |
klauss | 26:725cbbedadd5 | 9 | |
klauss | 0:4d17cd9c8f9d | 10 | //***************************************************************************** |
klauss | 0:4d17cd9c8f9d | 11 | // Pins/Modules Config |
klauss | 0:4d17cd9c8f9d | 12 | //***************************************************************************** |
klauss | 0:4d17cd9c8f9d | 13 | |
klauss | 0:4d17cd9c8f9d | 14 | DigitalOut led1(LED1); |
klauss | 0:4d17cd9c8f9d | 15 | DigitalOut led2(LED2); |
klauss | 0:4d17cd9c8f9d | 16 | DigitalOut led3(LED3); |
klauss | 0:4d17cd9c8f9d | 17 | DigitalOut led4(LED4); |
Cola | 22:d2a4b5939115 | 18 | DigitalOut CAB_LED(p24); |
klauss | 0:4d17cd9c8f9d | 19 | |
klauss | 0:4d17cd9c8f9d | 20 | DigitalOut DataReady(p11); //IO 27 |
klauss | 0:4d17cd9c8f9d | 21 | |
klauss | 0:4d17cd9c8f9d | 22 | DigitalOut data0(p30); //LSB |
klauss | 0:4d17cd9c8f9d | 23 | DigitalOut data1(p31); |
klauss | 0:4d17cd9c8f9d | 24 | DigitalOut data2(p32); |
klauss | 0:4d17cd9c8f9d | 25 | DigitalOut data3(p33); |
klauss | 0:4d17cd9c8f9d | 26 | DigitalOut data4(p34); |
klauss | 0:4d17cd9c8f9d | 27 | DigitalOut data5(p37); |
klauss | 0:4d17cd9c8f9d | 28 | DigitalOut data6(p38); |
klauss | 0:4d17cd9c8f9d | 29 | DigitalOut data7(p39); //MSB |
klauss | 0:4d17cd9c8f9d | 30 | |
klauss | 0:4d17cd9c8f9d | 31 | InterruptIn NextData(p8); //IO 96 |
klauss | 0:4d17cd9c8f9d | 32 | InterruptIn FrameSync(p17); // GCLK1 |
klauss | 0:4d17cd9c8f9d | 33 | |
klauss | 0:4d17cd9c8f9d | 34 | //Ticker ticker; // Timer para Debug |
klauss | 0:4d17cd9c8f9d | 35 | |
klauss | 0:4d17cd9c8f9d | 36 | DigitalOut RST(p29); // Pino de reset para o CPLD |
klauss | 0:4d17cd9c8f9d | 37 | DigitalIn PPD(p25); // Pino de conexao com o cristal do CPLD |
klauss | 0:4d17cd9c8f9d | 38 | |
klauss | 0:4d17cd9c8f9d | 39 | DigitalOut ENABLE_F_REG(p18); // Configuracao da Alimentacao do CPLD |
klauss | 0:4d17cd9c8f9d | 40 | DigitalOut ENABLE_F_RX(p19); |
klauss | 0:4d17cd9c8f9d | 41 | DigitalOut ENABLE_F_TX(p20); |
klauss | 0:4d17cd9c8f9d | 42 | |
klauss | 0:4d17cd9c8f9d | 43 | Serial Uart3(p9,p10); // default baudrate = 9600; Sem paridade, 8bits, 1 stop-bit |
klauss | 0:4d17cd9c8f9d | 44 | Serial pc (USBTX,USBRX); |
klauss | 0:4d17cd9c8f9d | 45 | |
klauss | 0:4d17cd9c8f9d | 46 | void start_cpld( void ) { //CPLD Start |
klauss | 0:4d17cd9c8f9d | 47 | |
klauss | 18:01a93677e40c | 48 | static uint16_t reset = 10000; |
klauss | 0:4d17cd9c8f9d | 49 | ENABLE_F_REG = 1; |
klauss | 0:4d17cd9c8f9d | 50 | ENABLE_F_TX = 1; |
klauss | 0:4d17cd9c8f9d | 51 | ENABLE_F_RX = 1; |
klauss | 0:4d17cd9c8f9d | 52 | DataReady = 0; |
klauss | 0:4d17cd9c8f9d | 53 | RST = 1; |
klauss | 26:725cbbedadd5 | 54 | while( reset-- > 1 ){} |
klauss | 0:4d17cd9c8f9d | 55 | RST = 0; |
klauss | 0:4d17cd9c8f9d | 56 | } |
klauss | 0:4d17cd9c8f9d | 57 | |
klauss | 0:4d17cd9c8f9d | 58 | void config_lpc( void ) { // Configure LPC4088 |
klauss | 0:4d17cd9c8f9d | 59 | |
klauss | 0:4d17cd9c8f9d | 60 | Uart3.attach(&SerialRecvInterrupt, Uart3.RxIrq); // UART3_IRQ configuration |
klauss | 0:4d17cd9c8f9d | 61 | Uart3.format(8,SerialBase::Forced1,1); // UART3 mode configuration |
klauss | 0:4d17cd9c8f9d | 62 | Uart3.baud(2000000); |
klauss | 0:4d17cd9c8f9d | 63 | NVIC_SetPriority(UART3_IRQn,1); |
klauss | 0:4d17cd9c8f9d | 64 | pc.baud(115200); // USART to PC USB USART |
klauss | 0:4d17cd9c8f9d | 65 | NextData.rise(&get2); // Extern Pin Interrupt |
klauss | 0:4d17cd9c8f9d | 66 | FrameSync.rise(&RXFrameSync); // FrameSync for RX - Interrupt |
klauss | 0:4d17cd9c8f9d | 67 | __enable_irq(); |
klauss | 0:4d17cd9c8f9d | 68 | //ticker.attach(&timer,0.01); // Timer para Debug |
klauss | 0:4d17cd9c8f9d | 69 | } |
klauss | 0:4d17cd9c8f9d | 70 | |
klauss | 0:4d17cd9c8f9d | 71 | static uint8_t itoh[16]; |
klauss | 0:4d17cd9c8f9d | 72 | static uint8_t hexbuf[10]; |
klauss | 0:4d17cd9c8f9d | 73 | |
klauss | 0:4d17cd9c8f9d | 74 | uint8_t *hextoascii ( uint8_t src ) { |
klauss | 0:4d17cd9c8f9d | 75 | |
klauss | 0:4d17cd9c8f9d | 76 | hexbuf[0] = itoh[(src>>4) & 0x0f]; |
klauss | 0:4d17cd9c8f9d | 77 | hexbuf[1] = itoh[src & 0x0f]; |
klauss | 0:4d17cd9c8f9d | 78 | hexbuf[2] = 0; |
klauss | 0:4d17cd9c8f9d | 79 | return hexbuf; |
klauss | 0:4d17cd9c8f9d | 80 | |
klauss | 0:4d17cd9c8f9d | 81 | } |
klauss | 0:4d17cd9c8f9d | 82 | |
klauss | 0:4d17cd9c8f9d | 83 | void uart3_puts(uint8_t *src, uint16_t size){ // Print a string in UART3 |
klauss | 0:4d17cd9c8f9d | 84 | while (size--){ |
klauss | 0:4d17cd9c8f9d | 85 | while ( !(LPC_UART3->LSR &= (1<<5)) ) {} |
klauss | 0:4d17cd9c8f9d | 86 | LPC_UART3->THR = *src++; |
klauss | 0:4d17cd9c8f9d | 87 | } |
klauss | 0:4d17cd9c8f9d | 88 | } |
klauss | 0:4d17cd9c8f9d | 89 | |
klauss | 0:4d17cd9c8f9d | 90 | void uart0_puts( uint8_t *src) { // Print a string in UART3 |
klauss | 0:4d17cd9c8f9d | 91 | |
klauss | 0:4d17cd9c8f9d | 92 | uint16_t size = 300; |
klauss | 0:4d17cd9c8f9d | 93 | |
klauss | 0:4d17cd9c8f9d | 94 | while (size--){ |
klauss | 0:4d17cd9c8f9d | 95 | while ( !(LPC_UART0->LSR & (1<<5)) ) {} |
klauss | 0:4d17cd9c8f9d | 96 | LPC_UART0->THR = *src++; |
klauss | 0:4d17cd9c8f9d | 97 | } |
klauss | 0:4d17cd9c8f9d | 98 | } |
klauss | 0:4d17cd9c8f9d | 99 | |
klauss | 0:4d17cd9c8f9d | 100 | void uart0_putsx(volatile uint8_t *src ){ // Print a string in UART0 |
klauss | 0:4d17cd9c8f9d | 101 | uint16_t size = 300;//sizeof( src ); |
klauss | 0:4d17cd9c8f9d | 102 | uint8_t *buff; |
klauss | 0:4d17cd9c8f9d | 103 | while (size--) |
klauss | 0:4d17cd9c8f9d | 104 | { |
klauss | 0:4d17cd9c8f9d | 105 | buff = hextoascii(*(src++)); |
klauss | 0:4d17cd9c8f9d | 106 | for ( uint8_t i = 0; i < 3; i++ ){ |
klauss | 0:4d17cd9c8f9d | 107 | while ( !(LPC_UART0->LSR &= (1<<5)) ) {} |
klauss | 0:4d17cd9c8f9d | 108 | LPC_UART0->THR = buff[i]; //*src++; |
klauss | 0:4d17cd9c8f9d | 109 | } |
klauss | 0:4d17cd9c8f9d | 110 | } |
klauss | 0:4d17cd9c8f9d | 111 | } |
klauss | 0:4d17cd9c8f9d | 112 | |
klauss | 0:4d17cd9c8f9d | 113 | void uart0_text( const char* src){ // Print a string of constant in UART0 |
klauss | 0:4d17cd9c8f9d | 114 | static uint16_t size; |
klauss | 0:4d17cd9c8f9d | 115 | size = sizeof (src); |
klauss | 0:4d17cd9c8f9d | 116 | while (size--){ |
klauss | 0:4d17cd9c8f9d | 117 | while ( !(LPC_UART0->LSR &= (1<<5)) ) {} |
klauss | 0:4d17cd9c8f9d | 118 | LPC_UART0->THR = *src++; |
klauss | 0:4d17cd9c8f9d | 119 | } |
klauss | 0:4d17cd9c8f9d | 120 | } |
klauss | 0:4d17cd9c8f9d | 121 | |
klauss | 0:4d17cd9c8f9d | 122 | void xstrcpy(uint8_t * dest, const uint8_t * src) { |
klauss | 0:4d17cd9c8f9d | 123 | while (*src) *dest++ = *src++; |
klauss | 0:4d17cd9c8f9d | 124 | *dest = 0; |
klauss | 0:4d17cd9c8f9d | 125 | } |
klauss | 0:4d17cd9c8f9d | 126 | |
klauss | 0:4d17cd9c8f9d | 127 | void xmemcpy(uint8_t * dest, uint8_t * src, uint16_t size){ |
klauss | 0:4d17cd9c8f9d | 128 | while (size--) *dest++ = *src++; |
klauss | 0:4d17cd9c8f9d | 129 | } |