Skip to content

Commit

Permalink
Merge pull request #1 from TimerOverflow/20161028
Browse files Browse the repository at this point in the history
20161028
  • Loading branch information
TimerOverflow authored Sep 10, 2021
2 parents b6dd449 + 0ff8cd4 commit 66cbcd0
Show file tree
Hide file tree
Showing 20 changed files with 2,703 additions and 0 deletions.
95 changes: 95 additions & 0 deletions AvrUartBaud.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*********************************************************************************/
/*
* Author : Jung Hyun Gu
* File name : AvrUartBaud.c
*/
/*********************************************************************************/
#include "AvrUartBaud.h"
/*********************************************************************************/
/** Global variable **/


/*********************************************************************************/
char AvrUartBaudControlInit(tag_UartBaudControl *BaudCtrl, long CpuClock, unsigned char volatile __tiny *pUBRRL, unsigned char volatile __tiny *pUBRRH)
{
/*
1) Parameter
- BaudCtrl : 'tag_UartBaudControl'의 인스턴스 주소.
- CpuClock : Target CPU의 Clock Speed.
- pUBRRL, pUBRRH : Uart Baud Rate Register의 주소.
2) Description
- Baud를 관리할 'tag_UartBaudControl' 인스턴스를 초기화한다.
- 본 초기화는 한번만 실행하면 된다.
- 다음 함수들은 반드시 본 초기화를 실행한 후 호출해야 한다.
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;
}
/*********************************************************************************/
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);
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);
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);
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);
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);
break;
}
}
}
/*********************************************************************************/
75 changes: 75 additions & 0 deletions AvrUartBaud.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*********************************************************************************/
/*
* Author : Jung Hyun Gu
* File name : AvrUartBaud.h
*/
/*********************************************************************************/
#ifndef __AVR_UART_BAUD_H__
#define __AVR_UART_BAUD_H__
/*********************************************************************************/
/** REVISION HISTORY **/
/*
2016. 10. 28. - 초기버전.
Jung Hyun Gu
*/
/*********************************************************************************/
/**Define**/

#define true 1
#define false 0
#define null 0

#define GET_UBRR(CPU_CLOCK, BAUD, U2X) ((CPU_CLOCK / (U2X ? 8 : 16) / BAUD) - 1)

/*********************************************************************************/
/**Enum**/

typedef enum
{
BAUD_9600 = 0,
BAUD_19200,
BAUD_38400,
BAUD_57600,
BAUD_115200,
BAUD_INIT,
}Enum_BaudRate;

/*********************************************************************************/
/**Struct**/

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;

/*********************************************************************************/
/**Function**/

char AvrUartBaudControlInit(tag_UartBaudControl *BaudCtrl, long CpuClock, unsigned char volatile __tiny *pUBRRL, unsigned char volatile __tiny *pUBRRH);
void AvrUartBaudChange(tag_UartBaudControl *BaudCtrl, Enum_BaudRate Baud);

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











6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# AvrUartBaud
baudrate setting library for AVR

- various baudrate support (9600 / 19200 / 38400 / 57600 / 115200)
- automatic calculate baudrate optimized cpu clock 11.0592Mhz, 14.7456Mhz

# Build & Tested Environment
- IAR C/C++ Compiler for AVR 6.11.1 (6.11.1.50453)
208 changes: 208 additions & 0 deletions example/AvrUartBaud.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
<?xml version="1.0" encoding="iso-8859-1"?>

