Lesson 03: PSoC Creator System Reference Guild - Data Types and APIs

PSoC Creator providers some useful APIs that can be used in your code.

  • Standard C data types (implicit sizes)
    Type Size
    (Bytes)
    Range Description Precision
    (Decimal place)
    printf() identifier
    char 1

    unsigned: 0 ... 255
    signed: -128 ... 127

    Character   %c
    short 2 unsigned: 0 ... 65535
    signed:-32,768 ... 32767
    Standard type specifying 2-byte integers   %i
    int 4 unsigned: 0 ... 4,294,967,295
    signed:-2,147,483,648 ... 2,147,483,647
    Integer number   %i
    long 4 unsigned: 0 ... 4,294,967,295
    signed:-2,147,483,648 ... 2,147,483,647
        %i
    float 4 1.175e-38 ... 3.40e+38 Signal presision floating point number 6 %f
    double 8 2.3E-308 ... 1.7E+308 Double presision floating point number 15 %f
    long double 8 2.3E-308 ... 1.7E+308     %f
    enum 1
    2
    1 byte if enum < 256
    2 bytes if enum > 256  0 ... 65535
    Used to define a list of aliases that represent integers    
  • Cypress-defined data types
    Type Description
    char8 8-bit (signed or unsigned, depending on the compiler selection for char)
    uint8 8-bit unsigned
    uint16 16-bit unsigned
    uint32 32-bit unsigned
    int8 8-bit signed
    int16 16-bit signed
    int32 32-bit signed
  • Types available through <stdint.h>
    Type Description
    uint8_t 8-bit unsigned integer
    uint16_t 16-bit unsigned integer
    uint32_t 32-bit unsigned integer
    uint64_t 64-bit unsigned integer
    int8_t 8-bit signed integer
    int16_t 16-bit signed integer
    int32_t 32-bit signed integer
    int64_t 64-bit signed integer
  • Delay Functions
    Function Prototype Arguments Description
    void CyDelay(uint32 milliseconds) uint32 milliseconds
    Number of milliseconds to delay
    Delay by the specified number of milliseconds.
    void CyDelayUs(uint32 microseconds) uint32 microseconds
    Number of microseconds to delay
    Delay by the specified number of microseconds.
    void CyDelayFreq(uint32 freq) uint32 freq
    Bus clock frequency in Hz;
    0: Use default value
    Nonzero: Set freq value
    Sets the Bus Clock frequency used to calculate the number of cycles needed to implement a delay with CyDelay or CyDelayUs functions.
    By default, the frequency used is based on the value determined by PSoC Creator at build time.
    void CyDelayCycles(uint32 cycles) uint32 cycles
    Number of cycles to delay
    Delay by the specified number of cycles using a software delay loop
  • Macro statements
    CyGlobalIntEnable Enables interrupts using the global interrupt mask
    CyGlobalIntDisable Disable interrupts using the global interrupt mask

 Here, lists some useful defines:

/* ========================================
 *
 * Copyright YOUR COMPANY, THE YEAR
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF your company.
 *
 * ========================================
*/
#ifndef MY_DEFINE_H
#define MY_DEFINE_H

#include  <stdint.h>
#include  <stdbool.h>
#include  <stdlib.h>
#include  <string.h>
#include  <math.h>

#define  HIGH      0x1
#define  LOW       0x0

#define  INPUT     0x0
#define  OUTPUT    0x1

#define  PI           3.1415926535897932384626433832795
#define  HALF_PI      1.5707963267948966192313216916398
#define  TWO_PI       6.283185307179586476925286766559
#define  DEG_TO_RAD   0.017453292519943295769236907684886
#define  RAD_TO_DEG   57.295779513082320876798154814105

#define  min(a,b)  ((a)<(b)?(a):(b))
#define  max(a,b)  ((a)>(b)?(a):(b))
#define  abs(x)    ((x)>0?(x):-(x))
#define  constrain(amt,low,high)  ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define  round(x)  ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define  radians(deg)  ((deg)*DEG_TO_RAD)
#define  degrees(rad)  ((rad)*RAD_TO_DEG)
#define  sq(x)     ((x)*(x))

#define  lowByte(w)   ((uint8_t) ((w) & 0xff))
#define  highByte(w)  ((uint8_t) ((w) >> 8))

#define  bitRead(value, bit)  (((value) >> (bit)) & 0x01)
#define  bitSet(value, bit)   ((value) |= (1UL << (bit)))
#define  bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define  bitWrite(value, bit, bitvalue)  (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
#define bit(b) (1UL << (b))

typedef  unsigned  int  word;
typedef  uint8_t  byte;

#endif