#include <avr32/io.h>
#include "usart.h"
#include "../pio/pio.h"
#include "../debug/print_funcs.h"
#include "../inc/macro.h"
#include "../power_manager/pm.h"
#include "../pdc/pdc.h"
Include dependency graph for usart_example2.c:
Go to the source code of this file.
Defines | |
| #define | APBA_USART_INSTANCE PM_APBA_USART2 |
| #define | USART_ADDR AVR32_USART2_ADDRESS; |
Functions | |
| int | main (void) |
| int | print_pm_stats (volatile avr32_usart_t *usart) |
| #define APBA_USART_INSTANCE PM_APBA_USART2 |
| #define USART_ADDR AVR32_USART2_ADDRESS; |
Definition at line 17 of file usart_example2.c.
| int main | ( | void | ) |
Definition at line 22 of file usart_example2.c.
References APBA_USART_INSTANCE, usart_options_t::baudrate, usart_options_t::channelmode, usart_options_t::charlength, clk_sel_opt_t::clock, clk_sel_opt_t::div_enable, clk_sel_opt_t::divider, pll_opt_t::divider, pll_opt_t::multiplier, pll_opt_t::oscillator, usart_options_t::paritytype, pio_enable_module(), pll_opt_t::pll, PM_AHB_DOMAIN, PM_APBA_DOMAIN, PM_APBB_DOMAIN, PM_CPU_DOMAIN, PM_LOCK_ERROR, PM_OSC0, PM_PLL0, pm_read_module_frequency(), pm_reset(), pm_set_clock_domain_scaler(), pm_set_mclk_source(), pm_set_pll(), print(), print_pm_stats(), usart_options_t::stopbits, USART_1_STOPBIT, USART_ADDR, usart_init_rs232(), USART_NO_PARITY, and USART_NORMAL_CHMODE.
00023 { 00024 volatile avr32_usart_t * usart = (void *) USART_ADDR; 00025 struct usart_options_t usart_opt; 00026 struct pll_opt_t pll_opt; 00027 00028 struct clk_sel_opt_t cpu_opt; 00029 struct clk_sel_opt_t ahb_opt; 00030 struct clk_sel_opt_t apba_opt; 00031 struct clk_sel_opt_t apbb_opt; 00032 00033 avr32_piomap_t usart_piomap = { \ 00034 {AVR32_USART2_RXD_0_PIN, AVR32_USART2_RXD_0_FUNCTION}, \ 00035 {AVR32_USART2_TXD_0_PIN, AVR32_USART2_TXD_0_FUNCTION}, \ 00036 {AVR32_USART0_CLK_0_PIN, AVR32_USART0_CLK_0_FUNCTION}, \ 00037 {AVR32_USART0_CTS_0_PIN, AVR32_USART0_CTS_0_FUNCTION}, \ 00038 {AVR32_USART0_RTS_0_PIN, AVR32_USART0_RTS_0_FUNCTION} \ 00039 }; 00040 00041 /* Set options for the USART */ 00042 usart_opt.baudrate = 57600; 00043 usart_opt.charlength = 8; 00044 usart_opt.paritytype = USART_NO_PARITY; 00045 usart_opt.stopbits = USART_1_STOPBIT; 00046 usart_opt.channelmode = USART_NORMAL_CHMODE; 00047 00048 00049 /* Set options for the PLL altering*/ 00050 pll_opt.pll=PM_PLL0; 00051 pll_opt.oscillator=PM_OSC0; 00052 pll_opt.multiplier=3; 00053 pll_opt.divider=2; 00054 00055 /* CPU options */ 00056 cpu_opt.clock = PM_CPU_DOMAIN; 00057 cpu_opt.div_enable = 1; 00058 cpu_opt.divider = 2; 00059 00060 /* AHB options */ 00061 ahb_opt.clock = PM_AHB_DOMAIN; 00062 ahb_opt.div_enable = 1; 00063 ahb_opt.divider = 2; 00064 00065 /* APBA options */ 00066 apba_opt.clock = PM_APBA_DOMAIN; 00067 apba_opt.div_enable = 1; 00068 apba_opt.divider = 2; 00069 00070 /* APBB options */ 00071 apbb_opt.clock = PM_APBB_DOMAIN; 00072 apbb_opt.div_enable = 1; 00073 apbb_opt.divider = 3; 00074 00075 pm_reset(); 00076 00077 /* Initialize the usart */ 00078 pio_enable_module( usart_piomap, 5 ); 00079 usart_init_rs232( usart, &usart_opt, pm_read_module_frequency(APBA_USART_INSTANCE)); 00080 00081 print(usart, "\nSo many assholes, so few... bullets\n"); 00082 print_pm_stats(usart); 00083 00084 //Set pll0 00085 print(usart, "Setting pll0...\n"); 00086 if(pm_set_pll(&pll_opt) == PM_LOCK_ERROR ){ 00087 print(usart, "pll0 did not lock\n"); 00088 } 00089 else 00090 print(usart, "pll0 successfully locked\n"); 00091 00092 // Set pll0 to mclk 00093 print(usart, "Setting pll0 to mclk..."); 00094 pm_set_mclk_source(PM_PLL0); 00095 usart_init_rs232( usart, &usart_opt, pm_read_module_frequency(APBA_USART_INSTANCE) ); 00096 print(usart,"\n"); 00097 00098 // Modifying clock domain 00099 print(usart, "Modifying clock domain...\n"); 00100 pm_set_clock_domain_scaler( &apbb_opt ); 00101 usart_init_rs232( usart, &usart_opt, pm_read_module_frequency(APBA_USART_INSTANCE) ); 00102 print_pm_stats(usart); 00103 usart_init_rs232( usart, &usart_opt, pm_read_module_frequency(APBA_USART_INSTANCE) ); 00104 00105 // Modifying clock domain 00106 print(usart, "\nModifying clock domain...\n"); 00107 pm_set_clock_domain_scaler( &ahb_opt ); 00108 usart_init_rs232( usart, &usart_opt, pm_read_module_frequency(APBA_USART_INSTANCE) ); 00109 print(usart,"\n"); 00110 print_pm_stats(usart); 00111 00112 return 42; 00113 }
Here is the call graph for this function:
| int print_pm_stats | ( | volatile avr32_usart_t * | usart | ) |
Definition at line 115 of file usart_example2.c.
References APBA_USART_INSTANCE, PM_AHB_DOMAIN, PM_APBA_DOMAIN, PM_APBB_DOMAIN, PM_APBB_PWM, PM_CPU_DOMAIN, PM_PLL0, pm_read_clock_domain_scaler(), pm_read_mclk(), pm_read_module_frequency(), pm_read_pll_frequency(), print(), and print_ulong().
Referenced by main().
00116 { 00117 00118 // Print out ALL the stats 00119 print(usart, "\n\r-> The current MCLK frequency is "); 00120 print_ulong(usart, pm_read_mclk()/1000000 ); 00121 print(usart, "MHZ\n"); 00122 print(usart, "-> The current pll0 frequency is "); 00123 print_ulong(usart, pm_read_pll_frequency(PM_PLL0)/1000000); 00124 print(usart, "MHZ\n"); 00125 print(usart, "-> The current CPU divider is "); 00126 print_ulong(usart, pm_read_clock_domain_scaler(PM_CPU_DOMAIN) ); 00127 print(usart, "\n"); 00128 print(usart, "-> The current AHB divider is "); 00129 print_ulong(usart, pm_read_clock_domain_scaler(PM_AHB_DOMAIN) ); 00130 print(usart, "\n"); 00131 print(usart, "-> The current APBA divider is "); 00132 print_ulong(usart, pm_read_clock_domain_scaler(PM_APBA_DOMAIN) ); 00133 print(usart, "\n"); 00134 print(usart, "-> The current APBB divider is "); 00135 print_ulong(usart, pm_read_clock_domain_scaler(PM_APBB_DOMAIN) ); 00136 print(usart, "\n"); 00137 print(usart, "-> The current USART frequency is "); 00138 print_ulong(usart, pm_read_module_frequency(APBA_USART_INSTANCE)); 00139 print(usart, "HZ\n"); 00140 print(usart, "-> The current PWM frequency is "); 00141 print_ulong(usart, pm_read_module_frequency(PM_APBB_PWM)); 00142 print(usart, "HZ\n\n"); 00143 00144 return 0; 00145 00146 }
Here is the call graph for this function:
1.5.1