Exemple #1
0
void app_setup() {
  P3OUT = 0x00;
  init_app_adt7310p16s16();
#ifndef SIMULATION
  // For simulation we use a shorter value to reduce simulation time. The value
  // is given as default value in chll/sripts/setup.tcl as 24000, which at a
  // clock frequency of 100kHz provides 240ms delay.
  // On chip we use e.g. 10MHz and therefore need a value of 2400000, but that
  // is not possible with the 16 bit counter. Therefore we use 20000 to realize
  // 2ms, which is defined above as SPI_DELAY.
  ParamWrite(PARAM_SPICOUNTERPRESET_I_ADDR,SPI_DELAY);
#endif
}
Exemple #2
0
void app_setup() {
  P3OUT = 0x00;
  init_app_adt7310p32ls32l();
#ifndef SIMULATION
  // For simulation we use a shorter value to reduce simulation time. The value
  // is given as default value in chll/sripts/setup.tcl as 24000, which at a
  // clock frequency of 100kHz provides 240ms delay.
  // On chip we use e.g. 10MHz and therefore need a value of 2400000, which
  // is defined above as SPI_DELAY.
  ParamWrite(PARAM_SPICOUNTERPRESETL_I_ADDR,SPI_DELAY & 0x0000FFFF);
  ParamWrite(PARAM_SPICOUNTERPRESETH_I_ADDR,SPI_DELAY >> 16);
#endif
}
void init_app_max6682mean() {
  // Configuration
  ConfigBegin();
  Configure(CFGREG_RECONFSIGNALS_ADDR,                 &CfgReconfSignals);
  Configure(CFGREG_BITDATA_ADDR,                       &Cfgbitdata);
  Configure(CFGREG_CFGREG_TRFSM0_0_ADDR,               &CfgCfgReg_TRFSM0_0);
  Configure(CFGREG_CFGREG_TRFSM1_0_ADDR,               &CfgCfgReg_TRFSM1_0);

  // Param default values
  ParamWrite(PARAM_I2C_DIVIDER800_ADDR,                           0x0000);
  ParamWrite(PARAM_I2C_ERRACKPARAM_ADDR,                          0x0000);
  ParamWrite(PARAM_PAUSECOUNTERPRESET_I_ADDR,                     0x0050);
  ParamWrite(PARAM_THRESHOLD_I_ADDR,                              0x0028);
  ParamWrite(PARAM_PERIODCOUNTERPRESETL_I_ADDR,                   0x03E8);
  ParamWrite(PARAM_PERIODCOUNTERPRESETH_I_ADDR,                   0x0000);
  ParamWrite(PARAM_PARAMIN_WORD_4_ADDR,                           0x0000);

  // Done with setup, release reconf.module from config mode
  ConfigEnd();
}
Exemple #4
0
void WriteGameSettings(sParam *settings)
{
	ParamWrite(SETTINGS_FILE, settings);
}
Exemple #5
0
void app_set_periode(uint16_t periode) {
  ParamWrite(PARAM_PERIODCOUNTERPRESET_I_ADDR, periode);
}
Exemple #6
0
void app_set_threshold(uint16_t threshold) {
  ParamWrite(PARAM_THRESHOLD_I_ADDR, threshold);
}
Exemple #7
0
/******************************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user routines.
 *                  It is a mixture of both USB and non-USB tasks.
 *
 * Note:            None
 *****************************************************************************/
