Serial Wombat Arduino Library
SerialWombatThroughputConsumer.h
Go to the documentation of this file.
1 #pragma once
2 /*
3 Copyright 2021-2023 Broadwell Consulting Inc.
4 
5 "Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6 the United States. See SerialWombat.com for usage guidance.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25 */
26 
27 #include <stdint.h>
28 #include "SerialWombat.h"
29 
45 {
46 public:
52 
53  /*
54  @brief Initialize an instance of the Throughput Conumer class. All delays are set to 0.
55  @return Returns a negative error code if initialization failed.
56  */
57  int16_t begin(uint8_t pin)
58  {
59  _pin = pin;
60  uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE0,pin,
62  0x55,0x55,0x55,0x55,0x55 };
63  return _sw.sendPacket(tx);
64  }
65 
66 
72 
73  int16_t writeAll(uint16_t delay)
74  {
75  for (int i = 0; i < 16; ++i)
76  {
77  uint8_t tx[] = {(uint8_t) SerialWombatCommands::CONFIGURE_PIN_MODE1,
78  _pin,
80  (uint8_t)i,
81  SW_LE16(delay), 0x55,0x55 };
82  int16_t result = _sw.sendPacket(tx);
83  if (result < 0)
84  {
85  return (result);
86  }
87  }
88  return 0;
89  }
90 
99  int16_t write(uint8_t frame, uint16_t delay)
100  {
101  uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE1,
102  _pin,
104  frame,
105  SW_LE16(delay), 0x55,0x55 };
106  return( _sw.sendPacket(tx));
107  }
108 
109 
117  int16_t delayInCommProcessing(uint16_t delay)
118  {
119  uint8_t tx[] = { (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE2,
120  _pin,
122  SW_LE16(delay), 0x55,0x55, 0x55 };
123  return(_sw.sendPacket(tx));
124  }
125 
126 };
127 
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:286
SerialWombatCommands::CONFIGURE_PIN_MODE0
@ CONFIGURE_PIN_MODE0
(200)
SerialWombatThroughputConsumer::write
int16_t write(uint8_t frame, uint16_t delay)
Set a frame delay time to a specified number of uS.
Definition: SerialWombatThroughputConsumer.h:99
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition: SerialWombatPin.h:134
SerialWombatThroughputConsumer::delayInCommProcessing
int16_t delayInCommProcessing(uint16_t delay)
Delay a specified number of uS within the packet processing routine.
Definition: SerialWombatThroughputConsumer.h:117
SerialWombat.h
SerialWombatPin
Describes a Serial Wombat Pin. Is base class for other pin modes.
Definition: SerialWombatPin.h:38
SerialWombatChip::sendPacket
int sendPacket(uint8_t tx[], uint8_t rx[])
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back.
Definition: SerialWombat.cpp:115
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition: SerialWombatPin.h:121
PIN_MODE_THROUGHPUT_CONSUMER
@ PIN_MODE_THROUGHPUT_CONSUMER
(4)
Definition: SerialWombat.h:246
SerialWombatPin::_pin
uint8_t _pin
Definition: SerialWombatPin.h:133
SerialWombatThroughputConsumer::SerialWombatThroughputConsumer
SerialWombatThroughputConsumer(SerialWombatChip &serialWombat)
Constructor for SerialWombatThroughputConsumer class.
Definition: SerialWombatThroughputConsumer.h:51
SerialWombatCommands::CONFIGURE_PIN_MODE2
@ CONFIGURE_PIN_MODE2
(202)
SW_LE16
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
Definition: SerialWombat.h:41
SerialWombatThroughputConsumer::writeAll
int16_t writeAll(uint16_t delay)
Set all delay times to a specified number of uS / /.
Definition: SerialWombatThroughputConsumer.h:73
SerialWombatCommands::CONFIGURE_PIN_MODE1
@ CONFIGURE_PIN_MODE1
(201)
SerialWombatThroughputConsumer
A Class that consumes CPU time on the Serial Wombat chip in order to facilitate testing.
Definition: SerialWombatThroughputConsumer.h:44
SerialWombatThroughputConsumer::begin
int16_t begin(uint8_t pin)
Definition: SerialWombatThroughputConsumer.h:57