/*
 * -------------------------------------------------------------------
 * MPLAB 16-Bit Device Blocks for Simulink v3.38.
 *
 *   Product Page:  http://www.microchip.com/SimulinkBlocks
 *           Forum: http://www.microchip.com/forums/f192.aspx
 *           Wiki:  http://microchip.wikidot.com/simulink:start
 * -------------------------------------------------------------------
 * File: dsPIC_main_22_4_2018.h
 *
 * Code generated for Simulink model 'dsPIC_main_22_4_2018'.
 *
 * Model version                  : 1.96
 * Simulink Coder version         : 8.9 (R2015b) 13-Aug-2015
 * C/C++ source code generated on : Sun Apr 22 14:14:28 2018
 */

#ifndef RTW_HEADER_dsPIC_main_22_4_2018_h_
#define RTW_HEADER_dsPIC_main_22_4_2018_h_
#include <math.h>
#include <string.h>
#include <stddef.h>
#ifndef dsPIC_main_22_4_2018_COMMON_INCLUDES_
# define dsPIC_main_22_4_2018_COMMON_INCLUDES_
#include "rtwtypes.h"
#endif                                 /* dsPIC_main_22_4_2018_COMMON_INCLUDES_ */

#include "dsPIC_main_22_4_2018_types.h"
#define FCY                            7.0E+7

/* Include for pic 33E */
#include <p33Exxxx.h>
#include <libpic30.h>                  /* For possible use with C function Call block (delay_ms or delay_us functions might be used by few peripherals) */
#include <libq.h>                      /* For possible use with C function Call block */

/* Macros for accessing real-time model data structure */
#ifndef rtmCounterLimit
# define rtmCounterLimit(rtm, idx)     ((rtm)->Timing.TaskCounters.cLimit[(idx)])
#endif

#ifndef rtmStepTask
# define rtmStepTask(rtm, idx)         ((rtm)->Timing.TaskCounters.TID[(idx)] == 0)
#endif

#ifndef rtmTaskCounter
# define rtmTaskCounter(rtm, idx)      ((rtm)->Timing.TaskCounters.TID[(idx)])
#endif

/* Declare UART1 Tx Circular Buffer Structure */
#define Tx_BUFF_SIZE_Uart1             (128)

typedef struct MCHP_UART1_TxStr{
  volatile uint8_T buffer[Tx_BUFF_SIZE_Uart1];/* Size Rx_BUFF_SIZE_Uart1 is 128 */
  uint_T tail;                         /* tail is the index for the next value to be read from the Circular buffer */
  volatile uint_T head;                /* head is the index for the next value to be written into the Circular buffer */
} MCHP_UART1_TxStr;

/* Declare UART1 Rx Circular Buffer Structure */
#define Rx_BUFF_SIZE_Uart1             (128)

typedef struct MCHP_UART1_RxStr{
  volatile uint8_T buffer[Rx_BUFF_SIZE_Uart1];/* Size Rx_BUFF_SIZE_Uart1 is 128 */
  volatile uint_T tail;                /* tail is the index for the next value to be written into the Circular buffer */
  uint_T head;                         /* head is the index for the next value to be read from the Circular buffer */
} MCHP_UART1_RxStr;

/* To read the UART1 Rx Circular with a custom code: read the next value: buffer[head], then increment head index by 1 modulo Rx_BUFF_SIZE_Uart1 (=128).
   code example:
   if (U1STAbits.URXDA != 0)
 // SET U1RXIF bit to 1 Flush internal UART buffer through the interrupt
   if (MCHP_UART1_Rx.tail != MCHP_UART1_Rx.head)	{  		// is buffer not empty ?
   output = (uint8_T) MCHP_UART1_Rx.buffer[MCHP_UART1_Rx.head ++];     // Read one char
   MCHP_UART1_Rx.head &= (Rx_BUFF_SIZE_Uart1-1); 	// modulo : use a simple bitewise "and" operator as <Rx_BUFF_SIZE_Uart1> is a power of 2
   }
 */

/* Block signals and states (auto storage) for system '<Root>' */
typedef struct {
  int32_T counter;                     /* '<Root>/Sine Wave' */
  uint8_T message[6];                  /* '<Root>/Message packeting' */
  uint8_T y[2];                        /* '<Root>/MATLAB Function' */
  uint8_T U1CH1;                       /* '<Root>/SPI1_external_adc_readings' */
  uint8_T SPI1_external_adc_readings_o2;/* '<Root>/SPI1_external_adc_readings' */
} DW_dsPIC_main_22_4_2018_T;

/* Real-time Model Data Structure */
struct tag_RTM_dsPIC_main_22_4_2018_T {
  /*
   * Timing:
   * The following substructure contains information regarding
   * the timing information for the model.
   */
  struct {
    struct {
      uint8_T TID[2];
      uint8_T cLimit[2];
    } TaskCounters;
  } Timing;
};

/* Block signals and states (auto storage) */
extern DW_dsPIC_main_22_4_2018_T dsPIC_main_22_4_2018_DW;

/* Model entry point functions */
extern void dsPIC_main_22_4_2018_initialize(void);
extern void dsPIC_main_22_4_2018_step0(void);
extern void dsPIC_main_22_4_2018_step1(void);

/* Real-time Model object */
extern RT_MODEL_dsPIC_main_22_4_2018_T *const dsPIC_main_22_4_2018_M;

/*-
 * The generated code includes comments that allow you to trace directly
 * back to the appropriate location in the model.  The basic format
 * is <system>/block_name, where system is the system number (uniquely
 * assigned by Simulink) and block_name is the name of the block.
 *
 * Use the MATLAB hilite_system command to trace the generated code back
 * to the model.  For example,
 *
 * hilite_system('<S3>')    - opens system 3
 * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
 *
 * Here is the system hierarchy for this model
 *
 * '<Root>' : 'dsPIC_main_22_4_2018'
 * '<S1>'   : 'dsPIC_main_22_4_2018/MATLAB Function'
 * '<S2>'   : 'dsPIC_main_22_4_2018/MATLAB Function2'
 * '<S3>'   : 'dsPIC_main_22_4_2018/Message packeting'
 * '<S4>'   : 'dsPIC_main_22_4_2018/Repeating Sequence Interpolated'
 * '<S5>'   : 'dsPIC_main_22_4_2018/Sine'
 * '<S6>'   : 'dsPIC_main_22_4_2018/Sine/Sine'
 * '<S7>'   : 'dsPIC_main_22_4_2018/Sine/Sine/Handle Quarter Symmetry Sine'
 */
#endif                                 /* RTW_HEADER_dsPIC_main_22_4_2018_h_ */

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
