Skip to content

Commit

Permalink
Merge pull request #2 from TimerOverflow/20161108
Browse files Browse the repository at this point in the history
20161108
  • Loading branch information
TimerOverflow authored Sep 10, 2021
2 parents 66cbcd0 + eb20f58 commit 7e2888a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
46 changes: 25 additions & 21 deletions AvrUartBaud.c
Original file line number Diff line number Diff line change
@@ -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 **/


Expand All @@ -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;
}
/*********************************************************************************/
Expand All @@ -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;
}
}
Expand Down
26 changes: 9 additions & 17 deletions AvrUartBaud.h
Original file line number Diff line number Diff line change
@@ -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**/
Expand Down Expand Up @@ -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;
Expand All @@ -62,14 +65,3 @@ void AvrUartBaudChange(tag_UartBaudControl *BaudCtrl, Enum_BaudRate Baud);

/*********************************************************************************/
#endif //__AVR_UART_BAUD_H__











0 comments on commit 7e2888a

Please sign in to comment.