<project>
<fileVersion>2</fileVersion>
<fileChecksum>3752300360</fileChecksum>
<configuration>
<name>Debug</name>
<outputs>
<file>$PROJ_DIR$\main.c</file>
<file>$PROJ_DIR$\Debug\Obj\main.r90</file>
<file>$PROJ_DIR$\Debug\Exe\AvrUartBaud.d90</file>
<file>$PROJ_DIR$\Debug\Obj\AvrUartBaud.pbd</file>
<file>$PROJ_DIR$\Debug\Obj\main.pbi</file>
<file>$TOOLKIT_DIR$\inc\comp_a90.h</file>
<file>$TOOLKIT_DIR$\inc\intrinsics.h</file>
<file>$TOOLKIT_DIR$\inc\inavr.h</file>
<file>$PROJ_DIR$\Debug\Obj\AvrUartBaud.r90</file>
<file>$PROJ_DIR$\..\AvrUartBaud.h</file>
<file>$TOOLKIT_DIR$\inc\iom64.h</file>
<file>$TOOLKIT_DIR$\inc\iomacro.h</file>
<file>$PROJ_DIR$\Debug\Exe\AvrUartBaud(AT64).d90</file>
<file>$TOOLKIT_DIR$\inc\ina90.h</file>
<file>$TOOLKIT_DIR$\config\lnkm64s.xcl</file>
<file>$TOOLKIT_DIR$\lib\clib\cl3s-ec_mul-sf.r90</file>
<file>$PROJ_DIR$\..\AvrUartBaud.c</file>
<file>$PROJ_DIR$\Debug\Obj\AvrUartBaud.pbi</file>
<file>$TOOLKIT_DIR$\inc\bitdefinitions\iom64.inc</file>
</outputs>
<file>
<name>[ROOT_NODE]</name>
<outputs>
<tool>
<name>XLINK</name>
<file> 12</file>
</tool>
</outputs>
</file>
<file>
<name>$PROJ_DIR$\main.c</name>
<outputs>
<tool>
<name>BICOMP</name>
<file> 4</file>
</tool>
<tool>
<name>ICCAVR</name>
<file> 1</file>
</tool>
</outputs>
<inputs>
<tool>
<name>BICOMP</name>
<file> 10 11 18 13 7 6 5</file>
</tool>
<tool>
<name>ICCAVR</name>
<file> 10 11 18 13 7 6 5 9</file>
</tool>
</inputs>
</file>
<file>
<name>$PROJ_DIR$\Debug\Obj\AvrUartBaud.pbd</name>
<inputs>
<tool>
<name>BILINK</name>
<file> 17 4</file>
</tool>
</inputs>
</file>
<file>
<name>$PROJ_DIR$\Debug\Exe\AvrUartBaud(AT64).d90</name>
<inputs>
<tool>
<name>XLINK</name>
<file> 14 8 1 15</file>
</tool>
</inputs>
</file>
<file>
<name>$PROJ_DIR$\..\AvrUartBaud.c</name>
<outputs>
<tool>
<name>BICOMP</name>
<file> 17</file>
</tool>
<tool>
<name>ICCAVR</name>
<file> 8</file>
</tool>
</outputs>
<inputs>
<tool>
<name>BICOMP</name>
<file> 9</file>
</tool>
<tool>
<name>ICCAVR</name>
<file> 9</file>
</tool>
</inputs>
</file>
<forcedrebuild>
<name>[REBUILD_ALL]</name>
</forcedrebuild>
</configuration>
<configuration>
<name>Release</name>
<outputs>
<file>$PROJ_DIR$\main.c</file>
<file>$PROJ_DIR$\Release\Obj\AvrUartBaud.r90</file>
<file>$PROJ_DIR$\Release\Obj\AvrUartBaud.pbi</file>
<file>$PROJ_DIR$\Release\Exe\AvrUartBaud(AT64).hex</file>
<file>$TOOLKIT_DIR$\inc\comp_a90.h</file>
<file>$TOOLKIT_DIR$\inc\intrinsics.h</file>
<file>$TOOLKIT_DIR$\inc\inavr.h</file>
<file>$PROJ_DIR$\..\AvrUartBaud.h</file>
<file>$TOOLKIT_DIR$\inc\iom64.h</file>
<file>$TOOLKIT_DIR$\inc\iomacro.h</file>
<file>$TOOLKIT_DIR$\inc\ina90.h</file>
<file>$PROJ_DIR$\Release\Obj\main.r90</file>
<file>$TOOLKIT_DIR$\config\lnkm64s.xcl</file>
<file>$PROJ_DIR$\Release\Obj\main.pbi</file>
<file>$TOOLKIT_DIR$\lib\clib\cl3s-ec_mul-sf.r90</file>
<file>$PROJ_DIR$\..\AvrUartBaud.c</file>
<file>$PROJ_DIR$\Release\Obj\AvrUartBaud.pbd</file>
<file>$TOOLKIT_DIR$\inc\bitdefinitions\iom64.inc</file>
<file>$PROJ_DIR$\Release\Exe\AvrUartBaud.hex</file>
</outputs>
<file>
<name>[ROOT_NODE]</name>
<outputs>
<tool>
<name>XLINK</name>
<file> 3</file>
</tool>
</outputs>
</file>
<file>
<name>$PROJ_DIR$\main.c</name>
<outputs>
<tool>
<name>BICOMP</name>
<file> 13</file>
</tool>
<tool>
<name>ICCAVR</name>
<file> 11</file>
</tool>
</outputs>
<inputs>
<tool>
<name>BICOMP</name>
<file> 8 9 17 10 6 5 4</file>
</tool>
<tool>
<name>ICCAVR</name>
<file> 8 9 17 10 6 5 4 7</file>
</tool>
</inputs>
</file>
<file>
<name>$PROJ_DIR$\Release\Exe\AvrUartBaud(AT64).hex</name>
<inputs>
<tool>
<name>XLINK</name>
<file> 12 1 11 14</file>
</tool>
</inputs>
</file>
<file>
<name>$PROJ_DIR$\..\AvrUartBaud.c</name>
<outputs>
<tool>
<name>BICOMP</name>
<file> 2</file>
</tool>
<tool>
<name>ICCAVR</name>
<file> 1</file>
</tool>
</outputs>
<inputs>
<tool>
<name>BICOMP</name>
<file> 7</file>
</tool>
<tool>
<name>ICCAVR</name>
<file> 7</file>
</tool>
</inputs>
</file>
<file>
<name>$PROJ_DIR$\Release\Obj\AvrUartBaud.pbd</name>
<inputs>
<tool>
<name>BILINK</name>
<file> 2 13</file>
</tool>
</inputs>
</file>
<forcedrebuild>
<name>[REBUILD_ALL]</name>
</forcedrebuild>
</configuration>
</project>


Loading

0 comments on commit 66cbcd0

Please sign in to comment.