Phoenard
PHNUtils.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
31 #include <Arduino.h>
32 
33 #ifndef __PHNUTILS_H__
34 #define __PHNUTILS_H__
35 
37 #define swap(a, b) { int16_t t = a; a = b; b = t; }
38 
40 int getFreeRAM(void);
41 
43 char* allocateCopy(const char* src);
44 
46 uint8_t bit_reverse(uint8_t b);
47 
48 // Stream utility functions
50 void flushRead(Stream &stream);
51 
53 bool waitAvailable(Stream &stream, unsigned long timeoutMS);
54 
62 bool flushTransfer(Stream &streamA, Stream &streamB);
63 
69 int strcpy_count(char* destination, const char* source);
70 
78 void shiftElements(void* ptr, int blockSize, int blockCount, int shiftCount);
79 
80 /* Utility classes are included here as they may use PHNUtils.h */
81 #include "BufferedReadStream.h"
82 #include "FlashMemoryStream.h"
83 #include "MemoryStream.h"
84 #include "DataBuffer.h"
85 
86 #endif
bool waitAvailable(Stream &stream, unsigned long timeoutMS)
Waits until a character becomes available to be read.
Definition: PHNUtils.cpp:37
void shiftElements(void *ptr, int blockSize, int blockCount, int shiftCount)
Shifts array elements forwards or backwards, settings the shift-out memory to NULL.
Definition: PHNUtils.cpp:125
uint8_t bit_reverse(uint8_t b)
Reverses the byte bit order.
Definition: PHNUtils.cpp:102
char * allocateCopy(const char *src)
Allocates a new copy of a String on the heap.
Definition: PHNUtils.cpp:110
Contains the MemoryStream for accessing RAM as a Stream.
int getFreeRAM(void)
Gets how much RAM is still available.
Definition: PHNUtils.cpp:57
void flushRead(Stream &stream)
Reads a stream until no further reading is possible.
Definition: PHNUtils.cpp:32
int strcpy_count(char *destination, const char *source)
Copies one string to another, counting how many characters are copied.
Definition: PHNUtils.cpp:117
bool flushTransfer(Stream &streamA, Stream &streamB)
Flushes one stream to another and vice versa.
Definition: PHNUtils.cpp:46
Contains the DataBuffer class for safely storing dynamic memory on the heap.
Contains the FlashMemoryStream for reading flash memory as a stream of data.
Contains the BufferedReadStream class to read data with a buffer.