Hi. Here are some pointers:
1) Please use the code markers in your posts to format the code to be easier to view.
Here is the same code using the code markers ("CODE DISPLAY" above the post form tool):
Code: Select all
out port p_out = XS1_PORT_8A;
out port p_clock_out = XS1_PORT_1A;
clock clk = XS1_CLKBLK_1; /*identifier for clock named clk*/
int main(void)
{
configure_clock_rate(clk, 100, 8); /*configures clock to 100/8 =12.5Mhz*/
configure_out_port(p_out, clk, 0);/* configures outputport p_out with 0*/
configure_port_clock_output(p_clock_out , clk);
start_clock(clk);
for (int i=0; i<5; i++)
p_out <: i;
}
2) A little trick I like to use when working with the various XMOS CPU devices is as follows:
a) launch a fresh workspace
b) upon reaching the IDE -> select the EXAMPLES icon on left side bar -> allow the tool to populate
c) select from an example that is closest to your CPU -> for your immediate project, I selected XCORE-200 Explorer Kit -> AN00155 (SIMPLE GPIO example -> double click to import this project
d) once back in EDIT perspective -> Project (top bar) -> Build All -> this project build will generate some errors that will auto-resolve as the project will demand some extra libraries to be imported and/or updated -> allow for the tool to auto resolve the issues. In the end, the AN00155 will build correctly and generate an executable binary with the .XE suffix.
e) After the above confirmation of a successful build, proceed to locate the main.xc file and massage this file to be your own.
Here is your code inside the same GPIO project:
Code: Select all
// Copyright (c) 2016, XMOS Ltd, All rights reserved
#include <xs1.h>
#include <platform.h>
#include <gpio.h>
out port p_out = XS1_PORT_8A;
out port p_clock_out = XS1_PORT_1A;
clock clk = XS1_CLKBLK_1; /*identifier for clock named clk*/
int main(void)
{
configure_clock_rate(clk, 100, 8); /*configures clock to 100/8 =12.5Mhz*/
configure_out_port(p_out, clk, 0);/* configures outputport p_out with 0*/
configure_port_clock_output(p_clock_out , clk);
start_clock(clk);
for (int i=0; i<5; i++)
p_out <: i;
}
/*
// GPIO port declarations
on tile[0] : in port explorer_buttons = XS1_PORT_4E;
on tile[0] : out port explorer_leds = XS1_PORT_4F;
// GPIO handler routine
void gpio_handler(client input_gpio_if button_1, client input_gpio_if button_2,
client output_gpio_if led_green, client output_gpio_if rgb_led_blue,
client output_gpio_if rgb_led_green, client output_gpio_if rgb_led_red) {
// LED state
unsigned int green_led_state = 0;
unsigned int rgb_led_state = 0;
// Initial button event state, active low
button_1.event_when_pins_eq(0);
button_2.event_when_pins_eq(0);
while (1) {
select {
// Triggered by events on button 1
case button_1.event():
if (button_1.input() == 0) {
green_led_state = ~green_led_state;
led_green.output(green_led_state);
// Set button event state to active high for debounce
button_1.event_when_pins_eq(1);
} else {
// Debounce button
delay_milliseconds(50);
button_1.event_when_pins_eq(0);
}
break;
// Triggered by events on button 2
case button_2.event():
if (button_2.input() == 0) {
rgb_led_red.output(0);
rgb_led_green.output(0);
rgb_led_blue.output(0);
rgb_led_state++;
rgb_led_state %= 4;
switch (rgb_led_state) {
case 1:
rgb_led_red.output(1);
break;
case 2:
rgb_led_green.output(1);
break;
case 3:
rgb_led_blue.output(1);
break;
}
// Set button event state to active high for debounce
button_2.event_when_pins_eq(1);
} else {
// Debounce button
delay_milliseconds(50);
button_2.event_when_pins_eq(0);
}
break;
}
// end of event select
}
}
// The main() function runs a single task which takes the gpio interfaces as parameters
int main() {
input_gpio_if i_explorer_buttons[2];
output_gpio_if i_explorer_leds[4];
par {
on tile[0] : input_gpio_with_events(i_explorer_buttons, 2, explorer_buttons, null);
on tile[0] : output_gpio(i_explorer_leds, 4, explorer_leds, null);
on tile[0] : gpio_handler(i_explorer_buttons[0], i_explorer_buttons[1],
i_explorer_leds[0], i_explorer_leds[1],
i_explorer_leds[2], i_explorer_leds[3]);
}
return 0;
}
*/
Project -> Build All again.
Then code should build fine but this time with your custom code.
xmos_pwm_compiled.png
Give it a try and post your results.
Also, personally also like to use real external tools to validate the hardware but do note that the XMOS toolchain features a simulator where you can test your code run without actual hardware. There are some code examples on how to use this tool (EXAMPLES (left bar) -> XSCOPE examples).