CCL是Configurable Custom Logic缩写,是用户可根据需要,扩展自己的逻辑。
本例通过 LUT0 LUT1 连接到内部 sequential logic,实现了一个 D lip flop
首先在ASFWIZARD中加入CCL模块,然后在ASF EXPLORER中打开快速指导:
根据快速指导形成程序:
然后编译:
以下是程序:
#include <asf.h>
void configure_ccl(void)
{
struct ccl_config conf;
ccl_get_config_defaults(&conf);
ccl_init(&conf);
}
void configure_ccl_lut0(void)
{
struct ccl_lut_config conf;
ccl_lut_get_config_defaults(&conf);
conf.truth_table_value = 0x02;
conf.input0_src_sel = CCL_LUT_INPUT_SRC_IO;
conf.input1_src_sel = CCL_LUT_INPUT_SRC_IO;
conf.input2_src_sel = CCL_LUT_INPUT_SRC_IO;
conf.filter_sel = CCL_LUTCTRL_FILTSEL_FILTER;
struct system_pinmux_config lut0_input_pin0_conf, lut0_input_pin1_conf, lut0_input_pin2_conf;
system_pinmux_get_config_defaults(&lut0_input_pin0_conf);
system_pinmux_get_config_defaults(&lut0_input_pin1_conf);
system_pinmux_get_config_defaults(&lut0_input_pin2_conf);
lut0_input_pin0_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
lut0_input_pin0_conf.mux_position = MUX_PA04I_CCL_IN0;
lut0_input_pin1_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
lut0_input_pin1_conf.mux_position = MUX_PA05I_CCL_IN1;
lut0_input_pin2_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
lut0_input_pin2_conf.mux_position = MUX_PA06I_CCL_IN2;
system_pinmux_pin_set_config(PIN_PA04I_CCL_IN0, &lut0_input_pin0_conf);
system_pinmux_pin_set_config(PIN_PA05I_CCL_IN1, &lut0_input_pin1_conf);
system_pinmux_pin_set_config(PIN_PA06I_CCL_IN2, &lut0_input_pin2_conf);
struct system_pinmux_config lut0_out_pin_conf;
system_pinmux_get_config_defaults(&lut0_out_pin_conf);
lut0_out_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
lut0_out_pin_conf.mux_position = MUX_PA07I_CCL_OUT0;
system_pinmux_pin_set_config(PIN_PA07I_CCL_OUT0, &lut0_out_pin_conf);
ccl_lut_set_config(CCL_LUT_0, &conf);
}
void configure_ccl_lut1(void)
{
struct ccl_lut_config conf;
ccl_lut_get_config_defaults(&conf);
conf.truth_table_value = 0x02;
conf.input0_src_sel = CCL_LUT_INPUT_SRC_IO;
conf.input1_src_sel = CCL_LUT_INPUT_SRC_IO;
conf.input2_src_sel = CCL_LUT_INPUT_SRC_IO;
conf.filter_sel = CCL_LUTCTRL_FILTSEL_FILTER;
struct system_pinmux_config lut1_input_pin0_conf, lut1_input_pin1_conf, lut1_input_pin2_conf;
system_pinmux_get_config_defaults(&lut1_input_pin0_conf);
system_pinmux_get_config_defaults(&lut1_input_pin1_conf);
system_pinmux_get_config_defaults(&lut1_input_pin2_conf);
lut1_input_pin0_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
lut1_input_pin0_conf.mux_position = MUX_PA08I_CCL_IN3;
lut1_input_pin1_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
lut1_input_pin1_conf.mux_position = MUX_PA09I_CCL_IN4;
lut1_input_pin2_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
lut1_input_pin2_conf.mux_position = MUX_PA10I_CCL_IN5;
system_pinmux_pin_set_config(PIN_PA08I_CCL_IN3, &lut1_input_pin0_conf);
system_pinmux_pin_set_config(PIN_PA09I_CCL_IN4, &lut1_input_pin1_conf);
system_pinmux_pin_set_config(PIN_PA10I_CCL_IN5, &lut1_input_pin2_conf);
struct system_pinmux_config lut1_out_pin_conf;
system_pinmux_get_config_defaults(&lut1_out_pin_conf);
lut1_out_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
lut1_out_pin_conf.mux_position = MUX_PA11I_CCL_OUT1;
system_pinmux_pin_set_config(PIN_PA11I_CCL_OUT1, &lut1_out_pin_conf);
ccl_lut_set_config(CCL_LUT_1, &conf);
}
int main (void)
{
/* Initialize the system and console*/
system_init();
configure_ccl();
configure_ccl_lut0();
configure_ccl_lut1();
ccl_seq_config(CCL_SEQ_0, CCL_SEQ_D_FLIP_FLOP);
ccl_lut_enable(CCL_LUT_0);
ccl_lut_enable(CCL_LUT_1);
ccl_module_enable();
while(1);
}
我用万用表量了下电压 LUT0 和 LUT1输出都是0,而输入都是1.
|