#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iothinx/iothinxio.h>
int main(
int argc,
char **
const argv)
{
int32_t rc;
uint32_t do_slot = 2;
uint8_t do_modes[16];
uint8_t pwm_channel_start = 0;
uint8_t pwm_channel_count = 2;
uint32_t pwm_starts = 0;
uint16_t pwm_freqs[4];
uint16_t pwm_dutys[4];
uint32_t pwm_counts[4];
int32_t i;
char ch;
while (-1 != (rc = getopt(argc, argv, "c:hn:s:")))
{
switch (rc)
{
case 'c':
pwm_channel_start = atoi(optarg);
break;
case 'n':
pwm_channel_count = atoi(optarg);
break;
case 's':
do_slot = atoi(optarg);
break;
case 'h':
default:
printf("PWM sample program.\n\n");
printf("Usage: ./pwm [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Slot of DO module. Default slot = %d\n", "-s", do_slot);
printf("\t%-8s PWM start channel. Default channel = %d\n", "-c", pwm_channel_start);
printf("\t%-8s PWM channel count. Default count = %d\n", "-n", pwm_channel_count);
printf("\n");
return 0;
}
}
printf("DO slot = %lu\n", do_slot);
printf("PWM start channel = %u\n", pwm_channel_start);
printf("PWM channel count = %u\n", pwm_channel_count);
{
printf("ioThinx_IO_Client_Init() = %d\n", rc);
return -1;
}
for (i = 0; i < pwm_channel_count; i++)
{
}
{
printf("ioThinx_DO_Config_SetModes() = %d\n", rc);
}
for (i = 0; i < pwm_channel_count; i++)
{
pwm_counts[i] = 0;
}
{
printf("ioThinx_DO_Config_SetPwmCounts() = %d\n", rc);
}
for (i = 0; i < pwm_channel_count; i++)
{
pwm_freqs[i] = 5;
pwm_dutys[i] = 50;
}
{
printf("ioThinx_DO_Config_SetPwmConfigures() = %d\n", rc);
}
{
printf("ioThinx_IO_Config_Reload() = %d\n", rc);
}
pwm_starts = 0;
for (i = 0; i < pwm_channel_count; i++)
{
pwm_starts |= 0x1 << (pwm_channel_start + i);
}
{
printf("ioThinx_DO_SetPwmStarts() = %d\n", rc);
}
do
{
pwm_dutys[0] = (pwm_dutys[0] >= 100) ? 0 : pwm_dutys[0] + 10;
{
printf("ioThinx_DO_SetPwmConfigures() = %d\n", rc);
}
for (i = 0; i < pwm_channel_count; i++)
{
printf("[%lu:%u] frequency = %d, duty cycle = %d\n", do_slot, pwm_channel_start+i, pwm_freqs[i], pwm_dutys[i]);
}
ch = getchar();
}
while (ch != 'q');
{
printf("ioThinx_DO_SetPwmStops() = %d\n", rc);
}
return 0;
}
57 uint8_t pwm_channel_start = 0;
58 uint8_t pwm_channel_count = 2;
59 uint32_t pwm_starts = 0;
60 uint16_t pwm_freqs[4];
61 uint16_t pwm_dutys[4];
62 uint32_t pwm_counts[4];
66 while (-1 != (rc = getopt(argc, argv,
"c:hn:s:")))
71 pwm_channel_start = atoi(optarg);
74 pwm_channel_count = atoi(optarg);
77 do_slot = atoi(optarg);
81 printf(
"PWM sample program.\n\n");
82 printf(
"Usage: ./pwm [OPTIONS]\n\n");
84 printf(
"\t%-8s Slot of DO module. Default slot = %d\n",
"-s", do_slot);
85 printf(
"\t%-8s PWM start channel. Default channel = %d\n",
"-c", pwm_channel_start);
86 printf(
"\t%-8s PWM channel count. Default count = %d\n",
"-n", pwm_channel_count);
92 printf(
"DO slot = %lu\n", do_slot);
93 printf(
"PWM start channel = %u\n", pwm_channel_start);
94 printf(
"PWM channel count = %u\n", pwm_channel_count);
100 printf(
"ioThinx_IO_Client_Init() = %d\n", rc);
105 for (i = 0; i < pwm_channel_count; i++)
112 printf(
"ioThinx_DO_Config_SetModes() = %d\n", rc);
115 for (i = 0; i < pwm_channel_count; i++)
122 printf(
"ioThinx_DO_Config_SetPwmCounts() = %d\n", rc);
125 for (i = 0; i < pwm_channel_count; i++)
133 printf(
"ioThinx_DO_Config_SetPwmConfigures() = %d\n", rc);
140 printf(
"ioThinx_IO_Config_Reload() = %d\n", rc);
145 for (i = 0; i < pwm_channel_count; i++)
147 pwm_starts |= 0x1 << (pwm_channel_start + i);
152 printf(
"ioThinx_DO_SetPwmStarts() = %d\n", rc);
158 pwm_dutys[0] = (pwm_dutys[0] >= 100) ? 0 : pwm_dutys[0] + 10;
162 printf(
"ioThinx_DO_SetPwmConfigures() = %d\n", rc);
164 for (i = 0; i < pwm_channel_count; i++)
166 printf(
"[%lu:%u] frequency = %d, duty cycle = %d\n", do_slot, pwm_channel_start+i, pwm_freqs[i], pwm_dutys[i]);
175 printf(
"ioThinx_DO_SetPwmStops() = %d\n", rc);
IOTHINX_ERR ioThinx_DO_SetPwmStops(uint32_t slot, uint32_t stops)
IOTHINX_ERR ioThinx_DO_Config_SetModes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
IOTHINX_ERR ioThinx_IO_Config_Reload(void)
IOTHINX_ERR ioThinx_DO_Config_SetPwmConfigures(uint32_t slot, uint8_t start, uint8_t count, uint16_t frequencies[], uint16_t duty_cycles[])
IOTHINX_ERR ioThinx_IO_Client_Init(void)
IOTHINX_ERR ioThinx_DO_SetPwmConfigures(uint32_t slot, uint8_t start, uint8_t count, uint16_t frequencies[], uint16_t duty_cycles[])
IOTHINX_ERR ioThinx_DO_SetPwmStarts(uint32_t slot, uint32_t starts)
IOTHINX_ERR ioThinx_DO_Config_SetPwmCounts(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])