void uart3_init (void) { __disable_irqn(UART3_IRQn); /* Enable UART3 module */ __set_PCONP(PCUART3, 1); __set_PCLKSEL(PCLK_UART3, PCLKDIV); /* Initialize UART */ U3LCR = 0x83; /* Select baud rate divisor latch */ U3DLM = DLVAL3 / 256; /* Set BRG dividers */ U3DLL = DLVAL3 % 256; U3FDR = (MULVAL << 4) | DIVADD; U3LCR = 0x03; /* Set serial format N81 and deselect divisor latch */ U3FCR = 0x87; /* Enable FIFO */ U3TER = 0x80; /* Enable Tansmission */ /* Clear Tx/Rx buffers */ TxBuff3.ri = 0; TxBuff3.wi = 0; TxBuff3.ct = 0; TxBuff3.act = 0; RxBuff3.ri = 0; RxBuff3.wi = 0; RxBuff3.ct = 0; /* Attach UART3 to I/O pad */ __set_PINSEL(0, 1, 2); /* P0.1 - TXD3 */\ __set_PINSEL(0, 0, 2); /* P0.0 - RXD3 */\ /* Enable Tx/Rx/Error interrupts */ U3IER = 0x07; __enable_irqn(UART3_IRQn); }
void uart1_init (void) { __disable_irqn(UART1_IRQn); /* Enable UART1 module */ __set_PCONP(PCUART1, 1); __set_PCLKSEL(PCLK_UART1, PCLKDIV); /* Initialize UART */ U1LCR = 0x83; /* Select baud rate divisor latch */ U1DLM = DLVAL1 / 256; /* Set BRG dividers */ U1DLL = DLVAL1 % 256; U1FDR = (MULVAL << 4) | DIVADD; U1LCR = 0x03; /* Set serial format N81 and deselect divisor latch */ U1FCR = 0x87; /* Enable FIFO */ U1TER = 0x80; /* Enable Tansmission */ /* Clear Tx/Rx buffers */ TxBuff1.ri = 0; TxBuff1.wi = 0; TxBuff1.ct = 0; TxBuff1.act = 0; RxBuff1.ri = 0; RxBuff1.wi = 0; RxBuff1.ct = 0; /* Attach UART1 to I/O pad */ __set_PINSEL(0, 16, 1); /* P0.16 - RXD1 */\ __set_PINSEL(0, 15, 1); /* P0.15 - TXD1 */\ /* Enable Tx/Rx/Error interrupts */ U1IER = 0x07; __enable_irqn(UART1_IRQn); }
void uart2_init (void) { __disable_irqn(UART2_IRQn); /* Enable UART2 module */ __set_PCONP(PCUART2, 1); __set_PCLKSEL(PCLK_UART2, PCLKDIV); /* Initialize UART */ U2LCR = 0x83; /* Select baud rate divisor latch */ U2DLM = DLVAL2 / 256; /* Set BRG dividers */ U2DLL = DLVAL2 % 256; U2FDR = (MULVAL << 4) | DIVADD; U2LCR = 0x03; /* Set serial format N81 and deselect divisor latch */ U2FCR = 0x87; /* Enable FIFO */ U2TER = 0x80; /* Enable Tansmission */ /* Clear Tx/Rx buffers */ TxBuff2.ri = 0; TxBuff2.wi = 0; TxBuff2.ct = 0; TxBuff2.act = 0; RxBuff2.ri = 0; RxBuff2.wi = 0; RxBuff2.ct = 0; /* Attach UART2 to I/O pad */ __set_PINSEL(0, 11, 1); /* P0.11 - TXD2 */\ __set_PINSEL(0, 10, 1); /* P0.10 - RXD2 */\ /* Enable Tx/Rx/Error interrupts */ U2IER = 0x07; __enable_irqn(UART2_IRQn); }
void uart0_init (void) { __disable_irqn(UART0_IRQn); /* Enable UART0 module */ __set_PCONP(PCUART0, 1); __set_PCLKSEL(PCLK_UART0, PCLKDIV); /* Initialize UART */ U0LCR = 0x83; /* Select baud rate divisor latch */ U0DLM = DLVAL0 / 256; /* Set BRG dividers */ U0DLL = DLVAL0 % 256; U0FDR = (MULVAL << 4) | DIVADD; U0LCR = 0x03; /* Set serial format N81 and deselect divisor latch */ U0FCR = 0x87; /* Enable FIFO */ U0TER = 0x80; /* Enable Tansmission */ /* Clear Tx/Rx buffers */ TxBuff0.ri = 0; TxBuff0.wi = 0; TxBuff0.ct = 0; TxBuff0.act = 0; RxBuff0.ri = 0; RxBuff0.wi = 0; RxBuff0.ct = 0; /* Attach UART0 to I/O pad */ __set_PINSEL(0, 3, 1); /* P0.3 - RXD0 */\ __set_PINSEL(0, 2, 1); /* P0.2 - TXD0 */\ /* Enable Tx/Rx/Error interrupts */ U0IER = 0x07; __enable_irqn(UART0_IRQn); }
void uart_init (void) { __disable_irqn(UART_IRQn); /* Enable UART module and set PCLK frequency */ __set_PCONP(PCUART, 1); __set_PCLKSEL(PCLK_UART, PCLKDIV); /* Initialize UART0 */ UART_LCR = 0x83; /* Select baud rate divisor latch */ UART_DLM = DLVAL / 256; /* Set BRG dividers */ UART_DLL = DLVAL % 256; UART_FDR = (MULVAL << 4) | DIVADD; UART_LCR = 0x03; /* Set serial format N81 and deselect divisor latch */ UART_FCR = 0x87; /* Enable FIFO */ UART_TER = 0x80; /* Enable Tansmission */ /* Clear Tx/Rx buffers */ TxBuff.ri = 0; TxBuff.wi = 0; TxBuff.ct = 0; TxBuff.act = 0; RxBuff.ri = 0; RxBuff.wi = 0; RxBuff.ct = 0; /* Attach UART to I/O pad */ ATTACH_UART(); /* Enable Tx/Rx/Error interrupts */ UART_IER = 0x07; __enable_irqn(UART_IRQn); }
void uart4_init (void) { __disable_irqn(UART4_IRQn); /* Enable UART4 module */ __set_PCONP(PCUART4, 1); /* Initialize UART */ U4LCR = 0x83; /* Select baud rate divisor latch */ U4DLM = DLVAL4 / 256; /* Set BRG dividers */ U4DLL = DLVAL4 % 256; U4FDR = (MULVAL << 4) | DIVADD; U4LCR = 0x03; /* Set serial format N81 and deselect divisor latch */ U4FCR = 0x87; /* Enable FIFO */ U4TER = 0x80; /* Enable Tansmission */ /* Clear Tx/Rx buffers */ TxBuff4.ri = 0; TxBuff4.wi = 0; TxBuff4.ct = 0; TxBuff4.act = 0; RxBuff4.ri = 0; RxBuff4.wi = 0; RxBuff4.ct = 0; /* Attach UART4 to I/O pad */ IOCON_P2[9] = 0x033; /* P2.9: RXD4 */\ IOCON_P0[22] = 0x003; /* P0.22: TXD4 */\ /* Enable Tx/Rx/Error interrupts */ U4IER = 0x07; __enable_irqn(UART4_IRQn); }
void psg_init() { psgbuf[0] = 0; psgmml = psgbuf; psgwaitcnt = psgwaitcnt2 = 0; IOCON_PIO1_5 = 0x000000d0; GPIO1DIR &= ~(1 << 5); __set_SYSAHBCLKCTRL(PCCT16B0, 1); // on 16bit timer 0 TMR16B0PR = (SYSCLK / 1000000) - 1; // pre scaler TMR16B0MR0 = 50; TMR16B0MCR = 0b011; // setting MR0 設定 stop reset interrupt __enable_irqn(CT16B0_IRQn); __set_irqn_priority(CT16B0_IRQn, 1); startPSG(); }
int main (void) { uint8_t i; dc.stat = 0; dc.count = 0; switch_flag = 0; /* misc I/Os Direction regs */ gpioSetDir(3, 0, 1); // DC-DC Convertor EN gpioSetDir(3, 1, 1); // Chg Disable pin gpioSetDir(3, 2, 1); // Low Chg pin gpioSetDir(1, 11, 0); // Switch /* LED Array Direction regs set to output */ gpioSetDir(2, 0, 1); // led no.0 the most left led. gpioSetDir(2, 1, 1); // led no.1 gpioSetDir(2, 2, 1); // led no.2 gpioSetDir(2, 3, 1); // led no.3 gpioSetDir(2, 4, 1); // led no.4 gpioSetDir(2, 5, 1); // led no.5 gpioSetDir(2, 6, 1); // led no.6 gpioSetDir(2, 7, 1); // led no.7 gpioSetDir(2, 8, 1); // led no.8 gpioSetDir(2, 9, 1); // led no.9 setChgPin(1); /* charge circuit off */ setLowChgPin(0); /* low charge off */ /* Enable SysTick timer in interval of 1 ms */ SYST_RVR = F_CPU / 1000 - 1; SYST_CSR = 0x07; initBQ29312A(); /* Initialize BQ29312A */ /* DON'T DSG FET TURN TO OFF WHEN DCIN DOESN'T CONNECT */ setDsgFet(1); // DSG FET turn to ON /* DON'T CHG FET TURN TO ON WHEN CONNECTING BATTERY */ setChgFet(0); // CHG FET turn to OFF GPIO2DATA = 0xffffff; /* all leds off */ setDCDC(1); /* Start DC5V output */ /* flash all LEDs */ for(i = 0; i <= 5; i++) { GPIO2DATA ^= ( _BV(0) | _BV(1) | _BV(2) | _BV(3) | _BV(4) | _BV(5) | _BV(6) | _BV(7) | _BV(8) | _BV(9) ); systickDelay(100); } /* Initialize ADC module */ adcInit(); checkBatteryStatus(); /* Call setBatteryFlag() 2000ms interval */ setTimer32Interval(1, 2000, setBatteryFlag); __enable_irqn(CT32B1_IRQn); /* Enale GPIO1-11 interrupt for battery check switch */ GPIO1IS &= ~(_BV(11)); /* Interrupt is Edge Sense */ GPIO1IBE &= ~(_BV(11)); /* Interrupt is Single Triger */ GPIO1IEV &= ~(_BV(11)); /* Select interrupt source (falling edge of P1.11 pin) */ GPIO1IE = _BV(11); /* Unmask interrupt of P1.11 pin */ __enable_irqn(PIO_1_IRQn); /* Enable PIO1 interrupt */ for (;;) { if(battery.checkBattery) checkBatteryStatus(); if(switch_flag) showBatteryLevel(); __WFI(); /* Wait for interrupt */ } }