Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Committer:
Cola
Date:
Sat Sep 20 20:43:33 2014 +0000
Revision:
22:d2a4b5939115
Parent:
18:01a93677e40c
Child:
26:725cbbedadd5
20-09-14 - led externo;

Who changed what in which revision?

UserRevisionLine numberNew 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 0:4d17cd9c8f9d 7 //*****************************************************************************
klauss 0:4d17cd9c8f9d 8 // Pins/Modules Config
klauss 0:4d17cd9c8f9d 9 //*****************************************************************************
klauss 0:4d17cd9c8f9d 10
klauss 0:4d17cd9c8f9d 11 DigitalOut led1(LED1);
klauss 0:4d17cd9c8f9d 12 DigitalOut led2(LED2);
klauss 0:4d17cd9c8f9d 13 DigitalOut led3(LED3);
klauss 0:4d17cd9c8f9d 14 DigitalOut led4(LED4);
Cola 22:d2a4b5939115 15 DigitalOut CAB_LED(p24);
klauss 0:4d17cd9c8f9d 16
klauss 0:4d17cd9c8f9d 17 DigitalOut DataReady(p11); //IO 27
klauss 0:4d17cd9c8f9d 18
klauss 0:4d17cd9c8f9d 19 DigitalOut data0(p30); //LSB
klauss 0:4d17cd9c8f9d 20 DigitalOut data1(p31);
klauss 0:4d17cd9c8f9d 21 DigitalOut data2(p32);
klauss 0:4d17cd9c8f9d 22 DigitalOut data3(p33);
klauss 0:4d17cd9c8f9d 23 DigitalOut data4(p34);
klauss 0:4d17cd9c8f9d 24 DigitalOut data5(p37);
klauss 0:4d17cd9c8f9d 25 DigitalOut data6(p38);
klauss 0:4d17cd9c8f9d 26 DigitalOut data7(p39); //MSB
klauss 0:4d17cd9c8f9d 27
klauss 0:4d17cd9c8f9d 28 InterruptIn NextData(p8); //IO 96
klauss 0:4d17cd9c8f9d 29 InterruptIn FrameSync(p17); // GCLK1
klauss 0:4d17cd9c8f9d 30
klauss 0:4d17cd9c8f9d 31 //Ticker ticker; // Timer para Debug
klauss 0:4d17cd9c8f9d 32
klauss 0:4d17cd9c8f9d 33 DigitalOut RST(p29); // Pino de reset para o CPLD
klauss 0:4d17cd9c8f9d 34 DigitalIn PPD(p25); // Pino de conexao com o cristal do CPLD
klauss 0:4d17cd9c8f9d 35
klauss 0:4d17cd9c8f9d 36 DigitalOut ENABLE_F_REG(p18); // Configuracao da Alimentacao do CPLD
klauss 0:4d17cd9c8f9d 37 DigitalOut ENABLE_F_RX(p19);
klauss 0:4d17cd9c8f9d 38 DigitalOut ENABLE_F_TX(p20);
klauss 0:4d17cd9c8f9d 39
klauss 0:4d17cd9c8f9d 40 Serial Uart3(p9,p10); // default baudrate = 9600; Sem paridade, 8bits, 1 stop-bit
klauss 0:4d17cd9c8f9d 41 Serial pc (USBTX,USBRX);
klauss 0:4d17cd9c8f9d 42
klauss 0:4d17cd9c8f9d 43 void start_cpld( void ) { //CPLD Start
klauss 0:4d17cd9c8f9d 44
klauss 18:01a93677e40c 45 static uint16_t reset = 10000;
klauss 0:4d17cd9c8f9d 46 ENABLE_F_REG = 1;
klauss 0:4d17cd9c8f9d 47 ENABLE_F_TX = 1;
klauss 0:4d17cd9c8f9d 48 ENABLE_F_RX = 1;
klauss 0:4d17cd9c8f9d 49 DataReady = 0;
klauss 0:4d17cd9c8f9d 50 RST = 1;
klauss 18:01a93677e40c 51 while(reset--){}
klauss 0:4d17cd9c8f9d 52 RST = 0;
klauss 0:4d17cd9c8f9d 53 }
klauss 0:4d17cd9c8f9d 54
klauss 0:4d17cd9c8f9d 55 void config_lpc( void ) { // Configure LPC4088
klauss 0:4d17cd9c8f9d 56
klauss 0:4d17cd9c8f9d 57 Uart3.attach(&SerialRecvInterrupt, Uart3.RxIrq); // UART3_IRQ configuration
klauss 0:4d17cd9c8f9d 58 Uart3.format(8,SerialBase::Forced1,1); // UART3 mode configuration
klauss 0:4d17cd9c8f9d 59 Uart3.baud(2000000);
klauss 0:4d17cd9c8f9d 60 NVIC_SetPriority(UART3_IRQn,1);
klauss 0:4d17cd9c8f9d 61 pc.baud(115200); // USART to PC USB USART
klauss 0:4d17cd9c8f9d 62 NextData.rise(&get2); // Extern Pin Interrupt
klauss 0:4d17cd9c8f9d 63 FrameSync.rise(&RXFrameSync); // FrameSync for RX - Interrupt
klauss 0:4d17cd9c8f9d 64 __enable_irq();
klauss 0:4d17cd9c8f9d 65 //ticker.attach(&timer,0.01); // Timer para Debug
klauss 0:4d17cd9c8f9d 66 }
klauss 0:4d17cd9c8f9d 67
klauss 0:4d17cd9c8f9d 68 static uint8_t itoh[16];
klauss 0:4d17cd9c8f9d 69 static uint8_t hexbuf[10];
klauss 0:4d17cd9c8f9d 70
klauss 0:4d17cd9c8f9d 71 uint8_t *hextoascii ( uint8_t src ) {
klauss 0:4d17cd9c8f9d 72
klauss 0:4d17cd9c8f9d 73 hexbuf[0] = itoh[(src>>4) & 0x0f];
klauss 0:4d17cd9c8f9d 74 hexbuf[1] = itoh[src & 0x0f];
klauss 0:4d17cd9c8f9d 75 hexbuf[2] = 0;
klauss 0:4d17cd9c8f9d 76 return hexbuf;
klauss 0:4d17cd9c8f9d 77
klauss 0:4d17cd9c8f9d 78 }
klauss 0:4d17cd9c8f9d 79
klauss 0:4d17cd9c8f9d 80 void uart3_puts(uint8_t *src, uint16_t size){ // Print a string in UART3
klauss 0:4d17cd9c8f9d 81 while (size--){
klauss 0:4d17cd9c8f9d 82 while ( !(LPC_UART3->LSR &= (1<<5)) ) {}
klauss 0:4d17cd9c8f9d 83 LPC_UART3->THR = *src++;
klauss 0:4d17cd9c8f9d 84 }
klauss 0:4d17cd9c8f9d 85 }
klauss 0:4d17cd9c8f9d 86
klauss 0:4d17cd9c8f9d 87 void uart0_puts( uint8_t *src) { // Print a string in UART3
klauss 0:4d17cd9c8f9d 88
klauss 0:4d17cd9c8f9d 89 uint16_t size = 300;
klauss 0:4d17cd9c8f9d 90
klauss 0:4d17cd9c8f9d 91 while (size--){
klauss 0:4d17cd9c8f9d 92 while ( !(LPC_UART0->LSR & (1<<5)) ) {}
klauss 0:4d17cd9c8f9d 93 LPC_UART0->THR = *src++;
klauss 0:4d17cd9c8f9d 94 }
klauss 0:4d17cd9c8f9d 95 }
klauss 0:4d17cd9c8f9d 96
klauss 0:4d17cd9c8f9d 97 void uart0_putsx(volatile uint8_t *src ){ // Print a string in UART0
klauss 0:4d17cd9c8f9d 98 uint16_t size = 300;//sizeof( src );
klauss 0:4d17cd9c8f9d 99 uint8_t *buff;
klauss 0:4d17cd9c8f9d 100 while (size--)
klauss 0:4d17cd9c8f9d 101 {
klauss 0:4d17cd9c8f9d 102 buff = hextoascii(*(src++));
klauss 0:4d17cd9c8f9d 103 for ( uint8_t i = 0; i < 3; i++ ){
klauss 0:4d17cd9c8f9d 104 while ( !(LPC_UART0->LSR &= (1<<5)) ) {}
klauss 0:4d17cd9c8f9d 105 LPC_UART0->THR = buff[i]; //*src++;
klauss 0:4d17cd9c8f9d 106 }
klauss 0:4d17cd9c8f9d 107 }
klauss 0:4d17cd9c8f9d 108 }
klauss 0:4d17cd9c8f9d 109
klauss 0:4d17cd9c8f9d 110 void uart0_text( const char* src){ // Print a string of constant in UART0
klauss 0:4d17cd9c8f9d 111 static uint16_t size;
klauss 0:4d17cd9c8f9d 112 size = sizeof (src);
klauss 0:4d17cd9c8f9d 113 while (size--){
klauss 0:4d17cd9c8f9d 114 while ( !(LPC_UART0->LSR &= (1<<5)) ) {}
klauss 0:4d17cd9c8f9d 115 LPC_UART0->THR = *src++;
klauss 0:4d17cd9c8f9d 116 }
klauss 0:4d17cd9c8f9d 117 }
klauss 0:4d17cd9c8f9d 118
klauss 0:4d17cd9c8f9d 119 void xstrcpy(uint8_t * dest, const uint8_t * src) {
klauss 0:4d17cd9c8f9d 120 while (*src) *dest++ = *src++;
klauss 0:4d17cd9c8f9d 121 *dest = 0;
klauss 0:4d17cd9c8f9d 122 }
klauss 0:4d17cd9c8f9d 123
klauss 0:4d17cd9c8f9d 124 void xmemcpy(uint8_t * dest, uint8_t * src, uint16_t size){
klauss 0:4d17cd9c8f9d 125 while (size--) *dest++ = *src++;
klauss 0:4d17cd9c8f9d 126 }