void USBUpdate(void) {
  byte data[2];
  byte i;
  byte paramNum;
  ulong tempLong;
  
  USBDeviceTasks();
  
  if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl==1)) {
    return;
  }

  //As the device completes the enumeration process, the USBCBInitEP() function will
  //get called.  In this function, we initialize the user application endpoints (in this
  //example code, the user application makes use of endpoint 1 IN and endpoint 1 OUT).
  //The USBGenRead() function call in the USBCBInitEP() function initializes endpoint 1 OUT
  //and "arms" it so that it can receive a packet of data from the host.  Once the endpoint
  //has been armed, the host can then send data to it (assuming some kind of application software
  //is running on the host, and the application software tries to send data to the USB device).

  //If the host sends a packet of data to the endpoint 1 OUT buffer, the hardware of the SIE will
  //automatically receive it and store the data at the memory location pointed to when we called
  //USBGenRead().  Additionally, the endpoint handle (in this case USBGenericOutHandle) will indicate
  //that the endpoint is no longer busy.  At this point, it is safe for this firmware to begin reading
  //from the endpoint buffer, and processing the data.  In this example, we have implemented a few very
  //simple commands.  For example, if the host sends a packet of data to the endpoint 1 OUT buffer, with the
  //first byte = 0x80, this is being used as a command to indicate that the firmware should "Toggle LED(s)".
  if(!USBHandleBusy(USBGenericOutHandle) && //Check if the endpoint has received any data from the host.
	  //Now check to make sure no previous attempts to send data to the host are still pending.  If any attemps are still
    //pending, we do not want to write to the endpoint 1 IN buffer again, until the previous transaction is complete.
    //Otherwise the unsent data waiting in the buffer will get overwritten and will result in unexpected behavior.
     (!USBGenericInHandle || !USBHandleBusy(USBGenericInHandle))) {
    if (OUTPacket[USB_PACKET_LEN] < 7) {
      // message too short
    }
    else {
      usbActivityTimeout = 3000; // reset timeout (in ms) 3 seconds
      
      switch(OUTPacket[USB_PACKET_CMD]) {				//Data arrived, check what kind of command might be in the packet of data.
      case USB_CMD_NULL:        // 0x00
        if (OUTPacket[USB_PACKET_LEN] != 7) {
          data[0] = USB_ERR_BAD_LEN;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else {
          UsbSendResp(USB_RESP_NULL, data);
        }  
        break;

      case USB_CMD_GET_VSTRING:
        if (OUTPacket[USB_PACKET_LEN] != 7) {
          data[0] = USB_ERR_BAD_LEN;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else {
          UsbSendResp(USB_RESP_GET_VSTRING, data);
        }  
        break;
        
      case USB_CMD_GET_CHAN:
        if (OUTPacket[USB_PACKET_LEN] != 7) {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else if (OUTPacket[USB_PACKET_STR] >= NUM_STRINGS) {
          data[0] = USB_ERR_BAD_PRM;
          data[1] = 0;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else if (!OUTPacket[USB_PACKET_MCT] || OUTPacket[USB_PACKET_MCT] > NUM_MCT) {
          data[0] = USB_ERR_BAD_PRM;
          data[1] = 1;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else {
          UsbSendResp(USB_RESP_GET_CHAN, data);
        }
        break;

      case USB_CMD_GET_MIRRORS:
        if (OUTPacket[USB_PACKET_LEN] != 7) {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else if (OUTPacket[USB_PACKET_STR] >= NUM_STRINGS) {
          data[0] = USB_ERR_BAD_PRM;
          data[1] = 0;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else if (!OUTPacket[USB_PACKET_MCT] || OUTPacket[USB_PACKET_MCT] > NUM_MCT) {
          data[0] = USB_ERR_BAD_PRM;
          data[1] = 1;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else {
          UsbSendResp(USB_RESP_GET_MIRRORS, data);
        }
        break;

      case USB_CMD_GET_STRING:
        if (OUTPacket[USB_PACKET_LEN] != 7) {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else if (OUTPacket[USB_PACKET_STR] >= NUM_STRINGS) {
          data[0] = USB_ERR_BAD_PRM;
          data[1] = 0;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        else {
          UsbSendResp(USB_RESP_GET_STRING, data);
        }
        break;

      case USB_CMD_FIELD_STATE:
        if (OUTPacket[USB_PACKET_LEN] == 7) {
          UsbSendResp(USB_RESP_FIELD_STATE, data);
        }  
        else if (OUTPacket[USB_PACKET_LEN] == 8) {
          FieldNewState(OUTPacket[USB_PACKET_DATA]);
          UsbSendResp(USB_RESP_FIELD_STATE, data);
        }  
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;

      case USB_CMD_GET_FCE:
        if (OUTPacket[USB_PACKET_LEN] == 7) {
          UsbSendResp(USB_RESP_GET_FCE, data);
        }  
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;
      
      case USB_CMD_GET_RTU:
        if (OUTPacket[USB_PACKET_LEN] == 7) {
          UsbSendResp(USB_RESP_GET_RTU, data);
        }  
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;

      case USB_CMD_SEND_MCT485:  // 0x64
        if (OUTPacket[USB_PACKET_LEN] >= 11
            && OUTPacket[USB_PACKET_LEN] <  MCT485_MAX_INDEX + 7) {
          //Mct485CannedMsg(MSG_ORIGIN_USB,
          //               OUTPacket[USB_PACKET_STR],
          //               OUTPacket[USB_PACKET_LEN]-7,
          //               &OUTPacket[USB_PACKET_DATA]);
          usb485TxString = OUTPacket[USB_PACKET_STR];
          usb485TxLen = OUTPacket[USB_PACKET_LEN]-7;
          for (i = 0; i < usb485TxLen; i++) {
            usb485TxBuffer[i] = OUTPacket[USB_PACKET_DATA+i];
          }
          // clear 485 response buffer
          usb485RxLen = 0;
          UsbSendResp(USB_RESP_SEND_MCT485, data);
        }  
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;

      case USB_CMD_GET_MCT485:   // 0x65
        if (OUTPacket[USB_PACKET_LEN] == 7) {
          UsbSendResp(USB_RESP_GET_MCT485, data);
        }  
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;
      
      case USB_CMD_RTC:         // 0x66
        if (OUTPacket[USB_PACKET_LEN] == 7) {
          UsbSendResp(USB_RESP_RTC, data);
        }
        else if (OUTPacket[USB_PACKET_LEN] == 13) {
          RtcSetClock(&OUTPacket[USB_PACKET_DATA]);
          UsbSendResp(USB_RESP_RTC, data);
        }
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;
      
      case USB_CMD_LOG:        // 0x67
        if (OUTPacket[USB_PACKET_LEN] == 7) {
          UsbSendResp(USB_RESP_LOG, data);
        }
        else if (OUTPacket[USB_PACKET_LEN] == 8) {
          if (OUTPacket[USB_PACKET_DATA] == 0) {
            DataLogFindFirstEntry();
          }
          else if (OUTPacket[USB_PACKET_DATA] == 0xFF) {  
            DataLogErase();
          }
          UsbSendResp(USB_RESP_LOG, data);
        }
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;
      
      case USB_CMD_DESICCANT:   // 0x68
        if (OUTPacket[USB_PACKET_LEN] == 7) {
          UsbSendResp(USB_RESP_DESICCANT, data);
        }
        else if (OUTPacket[USB_PACKET_LEN] == 9) {
          // manual force dessicant to set of outputs or state
          DesiccantNewState(OUTPacket[USB_PACKET_DATA], OUTPacket[USB_PACKET_DATA+1]);
          UsbSendResp(USB_RESP_DESICCANT, data);
        }  
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;
      
      case USB_CMD_SFC_PARAM:  // 0x69
        if (OUTPacket[USB_PACKET_LEN] == 8) {
          UsbSendResp(USB_RESP_SFC_PARAM, data);
        }
        else if (OUTPacket[USB_PACKET_LEN] > 8 && !(OUTPacket[USB_PACKET_LEN] & 0x03)) {
          // process one param at a time, prevents I2C queue entry overflow and avoids
          // I2C page boundary problems
          paramNum = OUTPacket[USB_PACKET_DATA];
          i = USB_PACKET_DATA+1;
          while (i < OUTPacket[USB_PACKET_LEN]-2) {
            tempLong = OUTPacket[i++];
            tempLong *= 256;
            tempLong += OUTPacket[i++];
            tempLong *= 256;
            tempLong += OUTPacket[i++];
            tempLong *= 256;
            tempLong += OUTPacket[i++];
            ParamWrite(paramNum, tempLong);
            paramNum++;
          }
          UsbSendResp(USB_RESP_SFC_PARAM, data);
        }  
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;
      
      case USB_CMD_MEMORY:     // 0x6A
        if (OUTPacket[USB_PACKET_LEN] == 11) {
          data[4] = 16;
          UsbSendResp(USB_RESP_MEMORY, data);
        }
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;
      
      case USB_CMD_TEST:      // 0x6B
        if (OUTPacket[USB_PACKET_LEN] == 8) {
          UsbSendResp(USB_RESP_TEST, data);
          for (tempLong = 0; tempLong < 1000000; tempLong++) {
          }
          if (OUTPacket[USB_PACKET_DATA] == 0x01) {
            Mct485Init();
          }
          else if (OUTPacket[USB_PACKET_DATA] == 0x02) {
            StringInit();
          }
          else if (OUTPacket[USB_PACKET_DATA] == 0x03) {
            FieldInit();
          }
          else if (OUTPacket[USB_PACKET_DATA] == 0x04) {
            SoftReset();
          }
        }
        else {
          data[0] = USB_ERR_BAD_LEN;
          data[1] = 7;
          UsbSendResp(USB_RESP_BAD_MSG, data);
        }
        break;
      } // switch (cmd)
    } // else process messages  

    //Re-arm the OUT endpoint for the next packet:
	  //The USBGenRead() function call "arms" the endpoint (and makes it "busy").  If the endpoint is armed, the SIE will
	  //automatically accept data from the host, if the host tries to send a packet of data to the endpoint.  Once a data
	  //packet addressed to this endpoint is received from the host, the endpoint will no longer be busy, and the application
	  //can read the data which will be sitting in the buffer.
    USBGenericOutHandle = USBGenRead(USBGEN_EP_NUM,(BYTE*)&OUTPacket,USBGEN_EP_SIZE);
  } // if
}// UsbUpdate()