Definition in file hmatrix_example.c.
#include <string.h>
#include "board.h"
#include "print_funcs.h"
#include "gpio.h"
#include "power_clocks_lib.h"
#include "usart.h"
Go to the source code of this file.
Defines | |
#define | NB_TOGGLE 512 |
USART Settings | |
#define | EXAMPLE_TARGET_DFLL_FREQ_HZ 96000000 |
#define | EXAMPLE_TARGET_MCUCLK_FREQ_HZ 12000000 |
#define | EXAMPLE_TARGET_PBACLK_FREQ_HZ 12000000 |
#define | EXAMPLE_USART (&AVR32_USART3) |
#define | EXAMPLE_USART_RX_FUNCTION AVR32_USART3_RXD_0_0_FUNCTION |
#define | EXAMPLE_USART_RX_PIN AVR32_USART3_RXD_0_0_PIN |
#define | EXAMPLE_USART_TX_FUNCTION AVR32_USART3_TXD_0_0_FUNCTION |
#define | EXAMPLE_USART_TX_PIN AVR32_USART3_TXD_0_0_PIN |
#define | FPBA EXAMPLE_TARGET_PBACLK_FREQ_HZ |
Functions | |
static void | configure_hmatrix (int mode) |
Initializes the HSB bus matrix. | |
int | main (void) |
The main function. | |
int | toggle_led (int number_of_toggle) |
Toggle LED. | |
Variables | |
volatile unsigned int | ccountt0 |
volatile unsigned int | ccountt1 |
Parameters to pcl_configure_clocks(). | |
static scif_gclk_opt_t | gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, OFF } |
static pcl_freq_param_t | pcl_dfll_freq_param |
#define EXAMPLE_TARGET_DFLL_FREQ_HZ 96000000 |
Definition at line 160 of file hmatrix_example.c.
#define EXAMPLE_TARGET_MCUCLK_FREQ_HZ 12000000 |
Definition at line 161 of file hmatrix_example.c.
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ 12000000 |
Definition at line 162 of file hmatrix_example.c.
#define EXAMPLE_USART (&AVR32_USART3) |
#define EXAMPLE_USART_RX_FUNCTION AVR32_USART3_RXD_0_0_FUNCTION |
#define EXAMPLE_USART_RX_PIN AVR32_USART3_RXD_0_0_PIN |
#define EXAMPLE_USART_TX_FUNCTION AVR32_USART3_TXD_0_0_FUNCTION |
#define EXAMPLE_USART_TX_PIN AVR32_USART3_TXD_0_0_PIN |
#define FPBA EXAMPLE_TARGET_PBACLK_FREQ_HZ |
#define NB_TOGGLE 512 |
static void configure_hmatrix | ( | int | mode | ) | [static] |
Initializes the HSB bus matrix.
Definition at line 224 of file hmatrix_example.c.
Referenced by main().
00225 { 00226 // Set flashc master type to last default to save one cycle for 00227 // each branch. 00228 int i; 00229 // Configure all Salve in Last Default Master 00230 for(i=0;i<AVR32_HMATRIX_SLAVE_NUM;i++) { 00231 AVR32_HMATRIX.SCFG[i].defmstr_type = mode; 00232 } 00233 }
int main | ( | void | ) |
The main function.
Definition at line 237 of file hmatrix_example.c.
References configure_hmatrix(), EXAMPLE_USART, EXAMPLE_USART_RX_FUNCTION, EXAMPLE_USART_RX_PIN, EXAMPLE_USART_TX_FUNCTION, EXAMPLE_USART_TX_PIN, FPBA, NB_TOGGLE, pcl_dfll_freq_param, and toggle_led().
00238 { 00239 00240 int result; 00241 00242 static const gpio_map_t USART_GPIO_MAP = 00243 { 00244 {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION}, 00245 {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION} 00246 }; 00247 00248 // USART options 00249 static const usart_options_t USART_OPTIONS = 00250 { 00251 .baudrate = 57600, 00252 .charlength = 8, 00253 .paritytype = USART_NO_PARITY, 00254 .stopbits = USART_1_STOPBIT, 00255 .channelmode = 0 00256 }; 00257 00258 #if BOARD == UC3L_EK 00259 // Note: on the AT32UC3L-EK board, there is no crystal/external clock connected 00260 // to the OSC0 pinout XIN0/XOUT0. We shall then program the DFLL and switch the 00261 // main clock source to the DFLL. 00262 pcl_configure_clocks(&pcl_dfll_freq_param); 00263 // Note: since it is dynamically computing the appropriate field values of the 00264 // configuration registers from the parameters structure, this function is not 00265 // optimal in terms of code size. For a code size optimal solution, it is better 00266 // to create a new function from pcl_configure_clocks_dfll0() and modify it 00267 // to use preprocessor computation from pre-defined target frequencies. 00268 #else 00269 // Configure Osc0 in crystal mode (i.e. use of an external crystal source, with 00270 // frequency FOSC0) with an appropriate startup time then switch the main clock 00271 // source to Osc0. 00272 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP); 00273 #endif 00274 00275 // Assign GPIO to USART. 00276 gpio_enable_module(USART_GPIO_MAP, 00277 sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0])); 00278 00279 // Initialize USART in RS232 mode. 00280 // Initialize USART in RS232 mode at 12MHz. 00281 usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, FPBA); 00282 00283 usart_write_line(EXAMPLE_USART, "\x1B[2J\x1B[H\r\nATMEL\r\n"); 00284 usart_write_line(EXAMPLE_USART, "AVR UC3 - HMATRIX example\r\n\n"); 00285 00286 //**************************************************************************** 00287 // - First test with AVR32_HMATRIX_DEFMSTR_TYPE_NO_DEFAULT 00288 //**************************************************************************** 00289 print(EXAMPLE_USART, "- Test 1 ----------------------------------------\n"); 00290 print(EXAMPLE_USART, "------ All Slave Default Master Type are: ------\n"); 00291 print(EXAMPLE_USART, " - No Default Master\n"); 00292 print(EXAMPLE_USART, " - leds Toggle: "); 00293 print_ulong(EXAMPLE_USART, NB_TOGGLE); 00294 print(EXAMPLE_USART, " times\n"); 00295 configure_hmatrix(AVR32_HMATRIX_DEFMSTR_TYPE_NO_DEFAULT); 00296 00297 result = toggle_led(NB_TOGGLE); 00298 00299 //**************************************************************************** 00300 // - Second test with AVR32_HMATRIX_DEFMSTR_TYPE_LAST_DEFAULT 00301 //**************************************************************************** 00302 print(EXAMPLE_USART, "- Test 2 ----------------------------------------\n"); 00303 print(EXAMPLE_USART, "------ All Slave Default Master Type are: ------\n"); 00304 print(EXAMPLE_USART, " - Last Default Master\n"); 00305 print(EXAMPLE_USART, " - No Default Master\n"); 00306 print(EXAMPLE_USART, " - leds Toggle: "); 00307 print_ulong(EXAMPLE_USART, NB_TOGGLE); 00308 print(EXAMPLE_USART, " times\n"); 00309 00310 configure_hmatrix(AVR32_HMATRIX_DEFMSTR_TYPE_LAST_DEFAULT); 00311 00312 result -= toggle_led(NB_TOGGLE); 00313 00314 print(EXAMPLE_USART, "--------------------------------------------------\n"); 00315 00316 print_ulong(EXAMPLE_USART, result); 00317 print(EXAMPLE_USART, " Cycles saved between test 1 and test 2\r\nDone!"); 00318 00319 // End of tests: go to sleep. 00320 SLEEP(AVR32_PM_SMODE_STATIC); 00321 while (TRUE); 00322 }
int toggle_led | ( | int | number_of_toggle | ) |
Toggle LED.
Definition at line 195 of file hmatrix_example.c.
References ccountt0, ccountt1, and EXAMPLE_USART.
Referenced by main().
00196 { 00197 unsigned int i; 00198 int result = -1; 00199 00200 //* 00201 //* Start the process 00202 //* 00203 ccountt0 = Get_system_register(AVR32_COUNT); 00204 00205 // Check the results of the encryption. 00206 for(i=0; i<number_of_toggle; i++) 00207 { 00208 gpio_tgl_gpio_pin(LED0_GPIO); 00209 } 00210 ccountt1 = Get_system_register(AVR32_COUNT); 00211 00212 print(EXAMPLE_USART, " - Number of cycles: "); 00213 result = ccountt1 - ccountt0; 00214 print_ulong(EXAMPLE_USART, ccountt1 - ccountt0); 00215 00216 print(EXAMPLE_USART, "\n"); 00217 00218 return result; 00219 }
volatile unsigned int ccountt0 |
volatile unsigned int ccountt1 |
scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, OFF } [static] |
Definition at line 167 of file hmatrix_example.c.
pcl_freq_param_t pcl_dfll_freq_param [static] |
Initial value:
{ .main_clk_src = PCL_MC_DFLL0, .cpu_f = EXAMPLE_TARGET_MCUCLK_FREQ_HZ, .pba_f = EXAMPLE_TARGET_PBACLK_FREQ_HZ, .pbb_f = EXAMPLE_TARGET_PBACLK_FREQ_HZ, .dfll_f = EXAMPLE_TARGET_DFLL_FREQ_HZ, .pextra_params = &gc_dfllif_ref_opt }
Definition at line 168 of file hmatrix_example.c.
Referenced by main().