Changeset 359 for asp3_tinet_ecnl_arm
- Timestamp:
- Jun 20, 2018, 7:59:22 PM (5 years ago)
- Location:
- asp3_tinet_ecnl_arm/trunk
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/src/main.c
r352 r359 220 220 221 221 /* 初期化 */ 222 if (ffarch_init() == 0) { 223 gpio_write(&led_blue, 0); 224 } 225 else { 226 gpio_write(&led_blue, 0); 227 gpio_write(&led_red, 1); 228 } 222 ffarch_init(); 229 223 230 224 gpio_write(&led_green, 0); -
asp3_tinet_ecnl_arm/trunk/app2_light/src/main.c
r352 r359 207 207 208 208 /* 初期化 */ 209 if (ffarch_init() == 0) { 210 gpio_write(&led_blue, 0); 211 } 212 else { 213 gpio_write(&led_blue, 0); 214 gpio_write(&led_red, 1); 215 } 209 ffarch_init(); 216 210 217 211 gpio_write(&led_green, 0); -
asp3_tinet_ecnl_arm/trunk/app3_human_detec/src/main.c
r352 r359 207 207 208 208 /* 初期化 */ 209 if (ffarch_init() == 0) { 210 gpio_write(&led_blue, 0); 211 } 212 else { 213 gpio_write(&led_blue, 0); 214 gpio_write(&led_red, 1); 215 } 209 ffarch_init(); 216 210 217 211 gpio_write(&led_green, 0); -
asp3_tinet_ecnl_arm/trunk/app4_aircon/src/main.c
r352 r359 207 207 208 208 /* 初期化 */ 209 if (ffarch_init() == 0) { 210 gpio_write(&led_blue, 0); 211 } 212 else { 213 gpio_write(&led_blue, 0); 214 gpio_write(&led_red, 1); 215 } 209 ffarch_init(); 216 210 217 211 gpio_write(&led_green, 0); -
asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.c
r352 r359 207 207 208 208 /* 初期化 */ 209 if (ffarch_init() == 0) { 210 gpio_write(&led_blue, 0); 211 } 212 else { 213 gpio_write(&led_blue, 0); 214 gpio_write(&led_red, 1); 215 } 209 ffarch_init(); 216 210 217 211 gpio_write(&led_green, 0); -
asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/src/main.c
r352 r359 207 207 208 208 /* 初期化 */ 209 if (ffarch_init() == 0) { 210 gpio_write(&led_blue, 0); 211 } 212 else { 213 gpio_write(&led_blue, 0); 214 gpio_write(&led_red, 1); 215 } 209 ffarch_init(); 216 210 217 211 gpio_write(&led_green, 0); -
asp3_tinet_ecnl_arm/trunk/app7_buzzer/src/main.c
r352 r359 207 207 208 208 /* 初期化 */ 209 if (ffarch_init() == 0) { 210 gpio_write(&led_blue, 0); 211 } 212 else { 213 gpio_write(&led_blue, 0); 214 gpio_write(&led_red, 1); 215 } 209 ffarch_init(); 216 210 217 211 gpio_write(&led_green, 0); -
asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/serial.h
r352 r359 60 60 uint_t reacnt; /* 受信バッファ中の文字数 */ 61 61 uint_t wricnt; /* 送信バッファ中の文字数 */ 62 uint_t wbufsz; /* 送信バッファサイズ */63 62 } T_SERIAL_RPOR; 64 63 -
asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tSerialPortMain.c
r352 r359 504 504 pk_rpor->reacnt = VAR_receiveCount; 505 505 pk_rpor->wricnt = VAR_sendCount; 506 pk_rpor->wbufsz = ATTR_sendBufferSize;507 506 return(E_OK); 508 507 } -
asp3_tinet_ecnl_arm/trunk/bnep_bridge/src/main.c
r352 r359 193 193 194 194 /* 初期化 */ 195 if (ffarch_init() == 0) { 196 gpio_write(&led_blue, 0); 197 } 198 else { 199 gpio_write(&led_blue, 0); 200 gpio_write(&led_red, 1); 201 } 195 ffarch_init(); 202 196 203 197 gpio_write(&led_green, 0); -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.c
r352 r359 53 53 #include "util/ntstdio.h" 54 54 55 //extern ntstdio_t ntstdio; 55 extern ntstdio_t ntstdio; 56 57 enum ffarch_state_t { 58 FFS_IDLE, 59 FFS_RETRY_WAIT, 60 }; 61 62 enum ffarch_state_t ffarch_state; 63 volatile int ffarch_timer; 64 int ffarch_retry_count; 65 uint8_t sdfs_new_status, sdfs_prev_status; 66 67 static void ffarch_initialize(); 68 69 /* 70 * FatFSタスク 71 */ 72 void ffarch_task(intptr_t exinf) 73 { 74 ER ret, ret2; 75 SYSTIM prev, now; 76 int timer; 77 78 ffarch_initialize(); 79 80 ret2 = get_tim(&now); 81 if (ret2 != E_OK){ 82 ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s", 83 itron_strerror(ret2)); 84 return; 85 } 86 87 for(;;){ 88 prev = now; 89 90 /* タイマー取得 */ 91 timer = ffarch_get_timer(); 92 93 /* 待ち */ 94 ret = tslp_tsk(timer); 95 if ((ret != E_OK) && (ret != E_TMOUT)) { 96 ntstdio_printf(&ntstdio, "[ffarch] tslp_tsk error: %s %d", 97 itron_strerror(ret), timer); 98 break; 99 } 100 101 ret2 = get_tim(&now); 102 if (ret2 != E_OK) { 103 ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s", 104 itron_strerror(ret2)); 105 break; 106 } 107 108 /* 時間経過 */ 109 int elapse = now - prev; 110 ffarch_progress(elapse); 111 112 /* タイムアウト処理 */ 113 ffarch_timeout(); 114 } 115 } 56 116 57 117 FATFS RomDisk; … … 71 131 bool_t SD_begin(); 72 132 73 int ffarch_init() 74 { 75 int result = -1; 76 133 void ffarch_init() 134 { 77 135 /* SD_CD */ 78 136 gpio_init_in(&ins, P7_8); … … 81 139 sdfs_init(&sdfs, P8_5, P8_6, P8_3, P8_4, "sd"); 82 140 83 result = SD_begin() ? 0 : -1; 84 if (result == 0) { 85 printf("SD card (1:) OK!\n"); 141 ffarch_state = FFS_IDLE; 142 ffarch_timer = 0; 143 ffarch_retry_count = 3; 144 sdfs_new_status = 0; 145 sdfs_prev_status = STA_NODISK; 146 147 ffarch_timeout(); 148 149 act_tsk(FFARCH_TASK); 150 151 if (romdisk_init()) { 152 ntstdio_printf(&ntstdio, "ROM disk (0:) OK!\n"); 86 153 } 87 154 else { 88 printf("SD card (1:) NG!\n"); 89 } 155 ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n"); 156 } 157 158 serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV); 159 } 160 161 void ffarch_initialize() 162 { 90 163 sta_cyc(SDFS_CYC); 91 92 if (romdisk_init())93 result = 0;94 95 if (result == 0) {96 printf("ROM disk (0:) OK!\n");97 }98 else {99 printf("ROM disk (0:) NG!\n");100 }101 102 /* uploadディレクトリを作成しておく */103 f_mkdir("1:/upload");104 105 serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);106 107 return result;108 164 } 109 165 … … 173 229 return ramdisk_get_status(); 174 230 case 1: 175 return sdfs _status(&sdfs);231 return sdfs._is_initialized; 176 232 } 177 233 return STA_NOINIT; … … 200 256 } 201 257 258 DRESULT sdfs_ioctl(BYTE ctrl, void *buff); 259 202 260 DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff) 203 261 { … … 206 264 return RES_PARERR; /* ramdisk_ioctl(cmd, buff); */ 207 265 case 1: 208 switch(cmd) { 209 case CTRL_SYNC: 210 return sdfs_sync(&sdfs); 211 case GET_SECTOR_COUNT: 212 return sdfs_sectors(&sdfs); 213 case GET_BLOCK_SIZE: 214 *((DWORD*)buff) = 1; // default when not known 215 return RES_OK; 216 } 266 return sdfs_ioctl(cmd, buff); 217 267 } 218 268 return RES_PARERR; 219 269 } 220 270 271 DRESULT sdfs_ioctl(BYTE ctrl, void *buff) 272 { 273 DRESULT res; 274 uint32_t *dp = (uint32_t *)buff, st, ed; 275 uint8_t *ptr = (uint8_t *)buff; 276 277 if (sdfs._is_initialized & STA_NOINIT) 278 return RES_NOTRDY; 279 280 res = RES_ERROR; 281 282 switch (ctrl) { 283 case CTRL_SYNC: 284 if (sdfs_sync(&sdfs) == 0) { 285 res = RES_OK; 286 } 287 break; 288 case GET_SECTOR_SIZE: 289 *(WORD*)buff = 512; 290 res = RES_OK; 291 break; 292 case GET_SECTOR_COUNT: 293 *(DWORD*)buff = sdfs._capacity / 512; 294 res = RES_OK; 295 break; 296 case GET_BLOCK_SIZE: 297 *(DWORD*)buff = sdfs._block_len; 298 res = RES_OK; 299 break; 300 case CTRL_TRIM: 301 res = sdfs_trim(&sdfs, dp[0], dp[1]); 302 break; 303 case MMC_GET_TYPE: 304 *ptr = sdfs._card_type; 305 res = RES_OK; 306 break; 307 case MMC_GET_CSD: 308 memcpy(ptr, sdfs._csd, sizeof(sdfs._csd)); 309 res = RES_OK; 310 break; 311 case MMC_GET_CID: 312 memcpy(ptr, sdfs._cid, sizeof(sdfs._cid)); 313 res = RES_OK; 314 break; 315 case MMC_GET_OCR: 316 if (sdfs_get_ocr(&sdfs, buff) == 0) { 317 res = RES_OK; 318 } 319 break; 320 case MMC_GET_SDSTAT: 321 if (sdfs_get_sdstat(&sdfs, buff) == 0) { 322 res = RES_OK; 323 } 324 break; 325 default: 326 res = RES_PARERR; 327 } 328 329 return res; 330 } 331 221 332 void sdfs_cychdr(intptr_t exinf) 222 333 { 223 BYTE s ;224 225 s = sdfs._is_initialized;226 if (WP()) /* Write protected */334 BYTE s = 0; 335 336 /* Write protected */ 337 if (WP()) 227 338 s |= STA_PROTECT; 228 else /* Write enabled */339 else 229 340 s &= ~STA_PROTECT; 230 if (gpio_read(&ins)) /* Card is in socket */ 341 342 /* Card is in socket */ 343 if (gpio_read(&ins)) 344 s |= (STA_NODISK | STA_NOINIT); 345 else 231 346 s &= ~STA_NODISK; 232 else /* Socket empty */ 233 s |= (STA_NODISK | STA_NOINIT); 234 sdfs._is_initialized = s; 347 348 sdfs_new_status = s; 349 350 if ((sdfs_prev_status != sdfs_new_status) && (ffarch_state == FFS_IDLE)) { 351 ffarch_timer = 0; 352 wup_tsk(FFARCH_TASK); 353 } 354 } 355 356 int ffarch_get_timer() 357 { 358 return ffarch_timer; 359 } 360 361 void ffarch_progress(int elapse) 362 { 363 if (ffarch_timer != TMO_FEVR) { 364 ffarch_timer -= elapse; 365 if (ffarch_timer < 0) { 366 ffarch_timer = 0; 367 } 368 } 369 } 370 371 void ffarch_timeout() 372 { 373 if (ffarch_timer != 0) 374 return; 375 376 switch (ffarch_state) { 377 case FFS_RETRY_WAIT: 378 if (ffarch_retry_count == 0) { 379 ntstdio_printf(&ntstdio, "SD card (1:) initialize tired...\n"); 380 381 ffarch_state = FFS_IDLE; 382 ffarch_timer = TMO_FEVR; 383 ffarch_retry_count = 3; 384 break; 385 } 386 ffarch_retry_count--; 387 //goto case FFS_IDLE; 388 case FFS_IDLE: 389 /* SDカードが入れられた場合 */ 390 if ((sdfs._is_initialized & STA_NOINIT) 391 || (((sdfs_prev_status & STA_NODISK) != 0) && ((sdfs_new_status & STA_NODISK) == 0))) { 392 ntstdio_printf(&ntstdio, "SD card initializing ...\n"); 393 394 if (SD_begin()) { 395 ntstdio_printf(&ntstdio, "SD card (1:) OK!\n"); 396 397 /* uploadディレクトリを作成しておく */ 398 f_mkdir("1:/upload"); 399 400 ffarch_state = FFS_IDLE; 401 ffarch_timer = TMO_FEVR; 402 ffarch_retry_count = 3; 403 } 404 else { 405 ntstdio_printf(&ntstdio, "SD card (1:) NG!\n"); 406 ffarch_state = FFS_RETRY_WAIT; 407 ffarch_timer = 1000 * 1000; 408 } 409 } 410 /* SDカードが抜かれた場合 */ 411 else if (((sdfs_prev_status & STA_NODISK) == 0) && ((sdfs_new_status & STA_NODISK) != 0)) { 412 ntstdio_printf(&ntstdio, "SD card unmount\n"); 413 414 f_mount(&Sd.FatFs, "1:", 0); 415 ffarch_state = FFS_IDLE; 416 ffarch_timer = TMO_FEVR; 417 ffarch_retry_count = 3; 418 } 419 if (((sdfs_prev_status ^ sdfs_new_status) & STA_PROTECT) != 0) { 420 if ((sdfs_new_status & STA_PROTECT) != 0) 421 sdfs._is_initialized |= STA_PROTECT; 422 else 423 sdfs._is_initialized &= ~STA_PROTECT; 424 } 425 sdfs_prev_status = sdfs_new_status; 426 break; 427 } 235 428 } 236 429 -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.cfg
r352 r359 38 38 #include "ffarch.h" 39 39 40 CRE_TSK(FFARCH_TASK, { TA_NULL, 0, ffarch_task, FFARCH_PRIORITY, FFARCH_STACK_SIZE, NULL }); 40 41 CRE_CYC(SDFS_CYC, { TA_NULL, { TNFY_HANDLER, 0, sdfs_cychdr }, 1000000, 0 }); 41 42 -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.h
r352 r359 38 38 #define _FFARCH_H_ 39 39 40 int ffarch_init(); 40 #define FFARCH_PRIORITY 5 41 #define FFARCH_STACK_SIZE 512 42 43 void ffarch_init(); 44 void ffarch_task(intptr_t exinf); 45 int ffarch_get_timer(); 46 void ffarch_progress(int elapse); 47 void ffarch_timeout(); 48 41 49 void sdfs_cychdr(intptr_t exinf); 42 50 -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.c
r352 r359 115 115 */ 116 116 #include "sdfs.h" 117 #include "diskio.h" 117 118 //#include "mbed_debug.h" 118 119 #include "mbed_wait_api.h" 119 120 #define debug(str, ...) 121 #define debug_if(cond, strt, ...) if(cond){ debug(str, __ARGS__); } 120 #include "util/ntstdio.h" 121 122 extern ntstdio_t ntstdio; 123 #define debug(...) ntstdio_printf(&ntstdio, __VA_ARGS__) 124 #define debug_if(cond, ...) if(cond){ ntstdio_printf(&ntstdio, __VA_ARGS__); } 122 125 123 126 static int sdfs_initialise_card_v1(sdfs_t *obj); … … 144 147 obj->_init_sck = 100000; 145 148 obj->_transfer_sck = 1000000; 149 obj->_is_initialized = STA_NOINIT; 146 150 } 147 151 … … 154 158 #define R1_PARAMETER_ERROR (1 << 6) 155 159 156 // Types157 #define SDCARD_FAIL 0 //!< v1.x Standard Capacity158 #define SDCARD_V1 1 //!< v2.x Standard Capacity159 #define SDCARD_V2 2 //!< v2.x High Capacity160 #define SDCARD_V2HC 3 //!< Not recognised as an SD Card161 162 160 int sdfs_initialise_card(sdfs_t *obj) 163 161 { … … 173 171 if (sdfs__cmd(obj, 0, 0) != R1_IDLE_STATE) { 174 172 debug("No disk, or could not put SD card in to SPI idle state\n"); 175 return SDCARD_FAIL;173 return CT_FAIL; 176 174 } 177 175 … … 186 184 else { 187 185 debug("Not in idle state after sending CMD8 (not an SD card?)\n"); 188 return SDCARD_FAIL;186 return CT_FAIL; 189 187 } 190 188 } … … 192 190 static int sdfs_initialise_card_v1(sdfs_t *obj) 193 191 { 192 sdfs__cmd(obj, 55, 0); 193 if (sdfs__cmd(obj, 41, 0) <= 1) { 194 obj->cdv = 512; 195 debug_if(SD_DBG, "\n\rInit: SEDCARD_V1\n\r"); 196 for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { 197 sdfs__cmd(obj, 55, 0); 198 if (sdfs__cmd(obj, 41, 0) == 0) { 199 break; 200 } 201 } 202 return CT_SD1; 203 } 204 else { 205 for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { 206 if (sdfs__cmd(obj, 1, 0) == 0) 207 break; 208 } 209 return CT_MMC; 210 } 211 //if (!Timer1 || sdfs__cmd(obj, 16, 512) != 0) /* Set block length: 512 */ 212 // ty = 0; 213 214 debug("Timeout waiting for v1.x card\n"); 215 return CT_FAIL; 216 } 217 218 static int sdfs_initialise_card_v2(sdfs_t *obj) 219 { 220 int n; 221 uint8_t ocr[4]; 222 223 /* Get 32 bit return value of R7 resp */ 224 for (n = 0; n < 4; n++) ocr[n] = spi_master_write(&obj->_spi, 0xFF); 194 225 for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { 195 226 sdfs__cmd(obj, 55, 0); 196 if (sdfs__cmd(obj, 41, 0) == 0) { 197 obj->cdv = 512; 198 debug_if(SD_DBG, "\n\rInit: SEDCARD_V1\n\r"); 199 return SDCARD_V1; 200 } 201 } 202 203 debug("Timeout waiting for v1.x card\n"); 204 return SDCARD_FAIL; 205 } 206 207 static int sdfs_initialise_card_v2(sdfs_t *obj) 208 { 209 for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { 227 if (sdfs__cmd(obj, 41, 0x40000000) == 0) { 228 if (sdfs__cmd58(obj) == 0) { 229 for (n = 0; n < 4; n++) ocr[n] = spi_master_write(&obj->_spi, 0xFF); 230 debug_if(SD_DBG, "\n\rInit: SDCARD_V2\n\r"); 231 obj->cdv = 1; 232 return (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; 233 } 234 } 210 235 wait_ms(50); 211 sdfs__cmd58(obj);212 sdfs__cmd(obj, 55, 0);213 if (sdfs__cmd(obj, 41, 0x40000000) == 0) {214 sdfs__cmd58(obj);215 debug_if(SD_DBG, "\n\rInit: SDCARD_V2\n\r");216 obj->cdv = 1;217 return SDCARD_V2;218 }219 236 } 220 237 221 238 debug("Timeout waiting for v2.x card\n"); 222 return SDCARD_FAIL;239 return CT_FAIL; 223 240 } 224 241 225 242 int sdfs_initialize(sdfs_t *obj) 226 243 { 227 obj->_is_initialized = sdfs_initialise_card(obj); 228 if (obj->_is_initialized == 0) { 244 obj->_is_initialized |= STA_NOINIT; 245 246 obj->_card_type = sdfs_initialise_card(obj); 247 if (obj->_card_type == 0) { 229 248 debug("Fail to initialize card\n"); 230 249 return 1; 231 250 } 232 debug_if(SD_DBG, "init card = %d\n", obj->_is_initialized); 251 debug_if(SD_DBG, "init card = %x\n", obj->_is_initialized); 252 233 253 obj->_sectors = sdfs__sd_sectors(obj); 254 255 if (sdfs__cmdx(obj, 10, 0) != 0 /* READ_CID */ 256 || sdfs__read(obj, obj->_cid, 16) != 0) { 257 obj->_card_type = CT_FAIL; 258 debug("Fail to read cid\n"); 259 return 1; 260 } 234 261 235 262 // Set block length to 512 (CMD16) 236 263 if (sdfs__cmd(obj, 16, 512) != 0) { 264 obj->_card_type = CT_FAIL; 237 265 debug("Set 512-byte block timed out\n"); 238 266 return 1; 239 267 } 268 269 obj->_is_initialized &= ~STA_NOINIT; 240 270 241 271 // Set SCK for data transfer … … 246 276 int sdfs_write(sdfs_t *obj, const uint8_t *buffer, uint32_t block_number, uint32_t count) 247 277 { 248 if ( !obj->_is_initialized) {278 if (obj->_is_initialized & (STA_NOINIT | STA_PROTECT)) { 249 279 return -1; 250 280 } … … 266 296 int sdfs_read(sdfs_t *obj, uint8_t *buffer, uint32_t block_number, uint32_t count) 267 297 { 268 if ( !obj->_is_initialized) {298 if (obj->_is_initialized & STA_NOINIT) { 269 299 return -1; 270 300 } … … 287 317 { 288 318 // FATFileSystem::disk_status() returns 0 when initialized 289 if ( obj->_is_initialized) {319 if ((obj->_is_initialized & STA_NOINIT) == 0) { 290 320 return 0; 291 321 } … … 294 324 } 295 325 } 296 int sdfs_sync(sdfs_t *obj) { return 0; } 326 297 327 uint64_t sdfs_sectors(sdfs_t *obj) { return obj->_sectors; } 298 328 … … 477 507 { 478 508 uint32_t c_size, c_size_mult, read_bl_len; 479 uint32_t block_len, mult, blocknr, capacity;509 uint32_t mult, blocknr; 480 510 uint32_t hc_c_size; 481 511 uint64_t blocks; … … 487 517 } 488 518 489 uint8_t csd[16]; 490 if (sdfs__read(obj, csd, 16) != 0) { 519 if (sdfs__read(obj, obj->_csd, 16) != 0) { 491 520 debug("Couldn't read csd response from disk\n"); 492 521 return 0; … … 498 527 // read_bl_len : csd[83:80] - the *maximum* read block length 499 528 500 int csd_structure = sdfs_ext_bits(obj, csd, 127, 126);529 int csd_structure = sdfs_ext_bits(obj, obj->_csd, 127, 126); 501 530 502 531 switch (csd_structure) { 503 532 case 0: 504 533 obj->cdv = 512; 505 c_size = sdfs_ext_bits(obj, csd, 73, 62);506 c_size_mult = sdfs_ext_bits(obj, csd, 49, 47);507 read_bl_len = sdfs_ext_bits(obj, csd, 83, 80);508 509 block_len = 1 << read_bl_len;534 c_size = sdfs_ext_bits(obj, obj->_csd, 73, 62); 535 c_size_mult = sdfs_ext_bits(obj, obj->_csd, 49, 47); 536 read_bl_len = sdfs_ext_bits(obj, obj->_csd, 83, 80); 537 538 obj->_block_len = 1 << read_bl_len; 510 539 mult = 1 << (c_size_mult + 2); 511 540 blocknr = (c_size + 1) * mult; 512 capacity = blocknr *block_len;513 blocks = capacity / 512;514 debug_if(SD_DBG, "\n\rSDCard\n\rc_size: %d \n\rcapacity: %ld \n\rsectors: %lld\n\r", c_size, capacity, blocks);541 obj->_capacity = blocknr * obj->_block_len; 542 blocks = obj->_capacity / 512; 543 debug_if(SD_DBG, "\n\rSDCard\n\rc_size: %d \n\rcapacity: %ld \n\rsectors: %lld\n\r", c_size, obj->_capacity, blocks); 515 544 break; 516 545 517 546 case 1: 518 547 obj->cdv = 1; 519 hc_c_size = sdfs_ext_bits(obj, csd, 63, 48);548 hc_c_size = sdfs_ext_bits(obj, obj->_csd, 63, 48); 520 549 blocks = (hc_c_size + 1) * 1024; 521 550 debug_if(SD_DBG, "\n\rSDHC Card \n\rhc_c_size: %d\n\rcapacity: %lld \n\rsectors: %lld\n\r", hc_c_size, blocks * 512, blocks); … … 528 557 return blocks; 529 558 } 559 560 static 561 int wait_ready(sdfs_t *obj, uint32_t wt) 562 { 563 /* Wait until card goes ready or timeout */ 564 for (int i = 0; i < wt; i++) { 565 if (spi_master_write(&obj->_spi, 0xFF) == 0xFF) 566 /* Card goes ready */ 567 return 1; 568 } 569 570 /* Timeout occured */ 571 return 0; 572 } 573 574 static 575 void deselect(sdfs_t *obj) 576 { 577 /* Set CS# high */ 578 gpio_write(&obj->_cs, 0); 579 580 /* Dummy clock (force DO hi-z for multiple slave SPI) */ 581 spi_master_write(&obj->_spi, 0xFF); 582 } 583 584 static 585 int select(sdfs_t *obj) 586 { 587 /* Set CS# low */ 588 gpio_write(&obj->_cs, 1); 589 590 /* Dummy clock (force DO enabled) */ 591 spi_master_write(&obj->_spi, 0xFF); 592 593 /* Wait for card ready */ 594 if (wait_ready(obj, 500)) 595 return 0; 596 597 deselect(obj); 598 599 /* Failed to select the card due to timeout */ 600 return -1; 601 } 602 603 int sdfs_sync(sdfs_t *obj) 604 { 605 int ret = select(obj); 606 deselect(obj); 607 return ret; 608 } 609 610 int sdfs_trim(sdfs_t *obj, uint32_t st, uint32_t ed) 611 { 612 int res = -1; 613 614 for(;;) { 615 /* Check if the card is SDC */ 616 if (!(obj->_card_type & CT_SDC)) 617 break; 618 /* Check if sector erase can be applied to the card */ 619 if (!(obj->_csd[0] >> 6) && !(obj->_csd[10] & 0x40)) 620 break; 621 /* Load sector block */ 622 if (!(obj->_card_type & CT_BLOCK)) { 623 st *= 512; ed *= 512; 624 } 625 /* Erase sector block */ 626 if ((sdfs__cmd(obj, 32, st) == 0) 627 && (sdfs__cmd(obj, 33, ed) == 0) 628 && (sdfs__cmd(obj, 38, 0) == 0) 629 && wait_ready(obj, 30000)) 630 res = 0; 631 } 632 633 return res; 634 } 635 636 int sdfs_get_ocr(sdfs_t *obj, uint8_t buff[4]) 637 { 638 int res = -1, n; 639 640 /* READ_OCR */ 641 if (sdfs__cmd58(obj) == 0) { 642 for (n = 4; n; n--) { 643 *buff++ = spi_master_write(&obj->_spi, 0xFF); 644 } 645 res = 0; 646 } 647 648 deselect(obj); 649 650 return res; 651 } 652 653 int sdfs_get_sdstat(sdfs_t *obj, uint8_t buff[64]) 654 { 655 int res = -1; 656 657 sdfs__cmd(obj, 55, 0); 658 659 /* SD_STATUS */ 660 if (sdfs__cmd(obj, 13, 0) == 0) { 661 spi_master_write(&obj->_spi, 0xFF); 662 if (sdfs__read(obj, buff, 64) == 0) 663 return 0; 664 } 665 666 deselect(obj); 667 668 return res; 669 } -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.h
r352 r359 34 34 #endif 35 35 36 /* MMC card type flags (MMC_GET_TYPE) */ 37 #define CT_FAIL 0x00 38 #define CT_MMC 0x01 /* MMC ver 3 */ 39 #define CT_SD1 0x02 /* SD ver 1 */ 40 #define CT_SD2 0x04 /* SD ver 2 */ 41 #define CT_SDC (CT_SD1|CT_SD2) /* SD */ 42 #define CT_BLOCK 0x08 /* Block addressing */ 43 36 44 /** Access the filesystem on an SD Card using SPI 37 45 * … … 51 59 typedef struct sdfs_s{ 52 60 const char* name; 61 volatile uint8_t _is_initialized; 62 uint8_t _card_type; 63 uint8_t _csd[16], _cid[16]; 64 uint64_t _capacity; 65 uint64_t _block_len; 53 66 uint64_t _sectors; 54 67 spi_t _spi; … … 57 70 uint32_t _init_sck; 58 71 uint32_t _transfer_sck; 59 int _is_initialized;60 72 } sdfs_t; 61 73 … … 76 88 int sdfs_sync(sdfs_t *obj); 77 89 uint64_t sdfs_sectors(sdfs_t *obj); 90 int sdfs_trim(sdfs_t *obj, uint32_t st, uint32_t ed); 91 int sdfs_get_ocr(sdfs_t *obj, uint8_t buff[4]); 92 int sdfs_get_sdstat(sdfs_t *obj, uint8_t buff[64]); 78 93 79 94 #ifdef __cplusplus -
asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c
r352 r359 400 400 FD_SET(fd, (fd_set *)&flgptn); 401 401 } 402 if (rpor.wricnt < rpor.wbufsz) {402 if (rpor.wricnt != 0) { 403 403 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 404 404 … … 428 428 FD_SET(fd, (fd_set *)flgptn); 429 429 } 430 if (rpor.wricnt < rpor.wbufsz) {430 if (rpor.wricnt != 0) { 431 431 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 432 432 -
asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c
r352 r359 60 60 #include "kernel_cfg.h" 61 61 #include "tinet_cfg.h" 62 #include "util/ntstdio.h" 63 64 extern ntstdio_t ntstdio; 62 65 63 66 T_DHCP4_CLI_CONTEXT *dhcp4_cli_initialize(ID tskid, ID cepid); … … 94 97 95 98 get_tid(&nc->tskid); 96 syslog(LOG_NOTICE, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);99 ntstdio_printf(&ntstdio, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf); 97 100 98 101 /* 初期化 */ … … 102 105 ret = get_tim(&time); 103 106 if (ret != E_OK) { 104 syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %7lu,%s",107 ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %7lu,%s", 105 108 nc->cepid, time / SYSTIM_HZ, itron_strerror(ret)); 106 109 return; … … 116 119 error = tslp_tsk(timer); 117 120 if ((error != E_OK) && (error != E_TMOUT)) { 118 syslog(LOG_NOTICE, "[NET MISC,%d] tslp_tsk error: %s %d",121 ntstdio_printf(&ntstdio, "[NET MISC,%d] tslp_tsk error: %s %d", 119 122 nc->cepid, itron_strerror(error), timer); 120 123 break; … … 123 126 ret = get_tim(&time); 124 127 if (ret != E_OK) { 125 syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %s",128 ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %s", 126 129 nc->cepid, itron_strerror(ret)); 127 130 break; -
asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c
r352 r359 50 50 #include <t_syslog.h> 51 51 #include "kernel_cfg.h" 52 #include "util/ntstdio.h" 53 54 extern ntstdio_t ntstdio; 52 55 53 56 #endif /* of #if defined(TARGET_KERNEL_ASP) */ … … 276 279 } 277 280 278 syslog(LOG_NOTICE, "[NTP CLI,%d] recv time: %s .%09u",281 ntstdio_printf(&ntstdio, "[NTP CLI,%d] recv time: %s .%09u\n", 279 282 nc->cepid, nc->buf, tp.tv_nsec); 280 283 } … … 308 311 line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4); 309 312 if (line == NULL || !in6_is_addr_ipv4mapped(&nc->ipaddr6)) { 310 syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",313 ntstdio_printf(&ntstdio, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.", 311 314 nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ); 312 315 nc->timer = SLP_ITV; … … 316 319 #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */ 317 320 if ((line = lookup_ipaddr(&nc->snd_rmt.ipaddr, NTP_SRV_URL, DEFAULT_API_PROTO)) == NULL) { 318 syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",321 ntstdio_printf(&ntstdio, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.", 319 322 nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ); 320 323 nc->timer = SLP_ITV; … … 420 423 421 424 if ((error = udp_snd_dat(nc->cepid, &nc->snd_rmt, ntp, len, TMO_NBLK)) != E_WBLK) { 422 syslog(LOG_NOTICE, "[NTP CLI,%d] udp_snd_dat error: %s",425 ntstdio_printf(&ntstdio, "[NTP CLI,%d] udp_snd_dat error: %s", 423 426 nc->cepid, itron_strerror(error)); 424 427 return error; … … 438 441 ret = get_tim(&time); 439 442 if (ret != E_OK) { 440 syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s",443 ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s", 441 444 nc->cepid, itron_strerror(ret)); 442 445 tp->tv_sec = 0; … … 458 461 ret = set_tim(time); 459 462 if (ret != E_OK) { 460 syslog(LOG_NOTICE, "[NTP CLI,%d] set_tim error: %s",463 ntstdio_printf(&ntstdio, "[NTP CLI,%d] set_tim error: %s", 461 464 nc->cepid, itron_strerror(ret)); 462 465 } … … 476 479 if (len < 0 && len != E_RLWAI) { 477 480 /* E_RLWAI 以外で、0 以下の場合は、エラーを意味している。*/ 478 syslog(LOG_NOTICE, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,481 ntstdio_printf(&ntstdio, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid, 479 482 itron_strerror(len), in_strtfn(fncd)); 480 483 } … … 483 486 if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0) 484 487 { 485 syslog(LOG_NOTICE, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,488 ntstdio_printf(&ntstdio, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid, 486 489 itron_strerror(len)); 487 490 } … … 515 518 516 519 get_tid(&nc->tskid); 517 syslog(LOG_NOTICE, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);520 ntstdio_printf(&ntstdio, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf); 518 521 519 522 /* 初期化 */ … … 522 525 ret = get_tim(&time); 523 526 if (ret != E_OK) { 524 syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %7lu,%s",527 ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %7lu,%s", 525 528 nc->cepid, time / SYSTIM_HZ, itron_strerror(ret)); 526 529 return; … … 536 539 error = tslp_tsk(timer); 537 540 if ((error != E_OK) && (error != E_TMOUT)) { 538 syslog(LOG_NOTICE, "[NTP CLI,%d] tslp_tsk error: %s %d",541 ntstdio_printf(&ntstdio, "[NTP CLI,%d] tslp_tsk error: %s %d", 539 542 nc->cepid, itron_strerror(error), timer); 540 543 break; … … 543 546 ret = get_tim(&time); 544 547 if (ret != E_OK) { 545 syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s",548 ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s", 546 549 nc->cepid, itron_strerror(ret)); 547 550 break;
Note:
See TracChangeset
for help on using the changeset viewer.