/* ... */
volatile bit got_sud;
+BYTE vendor_command;
static void setup_endpoints(void)
{
BOOL handle_vendorcommand(BYTE cmd)
{
/* Protocol implementation */
-
switch (cmd) {
- case CMD_GET_FW_VERSION:
- /* TODO */
- break;
case CMD_START:
- gpif_acquisition_start();
+ /* There is data to receive - arm EP0 */
+ EP0BCL = 0;
+ case CMD_GET_FW_VERSION:
+ vendor_command = cmd;
return TRUE;
default:
/* Unimplemented command. */
REVCTL = bmNOAUTOARM | bmSKIPCOMMIT;
got_sud = FALSE;
+ vendor_command = 0;
/* Renumerate. */
RENUMERATE_UNCOND();
handle_setupdata();
got_sud = FALSE;
}
+
+ if (vendor_command) {
+ switch (vendor_command) {
+ case CMD_GET_FW_VERSION:
+ /* TODO */
+
+ /* Acknowledge the vendor command. */
+ vendor_command = 0;
+ break;
+
+ case CMD_START:
+ if((EP0CS & bmEPBUSY) != 0)
+ break;
+
+ if(EP0BCL == 2) {
+ gpif_acquisition_start(
+ (const struct cmd_start_acquisition*)EP0BUF);
+ }
+
+ /* Acknowledge the vendor command. */
+ vendor_command = 0;
+ break;
+
+ default:
+ /* Unimplemented command. */
+ vendor_command = 0;
+ break;
+ }
+ }
}
gpif_init_flowstates();
}
-void gpif_acquisition_start(void)
+void gpif_acquisition_start(const struct cmd_start_acquisition *cmd)
{
xdata volatile BYTE *pSTATE;
+ IFCONFIG = (IFCONFIG & ~bm3048MHZ) |
+ ((cmd->flags & CMD_START_FLAGS_CLK_48MHZ) ? bm3048MHZ : 0);
+
/* GPIF terminology: DP = decision point, NDP = non-decision-point */
/* Populate WAVEDATA
/* Populate S0 */
pSTATE = &GPIF_WAVE_DATA;
- pSTATE[0] = 0x01;
+ pSTATE[0] = cmd->sample_delay;
pSTATE[8] = 0x02;
pSTATE[16] = 0x00;
pSTATE[24] = 0x00;
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdint.h>
+
/* Protocol commands */
#define CMD_GET_FW_VERSION 0xb0
#define CMD_START 0xb1
+
+#define CMD_START_FLAGS_CLK_SRC_POS 6
+
+#define CMD_START_FLAGS_CLK_30MHZ (0 << CMD_START_FLAGS_CLK_SRC_POS)
+#define CMD_START_FLAGS_CLK_48MHZ (1 << CMD_START_FLAGS_CLK_SRC_POS)
+
+struct cmd_start_acquisition
+{
+ uint8_t flags;
+ uint8_t sample_delay;
+};
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <command.h>
+
void gpif_init_la(void);
-void gpif_acquisition_start(void);
+void gpif_acquisition_start(const struct cmd_start_acquisition *cmd);