diff --git a/AvrUartBaud.c b/AvrUartBaud.c index bc16f4a..861fa4f 100644 --- a/AvrUartBaud.c +++ b/AvrUartBaud.c @@ -1,11 +1,15 @@ /*********************************************************************************/ /* - * Author : Jung Hyun Gu + * Author : Jeong Hyun Gu * File name : AvrUartBaud.c */ /*********************************************************************************/ #include "AvrUartBaud.h" /*********************************************************************************/ +#if(AVR_UART_BAUD_REVISION_DATE != 20161108) +#error wrong include file. (AvrUartBaud.h) +#endif +/*********************************************************************************/ /** Global variable **/ @@ -17,27 +21,27 @@ char AvrUartBaudControlInit(tag_UartBaudControl *BaudCtrl, long CpuClock, unsign - BaudCtrl : 'tag_UartBaudControl'의 인스턴스 주소. - CpuClock : Target CPU의 Clock Speed. - pUBRRL, pUBRRH : Uart Baud Rate Register의 주소. - + 2) Description - Baud를 관리할 'tag_UartBaudControl' 인스턴스를 초기화한다. - 본 초기화는 한번만 실행하면 된다. - 다음 함수들은 반드시 본 초기화를 실행한 후 호출해야 한다. - AvrUartBaudChange(); + AvrUartBaudChange(); */ - + if((pUBRRL) == null || (pUBRRH == null)) { return false; } - + BaudCtrl->CpuClock = CpuClock; BaudCtrl->Baud = BAUD_INIT; - + BaudCtrl->pUBRRL = pUBRRL; BaudCtrl->pUBRRH = pUBRRH; - + BaudCtrl->Bit.Init = true; - + return BaudCtrl->Bit.Init; } /*********************************************************************************/ @@ -47,47 +51,47 @@ void AvrUartBaudChange(tag_UartBaudControl *BaudCtrl, Enum_BaudRate Baud) 1) Parameter - BaudCtrl : 'tag_UartBaudControl'의 인스턴스 주소. - Baud : 변경하고자 하는 baud rate. - + 2) Description - 'BaudCtrl' 인스턴스의 baud rate를 변경한다. */ - + if(BaudCtrl->Bit.Init == false) { return; /* error */ } - + if(BaudCtrl->Baud != Baud) { BaudCtrl->Baud = Baud; - + switch(Baud) { default : case BAUD_9600 : *BaudCtrl->pUBRRH = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 9600, 0) >> 8); - *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 9600, 0) & 0x00FF); + *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 9600, 0) & 0x00FF); break; - + case BAUD_19200 : *BaudCtrl->pUBRRH = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 19200, 0) >> 8); - *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 19200, 0) & 0x00FF); + *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 19200, 0) & 0x00FF); break; - + case BAUD_38400 : *BaudCtrl->pUBRRH = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 38400, 0) >> 8); - *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 38400, 0) & 0x00FF); + *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 38400, 0) & 0x00FF); break; - + case BAUD_57600 : *BaudCtrl->pUBRRH = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 57600, 0) >> 8); - *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 57600, 0) & 0x00FF); + *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 57600, 0) & 0x00FF); break; - + case BAUD_115200 : *BaudCtrl->pUBRRH = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 115200, 0) >> 8); - *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 115200, 0) & 0x00FF); + *BaudCtrl->pUBRRL = (unsigned char) (GET_UBRR(BaudCtrl->CpuClock, 115200, 0) & 0x00FF); break; } } diff --git a/AvrUartBaud.h b/AvrUartBaud.h index f1d5796..b46d281 100644 --- a/AvrUartBaud.h +++ b/AvrUartBaud.h @@ -1,18 +1,21 @@ /*********************************************************************************/ /* - * Author : Jung Hyun Gu + * Author : Jeong Hyun Gu * File name : AvrUartBaud.h */ /*********************************************************************************/ #ifndef __AVR_UART_BAUD_H__ #define __AVR_UART_BAUD_H__ /*********************************************************************************/ +#define AVR_UART_BAUD_REVISION_DATE 20161108 +/*********************************************************************************/ /** REVISION HISTORY **/ /* + 2016. 11. 08. - revision valid check 추가. + Jung Hyun Gu + 2016. 10. 28. - 초기버전. Jung Hyun Gu - - */ /*********************************************************************************/ /**Define**/ @@ -44,12 +47,12 @@ typedef struct struct { unsigned char Init : 1; //초기화 - + }Bit; - + unsigned char volatile __tiny *pUBRRL; // unsigned char volatile __tiny *pUBRRH; // - + long CpuClock; //CPU클록 Enum_BaudRate Baud; // }tag_UartBaudControl; @@ -62,14 +65,3 @@ void AvrUartBaudChange(tag_UartBaudControl *BaudCtrl, Enum_BaudRate Baud); /*********************************************************************************/ #endif //__AVR_UART_BAUD_H__ - - - - - - - - - - -