//-------------------------------------------------------------------------- // // This module implements a manufacturing test mode // //-------------------------------------------------------------------------- // $Archive: /WirelessUSB/WUSB Kits/CY4632 LS KBM RDK/DocSrc/CD_Root/Firmware/Source Code/RDK Mouse/mfgtest.c $ // $Modtime: 6/16/04 4:38p10/01/04 1:18p $ // $Revision: 12 $ //-------------------------------------------------------------------------- // // Copyright 2004, Cypress Semiconductor Corporation. // // This software is owned by Cypress Semiconductor Corporation (Cypress) // and is protected by and subject to worldwide patent protection (United // States and foreign), United States copyright laws and international // treaty provisions. Cypress hereby grants to licensee a personal, // non-exclusive, non-transferable license to copy, use, modify, create // derivative works of, and compile the Cypress Source Code and derivative // works for the sole purpose of creating custom software in support of // licensee product to be used only in conjunction with a Cypress integrated // circuit as specified in the applicable agreement. Any reproduction, // modification, translation, compilation, or representation of this // software except as specified above is prohibited without the express // written permission of Cypress. // // Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, // WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // Cypress reserves the right to make changes without further notice to the // materials described herein. Cypress does not assume any liability arising // out of the application or use of any product or circuit described herein. // Cypress does not authorize its products for use as critical components in // life-support systems where a malfunction or failure may reasonably be // expected to result in significant injury to the user. The inclusion of // Cypress’ product in a life-support systems application implies that the // manufacturer assumes all risk of such use and in doing so indemnifies // Cypress against all charges. // // Use may be limited by and subject to the applicable Cypress software // license agreement. // //-------------------------------------------------------------------------- //-------------------------------------- // Included files //-------------------------------------- #include "GlobalParams.h" #include "mfgtest.h" #include "radio.h" #include "protocol.h" #include "timer.h" //-------------------------------------- // Local Definitions and Types //-------------------------------------- // Optionally compile complete module #if defined(MFG_TEST_CODE) && defined(TWO_WAY) typedef struct { UINT16 total_received_bits; UINT16 total_erased_bits; } MFG_RESULTS; #define MFG_HDR_TEST 0xF1 #define MFG_HDR_RES1 0xFB #define MFG_HDR_RES2 0xFD #define MFG_HDR_RES3 0xFE #define MFG_TEST_PKT_SIZE (MFG_PACKET_PAYLOAD_SIZE + 2) // add header & chksum #define MFG_RES_PKT_SIZE 10 //-------------------------------------- // Local Function Declarations //-------------------------------------- static void mfg_setup_radio(void); static BOOL mfg_receive_test_packets(MFG_RESULTS *); static void mfg_send_test_packets(void); static void mfg_send_results(MFG_RESULTS *); static void mfg_send_result_packet(UINT8 *pkt); //-------------------------------------- // Local Definitions //-------------------------------------- //-------------------------------------------------------------------------- // mfg_check_test //-------------------------------------------------------------------------- #ifndef MFG_ENTER_BY_KEY_NOT_PIN void mfg_pin_check() { // Set port pin for pull-up MFG_TEST_DM0 |= MFG_TEST_PIN; // pull-up drive on pin MFG_TEST_DM1 |= MFG_TEST_PIN; MFG_TEST_PORT |= MFG_TEST_PIN; // activate pull-up timer_delay_msec(100); if( (MFG_TEST_PORT & MFG_TEST_PIN) == 0 ) { mfg_test(); } // Set port drive back configured default MFG_TEST_DM0 = PORT_2_DRIVE_0; MFG_TEST_DM1 = PORT_2_DRIVE_1; } #endif //-------------------------------------------------------------------------- // mfg_test //-------------------------------------------------------------------------- void mfg_test() { MFG_RESULTS results; BOOL status; while(1) { mfg_setup_radio(); status = mfg_receive_test_packets(&results); if( status ) { mfg_send_test_packets(); mfg_send_results(&results); } } } //-------------------------------------------------------------------------- // mfg_setup_radio //-------------------------------------------------------------------------- static void mfg_setup_radio() { radio_wakeup(); SPI_RADIO_PUT(REG_THOLD_L, MFG_THRESHOLD_L & mTHRESHOLD_L); SPI_RADIO_PUT(REG_THOLD_H, MFG_THRESHOLD_H & mTHRESHOLD_H); SPI_RADIO_PUT(REG_PA, MFG_PA_BIAS & mPA_BIAS); SPI_RADIO_PUT(REG_SERDES_CTL, bSERDES_ENABLE | MFG_EOF_TIMEOUT & mEND_OF_FRAME_LEN ); radio_set_pn_code(MFG_PN_CODE); radio_receive_onset_channel(MFG_CHANNEL); radio_receive_on(); } //-------------------------------------------------------------------------- // mfg_receive_test_packets //-------------------------------------------------------------------------- static BOOL mfg_receive_test_packets(MFG_RESULTS *results) { UINT16 good_bits_in_packet; UINT16 erased_bits_in_packet; BOOL received = FALSE; UINT16 count; UINT8 bits; TIME_STAMP current_time; gChannelEof = 0; // get ready for packet gChannelBytes = 0; results->total_received_bits = 0; results->total_erased_bits = 0; // Get packets with timeout while(1) { current_time = timer_get_time_stamp(); do { if( gChannelEof != 0 ) { break; } timer_delay_50_usec(); } while( !timer_time_elapsed(current_time, MFG_RX_TIMEOUT) ); if( gChannelEof == 0 ) { if( received ) { // Timeout durring packet receive test break; } else { // Still waiting for start of packets continue; } } // Count valid bits in the packet received = TRUE; good_bits_in_packet = 0; erased_bits_in_packet = 0; for(count=0; count<gChannelBytes; count++) { for(bits=0; bits<8; bits++) { if( (gChannelValid[count] & 0x01) == 0x01 ) { ++good_bits_in_packet; } else { ++erased_bits_in_packet; } gChannelValid[count] >>= 1; } } // Check for noise if( good_bits_in_packet >= 4 ) { results->total_received_bits += 8 * gChannelBytes; results->total_erased_bits += erased_bits_in_packet; } count = ((UINT16)*((UINT8 *) (&rxPacket.first.byte) + 1) << 8) | *((UINT8 *) (&rxPacket.first.byte) + 2); if( count == MFG_NUM_PACKETS-1 ) { break; } gChannelEof = 0; // get ready for next packet gChannelBytes = 0; radio_switch_rxtransmit_on(); } return received; } //-------------------------------------------------------------------------- // mfg_send_test_packets //-------------------------------------------------------------------------- static void mfg_send_test_packets(void) { UINT8 pkt[MFG_TEST_PKT_SIZE]; UINT16 idx; UINT8 idx2; timer_delay_msec(MFG_PRE_TX_DELAY); for(idx=0; idx<MFG_NUM_PACKETS; idx++) { radio_switch_txtransmit_on(); // Build packet pkt[0] = MFG_HDR_TEST; pkt[1] = idx >> 8; pkt[2] = idx & 0xFF; for(idx2=3; idx2<MFG_TEST_PKT_SIZE-1; idx2++) { pkt[idx2] = 'A' + idx2 - 3; } pkt[idx2] = protocol_calc_ck_sum(pkt, MFG_TEST_PKT_SIZE-1, 0); radio_transmit(MFG_TEST_PKT_SIZE, pkt); timer_delay_msec(MFG_INTER_TX_DELAY); } } //-------------------------------------------------------------------------- // mfg_send_results //-------------------------------------------------------------------------- static void mfg_send_results(MFG_RESULTS *results) { UINT8 pkt[MFG_RES_PKT_SIZE]; UINT8 idx; // Build results 1 packet pkt[0] = MFG_HDR_RES1; pkt[1] = 0; pkt[2] = 0; pkt[3] = 0; pkt[4] = 0; pkt[5] = 0; pkt[6] = 0; pkt[7] = results->total_received_bits >> 8; pkt[8] = results->total_received_bits & 0xFF; pkt[9] = protocol_calc_ck_sum(pkt, 9, 0); mfg_send_result_packet(pkt); // Build results 2 packet pkt[0] = MFG_HDR_RES2; pkt[1] = 0; pkt[2] = 0; pkt[3] = results->total_erased_bits >> 8; pkt[4] = results->total_erased_bits & 0xFF; pkt[5] = 0; pkt[6] = 0; pkt[7] = 0; pkt[8] = 0; pkt[9] = protocol_calc_ck_sum(pkt, 9, 0); mfg_send_result_packet(pkt); // Build results 3 packet pkt[0] = MFG_HDR_RES3; for(idx=1; idx<9; idx++) { pkt[idx] = 0; } pkt[9] = protocol_calc_ck_sum(pkt, 9, 0); mfg_send_result_packet(pkt); } //-------------------------------------------------------------------------- // mfg_send_result_packet //-------------------------------------------------------------------------- static void mfg_send_result_packet(UINT8 *pkt) { UINT8 idx; timer_delay_msec(MFG_PRE_RESULTS_DELAY); for(idx=0; idx<MFG_NUM_RESULTS_PACKETS; idx++) { radio_switch_txtransmit_on(); radio_transmit(MFG_RES_PKT_SIZE, pkt); timer_delay_msec(MFG_INTER_RESULTS_DELAY); } } #endif // MFG_TEST